@@ -26,19 +26,19 @@ export interface ColumnLayout {
2626 folded : boolean ;
2727 /** 用户手动折叠态(自动折叠兜底下的用户意图保留) */
2828 manuallyFolded : boolean ;
29- setWidth : ( w : number ) => void ;
3029 /** 拖拽手柄增量化(负数=收窄——列方向感知由调用方处理) */
3130 resizeBy : ( delta : number ) => void ;
3231 resetWidth : ( ) => void ;
3332 setManualFolded : ( v : boolean ) => void ;
34- toggleFold : ( ) => void ;
3533 /** 立即展开(同时清自动/手动折叠态——窄窗下点击窄条仍可展开,resize 后按阈值重折) */
3634 expand : ( ) => void ;
3735}
3836
3937const clamp = ( w : number , min : number , max : number ) => Math . max ( min , Math . min ( max , Math . round ( w ) ) ) ;
4038
4139function readNumber ( key : string , fallback : number ) : number {
40+ // window 守卫(GroupSidebar 同款模式)——非浏览器环境(SSR/未来测试宿主)零崩溃
41+ if ( typeof window === "undefined" ) return fallback ;
4242 try {
4343 const v = window . localStorage . getItem ( `layout:col-width:${ key } ` ) ;
4444 return v != null ? Number ( v ) : fallback ;
@@ -48,6 +48,7 @@ function readNumber(key: string, fallback: number): number {
4848}
4949
5050function readBool ( key : string , fallback : boolean ) : boolean {
51+ if ( typeof window === "undefined" ) return fallback ;
5152 try {
5253 const v = window . localStorage . getItem ( `layout:col-fold:${ key } ` ) ;
5354 return v != null ? v === "1" : fallback ;
@@ -57,6 +58,7 @@ function readBool(key: string, fallback: boolean): boolean {
5758}
5859
5960function writeLayout ( key : string , value : string ) {
61+ if ( typeof window === "undefined" ) return ;
6062 try {
6163 window . localStorage . setItem ( key , value ) ;
6264 } catch {
@@ -85,12 +87,10 @@ export function useColumnLayout(key: string, opts: Options): ColumnLayout {
8587 useEffect ( ( ) => { writeLayout ( `layout:col-width:${ key } ` , String ( width ) ) ; } , [ key , width ] ) ;
8688 useEffect ( ( ) => { writeLayout ( `layout:col-fold:${ key } ` , manualFolded ? "1" : "0" ) ; } , [ key , manualFolded ] ) ;
8789
88- const setWidth = useCallback ( ( w : number ) => setWidthState ( clamp ( w , opts . min , opts . max ) ) , [ opts . min , opts . max ] ) ;
8990 const resizeBy = useCallback ( ( delta : number ) => {
9091 setWidthState ( ( cur ) => clamp ( cur + delta , opts . min , opts . max ) ) ;
9192 } , [ opts . min , opts . max ] ) ;
9293 const resetWidth = useCallback ( ( ) => setWidthState ( opts . default ) , [ opts . default ] ) ;
93- const toggleFold = useCallback ( ( ) => setManualFolded ( ( v ) => ! v ) , [ ] ) ;
9494 const expand = useCallback ( ( ) => {
9595 setAutoFolded ( false ) ;
9696 setManualFolded ( false ) ;
@@ -100,11 +100,9 @@ export function useColumnLayout(key: string, opts: Options): ColumnLayout {
100100 width,
101101 folded : autoFolded || manualFolded ,
102102 manuallyFolded : manualFolded ,
103- setWidth,
104103 resizeBy,
105104 resetWidth,
106105 setManualFolded,
107- toggleFold,
108106 expand,
109- } ) , [ width , autoFolded , manualFolded , setWidth , resizeBy , resetWidth , toggleFold , expand ] ) ;
107+ } ) , [ width , autoFolded , manualFolded , resizeBy , resetWidth , expand ] ) ;
110108}
0 commit comments