@zag-js/toast 0.2.12 → 0.2.14
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/{chunk-HRZITBY3.mjs → chunk-6TPPYHFP.mjs} +55 -6
- package/dist/{chunk-XQSCE3HI.mjs → chunk-DBPKSADW.mjs} +12 -12
- package/dist/chunk-DUZD3NLM.mjs +14 -0
- package/dist/{chunk-SSV22S55.mjs → chunk-EQTV3BNM.mjs} +7 -44
- package/dist/{chunk-HDTOIF42.mjs → chunk-MUJMFD4Y.mjs} +49 -20
- package/dist/{chunk-GKMHTDAP.mjs → chunk-TCF4OLIQ.mjs} +3 -7
- package/dist/index.js +133 -133
- package/dist/index.mjs +8 -19
- package/dist/toast-group.connect.d.ts +52 -0
- package/dist/toast-group.connect.js +70 -57
- package/dist/toast-group.connect.mjs +3 -4
- package/dist/toast-group.machine.js +12 -77
- package/dist/toast-group.machine.mjs +4 -5
- package/dist/toast.anatomy.d.ts +2 -2
- package/dist/toast.connect.d.ts +34 -1
- package/dist/toast.connect.js +51 -49
- package/dist/toast.connect.mjs +2 -2
- package/dist/toast.dom.d.ts +4 -1
- package/dist/toast.dom.js +2 -31
- package/dist/toast.dom.mjs +1 -1
- package/dist/toast.machine.js +8 -72
- package/dist/toast.machine.mjs +3 -4
- package/dist/toast.utils.js +12 -12
- package/dist/toast.utils.mjs +1 -1
- package/package.json +6 -5
- package/dist/chunk-AZ32UDL3.mjs +0 -41
- package/dist/chunk-LHAZKBRJ.mjs +0 -19
package/dist/toast.machine.js
CHANGED
|
@@ -24,77 +24,12 @@ __export(toast_machine_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(toast_machine_exports);
|
|
26
26
|
var import_core = require("@zag-js/core");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var runIfFn = (v, ...a) => {
|
|
30
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
31
|
-
return res ?? void 0;
|
|
32
|
-
};
|
|
33
|
-
var cast = (v) => v;
|
|
34
|
-
|
|
35
|
-
// ../../utilities/core/src/guard.ts
|
|
36
|
-
var isArray = (v) => Array.isArray(v);
|
|
37
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
38
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
39
|
-
|
|
40
|
-
// ../../utilities/core/src/object.ts
|
|
41
|
-
function compact(obj) {
|
|
42
|
-
if (obj === void 0)
|
|
43
|
-
return obj;
|
|
44
|
-
return Object.fromEntries(
|
|
45
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ../../utilities/dom/src/query.ts
|
|
50
|
-
function isDocument(el) {
|
|
51
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
52
|
-
}
|
|
53
|
-
function isWindow(value) {
|
|
54
|
-
return value?.toString() === "[object Window]";
|
|
55
|
-
}
|
|
56
|
-
function getDocument(el) {
|
|
57
|
-
if (isWindow(el))
|
|
58
|
-
return el.document;
|
|
59
|
-
if (isDocument(el))
|
|
60
|
-
return el;
|
|
61
|
-
return el?.ownerDocument ?? document;
|
|
62
|
-
}
|
|
63
|
-
function defineDomHelpers(helpers) {
|
|
64
|
-
const dom2 = {
|
|
65
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
66
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
67
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
68
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
69
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
70
|
-
};
|
|
71
|
-
return {
|
|
72
|
-
...dom2,
|
|
73
|
-
...helpers
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// ../../utilities/dom/src/listener.ts
|
|
78
|
-
var isRef = (v) => hasProp(v, "current");
|
|
79
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
80
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
81
|
-
node?.addEventListener(eventName, handler, options);
|
|
82
|
-
return () => {
|
|
83
|
-
node?.removeEventListener(eventName, handler, options);
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// ../../utilities/dom/src/visibility-event.ts
|
|
88
|
-
function trackDocumentVisibility(_doc, callback) {
|
|
89
|
-
const doc = cast(_doc);
|
|
90
|
-
return addDomEvent(doc, "visibilitychange", () => {
|
|
91
|
-
const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
|
|
92
|
-
callback(!!hidden);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
27
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
28
|
+
var import_utils = require("@zag-js/utils");
|
|
95
29
|
|
|
96
30
|
// src/toast.dom.ts
|
|
97
|
-
var
|
|
31
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
32
|
+
var dom = (0, import_dom_query.createScope)({
|
|
98
33
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
99
34
|
getRootId: (ctx) => `toast:${ctx.id}`,
|
|
100
35
|
getTitleId: (ctx) => `toast:${ctx.id}:title`,
|
|
@@ -119,7 +54,7 @@ function getToastDuration(duration, type) {
|
|
|
119
54
|
var { not, and, or } = import_core.guards;
|
|
120
55
|
function createToastMachine(options = {}) {
|
|
121
56
|
const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 0, ...restProps } = options;
|
|
122
|
-
const ctx = compact(restProps);
|
|
57
|
+
const ctx = (0, import_utils.compact)(restProps);
|
|
123
58
|
const computedDuration = getToastDuration(duration, type);
|
|
124
59
|
return (0, import_core.createMachine)(
|
|
125
60
|
{
|
|
@@ -206,8 +141,9 @@ function createToastMachine(options = {}) {
|
|
|
206
141
|
trackDocumentVisibility(ctx2, _evt, { send }) {
|
|
207
142
|
if (!ctx2.pauseOnPageIdle)
|
|
208
143
|
return;
|
|
209
|
-
|
|
210
|
-
|
|
144
|
+
const doc = dom.getDoc(ctx2);
|
|
145
|
+
return (0, import_dom_event.addDomEvent)(doc, "visibilitychange", () => {
|
|
146
|
+
send(doc.visibilityState === "hidden" ? "PAUSE" : "RESUME");
|
|
211
147
|
});
|
|
212
148
|
}
|
|
213
149
|
},
|
package/dist/toast.machine.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createToastMachine
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-AZ32UDL3.mjs";
|
|
3
|
+
} from "./chunk-EQTV3BNM.mjs";
|
|
4
|
+
import "./chunk-DBPKSADW.mjs";
|
|
5
|
+
import "./chunk-DUZD3NLM.mjs";
|
|
7
6
|
export {
|
|
8
7
|
createToastMachine
|
|
9
8
|
};
|
package/dist/toast.utils.js
CHANGED
|
@@ -47,11 +47,11 @@ function getToastDuration(duration, type) {
|
|
|
47
47
|
}
|
|
48
48
|
function getGroupPlacementStyle(ctx, placement) {
|
|
49
49
|
const offset = ctx.offsets;
|
|
50
|
-
const
|
|
50
|
+
const computedOffset = typeof offset === "string" ? { left: offset, right: offset, bottom: offset, top: offset } : offset;
|
|
51
51
|
const rtl = ctx.dir === "rtl";
|
|
52
|
-
const
|
|
53
|
-
const isRighty =
|
|
54
|
-
const isLefty =
|
|
52
|
+
const computedPlacement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
|
|
53
|
+
const isRighty = computedPlacement.includes("right");
|
|
54
|
+
const isLefty = computedPlacement.includes("left");
|
|
55
55
|
const styles = {
|
|
56
56
|
position: "fixed",
|
|
57
57
|
pointerEvents: ctx.count > 0 ? void 0 : "none",
|
|
@@ -66,20 +66,20 @@ function getGroupPlacementStyle(ctx, placement) {
|
|
|
66
66
|
if (isLefty)
|
|
67
67
|
alignItems = "flex-start";
|
|
68
68
|
styles.alignItems = alignItems;
|
|
69
|
-
if (
|
|
70
|
-
const offset2 =
|
|
69
|
+
if (computedPlacement.includes("top")) {
|
|
70
|
+
const offset2 = computedOffset.top;
|
|
71
71
|
styles.top = `calc(env(safe-area-inset-top, 0px) + ${offset2})`;
|
|
72
72
|
}
|
|
73
|
-
if (
|
|
74
|
-
const offset2 =
|
|
73
|
+
if (computedPlacement.includes("bottom")) {
|
|
74
|
+
const offset2 = computedOffset.bottom;
|
|
75
75
|
styles.bottom = `calc(env(safe-area-inset-bottom, 0px) + ${offset2})`;
|
|
76
76
|
}
|
|
77
|
-
if (!
|
|
78
|
-
const offset2 =
|
|
77
|
+
if (!computedPlacement.includes("left")) {
|
|
78
|
+
const offset2 = computedOffset.right;
|
|
79
79
|
styles.right = `calc(env(safe-area-inset-right, 0px) + ${offset2})`;
|
|
80
80
|
}
|
|
81
|
-
if (!
|
|
82
|
-
const offset2 =
|
|
81
|
+
if (!computedPlacement.includes("right")) {
|
|
82
|
+
const offset2 = computedOffset.left;
|
|
83
83
|
styles.left = `calc(env(safe-area-inset-left, 0px) + ${offset2})`;
|
|
84
84
|
}
|
|
85
85
|
return styles;
|
package/dist/toast.utils.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/toast",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"description": "Core logic for the toast widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,13 +27,14 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@zag-js/anatomy": "0.1.4",
|
|
30
|
-
"@zag-js/core": "0.2.
|
|
30
|
+
"@zag-js/core": "0.2.10",
|
|
31
|
+
"@zag-js/dom-query": "0.1.4",
|
|
32
|
+
"@zag-js/dom-event": "0.0.1",
|
|
33
|
+
"@zag-js/utils": "0.3.3",
|
|
31
34
|
"@zag-js/types": "0.3.4"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
|
-
"clean-package": "2.2.0"
|
|
35
|
-
"@zag-js/dom-utils": "0.2.4",
|
|
36
|
-
"@zag-js/utils": "0.3.3"
|
|
37
|
+
"clean-package": "2.2.0"
|
|
37
38
|
},
|
|
38
39
|
"clean-package": "../../../clean-package.config.json",
|
|
39
40
|
"main": "dist/index.js",
|
package/dist/chunk-AZ32UDL3.mjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// ../../utilities/dom/src/query.ts
|
|
2
|
-
function isDocument(el) {
|
|
3
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
4
|
-
}
|
|
5
|
-
function isWindow(value) {
|
|
6
|
-
return value?.toString() === "[object Window]";
|
|
7
|
-
}
|
|
8
|
-
function getDocument(el) {
|
|
9
|
-
if (isWindow(el))
|
|
10
|
-
return el.document;
|
|
11
|
-
if (isDocument(el))
|
|
12
|
-
return el;
|
|
13
|
-
return el?.ownerDocument ?? document;
|
|
14
|
-
}
|
|
15
|
-
function defineDomHelpers(helpers) {
|
|
16
|
-
const dom2 = {
|
|
17
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
18
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
19
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
20
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
21
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
22
|
-
};
|
|
23
|
-
return {
|
|
24
|
-
...dom2,
|
|
25
|
-
...helpers
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/toast.dom.ts
|
|
30
|
-
var dom = defineDomHelpers({
|
|
31
|
-
getGroupId: (placement) => `toast-group:${placement}`,
|
|
32
|
-
getRootId: (ctx) => `toast:${ctx.id}`,
|
|
33
|
-
getTitleId: (ctx) => `toast:${ctx.id}:title`,
|
|
34
|
-
getDescriptionId: (ctx) => `toast:${ctx.id}:description`,
|
|
35
|
-
getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
|
|
36
|
-
getPortalId: (ctx) => `toast-portal:${ctx.id}`
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
dom
|
|
41
|
-
};
|
package/dist/chunk-LHAZKBRJ.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// ../../utilities/core/src/functions.ts
|
|
2
|
-
var runIfFn = (v, ...a) => {
|
|
3
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
4
|
-
return res ?? void 0;
|
|
5
|
-
};
|
|
6
|
-
var cast = (v) => v;
|
|
7
|
-
var uuid = /* @__PURE__ */ (() => {
|
|
8
|
-
let id = 0;
|
|
9
|
-
return () => {
|
|
10
|
-
id++;
|
|
11
|
-
return id.toString(36);
|
|
12
|
-
};
|
|
13
|
-
})();
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
runIfFn,
|
|
17
|
-
cast,
|
|
18
|
-
uuid
|
|
19
|
-
};
|