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