@zag-js/toast 0.1.9 → 0.1.10
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.js +51 -22
- package/dist/index.mjs +51 -22
- package/dist/toast-group.machine.d.ts +1 -1
- package/dist/toast.dom.d.ts +16 -2
- package/dist/toast.types.d.ts +4 -4
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -57,6 +57,22 @@ __export(src_exports, {
|
|
|
57
57
|
module.exports = __toCommonJS(src_exports);
|
|
58
58
|
|
|
59
59
|
// ../../utilities/dom/dist/index.mjs
|
|
60
|
+
var __defProp2 = Object.defineProperty;
|
|
61
|
+
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
62
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
63
|
+
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
64
|
+
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
65
|
+
var __spreadValues2 = (a, b) => {
|
|
66
|
+
for (var prop in b || (b = {}))
|
|
67
|
+
if (__hasOwnProp2.call(b, prop))
|
|
68
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
69
|
+
if (__getOwnPropSymbols2)
|
|
70
|
+
for (var prop of __getOwnPropSymbols2(b)) {
|
|
71
|
+
if (__propIsEnum2.call(b, prop))
|
|
72
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
73
|
+
}
|
|
74
|
+
return a;
|
|
75
|
+
};
|
|
60
76
|
var dataAttr = (guard) => {
|
|
61
77
|
return guard ? "" : void 0;
|
|
62
78
|
};
|
|
@@ -68,6 +84,36 @@ var runIfFn = (v, ...a) => {
|
|
|
68
84
|
var cast = (v) => v;
|
|
69
85
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
70
86
|
var isDom = () => typeof window !== "undefined";
|
|
87
|
+
function isDocument(el) {
|
|
88
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
89
|
+
}
|
|
90
|
+
function isWindow(value) {
|
|
91
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
92
|
+
}
|
|
93
|
+
function getDocument(el) {
|
|
94
|
+
var _a;
|
|
95
|
+
if (isWindow(el))
|
|
96
|
+
return el.document;
|
|
97
|
+
if (isDocument(el))
|
|
98
|
+
return el;
|
|
99
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
100
|
+
}
|
|
101
|
+
function defineDomHelpers(helpers) {
|
|
102
|
+
const dom2 = {
|
|
103
|
+
getRootNode: (ctx) => {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
106
|
+
},
|
|
107
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
108
|
+
getWin: (ctx) => {
|
|
109
|
+
var _a;
|
|
110
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
111
|
+
},
|
|
112
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
113
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
114
|
+
};
|
|
115
|
+
return __spreadValues2(__spreadValues2({}, dom2), helpers);
|
|
116
|
+
}
|
|
71
117
|
var isRef = (v) => hasProp(v, "current");
|
|
72
118
|
function addDomEvent(target, eventName, handler, options) {
|
|
73
119
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -108,20 +154,12 @@ function warn(...a) {
|
|
|
108
154
|
var import_core = require("@zag-js/core");
|
|
109
155
|
|
|
110
156
|
// src/toast.dom.ts
|
|
111
|
-
var dom = {
|
|
112
|
-
getDoc: (ctx) => {
|
|
113
|
-
var _a;
|
|
114
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
115
|
-
},
|
|
116
|
-
getRootNode: (ctx) => {
|
|
117
|
-
var _a;
|
|
118
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
119
|
-
},
|
|
157
|
+
var dom = defineDomHelpers({
|
|
120
158
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
121
159
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
122
160
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
123
161
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
124
|
-
getPortalId: (ctx) => `toast-portal:${ctx.
|
|
162
|
+
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
125
163
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
126
164
|
createPortalEl: (ctx) => {
|
|
127
165
|
const existing = dom.getPortalEl(ctx);
|
|
@@ -131,7 +169,7 @@ var dom = {
|
|
|
131
169
|
portal.id = dom.getPortalId(ctx);
|
|
132
170
|
return portal;
|
|
133
171
|
}
|
|
134
|
-
};
|
|
172
|
+
});
|
|
135
173
|
|
|
136
174
|
// src/toast.utils.ts
|
|
137
175
|
function getToastsByPlacement(toasts) {
|
|
@@ -467,14 +505,13 @@ function createToastMachine(options = {}) {
|
|
|
467
505
|
}
|
|
468
506
|
|
|
469
507
|
// src/toast-group.machine.ts
|
|
470
|
-
function groupMachine(ctx
|
|
508
|
+
function groupMachine(ctx) {
|
|
471
509
|
return (0, import_core3.createMachine)({
|
|
472
510
|
id: "toaster",
|
|
473
511
|
initial: "active",
|
|
474
512
|
context: __spreadValues({
|
|
475
513
|
dir: "ltr",
|
|
476
514
|
max: Number.MAX_SAFE_INTEGER,
|
|
477
|
-
uid: "",
|
|
478
515
|
toasts: [],
|
|
479
516
|
gutter: "1rem",
|
|
480
517
|
zIndex: MAX_Z_INDEX,
|
|
@@ -486,15 +523,7 @@ function groupMachine(ctx = {}) {
|
|
|
486
523
|
count: (ctx2) => ctx2.toasts.length
|
|
487
524
|
},
|
|
488
525
|
on: {
|
|
489
|
-
SETUP: {
|
|
490
|
-
actions: (ctx2, evt) => {
|
|
491
|
-
ctx2.uid = evt.id;
|
|
492
|
-
if (evt.doc)
|
|
493
|
-
ctx2.doc = (0, import_core3.ref)(evt.doc);
|
|
494
|
-
if (evt.root)
|
|
495
|
-
ctx2.rootNode = (0, import_core3.ref)(evt.root);
|
|
496
|
-
}
|
|
497
|
-
},
|
|
526
|
+
SETUP: {},
|
|
498
527
|
PAUSE_TOAST: {
|
|
499
528
|
actions: (_ctx, evt, { self }) => {
|
|
500
529
|
self.sendChild("PAUSE", evt.id);
|
package/dist/index.mjs
CHANGED
|
@@ -31,6 +31,22 @@ var __objRest = (source, exclude) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// ../../utilities/dom/dist/index.mjs
|
|
34
|
+
var __defProp2 = Object.defineProperty;
|
|
35
|
+
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
36
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
37
|
+
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
38
|
+
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
39
|
+
var __spreadValues2 = (a, b) => {
|
|
40
|
+
for (var prop in b || (b = {}))
|
|
41
|
+
if (__hasOwnProp2.call(b, prop))
|
|
42
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
43
|
+
if (__getOwnPropSymbols2)
|
|
44
|
+
for (var prop of __getOwnPropSymbols2(b)) {
|
|
45
|
+
if (__propIsEnum2.call(b, prop))
|
|
46
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
47
|
+
}
|
|
48
|
+
return a;
|
|
49
|
+
};
|
|
34
50
|
var dataAttr = (guard) => {
|
|
35
51
|
return guard ? "" : void 0;
|
|
36
52
|
};
|
|
@@ -42,6 +58,36 @@ var runIfFn = (v, ...a) => {
|
|
|
42
58
|
var cast = (v) => v;
|
|
43
59
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
44
60
|
var isDom = () => typeof window !== "undefined";
|
|
61
|
+
function isDocument(el) {
|
|
62
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
63
|
+
}
|
|
64
|
+
function isWindow(value) {
|
|
65
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
66
|
+
}
|
|
67
|
+
function getDocument(el) {
|
|
68
|
+
var _a;
|
|
69
|
+
if (isWindow(el))
|
|
70
|
+
return el.document;
|
|
71
|
+
if (isDocument(el))
|
|
72
|
+
return el;
|
|
73
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
74
|
+
}
|
|
75
|
+
function defineDomHelpers(helpers) {
|
|
76
|
+
const dom2 = {
|
|
77
|
+
getRootNode: (ctx) => {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
80
|
+
},
|
|
81
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
82
|
+
getWin: (ctx) => {
|
|
83
|
+
var _a;
|
|
84
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
85
|
+
},
|
|
86
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
87
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
88
|
+
};
|
|
89
|
+
return __spreadValues2(__spreadValues2({}, dom2), helpers);
|
|
90
|
+
}
|
|
45
91
|
var isRef = (v) => hasProp(v, "current");
|
|
46
92
|
function addDomEvent(target, eventName, handler, options) {
|
|
47
93
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -82,20 +128,12 @@ function warn(...a) {
|
|
|
82
128
|
import { subscribe } from "@zag-js/core";
|
|
83
129
|
|
|
84
130
|
// src/toast.dom.ts
|
|
85
|
-
var dom = {
|
|
86
|
-
getDoc: (ctx) => {
|
|
87
|
-
var _a;
|
|
88
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
89
|
-
},
|
|
90
|
-
getRootNode: (ctx) => {
|
|
91
|
-
var _a;
|
|
92
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
93
|
-
},
|
|
131
|
+
var dom = defineDomHelpers({
|
|
94
132
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
95
133
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
96
134
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
97
135
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
98
|
-
getPortalId: (ctx) => `toast-portal:${ctx.
|
|
136
|
+
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
99
137
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
100
138
|
createPortalEl: (ctx) => {
|
|
101
139
|
const existing = dom.getPortalEl(ctx);
|
|
@@ -105,7 +143,7 @@ var dom = {
|
|
|
105
143
|
portal.id = dom.getPortalId(ctx);
|
|
106
144
|
return portal;
|
|
107
145
|
}
|
|
108
|
-
};
|
|
146
|
+
});
|
|
109
147
|
|
|
110
148
|
// src/toast.utils.ts
|
|
111
149
|
function getToastsByPlacement(toasts) {
|
|
@@ -441,14 +479,13 @@ function createToastMachine(options = {}) {
|
|
|
441
479
|
}
|
|
442
480
|
|
|
443
481
|
// src/toast-group.machine.ts
|
|
444
|
-
function groupMachine(ctx
|
|
482
|
+
function groupMachine(ctx) {
|
|
445
483
|
return createMachine2({
|
|
446
484
|
id: "toaster",
|
|
447
485
|
initial: "active",
|
|
448
486
|
context: __spreadValues({
|
|
449
487
|
dir: "ltr",
|
|
450
488
|
max: Number.MAX_SAFE_INTEGER,
|
|
451
|
-
uid: "",
|
|
452
489
|
toasts: [],
|
|
453
490
|
gutter: "1rem",
|
|
454
491
|
zIndex: MAX_Z_INDEX,
|
|
@@ -460,15 +497,7 @@ function groupMachine(ctx = {}) {
|
|
|
460
497
|
count: (ctx2) => ctx2.toasts.length
|
|
461
498
|
},
|
|
462
499
|
on: {
|
|
463
|
-
SETUP: {
|
|
464
|
-
actions: (ctx2, evt) => {
|
|
465
|
-
ctx2.uid = evt.id;
|
|
466
|
-
if (evt.doc)
|
|
467
|
-
ctx2.doc = ref(evt.doc);
|
|
468
|
-
if (evt.root)
|
|
469
|
-
ctx2.rootNode = ref(evt.root);
|
|
470
|
-
}
|
|
471
|
-
},
|
|
500
|
+
SETUP: {},
|
|
472
501
|
PAUSE_TOAST: {
|
|
473
502
|
actions: (_ctx, evt, { self }) => {
|
|
474
503
|
self.sendChild("PAUSE", evt.id);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { GroupMachineContext, UserDefinedGroupContext } from "./toast.types";
|
|
2
|
-
export declare function groupMachine(ctx
|
|
2
|
+
export declare function groupMachine(ctx: UserDefinedGroupContext): import("@zag-js/core").Machine<GroupMachineContext, import("@zag-js/core").StateMachine.StateSchema, import("@zag-js/core").StateMachine.AnyEventObject>;
|
package/dist/toast.dom.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import type { GroupMachineContext as GroupCtx, MachineContext as Ctx, Placement } from "./toast.types";
|
|
2
2
|
export declare const dom: {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
getRootNode: (ctx: {
|
|
4
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
5
|
+
}) => Document | ShadowRoot;
|
|
6
|
+
getDoc: (ctx: {
|
|
7
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
8
|
+
}) => Document;
|
|
9
|
+
getWin: (ctx: {
|
|
10
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
11
|
+
}) => Window & typeof globalThis;
|
|
12
|
+
getActiveElement: (ctx: {
|
|
13
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
14
|
+
}) => HTMLElement;
|
|
15
|
+
getById: <T_1 = HTMLElement>(ctx: {
|
|
16
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
17
|
+
}, id: string) => T_1;
|
|
18
|
+
} & {
|
|
5
19
|
getGroupId: (placement: Placement) => string;
|
|
6
20
|
getContainerId: (ctx: Ctx) => string;
|
|
7
21
|
getTitleId: (ctx: Ctx) => string;
|
package/dist/toast.types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Machine, StateMachine as S } from "@zag-js/core";
|
|
2
|
-
import type { Context, Direction, DirectionProperty, RootProperties } from "@zag-js/types";
|
|
2
|
+
import type { CommonProperties, Context, Direction, DirectionProperty, RequiredBy, RootProperties } from "@zag-js/types";
|
|
3
3
|
export declare type Type = "success" | "error" | "loading" | "info" | "custom";
|
|
4
4
|
export declare type Placement = "top-start" | "top" | "top-end" | "bottom-start" | "bottom" | "bottom-end";
|
|
5
5
|
declare type SharedContext = {
|
|
@@ -67,7 +67,7 @@ export declare type Options = Partial<ToastOptions>;
|
|
|
67
67
|
export declare type RenderOptions = Omit<ToastOptions, "render"> & {
|
|
68
68
|
dismiss(): void;
|
|
69
69
|
};
|
|
70
|
-
export declare type MachineContext = SharedContext & RootProperties & Omit<ToastOptions, "removeDelay"> & {
|
|
70
|
+
export declare type MachineContext = SharedContext & RootProperties & CommonProperties & Omit<ToastOptions, "removeDelay"> & {
|
|
71
71
|
/**
|
|
72
72
|
* The duration for the toast to kept alive before it is removed.
|
|
73
73
|
* Useful for exit transitions.
|
|
@@ -93,7 +93,7 @@ export declare type MachineState = {
|
|
|
93
93
|
export declare type State = S.State<MachineContext, MachineState>;
|
|
94
94
|
export declare type Send = S.Send;
|
|
95
95
|
export declare type Service = Machine<MachineContext, MachineState>;
|
|
96
|
-
declare type GroupPublicContext = SharedContext & DirectionProperty & {
|
|
96
|
+
declare type GroupPublicContext = SharedContext & DirectionProperty & CommonProperties & {
|
|
97
97
|
/**
|
|
98
98
|
* The gutter or spacing between toasts
|
|
99
99
|
*/
|
|
@@ -111,7 +111,7 @@ declare type GroupPublicContext = SharedContext & DirectionProperty & {
|
|
|
111
111
|
*/
|
|
112
112
|
offsets: string | Record<"left" | "right" | "bottom" | "top", string>;
|
|
113
113
|
};
|
|
114
|
-
export declare type UserDefinedGroupContext =
|
|
114
|
+
export declare type UserDefinedGroupContext = RequiredBy<GroupPublicContext, "id">;
|
|
115
115
|
declare type GroupComputedContext = Readonly<{
|
|
116
116
|
/**
|
|
117
117
|
* @computed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/toast",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Core logic for the toast widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,9 +29,11 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.1.
|
|
33
|
-
"@zag-js/
|
|
34
|
-
|
|
32
|
+
"@zag-js/core": "0.1.8",
|
|
33
|
+
"@zag-js/types": "0.2.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@zag-js/dom-utils": "0.1.7",
|
|
35
37
|
"@zag-js/utils": "0.1.2"
|
|
36
38
|
},
|
|
37
39
|
"scripts": {
|