@zag-js/toast 1.45.0 → 1.47.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/toast-group.machine.js +80 -22
- package/dist/toast-group.machine.mjs +81 -23
- package/dist/toast.connect.js +6 -5
- package/dist/toast.connect.mjs +6 -5
- package/dist/toast.dom.d.mts +12 -1
- package/dist/toast.dom.d.ts +12 -1
- package/dist/toast.dom.js +40 -2
- package/dist/toast.dom.mjs +35 -1
- package/dist/toast.machine.js +45 -33
- package/dist/toast.machine.mjs +46 -34
- package/dist/toast.store.js +107 -64
- package/dist/toast.store.mjs +108 -65
- package/dist/toast.types.d.mts +11 -4
- package/dist/toast.types.d.ts +11 -4
- package/dist/toast.utils.d.mts +3 -2
- package/dist/toast.utils.d.ts +3 -2
- package/dist/toast.utils.js +25 -4
- package/dist/toast.utils.mjs +23 -3
- package/package.json +7 -7
|
@@ -79,16 +79,22 @@ var groupMachine = createMachine({
|
|
|
79
79
|
overlap: ({ prop }) => prop("store").attrs.overlap,
|
|
80
80
|
placement: ({ prop }) => prop("store").attrs.placement
|
|
81
81
|
},
|
|
82
|
-
effects: ["subscribeToStore", "trackDocumentVisibility", "trackHotKeyPress"],
|
|
82
|
+
effects: ["subscribeToStore", "subscribeToLayout", "trackDocumentVisibility", "trackHotKeyPress"],
|
|
83
83
|
watch({ track, context, action }) {
|
|
84
84
|
track([() => context.hash("toasts")], () => {
|
|
85
85
|
queueMicrotask(() => {
|
|
86
|
-
action(["collapsedIfEmpty", "setDismissableBranch"]);
|
|
86
|
+
action(["collapsedIfEmpty", "setDismissableBranch", "resetInteractionIfEmpty"]);
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
89
|
},
|
|
90
90
|
exit: ["clearDismissableBranch", "clearLastFocusedEl", "clearMouseEventTimer"],
|
|
91
91
|
on: {
|
|
92
|
+
PAUSE_ALL: {
|
|
93
|
+
actions: ["pauseToasts"]
|
|
94
|
+
},
|
|
95
|
+
RESUME_ALL: {
|
|
96
|
+
actions: ["resumeToasts"]
|
|
97
|
+
},
|
|
92
98
|
"DOC.HOTKEY": {
|
|
93
99
|
actions: ["focusRegionEl"]
|
|
94
100
|
},
|
|
@@ -96,7 +102,7 @@ var groupMachine = createMachine({
|
|
|
96
102
|
{
|
|
97
103
|
guard: and("isOverlapping", "isPointerOut"),
|
|
98
104
|
target: "overlap",
|
|
99
|
-
actions: ["
|
|
105
|
+
actions: ["resumeToasts", "restoreFocusIfPointerOut"]
|
|
100
106
|
},
|
|
101
107
|
{
|
|
102
108
|
guard: "isPointerOut",
|
|
@@ -107,6 +113,9 @@ var groupMachine = createMachine({
|
|
|
107
113
|
actions: ["clearFocusWithin"]
|
|
108
114
|
}
|
|
109
115
|
],
|
|
116
|
+
"TOAST.DISMISS": {
|
|
117
|
+
actions: ["moveFocusOnDismiss"]
|
|
118
|
+
},
|
|
110
119
|
"TOAST.REMOVE": {
|
|
111
120
|
actions: ["removeToast", "removeHeight", "ignoreMouseEventsTemporarily"]
|
|
112
121
|
},
|
|
@@ -121,15 +130,14 @@ var groupMachine = createMachine({
|
|
|
121
130
|
{
|
|
122
131
|
guard: "isOverlapping",
|
|
123
132
|
target: "overlap",
|
|
124
|
-
actions: ["clearPointerWithin", "resumeToasts"
|
|
133
|
+
actions: ["clearPointerWithin", "resumeToasts"]
|
|
125
134
|
},
|
|
126
135
|
{
|
|
127
136
|
actions: ["clearPointerWithin", "resumeToasts"]
|
|
128
137
|
}
|
|
129
138
|
],
|
|
130
139
|
"REGION.OVERLAP": {
|
|
131
|
-
target: "overlap"
|
|
132
|
-
actions: ["collapseToasts"]
|
|
140
|
+
target: "overlap"
|
|
133
141
|
},
|
|
134
142
|
"REGION.FOCUS": {
|
|
135
143
|
actions: ["setLastFocusedEl", "pauseToasts"]
|
|
@@ -142,16 +150,18 @@ var groupMachine = createMachine({
|
|
|
142
150
|
overlap: {
|
|
143
151
|
on: {
|
|
144
152
|
"REGION.STACK": {
|
|
145
|
-
target: "stack"
|
|
146
|
-
actions: ["expandToasts"]
|
|
153
|
+
target: "stack"
|
|
147
154
|
},
|
|
148
155
|
"REGION.POINTER_ENTER": {
|
|
149
156
|
target: "stack",
|
|
150
|
-
actions: ["setPointerWithin", "pauseToasts"
|
|
157
|
+
actions: ["setPointerWithin", "pauseToasts"]
|
|
158
|
+
},
|
|
159
|
+
"REGION.POINTER_LEAVE": {
|
|
160
|
+
actions: ["clearPointerWithin", "resumeToasts"]
|
|
151
161
|
},
|
|
152
162
|
"REGION.FOCUS": {
|
|
153
163
|
target: "stack",
|
|
154
|
-
actions: ["setLastFocusedEl", "pauseToasts"
|
|
164
|
+
actions: ["setLastFocusedEl", "pauseToasts"]
|
|
155
165
|
}
|
|
156
166
|
}
|
|
157
167
|
}
|
|
@@ -179,6 +189,11 @@ var groupMachine = createMachine({
|
|
|
179
189
|
});
|
|
180
190
|
});
|
|
181
191
|
},
|
|
192
|
+
subscribeToLayout({ prop, send }) {
|
|
193
|
+
return prop("store").subscribeLayout((stacked) => {
|
|
194
|
+
send({ type: stacked ? "REGION.STACK" : "REGION.OVERLAP" });
|
|
195
|
+
});
|
|
196
|
+
},
|
|
182
197
|
trackHotKeyPress({ prop, send }) {
|
|
183
198
|
const handleKeyDown = (event) => {
|
|
184
199
|
const { hotkey } = prop("store").attrs;
|
|
@@ -192,6 +207,7 @@ var groupMachine = createMachine({
|
|
|
192
207
|
const { pauseOnPageIdle } = prop("store").attrs;
|
|
193
208
|
if (!pauseOnPageIdle) return;
|
|
194
209
|
const doc = scope.getDoc();
|
|
210
|
+
if (doc.visibilityState === "hidden") send({ type: "PAUSE_ALL" });
|
|
195
211
|
return (0, import_dom_query.addDomEvent)(doc, "visibilitychange", () => {
|
|
196
212
|
const isHidden = doc.visibilityState === "hidden";
|
|
197
213
|
send({ type: isHidden ? "PAUSE_ALL" : "RESUME_ALL" });
|
|
@@ -205,17 +221,19 @@ var groupMachine = createMachine({
|
|
|
205
221
|
const hasToasts = toasts.length > 0;
|
|
206
222
|
if (!hasToasts) {
|
|
207
223
|
refs.get("dismissableCleanup")?.();
|
|
224
|
+
refs.set("dismissableCleanup", void 0);
|
|
208
225
|
return;
|
|
209
226
|
}
|
|
210
227
|
if (hasToasts && refs.get("dismissableCleanup")) {
|
|
211
228
|
return;
|
|
212
229
|
}
|
|
213
230
|
const groupEl = () => dom.getRegionEl(scope, placement);
|
|
214
|
-
const cleanup = (0, import_dismissable.trackDismissableBranch)(groupEl, { defer: true });
|
|
231
|
+
const cleanup = (0, import_dismissable.trackDismissableBranch)(groupEl, { defer: true, getRootNode: scope.getRootNode });
|
|
215
232
|
refs.set("dismissableCleanup", cleanup);
|
|
216
233
|
},
|
|
217
234
|
clearDismissableBranch({ refs }) {
|
|
218
235
|
refs.get("dismissableCleanup")?.();
|
|
236
|
+
refs.set("dismissableCleanup", void 0);
|
|
219
237
|
},
|
|
220
238
|
focusRegionEl({ scope, computed }) {
|
|
221
239
|
queueMicrotask(() => {
|
|
@@ -225,15 +243,12 @@ var groupMachine = createMachine({
|
|
|
225
243
|
pauseToasts({ prop }) {
|
|
226
244
|
prop("store").pause();
|
|
227
245
|
},
|
|
228
|
-
resumeToasts({ prop }) {
|
|
246
|
+
resumeToasts({ prop, refs, scope, event }) {
|
|
247
|
+
if (event.type === "REGION.BLUR") refs.set("isFocusWithin", false);
|
|
248
|
+
const idle = prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden";
|
|
249
|
+
if (idle || refs.get("isPointerWithin") || refs.get("isFocusWithin")) return;
|
|
229
250
|
prop("store").resume();
|
|
230
251
|
},
|
|
231
|
-
expandToasts({ prop }) {
|
|
232
|
-
prop("store").expand();
|
|
233
|
-
},
|
|
234
|
-
collapseToasts({ prop }) {
|
|
235
|
-
prop("store").collapse();
|
|
236
|
-
},
|
|
237
252
|
removeToast({ prop, event }) {
|
|
238
253
|
prop("store").remove(event.id);
|
|
239
254
|
},
|
|
@@ -248,9 +263,34 @@ var groupMachine = createMachine({
|
|
|
248
263
|
send({ type: "REGION.OVERLAP" });
|
|
249
264
|
},
|
|
250
265
|
setLastFocusedEl({ refs, event }) {
|
|
251
|
-
if (refs.get("isFocusWithin")
|
|
266
|
+
if (refs.get("isFocusWithin")) return;
|
|
252
267
|
refs.set("isFocusWithin", true);
|
|
253
|
-
refs.set("lastFocusedEl", event.target);
|
|
268
|
+
refs.set("lastFocusedEl", event.target ?? null);
|
|
269
|
+
},
|
|
270
|
+
moveFocusOnDismiss({ refs, scope, computed, event }) {
|
|
271
|
+
if (event.focusVisible) {
|
|
272
|
+
const toastEls = dom.getToastEls(scope, computed("placement"));
|
|
273
|
+
const index = toastEls.findIndex((el) => (0, import_dom_query.contains)(el, scope.getActiveElement()));
|
|
274
|
+
const nextEl = findOpenToast(toastEls, index + 1, 1) ?? findOpenToast(toastEls, index - 1, -1);
|
|
275
|
+
if (nextEl) {
|
|
276
|
+
nextEl.focus({ preventScroll: true });
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const lastFocusedEl = refs.get("lastFocusedEl");
|
|
281
|
+
if (event.focusVisible && lastFocusedEl) {
|
|
282
|
+
lastFocusedEl.focus({ preventScroll: true });
|
|
283
|
+
} else {
|
|
284
|
+
scope.getActiveElement()?.blur();
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
resetInteractionIfEmpty({ refs, prop, scope, computed }) {
|
|
288
|
+
if (computed("count") > 0) return;
|
|
289
|
+
refs.set("isFocusWithin", false);
|
|
290
|
+
refs.set("isPointerWithin", false);
|
|
291
|
+
refs.set("lastFocusedEl", null);
|
|
292
|
+
const idle = prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden";
|
|
293
|
+
if (!idle) prop("store").resume();
|
|
254
294
|
},
|
|
255
295
|
restoreFocusIfPointerOut({ refs }) {
|
|
256
296
|
if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
|
|
@@ -277,8 +317,20 @@ var groupMachine = createMachine({
|
|
|
277
317
|
refs.set("lastFocusedEl", null);
|
|
278
318
|
refs.set("isFocusWithin", false);
|
|
279
319
|
},
|
|
280
|
-
ignoreMouseEventsTemporarily({ refs }) {
|
|
281
|
-
refs.get("ignoreMouseTimer").request()
|
|
320
|
+
ignoreMouseEventsTemporarily({ refs, scope, computed, send }) {
|
|
321
|
+
refs.get("ignoreMouseTimer").request(() => {
|
|
322
|
+
return (0, import_dom_query.addDomEvent)(
|
|
323
|
+
scope.getDoc(),
|
|
324
|
+
"pointermove",
|
|
325
|
+
(event) => {
|
|
326
|
+
if (!refs.get("isPointerWithin")) return;
|
|
327
|
+
const regionEl = dom.getRegionEl(scope, computed("placement"));
|
|
328
|
+
if ((0, import_dom_query.contains)(regionEl, (0, import_dom_query.getEventTarget)(event))) return;
|
|
329
|
+
send({ type: "REGION.POINTER_LEAVE", placement: computed("placement") });
|
|
330
|
+
},
|
|
331
|
+
{ once: true }
|
|
332
|
+
);
|
|
333
|
+
});
|
|
282
334
|
},
|
|
283
335
|
clearMouseEventTimer({ refs }) {
|
|
284
336
|
refs.get("ignoreMouseTimer").cancel();
|
|
@@ -286,6 +338,12 @@ var groupMachine = createMachine({
|
|
|
286
338
|
}
|
|
287
339
|
}
|
|
288
340
|
});
|
|
341
|
+
function findOpenToast(toastEls, from, step) {
|
|
342
|
+
for (let i = from; i >= 0 && i < toastEls.length; i += step) {
|
|
343
|
+
if (toastEls[i].dataset.state === "open") return toastEls[i];
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
289
347
|
// Annotate the CommonJS export names for ESM import in node:
|
|
290
348
|
0 && (module.exports = {
|
|
291
349
|
groupMachine
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/toast-group.machine.ts
|
|
2
2
|
import { setup } from "@zag-js/core";
|
|
3
3
|
import { trackDismissableBranch } from "@zag-js/dismissable";
|
|
4
|
-
import { addDomEvent, AnimationFrame } from "@zag-js/dom-query";
|
|
4
|
+
import { addDomEvent, AnimationFrame, contains, getEventTarget } from "@zag-js/dom-query";
|
|
5
5
|
import { uuid } from "@zag-js/utils";
|
|
6
6
|
import * as dom from "./toast.dom.mjs";
|
|
7
7
|
var { guards, createMachine } = setup();
|
|
@@ -45,16 +45,22 @@ var groupMachine = createMachine({
|
|
|
45
45
|
overlap: ({ prop }) => prop("store").attrs.overlap,
|
|
46
46
|
placement: ({ prop }) => prop("store").attrs.placement
|
|
47
47
|
},
|
|
48
|
-
effects: ["subscribeToStore", "trackDocumentVisibility", "trackHotKeyPress"],
|
|
48
|
+
effects: ["subscribeToStore", "subscribeToLayout", "trackDocumentVisibility", "trackHotKeyPress"],
|
|
49
49
|
watch({ track, context, action }) {
|
|
50
50
|
track([() => context.hash("toasts")], () => {
|
|
51
51
|
queueMicrotask(() => {
|
|
52
|
-
action(["collapsedIfEmpty", "setDismissableBranch"]);
|
|
52
|
+
action(["collapsedIfEmpty", "setDismissableBranch", "resetInteractionIfEmpty"]);
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
},
|
|
56
56
|
exit: ["clearDismissableBranch", "clearLastFocusedEl", "clearMouseEventTimer"],
|
|
57
57
|
on: {
|
|
58
|
+
PAUSE_ALL: {
|
|
59
|
+
actions: ["pauseToasts"]
|
|
60
|
+
},
|
|
61
|
+
RESUME_ALL: {
|
|
62
|
+
actions: ["resumeToasts"]
|
|
63
|
+
},
|
|
58
64
|
"DOC.HOTKEY": {
|
|
59
65
|
actions: ["focusRegionEl"]
|
|
60
66
|
},
|
|
@@ -62,7 +68,7 @@ var groupMachine = createMachine({
|
|
|
62
68
|
{
|
|
63
69
|
guard: and("isOverlapping", "isPointerOut"),
|
|
64
70
|
target: "overlap",
|
|
65
|
-
actions: ["
|
|
71
|
+
actions: ["resumeToasts", "restoreFocusIfPointerOut"]
|
|
66
72
|
},
|
|
67
73
|
{
|
|
68
74
|
guard: "isPointerOut",
|
|
@@ -73,6 +79,9 @@ var groupMachine = createMachine({
|
|
|
73
79
|
actions: ["clearFocusWithin"]
|
|
74
80
|
}
|
|
75
81
|
],
|
|
82
|
+
"TOAST.DISMISS": {
|
|
83
|
+
actions: ["moveFocusOnDismiss"]
|
|
84
|
+
},
|
|
76
85
|
"TOAST.REMOVE": {
|
|
77
86
|
actions: ["removeToast", "removeHeight", "ignoreMouseEventsTemporarily"]
|
|
78
87
|
},
|
|
@@ -87,15 +96,14 @@ var groupMachine = createMachine({
|
|
|
87
96
|
{
|
|
88
97
|
guard: "isOverlapping",
|
|
89
98
|
target: "overlap",
|
|
90
|
-
actions: ["clearPointerWithin", "resumeToasts"
|
|
99
|
+
actions: ["clearPointerWithin", "resumeToasts"]
|
|
91
100
|
},
|
|
92
101
|
{
|
|
93
102
|
actions: ["clearPointerWithin", "resumeToasts"]
|
|
94
103
|
}
|
|
95
104
|
],
|
|
96
105
|
"REGION.OVERLAP": {
|
|
97
|
-
target: "overlap"
|
|
98
|
-
actions: ["collapseToasts"]
|
|
106
|
+
target: "overlap"
|
|
99
107
|
},
|
|
100
108
|
"REGION.FOCUS": {
|
|
101
109
|
actions: ["setLastFocusedEl", "pauseToasts"]
|
|
@@ -108,16 +116,18 @@ var groupMachine = createMachine({
|
|
|
108
116
|
overlap: {
|
|
109
117
|
on: {
|
|
110
118
|
"REGION.STACK": {
|
|
111
|
-
target: "stack"
|
|
112
|
-
actions: ["expandToasts"]
|
|
119
|
+
target: "stack"
|
|
113
120
|
},
|
|
114
121
|
"REGION.POINTER_ENTER": {
|
|
115
122
|
target: "stack",
|
|
116
|
-
actions: ["setPointerWithin", "pauseToasts"
|
|
123
|
+
actions: ["setPointerWithin", "pauseToasts"]
|
|
124
|
+
},
|
|
125
|
+
"REGION.POINTER_LEAVE": {
|
|
126
|
+
actions: ["clearPointerWithin", "resumeToasts"]
|
|
117
127
|
},
|
|
118
128
|
"REGION.FOCUS": {
|
|
119
129
|
target: "stack",
|
|
120
|
-
actions: ["setLastFocusedEl", "pauseToasts"
|
|
130
|
+
actions: ["setLastFocusedEl", "pauseToasts"]
|
|
121
131
|
}
|
|
122
132
|
}
|
|
123
133
|
}
|
|
@@ -145,6 +155,11 @@ var groupMachine = createMachine({
|
|
|
145
155
|
});
|
|
146
156
|
});
|
|
147
157
|
},
|
|
158
|
+
subscribeToLayout({ prop, send }) {
|
|
159
|
+
return prop("store").subscribeLayout((stacked) => {
|
|
160
|
+
send({ type: stacked ? "REGION.STACK" : "REGION.OVERLAP" });
|
|
161
|
+
});
|
|
162
|
+
},
|
|
148
163
|
trackHotKeyPress({ prop, send }) {
|
|
149
164
|
const handleKeyDown = (event) => {
|
|
150
165
|
const { hotkey } = prop("store").attrs;
|
|
@@ -158,6 +173,7 @@ var groupMachine = createMachine({
|
|
|
158
173
|
const { pauseOnPageIdle } = prop("store").attrs;
|
|
159
174
|
if (!pauseOnPageIdle) return;
|
|
160
175
|
const doc = scope.getDoc();
|
|
176
|
+
if (doc.visibilityState === "hidden") send({ type: "PAUSE_ALL" });
|
|
161
177
|
return addDomEvent(doc, "visibilitychange", () => {
|
|
162
178
|
const isHidden = doc.visibilityState === "hidden";
|
|
163
179
|
send({ type: isHidden ? "PAUSE_ALL" : "RESUME_ALL" });
|
|
@@ -171,17 +187,19 @@ var groupMachine = createMachine({
|
|
|
171
187
|
const hasToasts = toasts.length > 0;
|
|
172
188
|
if (!hasToasts) {
|
|
173
189
|
refs.get("dismissableCleanup")?.();
|
|
190
|
+
refs.set("dismissableCleanup", void 0);
|
|
174
191
|
return;
|
|
175
192
|
}
|
|
176
193
|
if (hasToasts && refs.get("dismissableCleanup")) {
|
|
177
194
|
return;
|
|
178
195
|
}
|
|
179
196
|
const groupEl = () => dom.getRegionEl(scope, placement);
|
|
180
|
-
const cleanup = trackDismissableBranch(groupEl, { defer: true });
|
|
197
|
+
const cleanup = trackDismissableBranch(groupEl, { defer: true, getRootNode: scope.getRootNode });
|
|
181
198
|
refs.set("dismissableCleanup", cleanup);
|
|
182
199
|
},
|
|
183
200
|
clearDismissableBranch({ refs }) {
|
|
184
201
|
refs.get("dismissableCleanup")?.();
|
|
202
|
+
refs.set("dismissableCleanup", void 0);
|
|
185
203
|
},
|
|
186
204
|
focusRegionEl({ scope, computed }) {
|
|
187
205
|
queueMicrotask(() => {
|
|
@@ -191,15 +209,12 @@ var groupMachine = createMachine({
|
|
|
191
209
|
pauseToasts({ prop }) {
|
|
192
210
|
prop("store").pause();
|
|
193
211
|
},
|
|
194
|
-
resumeToasts({ prop }) {
|
|
212
|
+
resumeToasts({ prop, refs, scope, event }) {
|
|
213
|
+
if (event.type === "REGION.BLUR") refs.set("isFocusWithin", false);
|
|
214
|
+
const idle = prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden";
|
|
215
|
+
if (idle || refs.get("isPointerWithin") || refs.get("isFocusWithin")) return;
|
|
195
216
|
prop("store").resume();
|
|
196
217
|
},
|
|
197
|
-
expandToasts({ prop }) {
|
|
198
|
-
prop("store").expand();
|
|
199
|
-
},
|
|
200
|
-
collapseToasts({ prop }) {
|
|
201
|
-
prop("store").collapse();
|
|
202
|
-
},
|
|
203
218
|
removeToast({ prop, event }) {
|
|
204
219
|
prop("store").remove(event.id);
|
|
205
220
|
},
|
|
@@ -214,9 +229,34 @@ var groupMachine = createMachine({
|
|
|
214
229
|
send({ type: "REGION.OVERLAP" });
|
|
215
230
|
},
|
|
216
231
|
setLastFocusedEl({ refs, event }) {
|
|
217
|
-
if (refs.get("isFocusWithin")
|
|
232
|
+
if (refs.get("isFocusWithin")) return;
|
|
218
233
|
refs.set("isFocusWithin", true);
|
|
219
|
-
refs.set("lastFocusedEl", event.target);
|
|
234
|
+
refs.set("lastFocusedEl", event.target ?? null);
|
|
235
|
+
},
|
|
236
|
+
moveFocusOnDismiss({ refs, scope, computed, event }) {
|
|
237
|
+
if (event.focusVisible) {
|
|
238
|
+
const toastEls = dom.getToastEls(scope, computed("placement"));
|
|
239
|
+
const index = toastEls.findIndex((el) => contains(el, scope.getActiveElement()));
|
|
240
|
+
const nextEl = findOpenToast(toastEls, index + 1, 1) ?? findOpenToast(toastEls, index - 1, -1);
|
|
241
|
+
if (nextEl) {
|
|
242
|
+
nextEl.focus({ preventScroll: true });
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const lastFocusedEl = refs.get("lastFocusedEl");
|
|
247
|
+
if (event.focusVisible && lastFocusedEl) {
|
|
248
|
+
lastFocusedEl.focus({ preventScroll: true });
|
|
249
|
+
} else {
|
|
250
|
+
scope.getActiveElement()?.blur();
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
resetInteractionIfEmpty({ refs, prop, scope, computed }) {
|
|
254
|
+
if (computed("count") > 0) return;
|
|
255
|
+
refs.set("isFocusWithin", false);
|
|
256
|
+
refs.set("isPointerWithin", false);
|
|
257
|
+
refs.set("lastFocusedEl", null);
|
|
258
|
+
const idle = prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden";
|
|
259
|
+
if (!idle) prop("store").resume();
|
|
220
260
|
},
|
|
221
261
|
restoreFocusIfPointerOut({ refs }) {
|
|
222
262
|
if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
|
|
@@ -243,8 +283,20 @@ var groupMachine = createMachine({
|
|
|
243
283
|
refs.set("lastFocusedEl", null);
|
|
244
284
|
refs.set("isFocusWithin", false);
|
|
245
285
|
},
|
|
246
|
-
ignoreMouseEventsTemporarily({ refs }) {
|
|
247
|
-
refs.get("ignoreMouseTimer").request()
|
|
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
|
+
});
|
|
248
300
|
},
|
|
249
301
|
clearMouseEventTimer({ refs }) {
|
|
250
302
|
refs.get("ignoreMouseTimer").cancel();
|
|
@@ -252,6 +304,12 @@ var groupMachine = createMachine({
|
|
|
252
304
|
}
|
|
253
305
|
}
|
|
254
306
|
});
|
|
307
|
+
function findOpenToast(toastEls, from, step) {
|
|
308
|
+
for (let i = from; i >= 0 && i < toastEls.length; i += step) {
|
|
309
|
+
if (toastEls[i].dataset.state === "open") return toastEls[i];
|
|
310
|
+
}
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
255
313
|
export {
|
|
256
314
|
groupMachine
|
|
257
315
|
};
|
package/dist/toast.connect.js
CHANGED
|
@@ -47,10 +47,11 @@ function connect(service, normalize) {
|
|
|
47
47
|
const visible = state.hasTag("visible");
|
|
48
48
|
const paused = state.hasTag("paused");
|
|
49
49
|
const mounted = context.get("mounted");
|
|
50
|
+
const rendered = context.get("rendered");
|
|
50
51
|
const frontmost = computed("frontmost");
|
|
51
52
|
const placement = prop("parent").computed("placement");
|
|
52
53
|
const type = prop("type");
|
|
53
|
-
const stacked = prop("
|
|
54
|
+
const stacked = prop("parent").state.matches("stack");
|
|
54
55
|
const title = prop("title");
|
|
55
56
|
const description = prop("description");
|
|
56
57
|
const action = prop("action");
|
|
@@ -64,10 +65,10 @@ function connect(service, normalize) {
|
|
|
64
65
|
paused,
|
|
65
66
|
closable: !!prop("closable"),
|
|
66
67
|
pause() {
|
|
67
|
-
|
|
68
|
+
prop("parent").prop("store").pause(prop("id"));
|
|
68
69
|
},
|
|
69
70
|
resume() {
|
|
70
|
-
|
|
71
|
+
prop("parent").prop("store").resume(prop("id"));
|
|
71
72
|
},
|
|
72
73
|
dismiss() {
|
|
73
74
|
send({ type: "DISMISS", src: "programmatic" });
|
|
@@ -90,8 +91,8 @@ function connect(service, normalize) {
|
|
|
90
91
|
"data-overlap": (0, import_dom_query.dataAttr)(!stacked),
|
|
91
92
|
role: "status",
|
|
92
93
|
"aria-atomic": "true",
|
|
93
|
-
"aria-describedby": description ? dom.getDescriptionId(scope) : void 0,
|
|
94
|
-
"aria-labelledby": title ? dom.getTitleId(scope) : void 0,
|
|
94
|
+
"aria-describedby": description && rendered.description ? dom.getDescriptionId(scope) : void 0,
|
|
95
|
+
"aria-labelledby": title && rendered.title ? dom.getTitleId(scope) : void 0,
|
|
95
96
|
tabIndex: 0,
|
|
96
97
|
style: (0, import_toast2.getPlacementStyle)(service, visible),
|
|
97
98
|
onKeyDown(event) {
|
package/dist/toast.connect.mjs
CHANGED
|
@@ -13,10 +13,11 @@ function connect(service, normalize) {
|
|
|
13
13
|
const visible = state.hasTag("visible");
|
|
14
14
|
const paused = state.hasTag("paused");
|
|
15
15
|
const mounted = context.get("mounted");
|
|
16
|
+
const rendered = context.get("rendered");
|
|
16
17
|
const frontmost = computed("frontmost");
|
|
17
18
|
const placement = prop("parent").computed("placement");
|
|
18
19
|
const type = prop("type");
|
|
19
|
-
const stacked = prop("
|
|
20
|
+
const stacked = prop("parent").state.matches("stack");
|
|
20
21
|
const title = prop("title");
|
|
21
22
|
const description = prop("description");
|
|
22
23
|
const action = prop("action");
|
|
@@ -30,10 +31,10 @@ function connect(service, normalize) {
|
|
|
30
31
|
paused,
|
|
31
32
|
closable: !!prop("closable"),
|
|
32
33
|
pause() {
|
|
33
|
-
|
|
34
|
+
prop("parent").prop("store").pause(prop("id"));
|
|
34
35
|
},
|
|
35
36
|
resume() {
|
|
36
|
-
|
|
37
|
+
prop("parent").prop("store").resume(prop("id"));
|
|
37
38
|
},
|
|
38
39
|
dismiss() {
|
|
39
40
|
send({ type: "DISMISS", src: "programmatic" });
|
|
@@ -56,8 +57,8 @@ function connect(service, normalize) {
|
|
|
56
57
|
"data-overlap": dataAttr(!stacked),
|
|
57
58
|
role: "status",
|
|
58
59
|
"aria-atomic": "true",
|
|
59
|
-
"aria-describedby": description ? dom.getDescriptionId(scope) : void 0,
|
|
60
|
-
"aria-labelledby": title ? dom.getTitleId(scope) : void 0,
|
|
60
|
+
"aria-describedby": description && rendered.description ? dom.getDescriptionId(scope) : void 0,
|
|
61
|
+
"aria-labelledby": title && rendered.title ? dom.getTitleId(scope) : void 0,
|
|
61
62
|
tabIndex: 0,
|
|
62
63
|
style: getPlacementStyle(service, visible),
|
|
63
64
|
onKeyDown(event) {
|
package/dist/toast.dom.d.mts
CHANGED
|
@@ -5,10 +5,21 @@ import '@zag-js/dom-query';
|
|
|
5
5
|
|
|
6
6
|
declare const getRegionId: (placement: Placement) => string;
|
|
7
7
|
declare const getRegionEl: (ctx: Scope, placement: Placement) => HTMLElement | null;
|
|
8
|
+
declare const getToastEls: (ctx: Scope, placement: Placement) => HTMLElement[];
|
|
8
9
|
declare const getRootId: (ctx: Scope) => string;
|
|
9
10
|
declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
10
11
|
declare const getTitleId: (ctx: Scope) => string;
|
|
11
12
|
declare const getDescriptionId: (ctx: Scope) => string;
|
|
13
|
+
declare const getTitleEl: (ctx: Scope) => HTMLElement | null;
|
|
14
|
+
declare const getDescriptionEl: (ctx: Scope) => HTMLElement | null;
|
|
12
15
|
declare const getCloseTriggerId: (ctx: Scope) => string;
|
|
16
|
+
interface ObserveContentOptions {
|
|
17
|
+
filter?: ((el: Element) => boolean) | undefined;
|
|
18
|
+
/** Called when the content's size may have changed */
|
|
19
|
+
onChange: VoidFunction;
|
|
20
|
+
/** Called when the content's DOM changes */
|
|
21
|
+
onMutate?: VoidFunction | undefined;
|
|
22
|
+
}
|
|
23
|
+
declare function observeContent(rootEl: HTMLElement, options: ObserveContentOptions): () => void;
|
|
13
24
|
|
|
14
|
-
export { getCloseTriggerId, getDescriptionId, getRegionEl, getRegionId, getRootEl, getRootId, getTitleId };
|
|
25
|
+
export { getCloseTriggerId, getDescriptionEl, getDescriptionId, getRegionEl, getRegionId, getRootEl, getRootId, getTitleEl, getTitleId, getToastEls, observeContent };
|
package/dist/toast.dom.d.ts
CHANGED
|
@@ -5,10 +5,21 @@ import '@zag-js/dom-query';
|
|
|
5
5
|
|
|
6
6
|
declare const getRegionId: (placement: Placement) => string;
|
|
7
7
|
declare const getRegionEl: (ctx: Scope, placement: Placement) => HTMLElement | null;
|
|
8
|
+
declare const getToastEls: (ctx: Scope, placement: Placement) => HTMLElement[];
|
|
8
9
|
declare const getRootId: (ctx: Scope) => string;
|
|
9
10
|
declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
10
11
|
declare const getTitleId: (ctx: Scope) => string;
|
|
11
12
|
declare const getDescriptionId: (ctx: Scope) => string;
|
|
13
|
+
declare const getTitleEl: (ctx: Scope) => HTMLElement | null;
|
|
14
|
+
declare const getDescriptionEl: (ctx: Scope) => HTMLElement | null;
|
|
12
15
|
declare const getCloseTriggerId: (ctx: Scope) => string;
|
|
16
|
+
interface ObserveContentOptions {
|
|
17
|
+
filter?: ((el: Element) => boolean) | undefined;
|
|
18
|
+
/** Called when the content's size may have changed */
|
|
19
|
+
onChange: VoidFunction;
|
|
20
|
+
/** Called when the content's DOM changes */
|
|
21
|
+
onMutate?: VoidFunction | undefined;
|
|
22
|
+
}
|
|
23
|
+
declare function observeContent(rootEl: HTMLElement, options: ObserveContentOptions): () => void;
|
|
13
24
|
|
|
14
|
-
export { getCloseTriggerId, getDescriptionId, getRegionEl, getRegionId, getRootEl, getRootId, getTitleId };
|
|
25
|
+
export { getCloseTriggerId, getDescriptionEl, getDescriptionId, getRegionEl, getRegionId, getRootEl, getRootId, getTitleEl, getTitleId, getToastEls, observeContent };
|
package/dist/toast.dom.js
CHANGED
|
@@ -21,28 +21,66 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var toast_dom_exports = {};
|
|
22
22
|
__export(toast_dom_exports, {
|
|
23
23
|
getCloseTriggerId: () => getCloseTriggerId,
|
|
24
|
+
getDescriptionEl: () => getDescriptionEl,
|
|
24
25
|
getDescriptionId: () => getDescriptionId,
|
|
25
26
|
getRegionEl: () => getRegionEl,
|
|
26
27
|
getRegionId: () => getRegionId,
|
|
27
28
|
getRootEl: () => getRootEl,
|
|
28
29
|
getRootId: () => getRootId,
|
|
29
|
-
|
|
30
|
+
getTitleEl: () => getTitleEl,
|
|
31
|
+
getTitleId: () => getTitleId,
|
|
32
|
+
getToastEls: () => getToastEls,
|
|
33
|
+
observeContent: () => observeContent
|
|
30
34
|
});
|
|
31
35
|
module.exports = __toCommonJS(toast_dom_exports);
|
|
36
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
37
|
+
var import_utils = require("@zag-js/utils");
|
|
32
38
|
var getRegionId = (placement) => `toast-group:${placement}`;
|
|
33
39
|
var getRegionEl = (ctx, placement) => ctx.getById(`toast-group:${placement}`);
|
|
40
|
+
var getToastEls = (ctx, placement) => (0, import_dom_query.queryAll)(getRegionEl(ctx, placement), "[data-scope=toast][data-part=root]");
|
|
34
41
|
var getRootId = (ctx) => `toast:${ctx.id}`;
|
|
35
42
|
var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
36
43
|
var getTitleId = (ctx) => `toast:${ctx.id}:title`;
|
|
37
44
|
var getDescriptionId = (ctx) => `toast:${ctx.id}:description`;
|
|
45
|
+
var getTitleEl = (ctx) => ctx.getById(getTitleId(ctx));
|
|
46
|
+
var getDescriptionEl = (ctx) => ctx.getById(getDescriptionId(ctx));
|
|
38
47
|
var getCloseTriggerId = (ctx) => `toast${ctx.id}:close`;
|
|
48
|
+
function observeContent(rootEl, options) {
|
|
49
|
+
const { filter = () => true, onChange, onMutate } = options;
|
|
50
|
+
const win = (0, import_dom_query.getWindow)(rootEl);
|
|
51
|
+
const frame = import_dom_query.AnimationFrame.create();
|
|
52
|
+
const notify = () => frame.request(onChange);
|
|
53
|
+
let stopObservingChildren;
|
|
54
|
+
const observeChildren = () => {
|
|
55
|
+
stopObservingChildren?.();
|
|
56
|
+
const children = Array.from(rootEl.children).filter(filter);
|
|
57
|
+
stopObservingChildren = (0, import_utils.callAll)(...children.map((child) => import_dom_query.resizeObserverBorderBox.observe(child, notify)));
|
|
58
|
+
};
|
|
59
|
+
observeChildren();
|
|
60
|
+
const mutationObserver = new win.MutationObserver(() => {
|
|
61
|
+
frame.cancel();
|
|
62
|
+
onChange();
|
|
63
|
+
onMutate?.();
|
|
64
|
+
observeChildren();
|
|
65
|
+
});
|
|
66
|
+
mutationObserver.observe(rootEl, { childList: true, subtree: true, characterData: true });
|
|
67
|
+
return () => {
|
|
68
|
+
mutationObserver.disconnect();
|
|
69
|
+
stopObservingChildren?.();
|
|
70
|
+
frame.cancel();
|
|
71
|
+
};
|
|
72
|
+
}
|
|
39
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
74
|
0 && (module.exports = {
|
|
41
75
|
getCloseTriggerId,
|
|
76
|
+
getDescriptionEl,
|
|
42
77
|
getDescriptionId,
|
|
43
78
|
getRegionEl,
|
|
44
79
|
getRegionId,
|
|
45
80
|
getRootEl,
|
|
46
81
|
getRootId,
|
|
47
|
-
|
|
82
|
+
getTitleEl,
|
|
83
|
+
getTitleId,
|
|
84
|
+
getToastEls,
|
|
85
|
+
observeContent
|
|
48
86
|
});
|