@zag-js/toast 1.26.2 → 1.26.4
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 +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +47 -13
- package/dist/index.mjs +49 -15
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _zag_js_core from '@zag-js/core';
|
|
2
2
|
import { EventObject, Machine, Service } from '@zag-js/core';
|
|
3
3
|
import { DirectionProperty, CommonProperties, Required, Direction, RequiredBy, PropTypes, NormalizeProps } from '@zag-js/types';
|
|
4
|
+
import { AnimationFrame } from '@zag-js/dom-query';
|
|
4
5
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
5
6
|
|
|
6
7
|
type Type = "success" | "error" | "loading" | "info" | (string & {});
|
|
@@ -188,6 +189,8 @@ type ToastGroupSchema = {
|
|
|
188
189
|
dismissableCleanup?: VoidFunction | undefined;
|
|
189
190
|
lastFocusedEl: HTMLElement | null;
|
|
190
191
|
isFocusWithin: boolean;
|
|
192
|
+
isPointerWithin: boolean;
|
|
193
|
+
ignoreMouseTimer: AnimationFrame;
|
|
191
194
|
};
|
|
192
195
|
guard: string;
|
|
193
196
|
effect: string;
|
|
@@ -353,7 +356,7 @@ interface ToastApi<T extends PropTypes = PropTypes, O = any> {
|
|
|
353
356
|
|
|
354
357
|
declare function groupConnect<T extends PropTypes, O = any>(service: Service<ToastGroupSchema>, normalize: NormalizeProps<T>): ToastGroupApi<T, O>;
|
|
355
358
|
|
|
356
|
-
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"
|
|
359
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"group" | "title" | "root" | "description" | "actionTrigger" | "closeTrigger">;
|
|
357
360
|
|
|
358
361
|
declare function connect<T extends PropTypes, O>(service: Service<ToastSchema<O>>, normalize: NormalizeProps<T>): ToastApi<T, O>;
|
|
359
362
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _zag_js_core from '@zag-js/core';
|
|
2
2
|
import { EventObject, Machine, Service } from '@zag-js/core';
|
|
3
3
|
import { DirectionProperty, CommonProperties, Required, Direction, RequiredBy, PropTypes, NormalizeProps } from '@zag-js/types';
|
|
4
|
+
import { AnimationFrame } from '@zag-js/dom-query';
|
|
4
5
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
5
6
|
|
|
6
7
|
type Type = "success" | "error" | "loading" | "info" | (string & {});
|
|
@@ -188,6 +189,8 @@ type ToastGroupSchema = {
|
|
|
188
189
|
dismissableCleanup?: VoidFunction | undefined;
|
|
189
190
|
lastFocusedEl: HTMLElement | null;
|
|
190
191
|
isFocusWithin: boolean;
|
|
192
|
+
isPointerWithin: boolean;
|
|
193
|
+
ignoreMouseTimer: AnimationFrame;
|
|
191
194
|
};
|
|
192
195
|
guard: string;
|
|
193
196
|
effect: string;
|
|
@@ -353,7 +356,7 @@ interface ToastApi<T extends PropTypes = PropTypes, O = any> {
|
|
|
353
356
|
|
|
354
357
|
declare function groupConnect<T extends PropTypes, O = any>(service: Service<ToastGroupSchema>, normalize: NormalizeProps<T>): ToastGroupApi<T, O>;
|
|
355
358
|
|
|
356
|
-
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"
|
|
359
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"group" | "title" | "root" | "description" | "actionTrigger" | "closeTrigger">;
|
|
357
360
|
|
|
358
361
|
declare function connect<T extends PropTypes, O>(service: Service<ToastSchema<O>>, normalize: NormalizeProps<T>): ToastApi<T, O>;
|
|
359
362
|
|
package/dist/index.js
CHANGED
|
@@ -219,10 +219,16 @@ function groupConnect(service, normalize) {
|
|
|
219
219
|
"aria-live": "polite",
|
|
220
220
|
role: "region",
|
|
221
221
|
style: getGroupPlacementStyle(service, placement),
|
|
222
|
+
onMouseEnter() {
|
|
223
|
+
if (refs.get("ignoreMouseTimer").isActive()) return;
|
|
224
|
+
send({ type: "REGION.POINTER_ENTER", placement });
|
|
225
|
+
},
|
|
222
226
|
onMouseMove() {
|
|
227
|
+
if (refs.get("ignoreMouseTimer").isActive()) return;
|
|
223
228
|
send({ type: "REGION.POINTER_ENTER", placement });
|
|
224
229
|
},
|
|
225
230
|
onMouseLeave() {
|
|
231
|
+
if (refs.get("ignoreMouseTimer").isActive()) return;
|
|
226
232
|
send({ type: "REGION.POINTER_LEAVE", placement });
|
|
227
233
|
},
|
|
228
234
|
onFocus(event) {
|
|
@@ -241,7 +247,9 @@ function groupConnect(service, normalize) {
|
|
|
241
247
|
}
|
|
242
248
|
};
|
|
243
249
|
}
|
|
244
|
-
var
|
|
250
|
+
var { guards, createMachine } = core.setup();
|
|
251
|
+
var { and } = guards;
|
|
252
|
+
var groupMachine = createMachine({
|
|
245
253
|
props({ props }) {
|
|
246
254
|
return {
|
|
247
255
|
dir: "ltr",
|
|
@@ -257,6 +265,8 @@ var groupMachine = core.createMachine({
|
|
|
257
265
|
return {
|
|
258
266
|
lastFocusedEl: null,
|
|
259
267
|
isFocusWithin: false,
|
|
268
|
+
isPointerWithin: false,
|
|
269
|
+
ignoreMouseTimer: domQuery.AnimationFrame.create(),
|
|
260
270
|
dismissableCleanup: void 0
|
|
261
271
|
};
|
|
262
272
|
},
|
|
@@ -286,24 +296,28 @@ var groupMachine = core.createMachine({
|
|
|
286
296
|
});
|
|
287
297
|
});
|
|
288
298
|
},
|
|
289
|
-
exit: ["clearDismissableBranch", "clearLastFocusedEl"],
|
|
299
|
+
exit: ["clearDismissableBranch", "clearLastFocusedEl", "clearMouseEventTimer"],
|
|
290
300
|
on: {
|
|
291
301
|
"DOC.HOTKEY": {
|
|
292
302
|
actions: ["focusRegionEl"]
|
|
293
303
|
},
|
|
294
304
|
"REGION.BLUR": [
|
|
295
305
|
{
|
|
296
|
-
guard: "isOverlapping",
|
|
306
|
+
guard: and("isOverlapping", "isPointerOut"),
|
|
297
307
|
target: "overlap",
|
|
298
|
-
actions: ["collapseToasts", "resumeToasts", "
|
|
308
|
+
actions: ["collapseToasts", "resumeToasts", "restoreFocusIfPointerOut"]
|
|
299
309
|
},
|
|
300
310
|
{
|
|
311
|
+
guard: "isPointerOut",
|
|
301
312
|
target: "stack",
|
|
302
|
-
actions: ["resumeToasts", "
|
|
313
|
+
actions: ["resumeToasts", "restoreFocusIfPointerOut"]
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
actions: ["clearFocusWithin"]
|
|
303
317
|
}
|
|
304
318
|
],
|
|
305
319
|
"TOAST.REMOVE": {
|
|
306
|
-
actions: ["removeToast", "removeHeight"]
|
|
320
|
+
actions: ["removeToast", "removeHeight", "ignoreMouseEventsTemporarily"]
|
|
307
321
|
},
|
|
308
322
|
"TOAST.PAUSE": {
|
|
309
323
|
actions: ["pauseToasts"]
|
|
@@ -316,10 +330,10 @@ var groupMachine = core.createMachine({
|
|
|
316
330
|
{
|
|
317
331
|
guard: "isOverlapping",
|
|
318
332
|
target: "overlap",
|
|
319
|
-
actions: ["resumeToasts", "collapseToasts"]
|
|
333
|
+
actions: ["clearPointerWithin", "resumeToasts", "collapseToasts"]
|
|
320
334
|
},
|
|
321
335
|
{
|
|
322
|
-
actions: ["resumeToasts"]
|
|
336
|
+
actions: ["clearPointerWithin", "resumeToasts"]
|
|
323
337
|
}
|
|
324
338
|
],
|
|
325
339
|
"REGION.OVERLAP": {
|
|
@@ -330,7 +344,7 @@ var groupMachine = core.createMachine({
|
|
|
330
344
|
actions: ["setLastFocusedEl", "pauseToasts"]
|
|
331
345
|
},
|
|
332
346
|
"REGION.POINTER_ENTER": {
|
|
333
|
-
actions: ["pauseToasts"]
|
|
347
|
+
actions: ["setPointerWithin", "pauseToasts"]
|
|
334
348
|
}
|
|
335
349
|
}
|
|
336
350
|
},
|
|
@@ -342,7 +356,7 @@ var groupMachine = core.createMachine({
|
|
|
342
356
|
},
|
|
343
357
|
"REGION.POINTER_ENTER": {
|
|
344
358
|
target: "stack",
|
|
345
|
-
actions: ["pauseToasts", "expandToasts"]
|
|
359
|
+
actions: ["setPointerWithin", "pauseToasts", "expandToasts"]
|
|
346
360
|
},
|
|
347
361
|
"REGION.FOCUS": {
|
|
348
362
|
target: "stack",
|
|
@@ -353,7 +367,8 @@ var groupMachine = core.createMachine({
|
|
|
353
367
|
},
|
|
354
368
|
implementations: {
|
|
355
369
|
guards: {
|
|
356
|
-
isOverlapping: ({ computed }) => computed("overlap")
|
|
370
|
+
isOverlapping: ({ computed }) => computed("overlap"),
|
|
371
|
+
isPointerOut: ({ refs }) => !refs.get("isPointerWithin")
|
|
357
372
|
},
|
|
358
373
|
effects: {
|
|
359
374
|
subscribeToStore({ context, prop }) {
|
|
@@ -444,17 +459,36 @@ var groupMachine = core.createMachine({
|
|
|
444
459
|
refs.set("isFocusWithin", true);
|
|
445
460
|
refs.set("lastFocusedEl", event.target);
|
|
446
461
|
},
|
|
447
|
-
|
|
448
|
-
if (!refs.get("lastFocusedEl")) return;
|
|
462
|
+
restoreFocusIfPointerOut({ refs }) {
|
|
463
|
+
if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
|
|
449
464
|
refs.get("lastFocusedEl")?.focus({ preventScroll: true });
|
|
450
465
|
refs.set("lastFocusedEl", null);
|
|
451
466
|
refs.set("isFocusWithin", false);
|
|
452
467
|
},
|
|
468
|
+
setPointerWithin({ refs }) {
|
|
469
|
+
refs.set("isPointerWithin", true);
|
|
470
|
+
},
|
|
471
|
+
clearPointerWithin({ refs }) {
|
|
472
|
+
refs.set("isPointerWithin", false);
|
|
473
|
+
if (refs.get("lastFocusedEl") && !refs.get("isFocusWithin")) {
|
|
474
|
+
refs.get("lastFocusedEl")?.focus({ preventScroll: true });
|
|
475
|
+
refs.set("lastFocusedEl", null);
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
clearFocusWithin({ refs }) {
|
|
479
|
+
refs.set("isFocusWithin", false);
|
|
480
|
+
},
|
|
453
481
|
clearLastFocusedEl({ refs }) {
|
|
454
482
|
if (!refs.get("lastFocusedEl")) return;
|
|
455
483
|
refs.get("lastFocusedEl")?.focus({ preventScroll: true });
|
|
456
484
|
refs.set("lastFocusedEl", null);
|
|
457
485
|
refs.set("isFocusWithin", false);
|
|
486
|
+
},
|
|
487
|
+
ignoreMouseEventsTemporarily({ refs }) {
|
|
488
|
+
refs.get("ignoreMouseTimer").request();
|
|
489
|
+
},
|
|
490
|
+
clearMouseEventTimer({ refs }) {
|
|
491
|
+
refs.get("ignoreMouseTimer").cancel();
|
|
458
492
|
}
|
|
459
493
|
}
|
|
460
494
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { addDomEvent, raf, contains, dataAttr, MAX_Z_INDEX } from '@zag-js/dom-query';
|
|
1
|
+
import { addDomEvent, AnimationFrame, raf, contains, dataAttr, MAX_Z_INDEX } from '@zag-js/dom-query';
|
|
2
2
|
import { createAnatomy } from '@zag-js/anatomy';
|
|
3
|
-
import {
|
|
3
|
+
import { setup, createGuards, createMachine as createMachine$1 } from '@zag-js/core';
|
|
4
4
|
import { trackDismissableBranch } from '@zag-js/dismissable';
|
|
5
5
|
import { uuid, setRafTimeout, ensureProps, warn, runIfFn, compact } from '@zag-js/utils';
|
|
6
6
|
|
|
@@ -217,10 +217,16 @@ function groupConnect(service, normalize) {
|
|
|
217
217
|
"aria-live": "polite",
|
|
218
218
|
role: "region",
|
|
219
219
|
style: getGroupPlacementStyle(service, placement),
|
|
220
|
+
onMouseEnter() {
|
|
221
|
+
if (refs.get("ignoreMouseTimer").isActive()) return;
|
|
222
|
+
send({ type: "REGION.POINTER_ENTER", placement });
|
|
223
|
+
},
|
|
220
224
|
onMouseMove() {
|
|
225
|
+
if (refs.get("ignoreMouseTimer").isActive()) return;
|
|
221
226
|
send({ type: "REGION.POINTER_ENTER", placement });
|
|
222
227
|
},
|
|
223
228
|
onMouseLeave() {
|
|
229
|
+
if (refs.get("ignoreMouseTimer").isActive()) return;
|
|
224
230
|
send({ type: "REGION.POINTER_LEAVE", placement });
|
|
225
231
|
},
|
|
226
232
|
onFocus(event) {
|
|
@@ -239,6 +245,8 @@ function groupConnect(service, normalize) {
|
|
|
239
245
|
}
|
|
240
246
|
};
|
|
241
247
|
}
|
|
248
|
+
var { guards, createMachine } = setup();
|
|
249
|
+
var { and } = guards;
|
|
242
250
|
var groupMachine = createMachine({
|
|
243
251
|
props({ props }) {
|
|
244
252
|
return {
|
|
@@ -255,6 +263,8 @@ var groupMachine = createMachine({
|
|
|
255
263
|
return {
|
|
256
264
|
lastFocusedEl: null,
|
|
257
265
|
isFocusWithin: false,
|
|
266
|
+
isPointerWithin: false,
|
|
267
|
+
ignoreMouseTimer: AnimationFrame.create(),
|
|
258
268
|
dismissableCleanup: void 0
|
|
259
269
|
};
|
|
260
270
|
},
|
|
@@ -284,24 +294,28 @@ var groupMachine = createMachine({
|
|
|
284
294
|
});
|
|
285
295
|
});
|
|
286
296
|
},
|
|
287
|
-
exit: ["clearDismissableBranch", "clearLastFocusedEl"],
|
|
297
|
+
exit: ["clearDismissableBranch", "clearLastFocusedEl", "clearMouseEventTimer"],
|
|
288
298
|
on: {
|
|
289
299
|
"DOC.HOTKEY": {
|
|
290
300
|
actions: ["focusRegionEl"]
|
|
291
301
|
},
|
|
292
302
|
"REGION.BLUR": [
|
|
293
303
|
{
|
|
294
|
-
guard: "isOverlapping",
|
|
304
|
+
guard: and("isOverlapping", "isPointerOut"),
|
|
295
305
|
target: "overlap",
|
|
296
|
-
actions: ["collapseToasts", "resumeToasts", "
|
|
306
|
+
actions: ["collapseToasts", "resumeToasts", "restoreFocusIfPointerOut"]
|
|
297
307
|
},
|
|
298
308
|
{
|
|
309
|
+
guard: "isPointerOut",
|
|
299
310
|
target: "stack",
|
|
300
|
-
actions: ["resumeToasts", "
|
|
311
|
+
actions: ["resumeToasts", "restoreFocusIfPointerOut"]
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
actions: ["clearFocusWithin"]
|
|
301
315
|
}
|
|
302
316
|
],
|
|
303
317
|
"TOAST.REMOVE": {
|
|
304
|
-
actions: ["removeToast", "removeHeight"]
|
|
318
|
+
actions: ["removeToast", "removeHeight", "ignoreMouseEventsTemporarily"]
|
|
305
319
|
},
|
|
306
320
|
"TOAST.PAUSE": {
|
|
307
321
|
actions: ["pauseToasts"]
|
|
@@ -314,10 +328,10 @@ var groupMachine = createMachine({
|
|
|
314
328
|
{
|
|
315
329
|
guard: "isOverlapping",
|
|
316
330
|
target: "overlap",
|
|
317
|
-
actions: ["resumeToasts", "collapseToasts"]
|
|
331
|
+
actions: ["clearPointerWithin", "resumeToasts", "collapseToasts"]
|
|
318
332
|
},
|
|
319
333
|
{
|
|
320
|
-
actions: ["resumeToasts"]
|
|
334
|
+
actions: ["clearPointerWithin", "resumeToasts"]
|
|
321
335
|
}
|
|
322
336
|
],
|
|
323
337
|
"REGION.OVERLAP": {
|
|
@@ -328,7 +342,7 @@ var groupMachine = createMachine({
|
|
|
328
342
|
actions: ["setLastFocusedEl", "pauseToasts"]
|
|
329
343
|
},
|
|
330
344
|
"REGION.POINTER_ENTER": {
|
|
331
|
-
actions: ["pauseToasts"]
|
|
345
|
+
actions: ["setPointerWithin", "pauseToasts"]
|
|
332
346
|
}
|
|
333
347
|
}
|
|
334
348
|
},
|
|
@@ -340,7 +354,7 @@ var groupMachine = createMachine({
|
|
|
340
354
|
},
|
|
341
355
|
"REGION.POINTER_ENTER": {
|
|
342
356
|
target: "stack",
|
|
343
|
-
actions: ["pauseToasts", "expandToasts"]
|
|
357
|
+
actions: ["setPointerWithin", "pauseToasts", "expandToasts"]
|
|
344
358
|
},
|
|
345
359
|
"REGION.FOCUS": {
|
|
346
360
|
target: "stack",
|
|
@@ -351,7 +365,8 @@ var groupMachine = createMachine({
|
|
|
351
365
|
},
|
|
352
366
|
implementations: {
|
|
353
367
|
guards: {
|
|
354
|
-
isOverlapping: ({ computed }) => computed("overlap")
|
|
368
|
+
isOverlapping: ({ computed }) => computed("overlap"),
|
|
369
|
+
isPointerOut: ({ refs }) => !refs.get("isPointerWithin")
|
|
355
370
|
},
|
|
356
371
|
effects: {
|
|
357
372
|
subscribeToStore({ context, prop }) {
|
|
@@ -442,17 +457,36 @@ var groupMachine = createMachine({
|
|
|
442
457
|
refs.set("isFocusWithin", true);
|
|
443
458
|
refs.set("lastFocusedEl", event.target);
|
|
444
459
|
},
|
|
445
|
-
|
|
446
|
-
if (!refs.get("lastFocusedEl")) return;
|
|
460
|
+
restoreFocusIfPointerOut({ refs }) {
|
|
461
|
+
if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
|
|
447
462
|
refs.get("lastFocusedEl")?.focus({ preventScroll: true });
|
|
448
463
|
refs.set("lastFocusedEl", null);
|
|
449
464
|
refs.set("isFocusWithin", false);
|
|
450
465
|
},
|
|
466
|
+
setPointerWithin({ refs }) {
|
|
467
|
+
refs.set("isPointerWithin", true);
|
|
468
|
+
},
|
|
469
|
+
clearPointerWithin({ refs }) {
|
|
470
|
+
refs.set("isPointerWithin", false);
|
|
471
|
+
if (refs.get("lastFocusedEl") && !refs.get("isFocusWithin")) {
|
|
472
|
+
refs.get("lastFocusedEl")?.focus({ preventScroll: true });
|
|
473
|
+
refs.set("lastFocusedEl", null);
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
clearFocusWithin({ refs }) {
|
|
477
|
+
refs.set("isFocusWithin", false);
|
|
478
|
+
},
|
|
451
479
|
clearLastFocusedEl({ refs }) {
|
|
452
480
|
if (!refs.get("lastFocusedEl")) return;
|
|
453
481
|
refs.get("lastFocusedEl")?.focus({ preventScroll: true });
|
|
454
482
|
refs.set("lastFocusedEl", null);
|
|
455
483
|
refs.set("isFocusWithin", false);
|
|
484
|
+
},
|
|
485
|
+
ignoreMouseEventsTemporarily({ refs }) {
|
|
486
|
+
refs.get("ignoreMouseTimer").request();
|
|
487
|
+
},
|
|
488
|
+
clearMouseEventTimer({ refs }) {
|
|
489
|
+
refs.get("ignoreMouseTimer").cancel();
|
|
456
490
|
}
|
|
457
491
|
}
|
|
458
492
|
}
|
|
@@ -570,7 +604,7 @@ function connect(service, normalize) {
|
|
|
570
604
|
};
|
|
571
605
|
}
|
|
572
606
|
var { not } = createGuards();
|
|
573
|
-
var machine = createMachine({
|
|
607
|
+
var machine = createMachine$1({
|
|
574
608
|
props({ props }) {
|
|
575
609
|
ensureProps(props, ["id", "type", "parent", "removeDelay"], "toast");
|
|
576
610
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/toast",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.4",
|
|
4
4
|
"description": "Core logic for the toast widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@zag-js/anatomy": "1.26.
|
|
30
|
-
"@zag-js/core": "1.26.
|
|
31
|
-
"@zag-js/dom-query": "1.26.
|
|
32
|
-
"@zag-js/dismissable": "1.26.
|
|
33
|
-
"@zag-js/utils": "1.26.
|
|
34
|
-
"@zag-js/types": "1.26.
|
|
29
|
+
"@zag-js/anatomy": "1.26.4",
|
|
30
|
+
"@zag-js/core": "1.26.4",
|
|
31
|
+
"@zag-js/dom-query": "1.26.4",
|
|
32
|
+
"@zag-js/dismissable": "1.26.4",
|
|
33
|
+
"@zag-js/utils": "1.26.4",
|
|
34
|
+
"@zag-js/types": "1.26.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"clean-package": "2.2.0"
|