@zag-js/toast 1.47.0 → 1.49.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 +67 -60
  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 +286 -309
  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 +126 -120
  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 +265 -262
  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,315 +1,292 @@
1
- // src/toast-group.machine.ts
2
1
  import { setup } from "@zag-js/core";
3
2
  import { trackDismissableBranch } from "@zag-js/dismissable";
4
- import { addDomEvent, AnimationFrame, contains, getEventTarget } from "@zag-js/dom-query";
3
+ import { AnimationFrame, addDomEvent, contains, getEventTarget } from "@zag-js/dom-query";
5
4
  import { uuid } from "@zag-js/utils";
6
- import * as dom from "./toast.dom.mjs";
7
- var { guards, createMachine } = setup();
8
- var { and } = guards;
9
- var 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: ["subscribeToStore", "subscribeToLayout", "trackDocumentVisibility", "trackHotKeyPress"],
49
- watch({ track, context, action }) {
50
- track([() => context.hash("toasts")], () => {
51
- queueMicrotask(() => {
52
- action(["collapsedIfEmpty", "setDismissableBranch", "resetInteractionIfEmpty"]);
53
- });
54
- });
55
- },
56
- exit: ["clearDismissableBranch", "clearLastFocusedEl", "clearMouseEventTimer"],
57
- on: {
58
- PAUSE_ALL: {
59
- actions: ["pauseToasts"]
60
- },
61
- RESUME_ALL: {
62
- actions: ["resumeToasts"]
63
- },
64
- "DOC.HOTKEY": {
65
- actions: ["focusRegionEl"]
66
- },
67
- "REGION.BLUR": [
68
- {
69
- guard: and("isOverlapping", "isPointerOut"),
70
- target: "overlap",
71
- actions: ["resumeToasts", "restoreFocusIfPointerOut"]
72
- },
73
- {
74
- guard: "isPointerOut",
75
- target: "stack",
76
- actions: ["resumeToasts", "restoreFocusIfPointerOut"]
77
- },
78
- {
79
- actions: ["clearFocusWithin"]
80
- }
81
- ],
82
- "TOAST.DISMISS": {
83
- actions: ["moveFocusOnDismiss"]
84
- },
85
- "TOAST.REMOVE": {
86
- actions: ["removeToast", "removeHeight", "ignoreMouseEventsTemporarily"]
87
- },
88
- "TOAST.PAUSE": {
89
- actions: ["pauseToasts"]
90
- }
91
- },
92
- states: {
93
- stack: {
94
- on: {
95
- "REGION.POINTER_LEAVE": [
96
- {
97
- guard: "isOverlapping",
98
- target: "overlap",
99
- actions: ["clearPointerWithin", "resumeToasts"]
100
- },
101
- {
102
- actions: ["clearPointerWithin", "resumeToasts"]
103
- }
104
- ],
105
- "REGION.OVERLAP": {
106
- target: "overlap"
107
- },
108
- "REGION.FOCUS": {
109
- actions: ["setLastFocusedEl", "pauseToasts"]
110
- },
111
- "REGION.POINTER_ENTER": {
112
- actions: ["setPointerWithin", "pauseToasts"]
113
- }
114
- }
115
- },
116
- overlap: {
117
- on: {
118
- "REGION.STACK": {
119
- target: "stack"
120
- },
121
- "REGION.POINTER_ENTER": {
122
- target: "stack",
123
- actions: ["setPointerWithin", "pauseToasts"]
124
- },
125
- "REGION.POINTER_LEAVE": {
126
- actions: ["clearPointerWithin", "resumeToasts"]
127
- },
128
- "REGION.FOCUS": {
129
- target: "stack",
130
- actions: ["setLastFocusedEl", "pauseToasts"]
131
- }
132
- }
133
- }
134
- },
135
- implementations: {
136
- guards: {
137
- isOverlapping: ({ computed }) => computed("overlap"),
138
- isPointerOut: ({ refs }) => !refs.get("isPointerWithin")
139
- },
140
- effects: {
141
- subscribeToStore({ context, prop }) {
142
- const store = prop("store");
143
- context.set("toasts", store.getVisibleToasts());
144
- return store.subscribe((toast) => {
145
- if (toast.dismiss) {
146
- context.set("toasts", (prev) => prev.filter((t) => t.id !== toast.id));
147
- return;
148
- }
149
- context.set("toasts", (prev) => {
150
- const index = prev.findIndex((t) => t.id === toast.id);
151
- if (index !== -1) {
152
- return [...prev.slice(0, index), { ...prev[index], ...toast }, ...prev.slice(index + 1)];
153
- }
154
- return [toast, ...prev];
155
- });
156
- });
157
- },
158
- subscribeToLayout({ prop, send }) {
159
- return prop("store").subscribeLayout((stacked) => {
160
- send({ type: stacked ? "REGION.STACK" : "REGION.OVERLAP" });
161
- });
162
- },
163
- trackHotKeyPress({ prop, send }) {
164
- const handleKeyDown = (event) => {
165
- const { hotkey } = prop("store").attrs;
166
- const isHotkeyPressed = hotkey.every((key) => event[key] || event.code === key);
167
- if (!isHotkeyPressed) return;
168
- send({ type: "DOC.HOTKEY" });
169
- };
170
- return addDomEvent(document, "keydown", handleKeyDown, { capture: true });
171
- },
172
- trackDocumentVisibility({ prop, send, scope }) {
173
- const { pauseOnPageIdle } = prop("store").attrs;
174
- if (!pauseOnPageIdle) return;
175
- const doc = scope.getDoc();
176
- if (doc.visibilityState === "hidden") send({ type: "PAUSE_ALL" });
177
- return addDomEvent(doc, "visibilitychange", () => {
178
- const isHidden = doc.visibilityState === "hidden";
179
- send({ type: isHidden ? "PAUSE_ALL" : "RESUME_ALL" });
180
- });
181
- }
182
- },
183
- actions: {
184
- setDismissableBranch({ refs, context, computed, scope }) {
185
- const toasts = context.get("toasts");
186
- const placement = computed("placement");
187
- const hasToasts = toasts.length > 0;
188
- if (!hasToasts) {
189
- refs.get("dismissableCleanup")?.();
190
- refs.set("dismissableCleanup", void 0);
191
- return;
192
- }
193
- if (hasToasts && refs.get("dismissableCleanup")) {
194
- return;
195
- }
196
- const groupEl = () => dom.getRegionEl(scope, placement);
197
- const cleanup = trackDismissableBranch(groupEl, { defer: true, getRootNode: scope.getRootNode });
198
- refs.set("dismissableCleanup", cleanup);
199
- },
200
- clearDismissableBranch({ refs }) {
201
- refs.get("dismissableCleanup")?.();
202
- refs.set("dismissableCleanup", void 0);
203
- },
204
- focusRegionEl({ scope, computed }) {
205
- queueMicrotask(() => {
206
- dom.getRegionEl(scope, computed("placement"))?.focus();
207
- });
208
- },
209
- pauseToasts({ prop }) {
210
- prop("store").pause();
211
- },
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;
216
- prop("store").resume();
217
- },
218
- removeToast({ prop, event }) {
219
- prop("store").remove(event.id);
220
- },
221
- removeHeight({ event, context }) {
222
- if (event?.id == null) return;
223
- queueMicrotask(() => {
224
- context.set("heights", (heights) => heights.filter((height) => height.id !== event.id));
225
- });
226
- },
227
- collapsedIfEmpty({ send, computed }) {
228
- if (!computed("overlap") || computed("count") > 1) return;
229
- send({ type: "REGION.OVERLAP" });
230
- },
231
- setLastFocusedEl({ refs, event }) {
232
- if (refs.get("isFocusWithin")) return;
233
- refs.set("isFocusWithin", true);
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();
260
- },
261
- restoreFocusIfPointerOut({ refs }) {
262
- if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
263
- refs.get("lastFocusedEl")?.focus({ preventScroll: true });
264
- refs.set("lastFocusedEl", null);
265
- refs.set("isFocusWithin", false);
266
- },
267
- setPointerWithin({ refs }) {
268
- refs.set("isPointerWithin", true);
269
- },
270
- clearPointerWithin({ refs }) {
271
- refs.set("isPointerWithin", false);
272
- if (refs.get("lastFocusedEl") && !refs.get("isFocusWithin")) {
273
- refs.get("lastFocusedEl")?.focus({ preventScroll: true });
274
- refs.set("lastFocusedEl", null);
275
- }
276
- },
277
- clearFocusWithin({ refs }) {
278
- refs.set("isFocusWithin", false);
279
- },
280
- clearLastFocusedEl({ refs }) {
281
- if (!refs.get("lastFocusedEl")) return;
282
- refs.get("lastFocusedEl")?.focus({ preventScroll: true });
283
- refs.set("lastFocusedEl", null);
284
- refs.set("isFocusWithin", false);
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
- }
5
+ import { getRegionEl, getToastEls } from "./toast.dom.mjs";
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
- 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;
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 };
@@ -1,6 +1,2 @@
1
- import * as _zag_js_anatomy from '@zag-js/anatomy';
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>;
@@ -1,6 +1,2 @@
1
- import * as _zag_js_anatomy from '@zag-js/anatomy';
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>;