mirror of
https://github.com/nocodb/nocodb.git
synced 2026-05-04 22:26:59 +00:00
* fix: get rid of barrel files * chore: get rid of explicit imports * fix: use explicit import for classes and enums * fix: use explicit import for enum & class & aliases * fix: build issues
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
import { acceptHMRUpdate, defineStore } from 'pinia'
|
|
import { MAX_WIDTH_FOR_MOBILE_MODE } from '~/lib/constants'
|
|
|
|
export const useSidebarStore = defineStore('sidebarStore', () => {
|
|
const { width } = useWindowSize()
|
|
const isViewPortMobile = () => {
|
|
return width.value < MAX_WIDTH_FOR_MOBILE_MODE
|
|
}
|
|
const { isMobileMode } = useGlobal()
|
|
|
|
const tablesStore = useTablesStore()
|
|
const _isLeftSidebarOpen = ref(!isViewPortMobile())
|
|
const isLeftSidebarOpen = computed({
|
|
get() {
|
|
return (isMobileMode.value && !tablesStore.activeTableId) || _isLeftSidebarOpen.value
|
|
},
|
|
set(value) {
|
|
_isLeftSidebarOpen.value = value
|
|
},
|
|
})
|
|
|
|
const isRightSidebarOpen = ref(true)
|
|
|
|
const leftSidebarWidthPercent = ref(isViewPortMobile() ? 0 : 20)
|
|
|
|
const leftSideBarSize = ref({
|
|
old: 20,
|
|
current: leftSidebarWidthPercent.value,
|
|
})
|
|
|
|
const leftSidebarState = ref<
|
|
'openStart' | 'openEnd' | 'hiddenStart' | 'hiddenEnd' | 'peekOpenStart' | 'peekOpenEnd' | 'peekCloseOpen' | 'peekCloseEnd'
|
|
>(isLeftSidebarOpen.value ? 'openEnd' : 'hiddenEnd')
|
|
|
|
const mobileNormalizedSidebarSize = computed(() => {
|
|
if (isMobileMode.value) {
|
|
return isLeftSidebarOpen.value ? 100 : 0
|
|
}
|
|
|
|
return leftSideBarSize.value.current
|
|
})
|
|
|
|
const leftSidebarWidth = computed(() => (width.value * mobileNormalizedSidebarSize.value) / 100)
|
|
|
|
const nonHiddenMobileSidebarSize = computed(() => {
|
|
if (isMobileMode.value) {
|
|
return 100
|
|
}
|
|
|
|
return leftSideBarSize.value.current ?? leftSideBarSize.value.old
|
|
})
|
|
|
|
const nonHiddenLeftSidebarWidth = computed(() => (width.value * nonHiddenMobileSidebarSize.value) / 100)
|
|
|
|
const formRightSidebarState = ref({
|
|
minWidth: 384,
|
|
maxWidth: 600,
|
|
width: 384,
|
|
})
|
|
|
|
const formRightSidebarWidthPercent = computed(() => {
|
|
return (formRightSidebarState.value.width / (width.value - leftSidebarWidth.value)) * 100
|
|
})
|
|
|
|
return {
|
|
isLeftSidebarOpen,
|
|
isRightSidebarOpen,
|
|
leftSidebarWidthPercent,
|
|
leftSideBarSize,
|
|
leftSidebarState,
|
|
leftSidebarWidth,
|
|
mobileNormalizedSidebarSize,
|
|
nonHiddenLeftSidebarWidth,
|
|
windowSize: width,
|
|
formRightSidebarState,
|
|
formRightSidebarWidthPercent,
|
|
}
|
|
})
|
|
|
|
if (import.meta.hot) {
|
|
import.meta.hot.accept(acceptHMRUpdate(useSidebarStore as any, import.meta.hot))
|
|
}
|