@jsb188/react 1.0.4 → 1.1.2
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 -22
- package/states/apiData.ts +18 -14
- package/states/appContext.ts +424 -0
- package/states/connected.ts +135 -11
- package/states/index.ts +5 -0
- package/states/keyDown.ts +167 -0
- package/states/keyboardLayer.ts +57 -0
- package/states/modal.ts +403 -240
- package/states/popOver.ts +381 -233
- package/states/reactiveEvents.ts +99 -0
- package/states/uploads.ts +70 -0
- package/types/PopOver.d.ts +680 -0
- package/utils/hooks.ts +399 -251
- package/utils/lazy.ts +183 -0
- package/icons/Icon.tsx +0 -207
- package/icons/IconSVGs.tsx +0 -1486
- package/types/dom.d.ts +0 -7
- package/utils/dom.ts +0 -303
- package/utils/priorityTimeout.ts +0 -57
package/states/popOver.ts
CHANGED
|
@@ -1,282 +1,430 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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,
|
|
17
|
+
} from '@jsb188/react/types/PopOver.d';
|
|
18
|
+
import { atom, createStore, useAtom, useAtomValue, useSetAtom } from 'jotai';
|
|
19
|
+
import { useCallback, useMemo } from 'react';
|
|
3
20
|
|
|
4
21
|
/**
|
|
5
|
-
*
|
|
22
|
+
* Pop over class
|
|
6
23
|
*/
|
|
7
24
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
class PopOver {
|
|
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
|
+
}
|
|
16
110
|
}
|
|
17
111
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
width: number;
|
|
22
|
-
height: number;
|
|
23
|
-
left: number;
|
|
24
|
-
right: number;
|
|
25
|
-
top: number;
|
|
26
|
-
bottom: number;
|
|
27
|
-
x: number;
|
|
28
|
-
y: number;
|
|
29
|
-
}
|
|
112
|
+
/**
|
|
113
|
+
* Tooltip class
|
|
114
|
+
*/
|
|
30
115
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
116
|
+
class Tooltip {
|
|
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
|
+
}
|
|
46
149
|
}
|
|
47
150
|
|
|
48
|
-
|
|
49
|
-
name: PopOverNames;
|
|
50
|
-
variables: Record<string, any>;
|
|
51
|
-
}
|
|
151
|
+
const tooltipClass = new Tooltip();
|
|
52
152
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
children?: any; // ????????
|
|
57
|
-
}
|
|
153
|
+
/**
|
|
154
|
+
* Hover state for pop overs
|
|
155
|
+
*/
|
|
58
156
|
|
|
59
|
-
|
|
60
|
-
title?: string;
|
|
61
|
-
message?: string;
|
|
62
|
-
}
|
|
157
|
+
const popOverIsHoverState = atom(false);
|
|
63
158
|
|
|
64
|
-
export
|
|
65
|
-
|
|
66
|
-
|
|
159
|
+
export function usePopOverIsHover() {
|
|
160
|
+
return useAtomValue(popOverIsHoverState);
|
|
161
|
+
}
|
|
67
162
|
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
closePopOver: ClosePopOverFn;
|
|
71
|
-
updatePopOver: UpdatePopOverFn;
|
|
163
|
+
export function useSetPopOverIsHover() {
|
|
164
|
+
return useSetAtom(popOverIsHoverState);
|
|
72
165
|
}
|
|
73
166
|
|
|
74
|
-
|
|
75
|
-
|
|
167
|
+
/*
|
|
168
|
+
* Create one isolated set of popover definition, event, and command atoms.
|
|
169
|
+
*/
|
|
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
|
+
};
|
|
76
257
|
}
|
|
77
258
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export type UpdateTooltipFn = (data: TooltipProps) => void;
|
|
259
|
+
const sharedPopOverState = createPopOverStateAtoms();
|
|
260
|
+
const inactivePopOverState = atom(false);
|
|
81
261
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
+
};
|
|
86
279
|
}
|
|
87
280
|
|
|
88
|
-
|
|
89
|
-
|
|
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
|
+
);
|
|
90
316
|
}
|
|
91
317
|
|
|
92
318
|
/**
|
|
93
|
-
*
|
|
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.
|
|
94
322
|
*/
|
|
95
323
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
open(data: PopOverProps): PopOverProps | null {
|
|
101
|
-
if (!data?.name) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
return data;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
update(data: UpdateStateParams, prev: PopOverProps | null): PopOverProps | null {
|
|
108
|
-
const { name, ...variables } = data;
|
|
109
|
-
const nextName = name || prev?.name
|
|
110
|
-
if (!nextName) {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
return {
|
|
114
|
-
...prev,
|
|
115
|
-
name: nextName,
|
|
116
|
-
variables,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
close(): PopOverProps | null {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
324
|
+
export function useResetPopOver() {
|
|
325
|
+
const setResetPopOver = useSetAtom(sharedPopOverState.resetState);
|
|
326
|
+
return useCallback(() => setResetPopOver(), []);
|
|
123
327
|
}
|
|
124
328
|
|
|
125
329
|
/**
|
|
126
|
-
*
|
|
330
|
+
* Read the active popover definition without subscribing to item events.
|
|
127
331
|
*/
|
|
128
332
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
readonly state = atom<TooltipProps | null>(null);
|
|
132
|
-
|
|
133
|
-
open(data: TooltipProps): TooltipProps | null {
|
|
134
|
-
if (!data?.id) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
return data;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
update(data: TooltipProps, prev: TooltipProps | null): TooltipProps | null {
|
|
141
|
-
if (!data || !prev) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
return {
|
|
145
|
-
...prev,
|
|
146
|
-
...data,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
close(): TooltipProps | null {
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
333
|
+
export function usePopOverDefinition() {
|
|
334
|
+
return useAtomValue(sharedPopOverState.definitionState);
|
|
153
335
|
}
|
|
154
336
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Hover state for pop overs
|
|
337
|
+
/*
|
|
338
|
+
* Read whether one popover id is active without subscribing the caller to the full definition object.
|
|
160
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
|
+
);
|
|
161
345
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
export function usePopOverIsHover() {
|
|
165
|
-
return useAtomValue(popOverIsHoverState);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function useSetPopOverIsHover() {
|
|
169
|
-
return useSetAtom(popOverIsHoverState);
|
|
346
|
+
return useAtomValue(isActiveState);
|
|
170
347
|
}
|
|
171
348
|
|
|
172
349
|
/**
|
|
173
|
-
*
|
|
350
|
+
* Read only events emitted by a requested popover id or open instance.
|
|
174
351
|
*/
|
|
175
352
|
|
|
176
|
-
function
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function composeClosePopOverFn(
|
|
188
|
-
setPopOver: (value: PopOverProps | null) => void,
|
|
189
|
-
setPopOverIsHover: (update: boolean | ((prev: boolean) => boolean)) => void,
|
|
190
|
-
popOver: PopOverProps | null
|
|
191
|
-
): ClosePopOverFn {
|
|
192
|
-
return (dismissIfName?: PopOverNames) => {
|
|
193
|
-
if (!popOver || (typeof dismissIfName === 'string' && popOver.name !== dismissIfName)) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
setPopOverIsHover(false);
|
|
197
|
-
setPopOver(popOverClass.close());
|
|
198
|
-
};
|
|
199
|
-
}
|
|
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
|
+
}
|
|
200
361
|
|
|
201
|
-
|
|
202
|
-
return (data: UpdateStateParams) => {
|
|
203
|
-
// @ts-expect-error - I couldn't get rid of this type error
|
|
204
|
-
setPopOver((prev: PopOverProps | null) => {
|
|
205
|
-
const nextPopOverState = popOverClass.update(data, prev);
|
|
206
|
-
if (nextPopOverState) {
|
|
207
|
-
return nextPopOverState;
|
|
208
|
-
}
|
|
209
|
-
console.warn('Invalid {popOver} data for update():', data);
|
|
210
|
-
return prev;
|
|
211
|
-
});
|
|
212
|
-
};
|
|
362
|
+
return event;
|
|
213
363
|
}
|
|
214
364
|
|
|
215
365
|
/**
|
|
216
|
-
* Use pop over
|
|
366
|
+
* Use close pop over function
|
|
217
367
|
*/
|
|
218
368
|
|
|
219
|
-
export function
|
|
220
|
-
|
|
221
|
-
const setPopOverIsHover = useSetAtom(popOverIsHoverState);
|
|
369
|
+
export function useClosePopOver(): ClosePopOverFn {
|
|
370
|
+
const setClosePopOver = useSetAtom(sharedPopOverState.closeState);
|
|
222
371
|
|
|
223
|
-
|
|
224
|
-
|
|
372
|
+
return useCallback((dismissIf) => setClosePopOver(dismissIf), []);
|
|
373
|
+
}
|
|
225
374
|
|
|
226
|
-
|
|
227
|
-
|
|
375
|
+
/*
|
|
376
|
+
* Return only the stable command used to open a popover.
|
|
377
|
+
*/
|
|
378
|
+
export function useOpenPopOver(): OpenPopOverFn {
|
|
379
|
+
const setOpenPopOver = useSetAtom(sharedPopOverState.openState);
|
|
228
380
|
|
|
229
|
-
|
|
230
|
-
popOver,
|
|
231
|
-
openPopOver,
|
|
232
|
-
closePopOver,
|
|
233
|
-
updatePopOver,
|
|
234
|
-
};
|
|
381
|
+
return useCallback((data) => setOpenPopOver(data), []);
|
|
235
382
|
}
|
|
236
383
|
|
|
237
384
|
/**
|
|
238
385
|
* Create handlers functions for tooltips
|
|
239
386
|
*/
|
|
240
387
|
|
|
241
|
-
function composeOpenTooltipFn(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
+
};
|
|
250
397
|
}
|
|
251
398
|
|
|
252
|
-
function composeCloseTooltipFn(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
+
};
|
|
266
413
|
}
|
|
267
414
|
|
|
268
|
-
function composeUpdateTooltipFn(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
+
};
|
|
280
428
|
}
|
|
281
429
|
|
|
282
430
|
/**
|
|
@@ -284,16 +432,16 @@ function composeUpdateTooltipFn( setTooltip: (value: TooltipProps | null) => voi
|
|
|
284
432
|
*/
|
|
285
433
|
|
|
286
434
|
export function useTooltip(): TooltipHookProps {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
+
};
|
|
299
447
|
}
|