@jsb188/react 1.1.4 → 1.1.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsb188/react",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
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.4",
16
- "jotai": "^2.12.5",
17
- "react": "^19.1.0"
15
+ "@jsb188/app": "1.1.6",
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"
@@ -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 { guessFirstName, buildSingleText } from '@jsb188/app/utils/string';
4
+ import { buildSingleText, guessFirstName } from '@jsb188/app/utils/string';
5
5
  import { createContext, useContext } from 'react';
6
6
 
7
7
  /**
@@ -17,18 +17,19 @@ type AppContextAction = {
17
17
  | 'APP_GUEST'
18
18
  | 'APP_EDIT_AUTH'
19
19
  | 'APP_EDIT_ACCOUNT'
20
+ | 'APP_SWITCH_PRIMARY_ORGANIZATION'
20
21
  // Account theme
21
22
  | 'APP_THEME'
22
23
  | 'APP_SYSTEM_LIGHT_MODE'
23
24
  | 'APP_LIGHT_MODE'
24
- // App events
25
- | 'APP_KEY_DOWN'
26
25
  );
27
26
  data?: any;
28
27
  };
29
28
 
30
29
  export type AppContextDispatch = (action: AppContextAction) => void;
31
30
 
31
+ export type CurrentAccountObj = ReturnType<typeof useCurrentAccount>;
32
+
32
33
  /**
33
34
  * Types
34
35
  */
@@ -54,20 +55,13 @@ export type AppContextData = {
54
55
  settings: AccountSettings;
55
56
  activated: boolean;
56
57
  hasPassword: boolean;
57
- version: string | null;
58
+ webVersion: string | null;
59
+ alertUpdatesOnMount: boolean;
58
60
 
59
61
  // Preview theme overrides active theme
60
62
  systemLightMode: 'LIGHT' | 'DARK';
61
63
  previewLightMode: LightModeEnum | null;
62
64
  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
65
  };
72
66
 
73
67
  /**
@@ -86,24 +80,18 @@ export const DEFAULT_APP_CONTEXT = {
86
80
  theme: null,
87
81
  lightMode: 'LIGHT',
88
82
  timeZone: null,
89
- showSelfAvatar: true,
83
+ showSelfAvatar: false,
90
84
  isBubbleOther: false,
91
85
  showOtherAvatar: false,
92
86
  },
93
87
  activated: false,
94
88
  hasPassword: false,
95
- version: null,
89
+ webVersion: null,
90
+ alertUpdatesOnMount: false,
96
91
 
97
92
  systemLightMode: 'LIGHT',
98
93
  previewLightMode: null,
99
94
  previewTheme: null,
100
-
101
- keyDown: {
102
- metaKey: false,
103
- pressed: null,
104
- alert: false,
105
- modal: false,
106
- }
107
95
  } as AppContextData;
108
96
 
109
97
  /**
@@ -216,7 +204,7 @@ export function mergeAuthToDefaultValues(
216
204
 
217
205
  const authSettings = {
218
206
  ...DEFAULT_APP_CONTEXT.settings,
219
- ...auth.settings
207
+ ...auth.account.settings
220
208
  };
221
209
 
222
210
  authSettings.lightMode = ensureLightModeSetting(authSettings.lightMode);
@@ -228,8 +216,10 @@ export function mergeAuthToDefaultValues(
228
216
  account: auth.account,
229
217
  primaryOrganizationId: auth.primaryOrganizationId || null,
230
218
  settings: authSettings,
219
+
220
+ alertUpdatesOnMount: auth.alertUpdatesOnMount,
231
221
  hasPassword: auth.hasPassword,
232
- version: auth.version,
222
+ webVersion: auth.webVersion,
233
223
 
234
224
  // Theme
235
225
  systemLightMode,
@@ -292,6 +282,10 @@ export const appReducer = (state: AppContextData, action: AppContextAction) => {
292
282
  return {
293
283
  ...state,
294
284
  hasPassword: typeof data.hasPassword === 'boolean' ? data.hasPassword : state.hasPassword,
285
+ account: !data.email ? state.account : {
286
+ ...state.account,
287
+ email: data.email
288
+ },
295
289
  };
296
290
  }
297
291
  return state;
@@ -310,7 +304,7 @@ export const appReducer = (state: AppContextData, action: AppContextAction) => {
310
304
  ...data.plus,
311
305
  },
312
306
  },
313
- settings: {
307
+ settings: !data.settings ? state.settings : {
314
308
  ...DEFAULT_APP_CONTEXT.settings,
315
309
  ...data.settings,
316
310
  }
@@ -318,6 +312,12 @@ export const appReducer = (state: AppContextData, action: AppContextAction) => {
318
312
  }
319
313
  return state;
320
314
  }
315
+ case 'APP_SWITCH_PRIMARY_ORGANIZATION': {
316
+ return {
317
+ ...state,
318
+ primaryOrganizationId: data.primaryOrganizationId
319
+ };
320
+ }
321
321
  case 'APP_THEME': {
322
322
  if (!data?.preview) {
323
323
  // Active theme
@@ -355,21 +355,9 @@ export const appReducer = (state: AppContextData, action: AppContextAction) => {
355
355
  systemLightMode: data.lightMode,
356
356
  };
357
357
  }
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
358
  default:
372
- throw new Error('App Reducer Error: [' + __type + ']');
359
+ console.dev('Unknown app reducer action type:', __type);
360
+ return state;
373
361
  }
374
362
  };
375
363
 
@@ -385,18 +373,22 @@ export const AppContext = createContext({
385
373
  */
386
374
 
387
375
  export function useCurrentAccount() {
388
- const { appState: { activated, hasPassword, version, account, settings, primaryOrganizationId } } = useContext(AppContext);
376
+ const { appState: { activated, hasPassword, webVersion, alertUpdatesOnMount, account, settings, primaryOrganizationId }, dispatchApp } = useContext(AppContext);
389
377
  const hasName = !!account?.profile?.firstName || !!account?.profile?.lastName;
390
378
  const fullName = buildSingleText([account?.profile?.firstName, account?.profile?.lastName], ' ');
391
379
  const displayName = guessFirstName(fullName, 8);
392
380
 
393
381
  return {
382
+ // Dispatch
383
+ dispatchApp,
384
+
394
385
  // App state
395
386
  account,
396
387
  settings,
397
388
  activated,
398
389
  hasPassword,
399
- version,
390
+ webVersion,
391
+ alertUpdatesOnMount,
400
392
 
401
393
  // Computed
402
394
  isLoggedIn: !!account?.id,
package/states/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from './apiData';
2
2
  export * from './appContext';
3
3
  export * from './connected';
4
+ export * from './keyDown';
4
5
  export * from './modal';
5
6
  export * from './popOver';
7
+ export * from './toasts';
@@ -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,15 @@ export interface ModalProps {
19
19
  [key: string]: any;
20
20
  }
21
21
 
22
+ export interface ModalPopUpComponentProps {
23
+ // Can't extend ModalProps because [key: string]: any; nullifies the type checking
24
+ name: string;
25
+ preset: string | null;
26
+ onCloseModal: () => void;
27
+ }
28
+
29
+ type ModalPropsFn = (prev: ModalProps | null) => ModalProps | null;
30
+
22
31
  export type OpenModalScreenFn = (data: ModalRequestParams) => void;
23
32
 
24
33
  export type OpenModalPopUpFn = (data: ModalRequestParams | null, err?: ServerErrorObj) => void;
@@ -62,7 +71,7 @@ export const POPUP_DEFAULT_VALUES = {
62
71
  },
63
72
  not_verified_email: {
64
73
  iconName: 'mailbox',
65
- title: 'auth.check_email',
74
+ title: 'form.check_email',
66
75
  message: 'auth.not_verified_yet',
67
76
  },
68
77
  not_allowed_permission: {
@@ -226,9 +235,12 @@ const popUpClass = new ModalPopUp('popup', POPUP_DEFAULT_VALUES);
226
235
  * Create handler functions
227
236
  */
228
237
 
229
- function composeOpenModalScreenFn(setScreen: (value: ModalProps | null) => void) {
230
- return (data: ModalRequestParams) => {
231
- const nextScreenState = screenClass.open(data);
238
+ function composeOpenModalScreenFn(
239
+ setScreen: (value: ModalProps | null) => void,
240
+ prevScreen: ModalProps | null
241
+ ) {
242
+ return (data: ModalRequestParams | ModalPropsFn) => {
243
+ const nextScreenState = typeof data === 'function' ? data(prevScreen) : screenClass.open(data);
232
244
  if (nextScreenState) {
233
245
  setScreen(nextScreenState);
234
246
  } else {
@@ -266,7 +278,7 @@ function composeCloseModalPopUpFn(setPopUp: (value: ModalProps | null) => void)
266
278
 
267
279
  export function useModalScreen(): ModalScreenProps {
268
280
  const [screen, setScreen] = useAtom(screenClass.state);
269
- const openModalScreen = useCallback( composeOpenModalScreenFn(setScreen), []);
281
+ const openModalScreen = useCallback( composeOpenModalScreenFn(setScreen, screen), [screen]);
270
282
  const closeModalScreen = useCallback( composeCloseModalScreenFn(setScreen), []);
271
283
 
272
284
  return {
@@ -276,6 +288,17 @@ export function useModalScreen(): ModalScreenProps {
276
288
  };
277
289
  }
278
290
 
291
+ /**
292
+ * Use screen open function
293
+ */
294
+
295
+ export function useOpenModalScreen(): OpenModalScreenFn {
296
+ const [screen, setScreen] = useAtom(screenClass.state);
297
+ const openModalScreen = useCallback( composeOpenModalScreenFn(setScreen, screen), [screen]);
298
+
299
+ return openModalScreen;
300
+ }
301
+
279
302
  /**
280
303
  * Use modal popup hook
281
304
  */
@@ -297,10 +320,10 @@ export function useModalPopUp(): ModalPopUpProps {
297
320
  */
298
321
 
299
322
  export function useModalHandlers(): ModalHandlerProps {
300
- const setScreen = useSetAtom(screenClass.state);
323
+ const [screen, setScreen] = useAtom(screenClass.state);
301
324
  const setPopUp = useSetAtom(popUpClass.state);
302
325
 
303
- const openModalScreen = useCallback( composeOpenModalScreenFn(setScreen), []);
326
+ const openModalScreen = useCallback( composeOpenModalScreenFn(setScreen, screen), [screen]);
304
327
  const closeModalScreen = useCallback( composeCloseModalScreenFn(setScreen), []);
305
328
  const openModalPopUp = useCallback( composeOpenModalPopUpFn(setPopUp), []);
306
329
  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,
@@ -24,11 +22,15 @@ import { useCallback } from 'react';
24
22
  class PopOver {
25
23
  readonly name: string = 'pop_over_state';
26
24
  readonly state = atom<PopOverProps | null>(null);
25
+ public lastOpenId: string | null = null;
27
26
 
28
27
  open(data: PopOverProps): PopOverProps | null {
28
+ // console.log('::::: OPEN', data);
29
29
  if (!data?.name) {
30
30
  return null;
31
31
  }
32
+
33
+ this.lastOpenId = data?.id || data?.name;
32
34
  return data;
33
35
  }
34
36
 
@@ -38,6 +40,8 @@ class PopOver {
38
40
  if (!nextName) {
39
41
  return null;
40
42
  }
43
+
44
+ this.lastOpenId = prev?.id || nextName;
41
45
  return {
42
46
  ...prev,
43
47
  name: nextName,
@@ -46,16 +50,22 @@ class PopOver {
46
50
  }
47
51
 
48
52
  close(prev: PopOverProps | null): PopOverProps | null {
49
- if (!prev || !prev.animationClassName) {
53
+ // console.log('::::: CLOSE', this.lastOpenId, prev?.id);
54
+ if (
55
+ !prev || !prev.animationClassName ||
56
+ !this.lastOpenId
57
+ // || prev.id !== this.lastOpenId
58
+ ) {
50
59
  return null;
51
60
  }
52
61
 
53
- let nextAnimClassName = prev.animationClassName;
62
+ let nextAnimClassName = prev.animationClassName || '';
54
63
  if (/\bon_mount\b/.test(nextAnimClassName)) {
55
64
  nextAnimClassName = nextAnimClassName.replace(/\bon_mount\b/, '').trim();
56
65
  } else if (!/\breverse\b/.test(nextAnimClassName)) {
57
66
  nextAnimClassName += ' reverse';
58
67
  } else {
68
+ this.lastOpenId = null;
59
69
  return null;
60
70
  }
61
71
 
@@ -187,7 +197,7 @@ function composeSetPopOverState( setPopOver: (value: PopOverProps | null) => voi
187
197
  * Use pop over
188
198
  */
189
199
 
190
- export function usePopOver(): PopOverHookProps {
200
+ export function usePopOver() {
191
201
  const [popOver, setPopOver] = useAtom<PopOverProps | null>(popOverClass.state);
192
202
  const setPopOverIsHover = useSetAtom(popOverIsHoverState);
193
203
 
@@ -222,6 +232,17 @@ export function usePopOverState() {
222
232
  };
223
233
  }
224
234
 
235
+ /**
236
+ * Use close pop over function
237
+ */
238
+
239
+ export function useClosePopOver(): ClosePopOverFn {
240
+ const [popOver, setPopOver] = useAtom<PopOverProps | null>(popOverClass.state);
241
+ const setPopOverIsHover = useSetAtom(popOverIsHoverState);
242
+
243
+ return useCallback( composeClosePopOverFn(setPopOver, setPopOverIsHover, popOver), [popOver]);
244
+ }
245
+
225
246
  /**
226
247
  * Create handlers functions for tooltips
227
248
  */
@@ -260,8 +281,9 @@ function composeUpdateTooltipFn( setTooltip: (value: TooltipProps | null) => voi
260
281
  const nextTooltipState = tooltipClass.update(data, prev);
261
282
  if (nextTooltipState) {
262
283
  return nextTooltipState;
284
+ } else if (data && prev) {
285
+ console.warn('Invalid {tooltip} data for update():', data);
263
286
  }
264
- console.warn('Invalid {tooltip} data for update():', data);
265
287
  return prev;
266
288
  });
267
289
  };
@@ -0,0 +1,30 @@
1
+ import type { WSDataUpdateObj } from '@jsb188/app/types/app.d';
2
+ import { atom, useAtomValue, useSetAtom } from 'jotai';
3
+
4
+ /**
5
+ * Types; Fragment/observer hooks
6
+ */
7
+
8
+ export type ToastObj = Omit<WSDataUpdateObj, 'resetQueryKeys' | 'resetQueryRule' | 'fragment'>;
9
+
10
+ /**
11
+ * Toast; state
12
+ */
13
+
14
+ const toastState = atom<ToastObj | null>(null);
15
+
16
+ /**
17
+ * Export; get toast value
18
+ */
19
+
20
+ export function useToastValue() {
21
+ return useAtomValue(toastState);
22
+ }
23
+
24
+ /**
25
+ * Export; set toast state
26
+ */
27
+
28
+ export function useSetToast() {
29
+ return useSetAtom(toastState);
30
+ }
@@ -20,9 +20,11 @@ export interface ClientRectValues {
20
20
  */
21
21
 
22
22
  export interface PONListSubtitleObj {
23
- __type: 'SUBTITLE';
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
- value?: string | null;
36
+ __type: 'LIST_ITEM' | 'CHECK_LIST_ITEM' | 'SINGLE_OPTION_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
- __type: 'CHECK_LIST_ITEM';
71
+ __type: 'CHECK_LIST_ITEM' | 'SINGLE_OPTION_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 PODateRangeObj {
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 PONavItemObj = PONListSubtitleObj | POListBreakObj | POListItemObj | POCheckListItemObj | PONavAvatarItemObj | PODateRangeObj;
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 OptionsPOIface {
122
+ export interface POListIface {
94
123
  name: 'PO_LIST';
95
124
  variables: {
96
125
  notReady?: boolean;
@@ -102,15 +131,35 @@ export interface OptionsPOIface {
102
131
  description?: string;
103
132
  displayName?: string;
104
133
  photoUri?: string | null;
105
- selectedValue?: string | null;
106
- options: PONavItemObj[];
134
+ initialState?: Record<string, any>;
135
+ options: POListIfaceItem[];
107
136
  addFooterButton?: boolean;
108
137
  footerButtonText?: string;
109
138
  LinkComponent?: any;
139
+ remainingHeight?: number; // Auto calc'd from <PopOverWrapper />
110
140
  };
111
141
  }
112
142
 
113
- export interface ImagePOIface {
143
+ export interface POCheckListIface {
144
+ 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
+ };
160
+ }
161
+
162
+ export interface POImageIface {
114
163
  name: 'PO_VIEW_IMAGE'
115
164
  variables: {
116
165
  imageUri: string;
@@ -119,13 +168,36 @@ export interface ImagePOIface {
119
168
  }
120
169
  }
121
170
 
122
- export type PopOverIface = OptionsPOIface | ImagePOIface;
171
+ export interface POLabelsAndValuesIface {
172
+ name: 'PO_LABELS_AND_VALUES';
173
+ variables: {
174
+ name: string; // Name for form, for formValues object
175
+ designClassName?: string;
176
+ className?: string;
177
+ addFooterButton?: boolean;
178
+ footerButtonText?: string;
179
+ gridLayoutStyle?: string;
180
+ notReady?: boolean;
181
+ description?: string;
182
+ flipInputOrder?: boolean;
183
+ forceNumericValues?: boolean;
184
+ includeQuantity?: boolean;
185
+ labels: [string, string][];
186
+ inputs: {
187
+ label: string;
188
+ value: string;
189
+ quantity?: number;
190
+ }[];
191
+ }
192
+ }
193
+
194
+ export type PopOverIface = POListIface | POCheckListIface | POImageIface | POLabelsAndValuesIface;
123
195
 
124
196
  /**
125
197
  * Pop overs
126
198
  */
127
199
 
128
- export type POPosition = 'top' | 'left' | 'right' | 'bottom' | 'bottom_left';
200
+ export type POPosition = 'top' | 'left' | 'right' | 'bottom' | 'bottom_left' | 'bottom_right';
129
201
 
130
202
  interface FixedElementProps {
131
203
  id: string; // This ensures that the popover doesn't reset from within the same mouse pointer element
@@ -148,8 +220,12 @@ export interface PopOverProps extends Partial<FixedElementProps> {
148
220
  id?: string;
149
221
  name: string; // Used to be "__type"
150
222
  closing?: boolean; // If true, multiple close() functions are triggered to animate & close popover
223
+ zClassName?: string; // Class name for z-index, e.g. 'z6', 'z7', etc.
151
224
  animationClassName?: string;
152
225
  doNotTrackHover?: boolean;
226
+ doNotFixToBottom?: boolean; // If true, popover will not adjust position to fit in viewport
227
+ doNotRemoveOnPageEvents?: boolean; // If true, popover will be removed when the user scrolls or navigation events
228
+ scrollAreaDOMId?: string | null; // Some pages have different parts as the main body, this is the scroll element that need to be tracked
153
229
  globalState?: Record<string, any> | null; // Use this to listen to state changes from outside the popover
154
230
  }
155
231
 
@@ -159,8 +235,10 @@ export interface UpdatePopOverParams {
159
235
  }
160
236
 
161
237
  export interface PopOverGlobalStateParams {
162
- action: 'ITEM' | 'SUBMIT' | 'MOUNT' | 'UNMOUNT';
238
+ action: 'ITEM' | 'ITEM_AUTO' | 'SUBMIT' | 'MOUNT' | 'UNMOUNT';
239
+ name?: string | null; // Name of form item
163
240
  value: any;
241
+ doNotClosePopOver?: boolean;
164
242
  }
165
243
 
166
244
  export interface PopOverGlobalStateObj extends PopOverGlobalStateParams {
@@ -180,6 +258,7 @@ export interface PopOverHandlerProps {
180
258
  }
181
259
 
182
260
  export interface PopOverHookProps extends PopOverHandlerProps {
261
+ pathname?: string;
183
262
  popOver: PopOverProps | null;
184
263
  }
185
264
 
@@ -190,6 +269,9 @@ export interface PopOverHookProps extends PopOverHandlerProps {
190
269
  export interface TooltipProps extends Partial<FixedElementProps> {
191
270
  title?: string;
192
271
  message?: string;
272
+ tooltipClassName?: string;
273
+ leftIconName?: string;
274
+ rightIconName?: string;
193
275
  }
194
276
 
195
277
  export type OpenTooltipFn = (data: TooltipProps) => void;
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,25 @@ 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 isNullValue = value !== null || allowNull;
32
- if (isNullValue) {
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
- isNullValue
40
+ isNotNull
40
41
  ) {
41
- hasChanges = true;
42
+ if (value && typeof value === 'object') {
43
+ hasChanges = !areObjectsEqual(currentData[key], value);
44
+ } else {
45
+ hasChanges = true;
46
+ }
47
+
48
+ if (hasChanges) {
49
+ break;
50
+ }
42
51
  }
43
52
  }
44
53
  }
@@ -227,13 +236,15 @@ export function useAnimationVisibility<T>(
227
236
  return () => clearTimeout(timer);
228
237
  }
229
238
  } else if (visibility === .5) {
230
- // Use custom exit function if .5
231
- return;
239
+ const timer = setTimeout(() => {
240
+ setVisibility(0);
241
+ }, 300);
242
+ return () => clearTimeout(timer);
232
243
  }
233
244
 
234
245
  const shouldBeValue = hasData ? 2 : 0;
235
246
  if (shouldBeValue !== visibility) {
236
- setVisibility(1);
247
+ setVisibility(hasData ? 1 : .5);
237
248
  }
238
249
  }, [visibility, hasData]);
239
250
 
@@ -241,51 +252,64 @@ export function useAnimationVisibility<T>(
241
252
  }
242
253
 
243
254
  /**
244
- * Use in-component visibility state (0 | 1 | 2)
255
+ * Check if image are loaded
256
+ * NOTE: This only checks on mount
245
257
  */
246
258
 
247
- export function useVisible(
248
- openOnMount: boolean = true,
249
- onVisible?: (val: number) => void
250
- ): [
251
- 0 | .5 | 1 | 2,
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);
259
+ export function useImagesLoadStatus(
260
+ imageUrls: string[],
261
+ timeoutMS = 10000 // default timeout miliseconds
262
+ ): boolean {
263
+ const [loaded, setLoaded] = useState(false);
257
264
 
258
265
  useEffect(() => {
259
- if (onVisible) {
260
- onVisible(visible);
266
+ if (!imageUrls || imageUrls.length === 0) {
267
+ setLoaded(true);
268
+ return;
261
269
  }
262
270
 
263
- switch (visible) {
264
- case 0:
265
- if (!allowOpen.current) {
266
- allowOpen.current = true;
267
- return;
268
- }
271
+ let isCancelled = false;
272
+ let loadedCount = 0;
273
+ const timeout = setTimeout(() => {
274
+ if (!isCancelled) {
275
+ setLoaded(true);
276
+ }
277
+ }, timeoutMS);
269
278
 
270
- setVisible(1);
271
- break;
272
- case .5: {
273
- const timer = setTimeout(() => {
274
- allowOpen.current = false;
275
- setVisible(0);
276
- }, 100);
277
- return () => { clearTimeout(timer); };
279
+ const handleLoad = () => {
280
+ loadedCount += 1;
281
+ if (loadedCount === imageUrls.length && !isCancelled) {
282
+ clearTimeout(timeout);
283
+ setLoaded(true);
278
284
  }
279
- case 1: {
280
- const timer = setTimeout(() => {
281
- setVisible(2);
282
- }, 100);
283
- return () => { clearTimeout(timer); };
285
+ };
286
+
287
+ const handleError = () => {
288
+ loadedCount += 1; // count errors too, so they don’t block loading
289
+ if (loadedCount === imageUrls.length && !isCancelled) {
290
+ clearTimeout(timeout);
291
+ setLoaded(true);
284
292
  }
285
- case 2:
286
- break;
287
- }
288
- }, [visible]);
293
+ };
294
+
295
+ const imageElements = imageUrls.map((url) => {
296
+ const img = new Image();
297
+ img.onload = handleLoad;
298
+ img.onerror = handleError;
299
+ img.src = url;
300
+ return img;
301
+ });
302
+
303
+ return () => {
304
+ isCancelled = true;
305
+ clearTimeout(timeout);
306
+ // Optional: clear handlers to prevent leaks
307
+ imageElements.forEach((img) => {
308
+ img.onload = null;
309
+ img.onerror = null;
310
+ });
311
+ };
312
+ }, []);
289
313
 
290
- return [visible, setVisible];
314
+ return loaded;
291
315
  }
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[subItem.name] = subItem.setter(
37
+ setObject(newFormValues, subItem.name, subItem.setter(
37
38
  currentData,
38
39
  dataForSchema,
39
- );
40
+ ));
40
41
  } else if (currentData) {
41
- newFormValues[subItem.name] = currentData[subItem.name];
42
+ setObject(newFormValues, subItem.name, getObject(currentData, subItem.name));
42
43
  }
43
44
  });
44
- } else {
45
- if (typeof setter === 'function') {
46
- newFormValues[name] = setter(currentData, dataForSchema);
47
- } else if (currentData) {
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 (typeof computedItem[key] === 'function') {
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
  }