@jsb188/react 1.1.4 → 1.1.5
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/appContext.ts +17 -37
- package/states/index.ts +1 -0
- package/states/keyDown.ts +66 -0
- package/states/modal.ts +22 -6
- package/states/popOver.ts +1 -3
- package/types/PopOver.d.ts +66 -13
- package/utils/hooks.ts +64 -44
- package/utils/schema.ts +14 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
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.1.
|
|
15
|
+
"@jsb188/app": "1.1.5",
|
|
16
|
+
"jotai": "^2.13.1",
|
|
17
|
+
"react": "^19.1.1"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/states/appContext.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { clearAppCache, fetchLightModeSetting, isSystemDarkMode, saveAuthTokenToPlatform } from '@jsb188/app/platform';
|
|
2
2
|
import type { AccountData, AccountSettings, AuthenticationData, LightModeEnum } from '@jsb188/app/types/auth.d';
|
|
3
3
|
import { setAuthToken } from '@jsb188/app/utils/api';
|
|
4
|
-
import {
|
|
4
|
+
import { buildSingleText, guessFirstName } from '@jsb188/app/utils/string';
|
|
5
5
|
import { createContext, useContext } from 'react';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -21,14 +21,14 @@ type AppContextAction = {
|
|
|
21
21
|
| 'APP_THEME'
|
|
22
22
|
| 'APP_SYSTEM_LIGHT_MODE'
|
|
23
23
|
| 'APP_LIGHT_MODE'
|
|
24
|
-
// App events
|
|
25
|
-
| 'APP_KEY_DOWN'
|
|
26
24
|
);
|
|
27
25
|
data?: any;
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
export type AppContextDispatch = (action: AppContextAction) => void;
|
|
31
29
|
|
|
30
|
+
export type CurrentAccountObj = ReturnType<typeof useCurrentAccount>;
|
|
31
|
+
|
|
32
32
|
/**
|
|
33
33
|
* Types
|
|
34
34
|
*/
|
|
@@ -54,20 +54,13 @@ export type AppContextData = {
|
|
|
54
54
|
settings: AccountSettings;
|
|
55
55
|
activated: boolean;
|
|
56
56
|
hasPassword: boolean;
|
|
57
|
-
|
|
57
|
+
webVersion: string | null;
|
|
58
|
+
alertUpdatesOnMount: boolean;
|
|
58
59
|
|
|
59
60
|
// Preview theme overrides active theme
|
|
60
61
|
systemLightMode: 'LIGHT' | 'DARK';
|
|
61
62
|
previewLightMode: LightModeEnum | null;
|
|
62
63
|
previewTheme: string | null;
|
|
63
|
-
|
|
64
|
-
// This needs to get migrated to Jotai
|
|
65
|
-
keyDown: {
|
|
66
|
-
metaKey: boolean;
|
|
67
|
-
pressed: string | null;
|
|
68
|
-
alert: boolean;
|
|
69
|
-
modal: boolean;
|
|
70
|
-
};
|
|
71
64
|
};
|
|
72
65
|
|
|
73
66
|
/**
|
|
@@ -92,18 +85,12 @@ export const DEFAULT_APP_CONTEXT = {
|
|
|
92
85
|
},
|
|
93
86
|
activated: false,
|
|
94
87
|
hasPassword: false,
|
|
95
|
-
|
|
88
|
+
webVersion: null,
|
|
89
|
+
alertUpdatesOnMount: false,
|
|
96
90
|
|
|
97
91
|
systemLightMode: 'LIGHT',
|
|
98
92
|
previewLightMode: null,
|
|
99
93
|
previewTheme: null,
|
|
100
|
-
|
|
101
|
-
keyDown: {
|
|
102
|
-
metaKey: false,
|
|
103
|
-
pressed: null,
|
|
104
|
-
alert: false,
|
|
105
|
-
modal: false,
|
|
106
|
-
}
|
|
107
94
|
} as AppContextData;
|
|
108
95
|
|
|
109
96
|
/**
|
|
@@ -216,7 +203,7 @@ export function mergeAuthToDefaultValues(
|
|
|
216
203
|
|
|
217
204
|
const authSettings = {
|
|
218
205
|
...DEFAULT_APP_CONTEXT.settings,
|
|
219
|
-
...auth.settings
|
|
206
|
+
...auth.account.settings
|
|
220
207
|
};
|
|
221
208
|
|
|
222
209
|
authSettings.lightMode = ensureLightModeSetting(authSettings.lightMode);
|
|
@@ -228,8 +215,10 @@ export function mergeAuthToDefaultValues(
|
|
|
228
215
|
account: auth.account,
|
|
229
216
|
primaryOrganizationId: auth.primaryOrganizationId || null,
|
|
230
217
|
settings: authSettings,
|
|
218
|
+
|
|
219
|
+
alertUpdatesOnMount: auth.alertUpdatesOnMount,
|
|
231
220
|
hasPassword: auth.hasPassword,
|
|
232
|
-
|
|
221
|
+
webVersion: auth.webVersion,
|
|
233
222
|
|
|
234
223
|
// Theme
|
|
235
224
|
systemLightMode,
|
|
@@ -355,19 +344,6 @@ export const appReducer = (state: AppContextData, action: AppContextAction) => {
|
|
|
355
344
|
systemLightMode: data.lightMode,
|
|
356
345
|
};
|
|
357
346
|
}
|
|
358
|
-
case 'APP_KEY_DOWN': {
|
|
359
|
-
if (typeof data.pressed !=='string' && data.pressed !== null) {
|
|
360
|
-
return state;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return {
|
|
364
|
-
...state,
|
|
365
|
-
keyDown: {
|
|
366
|
-
...state.keyDown,
|
|
367
|
-
...data,
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
347
|
default:
|
|
372
348
|
throw new Error('App Reducer Error: [' + __type + ']');
|
|
373
349
|
}
|
|
@@ -385,18 +361,22 @@ export const AppContext = createContext({
|
|
|
385
361
|
*/
|
|
386
362
|
|
|
387
363
|
export function useCurrentAccount() {
|
|
388
|
-
const { appState: { activated, hasPassword,
|
|
364
|
+
const { appState: { activated, hasPassword, webVersion, alertUpdatesOnMount, account, settings, primaryOrganizationId }, dispatchApp } = useContext(AppContext);
|
|
389
365
|
const hasName = !!account?.profile?.firstName || !!account?.profile?.lastName;
|
|
390
366
|
const fullName = buildSingleText([account?.profile?.firstName, account?.profile?.lastName], ' ');
|
|
391
367
|
const displayName = guessFirstName(fullName, 8);
|
|
392
368
|
|
|
393
369
|
return {
|
|
370
|
+
// Dispatch
|
|
371
|
+
dispatchApp,
|
|
372
|
+
|
|
394
373
|
// App state
|
|
395
374
|
account,
|
|
396
375
|
settings,
|
|
397
376
|
activated,
|
|
398
377
|
hasPassword,
|
|
399
|
-
|
|
378
|
+
webVersion,
|
|
379
|
+
alertUpdatesOnMount,
|
|
400
380
|
|
|
401
381
|
// Computed
|
|
402
382
|
isLoggedIn: !!account?.id,
|
package/states/index.ts
CHANGED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { atom, useAtom, useSetAtom } from 'jotai';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Types
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type KeyDownObserverObj = {
|
|
9
|
+
metaKey: boolean;
|
|
10
|
+
pressed: null | string;
|
|
11
|
+
alert: boolean;
|
|
12
|
+
modal: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Observe reactivity for key down events
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const keyDownState = atom<KeyDownObserverObj>({
|
|
20
|
+
metaKey: false,
|
|
21
|
+
pressed: null,
|
|
22
|
+
alert: false,
|
|
23
|
+
modal: false,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Compose set key down function
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
function composeSetKeyDown(setter: (data: KeyDownObserverObj | ((prev: KeyDownObserverObj) => KeyDownObserverObj)) => void) {
|
|
31
|
+
return (data: Partial<KeyDownObserverObj>) => {
|
|
32
|
+
if (typeof data.pressed !== 'string' && data.pressed !== null) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setter((prev: KeyDownObserverObj) => {
|
|
37
|
+
return {
|
|
38
|
+
...prev,
|
|
39
|
+
...data,
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Export; get key down setter
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
export function useSetKeyDown() {
|
|
50
|
+
const setValue = useSetAtom(keyDownState);
|
|
51
|
+
const setKeyDown = useCallback( composeSetKeyDown(setValue), []);
|
|
52
|
+
|
|
53
|
+
return setKeyDown;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Export; use key down
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
export function useKeyDown() {
|
|
62
|
+
const [value, setValue] = useAtom(keyDownState);
|
|
63
|
+
const setKeyDown = useCallback( composeSetKeyDown(setValue), []);
|
|
64
|
+
|
|
65
|
+
return [value, setKeyDown] as const;
|
|
66
|
+
}
|
package/states/modal.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface ModalProps {
|
|
|
19
19
|
[key: string]: any;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
type ModalPropsFn = (prev: ModalProps | null) => ModalProps | null;
|
|
23
|
+
|
|
22
24
|
export type OpenModalScreenFn = (data: ModalRequestParams) => void;
|
|
23
25
|
|
|
24
26
|
export type OpenModalPopUpFn = (data: ModalRequestParams | null, err?: ServerErrorObj) => void;
|
|
@@ -226,9 +228,12 @@ const popUpClass = new ModalPopUp('popup', POPUP_DEFAULT_VALUES);
|
|
|
226
228
|
* Create handler functions
|
|
227
229
|
*/
|
|
228
230
|
|
|
229
|
-
function composeOpenModalScreenFn(
|
|
230
|
-
|
|
231
|
-
|
|
231
|
+
function composeOpenModalScreenFn(
|
|
232
|
+
setScreen: (value: ModalProps | null) => void,
|
|
233
|
+
prevScreen: ModalProps | null
|
|
234
|
+
) {
|
|
235
|
+
return (data: ModalRequestParams | ModalPropsFn) => {
|
|
236
|
+
const nextScreenState = typeof data === 'function' ? data(prevScreen) : screenClass.open(data);
|
|
232
237
|
if (nextScreenState) {
|
|
233
238
|
setScreen(nextScreenState);
|
|
234
239
|
} else {
|
|
@@ -266,7 +271,7 @@ function composeCloseModalPopUpFn(setPopUp: (value: ModalProps | null) => void)
|
|
|
266
271
|
|
|
267
272
|
export function useModalScreen(): ModalScreenProps {
|
|
268
273
|
const [screen, setScreen] = useAtom(screenClass.state);
|
|
269
|
-
const openModalScreen = useCallback( composeOpenModalScreenFn(setScreen), []);
|
|
274
|
+
const openModalScreen = useCallback( composeOpenModalScreenFn(setScreen, screen), [screen]);
|
|
270
275
|
const closeModalScreen = useCallback( composeCloseModalScreenFn(setScreen), []);
|
|
271
276
|
|
|
272
277
|
return {
|
|
@@ -276,6 +281,17 @@ export function useModalScreen(): ModalScreenProps {
|
|
|
276
281
|
};
|
|
277
282
|
}
|
|
278
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Use screen open function
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
export function useOpenModalScreen(): OpenModalScreenFn {
|
|
289
|
+
const [screen, setScreen] = useAtom(screenClass.state);
|
|
290
|
+
const openModalScreen = useCallback( composeOpenModalScreenFn(setScreen, screen), [screen]);
|
|
291
|
+
|
|
292
|
+
return openModalScreen;
|
|
293
|
+
}
|
|
294
|
+
|
|
279
295
|
/**
|
|
280
296
|
* Use modal popup hook
|
|
281
297
|
*/
|
|
@@ -297,10 +313,10 @@ export function useModalPopUp(): ModalPopUpProps {
|
|
|
297
313
|
*/
|
|
298
314
|
|
|
299
315
|
export function useModalHandlers(): ModalHandlerProps {
|
|
300
|
-
const setScreen =
|
|
316
|
+
const [screen, setScreen] = useAtom(screenClass.state);
|
|
301
317
|
const setPopUp = useSetAtom(popUpClass.state);
|
|
302
318
|
|
|
303
|
-
const openModalScreen = useCallback( composeOpenModalScreenFn(setScreen), []);
|
|
319
|
+
const openModalScreen = useCallback( composeOpenModalScreenFn(setScreen, screen), [screen]);
|
|
304
320
|
const closeModalScreen = useCallback( composeCloseModalScreenFn(setScreen), []);
|
|
305
321
|
const openModalPopUp = useCallback( composeOpenModalPopUpFn(setPopUp), []);
|
|
306
322
|
const closeModalPopUp = useCallback( composeCloseModalPopUpFn(setPopUp), []);
|
package/states/popOver.ts
CHANGED
|
@@ -3,9 +3,7 @@ import {
|
|
|
3
3
|
CloseTooltipFn,
|
|
4
4
|
OpenPopOverFn,
|
|
5
5
|
OpenTooltipFn,
|
|
6
|
-
PopOverGlobalStateObj,
|
|
7
6
|
PopOverGlobalStateParams,
|
|
8
|
-
PopOverHookProps,
|
|
9
7
|
PopOverProps,
|
|
10
8
|
SetPopOverStateFn,
|
|
11
9
|
TooltipHookProps,
|
|
@@ -187,7 +185,7 @@ function composeSetPopOverState( setPopOver: (value: PopOverProps | null) => voi
|
|
|
187
185
|
* Use pop over
|
|
188
186
|
*/
|
|
189
187
|
|
|
190
|
-
export function usePopOver()
|
|
188
|
+
export function usePopOver() {
|
|
191
189
|
const [popOver, setPopOver] = useAtom<PopOverProps | null>(popOverClass.state);
|
|
192
190
|
const setPopOverIsHover = useSetAtom(popOverIsHoverState);
|
|
193
191
|
|
package/types/PopOver.d.ts
CHANGED
|
@@ -20,9 +20,11 @@ export interface ClientRectValues {
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
export interface PONListSubtitleObj {
|
|
23
|
-
__type: '
|
|
23
|
+
__type: 'LIST_SUBTITLE';
|
|
24
24
|
hidden?: boolean;
|
|
25
25
|
text: string;
|
|
26
|
+
textClassName?: string;
|
|
27
|
+
colorIndicator?: ColorEnum;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export interface POListBreakObj {
|
|
@@ -31,10 +33,12 @@ export interface POListBreakObj {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export interface POListItemObj {
|
|
34
|
-
__type: 'LIST_ITEM' | 'CHECK_LIST_ITEM';
|
|
35
|
-
|
|
36
|
+
__type: 'LIST_ITEM' | 'CHECK_LIST_ITEM' | 'LIST_ITEM_POPUP';
|
|
37
|
+
name?: string; // Name for form, for formValues object; if not set, index will be used
|
|
38
|
+
value?: string | boolean | null;
|
|
36
39
|
text: string;
|
|
37
40
|
className?: string;
|
|
41
|
+
textClassName?: string;
|
|
38
42
|
colorIndicator?: ColorEnum;
|
|
39
43
|
avatarDisplayName?: string;
|
|
40
44
|
photoUri?: string | null;
|
|
@@ -43,8 +47,10 @@ export interface POListItemObj {
|
|
|
43
47
|
iconName?: string;
|
|
44
48
|
rightIconName?: string;
|
|
45
49
|
rightIconClassName?: string;
|
|
50
|
+
selected?: boolean;
|
|
46
51
|
hidden?: boolean;
|
|
47
52
|
disabled?: boolean;
|
|
53
|
+
onClick?: (name: string | null, value?: any) => void; // optional, if you want to bypass globalState handlers
|
|
48
54
|
|
|
49
55
|
// Presets
|
|
50
56
|
preset?: 'small' | 'default';
|
|
@@ -56,14 +62,20 @@ export interface POListItemObj {
|
|
|
56
62
|
// ?
|
|
57
63
|
}
|
|
58
64
|
|
|
65
|
+
export interface POModalItemObj extends POListItemObj {
|
|
66
|
+
__type: 'LIST_ITEM_POPUP' | 'LIST_ITEM_MODAL';
|
|
67
|
+
variables: any; // Variables for the pop up
|
|
68
|
+
}
|
|
69
|
+
|
|
59
70
|
export interface POCheckListItemObj extends POListItemObj {
|
|
60
71
|
__type: 'CHECK_LIST_ITEM';
|
|
72
|
+
name?: string; // Name for form, for formValues object; if not set, index will be used
|
|
61
73
|
hidden?: boolean;
|
|
62
|
-
checked?: boolean;
|
|
63
74
|
}
|
|
64
75
|
|
|
65
76
|
export interface PONavAvatarItemObj {
|
|
66
77
|
__type: 'AVATAR_ITEM';
|
|
78
|
+
name?: string; // Name for form, for formValues object; if not set, index will be used
|
|
67
79
|
value?: string | null;
|
|
68
80
|
text: string;
|
|
69
81
|
label: string;
|
|
@@ -74,6 +86,7 @@ export interface PONavAvatarItemObj {
|
|
|
74
86
|
allowDisabledOnClick?: boolean;
|
|
75
87
|
rightIconName?: string;
|
|
76
88
|
hidden?: boolean;
|
|
89
|
+
square?: boolean;
|
|
77
90
|
disabled?: boolean;
|
|
78
91
|
|
|
79
92
|
// Web props
|
|
@@ -83,14 +96,30 @@ export interface PONavAvatarItemObj {
|
|
|
83
96
|
// ?
|
|
84
97
|
}
|
|
85
98
|
|
|
86
|
-
export interface
|
|
99
|
+
export interface PODatePickerObj {
|
|
100
|
+
__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
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface PODateRangeObj extends PODatePickerObj {
|
|
87
108
|
__type: 'DATE_RANGE';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface POTextObj {
|
|
112
|
+
__type: 'TEXT';
|
|
88
113
|
hidden?: boolean;
|
|
114
|
+
text: string;
|
|
115
|
+
className?: string;
|
|
116
|
+
designClassName?: string;
|
|
89
117
|
}
|
|
90
118
|
|
|
91
|
-
export type
|
|
119
|
+
export type POListIfaceItem = PONavAvatarItemObj | PONListSubtitleObj | POListBreakObj | POListItemObj | POCheckListItemObj | POModalItemObj | PODatePickerObj | PODateRangeObj | POTextObj;
|
|
120
|
+
export type POCheckListIfaceItem = PONListSubtitleObj | POListBreakObj | POCheckListItemObj;
|
|
92
121
|
|
|
93
|
-
export interface
|
|
122
|
+
export interface POListIface {
|
|
94
123
|
name: 'PO_LIST';
|
|
95
124
|
variables: {
|
|
96
125
|
notReady?: boolean;
|
|
@@ -102,15 +131,34 @@ export interface OptionsPOIface {
|
|
|
102
131
|
description?: string;
|
|
103
132
|
displayName?: string;
|
|
104
133
|
photoUri?: string | null;
|
|
105
|
-
|
|
106
|
-
options:
|
|
134
|
+
initialState?: Record<string, any>;
|
|
135
|
+
options: POListIfaceItem[];
|
|
107
136
|
addFooterButton?: boolean;
|
|
108
137
|
footerButtonText?: string;
|
|
109
138
|
LinkComponent?: any;
|
|
110
139
|
};
|
|
111
140
|
}
|
|
112
141
|
|
|
113
|
-
export interface
|
|
142
|
+
export interface POCheckListIface {
|
|
143
|
+
name: 'PO_CHECK_LIST';
|
|
144
|
+
variables: {
|
|
145
|
+
notReady?: boolean;
|
|
146
|
+
className?: string;
|
|
147
|
+
designClassName?: string;
|
|
148
|
+
savingValue?: string;
|
|
149
|
+
iconName?: string;
|
|
150
|
+
title?: string;
|
|
151
|
+
description?: string;
|
|
152
|
+
displayName?: string;
|
|
153
|
+
photoUri?: string | null;
|
|
154
|
+
options: POCheckListIfaceItem[];
|
|
155
|
+
initialState?: (string | null)[];
|
|
156
|
+
addFooterButton?: boolean;
|
|
157
|
+
footerButtonText?: string;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface POImageIface {
|
|
114
162
|
name: 'PO_VIEW_IMAGE'
|
|
115
163
|
variables: {
|
|
116
164
|
imageUri: string;
|
|
@@ -119,13 +167,13 @@ export interface ImagePOIface {
|
|
|
119
167
|
}
|
|
120
168
|
}
|
|
121
169
|
|
|
122
|
-
export type PopOverIface =
|
|
170
|
+
export type PopOverIface = POListIface | POCheckListIface | POImageIface;
|
|
123
171
|
|
|
124
172
|
/**
|
|
125
173
|
* Pop overs
|
|
126
174
|
*/
|
|
127
175
|
|
|
128
|
-
export type POPosition = 'top' | 'left' | 'right' | 'bottom' | 'bottom_left';
|
|
176
|
+
export type POPosition = 'top' | 'left' | 'right' | 'bottom' | 'bottom_left' | 'bottom_right';
|
|
129
177
|
|
|
130
178
|
interface FixedElementProps {
|
|
131
179
|
id: string; // This ensures that the popover doesn't reset from within the same mouse pointer element
|
|
@@ -148,8 +196,11 @@ export interface PopOverProps extends Partial<FixedElementProps> {
|
|
|
148
196
|
id?: string;
|
|
149
197
|
name: string; // Used to be "__type"
|
|
150
198
|
closing?: boolean; // If true, multiple close() functions are triggered to animate & close popover
|
|
199
|
+
zClassName?: string; // Class name for z-index, e.g. 'z6', 'z7', etc.
|
|
151
200
|
animationClassName?: string;
|
|
152
201
|
doNotTrackHover?: boolean;
|
|
202
|
+
doNotRemoveOnPageEvents?: boolean; // If true, popover will be removed when the user scrolls or navigation events
|
|
203
|
+
scrollAreaDOMId?: string | null; // Some pages have different parts as the main body, this is the scroll element that need to be tracked
|
|
153
204
|
globalState?: Record<string, any> | null; // Use this to listen to state changes from outside the popover
|
|
154
205
|
}
|
|
155
206
|
|
|
@@ -159,7 +210,8 @@ export interface UpdatePopOverParams {
|
|
|
159
210
|
}
|
|
160
211
|
|
|
161
212
|
export interface PopOverGlobalStateParams {
|
|
162
|
-
action: 'ITEM' | 'SUBMIT' | 'MOUNT' | 'UNMOUNT';
|
|
213
|
+
action: 'ITEM' | 'ITEM_AUTO' | 'SUBMIT' | 'MOUNT' | 'UNMOUNT';
|
|
214
|
+
name?: string | null; // Name of form item
|
|
163
215
|
value: any;
|
|
164
216
|
}
|
|
165
217
|
|
|
@@ -180,6 +232,7 @@ export interface PopOverHandlerProps {
|
|
|
180
232
|
}
|
|
181
233
|
|
|
182
234
|
export interface PopOverHookProps extends PopOverHandlerProps {
|
|
235
|
+
pathname?: string;
|
|
183
236
|
popOver: PopOverProps | null;
|
|
184
237
|
}
|
|
185
238
|
|
package/utils/hooks.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { areObjectsEqual } from '@jsb188/app/utils/object';
|
|
1
2
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -28,17 +29,21 @@ function getDatabaseAction(
|
|
|
28
29
|
// But if not, add an extra param.
|
|
29
30
|
const value = typeof data[key] === 'string' ? data[key].trim() : data[key];
|
|
30
31
|
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
32
|
+
const isNotNull = value !== null || allowNull;
|
|
33
|
+
if (isNotNull) {
|
|
33
34
|
documentData[key] = value;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
if (
|
|
37
38
|
// Doing loose != check instead of !== type check
|
|
38
39
|
currentData[key] != value &&
|
|
39
|
-
|
|
40
|
+
isNotNull
|
|
40
41
|
) {
|
|
41
|
-
|
|
42
|
+
if (value && typeof value === 'object') {
|
|
43
|
+
hasChanges = !areObjectsEqual(currentData[key], value);
|
|
44
|
+
} else {
|
|
45
|
+
hasChanges = true;
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
}
|
|
@@ -227,13 +232,15 @@ export function useAnimationVisibility<T>(
|
|
|
227
232
|
return () => clearTimeout(timer);
|
|
228
233
|
}
|
|
229
234
|
} else if (visibility === .5) {
|
|
230
|
-
|
|
231
|
-
|
|
235
|
+
const timer = setTimeout(() => {
|
|
236
|
+
setVisibility(0);
|
|
237
|
+
}, 300);
|
|
238
|
+
return () => clearTimeout(timer);
|
|
232
239
|
}
|
|
233
240
|
|
|
234
241
|
const shouldBeValue = hasData ? 2 : 0;
|
|
235
242
|
if (shouldBeValue !== visibility) {
|
|
236
|
-
setVisibility(1);
|
|
243
|
+
setVisibility(hasData ? 1 : .5);
|
|
237
244
|
}
|
|
238
245
|
}, [visibility, hasData]);
|
|
239
246
|
|
|
@@ -241,51 +248,64 @@ export function useAnimationVisibility<T>(
|
|
|
241
248
|
}
|
|
242
249
|
|
|
243
250
|
/**
|
|
244
|
-
*
|
|
251
|
+
* Check if image are loaded
|
|
252
|
+
* NOTE: This only checks on mount
|
|
245
253
|
*/
|
|
246
254
|
|
|
247
|
-
export function
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
):
|
|
251
|
-
|
|
252
|
-
(val: 0 | .5 | 1 | 2) => void
|
|
253
|
-
] {
|
|
254
|
-
|
|
255
|
-
const [visible, setVisible] = useState(0 as 0 | .5 | 1 | 2);
|
|
256
|
-
const allowOpen = useRef(openOnMount);
|
|
255
|
+
export function useImagesLoadStatus(
|
|
256
|
+
imageUrls: string[],
|
|
257
|
+
timeoutMS = 10000 // default timeout miliseconds
|
|
258
|
+
): boolean {
|
|
259
|
+
const [loaded, setLoaded] = useState(false);
|
|
257
260
|
|
|
258
261
|
useEffect(() => {
|
|
259
|
-
if (
|
|
260
|
-
|
|
262
|
+
if (!imageUrls || imageUrls.length === 0) {
|
|
263
|
+
setLoaded(true);
|
|
264
|
+
return;
|
|
261
265
|
}
|
|
262
266
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
let isCancelled = false;
|
|
268
|
+
let loadedCount = 0;
|
|
269
|
+
const timeout = setTimeout(() => {
|
|
270
|
+
if (!isCancelled) {
|
|
271
|
+
setLoaded(true);
|
|
272
|
+
}
|
|
273
|
+
}, timeoutMS);
|
|
269
274
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
setVisible(0);
|
|
276
|
-
}, 100);
|
|
277
|
-
return () => { clearTimeout(timer); };
|
|
275
|
+
const handleLoad = () => {
|
|
276
|
+
loadedCount += 1;
|
|
277
|
+
if (loadedCount === imageUrls.length && !isCancelled) {
|
|
278
|
+
clearTimeout(timeout);
|
|
279
|
+
setLoaded(true);
|
|
278
280
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const handleError = () => {
|
|
284
|
+
loadedCount += 1; // count errors too, so they don’t block loading
|
|
285
|
+
if (loadedCount === imageUrls.length && !isCancelled) {
|
|
286
|
+
clearTimeout(timeout);
|
|
287
|
+
setLoaded(true);
|
|
284
288
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const imageElements = imageUrls.map((url) => {
|
|
292
|
+
const img = new Image();
|
|
293
|
+
img.onload = handleLoad;
|
|
294
|
+
img.onerror = handleError;
|
|
295
|
+
img.src = url;
|
|
296
|
+
return img;
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
return () => {
|
|
300
|
+
isCancelled = true;
|
|
301
|
+
clearTimeout(timeout);
|
|
302
|
+
// Optional: clear handlers to prevent leaks
|
|
303
|
+
imageElements.forEach((img) => {
|
|
304
|
+
img.onload = null;
|
|
305
|
+
img.onerror = null;
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
}, []);
|
|
289
309
|
|
|
290
|
-
return
|
|
310
|
+
return loaded;
|
|
291
311
|
}
|
package/utils/schema.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import i18n from '@jsb188/app/i18n';
|
|
3
3
|
import type { FormItemSchemaObj, FormSchemaObj } from '@jsb188/app/types/form.d';
|
|
4
|
+
import { getObject, setObject } from '@jsb188/app/utils/object';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Types
|
|
@@ -31,22 +32,20 @@ export function makeFormValues(
|
|
|
31
32
|
|
|
32
33
|
if (currentData || dataForSchema) {
|
|
33
34
|
if (Array.isArray(items)) {
|
|
34
|
-
items.forEach((subItem: any) => {
|
|
35
|
+
items.forEach(({ item: subItem }: any) => {
|
|
35
36
|
if (typeof subItem.setter === 'function') {
|
|
36
|
-
newFormValues
|
|
37
|
+
setObject(newFormValues, subItem.name, subItem.setter(
|
|
37
38
|
currentData,
|
|
38
39
|
dataForSchema,
|
|
39
|
-
);
|
|
40
|
+
));
|
|
40
41
|
} else if (currentData) {
|
|
41
|
-
newFormValues
|
|
42
|
+
setObject(newFormValues, subItem.name, getObject(currentData, subItem.name));
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
|
-
} else {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
newFormValues[name] = currentData[name];
|
|
49
|
-
}
|
|
45
|
+
} else if (typeof setter === 'function') {
|
|
46
|
+
setObject(newFormValues, name, setter(currentData, dataForSchema));
|
|
47
|
+
} else if (currentData) {
|
|
48
|
+
setObject(newFormValues, name, getObject(currentData, name));
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
}
|
|
@@ -87,7 +86,11 @@ export function useSchema(
|
|
|
87
86
|
const computedItem: Record<string, any> = { ...item };
|
|
88
87
|
if (computedItem) {
|
|
89
88
|
for (const key in computedItem) {
|
|
90
|
-
if (
|
|
89
|
+
if (
|
|
90
|
+
typeof computedItem[key] === 'function' &&
|
|
91
|
+
!key.startsWith('onClick') &&
|
|
92
|
+
!['getter', 'setter'].includes(key)
|
|
93
|
+
) {
|
|
91
94
|
computedItem[key] = computedItem[key](dataForSchema);
|
|
92
95
|
}
|
|
93
96
|
}
|