@zag-js/tooltip 1.47.0 → 1.48.0
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/dist/index.d.mts +6 -9
- package/dist/index.d.ts +6 -9
- package/dist/index.js +12 -38
- package/dist/index.mjs +2 -7
- package/dist/tooltip.anatomy.d.mts +2 -6
- package/dist/tooltip.anatomy.d.ts +2 -6
- package/dist/tooltip.anatomy.js +8 -33
- package/dist/tooltip.anatomy.mjs +4 -7
- package/dist/tooltip.connect.d.mts +4 -8
- package/dist/tooltip.connect.d.ts +4 -8
- package/dist/tooltip.connect.js +179 -186
- package/dist/tooltip.connect.mjs +173 -149
- package/dist/tooltip.dom.d.mts +11 -14
- package/dist/tooltip.dom.d.ts +11 -14
- package/dist/tooltip.dom.js +31 -65
- package/dist/tooltip.dom.mjs +17 -30
- package/dist/tooltip.machine.d.mts +2 -8
- package/dist/tooltip.machine.d.ts +2 -8
- package/dist/tooltip.machine.js +423 -465
- package/dist/tooltip.machine.mjs +416 -427
- package/dist/tooltip.props.d.mts +3 -9
- package/dist/tooltip.props.d.ts +3 -9
- package/dist/tooltip.props.js +29 -54
- package/dist/tooltip.props.mjs +25 -28
- package/dist/tooltip.store.d.mts +5 -9
- package/dist/tooltip.store.d.ts +5 -9
- package/dist/tooltip.store.js +9 -33
- package/dist/tooltip.store.mjs +6 -8
- package/dist/tooltip.types.d.mts +146 -149
- package/dist/tooltip.types.d.ts +146 -149
- package/dist/tooltip.types.js +4 -18
- package/dist/tooltip.types.mjs +1 -0
- package/package.json +10 -10
package/dist/tooltip.machine.mjs
CHANGED
|
@@ -1,432 +1,421 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { getActiveTriggerEl, getPositionerEl } from "./tooltip.dom.mjs";
|
|
2
|
+
import { store } from "./tooltip.store.mjs";
|
|
3
3
|
import { addDomEvent, getOverflowAncestors, isComposingEvent } from "@zag-js/dom-query";
|
|
4
4
|
import { trackFocusVisible } from "@zag-js/focus-visible";
|
|
5
5
|
import { getPlacement } from "@zag-js/popper";
|
|
6
6
|
import { ensureProps } from "@zag-js/utils";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
},
|
|
421
|
-
waitForCloseDelay: ({ send, prop, event }) => {
|
|
422
|
-
const id = setTimeout(() => {
|
|
423
|
-
send({ type: "after.closeDelay", previousEvent: event });
|
|
424
|
-
}, prop("closeDelay"));
|
|
425
|
-
return () => clearTimeout(id);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
7
|
+
import { createGuards, createMachine } from "@zag-js/core";
|
|
8
|
+
// src/tooltip.machine.ts
|
|
9
|
+
const { and, not } = createGuards();
|
|
10
|
+
const machine = createMachine({
|
|
11
|
+
initialState: ({ prop }) => {
|
|
12
|
+
return prop("open") || prop("defaultOpen") ? "open" : "closed";
|
|
13
|
+
},
|
|
14
|
+
props({ props }) {
|
|
15
|
+
ensureProps(props, ["id"]);
|
|
16
|
+
const closeOnClick = props.closeOnClick ?? true;
|
|
17
|
+
const closeOnPointerDown = props.closeOnPointerDown ?? closeOnClick;
|
|
18
|
+
return {
|
|
19
|
+
openDelay: 400,
|
|
20
|
+
closeDelay: 150,
|
|
21
|
+
closeOnEscape: true,
|
|
22
|
+
interactive: false,
|
|
23
|
+
closeOnScroll: true,
|
|
24
|
+
disabled: false,
|
|
25
|
+
...props,
|
|
26
|
+
closeOnPointerDown,
|
|
27
|
+
closeOnClick,
|
|
28
|
+
positioning: {
|
|
29
|
+
placement: "bottom",
|
|
30
|
+
...props.positioning
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
effects: ["trackFocusVisible", "trackStore"],
|
|
35
|
+
exit: ["clearGlobalId"],
|
|
36
|
+
context: ({ bindable, prop, scope }) => ({
|
|
37
|
+
currentPlacement: bindable(() => ({ defaultValue: void 0 })),
|
|
38
|
+
hasPointerMoveOpened: bindable(() => ({ defaultValue: null })),
|
|
39
|
+
triggerValue: bindable(() => ({
|
|
40
|
+
defaultValue: prop("defaultTriggerValue") ?? null,
|
|
41
|
+
value: prop("triggerValue"),
|
|
42
|
+
onChange(value) {
|
|
43
|
+
const onTriggerValueChange = prop("onTriggerValueChange");
|
|
44
|
+
if (!onTriggerValueChange) return;
|
|
45
|
+
onTriggerValueChange({
|
|
46
|
+
value,
|
|
47
|
+
triggerElement: getActiveTriggerEl(scope, value)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}))
|
|
51
|
+
}),
|
|
52
|
+
watch({ track, action, prop }) {
|
|
53
|
+
track([() => prop("disabled")], () => {
|
|
54
|
+
action(["closeIfDisabled"]);
|
|
55
|
+
});
|
|
56
|
+
track([() => prop("open")], () => {
|
|
57
|
+
action(["toggleVisibility"]);
|
|
58
|
+
});
|
|
59
|
+
track([() => prop("triggerValue")], () => {
|
|
60
|
+
action(["repositionImmediate"]);
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
on: { "triggerValue.set": { actions: ["setTriggerValue", "repositionImmediate"] } },
|
|
64
|
+
states: {
|
|
65
|
+
closed: {
|
|
66
|
+
entry: ["clearGlobalId"],
|
|
67
|
+
on: {
|
|
68
|
+
"controlled.open": { target: "open" },
|
|
69
|
+
open: [{
|
|
70
|
+
guard: "isOpenControlled",
|
|
71
|
+
actions: ["setTriggerValue", "invokeOnOpen"]
|
|
72
|
+
}, {
|
|
73
|
+
target: "open",
|
|
74
|
+
actions: ["setTriggerValue", "invokeOnOpen"]
|
|
75
|
+
}],
|
|
76
|
+
"pointer.leave": { actions: ["clearPointerMoveOpened"] },
|
|
77
|
+
"pointer.move": [{
|
|
78
|
+
guard: and("noVisibleTooltip", not("hasPointerMoveOpened")),
|
|
79
|
+
target: "opening",
|
|
80
|
+
actions: ["setTriggerValue"]
|
|
81
|
+
}, {
|
|
82
|
+
guard: not("hasPointerMoveOpened"),
|
|
83
|
+
target: "open",
|
|
84
|
+
actions: [
|
|
85
|
+
"setPointerMoveOpened",
|
|
86
|
+
"invokeOnOpen",
|
|
87
|
+
"setTriggerValue"
|
|
88
|
+
]
|
|
89
|
+
}]
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
opening: {
|
|
93
|
+
effects: [
|
|
94
|
+
"trackScroll",
|
|
95
|
+
"trackPointerlockChange",
|
|
96
|
+
"waitForOpenDelay"
|
|
97
|
+
],
|
|
98
|
+
on: {
|
|
99
|
+
"after.openDelay": [{
|
|
100
|
+
guard: "isOpenControlled",
|
|
101
|
+
actions: ["setPointerMoveOpened", "invokeOnOpen"]
|
|
102
|
+
}, {
|
|
103
|
+
target: "open",
|
|
104
|
+
actions: ["setPointerMoveOpened", "invokeOnOpen"]
|
|
105
|
+
}],
|
|
106
|
+
"controlled.open": { target: "open" },
|
|
107
|
+
"controlled.close": { target: "closed" },
|
|
108
|
+
open: [{
|
|
109
|
+
guard: "isOpenControlled",
|
|
110
|
+
actions: ["setTriggerValue", "invokeOnOpen"]
|
|
111
|
+
}, {
|
|
112
|
+
target: "open",
|
|
113
|
+
actions: ["setTriggerValue", "invokeOnOpen"]
|
|
114
|
+
}],
|
|
115
|
+
"pointer.leave": [
|
|
116
|
+
{
|
|
117
|
+
guard: "isDisabled",
|
|
118
|
+
actions: ["clearPointerMoveOpened"]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
guard: "isOpenControlled",
|
|
122
|
+
actions: [
|
|
123
|
+
"clearPointerMoveOpened",
|
|
124
|
+
"invokeOnClose",
|
|
125
|
+
"toggleVisibility"
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
target: "closed",
|
|
130
|
+
actions: ["clearPointerMoveOpened", "invokeOnClose"]
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
close: [{
|
|
134
|
+
guard: "isOpenControlled",
|
|
135
|
+
actions: ["invokeOnClose", "toggleVisibility"]
|
|
136
|
+
}, {
|
|
137
|
+
target: "closed",
|
|
138
|
+
actions: ["invokeOnClose"]
|
|
139
|
+
}]
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
open: {
|
|
143
|
+
effects: [
|
|
144
|
+
"trackEscapeKey",
|
|
145
|
+
"trackScroll",
|
|
146
|
+
"trackPointerlockChange",
|
|
147
|
+
"trackPositioning"
|
|
148
|
+
],
|
|
149
|
+
entry: ["setGlobalId"],
|
|
150
|
+
on: {
|
|
151
|
+
"controlled.close": { target: "closed" },
|
|
152
|
+
close: [{
|
|
153
|
+
guard: "isOpenControlled",
|
|
154
|
+
actions: ["invokeOnClose"]
|
|
155
|
+
}, {
|
|
156
|
+
target: "closed",
|
|
157
|
+
actions: ["invokeOnClose"]
|
|
158
|
+
}],
|
|
159
|
+
"pointer.leave": [
|
|
160
|
+
{
|
|
161
|
+
guard: "isDisabled",
|
|
162
|
+
actions: ["clearPointerMoveOpened"]
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
guard: "isVisible",
|
|
166
|
+
target: "closing",
|
|
167
|
+
actions: ["clearPointerMoveOpened"]
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
guard: "isOpenControlled",
|
|
171
|
+
actions: ["clearPointerMoveOpened", "invokeOnClose"]
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
target: "closed",
|
|
175
|
+
actions: ["clearPointerMoveOpened", "invokeOnClose"]
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
"content.pointer.leave": {
|
|
179
|
+
guard: "isInteractive",
|
|
180
|
+
target: "closing"
|
|
181
|
+
},
|
|
182
|
+
"positioning.set": { actions: ["reposition"] },
|
|
183
|
+
"triggerValue.set": {
|
|
184
|
+
target: "closing",
|
|
185
|
+
actions: ["setTriggerValue", "immediateReopen"]
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
closing: {
|
|
190
|
+
effects: ["trackPositioning", "waitForCloseDelay"],
|
|
191
|
+
on: {
|
|
192
|
+
"after.closeDelay": [{
|
|
193
|
+
guard: "isOpenControlled",
|
|
194
|
+
actions: ["invokeOnClose"]
|
|
195
|
+
}, {
|
|
196
|
+
target: "closed",
|
|
197
|
+
actions: ["invokeOnClose"]
|
|
198
|
+
}],
|
|
199
|
+
"controlled.close": { target: "closed" },
|
|
200
|
+
"controlled.open": { target: "open" },
|
|
201
|
+
close: [{
|
|
202
|
+
guard: "isOpenControlled",
|
|
203
|
+
actions: ["invokeOnClose"]
|
|
204
|
+
}, {
|
|
205
|
+
target: "closed",
|
|
206
|
+
actions: ["invokeOnClose"]
|
|
207
|
+
}],
|
|
208
|
+
"pointer.move": [{
|
|
209
|
+
guard: "isOpenControlled",
|
|
210
|
+
actions: [
|
|
211
|
+
"setPointerMoveOpened",
|
|
212
|
+
"setTriggerValue",
|
|
213
|
+
"invokeOnOpen",
|
|
214
|
+
"toggleVisibility"
|
|
215
|
+
]
|
|
216
|
+
}, {
|
|
217
|
+
target: "open",
|
|
218
|
+
actions: [
|
|
219
|
+
"setPointerMoveOpened",
|
|
220
|
+
"setTriggerValue",
|
|
221
|
+
"invokeOnOpen"
|
|
222
|
+
]
|
|
223
|
+
}],
|
|
224
|
+
"triggerValue.set": {
|
|
225
|
+
target: "open",
|
|
226
|
+
actions: ["setTriggerValue", "repositionImmediate"]
|
|
227
|
+
},
|
|
228
|
+
reopen: { target: "open" },
|
|
229
|
+
"content.pointer.move": {
|
|
230
|
+
guard: "isInteractive",
|
|
231
|
+
target: "open"
|
|
232
|
+
},
|
|
233
|
+
"positioning.set": { actions: ["reposition"] }
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
implementations: {
|
|
238
|
+
guards: {
|
|
239
|
+
noVisibleTooltip: () => store.get("id") === null,
|
|
240
|
+
isVisible: ({ prop }) => prop("id") === store.get("id"),
|
|
241
|
+
isInteractive: ({ prop }) => !!prop("interactive"),
|
|
242
|
+
hasPointerMoveOpened: ({ context }) => !!context.get("hasPointerMoveOpened"),
|
|
243
|
+
isOpenControlled: ({ prop }) => prop("open") !== void 0,
|
|
244
|
+
isDisabled: ({ prop }) => !!prop("disabled")
|
|
245
|
+
},
|
|
246
|
+
actions: {
|
|
247
|
+
setGlobalId: ({ prop }) => {
|
|
248
|
+
const prevId = store.get("id");
|
|
249
|
+
const isInstant = prevId !== null && prevId !== prop("id");
|
|
250
|
+
store.update({
|
|
251
|
+
id: prop("id"),
|
|
252
|
+
prevId: isInstant ? prevId : null,
|
|
253
|
+
instant: isInstant
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
clearGlobalId: ({ prop }) => {
|
|
257
|
+
if (prop("id") === store.get("id")) store.update({
|
|
258
|
+
id: null,
|
|
259
|
+
prevId: null,
|
|
260
|
+
instant: false
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
invokeOnOpen: ({ prop }) => {
|
|
264
|
+
prop("onOpenChange")?.({ open: true });
|
|
265
|
+
},
|
|
266
|
+
invokeOnClose: ({ prop }) => {
|
|
267
|
+
prop("onOpenChange")?.({ open: false });
|
|
268
|
+
},
|
|
269
|
+
closeIfDisabled: ({ prop, send }) => {
|
|
270
|
+
if (!prop("disabled")) return;
|
|
271
|
+
send({
|
|
272
|
+
type: "close",
|
|
273
|
+
src: "disabled.change"
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
reposition: ({ context, event, prop, scope }) => {
|
|
277
|
+
if (event.type !== "positioning.set") return;
|
|
278
|
+
const getPositionerEl$1 = () => getPositionerEl(scope);
|
|
279
|
+
const getTriggerEl = () => getActiveTriggerEl(scope, context.get("triggerValue"));
|
|
280
|
+
getPlacement(getTriggerEl, getPositionerEl$1, {
|
|
281
|
+
...prop("positioning"),
|
|
282
|
+
...event.options,
|
|
283
|
+
listeners: false,
|
|
284
|
+
onComplete(data) {
|
|
285
|
+
context.set("currentPlacement", data.placement);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
},
|
|
289
|
+
repositionImmediate: ({ context, event, prop, scope }) => {
|
|
290
|
+
const triggerValue = event.value ?? context.get("triggerValue");
|
|
291
|
+
const getPositionerEl$2 = () => getPositionerEl(scope);
|
|
292
|
+
const getTriggerEl = () => getActiveTriggerEl(scope, triggerValue);
|
|
293
|
+
return getPlacement(getTriggerEl, getPositionerEl$2, {
|
|
294
|
+
...prop("positioning"),
|
|
295
|
+
onComplete(data) {
|
|
296
|
+
context.set("currentPlacement", data.placement);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
toggleVisibility: ({ prop, event, send }) => {
|
|
301
|
+
queueMicrotask(() => {
|
|
302
|
+
send({
|
|
303
|
+
type: prop("open") ? "controlled.open" : "controlled.close",
|
|
304
|
+
previousEvent: event
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
setPointerMoveOpened: ({ context, event }) => {
|
|
309
|
+
const triggerId = event.triggerId ?? event.previousEvent?.triggerId;
|
|
310
|
+
context.set("hasPointerMoveOpened", triggerId ?? null);
|
|
311
|
+
},
|
|
312
|
+
clearPointerMoveOpened: ({ context }) => {
|
|
313
|
+
context.set("hasPointerMoveOpened", null);
|
|
314
|
+
},
|
|
315
|
+
setTriggerValue: ({ context, event }) => {
|
|
316
|
+
if (event.value === void 0) return;
|
|
317
|
+
context.set("triggerValue", event.value);
|
|
318
|
+
},
|
|
319
|
+
immediateReopen: ({ send }) => {
|
|
320
|
+
queueMicrotask(() => {
|
|
321
|
+
send({ type: "reopen" });
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
effects: {
|
|
326
|
+
trackFocusVisible: ({ scope }) => {
|
|
327
|
+
return trackFocusVisible({ root: scope.getRootNode?.() });
|
|
328
|
+
},
|
|
329
|
+
trackPositioning: ({ context, prop, scope }) => {
|
|
330
|
+
if (!context.get("currentPlacement")) context.set("currentPlacement", prop("positioning").placement);
|
|
331
|
+
const getPositionerEl$3 = () => getPositionerEl(scope);
|
|
332
|
+
const getTriggerEl = () => getActiveTriggerEl(scope, context.get("triggerValue"));
|
|
333
|
+
return getPlacement(getTriggerEl, getPositionerEl$3, {
|
|
334
|
+
...prop("positioning"),
|
|
335
|
+
defer: true,
|
|
336
|
+
onComplete(data) {
|
|
337
|
+
context.set("currentPlacement", data.placement);
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
},
|
|
341
|
+
trackPointerlockChange: ({ send, scope }) => {
|
|
342
|
+
const doc = scope.getDoc();
|
|
343
|
+
const onChange = () => send({
|
|
344
|
+
type: "close",
|
|
345
|
+
src: "pointerlock:change"
|
|
346
|
+
});
|
|
347
|
+
return addDomEvent(doc, "pointerlockchange", onChange, false);
|
|
348
|
+
},
|
|
349
|
+
trackScroll: ({ send, prop, scope, context }) => {
|
|
350
|
+
if (!prop("closeOnScroll")) return;
|
|
351
|
+
const triggerValue = context.get("triggerValue");
|
|
352
|
+
const triggerEl = getActiveTriggerEl(scope, triggerValue);
|
|
353
|
+
if (!triggerEl) return;
|
|
354
|
+
const cleanups = getOverflowAncestors(triggerEl).map((overflowParent) => {
|
|
355
|
+
const onScroll = () => {
|
|
356
|
+
send({
|
|
357
|
+
type: "close",
|
|
358
|
+
src: "scroll"
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
return addDomEvent(overflowParent, "scroll", onScroll, {
|
|
362
|
+
passive: true,
|
|
363
|
+
capture: true
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
return () => {
|
|
367
|
+
cleanups.forEach((fn) => fn?.());
|
|
368
|
+
};
|
|
369
|
+
},
|
|
370
|
+
trackStore: ({ prop, send }) => {
|
|
371
|
+
let cleanup;
|
|
372
|
+
let cancelled = false;
|
|
373
|
+
queueMicrotask(() => {
|
|
374
|
+
if (cancelled) return;
|
|
375
|
+
cleanup = store.subscribe(() => {
|
|
376
|
+
if (store.get("id") !== prop("id")) send({
|
|
377
|
+
type: "close",
|
|
378
|
+
src: "id.change"
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
return () => {
|
|
383
|
+
cancelled = true;
|
|
384
|
+
cleanup?.();
|
|
385
|
+
};
|
|
386
|
+
},
|
|
387
|
+
trackEscapeKey: ({ send, prop }) => {
|
|
388
|
+
if (!prop("closeOnEscape")) return;
|
|
389
|
+
const onKeyDown = (event) => {
|
|
390
|
+
if (isComposingEvent(event)) return;
|
|
391
|
+
if (event.key !== "Escape") return;
|
|
392
|
+
event.stopPropagation();
|
|
393
|
+
send({
|
|
394
|
+
type: "close",
|
|
395
|
+
src: "keydown.escape"
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
return addDomEvent(document, "keydown", onKeyDown, true);
|
|
399
|
+
},
|
|
400
|
+
waitForOpenDelay: ({ send, prop, event }) => {
|
|
401
|
+
const id = setTimeout(() => {
|
|
402
|
+
send({
|
|
403
|
+
type: "after.openDelay",
|
|
404
|
+
previousEvent: event
|
|
405
|
+
});
|
|
406
|
+
}, prop("openDelay"));
|
|
407
|
+
return () => clearTimeout(id);
|
|
408
|
+
},
|
|
409
|
+
waitForCloseDelay: ({ send, prop, event }) => {
|
|
410
|
+
const id = setTimeout(() => {
|
|
411
|
+
send({
|
|
412
|
+
type: "after.closeDelay",
|
|
413
|
+
previousEvent: event
|
|
414
|
+
});
|
|
415
|
+
}, prop("closeDelay"));
|
|
416
|
+
return () => clearTimeout(id);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
429
420
|
});
|
|
430
|
-
export {
|
|
431
|
-
machine
|
|
432
|
-
};
|
|
421
|
+
export { machine };
|