@jsb188/react 1.1.10 → 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 +24 -20
- package/states/apiData.ts +18 -16
- package/states/appContext.ts +327 -312
- package/states/connected.ts +135 -11
- package/states/index.ts +2 -1
- package/states/keyDown.ts +148 -47
- package/states/keyboardLayer.ts +57 -0
- package/states/modal.ts +369 -268
- package/states/popOver.ts +374 -244
- package/states/reactiveEvents.ts +99 -0
- package/states/uploads.ts +39 -27
- package/types/PopOver.d.ts +552 -223
- package/utils/hooks.ts +387 -272
- package/utils/lazy.ts +183 -0
- package/states/toasts.ts +0 -30
- package/utils/schema.ts +0 -158
package/states/popOver.ts
CHANGED
|
@@ -1,100 +1,112 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import type {
|
|
2
|
+
AcknowledgePopOverEventFn,
|
|
3
|
+
ClosePopOverFn,
|
|
4
|
+
CloseTooltipFn,
|
|
5
|
+
OpenPopOverFn,
|
|
6
|
+
OpenTooltipFn,
|
|
7
|
+
PopOverEventFilter,
|
|
8
|
+
PopOverEventObj,
|
|
9
|
+
PopOverEventParams,
|
|
10
|
+
PopOverProps,
|
|
11
|
+
PublishPopOverEventFn,
|
|
12
|
+
TooltipHookProps,
|
|
13
|
+
TooltipProps,
|
|
14
|
+
UpdatePopOverFn,
|
|
15
|
+
UpdatePopOverParams,
|
|
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 = PopOverProps | null | ((prev: PopOverProps | null) => PopOverProps | null);
|
|
19
|
-
type SetPopOverAtomFn = (value: SetPopOverAtomStateValue) => void;
|
|
18
|
+
import { atom, createStore, useAtom, useAtomValue, useSetAtom } from 'jotai';
|
|
19
|
+
import { useCallback, useMemo } from 'react';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Pop over class
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
class PopOver {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
26
|
+
readonly name: string = 'pop_over_state';
|
|
27
|
+
readonly state = atom<PopOverProps | null>(null);
|
|
28
|
+
readonly eventState = atom<PopOverEventObj | null>(null);
|
|
29
|
+
public lastOpenId: string | null = null;
|
|
30
|
+
private eventId = 0;
|
|
31
|
+
private instanceId = 0;
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* Validate and normalize a newly opened popover definition.
|
|
35
|
+
*/
|
|
36
|
+
open(data: PopOverProps): PopOverProps | null {
|
|
37
|
+
if (!data?.name) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.lastOpenId = data.id || data.name;
|
|
42
|
+
this.instanceId += 1;
|
|
43
|
+
return {
|
|
44
|
+
...data,
|
|
45
|
+
instanceId: `popover_${this.instanceId}`,
|
|
46
|
+
} as PopOverProps;
|
|
47
|
+
}
|
|
48
|
+
|
|
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) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (prev.name === data.iface.name && prev.variables === data.iface.variables) {
|
|
57
|
+
return prev;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.lastOpenId = prev.id || data.iface.name;
|
|
61
|
+
return {
|
|
62
|
+
...prev,
|
|
63
|
+
...data.iface,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* Start the exit animation once and ignore additional dismiss requests until it completes.
|
|
69
|
+
*/
|
|
70
|
+
close(prev: PopOverProps | null): PopOverProps | null {
|
|
71
|
+
if (!prev?.animationClassName || !this.lastOpenId) {
|
|
72
|
+
this.lastOpenId = null;
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if ((prev.id || prev.name) !== this.lastOpenId) {
|
|
77
|
+
return prev;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (prev.closing) {
|
|
81
|
+
return prev;
|
|
82
|
+
}
|
|
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
|
+
|
|
87
|
+
return {
|
|
88
|
+
...prev,
|
|
89
|
+
closing: true,
|
|
90
|
+
animationClassName: nextAnimClassName,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
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) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.eventId += 1;
|
|
103
|
+
return {
|
|
104
|
+
...event,
|
|
105
|
+
id: prev.id,
|
|
106
|
+
eventId: this.eventId,
|
|
107
|
+
instanceId: prev.instanceId,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
/**
|
|
@@ -102,32 +114,40 @@ class PopOver {
|
|
|
102
114
|
*/
|
|
103
115
|
|
|
104
116
|
class Tooltip {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
117
|
+
readonly name: string = 'tooltip_state';
|
|
118
|
+
readonly state = atom<TooltipProps | null>(null);
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
* Validate one tooltip before opening it.
|
|
122
|
+
*/
|
|
123
|
+
open(data: TooltipProps): TooltipProps | null {
|
|
124
|
+
if (!data?.id) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return data;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/*
|
|
131
|
+
* Merge changed tooltip properties into the active tooltip.
|
|
132
|
+
*/
|
|
133
|
+
update(data: TooltipProps, prev: TooltipProps | null): TooltipProps | null {
|
|
134
|
+
if (!data || !prev) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
...prev,
|
|
139
|
+
...data,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/*
|
|
144
|
+
* Remove the active tooltip.
|
|
145
|
+
*/
|
|
146
|
+
close(): TooltipProps | null {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
128
149
|
}
|
|
129
150
|
|
|
130
|
-
const popOverClass = new PopOver();
|
|
131
151
|
const tooltipClass = new Tooltip();
|
|
132
152
|
|
|
133
153
|
/**
|
|
@@ -137,107 +157,209 @@ const tooltipClass = new Tooltip();
|
|
|
137
157
|
const popOverIsHoverState = atom(false);
|
|
138
158
|
|
|
139
159
|
export function usePopOverIsHover() {
|
|
140
|
-
|
|
160
|
+
return useAtomValue(popOverIsHoverState);
|
|
141
161
|
}
|
|
142
162
|
|
|
143
163
|
export function useSetPopOverIsHover() {
|
|
144
|
-
|
|
164
|
+
return useSetAtom(popOverIsHoverState);
|
|
145
165
|
}
|
|
146
166
|
|
|
147
|
-
|
|
148
|
-
* Create
|
|
167
|
+
/*
|
|
168
|
+
* Create one isolated set of popover definition, event, and command atoms.
|
|
149
169
|
*/
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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) {
|
|
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);
|
|
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,
|
|
256
|
+
};
|
|
160
257
|
}
|
|
161
258
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
259
|
+
const sharedPopOverState = createPopOverStateAtoms();
|
|
260
|
+
const inactivePopOverState = atom(false);
|
|
261
|
+
|
|
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),
|
|
278
|
+
};
|
|
176
279
|
}
|
|
177
280
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
+
);
|
|
189
316
|
}
|
|
190
317
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
});
|
|
201
|
-
};
|
|
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(), []);
|
|
202
327
|
}
|
|
203
328
|
|
|
204
329
|
/**
|
|
205
|
-
*
|
|
330
|
+
* Read the active popover definition without subscribing to item events.
|
|
206
331
|
*/
|
|
207
332
|
|
|
208
|
-
export function
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
setPopOverState
|
|
223
|
-
};
|
|
333
|
+
export function usePopOverDefinition() {
|
|
334
|
+
return useAtomValue(sharedPopOverState.definitionState);
|
|
335
|
+
}
|
|
336
|
+
|
|
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],
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
return useAtomValue(isActiveState);
|
|
224
347
|
}
|
|
225
348
|
|
|
226
349
|
/**
|
|
227
|
-
*
|
|
350
|
+
* Read only events emitted by a requested popover id or open instance.
|
|
228
351
|
*/
|
|
229
352
|
|
|
230
|
-
export function
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
};
|
|
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
|
+
}
|
|
361
|
+
|
|
362
|
+
return event;
|
|
241
363
|
}
|
|
242
364
|
|
|
243
365
|
/**
|
|
@@ -245,56 +367,64 @@ export function usePopOverState() {
|
|
|
245
367
|
*/
|
|
246
368
|
|
|
247
369
|
export function useClosePopOver(): ClosePopOverFn {
|
|
248
|
-
|
|
249
|
-
|
|
370
|
+
const setClosePopOver = useSetAtom(sharedPopOverState.closeState);
|
|
371
|
+
|
|
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);
|
|
250
380
|
|
|
251
|
-
|
|
381
|
+
return useCallback((data) => setOpenPopOver(data), []);
|
|
252
382
|
}
|
|
253
383
|
|
|
254
384
|
/**
|
|
255
385
|
* Create handlers functions for tooltips
|
|
256
386
|
*/
|
|
257
387
|
|
|
258
|
-
function composeOpenTooltipFn(
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
388
|
+
function composeOpenTooltipFn(setTooltip: (value: TooltipProps | null) => void): OpenTooltipFn {
|
|
389
|
+
return (data: TooltipProps) => {
|
|
390
|
+
const nextTooltipState = tooltipClass.open(data);
|
|
391
|
+
if (nextTooltipState) {
|
|
392
|
+
setTooltip(nextTooltipState);
|
|
393
|
+
} else {
|
|
394
|
+
console.warn('Invalid {tooltip} data for open():', data);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
267
397
|
}
|
|
268
398
|
|
|
269
|
-
function composeCloseTooltipFn(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
399
|
+
function composeCloseTooltipFn(setTooltip: (value: TooltipProps | null) => void): CloseTooltipFn {
|
|
400
|
+
return (removeId?: string) => {
|
|
401
|
+
if (!removeId) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// @ts-expect-error - I couldn't get rid of this type error
|
|
406
|
+
setTooltip((prev: TooltipProps | null) => {
|
|
407
|
+
if (prev?.id !== removeId) {
|
|
408
|
+
return prev;
|
|
409
|
+
}
|
|
410
|
+
return tooltipClass.close();
|
|
411
|
+
});
|
|
412
|
+
};
|
|
283
413
|
}
|
|
284
414
|
|
|
285
|
-
function composeUpdateTooltipFn(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
415
|
+
function composeUpdateTooltipFn(setTooltip: (value: TooltipProps | null) => void): UpdateTooltipFn {
|
|
416
|
+
return (data: TooltipProps) => {
|
|
417
|
+
// @ts-expect-error - I couldn't get rid of this type error
|
|
418
|
+
setTooltip((prev: TooltipProps | null) => {
|
|
419
|
+
const nextTooltipState = tooltipClass.update(data, prev);
|
|
420
|
+
if (nextTooltipState) {
|
|
421
|
+
return nextTooltipState;
|
|
422
|
+
} else if (data && prev) {
|
|
423
|
+
console.warn('Invalid {tooltip} data for update():', data);
|
|
424
|
+
}
|
|
425
|
+
return prev;
|
|
426
|
+
});
|
|
427
|
+
};
|
|
298
428
|
}
|
|
299
429
|
|
|
300
430
|
/**
|
|
@@ -302,16 +432,16 @@ function composeUpdateTooltipFn( setTooltip: (value: TooltipProps | null) => voi
|
|
|
302
432
|
*/
|
|
303
433
|
|
|
304
434
|
export function useTooltip(): TooltipHookProps {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
435
|
+
const [tooltip, setTooltip] = useAtom<TooltipProps | null>(tooltipClass.state);
|
|
436
|
+
|
|
437
|
+
const openTooltip = useCallback(composeOpenTooltipFn(setTooltip), []);
|
|
438
|
+
const closeTooltip = useCallback(composeCloseTooltipFn(setTooltip), []);
|
|
439
|
+
const updateTooltip = useCallback(composeUpdateTooltipFn(setTooltip), []);
|
|
440
|
+
|
|
441
|
+
return {
|
|
442
|
+
tooltip,
|
|
443
|
+
openTooltip,
|
|
444
|
+
closeTooltip,
|
|
445
|
+
updateTooltip,
|
|
446
|
+
};
|
|
317
447
|
}
|