@zag-js/toast 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 +10 -17
- package/dist/index.d.ts +10 -17
- package/dist/index.js +18 -45
- package/dist/index.mjs +5 -11
- package/dist/toast-group.connect.d.mts +4 -8
- package/dist/toast-group.connect.d.ts +4 -8
- package/dist/toast-group.connect.js +73 -97
- package/dist/toast-group.connect.mjs +68 -61
- package/dist/toast-group.machine.d.mts +2 -8
- package/dist/toast-group.machine.d.ts +2 -8
- package/dist/toast-group.machine.js +292 -346
- package/dist/toast-group.machine.mjs +287 -310
- package/dist/toast.anatomy.d.mts +2 -6
- package/dist/toast.anatomy.d.ts +2 -6
- package/dist/toast.anatomy.js +8 -40
- package/dist/toast.anatomy.mjs +4 -14
- package/dist/toast.connect.d.mts +4 -8
- package/dist/toast.connect.d.ts +4 -8
- package/dist/toast.connect.js +133 -158
- package/dist/toast.connect.mjs +128 -122
- package/dist/toast.dom.d.mts +19 -23
- package/dist/toast.dom.d.ts +19 -23
- package/dist/toast.dom.js +54 -83
- package/dist/toast.dom.mjs +39 -47
- package/dist/toast.machine.d.mts +2 -8
- package/dist/toast.machine.d.ts +2 -8
- package/dist/toast.machine.js +272 -300
- package/dist/toast.machine.mjs +267 -264
- package/dist/toast.store.d.mts +2 -8
- package/dist/toast.store.d.ts +2 -8
- package/dist/toast.store.js +344 -306
- package/dist/toast.store.mjs +340 -281
- package/dist/toast.types.d.mts +372 -374
- package/dist/toast.types.d.ts +372 -374
- package/dist/toast.types.js +4 -18
- package/dist/toast.types.mjs +1 -0
- package/dist/toast.utils.d.mts +10 -14
- package/dist/toast.utils.d.ts +10 -14
- package/dist/toast.utils.js +167 -217
- package/dist/toast.utils.mjs +157 -186
- package/package.json +9 -9
|
@@ -1,315 +1,292 @@
|
|
|
1
|
-
|
|
1
|
+
import { getRegionEl, getToastEls } from "./toast.dom.mjs";
|
|
2
|
+
import { AnimationFrame, addDomEvent, contains, getEventTarget } from "@zag-js/dom-query";
|
|
3
|
+
import { uuid } from "@zag-js/utils";
|
|
2
4
|
import { setup } from "@zag-js/core";
|
|
3
5
|
import { trackDismissableBranch } from "@zag-js/dismissable";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
ignoreMouseEventsTemporarily({ refs, scope, computed, send }) {
|
|
287
|
-
refs.get("ignoreMouseTimer").request(() => {
|
|
288
|
-
return addDomEvent(
|
|
289
|
-
scope.getDoc(),
|
|
290
|
-
"pointermove",
|
|
291
|
-
(event) => {
|
|
292
|
-
if (!refs.get("isPointerWithin")) return;
|
|
293
|
-
const regionEl = dom.getRegionEl(scope, computed("placement"));
|
|
294
|
-
if (contains(regionEl, getEventTarget(event))) return;
|
|
295
|
-
send({ type: "REGION.POINTER_LEAVE", placement: computed("placement") });
|
|
296
|
-
},
|
|
297
|
-
{ once: true }
|
|
298
|
-
);
|
|
299
|
-
});
|
|
300
|
-
},
|
|
301
|
-
clearMouseEventTimer({ refs }) {
|
|
302
|
-
refs.get("ignoreMouseTimer").cancel();
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
6
|
+
// src/toast-group.machine.ts
|
|
7
|
+
const { guards, createMachine } = setup();
|
|
8
|
+
const { and } = guards;
|
|
9
|
+
const groupMachine = createMachine({
|
|
10
|
+
props({ props }) {
|
|
11
|
+
return {
|
|
12
|
+
dir: "ltr",
|
|
13
|
+
id: uuid(),
|
|
14
|
+
...props,
|
|
15
|
+
store: props.store
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
initialState({ prop }) {
|
|
19
|
+
return prop("store").attrs.overlap ? "overlap" : "stack";
|
|
20
|
+
},
|
|
21
|
+
refs() {
|
|
22
|
+
return {
|
|
23
|
+
lastFocusedEl: null,
|
|
24
|
+
isFocusWithin: false,
|
|
25
|
+
isPointerWithin: false,
|
|
26
|
+
ignoreMouseTimer: AnimationFrame.create(),
|
|
27
|
+
dismissableCleanup: void 0
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
context({ bindable }) {
|
|
31
|
+
return {
|
|
32
|
+
toasts: bindable(() => ({
|
|
33
|
+
defaultValue: [],
|
|
34
|
+
sync: true,
|
|
35
|
+
hash: (toasts) => toasts.map((t) => t.id).join(",")
|
|
36
|
+
})),
|
|
37
|
+
heights: bindable(() => ({
|
|
38
|
+
defaultValue: [],
|
|
39
|
+
sync: true
|
|
40
|
+
}))
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
computed: {
|
|
44
|
+
count: ({ context }) => context.get("toasts").length,
|
|
45
|
+
overlap: ({ prop }) => prop("store").attrs.overlap,
|
|
46
|
+
placement: ({ prop }) => prop("store").attrs.placement
|
|
47
|
+
},
|
|
48
|
+
effects: [
|
|
49
|
+
"subscribeToStore",
|
|
50
|
+
"subscribeToLayout",
|
|
51
|
+
"trackDocumentVisibility",
|
|
52
|
+
"trackHotKeyPress"
|
|
53
|
+
],
|
|
54
|
+
watch({ track, context, action }) {
|
|
55
|
+
track([() => context.hash("toasts")], () => {
|
|
56
|
+
queueMicrotask(() => {
|
|
57
|
+
action([
|
|
58
|
+
"collapsedIfEmpty",
|
|
59
|
+
"setDismissableBranch",
|
|
60
|
+
"resetInteractionIfEmpty"
|
|
61
|
+
]);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
exit: [
|
|
66
|
+
"clearDismissableBranch",
|
|
67
|
+
"clearLastFocusedEl",
|
|
68
|
+
"clearMouseEventTimer"
|
|
69
|
+
],
|
|
70
|
+
on: {
|
|
71
|
+
PAUSE_ALL: { actions: ["pauseToasts"] },
|
|
72
|
+
RESUME_ALL: { actions: ["resumeToasts"] },
|
|
73
|
+
"DOC.HOTKEY": { actions: ["focusRegionEl"] },
|
|
74
|
+
"REGION.BLUR": [
|
|
75
|
+
{
|
|
76
|
+
guard: and("isOverlapping", "isPointerOut"),
|
|
77
|
+
target: "overlap",
|
|
78
|
+
actions: ["resumeToasts", "restoreFocusIfPointerOut"]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
guard: "isPointerOut",
|
|
82
|
+
target: "stack",
|
|
83
|
+
actions: ["resumeToasts", "restoreFocusIfPointerOut"]
|
|
84
|
+
},
|
|
85
|
+
{ actions: ["clearFocusWithin"] }
|
|
86
|
+
],
|
|
87
|
+
"TOAST.DISMISS": { actions: ["moveFocusOnDismiss"] },
|
|
88
|
+
"TOAST.REMOVE": { actions: [
|
|
89
|
+
"removeToast",
|
|
90
|
+
"removeHeight",
|
|
91
|
+
"ignoreMouseEventsTemporarily"
|
|
92
|
+
] },
|
|
93
|
+
"TOAST.PAUSE": { actions: ["pauseToasts"] }
|
|
94
|
+
},
|
|
95
|
+
states: {
|
|
96
|
+
stack: { on: {
|
|
97
|
+
"REGION.POINTER_LEAVE": [{
|
|
98
|
+
guard: "isOverlapping",
|
|
99
|
+
target: "overlap",
|
|
100
|
+
actions: ["clearPointerWithin", "resumeToasts"]
|
|
101
|
+
}, { actions: ["clearPointerWithin", "resumeToasts"] }],
|
|
102
|
+
"REGION.OVERLAP": { target: "overlap" },
|
|
103
|
+
"REGION.FOCUS": { actions: ["setLastFocusedEl", "pauseToasts"] },
|
|
104
|
+
"REGION.POINTER_ENTER": { actions: ["setPointerWithin", "pauseToasts"] }
|
|
105
|
+
} },
|
|
106
|
+
overlap: { on: {
|
|
107
|
+
"REGION.STACK": { target: "stack" },
|
|
108
|
+
"REGION.POINTER_ENTER": {
|
|
109
|
+
target: "stack",
|
|
110
|
+
actions: ["setPointerWithin", "pauseToasts"]
|
|
111
|
+
},
|
|
112
|
+
"REGION.POINTER_LEAVE": { actions: ["clearPointerWithin", "resumeToasts"] },
|
|
113
|
+
"REGION.FOCUS": {
|
|
114
|
+
target: "stack",
|
|
115
|
+
actions: ["setLastFocusedEl", "pauseToasts"]
|
|
116
|
+
}
|
|
117
|
+
} }
|
|
118
|
+
},
|
|
119
|
+
implementations: {
|
|
120
|
+
guards: {
|
|
121
|
+
isOverlapping: ({ computed }) => computed("overlap"),
|
|
122
|
+
isPointerOut: ({ refs }) => !refs.get("isPointerWithin")
|
|
123
|
+
},
|
|
124
|
+
effects: {
|
|
125
|
+
subscribeToStore({ context, prop }) {
|
|
126
|
+
const store = prop("store");
|
|
127
|
+
context.set("toasts", store.getVisibleToasts());
|
|
128
|
+
return store.subscribe((toast) => {
|
|
129
|
+
if (toast.dismiss) {
|
|
130
|
+
context.set("toasts", (prev) => prev.filter((t) => t.id !== toast.id));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
context.set("toasts", (prev) => {
|
|
134
|
+
const index = prev.findIndex((t) => t.id === toast.id);
|
|
135
|
+
if (index !== -1) return [
|
|
136
|
+
...prev.slice(0, index),
|
|
137
|
+
{
|
|
138
|
+
...prev[index],
|
|
139
|
+
...toast
|
|
140
|
+
},
|
|
141
|
+
...prev.slice(index + 1)
|
|
142
|
+
];
|
|
143
|
+
return [toast, ...prev];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
subscribeToLayout({ prop, send }) {
|
|
148
|
+
return prop("store").subscribeLayout((stacked) => {
|
|
149
|
+
send({ type: stacked ? "REGION.STACK" : "REGION.OVERLAP" });
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
trackHotKeyPress({ prop, send }) {
|
|
153
|
+
const handleKeyDown = (event) => {
|
|
154
|
+
const { hotkey } = prop("store").attrs;
|
|
155
|
+
if (!hotkey.every((key) => event[key] || event.code === key)) return;
|
|
156
|
+
send({ type: "DOC.HOTKEY" });
|
|
157
|
+
};
|
|
158
|
+
return addDomEvent(document, "keydown", handleKeyDown, { capture: true });
|
|
159
|
+
},
|
|
160
|
+
trackDocumentVisibility({ prop, send, scope }) {
|
|
161
|
+
const { pauseOnPageIdle } = prop("store").attrs;
|
|
162
|
+
if (!pauseOnPageIdle) return;
|
|
163
|
+
const doc = scope.getDoc();
|
|
164
|
+
if (doc.visibilityState === "hidden") send({ type: "PAUSE_ALL" });
|
|
165
|
+
return addDomEvent(doc, "visibilitychange", () => {
|
|
166
|
+
send({ type: doc.visibilityState === "hidden" ? "PAUSE_ALL" : "RESUME_ALL" });
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
actions: {
|
|
171
|
+
setDismissableBranch({ refs, context, computed, scope }) {
|
|
172
|
+
const toasts = context.get("toasts");
|
|
173
|
+
const placement = computed("placement");
|
|
174
|
+
const hasToasts = toasts.length > 0;
|
|
175
|
+
if (!hasToasts) {
|
|
176
|
+
refs.get("dismissableCleanup")?.();
|
|
177
|
+
refs.set("dismissableCleanup", void 0);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (hasToasts && refs.get("dismissableCleanup")) return;
|
|
181
|
+
const groupEl = () => getRegionEl(scope, placement);
|
|
182
|
+
const cleanup = trackDismissableBranch(groupEl, {
|
|
183
|
+
defer: true,
|
|
184
|
+
getRootNode: scope.getRootNode
|
|
185
|
+
});
|
|
186
|
+
refs.set("dismissableCleanup", cleanup);
|
|
187
|
+
},
|
|
188
|
+
clearDismissableBranch({ refs }) {
|
|
189
|
+
refs.get("dismissableCleanup")?.();
|
|
190
|
+
refs.set("dismissableCleanup", void 0);
|
|
191
|
+
},
|
|
192
|
+
focusRegionEl({ scope, computed }) {
|
|
193
|
+
queueMicrotask(() => {
|
|
194
|
+
getRegionEl(scope, computed("placement"))?.focus();
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
pauseToasts({ prop }) {
|
|
198
|
+
prop("store").pause();
|
|
199
|
+
},
|
|
200
|
+
resumeToasts({ prop, refs, scope, event }) {
|
|
201
|
+
if (event.type === "REGION.BLUR") refs.set("isFocusWithin", false);
|
|
202
|
+
if (prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden" || refs.get("isPointerWithin") || refs.get("isFocusWithin")) return;
|
|
203
|
+
prop("store").resume();
|
|
204
|
+
},
|
|
205
|
+
removeToast({ prop, event }) {
|
|
206
|
+
prop("store").remove(event.id);
|
|
207
|
+
},
|
|
208
|
+
removeHeight({ event, context }) {
|
|
209
|
+
if (event?.id == null) return;
|
|
210
|
+
queueMicrotask(() => {
|
|
211
|
+
context.set("heights", (heights) => heights.filter((height) => height.id !== event.id));
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
collapsedIfEmpty({ send, computed }) {
|
|
215
|
+
if (!computed("overlap") || computed("count") > 1) return;
|
|
216
|
+
send({ type: "REGION.OVERLAP" });
|
|
217
|
+
},
|
|
218
|
+
setLastFocusedEl({ refs, event }) {
|
|
219
|
+
if (refs.get("isFocusWithin")) return;
|
|
220
|
+
refs.set("isFocusWithin", true);
|
|
221
|
+
refs.set("lastFocusedEl", event.target ?? null);
|
|
222
|
+
},
|
|
223
|
+
moveFocusOnDismiss({ refs, scope, computed, event }) {
|
|
224
|
+
if (event.focusVisible) {
|
|
225
|
+
const toastEls = getToastEls(scope, computed("placement"));
|
|
226
|
+
const index = toastEls.findIndex((el) => contains(el, scope.getActiveElement()));
|
|
227
|
+
const nextEl = findOpenToast(toastEls, index + 1, 1) ?? findOpenToast(toastEls, index - 1, -1);
|
|
228
|
+
if (nextEl) {
|
|
229
|
+
nextEl.focus({ preventScroll: true });
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const lastFocusedEl = refs.get("lastFocusedEl");
|
|
234
|
+
if (event.focusVisible && lastFocusedEl) lastFocusedEl.focus({ preventScroll: true });
|
|
235
|
+
else scope.getActiveElement()?.blur();
|
|
236
|
+
},
|
|
237
|
+
resetInteractionIfEmpty({ refs, prop, scope, computed }) {
|
|
238
|
+
if (computed("count") > 0) return;
|
|
239
|
+
refs.set("isFocusWithin", false);
|
|
240
|
+
refs.set("isPointerWithin", false);
|
|
241
|
+
refs.set("lastFocusedEl", null);
|
|
242
|
+
if (!(prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden")) prop("store").resume();
|
|
243
|
+
},
|
|
244
|
+
restoreFocusIfPointerOut({ refs }) {
|
|
245
|
+
if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
|
|
246
|
+
refs.get("lastFocusedEl")?.focus({ preventScroll: true });
|
|
247
|
+
refs.set("lastFocusedEl", null);
|
|
248
|
+
refs.set("isFocusWithin", false);
|
|
249
|
+
},
|
|
250
|
+
setPointerWithin({ refs }) {
|
|
251
|
+
refs.set("isPointerWithin", true);
|
|
252
|
+
},
|
|
253
|
+
clearPointerWithin({ refs }) {
|
|
254
|
+
refs.set("isPointerWithin", false);
|
|
255
|
+
if (refs.get("lastFocusedEl") && !refs.get("isFocusWithin")) {
|
|
256
|
+
refs.get("lastFocusedEl")?.focus({ preventScroll: true });
|
|
257
|
+
refs.set("lastFocusedEl", null);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
clearFocusWithin({ refs }) {
|
|
261
|
+
refs.set("isFocusWithin", false);
|
|
262
|
+
},
|
|
263
|
+
clearLastFocusedEl({ refs }) {
|
|
264
|
+
if (!refs.get("lastFocusedEl")) return;
|
|
265
|
+
refs.get("lastFocusedEl")?.focus({ preventScroll: true });
|
|
266
|
+
refs.set("lastFocusedEl", null);
|
|
267
|
+
refs.set("isFocusWithin", false);
|
|
268
|
+
},
|
|
269
|
+
ignoreMouseEventsTemporarily({ refs, scope, computed, send }) {
|
|
270
|
+
refs.get("ignoreMouseTimer").request(() => {
|
|
271
|
+
return addDomEvent(scope.getDoc(), "pointermove", (event) => {
|
|
272
|
+
if (!refs.get("isPointerWithin")) return;
|
|
273
|
+
const regionEl = getRegionEl(scope, computed("placement"));
|
|
274
|
+
if (contains(regionEl, getEventTarget(event))) return;
|
|
275
|
+
send({
|
|
276
|
+
type: "REGION.POINTER_LEAVE",
|
|
277
|
+
placement: computed("placement")
|
|
278
|
+
});
|
|
279
|
+
}, { once: true });
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
clearMouseEventTimer({ refs }) {
|
|
283
|
+
refs.get("ignoreMouseTimer").cancel();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
306
287
|
});
|
|
307
288
|
function findOpenToast(toastEls, from, step) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
return null;
|
|
289
|
+
for (let i = from; i >= 0 && i < toastEls.length; i += step) if (toastEls[i].dataset.state === "open") return toastEls[i];
|
|
290
|
+
return null;
|
|
312
291
|
}
|
|
313
|
-
export {
|
|
314
|
-
groupMachine
|
|
315
|
-
};
|
|
292
|
+
export { groupMachine };
|
package/dist/toast.anatomy.d.mts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"group" | "title" | "root" | "description" | "actionTrigger" | "closeTrigger">;
|
|
4
|
-
declare const parts: Record<"group" | "title" | "root" | "description" | "actionTrigger" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
-
|
|
6
|
-
export { anatomy, parts };
|
|
1
|
+
export declare const anatomy: import("@zag-js/anatomy").AnatomyInstance<"actionTrigger" | "closeTrigger" | "description" | "group" | "root" | "title">;
|
|
2
|
+
export declare const parts: Record<"actionTrigger" | "closeTrigger" | "description" | "group" | "root" | "title", import("@zag-js/anatomy").AnatomyPart>;
|
package/dist/toast.anatomy.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"group" | "title" | "root" | "description" | "actionTrigger" | "closeTrigger">;
|
|
4
|
-
declare const parts: Record<"group" | "title" | "root" | "description" | "actionTrigger" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
-
|
|
6
|
-
export { anatomy, parts };
|
|
1
|
+
export declare const anatomy: import("@zag-js/anatomy").AnatomyInstance<"actionTrigger" | "closeTrigger" | "description" | "group" | "root" | "title">;
|
|
2
|
+
export declare const parts: Record<"actionTrigger" | "closeTrigger" | "description" | "group" | "root" | "title", import("@zag-js/anatomy").AnatomyPart>;
|