@jsb188/react 1.1.5 → 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 +2 -2
- package/states/appContext.ts +15 -3
- package/states/index.ts +1 -0
- package/states/modal.ts +8 -1
- package/states/popOver.ts +27 -3
- package/states/toasts.ts +30 -0
- package/types/PopOver.d.ts +32 -3
- package/utils/hooks.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/react",
|
|
3
|
-
"version": "1.1.
|
|
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,7 +12,7 @@
|
|
|
12
12
|
"./types/PopOver.d": "./types/PopOver.d.ts"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@jsb188/app": "1.1.
|
|
15
|
+
"@jsb188/app": "1.1.6",
|
|
16
16
|
"jotai": "^2.13.1",
|
|
17
17
|
"react": "^19.1.1"
|
|
18
18
|
},
|
package/states/appContext.ts
CHANGED
|
@@ -17,6 +17,7 @@ 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'
|
|
@@ -79,7 +80,7 @@ export const DEFAULT_APP_CONTEXT = {
|
|
|
79
80
|
theme: null,
|
|
80
81
|
lightMode: 'LIGHT',
|
|
81
82
|
timeZone: null,
|
|
82
|
-
showSelfAvatar:
|
|
83
|
+
showSelfAvatar: false,
|
|
83
84
|
isBubbleOther: false,
|
|
84
85
|
showOtherAvatar: false,
|
|
85
86
|
},
|
|
@@ -281,6 +282,10 @@ export const appReducer = (state: AppContextData, action: AppContextAction) => {
|
|
|
281
282
|
return {
|
|
282
283
|
...state,
|
|
283
284
|
hasPassword: typeof data.hasPassword === 'boolean' ? data.hasPassword : state.hasPassword,
|
|
285
|
+
account: !data.email ? state.account : {
|
|
286
|
+
...state.account,
|
|
287
|
+
email: data.email
|
|
288
|
+
},
|
|
284
289
|
};
|
|
285
290
|
}
|
|
286
291
|
return state;
|
|
@@ -299,7 +304,7 @@ export const appReducer = (state: AppContextData, action: AppContextAction) => {
|
|
|
299
304
|
...data.plus,
|
|
300
305
|
},
|
|
301
306
|
},
|
|
302
|
-
settings: {
|
|
307
|
+
settings: !data.settings ? state.settings : {
|
|
303
308
|
...DEFAULT_APP_CONTEXT.settings,
|
|
304
309
|
...data.settings,
|
|
305
310
|
}
|
|
@@ -307,6 +312,12 @@ export const appReducer = (state: AppContextData, action: AppContextAction) => {
|
|
|
307
312
|
}
|
|
308
313
|
return state;
|
|
309
314
|
}
|
|
315
|
+
case 'APP_SWITCH_PRIMARY_ORGANIZATION': {
|
|
316
|
+
return {
|
|
317
|
+
...state,
|
|
318
|
+
primaryOrganizationId: data.primaryOrganizationId
|
|
319
|
+
};
|
|
320
|
+
}
|
|
310
321
|
case 'APP_THEME': {
|
|
311
322
|
if (!data?.preview) {
|
|
312
323
|
// Active theme
|
|
@@ -345,7 +356,8 @@ export const appReducer = (state: AppContextData, action: AppContextAction) => {
|
|
|
345
356
|
};
|
|
346
357
|
}
|
|
347
358
|
default:
|
|
348
|
-
|
|
359
|
+
console.dev('Unknown app reducer action type:', __type);
|
|
360
|
+
return state;
|
|
349
361
|
}
|
|
350
362
|
};
|
|
351
363
|
|
package/states/index.ts
CHANGED
package/states/modal.ts
CHANGED
|
@@ -19,6 +19,13 @@ 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
|
+
|
|
22
29
|
type ModalPropsFn = (prev: ModalProps | null) => ModalProps | null;
|
|
23
30
|
|
|
24
31
|
export type OpenModalScreenFn = (data: ModalRequestParams) => void;
|
|
@@ -64,7 +71,7 @@ export const POPUP_DEFAULT_VALUES = {
|
|
|
64
71
|
},
|
|
65
72
|
not_verified_email: {
|
|
66
73
|
iconName: 'mailbox',
|
|
67
|
-
title: '
|
|
74
|
+
title: 'form.check_email',
|
|
68
75
|
message: 'auth.not_verified_yet',
|
|
69
76
|
},
|
|
70
77
|
not_allowed_permission: {
|
package/states/popOver.ts
CHANGED
|
@@ -22,11 +22,15 @@ import { useCallback } from 'react';
|
|
|
22
22
|
class PopOver {
|
|
23
23
|
readonly name: string = 'pop_over_state';
|
|
24
24
|
readonly state = atom<PopOverProps | null>(null);
|
|
25
|
+
public lastOpenId: string | null = null;
|
|
25
26
|
|
|
26
27
|
open(data: PopOverProps): PopOverProps | null {
|
|
28
|
+
// console.log('::::: OPEN', data);
|
|
27
29
|
if (!data?.name) {
|
|
28
30
|
return null;
|
|
29
31
|
}
|
|
32
|
+
|
|
33
|
+
this.lastOpenId = data?.id || data?.name;
|
|
30
34
|
return data;
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -36,6 +40,8 @@ class PopOver {
|
|
|
36
40
|
if (!nextName) {
|
|
37
41
|
return null;
|
|
38
42
|
}
|
|
43
|
+
|
|
44
|
+
this.lastOpenId = prev?.id || nextName;
|
|
39
45
|
return {
|
|
40
46
|
...prev,
|
|
41
47
|
name: nextName,
|
|
@@ -44,16 +50,22 @@ class PopOver {
|
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
close(prev: PopOverProps | null): PopOverProps | null {
|
|
47
|
-
|
|
53
|
+
// console.log('::::: CLOSE', this.lastOpenId, prev?.id);
|
|
54
|
+
if (
|
|
55
|
+
!prev || !prev.animationClassName ||
|
|
56
|
+
!this.lastOpenId
|
|
57
|
+
// || prev.id !== this.lastOpenId
|
|
58
|
+
) {
|
|
48
59
|
return null;
|
|
49
60
|
}
|
|
50
61
|
|
|
51
|
-
let nextAnimClassName = prev.animationClassName;
|
|
62
|
+
let nextAnimClassName = prev.animationClassName || '';
|
|
52
63
|
if (/\bon_mount\b/.test(nextAnimClassName)) {
|
|
53
64
|
nextAnimClassName = nextAnimClassName.replace(/\bon_mount\b/, '').trim();
|
|
54
65
|
} else if (!/\breverse\b/.test(nextAnimClassName)) {
|
|
55
66
|
nextAnimClassName += ' reverse';
|
|
56
67
|
} else {
|
|
68
|
+
this.lastOpenId = null;
|
|
57
69
|
return null;
|
|
58
70
|
}
|
|
59
71
|
|
|
@@ -220,6 +232,17 @@ export function usePopOverState() {
|
|
|
220
232
|
};
|
|
221
233
|
}
|
|
222
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
|
+
|
|
223
246
|
/**
|
|
224
247
|
* Create handlers functions for tooltips
|
|
225
248
|
*/
|
|
@@ -258,8 +281,9 @@ function composeUpdateTooltipFn( setTooltip: (value: TooltipProps | null) => voi
|
|
|
258
281
|
const nextTooltipState = tooltipClass.update(data, prev);
|
|
259
282
|
if (nextTooltipState) {
|
|
260
283
|
return nextTooltipState;
|
|
284
|
+
} else if (data && prev) {
|
|
285
|
+
console.warn('Invalid {tooltip} data for update():', data);
|
|
261
286
|
}
|
|
262
|
-
console.warn('Invalid {tooltip} data for update():', data);
|
|
263
287
|
return prev;
|
|
264
288
|
});
|
|
265
289
|
};
|
package/states/toasts.ts
ADDED
|
@@ -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
|
+
}
|
package/types/PopOver.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface POListBreakObj {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export interface POListItemObj {
|
|
36
|
-
__type: 'LIST_ITEM' | 'CHECK_LIST_ITEM' | 'LIST_ITEM_POPUP';
|
|
36
|
+
__type: 'LIST_ITEM' | 'CHECK_LIST_ITEM' | 'SINGLE_OPTION_LIST_ITEM' | 'LIST_ITEM_POPUP';
|
|
37
37
|
name?: string; // Name for form, for formValues object; if not set, index will be used
|
|
38
38
|
value?: string | boolean | null;
|
|
39
39
|
text: string;
|
|
@@ -68,7 +68,7 @@ export interface POModalItemObj extends POListItemObj {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export interface POCheckListItemObj extends POListItemObj {
|
|
71
|
-
__type: 'CHECK_LIST_ITEM';
|
|
71
|
+
__type: 'CHECK_LIST_ITEM' | 'SINGLE_OPTION_LIST_ITEM';
|
|
72
72
|
name?: string; // Name for form, for formValues object; if not set, index will be used
|
|
73
73
|
hidden?: boolean;
|
|
74
74
|
}
|
|
@@ -136,6 +136,7 @@ export interface POListIface {
|
|
|
136
136
|
addFooterButton?: boolean;
|
|
137
137
|
footerButtonText?: string;
|
|
138
138
|
LinkComponent?: any;
|
|
139
|
+
remainingHeight?: number; // Auto calc'd from <PopOverWrapper />
|
|
139
140
|
};
|
|
140
141
|
}
|
|
141
142
|
|
|
@@ -167,7 +168,30 @@ export interface POImageIface {
|
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
export
|
|
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;
|
|
171
195
|
|
|
172
196
|
/**
|
|
173
197
|
* Pop overs
|
|
@@ -199,6 +223,7 @@ export interface PopOverProps extends Partial<FixedElementProps> {
|
|
|
199
223
|
zClassName?: string; // Class name for z-index, e.g. 'z6', 'z7', etc.
|
|
200
224
|
animationClassName?: string;
|
|
201
225
|
doNotTrackHover?: boolean;
|
|
226
|
+
doNotFixToBottom?: boolean; // If true, popover will not adjust position to fit in viewport
|
|
202
227
|
doNotRemoveOnPageEvents?: boolean; // If true, popover will be removed when the user scrolls or navigation events
|
|
203
228
|
scrollAreaDOMId?: string | null; // Some pages have different parts as the main body, this is the scroll element that need to be tracked
|
|
204
229
|
globalState?: Record<string, any> | null; // Use this to listen to state changes from outside the popover
|
|
@@ -213,6 +238,7 @@ export interface PopOverGlobalStateParams {
|
|
|
213
238
|
action: 'ITEM' | 'ITEM_AUTO' | 'SUBMIT' | 'MOUNT' | 'UNMOUNT';
|
|
214
239
|
name?: string | null; // Name of form item
|
|
215
240
|
value: any;
|
|
241
|
+
doNotClosePopOver?: boolean;
|
|
216
242
|
}
|
|
217
243
|
|
|
218
244
|
export interface PopOverGlobalStateObj extends PopOverGlobalStateParams {
|
|
@@ -243,6 +269,9 @@ export interface PopOverHookProps extends PopOverHandlerProps {
|
|
|
243
269
|
export interface TooltipProps extends Partial<FixedElementProps> {
|
|
244
270
|
title?: string;
|
|
245
271
|
message?: string;
|
|
272
|
+
tooltipClassName?: string;
|
|
273
|
+
leftIconName?: string;
|
|
274
|
+
rightIconName?: string;
|
|
246
275
|
}
|
|
247
276
|
|
|
248
277
|
export type OpenTooltipFn = (data: TooltipProps) => void;
|