@jsb188/react 1.1.7 → 1.1.10
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 +4 -4
- package/states/apiData.ts +3 -1
- package/states/appContext.ts +6 -7
- package/states/modal.ts +65 -25
- package/states/popOver.ts +21 -13
- package/states/toasts.ts +1 -1
- package/types/PopOver.d.ts +164 -102
- package/utils/hooks.ts +36 -1
- package/utils/schema.ts +10 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "Contains react (and DOM) related utils and hooks.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "jsb188",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"./types/PopOver.d": "./types/PopOver.d.ts"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@jsb188/app": "1.1.
|
|
16
|
-
"jotai": "^2.
|
|
17
|
-
"react": "^19.
|
|
15
|
+
"@jsb188/app": "1.1.10",
|
|
16
|
+
"jotai": "^2.20.0",
|
|
17
|
+
"react": "^19.2.7"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/states/apiData.ts
CHANGED
|
@@ -8,6 +8,7 @@ type QueryObserverObj = {
|
|
|
8
8
|
count: number;
|
|
9
9
|
name: string;
|
|
10
10
|
forceRefetch: boolean;
|
|
11
|
+
resetOnly: boolean;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
type FragmentObserverObj = {
|
|
@@ -22,7 +23,8 @@ type FragmentObserverObj = {
|
|
|
22
23
|
const queryObserverState = atom<QueryObserverObj>({
|
|
23
24
|
count: 0,
|
|
24
25
|
name: '',
|
|
25
|
-
forceRefetch: false
|
|
26
|
+
forceRefetch: false,
|
|
27
|
+
resetOnly: false
|
|
26
28
|
});
|
|
27
29
|
|
|
28
30
|
/**
|
package/states/appContext.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { clearAppCache, fetchLightModeSetting, isSystemDarkMode, saveAuthTokenToPlatform } from '@jsb188/app/platform';
|
|
2
|
-
import type { AccountData, AccountSettings, AuthenticationData, LightModeEnum } from '@jsb188/app/types/auth.d';
|
|
3
|
-
import { setAuthToken } from '@jsb188/app/utils/api';
|
|
4
|
-
import {
|
|
1
|
+
import { clearAppCache, fetchLightModeSetting, isSystemDarkMode, saveAuthTokenToPlatform } from '@jsb188/app/platform.ts';
|
|
2
|
+
import type { AccountData, AccountSettings, AuthenticationData, LightModeEnum } from '@jsb188/app/types/auth.d.ts';
|
|
3
|
+
import { setAuthToken } from '@jsb188/app/utils/api.ts';
|
|
4
|
+
import { getDisplayName } from '@jsb188/app/utils/string.ts';
|
|
5
5
|
import { createContext, useContext } from 'react';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -163,7 +163,7 @@ export function getTheme(
|
|
|
163
163
|
);
|
|
164
164
|
|
|
165
165
|
return {
|
|
166
|
-
lightMode,
|
|
166
|
+
lightMode: lightMode || 'LIGHT',
|
|
167
167
|
theme,
|
|
168
168
|
};
|
|
169
169
|
}
|
|
@@ -375,8 +375,7 @@ export const AppContext = createContext({
|
|
|
375
375
|
export function useCurrentAccount() {
|
|
376
376
|
const { appState: { activated, hasPassword, webVersion, alertUpdatesOnMount, account, settings, primaryOrganizationId }, dispatchApp } = useContext(AppContext);
|
|
377
377
|
const hasName = !!account?.profile?.firstName || !!account?.profile?.lastName;
|
|
378
|
-
const fullName =
|
|
379
|
-
const displayName = guessFirstName(fullName, 8);
|
|
378
|
+
const { fullName, displayName } = getDisplayName(account?.profile?.firstName, account?.profile?.lastName);
|
|
380
379
|
|
|
381
380
|
return {
|
|
382
381
|
// Dispatch
|
package/states/modal.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import i18n from '@jsb188/app/i18n';
|
|
2
|
-
import type { ServerErrorObj } from '@jsb188/app/types/app.d';
|
|
1
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
+
import type { ColorEnum, ServerErrorObj } from '@jsb188/app/types/app.d.ts';
|
|
3
3
|
import { atom, useAtom, useSetAtom } from 'jotai';
|
|
4
4
|
import { useCallback } from 'react';
|
|
5
5
|
|
|
@@ -10,12 +10,14 @@ import { useCallback } from 'react';
|
|
|
10
10
|
interface ModalRequestParams {
|
|
11
11
|
name: string;
|
|
12
12
|
preset?: string;
|
|
13
|
+
color?: ColorEnum | null;
|
|
13
14
|
props?: Record<string, any>;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export interface ModalProps {
|
|
17
18
|
name: string;
|
|
18
19
|
preset: string | null;
|
|
20
|
+
modalSessionKey?: string;
|
|
19
21
|
[key: string]: any;
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -27,10 +29,13 @@ export interface ModalPopUpComponentProps {
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
type ModalPropsFn = (prev: ModalProps | null) => ModalProps | null;
|
|
32
|
+
type ModalScreenSetter = (
|
|
33
|
+
value: ModalProps | null | ((prev: ModalProps | null) => ModalProps | null)
|
|
34
|
+
) => void;
|
|
30
35
|
|
|
31
|
-
export type OpenModalScreenFn = (data: ModalRequestParams) => void;
|
|
36
|
+
export type OpenModalScreenFn = (data: ModalRequestParams | ModalPropsFn) => void;
|
|
32
37
|
|
|
33
|
-
export type OpenModalPopUpFn = (data: ModalRequestParams | null, err?: ServerErrorObj) => void;
|
|
38
|
+
export type OpenModalPopUpFn = (data: ModalRequestParams | null, err?: Partial<ServerErrorObj>) => void;
|
|
34
39
|
|
|
35
40
|
export interface ModalScreenProps {
|
|
36
41
|
screen: ModalProps | null;
|
|
@@ -45,6 +50,7 @@ export interface ModalPopUpProps {
|
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
export interface ModalHandlerProps {
|
|
53
|
+
color?: ColorEnum | null;
|
|
48
54
|
openModalScreen: OpenModalScreenFn;
|
|
49
55
|
openModalPopUp: OpenModalPopUpFn;
|
|
50
56
|
closeModalScreen: () => void;
|
|
@@ -94,17 +100,14 @@ export const POPUP_DEFAULT_VALUES = {
|
|
|
94
100
|
// Not allowed in chat
|
|
95
101
|
iconName: 'lock-square-rounded-filled',
|
|
96
102
|
},
|
|
97
|
-
'20021': {
|
|
98
|
-
iconName: 'mood-sad-dizzy',
|
|
99
|
-
},
|
|
100
103
|
'10000': {
|
|
101
104
|
preset: 'force_reload',
|
|
102
|
-
iconName: '
|
|
105
|
+
// iconName: '..', // This is controlled via i18n now
|
|
103
106
|
},
|
|
104
107
|
'10012': {
|
|
105
108
|
preset: 'force_reload',
|
|
106
109
|
title: 'error.login_changed',
|
|
107
|
-
iconName: '
|
|
110
|
+
iconName: 'question-circle', // Deprecated; icon names are controlled via i18n now
|
|
108
111
|
},
|
|
109
112
|
} as Record<string, Record<string, string>>;
|
|
110
113
|
|
|
@@ -126,13 +129,15 @@ class ModalScreen {
|
|
|
126
129
|
|
|
127
130
|
open(data: ModalRequestParams): ModalProps | null {
|
|
128
131
|
if (data) {
|
|
129
|
-
const { name, props } = data;
|
|
132
|
+
const { name, color, props } = data;
|
|
130
133
|
const values = this.defaultValues?.[name ?? ''];
|
|
131
134
|
|
|
132
135
|
return {
|
|
133
136
|
name,
|
|
137
|
+
color,
|
|
134
138
|
...values,
|
|
135
139
|
...props,
|
|
140
|
+
modalSessionKey: getModalScreenSessionKey(),
|
|
136
141
|
};
|
|
137
142
|
}
|
|
138
143
|
|
|
@@ -144,6 +149,14 @@ class ModalScreen {
|
|
|
144
149
|
}
|
|
145
150
|
}
|
|
146
151
|
|
|
152
|
+
/*
|
|
153
|
+
* Create a unique session key for each fresh modal screen open request.
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
function getModalScreenSessionKey() {
|
|
157
|
+
return `modal-screen-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
158
|
+
}
|
|
159
|
+
|
|
147
160
|
/**
|
|
148
161
|
* Modal popup class
|
|
149
162
|
*/
|
|
@@ -151,7 +164,7 @@ class ModalScreen {
|
|
|
151
164
|
class ModalPopUp extends ModalScreen {
|
|
152
165
|
readonly name: string = 'modal_popup_state';
|
|
153
166
|
|
|
154
|
-
open(data: ModalRequestParams | null, error?: ServerErrorObj): ModalProps | null {
|
|
167
|
+
open(data: ModalRequestParams | null, error?: Partial<ServerErrorObj>): ModalProps | null {
|
|
155
168
|
if (data) {
|
|
156
169
|
const { preset, name, props } = data;
|
|
157
170
|
const values = this.defaultValues?.[name ?? ''];
|
|
@@ -211,7 +224,7 @@ class ModalPopUp extends ModalScreen {
|
|
|
211
224
|
id: `gql-${errorCode}`,
|
|
212
225
|
iconName: error.iconName || defIconName,
|
|
213
226
|
title: error.title || defTitle || i18n.t('error.error'),
|
|
214
|
-
message: error.message || defMessage || i18n.t('error.
|
|
227
|
+
message: error.message || defMessage || i18n.t('error.unknown_error_msg'),
|
|
215
228
|
...values,
|
|
216
229
|
};
|
|
217
230
|
}
|
|
@@ -235,17 +248,44 @@ const popUpClass = new ModalPopUp('popup', POPUP_DEFAULT_VALUES);
|
|
|
235
248
|
* Create handler functions
|
|
236
249
|
*/
|
|
237
250
|
|
|
238
|
-
|
|
239
|
-
|
|
251
|
+
/*
|
|
252
|
+
* Build the next modal screen state from either a direct open request or a state updater function.
|
|
253
|
+
*/
|
|
254
|
+
|
|
255
|
+
function getNextModalScreenState(
|
|
256
|
+
data: ModalRequestParams | ModalPropsFn,
|
|
240
257
|
prevScreen: ModalProps | null
|
|
241
258
|
) {
|
|
259
|
+
const isStateUpdater = typeof data === 'function';
|
|
260
|
+
const nextScreenValue = isStateUpdater ? data(prevScreen) : screenClass.open(data);
|
|
261
|
+
|
|
262
|
+
return (
|
|
263
|
+
isStateUpdater &&
|
|
264
|
+
nextScreenValue &&
|
|
265
|
+
prevScreen?.modalSessionKey &&
|
|
266
|
+
!nextScreenValue.modalSessionKey
|
|
267
|
+
) ? {
|
|
268
|
+
...nextScreenValue,
|
|
269
|
+
modalSessionKey: prevScreen.modalSessionKey,
|
|
270
|
+
} : nextScreenValue;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/*
|
|
274
|
+
* Compose a stable modal screen open function that reads the latest screen state from the atom setter.
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
function composeOpenModalScreenFn(setScreen: ModalScreenSetter) {
|
|
242
278
|
return (data: ModalRequestParams | ModalPropsFn) => {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
279
|
+
setScreen((prevScreen) => {
|
|
280
|
+
const nextScreenState = getNextModalScreenState(data, prevScreen);
|
|
281
|
+
|
|
282
|
+
if (nextScreenState) {
|
|
283
|
+
return nextScreenState;
|
|
284
|
+
}
|
|
285
|
+
|
|
247
286
|
console.warn('Invalid {screen} data:', data);
|
|
248
|
-
|
|
287
|
+
return prevScreen;
|
|
288
|
+
});
|
|
249
289
|
};
|
|
250
290
|
}
|
|
251
291
|
|
|
@@ -256,7 +296,7 @@ function composeCloseModalScreenFn(setScreen: (value: ModalProps | null) => void
|
|
|
256
296
|
}
|
|
257
297
|
|
|
258
298
|
function composeOpenModalPopUpFn(setPopUp: (value: ModalProps | null) => void) {
|
|
259
|
-
return (data: ModalRequestParams | null, err?: ServerErrorObj) => {
|
|
299
|
+
return (data: ModalRequestParams | null, err?: Partial<ServerErrorObj>) => {
|
|
260
300
|
const nextPopUpState = popUpClass.open(data, err);
|
|
261
301
|
if (nextPopUpState) {
|
|
262
302
|
setPopUp(nextPopUpState);
|
|
@@ -278,7 +318,7 @@ function composeCloseModalPopUpFn(setPopUp: (value: ModalProps | null) => void)
|
|
|
278
318
|
|
|
279
319
|
export function useModalScreen(): ModalScreenProps {
|
|
280
320
|
const [screen, setScreen] = useAtom(screenClass.state);
|
|
281
|
-
const openModalScreen = useCallback(
|
|
321
|
+
const openModalScreen = useCallback(composeOpenModalScreenFn(setScreen), [setScreen]);
|
|
282
322
|
const closeModalScreen = useCallback( composeCloseModalScreenFn(setScreen), []);
|
|
283
323
|
|
|
284
324
|
return {
|
|
@@ -293,8 +333,8 @@ export function useModalScreen(): ModalScreenProps {
|
|
|
293
333
|
*/
|
|
294
334
|
|
|
295
335
|
export function useOpenModalScreen(): OpenModalScreenFn {
|
|
296
|
-
const
|
|
297
|
-
const openModalScreen = useCallback(
|
|
336
|
+
const setScreen = useSetAtom(screenClass.state);
|
|
337
|
+
const openModalScreen = useCallback(composeOpenModalScreenFn(setScreen), [setScreen]);
|
|
298
338
|
|
|
299
339
|
return openModalScreen;
|
|
300
340
|
}
|
|
@@ -320,10 +360,10 @@ export function useModalPopUp(): ModalPopUpProps {
|
|
|
320
360
|
*/
|
|
321
361
|
|
|
322
362
|
export function useModalHandlers(): ModalHandlerProps {
|
|
323
|
-
const
|
|
363
|
+
const setScreen = useSetAtom(screenClass.state);
|
|
324
364
|
const setPopUp = useSetAtom(popUpClass.state);
|
|
325
365
|
|
|
326
|
-
const openModalScreen = useCallback(
|
|
366
|
+
const openModalScreen = useCallback(composeOpenModalScreenFn(setScreen), [setScreen]);
|
|
327
367
|
const closeModalScreen = useCallback( composeCloseModalScreenFn(setScreen), []);
|
|
328
368
|
const openModalPopUp = useCallback( composeOpenModalPopUpFn(setPopUp), []);
|
|
329
369
|
const closeModalPopUp = useCallback( composeCloseModalPopUpFn(setPopUp), []);
|
package/states/popOver.ts
CHANGED
|
@@ -15,6 +15,9 @@ import {
|
|
|
15
15
|
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai';
|
|
16
16
|
import { useCallback } from 'react';
|
|
17
17
|
|
|
18
|
+
type SetPopOverAtomStateValue = PopOverProps | null | ((prev: PopOverProps | null) => PopOverProps | null);
|
|
19
|
+
type SetPopOverAtomFn = (value: SetPopOverAtomStateValue) => void;
|
|
20
|
+
|
|
18
21
|
/**
|
|
19
22
|
* Pop over class
|
|
20
23
|
*/
|
|
@@ -54,11 +57,14 @@ class PopOver {
|
|
|
54
57
|
if (
|
|
55
58
|
!prev || !prev.animationClassName ||
|
|
56
59
|
!this.lastOpenId
|
|
57
|
-
// || prev.id !== this.lastOpenId
|
|
58
60
|
) {
|
|
59
61
|
return null;
|
|
60
62
|
}
|
|
61
63
|
|
|
64
|
+
if ((prev.id || prev.name) !== this.lastOpenId) {
|
|
65
|
+
return prev;
|
|
66
|
+
}
|
|
67
|
+
|
|
62
68
|
let nextAnimClassName = prev.animationClassName || '';
|
|
63
69
|
if (/\bon_mount\b/.test(nextAnimClassName)) {
|
|
64
70
|
nextAnimClassName = nextAnimClassName.replace(/\bon_mount\b/, '').trim();
|
|
@@ -154,16 +160,18 @@ function composeOpenPopOverFn( setPopOver: (value: PopOverProps | null) => void)
|
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
function composeClosePopOverFn(
|
|
157
|
-
setPopOver:
|
|
158
|
-
setPopOverIsHover: (update: boolean | ((prev: boolean) => boolean)) => void
|
|
159
|
-
popOver: PopOverProps | null
|
|
163
|
+
setPopOver: SetPopOverAtomFn,
|
|
164
|
+
setPopOverIsHover: (update: boolean | ((prev: boolean) => boolean)) => void
|
|
160
165
|
): ClosePopOverFn {
|
|
161
166
|
return (dismissIfName?: string) => {
|
|
162
|
-
if (!popOver || (typeof dismissIfName === 'string' && popOver.name !== dismissIfName)) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
167
|
setPopOverIsHover(false);
|
|
166
|
-
setPopOver(
|
|
168
|
+
setPopOver((prev: PopOverProps | null) => {
|
|
169
|
+
if (!prev || (typeof dismissIfName === 'string' && prev.name !== dismissIfName)) {
|
|
170
|
+
return prev;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return popOverClass.close(prev);
|
|
174
|
+
});
|
|
167
175
|
};
|
|
168
176
|
}
|
|
169
177
|
|
|
@@ -202,7 +210,7 @@ export function usePopOver() {
|
|
|
202
210
|
const setPopOverIsHover = useSetAtom(popOverIsHoverState);
|
|
203
211
|
|
|
204
212
|
const openPopOver = useCallback( composeOpenPopOverFn(setPopOver), []);
|
|
205
|
-
const closePopOver = useCallback( composeClosePopOverFn(setPopOver, setPopOverIsHover
|
|
213
|
+
const closePopOver = useCallback( composeClosePopOverFn(setPopOver, setPopOverIsHover), []);
|
|
206
214
|
const updatePopOver = useCallback( composeUpdatePopOverFn(setPopOver), []);
|
|
207
215
|
const setPopOverState = useCallback( composeSetPopOverState(setPopOver), []);
|
|
208
216
|
|
|
@@ -223,10 +231,10 @@ export function usePopOverState() {
|
|
|
223
231
|
const [popOver, setPopOver] = useAtom<PopOverProps | null>(popOverClass.state);
|
|
224
232
|
const setPopOverIsHover = useSetAtom(popOverIsHoverState);
|
|
225
233
|
const updatePopOver = useCallback( composeUpdatePopOverFn(setPopOver), []);
|
|
226
|
-
const closePopOver = useCallback( composeClosePopOverFn(setPopOver, setPopOverIsHover
|
|
234
|
+
const closePopOver = useCallback( composeClosePopOverFn(setPopOver, setPopOverIsHover), []);
|
|
227
235
|
|
|
228
236
|
return {
|
|
229
|
-
|
|
237
|
+
popOver: popOver?.globalState,
|
|
230
238
|
closePopOver,
|
|
231
239
|
updatePopOver
|
|
232
240
|
};
|
|
@@ -237,10 +245,10 @@ export function usePopOverState() {
|
|
|
237
245
|
*/
|
|
238
246
|
|
|
239
247
|
export function useClosePopOver(): ClosePopOverFn {
|
|
240
|
-
const [
|
|
248
|
+
const [, setPopOver] = useAtom<PopOverProps | null>(popOverClass.state);
|
|
241
249
|
const setPopOverIsHover = useSetAtom(popOverIsHoverState);
|
|
242
250
|
|
|
243
|
-
return useCallback( composeClosePopOverFn(setPopOver, setPopOverIsHover
|
|
251
|
+
return useCallback( composeClosePopOverFn(setPopOver, setPopOverIsHover), []);
|
|
244
252
|
}
|
|
245
253
|
|
|
246
254
|
/**
|
package/states/toasts.ts
CHANGED
package/types/PopOver.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ColorEnum } from '@jsb188/app/types/app.d';
|
|
1
|
+
import type { ColorEnum } from '@jsb188/app/types/app.d.ts';
|
|
2
|
+
import type { CSSProperties, ElementType } from 'react';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Utility types
|
|
@@ -15,164 +16,221 @@ export interface ClientRectValues {
|
|
|
15
16
|
y: number;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
export type POPosition = 'top' | 'left' | 'right' | 'bottom' | 'bottom_left' | 'bottom_right';
|
|
20
|
+
export type AbsolutePosition = Pick<CSSProperties, 'left' | 'right' | 'top' | 'bottom'>;
|
|
21
|
+
|
|
22
|
+
export type POItemValue = string | number | boolean | null;
|
|
23
|
+
export type POStateValue = any;
|
|
24
|
+
export type POFormState = Record<string, POStateValue>;
|
|
25
|
+
export type POListItemClickFn = (
|
|
26
|
+
name: string | null,
|
|
27
|
+
value?: POStateValue,
|
|
28
|
+
notEventBased?: boolean,
|
|
29
|
+
dismissOnClick?: boolean,
|
|
30
|
+
) => void;
|
|
31
|
+
|
|
18
32
|
/**
|
|
19
|
-
* Pop over
|
|
33
|
+
* Pop over list items
|
|
20
34
|
*/
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
__type:
|
|
36
|
+
export interface POItemBase {
|
|
37
|
+
__type: string;
|
|
24
38
|
hidden?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface POListSubtitleObj extends POItemBase {
|
|
42
|
+
__type: 'LIST_SUBTITLE';
|
|
25
43
|
text: string;
|
|
26
44
|
textClassName?: string;
|
|
27
45
|
colorIndicator?: ColorEnum;
|
|
28
46
|
}
|
|
29
47
|
|
|
30
|
-
export
|
|
48
|
+
export type PONListSubtitleObj = POListSubtitleObj;
|
|
49
|
+
|
|
50
|
+
export interface POListBreakObj extends POItemBase {
|
|
31
51
|
__type: 'BREAK';
|
|
32
|
-
hidden?: boolean;
|
|
33
52
|
}
|
|
34
53
|
|
|
35
|
-
export interface
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
value?: string | boolean | null;
|
|
54
|
+
export interface POActionListItemBase extends POItemBase {
|
|
55
|
+
name?: string;
|
|
56
|
+
value?: POItemValue;
|
|
39
57
|
text: string;
|
|
58
|
+
description?: string | null;
|
|
40
59
|
className?: string;
|
|
41
60
|
textClassName?: string;
|
|
42
61
|
colorIndicator?: ColorEnum;
|
|
43
62
|
avatarDisplayName?: string;
|
|
44
63
|
photoUri?: string | null;
|
|
45
|
-
LinkComponent?:
|
|
64
|
+
LinkComponent?: ElementType;
|
|
46
65
|
allowDisabledOnClick?: boolean;
|
|
47
66
|
iconName?: string;
|
|
48
67
|
rightIconName?: string;
|
|
49
68
|
rightIconClassName?: string;
|
|
50
69
|
selected?: boolean;
|
|
51
|
-
hidden?: boolean;
|
|
52
70
|
disabled?: boolean;
|
|
53
|
-
onClick?:
|
|
54
|
-
|
|
55
|
-
// Presets
|
|
71
|
+
onClick?: POListItemClickFn;
|
|
56
72
|
preset?: 'small' | 'default';
|
|
57
|
-
|
|
58
|
-
// Web props
|
|
59
73
|
to?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface POListItemObj extends POActionListItemBase {
|
|
77
|
+
__type: 'LIST_ITEM' | 'LIST_ITEM_COPY';
|
|
78
|
+
}
|
|
60
79
|
|
|
61
|
-
|
|
62
|
-
|
|
80
|
+
export interface POCheckListItemObj extends Omit<POActionListItemBase, 'onClick'> {
|
|
81
|
+
__type: 'CHECK_LIST_ITEM' | 'SINGLE_OPTION_LIST_ITEM';
|
|
63
82
|
}
|
|
64
83
|
|
|
65
|
-
export interface POModalItemObj extends
|
|
84
|
+
export interface POModalItemObj extends Omit<POActionListItemBase, 'onClick'> {
|
|
66
85
|
__type: 'LIST_ITEM_POPUP' | 'LIST_ITEM_MODAL';
|
|
67
|
-
variables:
|
|
86
|
+
variables: POStateValue;
|
|
87
|
+
useMutationArgs?: POStateValue[];
|
|
68
88
|
}
|
|
69
89
|
|
|
70
|
-
export interface
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
90
|
+
export interface POListItemPickerOptionObj {
|
|
91
|
+
iconName: string;
|
|
92
|
+
selectedIconName: string;
|
|
93
|
+
className?: string;
|
|
94
|
+
value: POItemValue;
|
|
74
95
|
}
|
|
75
96
|
|
|
76
|
-
export interface
|
|
97
|
+
export interface POListItemPickerObj extends Omit<POActionListItemBase, '__type' | 'text' | 'value' | 'iconName' | 'onClick'> {
|
|
98
|
+
__type: 'LIST_ITEM_PICKER';
|
|
99
|
+
label: string;
|
|
100
|
+
options: POListItemPickerOptionObj[];
|
|
101
|
+
selectedValue?: POItemValue;
|
|
102
|
+
mutationName: string;
|
|
103
|
+
useMutation?: (...args: POStateValue[]) => Record<string, POStateValue>;
|
|
104
|
+
useMutationArgs?: POStateValue[];
|
|
105
|
+
mutationVariables?: Record<string, POStateValue> | ((value: POStateValue) => Record<string, POStateValue>);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface POListColorsObj extends POItemBase {
|
|
109
|
+
__type: 'LIST_COLORS';
|
|
110
|
+
name?: string;
|
|
111
|
+
colors?: readonly string[];
|
|
112
|
+
selectedValue?: string | null;
|
|
113
|
+
className?: string;
|
|
114
|
+
disabled?: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface POListSubmenuObj extends Pick<POListVariables, 'notReady' | 'designClassName' | 'shadowClassName' | 'className' | 'savingValue'> {
|
|
118
|
+
initialState?: POFormState | null;
|
|
119
|
+
options: POListIfaceItem[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface POListSubmenuItemObj extends Omit<POActionListItemBase, '__type' | 'onClick'> {
|
|
123
|
+
__type: 'LIST_SUBMENU_ITEM';
|
|
124
|
+
submenu: POListSubmenuObj;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface PONavAvatarItemObj extends POItemBase {
|
|
77
128
|
__type: 'AVATAR_ITEM';
|
|
78
|
-
name?: string;
|
|
129
|
+
name?: string;
|
|
79
130
|
value?: string | null;
|
|
80
131
|
text: string;
|
|
81
132
|
label: string;
|
|
82
133
|
avatarDisplayName?: string;
|
|
83
134
|
photoUri?: string | null;
|
|
84
135
|
className?: string;
|
|
85
|
-
LinkComponent?:
|
|
136
|
+
LinkComponent?: ElementType;
|
|
86
137
|
allowDisabledOnClick?: boolean;
|
|
87
138
|
rightIconName?: string;
|
|
88
|
-
hidden?: boolean;
|
|
89
139
|
square?: boolean;
|
|
90
140
|
disabled?: boolean;
|
|
91
|
-
|
|
92
|
-
// Web props
|
|
93
141
|
to?: string;
|
|
142
|
+
}
|
|
94
143
|
|
|
95
|
-
|
|
96
|
-
|
|
144
|
+
export interface PODateItemBase extends POItemBase {
|
|
145
|
+
name?: string;
|
|
146
|
+
minDate?: Date;
|
|
147
|
+
maxDate?: Date;
|
|
97
148
|
}
|
|
98
149
|
|
|
99
|
-
export interface PODatePickerObj {
|
|
150
|
+
export interface PODatePickerObj extends PODateItemBase {
|
|
100
151
|
__type: 'DATE_PICKER';
|
|
101
|
-
hidden?: boolean;
|
|
102
|
-
name?: string; // Name for form, for formValues object; if not set, index will be used
|
|
103
|
-
minDate?: Date; // Optional minimum date
|
|
104
|
-
maxDate?: Date; // Optional maximum date
|
|
105
152
|
}
|
|
106
153
|
|
|
107
|
-
export interface PODateRangeObj extends
|
|
154
|
+
export interface PODateRangeObj extends PODateItemBase {
|
|
108
155
|
__type: 'DATE_RANGE';
|
|
109
156
|
}
|
|
110
157
|
|
|
111
|
-
export interface POTextObj {
|
|
158
|
+
export interface POTextObj extends POItemBase {
|
|
112
159
|
__type: 'TEXT';
|
|
113
|
-
hidden?: boolean;
|
|
114
160
|
text: string;
|
|
115
161
|
className?: string;
|
|
116
162
|
designClassName?: string;
|
|
117
163
|
}
|
|
118
164
|
|
|
119
|
-
export type POListIfaceItem =
|
|
120
|
-
|
|
165
|
+
export type POListIfaceItem =
|
|
166
|
+
| PONavAvatarItemObj
|
|
167
|
+
| POListSubtitleObj
|
|
168
|
+
| POListBreakObj
|
|
169
|
+
| POListItemObj
|
|
170
|
+
| POCheckListItemObj
|
|
171
|
+
| POListItemPickerObj
|
|
172
|
+
| POListColorsObj
|
|
173
|
+
| POListSubmenuItemObj
|
|
174
|
+
| POModalItemObj
|
|
175
|
+
| PODatePickerObj
|
|
176
|
+
| PODateRangeObj
|
|
177
|
+
| POTextObj;
|
|
178
|
+
|
|
179
|
+
export type POCheckListIfaceItem = POListSubtitleObj | POListBreakObj | POCheckListItemObj;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Pop over ifaces
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
export interface POListVariables {
|
|
186
|
+
notReady?: boolean;
|
|
187
|
+
designClassName?: string;
|
|
188
|
+
shadowClassName?: string;
|
|
189
|
+
className?: string;
|
|
190
|
+
savingValue?: POItemValue;
|
|
191
|
+
iconName?: string;
|
|
192
|
+
title?: string;
|
|
193
|
+
description?: string;
|
|
194
|
+
displayName?: string;
|
|
195
|
+
photoUri?: string | null;
|
|
196
|
+
initialState?: POFormState | POStateValue[] | POItemValue;
|
|
197
|
+
options: POListIfaceItem[];
|
|
198
|
+
addFooterButton?: boolean;
|
|
199
|
+
footerButtonText?: string;
|
|
200
|
+
LinkComponent?: ElementType;
|
|
201
|
+
remainingHeight?: number;
|
|
202
|
+
}
|
|
121
203
|
|
|
122
204
|
export interface POListIface {
|
|
123
205
|
name: 'PO_LIST';
|
|
124
|
-
variables:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
title?: string;
|
|
131
|
-
description?: string;
|
|
132
|
-
displayName?: string;
|
|
133
|
-
photoUri?: string | null;
|
|
134
|
-
initialState?: Record<string, any>;
|
|
135
|
-
options: POListIfaceItem[];
|
|
136
|
-
addFooterButton?: boolean;
|
|
137
|
-
footerButtonText?: string;
|
|
138
|
-
LinkComponent?: any;
|
|
139
|
-
remainingHeight?: number; // Auto calc'd from <PopOverWrapper />
|
|
140
|
-
};
|
|
206
|
+
variables: POListVariables;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface POCheckListVariables extends Omit<POListVariables, 'options' | 'initialState'> {
|
|
210
|
+
options: POCheckListIfaceItem[];
|
|
211
|
+
initialState?: POItemValue[];
|
|
141
212
|
}
|
|
142
213
|
|
|
143
214
|
export interface POCheckListIface {
|
|
144
215
|
name: 'PO_CHECK_LIST';
|
|
145
|
-
variables:
|
|
146
|
-
notReady?: boolean;
|
|
147
|
-
className?: string;
|
|
148
|
-
designClassName?: string;
|
|
149
|
-
savingValue?: string;
|
|
150
|
-
iconName?: string;
|
|
151
|
-
title?: string;
|
|
152
|
-
description?: string;
|
|
153
|
-
displayName?: string;
|
|
154
|
-
photoUri?: string | null;
|
|
155
|
-
options: POCheckListIfaceItem[];
|
|
156
|
-
initialState?: (string | null)[];
|
|
157
|
-
addFooterButton?: boolean;
|
|
158
|
-
footerButtonText?: string;
|
|
159
|
-
};
|
|
216
|
+
variables: POCheckListVariables;
|
|
160
217
|
}
|
|
161
218
|
|
|
162
219
|
export interface POImageIface {
|
|
163
|
-
name: 'PO_VIEW_IMAGE'
|
|
220
|
+
name: 'PO_VIEW_IMAGE';
|
|
164
221
|
variables: {
|
|
165
222
|
imageUri: string;
|
|
166
223
|
alt?: string;
|
|
167
|
-
rect
|
|
168
|
-
}
|
|
224
|
+
rect?: ClientRectValues;
|
|
225
|
+
};
|
|
169
226
|
}
|
|
170
227
|
|
|
171
228
|
export interface POLabelsAndValuesIface {
|
|
172
229
|
name: 'PO_LABELS_AND_VALUES';
|
|
173
230
|
variables: {
|
|
174
|
-
name: string;
|
|
231
|
+
name: string;
|
|
175
232
|
designClassName?: string;
|
|
233
|
+
shadowClassName?: string;
|
|
176
234
|
className?: string;
|
|
177
235
|
addFooterButton?: boolean;
|
|
178
236
|
footerButtonText?: string;
|
|
@@ -182,31 +240,32 @@ export interface POLabelsAndValuesIface {
|
|
|
182
240
|
flipInputOrder?: boolean;
|
|
183
241
|
forceNumericValues?: boolean;
|
|
184
242
|
includeQuantity?: boolean;
|
|
185
|
-
|
|
243
|
+
includeUnit?: boolean;
|
|
244
|
+
labels: string[];
|
|
186
245
|
inputs: {
|
|
187
246
|
label: string;
|
|
188
247
|
value: string;
|
|
189
248
|
quantity?: number;
|
|
249
|
+
unit?: string;
|
|
190
250
|
}[];
|
|
191
|
-
}
|
|
251
|
+
};
|
|
192
252
|
}
|
|
193
253
|
|
|
194
254
|
export type PopOverIface = POListIface | POCheckListIface | POImageIface | POLabelsAndValuesIface;
|
|
255
|
+
export type PopOverName = PopOverIface['name'] | (string & {});
|
|
256
|
+
export type PopOverVariables = PopOverIface['variables'] | Record<string, POStateValue>;
|
|
195
257
|
|
|
196
258
|
/**
|
|
197
259
|
* Pop overs
|
|
198
260
|
*/
|
|
199
261
|
|
|
200
|
-
export
|
|
201
|
-
|
|
202
|
-
interface FixedElementProps {
|
|
203
|
-
id: string; // This ensures that the popover doesn't reset from within the same mouse pointer element
|
|
262
|
+
export interface PopOverPositionProps {
|
|
204
263
|
className: string;
|
|
205
264
|
position: POPosition;
|
|
206
|
-
variables:
|
|
265
|
+
variables: PopOverVariables;
|
|
207
266
|
popOverWidth: number;
|
|
208
267
|
popOverHeight: number;
|
|
209
|
-
rect
|
|
268
|
+
rect: ClientRectValues;
|
|
210
269
|
offsetX: number;
|
|
211
270
|
offsetY: number;
|
|
212
271
|
leftEdgeThreshold: number;
|
|
@@ -216,33 +275,32 @@ interface FixedElementProps {
|
|
|
216
275
|
hover: boolean;
|
|
217
276
|
}
|
|
218
277
|
|
|
219
|
-
export interface PopOverProps extends Partial<
|
|
278
|
+
export interface PopOverProps extends Partial<PopOverPositionProps> {
|
|
220
279
|
id?: string;
|
|
221
|
-
name:
|
|
222
|
-
closing?: boolean;
|
|
223
|
-
zClassName?: string;
|
|
280
|
+
name: PopOverName;
|
|
281
|
+
closing?: boolean;
|
|
282
|
+
zClassName?: string;
|
|
224
283
|
animationClassName?: string;
|
|
225
284
|
doNotTrackHover?: boolean;
|
|
226
|
-
doNotFixToBottom?: boolean;
|
|
227
|
-
doNotRemoveOnPageEvents?: boolean;
|
|
228
|
-
scrollAreaDOMId?: string | null;
|
|
229
|
-
globalState?:
|
|
285
|
+
doNotFixToBottom?: boolean;
|
|
286
|
+
doNotRemoveOnPageEvents?: boolean;
|
|
287
|
+
scrollAreaDOMId?: string | null;
|
|
288
|
+
globalState?: PopOverGlobalStateObj | null;
|
|
230
289
|
}
|
|
231
290
|
|
|
232
|
-
export interface UpdatePopOverParams {
|
|
233
|
-
name:
|
|
234
|
-
variables: Record<string, any>;
|
|
291
|
+
export interface UpdatePopOverParams extends Record<string, POStateValue> {
|
|
292
|
+
name: PopOverName;
|
|
235
293
|
}
|
|
236
294
|
|
|
237
295
|
export interface PopOverGlobalStateParams {
|
|
238
296
|
action: 'ITEM' | 'ITEM_AUTO' | 'SUBMIT' | 'MOUNT' | 'UNMOUNT';
|
|
239
|
-
name?: string | null;
|
|
240
|
-
value:
|
|
297
|
+
name?: string | null;
|
|
298
|
+
value: POStateValue;
|
|
241
299
|
doNotClosePopOver?: boolean;
|
|
242
300
|
}
|
|
243
301
|
|
|
244
302
|
export interface PopOverGlobalStateObj extends PopOverGlobalStateParams {
|
|
245
|
-
id
|
|
303
|
+
id?: string;
|
|
246
304
|
}
|
|
247
305
|
|
|
248
306
|
export type OpenPopOverFn = (data: PopOverProps) => void;
|
|
@@ -266,10 +324,14 @@ export interface PopOverHookProps extends PopOverHandlerProps {
|
|
|
266
324
|
* Tooltips
|
|
267
325
|
*/
|
|
268
326
|
|
|
269
|
-
export interface TooltipProps extends Partial<
|
|
327
|
+
export interface TooltipProps extends Partial<Omit<PopOverPositionProps, 'variables'>> {
|
|
328
|
+
id?: string;
|
|
329
|
+
absolute?: AbsolutePosition;
|
|
330
|
+
__html?: string;
|
|
270
331
|
title?: string;
|
|
271
332
|
message?: string;
|
|
272
333
|
tooltipClassName?: string;
|
|
334
|
+
fontClassName?: string;
|
|
273
335
|
leftIconName?: string;
|
|
274
336
|
rightIconName?: string;
|
|
275
337
|
}
|
package/utils/hooks.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { areObjectsEqual } from '@jsb188/app/utils/object';
|
|
1
|
+
import { areObjectsEqual } from '@jsb188/app/utils/object.ts';
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -313,3 +313,38 @@ export function useImagesLoadStatus(
|
|
|
313
313
|
|
|
314
314
|
return loaded;
|
|
315
315
|
}
|
|
316
|
+
|
|
317
|
+
/*
|
|
318
|
+
* Track whether a referenced div's scroll position has passed a pixel offset.
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
export function useScrollPastPosition(
|
|
322
|
+
pixels: number,
|
|
323
|
+
) {
|
|
324
|
+
const divRef = useRef<HTMLDivElement>(null);
|
|
325
|
+
const [hasScrolledPast, setHasScrolledPast] = useState(false);
|
|
326
|
+
|
|
327
|
+
useEffect(() => {
|
|
328
|
+
const element = divRef.current;
|
|
329
|
+
if (!element) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const handleScroll = () => {
|
|
334
|
+
const nextValue = element.scrollTop > pixels;
|
|
335
|
+
|
|
336
|
+
setHasScrolledPast((currentValue) => {
|
|
337
|
+
return currentValue === nextValue ? currentValue : nextValue;
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
element.addEventListener('scroll', handleScroll, { passive: true });
|
|
342
|
+
handleScroll();
|
|
343
|
+
|
|
344
|
+
return () => {
|
|
345
|
+
element.removeEventListener('scroll', handleScroll);
|
|
346
|
+
};
|
|
347
|
+
}, [pixels]);
|
|
348
|
+
|
|
349
|
+
return [divRef, hasScrolledPast] as const;
|
|
350
|
+
}
|
package/utils/schema.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import i18n from '@jsb188/app/i18n';
|
|
3
|
-
import type { FormItemSchemaObj, FormSchemaObj } from '@jsb188/app/types/form.d';
|
|
4
|
-
import { getObject, setObject } from '@jsb188/app/utils/object';
|
|
2
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
import type { FormItemSchemaObj, FormSchemaObj } from '@jsb188/app/types/form.d.ts';
|
|
4
|
+
import { getObject, setObject } from '@jsb188/app/utils/object.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Types
|
|
@@ -28,7 +28,12 @@ export function makeFormValues(
|
|
|
28
28
|
const { listData } = schema;
|
|
29
29
|
|
|
30
30
|
for (const obj of listData) {
|
|
31
|
-
const
|
|
31
|
+
const item = obj?.item || {};
|
|
32
|
+
const { name, setter, items } = item;
|
|
33
|
+
|
|
34
|
+
if (!name && !Array.isArray(items)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
32
37
|
|
|
33
38
|
if (currentData || dataForSchema) {
|
|
34
39
|
if (Array.isArray(items)) {
|
|
@@ -125,7 +130,7 @@ export function useSchema(
|
|
|
125
130
|
firstError = typeof error === 'function' ? error(value) : error;
|
|
126
131
|
} else {
|
|
127
132
|
firstError = {
|
|
128
|
-
message: i18n.t('error.
|
|
133
|
+
message: i18n.t('error.unknown_error_msg'),
|
|
129
134
|
};
|
|
130
135
|
}
|
|
131
136
|
}
|