@@ -20,10 +20,33 @@ function parseSidebarWidth(raw: string | undefined) {
2020 return clampSidebarWidth ( parsed )
2121}
2222
23+ function parseCollapsedState ( raw : unknown ) {
24+ if ( ! raw ) {
25+ return false
26+ }
27+
28+ if ( typeof raw === 'boolean' ) {
29+ return raw
30+ }
31+
32+ if ( typeof raw === 'number' ) {
33+ return raw === 1
34+ }
35+
36+ if ( typeof raw !== 'string' ) {
37+ return false
38+ }
39+
40+ const normalized = raw . trim ( ) . toLowerCase ( )
41+ return normalized === '1' || normalized === 'true' || normalized === 'yes'
42+ }
43+
2344export const useEditoroUiStore = defineStore ( 'editoro-ui' , ( ) => {
2445 const sidebarWidthCookie = useCookie < string > ( 'editoro.sidebar.width' , { path : '/' , sameSite : 'lax' } )
46+ const sidebarCollapsedCookie = useCookie < string > ( 'editoro.sidebar.collapsed' , { path : '/' , sameSite : 'lax' } )
2547
2648 const sidebarWidth = ref ( parseSidebarWidth ( sidebarWidthCookie . value ) )
49+ const isSidebarCollapsed = ref ( parseCollapsedState ( sidebarCollapsedCookie . value ) )
2750 const isResizingSidebar = ref ( false )
2851 const sidebarResizeStartX = ref ( 0 )
2952 const sidebarResizeStartWidth = ref ( sidebarWidth . value )
@@ -59,7 +82,7 @@ export const useEditoroUiStore = defineStore('editoro-ui', () => {
5982 }
6083
6184 function onSidebarResizeStart ( event : MouseEvent ) {
62- if ( ! import . meta. client ) {
85+ if ( ! import . meta. client || isSidebarCollapsed . value ) {
6386 return
6487 }
6588
@@ -72,6 +95,24 @@ export const useEditoroUiStore = defineStore('editoro-ui', () => {
7295 window . addEventListener ( 'mouseup' , stopSidebarResize )
7396 }
7497
98+ function collapseSidebar ( ) {
99+ stopSidebarResize ( )
100+ isSidebarCollapsed . value = true
101+ }
102+
103+ function expandSidebar ( ) {
104+ isSidebarCollapsed . value = false
105+ }
106+
107+ function toggleSidebarCollapsed ( ) {
108+ if ( isSidebarCollapsed . value ) {
109+ expandSidebar ( )
110+ return
111+ }
112+
113+ collapseSidebar ( )
114+ }
115+
75116 function openCreateModal ( type : CreateTargetType ) {
76117 createTargetType . value = type
77118 createInputPath . value = ''
@@ -103,10 +144,15 @@ export const useEditoroUiStore = defineStore('editoro-ui', () => {
103144 sidebarWidthCookie . value = String ( clampSidebarWidth ( value ) )
104145 } )
105146
147+ watch ( isSidebarCollapsed , ( value ) => {
148+ sidebarCollapsedCookie . value = value ? '1' : '0'
149+ } , { immediate : true } )
150+
106151 return {
107152 minSidebarWidth : MIN_SIDEBAR_WIDTH ,
108153 maxSidebarWidth : MAX_SIDEBAR_WIDTH ,
109154 sidebarWidth,
155+ isSidebarCollapsed,
110156 createModalOpen,
111157 createTargetType,
112158 createInputPath,
@@ -115,6 +161,9 @@ export const useEditoroUiStore = defineStore('editoro-ui', () => {
115161 deleteModalOpen,
116162 onSidebarResizeStart,
117163 stopSidebarResize,
164+ collapseSidebar,
165+ expandSidebar,
166+ toggleSidebarCollapsed,
118167 openCreateModal,
119168 closeCreateModal,
120169 openRenameModal,
0 commit comments