@jsb188/app-settings-web 1.1.10 → 1.1.12
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/package.json +24 -20
- 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/tsconfig.json +13 -0
- package/src/AppSettingsLayout.tsx +0 -211
- package/src/ChangeCredentialsLayout.tsx +0 -289
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
+
import { useConfirmPassword } from '@jsb188/graphql/hooks/use-auth-mtn';
|
|
3
|
+
import { FormOptions, Input, SMSCodeInput } from '@jsb188/form/modules/Form';
|
|
4
|
+
import { AlertPopUp, ModalErrorMessage } from '@jsb188/react-web/ui/ModalUI';
|
|
5
|
+
import type { ModalPopUpComponentProps } from '@jsb188/react/states';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
|
|
8
|
+
const FILE_CONSTANTS = {
|
|
9
|
+
smsCodeLength: 5,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export interface ConfirmPasswordProps extends ModalPopUpComponentProps {
|
|
13
|
+
confirmPasswordTitle?: string;
|
|
14
|
+
confirmPasswordMessage?: string;
|
|
15
|
+
onPasswordVerified?: (password: string) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ChangeCredentialsFinishedProps extends ModalPopUpComponentProps {
|
|
19
|
+
finishedIconName?: string;
|
|
20
|
+
finishedTitle?: string;
|
|
21
|
+
finishedMessage?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ChangeCredentialsProps extends ConfirmPasswordProps {
|
|
25
|
+
iconName: string;
|
|
26
|
+
skipPassword?: boolean;
|
|
27
|
+
title: string;
|
|
28
|
+
message: string;
|
|
29
|
+
|
|
30
|
+
finishedIconName?: string;
|
|
31
|
+
finishedTitle?: string;
|
|
32
|
+
finishedMessage?: string;
|
|
33
|
+
|
|
34
|
+
verifyIconName?: string;
|
|
35
|
+
verifyTitle?: string;
|
|
36
|
+
verifyMessage?: string;
|
|
37
|
+
|
|
38
|
+
confirmText?: string;
|
|
39
|
+
confirmSMSCodeText?: string;
|
|
40
|
+
status: 'WAITING_FOR_INPUT' | 'WAITING_FOR_VERIFICATION' | 'WAITING_FOR_SMS_CODE' | 'FINISHED';
|
|
41
|
+
onSubmit: (values: string[], confirmedPassword?: string) => void;
|
|
42
|
+
onSubmitSMSCode?: (smsCode: string, values: string[], confirmedPassword?: string) => void;
|
|
43
|
+
|
|
44
|
+
loading?: boolean;
|
|
45
|
+
error: any;
|
|
46
|
+
resetErrors: () => void;
|
|
47
|
+
inputs: (
|
|
48
|
+
| {
|
|
49
|
+
__type: 'TEXT_INPUT';
|
|
50
|
+
type?: 'text' | 'password';
|
|
51
|
+
label: string;
|
|
52
|
+
placeholder?: string;
|
|
53
|
+
}
|
|
54
|
+
| {
|
|
55
|
+
__type: 'OPTIONS_LIST';
|
|
56
|
+
label: string;
|
|
57
|
+
defaultValue?: string;
|
|
58
|
+
options: {
|
|
59
|
+
text: string;
|
|
60
|
+
value: string;
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
}[];
|
|
63
|
+
}
|
|
64
|
+
)[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Render credential errors consistently across password, input, and SMS steps.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
const CredentialsErrorMessage = (p: Pick<ChangeCredentialsProps, 'error' | 'resetErrors'>) =>
|
|
72
|
+
p.error ? (
|
|
73
|
+
<div className='px_md mt_md -mb_df'>
|
|
74
|
+
<ModalErrorMessage
|
|
75
|
+
error={p.error}
|
|
76
|
+
resetErrors={p.resetErrors}
|
|
77
|
+
/>
|
|
78
|
+
</div>
|
|
79
|
+
) : null;
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
* Confirm the current password before changing sensitive account settings.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
const ConfirmPasswordForm = (p: ConfirmPasswordProps) => {
|
|
86
|
+
const { onCloseModal, confirmPasswordTitle, confirmPasswordMessage, onPasswordVerified } = p;
|
|
87
|
+
const [password, setPassword] = useState('');
|
|
88
|
+
|
|
89
|
+
const { confirmPassword, error, resetErrors, saving } = useConfirmPassword({
|
|
90
|
+
onCompleted: (data: { confirmPassword?: boolean }, _error, variables) => {
|
|
91
|
+
if (data.confirmPassword && typeof variables?.password === 'string') {
|
|
92
|
+
onPasswordVerified?.(variables.password);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
onError: () => {
|
|
96
|
+
setPassword('');
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* Share the same submission guard between the button and keyboard shortcut.
|
|
102
|
+
*/
|
|
103
|
+
const onConfirmPassword = () => {
|
|
104
|
+
if (!password || saving) return;
|
|
105
|
+
confirmPassword({
|
|
106
|
+
variables: {
|
|
107
|
+
password,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/*
|
|
113
|
+
* Ignore repeated or composing Enter and prevent a second native submission.
|
|
114
|
+
*/
|
|
115
|
+
const onPressEnter = (e: React.KeyboardEvent) => {
|
|
116
|
+
if (e.key !== 'Enter' || e.defaultPrevented || e.repeat || e.nativeEvent.isComposing) return;
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
onConfirmPassword();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<AlertPopUp
|
|
123
|
+
doNotExitOnConfirm
|
|
124
|
+
loading={saving}
|
|
125
|
+
iconName='password-lock-2'
|
|
126
|
+
confirmText={i18n.t('c.authenticate')}
|
|
127
|
+
cancelText={i18n.t('c.cancel')}
|
|
128
|
+
onConfirm={onConfirmPassword}
|
|
129
|
+
onCloseModal={onCloseModal}
|
|
130
|
+
disabledConfirm={!password || saving}
|
|
131
|
+
title={confirmPasswordTitle ?? i18n.t('account.enter_password')}
|
|
132
|
+
message={confirmPasswordMessage ?? i18n.t('account.enter_password_msg')}
|
|
133
|
+
>
|
|
134
|
+
<CredentialsErrorMessage
|
|
135
|
+
error={error}
|
|
136
|
+
resetErrors={resetErrors}
|
|
137
|
+
/>
|
|
138
|
+
|
|
139
|
+
<div className='mt_df mx_md'>
|
|
140
|
+
<Input
|
|
141
|
+
type='password'
|
|
142
|
+
autoComplete='current-password'
|
|
143
|
+
disabled={saving}
|
|
144
|
+
label={i18n.t('account.password')}
|
|
145
|
+
placeholder='••••'
|
|
146
|
+
value={password}
|
|
147
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
148
|
+
onKeyDown={onPressEnter}
|
|
149
|
+
autoFocus
|
|
150
|
+
/>
|
|
151
|
+
</div>
|
|
152
|
+
</AlertPopUp>
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Change account settings that require confirmations (such as credentials)
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
export const ChangeCredentialsLayout = (p: ChangeCredentialsProps) => {
|
|
161
|
+
const {
|
|
162
|
+
iconName,
|
|
163
|
+
skipPassword,
|
|
164
|
+
title,
|
|
165
|
+
message,
|
|
166
|
+
confirmText,
|
|
167
|
+
confirmSMSCodeText,
|
|
168
|
+
loading,
|
|
169
|
+
error,
|
|
170
|
+
resetErrors,
|
|
171
|
+
inputs,
|
|
172
|
+
onSubmit,
|
|
173
|
+
onSubmitSMSCode,
|
|
174
|
+
status,
|
|
175
|
+
finishedIconName,
|
|
176
|
+
finishedTitle,
|
|
177
|
+
finishedMessage,
|
|
178
|
+
verifyIconName,
|
|
179
|
+
verifyTitle,
|
|
180
|
+
verifyMessage,
|
|
181
|
+
onPasswordVerified,
|
|
182
|
+
...rest
|
|
183
|
+
} = p;
|
|
184
|
+
const { onCloseModal } = rest;
|
|
185
|
+
const [confirmedPassword, setConfirmedPassword] = useState<string | null>(null);
|
|
186
|
+
const [smsCode, setSMSCode] = useState('');
|
|
187
|
+
const [values, setValues] = useState(() => inputs.map((input) => (input.__type === 'OPTIONS_LIST' ? input.defaultValue || '' : '')));
|
|
188
|
+
const hasValidInputs = inputs.length > 0 && inputs.every((_input, index) => !!values[index]?.trim());
|
|
189
|
+
const hasSMSCode = smsCode.length === FILE_CONSTANTS.smsCodeLength;
|
|
190
|
+
|
|
191
|
+
/*
|
|
192
|
+
* Retain the verified password and notify the caller when authentication completes.
|
|
193
|
+
*/
|
|
194
|
+
const onVerified = (password: string) => {
|
|
195
|
+
setConfirmedPassword(password);
|
|
196
|
+
onPasswordVerified?.(password);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/*
|
|
200
|
+
* Preserve other field updates when React batches changes to multiple inputs.
|
|
201
|
+
*/
|
|
202
|
+
const onChangeValue = (index: number, value: string) => {
|
|
203
|
+
setValues((current) => {
|
|
204
|
+
const nextValues = [...current];
|
|
205
|
+
nextValues[index] = value;
|
|
206
|
+
return nextValues;
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/*
|
|
211
|
+
* Submit only complete credential values while no request is pending.
|
|
212
|
+
*/
|
|
213
|
+
const onConfirm = () => {
|
|
214
|
+
if (!hasValidInputs || loading) return;
|
|
215
|
+
onSubmit(values, confirmedPassword ?? '');
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/*
|
|
219
|
+
* Validate both automatic SMS submissions and explicit confirmation identically.
|
|
220
|
+
*/
|
|
221
|
+
const onConfirmSMSCode = (code: string) => {
|
|
222
|
+
const normalizedCode = code.trim();
|
|
223
|
+
if (loading || normalizedCode.length !== FILE_CONSTANTS.smsCodeLength || !/^\d+$/.test(normalizedCode)) return;
|
|
224
|
+
onSubmitSMSCode?.(normalizedCode, values, confirmedPassword ?? '');
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/*
|
|
228
|
+
* Use the button's validation and loading guards for keyboard submission too.
|
|
229
|
+
*/
|
|
230
|
+
const onPressEnter = (e: React.KeyboardEvent) => {
|
|
231
|
+
if (e.key !== 'Enter' || e.defaultPrevented || e.repeat || e.nativeEvent.isComposing) return;
|
|
232
|
+
e.preventDefault();
|
|
233
|
+
onConfirm();
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
switch (status) {
|
|
237
|
+
case 'FINISHED':
|
|
238
|
+
return (
|
|
239
|
+
<AlertPopUp
|
|
240
|
+
onCloseModal={onCloseModal}
|
|
241
|
+
iconName={finishedIconName || 'circle-check'}
|
|
242
|
+
title={finishedTitle || i18n.t('c.success_')}
|
|
243
|
+
message={finishedMessage || i18n.t('c.your_request_is_completed_msg')}
|
|
244
|
+
/>
|
|
245
|
+
);
|
|
246
|
+
case 'WAITING_FOR_VERIFICATION':
|
|
247
|
+
return (
|
|
248
|
+
<AlertPopUp
|
|
249
|
+
onCloseModal={onCloseModal}
|
|
250
|
+
iconName={verifyIconName || iconName}
|
|
251
|
+
title={verifyTitle || i18n.t('c.please_verify')}
|
|
252
|
+
message={verifyMessage || i18n.t('c.request_will_complete_once_verified_msg')}
|
|
253
|
+
/>
|
|
254
|
+
);
|
|
255
|
+
case 'WAITING_FOR_SMS_CODE':
|
|
256
|
+
return (
|
|
257
|
+
<AlertPopUp
|
|
258
|
+
iconName={verifyIconName || iconName}
|
|
259
|
+
loading={loading}
|
|
260
|
+
onCloseModal={onCloseModal}
|
|
261
|
+
doNotExitOnConfirm
|
|
262
|
+
onConfirm={() => onConfirmSMSCode(smsCode)}
|
|
263
|
+
title={verifyTitle || i18n.t('c.please_verify')}
|
|
264
|
+
message={verifyMessage || i18n.t('c.request_will_complete_once_verified_msg')}
|
|
265
|
+
confirmText={confirmSMSCodeText || i18n.t('c.ok')}
|
|
266
|
+
cancelText={i18n.t('c.cancel')}
|
|
267
|
+
disabledConfirm={!hasSMSCode || loading || !onSubmitSMSCode}
|
|
268
|
+
>
|
|
269
|
+
<CredentialsErrorMessage
|
|
270
|
+
error={error}
|
|
271
|
+
resetErrors={resetErrors}
|
|
272
|
+
/>
|
|
273
|
+
|
|
274
|
+
<div className='mt_md mx_md'>
|
|
275
|
+
<SMSCodeInput
|
|
276
|
+
codeLength={FILE_CONSTANTS.smsCodeLength}
|
|
277
|
+
saving={loading}
|
|
278
|
+
error={error}
|
|
279
|
+
onChangeCode={setSMSCode}
|
|
280
|
+
onSubmit={onConfirmSMSCode}
|
|
281
|
+
/>
|
|
282
|
+
</div>
|
|
283
|
+
</AlertPopUp>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (confirmedPassword === null && !skipPassword) {
|
|
288
|
+
return (
|
|
289
|
+
<ConfirmPasswordForm
|
|
290
|
+
{...rest}
|
|
291
|
+
onPasswordVerified={onVerified}
|
|
292
|
+
/>
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return (
|
|
297
|
+
<AlertPopUp
|
|
298
|
+
iconName={iconName}
|
|
299
|
+
doNotExitOnConfirm
|
|
300
|
+
loading={loading}
|
|
301
|
+
onCloseModal={onCloseModal}
|
|
302
|
+
onConfirm={onConfirm}
|
|
303
|
+
title={title}
|
|
304
|
+
message={message}
|
|
305
|
+
confirmText={confirmText}
|
|
306
|
+
cancelText={i18n.t('c.cancel')}
|
|
307
|
+
disabledConfirm={!hasValidInputs || loading}
|
|
308
|
+
>
|
|
309
|
+
<CredentialsErrorMessage
|
|
310
|
+
error={error}
|
|
311
|
+
resetErrors={resetErrors}
|
|
312
|
+
/>
|
|
313
|
+
|
|
314
|
+
<div className='mt_df mx_md'>
|
|
315
|
+
{inputs.map((input, index) => {
|
|
316
|
+
if (input.__type === 'OPTIONS_LIST') {
|
|
317
|
+
return (
|
|
318
|
+
<FormOptions
|
|
319
|
+
key={index}
|
|
320
|
+
name={input.label}
|
|
321
|
+
label={input.label}
|
|
322
|
+
value={values[index]}
|
|
323
|
+
options={input.options}
|
|
324
|
+
disabled={loading}
|
|
325
|
+
onChange={(_e, _name, value) => onChangeValue(index, value === null ? '' : String(value))}
|
|
326
|
+
/>
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return (
|
|
331
|
+
<Input
|
|
332
|
+
key={index}
|
|
333
|
+
type={input.type || 'text'}
|
|
334
|
+
label={input.label}
|
|
335
|
+
placeholder={input.placeholder}
|
|
336
|
+
disabled={loading}
|
|
337
|
+
value={values[index]}
|
|
338
|
+
onChange={(e) => onChangeValue(index, e.target.value)}
|
|
339
|
+
onKeyDown={onPressEnter}
|
|
340
|
+
autoFocus={!index}
|
|
341
|
+
/>
|
|
342
|
+
);
|
|
343
|
+
})}
|
|
344
|
+
</div>
|
|
345
|
+
</AlertPopUp>
|
|
346
|
+
);
|
|
347
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { HorizontalScrollIndicators } from '@jsb188/react-web/modules/Scroll';
|
|
3
|
+
import { TABLE_ROW_HEIGHT } from '@jsb188/react-web/modules/table/layout';
|
|
4
|
+
import { VZTable } from '@jsb188/react-web/table/Table';
|
|
5
|
+
import { EndOfTableFooter, type TableDesign } from '@jsb188/react-web/ui/TableUI';
|
|
6
|
+
import { type ComponentProps, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
|
+
import { createPortal } from 'react-dom';
|
|
8
|
+
|
|
9
|
+
export type AppSettingsTableUIProps = Omit<
|
|
10
|
+
ComponentProps<typeof VZTable>,
|
|
11
|
+
| 'fillAvailableRows'
|
|
12
|
+
| 'hasParentScrollArea'
|
|
13
|
+
| 'listDataOffset'
|
|
14
|
+
| 'listEndIndex'
|
|
15
|
+
| 'listStartIndex'
|
|
16
|
+
| 'tableDesign'
|
|
17
|
+
| 'virtualizedBody'
|
|
18
|
+
> & {
|
|
19
|
+
className?: string;
|
|
20
|
+
endOfListMessage?: string;
|
|
21
|
+
minRowsToShow?: number;
|
|
22
|
+
tableDesign: TableDesign;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* Render an edge-to-edge settings table within the layout's existing scroll area.
|
|
27
|
+
*/
|
|
28
|
+
export const AppSettingsTableUI = (p: AppSettingsTableUIProps) => {
|
|
29
|
+
const { className, endOfListMessage, footerNode, headers, minRowsToShow, tableDesign, ...tableProps } = p;
|
|
30
|
+
const loadedDataSize = p.listData?.length;
|
|
31
|
+
const [visibleRowThreshold, setVisibleRowThreshold] = useState(20);
|
|
32
|
+
const tableAreaRef = useRef<HTMLDivElement>(null);
|
|
33
|
+
const scrollAreaRef = useRef<HTMLElement>(null);
|
|
34
|
+
const [indicatorFrame, setIndicatorFrame] = useState<HTMLElement | null>(null);
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* Bind the portal and scroll owner before indicator effects subscribe to its events.
|
|
38
|
+
*/
|
|
39
|
+
const setTableAreaRef = useCallback((element: HTMLDivElement | null) => {
|
|
40
|
+
tableAreaRef.current = element;
|
|
41
|
+
const scrollArea = element?.closest<HTMLElement>('.app_scr') || null;
|
|
42
|
+
scrollAreaRef.current = scrollArea;
|
|
43
|
+
setIndicatorFrame(scrollArea?.parentElement || null);
|
|
44
|
+
}, []);
|
|
45
|
+
/*
|
|
46
|
+
* Estimate the rows fitting below the title and table header, with two extra rows and a minimum of twenty.
|
|
47
|
+
*/
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const tableArea = tableAreaRef.current;
|
|
50
|
+
const scrollArea = scrollAreaRef.current;
|
|
51
|
+
if (minRowsToShow !== undefined || !tableArea || !scrollArea) return;
|
|
52
|
+
|
|
53
|
+
/* Recalculate from unscrolled coordinates so scrolling cannot change the footer threshold. */
|
|
54
|
+
const measureVisibleRows = () => {
|
|
55
|
+
const tableTop =
|
|
56
|
+
tableArea.getBoundingClientRect().top - scrollArea.getBoundingClientRect().top - scrollArea.clientTop + scrollArea.scrollTop;
|
|
57
|
+
const headerHeight = tableArea.querySelector('.thead')?.getBoundingClientRect().height ?? TABLE_ROW_HEIGHT;
|
|
58
|
+
const availableHeight = Math.max(0, scrollArea.clientHeight - tableTop - headerHeight);
|
|
59
|
+
setVisibleRowThreshold(Math.max(20, Math.floor(availableHeight / TABLE_ROW_HEIGHT) + 2));
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
measureVisibleRows();
|
|
63
|
+
if (!globalThis.ResizeObserver) return;
|
|
64
|
+
const observer = new ResizeObserver(measureVisibleRows);
|
|
65
|
+
observer.observe(tableArea);
|
|
66
|
+
observer.observe(scrollArea);
|
|
67
|
+
return () => observer.disconnect();
|
|
68
|
+
}, [minRowsToShow, indicatorFrame]);
|
|
69
|
+
|
|
70
|
+
const renderHeaders = useMemo(
|
|
71
|
+
() => (headers === undefined ? tableDesign.columns.map((column) => column.header || {}) : headers),
|
|
72
|
+
[headers, tableDesign],
|
|
73
|
+
);
|
|
74
|
+
const renderDesign = useMemo(
|
|
75
|
+
() => ({ ...tableDesign, dividers: { rows: true, columns: true, ...tableDesign.dividers } }),
|
|
76
|
+
[tableDesign],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div className={cn('-mx_50 min_w_0 ft_sm', className)}>
|
|
81
|
+
<div
|
|
82
|
+
ref={setTableAreaRef}
|
|
83
|
+
className="pl_40 min_w_0 rel"
|
|
84
|
+
>
|
|
85
|
+
{/* Keep the gutter border scoped to the header and rows, above the footer. */}
|
|
86
|
+
<div
|
|
87
|
+
aria-hidden
|
|
88
|
+
className="abs_l w_40 bd_r_1 bd_lt noclick"
|
|
89
|
+
/>
|
|
90
|
+
<VZTable
|
|
91
|
+
borderStyle="BORDER"
|
|
92
|
+
resizableColumns
|
|
93
|
+
rowMenuZClassName="z8"
|
|
94
|
+
showBottomDivider
|
|
95
|
+
{...tableProps}
|
|
96
|
+
headers={renderHeaders}
|
|
97
|
+
tableDesign={renderDesign}
|
|
98
|
+
hasParentScrollArea
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
101
|
+
{indicatorFrame &&
|
|
102
|
+
createPortal(
|
|
103
|
+
<HorizontalScrollIndicators
|
|
104
|
+
scrollRef={scrollAreaRef}
|
|
105
|
+
contentRef={tableAreaRef}
|
|
106
|
+
/>,
|
|
107
|
+
indicatorFrame,
|
|
108
|
+
)}
|
|
109
|
+
{(footerNode || loadedDataSize !== undefined) && (
|
|
110
|
+
<div className="pl_40">
|
|
111
|
+
{footerNode}
|
|
112
|
+
{loadedDataSize !== undefined && (
|
|
113
|
+
<EndOfTableFooter
|
|
114
|
+
minRowsToShow={minRowsToShow ?? visibleRowThreshold}
|
|
115
|
+
endOfListMessage={endOfListMessage}
|
|
116
|
+
loadedDataSize={loadedDataSize}
|
|
117
|
+
maxFetchLimit={Infinity}
|
|
118
|
+
/>
|
|
119
|
+
)}
|
|
120
|
+
</div>
|
|
121
|
+
)}
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
3
|
+
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
4
|
+
import type { ReactDivElement } from '@jsb188/react-web/types/dom.d';
|
|
5
|
+
import { ActivityDots, BigLoading } from '@jsb188/react-web/ui/Loading';
|
|
6
|
+
import { ShortcutKey } from '@jsb188/react-web/ui/OtherUI';
|
|
7
|
+
import { forwardRef, type CSSProperties } from 'react';
|
|
8
|
+
|
|
9
|
+
interface AppSettingsNavSubtitleProps {
|
|
10
|
+
__type: 'LIST_SUBTITLE';
|
|
11
|
+
text: string;
|
|
12
|
+
selected?: unknown;
|
|
13
|
+
value?: unknown;
|
|
14
|
+
onClick?: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface AppSettingsNavItemProps {
|
|
18
|
+
__type: 'LIST_ITEM';
|
|
19
|
+
value: string;
|
|
20
|
+
iconName: string;
|
|
21
|
+
text: string;
|
|
22
|
+
rightIconName?: string;
|
|
23
|
+
selected?: boolean;
|
|
24
|
+
onClick?: (value: string) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type AppSettingsSideNavOption = AppSettingsNavSubtitleProps | AppSettingsNavItemProps;
|
|
28
|
+
|
|
29
|
+
interface AppSettingsFloatingSaveButtonProps {
|
|
30
|
+
hasChanges: boolean;
|
|
31
|
+
rightInset: number;
|
|
32
|
+
saving: boolean;
|
|
33
|
+
onSave: () => void;
|
|
34
|
+
onReset: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface AppSettingsContentContainerProps extends ReactDivElement {
|
|
38
|
+
notReady?: boolean;
|
|
39
|
+
addFooterPadding?: boolean;
|
|
40
|
+
addYOverflow?: boolean;
|
|
41
|
+
fadeBottom?: boolean;
|
|
42
|
+
bottomFadeOffset?: number;
|
|
43
|
+
rightInset?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Render the app settings content container.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
export const AppSettingsContentContainer = forwardRef<HTMLDivElement, AppSettingsContentContainerProps>((p, ref) => {
|
|
51
|
+
const {
|
|
52
|
+
notReady,
|
|
53
|
+
addFooterPadding,
|
|
54
|
+
addYOverflow,
|
|
55
|
+
fadeBottom,
|
|
56
|
+
bottomFadeOffset = 0,
|
|
57
|
+
rightInset = 0,
|
|
58
|
+
className,
|
|
59
|
+
style,
|
|
60
|
+
children,
|
|
61
|
+
...other
|
|
62
|
+
} = p;
|
|
63
|
+
return (
|
|
64
|
+
<div
|
|
65
|
+
ref={ref}
|
|
66
|
+
className={cn(
|
|
67
|
+
'f h_f min_w_0 r_df mask_fade_bottom_200',
|
|
68
|
+
addYOverflow && 'app_scr auto_x',
|
|
69
|
+
addFooterPadding && 'pb_lg',
|
|
70
|
+
className,
|
|
71
|
+
notReady && 'v_center',
|
|
72
|
+
)}
|
|
73
|
+
style={
|
|
74
|
+
{
|
|
75
|
+
...style,
|
|
76
|
+
'--mask-scrollbar-inset': `${rightInset}px`,
|
|
77
|
+
'--mask-bottom-offset': `${bottomFadeOffset}px`,
|
|
78
|
+
'--mask-fade-progress': fadeBottom ? 1 : 0,
|
|
79
|
+
} as CSSProperties
|
|
80
|
+
}
|
|
81
|
+
{...other}
|
|
82
|
+
>
|
|
83
|
+
{notReady ? <BigLoading color='alt' /> : children}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
AppSettingsContentContainer.displayName = 'AppSettingsContentContainer';
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Render one app settings navigation item.
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
const AppSettingsSideNavItem = (p: AppSettingsSideNavOption) => {
|
|
95
|
+
if (p.__type === 'LIST_SUBTITLE') {
|
|
96
|
+
return (
|
|
97
|
+
<div className='px_xs py_4 ml_2 mb_2 title'>
|
|
98
|
+
<span className='cl_lt ft_sm ft_medium'>{p.text}</span>
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const { value, text, selected, onClick, iconName, rightIconName } = p;
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<button
|
|
107
|
+
type='button'
|
|
108
|
+
aria-current={selected ? 'page' : undefined}
|
|
109
|
+
disabled={!onClick}
|
|
110
|
+
className={cn('r_sm h_item mb_2 w_f link px_xs py_4', selected ? '_bg shadow_line_soft disabled cl_df' : 'bg_hv cl_df')}
|
|
111
|
+
onClick={onClick && !selected ? () => onClick(value) : undefined}
|
|
112
|
+
>
|
|
113
|
+
{iconName && (
|
|
114
|
+
<span className='w_25 h_center shift_left mr_4 ft_sm'>
|
|
115
|
+
<Icon name={iconName} />
|
|
116
|
+
</span>
|
|
117
|
+
)}
|
|
118
|
+
|
|
119
|
+
<span className='ellip pb_1 shift_down lh_1'>{text}</span>
|
|
120
|
+
|
|
121
|
+
{rightIconName && (
|
|
122
|
+
<span className='ic_sm ml_xs'>
|
|
123
|
+
<Icon name={rightIconName} />
|
|
124
|
+
</span>
|
|
125
|
+
)}
|
|
126
|
+
</button>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Render app settings side navigation.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
export const AppSettingsSideNav = (p: {
|
|
135
|
+
selectedValue: string;
|
|
136
|
+
options: AppSettingsSideNavOption[][];
|
|
137
|
+
onClickItem: (value: string) => void;
|
|
138
|
+
}) => {
|
|
139
|
+
const { selectedValue, options, onClickItem } = p;
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<nav className='f_stretch w_270 py_lg bg_fade y_scr always'>
|
|
143
|
+
{options.map((list, i) => (
|
|
144
|
+
<div
|
|
145
|
+
className='px_df py_10'
|
|
146
|
+
key={i}
|
|
147
|
+
>
|
|
148
|
+
{list.map((item) => (
|
|
149
|
+
<AppSettingsSideNavItem
|
|
150
|
+
key={item.__type === 'LIST_ITEM' ? item.value : `subtitle_${item.text}`}
|
|
151
|
+
{...item}
|
|
152
|
+
selected={selectedValue === item.value}
|
|
153
|
+
onClick={onClickItem}
|
|
154
|
+
/>
|
|
155
|
+
))}
|
|
156
|
+
</div>
|
|
157
|
+
))}
|
|
158
|
+
</nav>
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Render app settings save and reset controls.
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
export const AppSettingsFloatingSaveButton = forwardRef<HTMLDivElement, AppSettingsFloatingSaveButtonProps>((p, ref) => {
|
|
167
|
+
const { hasChanges, rightInset, saving, onSave, onReset } = p;
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<div
|
|
171
|
+
ref={ref}
|
|
172
|
+
aria-hidden={!hasChanges}
|
|
173
|
+
inert={!hasChanges}
|
|
174
|
+
style={{ right: rightInset }}
|
|
175
|
+
className={cn(
|
|
176
|
+
'abs_b mx_df p_12 bg_primary_fd_solid h_spread rt_df z1 anim_move_up_center target anim_inner spd_1',
|
|
177
|
+
hasChanges ? 'visible shadow_line_alt' : 'noclick',
|
|
178
|
+
)}
|
|
179
|
+
>
|
|
180
|
+
<div className='h_item px_xs'>{i18n.t('c.unsaved_changes_msg')}</div>
|
|
181
|
+
|
|
182
|
+
<div className='h_right'>
|
|
183
|
+
<div className='pill pill_sm h_center mr_xs'>
|
|
184
|
+
<button
|
|
185
|
+
type='button'
|
|
186
|
+
className='text'
|
|
187
|
+
disabled={!hasChanges || saving}
|
|
188
|
+
onClick={onReset}
|
|
189
|
+
>
|
|
190
|
+
<span className='h_right'>
|
|
191
|
+
<Icon name='arrow-back-up' />
|
|
192
|
+
<span className='ml_xs'>{i18n.t('c.undo_changes')}</span>
|
|
193
|
+
</span>
|
|
194
|
+
</button>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<button
|
|
198
|
+
type='button'
|
|
199
|
+
className={cn('pill pill_df r bg_primary', saving && 'loading')}
|
|
200
|
+
aria-busy={saving || undefined}
|
|
201
|
+
disabled={!hasChanges || saving}
|
|
202
|
+
onClick={onSave}
|
|
203
|
+
>
|
|
204
|
+
{saving && (
|
|
205
|
+
<div className='abs_full v_center'>
|
|
206
|
+
<ActivityDots />
|
|
207
|
+
</div>
|
|
208
|
+
)}
|
|
209
|
+
<span>
|
|
210
|
+
{/* Need the extra <span /> to use the :last-child rule in <ShortcutKey /> */}
|
|
211
|
+
{i18n.t('c.save_changes')}
|
|
212
|
+
</span>
|
|
213
|
+
<ShortcutKey
|
|
214
|
+
letter='S'
|
|
215
|
+
className='bg_darker_3 shift_up ml_7'
|
|
216
|
+
/>
|
|
217
|
+
</button>
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
AppSettingsFloatingSaveButton.displayName = 'AppSettingsFloatingSaveButton';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"allowImportingTsExtensions": true,
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*"]
|
|
13
|
+
}
|