@zag-js/toast 0.0.0-dev-20220416152643 → 0.0.0-dev-20220417135151
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.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +98 -89
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +98 -89
- package/dist/index.mjs.map +2 -2
- package/dist/toast-group.connect.d.ts +2 -3
- package/dist/toast-group.connect.d.ts.map +1 -1
- package/dist/toast-group.machine.d.ts +2 -2
- package/dist/toast-group.machine.d.ts.map +1 -1
- package/dist/toast.connect.d.ts +2 -3
- package/dist/toast.connect.d.ts.map +1 -1
- package/dist/toast.types.d.ts +61 -48
- package/dist/toast.types.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { groupConnect } from "./toast-group.connect";
|
|
2
|
+
import { groupMachine } from "./toast-group.machine";
|
|
2
3
|
import { createToastMachine as createMachine } from "./toast.machine";
|
|
3
4
|
export { connect } from "./toast.connect";
|
|
4
5
|
export type { GroupMachineContext, MachineContext, MachineState, Placement, Service, Type } from "./toast.types";
|
|
5
6
|
export { createMachine };
|
|
6
7
|
export declare const group: {
|
|
7
8
|
connect: typeof groupConnect;
|
|
8
|
-
machine:
|
|
9
|
+
machine: typeof groupMachine;
|
|
9
10
|
};
|
|
10
11
|
export declare function api(): import("./toast.types").Toaster;
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,kBAAkB,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAErE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAChH,OAAO,EAAE,aAAa,EAAE,CAAA;AAExB,eAAO,MAAM,KAAK;;;CAGjB,CAAA;AAED,wBAAgB,GAAG,oCAMlB"}
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,13 @@ var runIfFn = (v, ...a) => {
|
|
|
60
60
|
const res = typeof v === "function" ? v(...a) : v;
|
|
61
61
|
return res != null ? res : void 0;
|
|
62
62
|
};
|
|
63
|
+
var uuid = /* @__PURE__ */ (() => {
|
|
64
|
+
let id = 0;
|
|
65
|
+
return () => {
|
|
66
|
+
id++;
|
|
67
|
+
return id.toString(36);
|
|
68
|
+
};
|
|
69
|
+
})();
|
|
63
70
|
var isDom = () => !!(typeof window !== "undefined");
|
|
64
71
|
function warn(...a) {
|
|
65
72
|
const m = a.length === 1 ? a[0] : a[1];
|
|
@@ -173,7 +180,7 @@ function groupConnect(state, send, normalize = normalizeProp) {
|
|
|
173
180
|
return !!state.context.toasts.find((toast) => toast.id == id);
|
|
174
181
|
},
|
|
175
182
|
create(options) {
|
|
176
|
-
const uid =
|
|
183
|
+
const uid = `toast:${uuid()}`;
|
|
177
184
|
const id = options.id ? options.id : uid;
|
|
178
185
|
if (group2.isVisible(id))
|
|
179
186
|
return;
|
|
@@ -519,97 +526,99 @@ function createToastMachine(options = {}) {
|
|
|
519
526
|
}
|
|
520
527
|
|
|
521
528
|
// src/toast-group.machine.ts
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
on: {
|
|
540
|
-
SETUP: {
|
|
541
|
-
actions: (ctx, evt) => {
|
|
542
|
-
ctx.uid = evt.id;
|
|
543
|
-
if (evt.doc)
|
|
544
|
-
ctx.doc = (0, import_core3.ref)(evt.doc);
|
|
545
|
-
}
|
|
546
|
-
},
|
|
547
|
-
PAUSE_TOAST: {
|
|
548
|
-
actions: (_ctx, evt, { self }) => {
|
|
549
|
-
self.sendChild("PAUSE", evt.id);
|
|
550
|
-
}
|
|
551
|
-
},
|
|
552
|
-
PAUSE_ALL: {
|
|
553
|
-
actions: (ctx) => {
|
|
554
|
-
ctx.toasts.forEach((toast) => toast.send("PAUSE"));
|
|
555
|
-
}
|
|
556
|
-
},
|
|
557
|
-
RESUME_TOAST: {
|
|
558
|
-
actions: (_ctx, evt, { self }) => {
|
|
559
|
-
self.sendChild("RESUME", evt.id);
|
|
560
|
-
}
|
|
561
|
-
},
|
|
562
|
-
RESUME_ALL: {
|
|
563
|
-
actions: (ctx) => {
|
|
564
|
-
ctx.toasts.forEach((toast) => toast.send("RESUME"));
|
|
565
|
-
}
|
|
566
|
-
},
|
|
567
|
-
ADD_TOAST: {
|
|
568
|
-
guard: (ctx) => ctx.toasts.length < ctx.max,
|
|
569
|
-
actions: (ctx, evt, { self }) => {
|
|
570
|
-
var _a;
|
|
571
|
-
const options = __spreadProps(__spreadValues({}, evt.toast), {
|
|
572
|
-
pauseOnPageIdle: ctx.pauseOnPageIdle,
|
|
573
|
-
pauseOnInteraction: ctx.pauseOnInteraction,
|
|
574
|
-
dir: ctx.dir,
|
|
575
|
-
doc: (0, import_core3.ref)((_a = ctx.doc) != null ? _a : document)
|
|
576
|
-
});
|
|
577
|
-
const toast = createToastMachine(options);
|
|
578
|
-
const actor = self.spawn(toast);
|
|
579
|
-
ctx.toasts.push(actor);
|
|
580
|
-
}
|
|
581
|
-
},
|
|
582
|
-
UPDATE_TOAST: {
|
|
583
|
-
actions: (_ctx, evt, { self }) => {
|
|
584
|
-
self.sendChild({ type: "UPDATE", toast: evt.toast }, evt.id);
|
|
585
|
-
}
|
|
586
|
-
},
|
|
587
|
-
DISMISS_TOAST: {
|
|
588
|
-
actions: (_ctx, evt, { self }) => {
|
|
589
|
-
self.sendChild("DISMISS", evt.id);
|
|
590
|
-
}
|
|
591
|
-
},
|
|
592
|
-
DISMISS_ALL: {
|
|
593
|
-
actions: (ctx) => {
|
|
594
|
-
ctx.toasts.forEach((toast) => toast.send("DISMISS"));
|
|
595
|
-
}
|
|
596
|
-
},
|
|
597
|
-
REMOVE_TOAST: {
|
|
598
|
-
actions: (ctx, evt, { self }) => {
|
|
599
|
-
self.stopChild(evt.id);
|
|
600
|
-
const index = ctx.toasts.findIndex((toast) => toast.id === evt.id);
|
|
601
|
-
ctx.toasts.splice(index, 1);
|
|
602
|
-
}
|
|
529
|
+
function groupMachine(ctx = {}) {
|
|
530
|
+
return (0, import_core3.createMachine)({
|
|
531
|
+
id: "toaster",
|
|
532
|
+
initial: "active",
|
|
533
|
+
context: __spreadValues({
|
|
534
|
+
dir: "ltr",
|
|
535
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
536
|
+
uid: "",
|
|
537
|
+
toasts: [],
|
|
538
|
+
gutter: "1rem",
|
|
539
|
+
zIndex: MAX_Z_INDEX,
|
|
540
|
+
pauseOnPageIdle: false,
|
|
541
|
+
pauseOnInteraction: true,
|
|
542
|
+
offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" }
|
|
543
|
+
}, ctx),
|
|
544
|
+
computed: {
|
|
545
|
+
count: (ctx2) => ctx2.toasts.length
|
|
603
546
|
},
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
547
|
+
on: {
|
|
548
|
+
SETUP: {
|
|
549
|
+
actions: (ctx2, evt) => {
|
|
550
|
+
ctx2.uid = evt.id;
|
|
551
|
+
if (evt.doc)
|
|
552
|
+
ctx2.doc = (0, import_core3.ref)(evt.doc);
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
PAUSE_TOAST: {
|
|
556
|
+
actions: (_ctx, evt, { self }) => {
|
|
557
|
+
self.sendChild("PAUSE", evt.id);
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
PAUSE_ALL: {
|
|
561
|
+
actions: (ctx2) => {
|
|
562
|
+
ctx2.toasts.forEach((toast) => toast.send("PAUSE"));
|
|
563
|
+
}
|
|
564
|
+
},
|
|
565
|
+
RESUME_TOAST: {
|
|
566
|
+
actions: (_ctx, evt, { self }) => {
|
|
567
|
+
self.sendChild("RESUME", evt.id);
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
RESUME_ALL: {
|
|
571
|
+
actions: (ctx2) => {
|
|
572
|
+
ctx2.toasts.forEach((toast) => toast.send("RESUME"));
|
|
573
|
+
}
|
|
574
|
+
},
|
|
575
|
+
ADD_TOAST: {
|
|
576
|
+
guard: (ctx2) => ctx2.toasts.length < ctx2.max,
|
|
577
|
+
actions: (ctx2, evt, { self }) => {
|
|
578
|
+
var _a;
|
|
579
|
+
const options = __spreadProps(__spreadValues({}, evt.toast), {
|
|
580
|
+
pauseOnPageIdle: ctx2.pauseOnPageIdle,
|
|
581
|
+
pauseOnInteraction: ctx2.pauseOnInteraction,
|
|
582
|
+
dir: ctx2.dir,
|
|
583
|
+
doc: (0, import_core3.ref)((_a = ctx2.doc) != null ? _a : document)
|
|
584
|
+
});
|
|
585
|
+
const toast = createToastMachine(options);
|
|
586
|
+
const actor = self.spawn(toast);
|
|
587
|
+
ctx2.toasts.push(actor);
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
UPDATE_TOAST: {
|
|
591
|
+
actions: (_ctx, evt, { self }) => {
|
|
592
|
+
self.sendChild({ type: "UPDATE", toast: evt.toast }, evt.id);
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
DISMISS_TOAST: {
|
|
596
|
+
actions: (_ctx, evt, { self }) => {
|
|
597
|
+
self.sendChild("DISMISS", evt.id);
|
|
598
|
+
}
|
|
599
|
+
},
|
|
600
|
+
DISMISS_ALL: {
|
|
601
|
+
actions: (ctx2) => {
|
|
602
|
+
ctx2.toasts.forEach((toast) => toast.send("DISMISS"));
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
REMOVE_TOAST: {
|
|
606
|
+
actions: (ctx2, evt, { self }) => {
|
|
607
|
+
self.stopChild(evt.id);
|
|
608
|
+
const index = ctx2.toasts.findIndex((toast) => toast.id === evt.id);
|
|
609
|
+
ctx2.toasts.splice(index, 1);
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
REMOVE_ALL: {
|
|
613
|
+
actions: (ctx2, _evt, { self }) => {
|
|
614
|
+
ctx2.toasts.forEach((toast) => self.stopChild(toast.id));
|
|
615
|
+
while (ctx2.toasts.length)
|
|
616
|
+
ctx2.toasts.pop();
|
|
617
|
+
}
|
|
609
618
|
}
|
|
610
619
|
}
|
|
611
|
-
}
|
|
612
|
-
}
|
|
620
|
+
});
|
|
621
|
+
}
|
|
613
622
|
|
|
614
623
|
// src/toast.connect.ts
|
|
615
624
|
function connect(state, send, normalize = normalizeProp) {
|