@jsb188/app-settings-web 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +19 -7
- package/src/assets.d.ts +1 -0
- package/src/main.ts +3 -2
- package/src/modules/AppSettingsLayout.tsx +331 -0
- package/src/modules/AppSettingsTable.tsx +70 -0
- package/src/modules/ChangeCredentialsLayout.tsx +347 -0
- package/src/ui/AppSettingsTableUI.tsx +124 -0
- package/src/ui/AppSettingsUI.tsx +223 -0
- package/src/AppSettingsLayout.tsx +0 -213
- package/src/ChangeCredentialsLayout.tsx +0 -350
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jsb188
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/app-settings-web",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
4
4
|
"description": "App settings module for web.",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "MIT",
|
|
6
6
|
"author": "jsb188",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./src/main.ts"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@jsb188/app": "1.1.
|
|
13
|
-
"@jsb188/
|
|
12
|
+
"@jsb188/app": "1.1.13",
|
|
13
|
+
"@jsb188/graphql": "1.1.13",
|
|
14
|
+
"@jsb188/react": "1.1.13",
|
|
15
|
+
"@jsb188/react-web": "1.1.13",
|
|
14
16
|
"jotai": "^2.20.2",
|
|
15
|
-
"react": "^19.
|
|
16
|
-
"react-
|
|
17
|
+
"react": "^19.3.0",
|
|
18
|
+
"react-dom": "^19.3.0",
|
|
19
|
+
"react-router": "^8.4.0",
|
|
20
|
+
"@jsb188/form": "1.1.13"
|
|
17
21
|
},
|
|
18
22
|
"scripts": {
|
|
19
23
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
20
24
|
"build": "tsc"
|
|
21
|
-
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src/**/*.{ts,tsx,css,svg}",
|
|
28
|
+
"!**/*.test.*",
|
|
29
|
+
"!**/*.spec.*",
|
|
30
|
+
"!**/tests/**",
|
|
31
|
+
"!**/*.md",
|
|
32
|
+
"!**/.DS_Store"
|
|
33
|
+
]
|
|
22
34
|
}
|
package/src/assets.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '*.css';
|
package/src/main.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from './AppSettingsLayout';
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './modules/AppSettingsLayout';
|
|
2
|
+
export * from './modules/AppSettingsTable';
|
|
3
|
+
export * from './modules/ChangeCredentialsLayout';
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { useIsKeyboardLayerActive } from '@jsb188/react/states/keyboardLayer';
|
|
2
|
+
import { useElementSize } from '@jsb188/react-web/hooks/use-element-size';
|
|
3
|
+
import { getErrorMessageContent } from '@jsb188/react-web/modules/layout/MainLayout';
|
|
4
|
+
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
5
|
+
import Markdown from '@jsb188/react-web/ui/Markdown';
|
|
6
|
+
import { splitTableListGridTracks } from '@jsb188/react-web/modules/TableList.helpers';
|
|
7
|
+
import { getTableGridTemplateColumns, getTableWidthStyle } from '@jsb188/react-web/modules/table/layout';
|
|
8
|
+
import { TableDataCell, TableDataRow, TableEmptyCell, TableHeaderRow, TableRoot } from '@jsb188/react-web/ui/TableUI';
|
|
9
|
+
import type { ModalHandlerProps, OpenModalPopUpFn } from '@jsb188/react/states';
|
|
10
|
+
import { useClosePopOver } from '@jsb188/react/states';
|
|
11
|
+
import { useCallback, useEffect, useMemo, useState, type ComponentType, type ReactNode } from 'react';
|
|
12
|
+
import {
|
|
13
|
+
AppSettingsContentContainer,
|
|
14
|
+
AppSettingsFloatingSaveButton,
|
|
15
|
+
AppSettingsSideNav,
|
|
16
|
+
type AppSettingsSideNavOption,
|
|
17
|
+
} from '../ui/AppSettingsUI';
|
|
18
|
+
|
|
19
|
+
const FILE_CONSTANTS = {
|
|
20
|
+
mockRowCount: 10,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Types
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
interface ControllerState {
|
|
28
|
+
switchCase: string;
|
|
29
|
+
hasChanges: boolean;
|
|
30
|
+
saving: boolean;
|
|
31
|
+
saveCounter: number;
|
|
32
|
+
resetCounter: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface AppSettingsSwitchCaseProps extends ControllerState {
|
|
36
|
+
onSave: () => void;
|
|
37
|
+
onChangeDiff: (hasChanges?: boolean, saving?: boolean) => void;
|
|
38
|
+
openModalPopUp: OpenModalPopUpFn;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface AppSettingsTableContentProps {
|
|
42
|
+
notReady?: boolean;
|
|
43
|
+
gridLayoutStyle: string;
|
|
44
|
+
children?: ReactNode;
|
|
45
|
+
error?: any;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Match the settings table's gutter, header, row sizing, and dividers while data loads.
|
|
50
|
+
*/
|
|
51
|
+
const AppSettingsTableMock = (p: { gridLayoutStyle: string }) => {
|
|
52
|
+
// Settings grids end with an actions track; the table primitives provide that track themselves.
|
|
53
|
+
const columns = useMemo(
|
|
54
|
+
() =>
|
|
55
|
+
splitTableListGridTracks(p.gridLayoutStyle)
|
|
56
|
+
.slice(0, -1)
|
|
57
|
+
.map((width, index) => ({
|
|
58
|
+
key: `mock-${index}`,
|
|
59
|
+
width,
|
|
60
|
+
header: {
|
|
61
|
+
headerContent: (
|
|
62
|
+
<span
|
|
63
|
+
className='mock alt bl min_w_20'
|
|
64
|
+
style={{ width: '40%' }}
|
|
65
|
+
>
|
|
66
|
+
....
|
|
67
|
+
</span>
|
|
68
|
+
),
|
|
69
|
+
},
|
|
70
|
+
})),
|
|
71
|
+
[p.gridLayoutStyle],
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<div
|
|
76
|
+
aria-busy='true'
|
|
77
|
+
className='-mx_50 min_w_0 ft_sm mt_md'
|
|
78
|
+
>
|
|
79
|
+
<div
|
|
80
|
+
aria-hidden
|
|
81
|
+
className='pl_40 min_w_0 rel'
|
|
82
|
+
>
|
|
83
|
+
<div className='abs_l w_40 bd_r_1 bd_lt noclick' />
|
|
84
|
+
<TableRoot style={{ gridTemplateColumns: getTableGridTemplateColumns(columns, {}), width: getTableWidthStyle(columns, {}) }}>
|
|
85
|
+
<TableHeaderRow
|
|
86
|
+
addHorizontalPadding
|
|
87
|
+
columns={columns}
|
|
88
|
+
showColumnDividers
|
|
89
|
+
/>
|
|
90
|
+
<div className='table_grid_body'>
|
|
91
|
+
{Array.from({ length: FILE_CONSTANTS.mockRowCount }, (_, rowIndex) => (
|
|
92
|
+
<TableDataRow key={rowIndex}>
|
|
93
|
+
{columns.map((column, columnIndex) => (
|
|
94
|
+
<TableDataCell
|
|
95
|
+
key={column.key}
|
|
96
|
+
addHorizontalPadding
|
|
97
|
+
columnIndex={columnIndex}
|
|
98
|
+
isLastColumn={columnIndex === columns.length - 1}
|
|
99
|
+
showColumnDivider={columnIndex > 0}
|
|
100
|
+
showRowDivider
|
|
101
|
+
showBottomDivider={rowIndex === FILE_CONSTANTS.mockRowCount - 1}
|
|
102
|
+
>
|
|
103
|
+
<span
|
|
104
|
+
className='mock alt bl min_w_20'
|
|
105
|
+
style={{ width: `${50 + ((rowIndex + columnIndex) % 4) * 10}%` }}
|
|
106
|
+
>
|
|
107
|
+
....
|
|
108
|
+
</span>
|
|
109
|
+
</TableDataCell>
|
|
110
|
+
))}
|
|
111
|
+
<TableEmptyCell
|
|
112
|
+
showColumnDivider
|
|
113
|
+
showRowDivider
|
|
114
|
+
className={rowIndex === FILE_CONSTANTS.mockRowCount - 1 ? 'bd_b_1 bd_lt' : undefined}
|
|
115
|
+
/>
|
|
116
|
+
</TableDataRow>
|
|
117
|
+
))}
|
|
118
|
+
</div>
|
|
119
|
+
</TableRoot>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* App settings table content helper with a built-in loading table state
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
export const AppSettingsTableContent = (p: AppSettingsTableContentProps) => {
|
|
130
|
+
const { notReady, gridLayoutStyle, children, error } = p;
|
|
131
|
+
|
|
132
|
+
if (notReady) {
|
|
133
|
+
if (error) {
|
|
134
|
+
const errObj = getErrorMessageContent(error);
|
|
135
|
+
return (
|
|
136
|
+
<div className='h_item gap_df'>
|
|
137
|
+
<div className='bd_2 bd_lt w_80 h_80 v_center r_df ic_lg ft_md rel pattern_texture medium_bf of'>
|
|
138
|
+
<span className='rel'>
|
|
139
|
+
<Icon
|
|
140
|
+
tryColor
|
|
141
|
+
name={errObj.titleIconName}
|
|
142
|
+
backupName='alert-circle'
|
|
143
|
+
/>
|
|
144
|
+
</span>
|
|
145
|
+
</div>
|
|
146
|
+
|
|
147
|
+
<div className='lh_2'>
|
|
148
|
+
<div className='ft_medium ft_df mt_1 mb_4'>{errObj.title}</div>
|
|
149
|
+
<Markdown
|
|
150
|
+
as='p'
|
|
151
|
+
preset='article'
|
|
152
|
+
className='ft_sm cl_lt'
|
|
153
|
+
>
|
|
154
|
+
{errObj.message}
|
|
155
|
+
</Markdown>
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return <AppSettingsTableMock gridLayoutStyle={gridLayoutStyle} />;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return children;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* App settings layout
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
export const AppSettingsLayout = (
|
|
172
|
+
p: ModalHandlerProps & {
|
|
173
|
+
switchCase: string;
|
|
174
|
+
SwitchCaseComponent: ComponentType<AppSettingsSwitchCaseProps>;
|
|
175
|
+
options: AppSettingsSideNavOption[][];
|
|
176
|
+
// biome-ignore lint/suspicious/noConfusingVoidType: Ordinary void callbacks and an explicit false navigation veto are both supported.
|
|
177
|
+
onClickNavItem?: (value: string) => boolean | void; // If "false" is returned, it denies the switchCase change
|
|
178
|
+
},
|
|
179
|
+
) => {
|
|
180
|
+
const { SwitchCaseComponent, openModalPopUp, options } = p;
|
|
181
|
+
const isKeyboardLayerActive = useIsKeyboardLayerActive();
|
|
182
|
+
const closePopOver = useClosePopOver();
|
|
183
|
+
const { elementRef: scrollAreaRef, rightInset } = useElementSize<HTMLDivElement>();
|
|
184
|
+
const { elementRef: saveBarRef, height: saveBarHeight } = useElementSize<HTMLDivElement>();
|
|
185
|
+
|
|
186
|
+
const [controller, setController] = useState<ControllerState & { mountCounter: number }>({
|
|
187
|
+
switchCase: p.switchCase,
|
|
188
|
+
hasChanges: false,
|
|
189
|
+
saving: false,
|
|
190
|
+
saveCounter: 0,
|
|
191
|
+
resetCounter: 0,
|
|
192
|
+
mountCounter: 0,
|
|
193
|
+
});
|
|
194
|
+
// Keep each draft's identity private and unique even when returning to a previously visited section.
|
|
195
|
+
const { mountCounter, ...screenController } = controller;
|
|
196
|
+
|
|
197
|
+
/*
|
|
198
|
+
* Switch sections only after the caller accepts the navigation.
|
|
199
|
+
*/
|
|
200
|
+
const onClickNavItem = (value: string) => {
|
|
201
|
+
const handlerValue = p.onClickNavItem?.(value);
|
|
202
|
+
if (handlerValue !== false && value !== controller.switchCase) {
|
|
203
|
+
closePopOver();
|
|
204
|
+
setController((current) => ({
|
|
205
|
+
switchCase: value,
|
|
206
|
+
hasChanges: false,
|
|
207
|
+
saving: false,
|
|
208
|
+
saveCounter: 0,
|
|
209
|
+
resetCounter: 0,
|
|
210
|
+
mountCounter: current.mountCounter + 1,
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/*
|
|
216
|
+
* Request a save using the latest dirty and submission state.
|
|
217
|
+
*/
|
|
218
|
+
const onSave = useCallback(() => {
|
|
219
|
+
setController((current) =>
|
|
220
|
+
current.hasChanges && !current.saving ? { ...current, saveCounter: current.saveCounter + 1 } : current,
|
|
221
|
+
);
|
|
222
|
+
}, []);
|
|
223
|
+
|
|
224
|
+
/*
|
|
225
|
+
* Discard the current draft by remounting the section once saving has finished.
|
|
226
|
+
*/
|
|
227
|
+
const onReset = () => {
|
|
228
|
+
setController((current) =>
|
|
229
|
+
current.hasChanges && !current.saving
|
|
230
|
+
? { ...current, hasChanges: false, resetCounter: current.resetCounter + 1, mountCounter: current.mountCounter + 1 }
|
|
231
|
+
: current,
|
|
232
|
+
);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/*
|
|
236
|
+
* Merge partial form status updates without overwriting queued changes or another section's state.
|
|
237
|
+
*/
|
|
238
|
+
const onChangeDiff = (hasChanges?: boolean, saving?: boolean) => {
|
|
239
|
+
setController((current) => {
|
|
240
|
+
if (current.mountCounter !== mountCounter) {
|
|
241
|
+
return current;
|
|
242
|
+
}
|
|
243
|
+
const nextHasChanges = typeof hasChanges === 'boolean' ? hasChanges : current.hasChanges;
|
|
244
|
+
const nextSaving = typeof saving === 'boolean' ? saving : current.saving;
|
|
245
|
+
return current.hasChanges === nextHasChanges && current.saving === nextSaving
|
|
246
|
+
? current
|
|
247
|
+
: { ...current, hasChanges: nextHasChanges, saving: nextSaving };
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
/*
|
|
253
|
+
* Save settings only while this modal owns the keyboard.
|
|
254
|
+
*/
|
|
255
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
256
|
+
if (
|
|
257
|
+
!isKeyboardLayerActive(event) ||
|
|
258
|
+
event.defaultPrevented ||
|
|
259
|
+
event.isComposing ||
|
|
260
|
+
!(event.metaKey || event.ctrlKey) ||
|
|
261
|
+
event.key.toLowerCase() !== 's'
|
|
262
|
+
)
|
|
263
|
+
return;
|
|
264
|
+
event.preventDefault();
|
|
265
|
+
if (!event.repeat) {
|
|
266
|
+
onSave();
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
window.addEventListener('keydown', onKeyDown);
|
|
270
|
+
return () => window.removeEventListener('keydown', onKeyDown);
|
|
271
|
+
}, [isKeyboardLayerActive, onSave]);
|
|
272
|
+
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
// Listen to scroll events inside scrollAreaRef
|
|
275
|
+
|
|
276
|
+
const scrollArea = scrollAreaRef.current;
|
|
277
|
+
if (!scrollArea) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/*
|
|
282
|
+
* Close the open popover without treating the scroll event as a dismissal filter.
|
|
283
|
+
*/
|
|
284
|
+
const onScroll = () => closePopOver();
|
|
285
|
+
scrollArea.addEventListener('scroll', onScroll, { passive: true });
|
|
286
|
+
|
|
287
|
+
return () => {
|
|
288
|
+
scrollArea.removeEventListener('scroll', onScroll);
|
|
289
|
+
};
|
|
290
|
+
}, [closePopOver]);
|
|
291
|
+
|
|
292
|
+
return (
|
|
293
|
+
<div className='w_f h_top f rel of'>
|
|
294
|
+
<AppSettingsSideNav
|
|
295
|
+
selectedValue={controller.switchCase}
|
|
296
|
+
options={options}
|
|
297
|
+
onClickItem={onClickNavItem}
|
|
298
|
+
/>
|
|
299
|
+
|
|
300
|
+
<div className='f h_f min_w_0 rel'>
|
|
301
|
+
<AppSettingsContentContainer
|
|
302
|
+
ref={scrollAreaRef}
|
|
303
|
+
addFooterPadding
|
|
304
|
+
addYOverflow
|
|
305
|
+
fadeBottom={controller.hasChanges}
|
|
306
|
+
bottomFadeOffset={saveBarHeight}
|
|
307
|
+
rightInset={rightInset}
|
|
308
|
+
>
|
|
309
|
+
<div className='f py_md px_50'>
|
|
310
|
+
<SwitchCaseComponent
|
|
311
|
+
key={mountCounter}
|
|
312
|
+
onSave={onSave}
|
|
313
|
+
onChangeDiff={onChangeDiff}
|
|
314
|
+
openModalPopUp={openModalPopUp}
|
|
315
|
+
{...screenController}
|
|
316
|
+
/>
|
|
317
|
+
</div>
|
|
318
|
+
</AppSettingsContentContainer>
|
|
319
|
+
|
|
320
|
+
<AppSettingsFloatingSaveButton
|
|
321
|
+
ref={saveBarRef}
|
|
322
|
+
rightInset={rightInset}
|
|
323
|
+
hasChanges={controller.hasChanges}
|
|
324
|
+
saving={controller.saving}
|
|
325
|
+
onSave={onSave}
|
|
326
|
+
onReset={onReset}
|
|
327
|
+
/>
|
|
328
|
+
</div>
|
|
329
|
+
</div>
|
|
330
|
+
);
|
|
331
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useCurrentAccount } from '@jsb188/react/states';
|
|
2
|
+
import {
|
|
3
|
+
getEditableTableColumnWidthStorageKey,
|
|
4
|
+
getStoredEditableTableColumnWidths,
|
|
5
|
+
saveEditableTableColumnWidths,
|
|
6
|
+
} from '@jsb188/react-web/modules/TableList.helpers';
|
|
7
|
+
import type { EditableTableColumnWidthStorageConfig } from '@jsb188/react-web/modules/TableList';
|
|
8
|
+
import { getTableColumnPixelWidth } from '@jsb188/react-web/modules/table/layout';
|
|
9
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
10
|
+
import { AppSettingsTableUI, type AppSettingsTableUIProps } from '../ui/AppSettingsTableUI';
|
|
11
|
+
|
|
12
|
+
export type AppSettingsTableProps = AppSettingsTableUIProps & {
|
|
13
|
+
columnWidthStorage?: EditableTableColumnWidthStorageConfig;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* Preserve account-scoped column widths while presenting a nonvirtualized settings table.
|
|
18
|
+
*/
|
|
19
|
+
export const AppSettingsTable = (p: AppSettingsTableProps) => {
|
|
20
|
+
const { columnWidthStorage, columnWidths, onColumnResizeCommit, ...tableProps } = p;
|
|
21
|
+
const { account } = useCurrentAccount();
|
|
22
|
+
const storageKey = getEditableTableColumnWidthStorageKey(account?.id, columnWidthStorage);
|
|
23
|
+
const [stored, setStored] = useState(() => ({ storageKey, widths: getStoredEditableTableColumnWidths(storageKey) }));
|
|
24
|
+
const columns = p.tableDesign.columns;
|
|
25
|
+
|
|
26
|
+
// Reset before rendering the child table so account/table switches never commit another scope's widths or defaults.
|
|
27
|
+
if (stored.storageKey !== storageKey) {
|
|
28
|
+
setStored({ storageKey, widths: getStoredEditableTableColumnWidths(storageKey) });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const savedColumnWidths = useMemo(() => {
|
|
32
|
+
if (stored.storageKey !== storageKey) return {};
|
|
33
|
+
|
|
34
|
+
return columns.reduce<Record<string, number>>((widths, column, index) => {
|
|
35
|
+
// Legacy widths use source indexes; flexible tracks must retain their natural sizing.
|
|
36
|
+
if (getTableColumnPixelWidth(column.width) !== null && Number.isFinite(stored.widths[index])) {
|
|
37
|
+
widths[column.key] = stored.widths[index];
|
|
38
|
+
}
|
|
39
|
+
return widths;
|
|
40
|
+
}, {});
|
|
41
|
+
}, [columns, storageKey, stored]);
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Persist keyed VZTable widths in the existing source-index storage format.
|
|
45
|
+
*/
|
|
46
|
+
const commitColumnWidths = useCallback(
|
|
47
|
+
(widths: Record<string, number>) => {
|
|
48
|
+
const indexedWidths = columns.reduce<Record<number, number>>((result, column, index) => {
|
|
49
|
+
if (getTableColumnPixelWidth(column.width) !== null && Number.isFinite(widths[column.key])) {
|
|
50
|
+
result[index] = widths[column.key];
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}, {});
|
|
54
|
+
setStored({ storageKey, widths: indexedWidths });
|
|
55
|
+
saveEditableTableColumnWidths(storageKey, indexedWidths);
|
|
56
|
+
onColumnResizeCommit?.(widths);
|
|
57
|
+
},
|
|
58
|
+
[columns, onColumnResizeCommit, storageKey],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// Discard any in-progress resize when the account or table storage scope changes.
|
|
62
|
+
return (
|
|
63
|
+
<AppSettingsTableUI
|
|
64
|
+
key={storageKey}
|
|
65
|
+
{...tableProps}
|
|
66
|
+
columnWidths={columnWidths ?? savedColumnWidths}
|
|
67
|
+
onColumnResizeCommit={commitColumnWidths}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
};
|