@jsb188/react 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libs/README.md +75 -0
- package/libs/page-filters.helpers.ts +65 -0
- package/libs/page-filters.ts +223 -0
- package/libs/use-page-filters.ts +147 -0
- package/package.json +8 -4
- package/states/appContext.ts +15 -53
- package/states/index.ts +1 -0
- package/states/keyDown.ts +147 -51
- package/states/keyboardLayer.ts +57 -0
- package/states/modal.ts +158 -88
- package/states/popOver.ts +245 -154
- package/states/reactiveEvents.ts +53 -10
- package/states/uploads.ts +0 -2
- package/types/PopOver.d.ts +190 -55
- package/utils/hooks.ts +109 -29
- package/utils/lazy.ts +183 -0
- package/utils/schema.ts +0 -170
package/states/popOver.ts
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
AcknowledgePopOverEventFn,
|
|
2
3
|
ClosePopOverFn,
|
|
3
4
|
CloseTooltipFn,
|
|
4
5
|
OpenPopOverFn,
|
|
5
6
|
OpenTooltipFn,
|
|
6
|
-
|
|
7
|
+
PopOverEventFilter,
|
|
8
|
+
PopOverEventObj,
|
|
9
|
+
PopOverEventParams,
|
|
7
10
|
PopOverProps,
|
|
8
|
-
|
|
11
|
+
PublishPopOverEventFn,
|
|
9
12
|
TooltipHookProps,
|
|
10
13
|
TooltipProps,
|
|
11
14
|
UpdatePopOverFn,
|
|
12
15
|
UpdatePopOverParams,
|
|
13
16
|
UpdateTooltipFn,
|
|
14
17
|
} from '@jsb188/react/types/PopOver.d';
|
|
15
|
-
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai';
|
|
16
|
-
import { useCallback } from 'react';
|
|
17
|
-
|
|
18
|
-
type SetPopOverAtomStateValue =
|
|
19
|
-
| PopOverProps
|
|
20
|
-
| null
|
|
21
|
-
| ((prev: PopOverProps | null) => PopOverProps | null);
|
|
22
|
-
type SetPopOverAtomFn = (value: SetPopOverAtomStateValue) => void;
|
|
18
|
+
import { atom, createStore, useAtom, useAtomValue, useSetAtom } from 'jotai';
|
|
19
|
+
import { useCallback, useMemo } from 'react';
|
|
23
20
|
|
|
24
21
|
/**
|
|
25
22
|
* Pop over class
|
|
@@ -28,39 +25,51 @@ type SetPopOverAtomFn = (value: SetPopOverAtomStateValue) => void;
|
|
|
28
25
|
class PopOver {
|
|
29
26
|
readonly name: string = 'pop_over_state';
|
|
30
27
|
readonly state = atom<PopOverProps | null>(null);
|
|
28
|
+
readonly eventState = atom<PopOverEventObj | null>(null);
|
|
31
29
|
public lastOpenId: string | null = null;
|
|
30
|
+
private eventId = 0;
|
|
31
|
+
private instanceId = 0;
|
|
32
32
|
|
|
33
|
+
/*
|
|
34
|
+
* Validate and normalize a newly opened popover definition.
|
|
35
|
+
*/
|
|
33
36
|
open(data: PopOverProps): PopOverProps | null {
|
|
34
|
-
// console.log('::::: OPEN', data);
|
|
35
37
|
if (!data?.name) {
|
|
36
38
|
return null;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
this.lastOpenId = data
|
|
40
|
-
|
|
41
|
+
this.lastOpenId = data.id || data.name;
|
|
42
|
+
this.instanceId += 1;
|
|
43
|
+
return {
|
|
44
|
+
...data,
|
|
45
|
+
instanceId: `popover_${this.instanceId}`,
|
|
46
|
+
} as PopOverProps;
|
|
41
47
|
}
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
): PopOverProps | null {
|
|
47
|
-
|
|
48
|
-
const nextName = name || prev?.name;
|
|
49
|
-
if (!nextName) {
|
|
49
|
+
/*
|
|
50
|
+
* Replace only the active popover iface while preserving its layout and instance identity.
|
|
51
|
+
*/
|
|
52
|
+
update(data: UpdatePopOverParams, prev: PopOverProps | null): PopOverProps | null {
|
|
53
|
+
if (!prev) {
|
|
50
54
|
return null;
|
|
51
55
|
}
|
|
56
|
+
if (prev.name === data.iface.name && prev.variables === data.iface.variables) {
|
|
57
|
+
return prev;
|
|
58
|
+
}
|
|
52
59
|
|
|
53
|
-
this.lastOpenId = prev
|
|
60
|
+
this.lastOpenId = prev.id || data.iface.name;
|
|
54
61
|
return {
|
|
55
62
|
...prev,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} as PopOverProps;
|
|
63
|
+
...data.iface,
|
|
64
|
+
};
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
/*
|
|
68
|
+
* Start the exit animation once and ignore additional dismiss requests until it completes.
|
|
69
|
+
*/
|
|
61
70
|
close(prev: PopOverProps | null): PopOverProps | null {
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
if (!prev?.animationClassName || !this.lastOpenId) {
|
|
72
|
+
this.lastOpenId = null;
|
|
64
73
|
return null;
|
|
65
74
|
}
|
|
66
75
|
|
|
@@ -68,16 +77,13 @@ class PopOver {
|
|
|
68
77
|
return prev;
|
|
69
78
|
}
|
|
70
79
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
nextAnimClassName = nextAnimClassName.replace(/\bon_mount\b/, '').trim();
|
|
74
|
-
} else if (!/\breverse\b/.test(nextAnimClassName)) {
|
|
75
|
-
nextAnimClassName += ' reverse';
|
|
76
|
-
} else {
|
|
77
|
-
this.lastOpenId = null;
|
|
78
|
-
return null;
|
|
80
|
+
if (prev.closing) {
|
|
81
|
+
return prev;
|
|
79
82
|
}
|
|
80
83
|
|
|
84
|
+
// Start the exit directly; stripping on_mount first creates a visible frame before the reverse animation restarts.
|
|
85
|
+
const nextAnimClassName = `${prev.animationClassName.replace(/\bon_mount\b/, '').trim()} reverse`;
|
|
86
|
+
|
|
81
87
|
return {
|
|
82
88
|
...prev,
|
|
83
89
|
closing: true,
|
|
@@ -85,22 +91,20 @@ class PopOver {
|
|
|
85
91
|
};
|
|
86
92
|
}
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (!prev) {
|
|
94
|
+
/*
|
|
95
|
+
* Create one immutable event scoped to the currently open popover instance.
|
|
96
|
+
*/
|
|
97
|
+
createEvent(event: PopOverEventParams, prev: PopOverProps | null): PopOverEventObj | null {
|
|
98
|
+
if (!prev?.instanceId) {
|
|
93
99
|
return null;
|
|
94
100
|
}
|
|
95
101
|
|
|
102
|
+
this.eventId += 1;
|
|
96
103
|
return {
|
|
97
|
-
...
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
id: prev.id,
|
|
102
|
-
...globalState,
|
|
103
|
-
},
|
|
104
|
+
...event,
|
|
105
|
+
id: prev.id,
|
|
106
|
+
eventId: this.eventId,
|
|
107
|
+
instanceId: prev.instanceId,
|
|
104
108
|
};
|
|
105
109
|
}
|
|
106
110
|
}
|
|
@@ -113,6 +117,9 @@ class Tooltip {
|
|
|
113
117
|
readonly name: string = 'tooltip_state';
|
|
114
118
|
readonly state = atom<TooltipProps | null>(null);
|
|
115
119
|
|
|
120
|
+
/*
|
|
121
|
+
* Validate one tooltip before opening it.
|
|
122
|
+
*/
|
|
116
123
|
open(data: TooltipProps): TooltipProps | null {
|
|
117
124
|
if (!data?.id) {
|
|
118
125
|
return null;
|
|
@@ -120,6 +127,9 @@ class Tooltip {
|
|
|
120
127
|
return data;
|
|
121
128
|
}
|
|
122
129
|
|
|
130
|
+
/*
|
|
131
|
+
* Merge changed tooltip properties into the active tooltip.
|
|
132
|
+
*/
|
|
123
133
|
update(data: TooltipProps, prev: TooltipProps | null): TooltipProps | null {
|
|
124
134
|
if (!data || !prev) {
|
|
125
135
|
return null;
|
|
@@ -130,12 +140,14 @@ class Tooltip {
|
|
|
130
140
|
};
|
|
131
141
|
}
|
|
132
142
|
|
|
143
|
+
/*
|
|
144
|
+
* Remove the active tooltip.
|
|
145
|
+
*/
|
|
133
146
|
close(): TooltipProps | null {
|
|
134
147
|
return null;
|
|
135
148
|
}
|
|
136
149
|
}
|
|
137
150
|
|
|
138
|
-
const popOverClass = new PopOver();
|
|
139
151
|
const tooltipClass = new Tooltip();
|
|
140
152
|
|
|
141
153
|
/**
|
|
@@ -152,123 +164,202 @@ export function useSetPopOverIsHover() {
|
|
|
152
164
|
return useSetAtom(popOverIsHoverState);
|
|
153
165
|
}
|
|
154
166
|
|
|
155
|
-
|
|
156
|
-
* Create
|
|
167
|
+
/*
|
|
168
|
+
* Create one isolated set of popover definition, event, and command atoms.
|
|
157
169
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const nextPopOverState = popOverClass.open(data);
|
|
164
|
-
if (nextPopOverState) {
|
|
165
|
-
setPopOver(nextPopOverState);
|
|
166
|
-
} else {
|
|
170
|
+
function createPopOverStateAtoms() {
|
|
171
|
+
const popOver = new PopOver();
|
|
172
|
+
const openState = atom(null, (_get, set, data: PopOverProps) => {
|
|
173
|
+
const nextPopOver = popOver.open(data);
|
|
174
|
+
if (!nextPopOver) {
|
|
167
175
|
console.warn('Invalid {popOver} data for open():', data);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
set(popOver.eventState, null);
|
|
180
|
+
set(popOver.state, nextPopOver);
|
|
181
|
+
});
|
|
182
|
+
const closeState = atom(null, (get, set, dismissIf?: string | { id?: string; name?: string }) => {
|
|
183
|
+
const prev = get(popOver.state);
|
|
184
|
+
const dismissIfId = typeof dismissIf === 'object' ? dismissIf.id : undefined;
|
|
185
|
+
const dismissIfName = typeof dismissIf === 'string' ? dismissIf : dismissIf?.name;
|
|
186
|
+
if (!prev || (dismissIfId && prev.id !== dismissIfId) || (dismissIfName && prev.name !== dismissIfName)) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
set(popOverIsHoverState, false);
|
|
191
|
+
const nextPopOver = popOver.close(prev);
|
|
192
|
+
set(popOver.state, nextPopOver);
|
|
193
|
+
if (!nextPopOver) {
|
|
194
|
+
set(popOver.eventState, null);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
/*
|
|
198
|
+
* Finish the rendered exit only if the same closing instance is still active.
|
|
199
|
+
*/
|
|
200
|
+
const completeCloseState = atom(null, (get, set, instanceId: string) => {
|
|
201
|
+
const current = get(popOver.state);
|
|
202
|
+
if (!current?.closing || current.instanceId !== instanceId) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
popOver.lastOpenId = null;
|
|
207
|
+
set(popOver.state, null);
|
|
208
|
+
set(popOver.eventState, null);
|
|
209
|
+
});
|
|
210
|
+
const updateState = atom(null, (get, set, data: UpdatePopOverParams) => {
|
|
211
|
+
const currentPopOver = get(popOver.state);
|
|
212
|
+
const nextPopOver = popOver.update(data, currentPopOver);
|
|
213
|
+
if (!nextPopOver) {
|
|
214
|
+
console.warn('{popOver} data should never be null when using update():', data);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (nextPopOver === currentPopOver) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
set(popOver.state, nextPopOver);
|
|
222
|
+
});
|
|
223
|
+
const publishEventState = atom(null, (get, set, data: PopOverEventParams) => {
|
|
224
|
+
const event = popOver.createEvent(data, get(popOver.state));
|
|
225
|
+
if (!event) {
|
|
226
|
+
console.warn('{popOver} data should never be null when publishing an event:', data);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
set(popOver.eventState, event);
|
|
231
|
+
});
|
|
232
|
+
const acknowledgeEventState = atom(null, (get, set, eventId: number) => {
|
|
233
|
+
if (get(popOver.eventState)?.eventId === eventId) {
|
|
234
|
+
set(popOver.eventState, null);
|
|
168
235
|
}
|
|
236
|
+
});
|
|
237
|
+
// Hard reset without the close animation; for when the popover/tooltip renderer unmounts
|
|
238
|
+
const resetState = atom(null, (_get, set) => {
|
|
239
|
+
popOver.lastOpenId = null;
|
|
240
|
+
set(popOverIsHoverState, false);
|
|
241
|
+
set(popOver.state, null);
|
|
242
|
+
set(popOver.eventState, null);
|
|
243
|
+
set(tooltipClass.state, tooltipClass.close());
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
acknowledgeEventState,
|
|
248
|
+
closeState,
|
|
249
|
+
completeCloseState,
|
|
250
|
+
definitionState: popOver.state,
|
|
251
|
+
eventState: popOver.eventState,
|
|
252
|
+
openState,
|
|
253
|
+
publishEventState,
|
|
254
|
+
resetState,
|
|
255
|
+
updateState,
|
|
169
256
|
};
|
|
170
257
|
}
|
|
171
258
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
setPopOverIsHover: (update: boolean | ((prev: boolean) => boolean)) => void,
|
|
175
|
-
): ClosePopOverFn {
|
|
176
|
-
return (dismissIfName?: string) => {
|
|
177
|
-
setPopOverIsHover(false);
|
|
178
|
-
setPopOver((prev: PopOverProps | null) => {
|
|
179
|
-
if (
|
|
180
|
-
!prev ||
|
|
181
|
-
(typeof dismissIfName === 'string' && prev.name !== dismissIfName)
|
|
182
|
-
) {
|
|
183
|
-
return prev;
|
|
184
|
-
}
|
|
259
|
+
const sharedPopOverState = createPopOverStateAtoms();
|
|
260
|
+
const inactivePopOverState = atom(false);
|
|
185
261
|
|
|
186
|
-
|
|
187
|
-
|
|
262
|
+
/*
|
|
263
|
+
* Create an isolated imperative popover controller for non-React integrations and state tests.
|
|
264
|
+
*/
|
|
265
|
+
export function createPopOverController() {
|
|
266
|
+
const store = createStore();
|
|
267
|
+
const state = createPopOverStateAtoms();
|
|
268
|
+
|
|
269
|
+
return {
|
|
270
|
+
acknowledgePopOverEvent: (eventId: number) => store.set(state.acknowledgeEventState, eventId),
|
|
271
|
+
closePopOver: (dismissIf?: string | { id?: string; name?: string }) => store.set(state.closeState, dismissIf),
|
|
272
|
+
completePopOverClose: (instanceId: string) => store.set(state.completeCloseState, instanceId),
|
|
273
|
+
getDefinition: () => store.get(state.definitionState),
|
|
274
|
+
getEvent: () => store.get(state.eventState),
|
|
275
|
+
openPopOver: (data: PopOverProps) => store.set(state.openState, data),
|
|
276
|
+
publishPopOverEvent: (data: PopOverEventParams) => store.set(state.publishEventState, data),
|
|
277
|
+
updatePopOver: (data: UpdatePopOverParams) => store.set(state.updateState, data),
|
|
188
278
|
};
|
|
189
279
|
}
|
|
190
280
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
281
|
+
/*
|
|
282
|
+
* Create stable commands for the shared popover definition and event atoms.
|
|
283
|
+
*/
|
|
284
|
+
export function usePopOverActions() {
|
|
285
|
+
const setOpenPopOver = useSetAtom(sharedPopOverState.openState);
|
|
286
|
+
const setClosePopOver = useSetAtom(sharedPopOverState.closeState);
|
|
287
|
+
const setCompletePopOverClose = useSetAtom(sharedPopOverState.completeCloseState);
|
|
288
|
+
const setUpdatePopOver = useSetAtom(sharedPopOverState.updateState);
|
|
289
|
+
const setPublishPopOverEvent = useSetAtom(sharedPopOverState.publishEventState);
|
|
290
|
+
const setAcknowledgePopOverEvent = useSetAtom(sharedPopOverState.acknowledgeEventState);
|
|
291
|
+
|
|
292
|
+
/*
|
|
293
|
+
* Acknowledge one event after its scoped consumer has handled it.
|
|
294
|
+
*/
|
|
295
|
+
const acknowledgePopOverEvent = useCallback<AcknowledgePopOverEventFn>((eventId: number) => setAcknowledgePopOverEvent(eventId), []);
|
|
296
|
+
/*
|
|
297
|
+
* Remove the closing instance after the renderer finishes its exit animation.
|
|
298
|
+
*/
|
|
299
|
+
const completePopOverClose = useCallback((instanceId: string) => setCompletePopOverClose(instanceId), []);
|
|
300
|
+
const openPopOver = useCallback<OpenPopOverFn>((data) => setOpenPopOver(data), []);
|
|
301
|
+
const closePopOver = useCallback<ClosePopOverFn>((dismissIf) => setClosePopOver(dismissIf), []);
|
|
302
|
+
const updatePopOver = useCallback<UpdatePopOverFn>((data) => setUpdatePopOver(data), []);
|
|
303
|
+
const publishPopOverEvent = useCallback<PublishPopOverEventFn>((data) => setPublishPopOverEvent(data), []);
|
|
304
|
+
|
|
305
|
+
return useMemo(
|
|
306
|
+
() => ({
|
|
307
|
+
acknowledgePopOverEvent,
|
|
308
|
+
openPopOver,
|
|
309
|
+
closePopOver,
|
|
310
|
+
completePopOverClose,
|
|
311
|
+
updatePopOver,
|
|
312
|
+
publishPopOverEvent,
|
|
313
|
+
}),
|
|
314
|
+
[acknowledgePopOverEvent, closePopOver, completePopOverClose, openPopOver, publishPopOverEvent, updatePopOver],
|
|
315
|
+
);
|
|
205
316
|
}
|
|
206
317
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
console.warn(
|
|
217
|
-
'{popOver} data should never be null when using setGlobalState():',
|
|
218
|
-
data,
|
|
219
|
-
);
|
|
220
|
-
return prev;
|
|
221
|
-
});
|
|
222
|
-
};
|
|
318
|
+
/**
|
|
319
|
+
* Return a stable function that clears the popover definition, event, hover,
|
|
320
|
+
* and tooltip state at once (no close animation). Use it when the component that
|
|
321
|
+
* renders popovers unmounts, so a stale popover can't reappear on remount.
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
export function useResetPopOver() {
|
|
325
|
+
const setResetPopOver = useSetAtom(sharedPopOverState.resetState);
|
|
326
|
+
return useCallback(() => setResetPopOver(), []);
|
|
223
327
|
}
|
|
224
328
|
|
|
225
329
|
/**
|
|
226
|
-
*
|
|
330
|
+
* Read the active popover definition without subscribing to item events.
|
|
227
331
|
*/
|
|
228
332
|
|
|
229
|
-
export function
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
);
|
|
233
|
-
const setPopOverIsHover = useSetAtom(popOverIsHoverState);
|
|
333
|
+
export function usePopOverDefinition() {
|
|
334
|
+
return useAtomValue(sharedPopOverState.definitionState);
|
|
335
|
+
}
|
|
234
336
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
337
|
+
/*
|
|
338
|
+
* Read whether one popover id is active without subscribing the caller to the full definition object.
|
|
339
|
+
*/
|
|
340
|
+
export function usePopOverIsActive(popOverId: string | null | undefined) {
|
|
341
|
+
const isActiveState = useMemo(
|
|
342
|
+
() => (popOverId ? atom((get) => get(sharedPopOverState.definitionState)?.id === popOverId) : inactivePopOverState),
|
|
343
|
+
[popOverId],
|
|
239
344
|
);
|
|
240
|
-
const updatePopOver = useCallback(composeUpdatePopOverFn(setPopOver), []);
|
|
241
|
-
const setPopOverState = useCallback(composeSetPopOverState(setPopOver), []);
|
|
242
345
|
|
|
243
|
-
return
|
|
244
|
-
popOver,
|
|
245
|
-
openPopOver,
|
|
246
|
-
closePopOver,
|
|
247
|
-
updatePopOver,
|
|
248
|
-
setPopOverState,
|
|
249
|
-
};
|
|
346
|
+
return useAtomValue(isActiveState);
|
|
250
347
|
}
|
|
251
348
|
|
|
252
349
|
/**
|
|
253
|
-
*
|
|
350
|
+
* Read only events emitted by a requested popover id or open instance.
|
|
254
351
|
*/
|
|
255
352
|
|
|
256
|
-
export function
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
[],
|
|
265
|
-
);
|
|
353
|
+
export function usePopOverEvent(filter: PopOverEventFilter = {}) {
|
|
354
|
+
const event = useAtomValue(sharedPopOverState.eventState);
|
|
355
|
+
if (
|
|
356
|
+
(filter.instanceId !== undefined && event?.instanceId !== filter.instanceId) ||
|
|
357
|
+
(filter.popOverId !== undefined && event?.id !== filter.popOverId)
|
|
358
|
+
) {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
266
361
|
|
|
267
|
-
return
|
|
268
|
-
popOver: popOver?.globalState,
|
|
269
|
-
closePopOver,
|
|
270
|
-
updatePopOver,
|
|
271
|
-
};
|
|
362
|
+
return event;
|
|
272
363
|
}
|
|
273
364
|
|
|
274
365
|
/**
|
|
@@ -276,19 +367,25 @@ export function usePopOverState() {
|
|
|
276
367
|
*/
|
|
277
368
|
|
|
278
369
|
export function useClosePopOver(): ClosePopOverFn {
|
|
279
|
-
const
|
|
280
|
-
const setPopOverIsHover = useSetAtom(popOverIsHoverState);
|
|
370
|
+
const setClosePopOver = useSetAtom(sharedPopOverState.closeState);
|
|
281
371
|
|
|
282
|
-
return useCallback(
|
|
372
|
+
return useCallback((dismissIf) => setClosePopOver(dismissIf), []);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/*
|
|
376
|
+
* Return only the stable command used to open a popover.
|
|
377
|
+
*/
|
|
378
|
+
export function useOpenPopOver(): OpenPopOverFn {
|
|
379
|
+
const setOpenPopOver = useSetAtom(sharedPopOverState.openState);
|
|
380
|
+
|
|
381
|
+
return useCallback((data) => setOpenPopOver(data), []);
|
|
283
382
|
}
|
|
284
383
|
|
|
285
384
|
/**
|
|
286
385
|
* Create handlers functions for tooltips
|
|
287
386
|
*/
|
|
288
387
|
|
|
289
|
-
function composeOpenTooltipFn(
|
|
290
|
-
setTooltip: (value: TooltipProps | null) => void,
|
|
291
|
-
): OpenTooltipFn {
|
|
388
|
+
function composeOpenTooltipFn(setTooltip: (value: TooltipProps | null) => void): OpenTooltipFn {
|
|
292
389
|
return (data: TooltipProps) => {
|
|
293
390
|
const nextTooltipState = tooltipClass.open(data);
|
|
294
391
|
if (nextTooltipState) {
|
|
@@ -299,9 +396,7 @@ function composeOpenTooltipFn(
|
|
|
299
396
|
};
|
|
300
397
|
}
|
|
301
398
|
|
|
302
|
-
function composeCloseTooltipFn(
|
|
303
|
-
setTooltip: (value: TooltipProps | null) => void,
|
|
304
|
-
): CloseTooltipFn {
|
|
399
|
+
function composeCloseTooltipFn(setTooltip: (value: TooltipProps | null) => void): CloseTooltipFn {
|
|
305
400
|
return (removeId?: string) => {
|
|
306
401
|
if (!removeId) {
|
|
307
402
|
return;
|
|
@@ -317,9 +412,7 @@ function composeCloseTooltipFn(
|
|
|
317
412
|
};
|
|
318
413
|
}
|
|
319
414
|
|
|
320
|
-
function composeUpdateTooltipFn(
|
|
321
|
-
setTooltip: (value: TooltipProps | null) => void,
|
|
322
|
-
): UpdateTooltipFn {
|
|
415
|
+
function composeUpdateTooltipFn(setTooltip: (value: TooltipProps | null) => void): UpdateTooltipFn {
|
|
323
416
|
return (data: TooltipProps) => {
|
|
324
417
|
// @ts-expect-error - I couldn't get rid of this type error
|
|
325
418
|
setTooltip((prev: TooltipProps | null) => {
|
|
@@ -339,9 +432,7 @@ function composeUpdateTooltipFn(
|
|
|
339
432
|
*/
|
|
340
433
|
|
|
341
434
|
export function useTooltip(): TooltipHookProps {
|
|
342
|
-
const [tooltip, setTooltip] = useAtom<TooltipProps | null>(
|
|
343
|
-
tooltipClass.state,
|
|
344
|
-
);
|
|
435
|
+
const [tooltip, setTooltip] = useAtom<TooltipProps | null>(tooltipClass.state);
|
|
345
436
|
|
|
346
437
|
const openTooltip = useCallback(composeOpenTooltipFn(setTooltip), []);
|
|
347
438
|
const closeTooltip = useCallback(composeCloseTooltipFn(setTooltip), []);
|
package/states/reactiveEvents.ts
CHANGED
|
@@ -1,18 +1,38 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ReactiveMessageObj,
|
|
3
|
+
WSDataUpdateObj,
|
|
4
|
+
} from '@jsb188/app/types/app.d.ts';
|
|
2
5
|
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Types; reactive events
|
|
6
9
|
*/
|
|
7
10
|
|
|
8
|
-
export type ReactiveEventObj =
|
|
9
|
-
|
|
10
|
-
'resetQueries' | 'resetQueryRule' | 'fragment'
|
|
11
|
-
> & {
|
|
11
|
+
export type ReactiveEventObj = ReactiveMessageObj & {
|
|
12
|
+
id: string;
|
|
12
13
|
seen?: boolean;
|
|
13
14
|
timestamp: number;
|
|
14
15
|
};
|
|
15
16
|
|
|
17
|
+
type ReactiveEventInput = Pick<WSDataUpdateObj, 'id' | 'messages'> & {
|
|
18
|
+
timestamp?: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Expand one websocket update's messages into independently rendered history rows.
|
|
23
|
+
*/
|
|
24
|
+
function makeReactiveEventRows(
|
|
25
|
+
reactiveEvent: ReactiveEventInput,
|
|
26
|
+
): ReactiveEventObj[] {
|
|
27
|
+
const timestamp = reactiveEvent.timestamp ?? Date.now();
|
|
28
|
+
|
|
29
|
+
return (reactiveEvent.messages || []).map((message, index) => ({
|
|
30
|
+
...message,
|
|
31
|
+
id: `${reactiveEvent.id}:${timestamp}:${index}`,
|
|
32
|
+
timestamp,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
|
|
16
36
|
/**
|
|
17
37
|
* Reactive event state
|
|
18
38
|
*/
|
|
@@ -23,13 +43,28 @@ const hasUnseenReactiveEventState = atom((get) =>
|
|
|
23
43
|
);
|
|
24
44
|
const setReactiveEventState = atom(
|
|
25
45
|
null,
|
|
26
|
-
(_get, set, reactiveEvent:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
46
|
+
(_get, set, reactiveEvent: ReactiveEventInput) => {
|
|
47
|
+
const savedReactiveEvents = makeReactiveEventRows(reactiveEvent);
|
|
48
|
+
if (!savedReactiveEvents.length) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
set(reactiveEventState, (reactiveEvents) =>
|
|
53
|
+
[...savedReactiveEvents, ...reactiveEvents].slice(0, 50),
|
|
54
|
+
);
|
|
31
55
|
},
|
|
32
56
|
);
|
|
57
|
+
const markReactiveEventsSeenState = atom(null, (get, set) => {
|
|
58
|
+
const reactiveEvents = get(reactiveEventState);
|
|
59
|
+
if (reactiveEvents.some((reactiveEvent) => !reactiveEvent.seen)) {
|
|
60
|
+
set(
|
|
61
|
+
reactiveEventState,
|
|
62
|
+
reactiveEvents.map((reactiveEvent) =>
|
|
63
|
+
reactiveEvent.seen ? reactiveEvent : { ...reactiveEvent, seen: true },
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
33
68
|
|
|
34
69
|
/**
|
|
35
70
|
* Return all reactive events from newest to oldest.
|
|
@@ -47,6 +82,14 @@ export function useHasUnseenReactiveEvent() {
|
|
|
47
82
|
return useAtomValue(hasUnseenReactiveEventState);
|
|
48
83
|
}
|
|
49
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Return the setter that marks the current event history as seen.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
export function useMarkReactiveEventsSeen() {
|
|
90
|
+
return useSetAtom(markReactiveEventsSeenState);
|
|
91
|
+
}
|
|
92
|
+
|
|
50
93
|
/**
|
|
51
94
|
* Return the setter that prepends one reactive event to the capped history.
|
|
52
95
|
*/
|
package/states/uploads.ts
CHANGED
|
@@ -30,7 +30,6 @@ export function useUploadsValue() {
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
export function useUploadActions() {
|
|
33
|
-
const uploads = useAtomValue(uploadsState);
|
|
34
33
|
const setUploads = useSetAtom(uploadsState);
|
|
35
34
|
|
|
36
35
|
const startUploadProgress = useCallback(
|
|
@@ -64,7 +63,6 @@ export function useUploadActions() {
|
|
|
64
63
|
);
|
|
65
64
|
|
|
66
65
|
return {
|
|
67
|
-
uploads,
|
|
68
66
|
startUploadProgress,
|
|
69
67
|
updateUploadProgress,
|
|
70
68
|
removeUploadProgress,
|