@zag-js/toast 0.0.0-dev-20220704163406 → 0.0.0-dev-20220708193601
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 +49 -22
- package/dist/index.mjs +49 -22
- package/dist/toast-group.machine.d.ts +1 -1
- package/dist/toast.dom.d.ts +10 -2
- package/dist/toast.types.d.ts +4 -4
- package/package.json +4 -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,34 @@ 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 withRootHelpers(domUtils) {
|
|
102
|
+
const roots = {
|
|
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(roots.getRootNode(ctx)),
|
|
108
|
+
getWin: (ctx) => {
|
|
109
|
+
var _a;
|
|
110
|
+
return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return __spreadValues2(__spreadValues2({}, roots), domUtils);
|
|
114
|
+
}
|
|
71
115
|
var isRef = (v) => hasProp(v, "current");
|
|
72
116
|
function addDomEvent(target, eventName, handler, options) {
|
|
73
117
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -108,20 +152,12 @@ function warn(...a) {
|
|
|
108
152
|
var import_core = require("@zag-js/core");
|
|
109
153
|
|
|
110
154
|
// 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
|
-
},
|
|
155
|
+
var dom = withRootHelpers({
|
|
120
156
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
121
157
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
122
158
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
123
159
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
124
|
-
getPortalId: (ctx) => `toast-portal:${ctx.
|
|
160
|
+
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
125
161
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
126
162
|
createPortalEl: (ctx) => {
|
|
127
163
|
const existing = dom.getPortalEl(ctx);
|
|
@@ -131,7 +167,7 @@ var dom = {
|
|
|
131
167
|
portal.id = dom.getPortalId(ctx);
|
|
132
168
|
return portal;
|
|
133
169
|
}
|
|
134
|
-
};
|
|
170
|
+
});
|
|
135
171
|
|
|
136
172
|
// src/toast.utils.ts
|
|
137
173
|
function getToastsByPlacement(toasts) {
|
|
@@ -467,14 +503,13 @@ function createToastMachine(options = {}) {
|
|
|
467
503
|
}
|
|
468
504
|
|
|
469
505
|
// src/toast-group.machine.ts
|
|
470
|
-
function groupMachine(ctx
|
|
506
|
+
function groupMachine(ctx) {
|
|
471
507
|
return (0, import_core3.createMachine)({
|
|
472
508
|
id: "toaster",
|
|
473
509
|
initial: "active",
|
|
474
510
|
context: __spreadValues({
|
|
475
511
|
dir: "ltr",
|
|
476
512
|
max: Number.MAX_SAFE_INTEGER,
|
|
477
|
-
uid: "",
|
|
478
513
|
toasts: [],
|
|
479
514
|
gutter: "1rem",
|
|
480
515
|
zIndex: MAX_Z_INDEX,
|
|
@@ -486,15 +521,7 @@ function groupMachine(ctx = {}) {
|
|
|
486
521
|
count: (ctx2) => ctx2.toasts.length
|
|
487
522
|
},
|
|
488
523
|
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
|
-
},
|
|
524
|
+
SETUP: {},
|
|
498
525
|
PAUSE_TOAST: {
|
|
499
526
|
actions: (_ctx, evt, { self }) => {
|
|
500
527
|
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,34 @@ 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 withRootHelpers(domUtils) {
|
|
76
|
+
const roots = {
|
|
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(roots.getRootNode(ctx)),
|
|
82
|
+
getWin: (ctx) => {
|
|
83
|
+
var _a;
|
|
84
|
+
return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return __spreadValues2(__spreadValues2({}, roots), domUtils);
|
|
88
|
+
}
|
|
45
89
|
var isRef = (v) => hasProp(v, "current");
|
|
46
90
|
function addDomEvent(target, eventName, handler, options) {
|
|
47
91
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -82,20 +126,12 @@ function warn(...a) {
|
|
|
82
126
|
import { subscribe } from "@zag-js/core";
|
|
83
127
|
|
|
84
128
|
// 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
|
-
},
|
|
129
|
+
var dom = withRootHelpers({
|
|
94
130
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
95
131
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
96
132
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
97
133
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
98
|
-
getPortalId: (ctx) => `toast-portal:${ctx.
|
|
134
|
+
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
99
135
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
100
136
|
createPortalEl: (ctx) => {
|
|
101
137
|
const existing = dom.getPortalEl(ctx);
|
|
@@ -105,7 +141,7 @@ var dom = {
|
|
|
105
141
|
portal.id = dom.getPortalId(ctx);
|
|
106
142
|
return portal;
|
|
107
143
|
}
|
|
108
|
-
};
|
|
144
|
+
});
|
|
109
145
|
|
|
110
146
|
// src/toast.utils.ts
|
|
111
147
|
function getToastsByPlacement(toasts) {
|
|
@@ -441,14 +477,13 @@ function createToastMachine(options = {}) {
|
|
|
441
477
|
}
|
|
442
478
|
|
|
443
479
|
// src/toast-group.machine.ts
|
|
444
|
-
function groupMachine(ctx
|
|
480
|
+
function groupMachine(ctx) {
|
|
445
481
|
return createMachine2({
|
|
446
482
|
id: "toaster",
|
|
447
483
|
initial: "active",
|
|
448
484
|
context: __spreadValues({
|
|
449
485
|
dir: "ltr",
|
|
450
486
|
max: Number.MAX_SAFE_INTEGER,
|
|
451
|
-
uid: "",
|
|
452
487
|
toasts: [],
|
|
453
488
|
gutter: "1rem",
|
|
454
489
|
zIndex: MAX_Z_INDEX,
|
|
@@ -460,15 +495,7 @@ function groupMachine(ctx = {}) {
|
|
|
460
495
|
count: (ctx2) => ctx2.toasts.length
|
|
461
496
|
},
|
|
462
497
|
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
|
-
},
|
|
498
|
+
SETUP: {},
|
|
472
499
|
PAUSE_TOAST: {
|
|
473
500
|
actions: (_ctx, evt, { self }) => {
|
|
474
501
|
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,15 @@
|
|
|
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
|
+
} & {
|
|
5
13
|
getGroupId: (placement: Placement) => string;
|
|
6
14
|
getContainerId: (ctx: Ctx) => string;
|
|
7
15
|
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.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20220708193601",
|
|
4
4
|
"description": "Core logic for the toast widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.
|
|
33
|
-
"@zag-js/dom-utils": "0.0.0-dev-
|
|
34
|
-
"@zag-js/types": "0.0.0-dev-
|
|
32
|
+
"@zag-js/core": "0.1.7",
|
|
33
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220708193601",
|
|
34
|
+
"@zag-js/types": "0.0.0-dev-20220708193601",
|
|
35
35
|
"@zag-js/utils": "0.1.2"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|