@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
|
@@ -25,55 +25,16 @@ __export(toast_group_connect_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(toast_group_connect_exports);
|
|
27
27
|
var import_core = require("@zag-js/core");
|
|
28
|
-
|
|
29
|
-
// ../../utilities/core/src/functions.ts
|
|
30
|
-
var runIfFn = (v, ...a) => {
|
|
31
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
32
|
-
return res ?? void 0;
|
|
33
|
-
};
|
|
34
|
-
var uuid = /* @__PURE__ */ (() => {
|
|
35
|
-
let id = 0;
|
|
36
|
-
return () => {
|
|
37
|
-
id++;
|
|
38
|
-
return id.toString(36);
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
28
|
+
var import_utils = require("@zag-js/utils");
|
|
41
29
|
|
|
42
30
|
// src/toast.anatomy.ts
|
|
43
31
|
var import_anatomy = require("@zag-js/anatomy");
|
|
44
32
|
var anatomy = (0, import_anatomy.createAnatomy)("toast").parts("group", "root", "title", "description", "closeTrigger");
|
|
45
33
|
var parts = anatomy.build();
|
|
46
34
|
|
|
47
|
-
// ../../utilities/dom/src/query.ts
|
|
48
|
-
function isDocument(el) {
|
|
49
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
50
|
-
}
|
|
51
|
-
function isWindow(value) {
|
|
52
|
-
return value?.toString() === "[object Window]";
|
|
53
|
-
}
|
|
54
|
-
function getDocument(el) {
|
|
55
|
-
if (isWindow(el))
|
|
56
|
-
return el.document;
|
|
57
|
-
if (isDocument(el))
|
|
58
|
-
return el;
|
|
59
|
-
return el?.ownerDocument ?? document;
|
|
60
|
-
}
|
|
61
|
-
function defineDomHelpers(helpers) {
|
|
62
|
-
const dom2 = {
|
|
63
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
64
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
65
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
66
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
67
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
68
|
-
};
|
|
69
|
-
return {
|
|
70
|
-
...dom2,
|
|
71
|
-
...helpers
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
35
|
// src/toast.dom.ts
|
|
76
|
-
var
|
|
36
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
37
|
+
var dom = (0, import_dom_query.createScope)({
|
|
77
38
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
78
39
|
getRootId: (ctx) => `toast:${ctx.id}`,
|
|
79
40
|
getTitleId: (ctx) => `toast:${ctx.id}:title`,
|
|
@@ -94,11 +55,11 @@ function getToastsByPlacement(toasts) {
|
|
|
94
55
|
}
|
|
95
56
|
function getGroupPlacementStyle(ctx, placement) {
|
|
96
57
|
const offset = ctx.offsets;
|
|
97
|
-
const
|
|
58
|
+
const computedOffset = typeof offset === "string" ? { left: offset, right: offset, bottom: offset, top: offset } : offset;
|
|
98
59
|
const rtl = ctx.dir === "rtl";
|
|
99
|
-
const
|
|
100
|
-
const isRighty =
|
|
101
|
-
const isLefty =
|
|
60
|
+
const computedPlacement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
|
|
61
|
+
const isRighty = computedPlacement.includes("right");
|
|
62
|
+
const isLefty = computedPlacement.includes("left");
|
|
102
63
|
const styles = {
|
|
103
64
|
position: "fixed",
|
|
104
65
|
pointerEvents: ctx.count > 0 ? void 0 : "none",
|
|
@@ -113,20 +74,20 @@ function getGroupPlacementStyle(ctx, placement) {
|
|
|
113
74
|
if (isLefty)
|
|
114
75
|
alignItems = "flex-start";
|
|
115
76
|
styles.alignItems = alignItems;
|
|
116
|
-
if (
|
|
117
|
-
const offset2 =
|
|
77
|
+
if (computedPlacement.includes("top")) {
|
|
78
|
+
const offset2 = computedOffset.top;
|
|
118
79
|
styles.top = `calc(env(safe-area-inset-top, 0px) + ${offset2})`;
|
|
119
80
|
}
|
|
120
|
-
if (
|
|
121
|
-
const offset2 =
|
|
81
|
+
if (computedPlacement.includes("bottom")) {
|
|
82
|
+
const offset2 = computedOffset.bottom;
|
|
122
83
|
styles.bottom = `calc(env(safe-area-inset-bottom, 0px) + ${offset2})`;
|
|
123
84
|
}
|
|
124
|
-
if (!
|
|
125
|
-
const offset2 =
|
|
85
|
+
if (!computedPlacement.includes("left")) {
|
|
86
|
+
const offset2 = computedOffset.right;
|
|
126
87
|
styles.right = `calc(env(safe-area-inset-right, 0px) + ${offset2})`;
|
|
127
88
|
}
|
|
128
|
-
if (!
|
|
129
|
-
const offset2 =
|
|
89
|
+
if (!computedPlacement.includes("right")) {
|
|
90
|
+
const offset2 = computedOffset.left;
|
|
130
91
|
styles.left = `calc(env(safe-area-inset-left, 0px) + ${offset2})`;
|
|
131
92
|
}
|
|
132
93
|
return styles;
|
|
@@ -136,22 +97,40 @@ function getGroupPlacementStyle(ctx, placement) {
|
|
|
136
97
|
var toaster = {};
|
|
137
98
|
function groupConnect(state, send, normalize) {
|
|
138
99
|
const group = {
|
|
100
|
+
/**
|
|
101
|
+
* The total number of toasts
|
|
102
|
+
*/
|
|
139
103
|
count: state.context.count,
|
|
104
|
+
/**
|
|
105
|
+
* The active toasts
|
|
106
|
+
*/
|
|
140
107
|
toasts: state.context.toasts,
|
|
108
|
+
/**
|
|
109
|
+
* The active toasts by placement
|
|
110
|
+
*/
|
|
141
111
|
toastsByPlacement: getToastsByPlacement(state.context.toasts),
|
|
112
|
+
/**
|
|
113
|
+
* Returns whether the toast id is visible
|
|
114
|
+
*/
|
|
142
115
|
isVisible(id) {
|
|
143
116
|
if (!state.context.toasts.length)
|
|
144
117
|
return false;
|
|
145
118
|
return !!state.context.toasts.find((toast) => toast.id == id);
|
|
146
119
|
},
|
|
120
|
+
/**
|
|
121
|
+
* Function to create a toast.
|
|
122
|
+
*/
|
|
147
123
|
create(options) {
|
|
148
|
-
const uid = `toast:${uuid()}`;
|
|
124
|
+
const uid = `toast:${(0, import_utils.uuid)()}`;
|
|
149
125
|
const id = options.id ? options.id : uid;
|
|
150
126
|
if (group.isVisible(id))
|
|
151
127
|
return;
|
|
152
128
|
send({ type: "ADD_TOAST", toast: { ...options, id } });
|
|
153
129
|
return id;
|
|
154
130
|
},
|
|
131
|
+
/**
|
|
132
|
+
* Function to create or update a toast.
|
|
133
|
+
*/
|
|
155
134
|
upsert(options) {
|
|
156
135
|
const { id } = options;
|
|
157
136
|
const isVisible = id ? group.isVisible(id) : false;
|
|
@@ -161,6 +140,10 @@ function groupConnect(state, send, normalize) {
|
|
|
161
140
|
return group.create(options);
|
|
162
141
|
}
|
|
163
142
|
},
|
|
143
|
+
/**
|
|
144
|
+
* Function to dismiss a toast by id.
|
|
145
|
+
* If no id is provided, all toasts will be dismissed.
|
|
146
|
+
*/
|
|
164
147
|
dismiss(id) {
|
|
165
148
|
if (id == null) {
|
|
166
149
|
send("DISMISS_ALL");
|
|
@@ -168,6 +151,10 @@ function groupConnect(state, send, normalize) {
|
|
|
168
151
|
send({ type: "DISMISS_TOAST", id });
|
|
169
152
|
}
|
|
170
153
|
},
|
|
154
|
+
/**
|
|
155
|
+
* Function to remove a toast by id.
|
|
156
|
+
* If no id is provided, all toasts will be removed.
|
|
157
|
+
*/
|
|
171
158
|
remove(id) {
|
|
172
159
|
if (id == null) {
|
|
173
160
|
send("REMOVE_ALL");
|
|
@@ -175,41 +162,64 @@ function groupConnect(state, send, normalize) {
|
|
|
175
162
|
send({ type: "REMOVE_TOAST", id });
|
|
176
163
|
}
|
|
177
164
|
},
|
|
165
|
+
/**
|
|
166
|
+
* Function to dismiss all toasts by placement.
|
|
167
|
+
*/
|
|
178
168
|
dismissByPlacement(placement) {
|
|
179
169
|
const toasts = group.toastsByPlacement[placement];
|
|
180
170
|
if (toasts) {
|
|
181
171
|
toasts.forEach((toast) => group.dismiss(toast.id));
|
|
182
172
|
}
|
|
183
173
|
},
|
|
174
|
+
/**
|
|
175
|
+
* Function to update a toast's options by id.
|
|
176
|
+
*/
|
|
184
177
|
update(id, options) {
|
|
185
178
|
if (!group.isVisible(id))
|
|
186
179
|
return;
|
|
187
180
|
send({ type: "UPDATE_TOAST", id, toast: options });
|
|
188
181
|
return id;
|
|
189
182
|
},
|
|
183
|
+
/**
|
|
184
|
+
* Function to create a loading toast.
|
|
185
|
+
*/
|
|
190
186
|
loading(options) {
|
|
191
187
|
options.type = "loading";
|
|
192
188
|
return group.upsert(options);
|
|
193
189
|
},
|
|
190
|
+
/**
|
|
191
|
+
* Function to create a success toast.
|
|
192
|
+
*/
|
|
194
193
|
success(options) {
|
|
195
194
|
options.type = "success";
|
|
196
195
|
return group.upsert(options);
|
|
197
196
|
},
|
|
197
|
+
/**
|
|
198
|
+
* Function to create an error toast.
|
|
199
|
+
*/
|
|
198
200
|
error(options) {
|
|
199
201
|
options.type = "error";
|
|
200
202
|
return group.upsert(options);
|
|
201
203
|
},
|
|
204
|
+
/**
|
|
205
|
+
* Function to create a toast from a promise.
|
|
206
|
+
* - When the promise resolves, the toast will be updated with the success options.
|
|
207
|
+
* - When the promise rejects, the toast will be updated with the error options.
|
|
208
|
+
*/
|
|
202
209
|
promise(promise, options, shared = {}) {
|
|
203
210
|
const id = group.loading({ ...shared, ...options.loading });
|
|
204
211
|
promise.then((response) => {
|
|
205
|
-
const successOptions = runIfFn(options.success, response);
|
|
212
|
+
const successOptions = (0, import_utils.runIfFn)(options.success, response);
|
|
206
213
|
group.success({ ...shared, ...successOptions, id });
|
|
207
214
|
}).catch((error) => {
|
|
208
|
-
const errorOptions = runIfFn(options.error, error);
|
|
215
|
+
const errorOptions = (0, import_utils.runIfFn)(options.error, error);
|
|
209
216
|
group.error({ ...shared, ...errorOptions, id });
|
|
210
217
|
});
|
|
211
218
|
return promise;
|
|
212
219
|
},
|
|
220
|
+
/**
|
|
221
|
+
* Function to pause a toast by id.
|
|
222
|
+
*/
|
|
213
223
|
pause(id) {
|
|
214
224
|
if (id == null) {
|
|
215
225
|
send("PAUSE_ALL");
|
|
@@ -217,6 +227,9 @@ function groupConnect(state, send, normalize) {
|
|
|
217
227
|
send({ type: "PAUSE_TOAST", id });
|
|
218
228
|
}
|
|
219
229
|
},
|
|
230
|
+
/**
|
|
231
|
+
* Function to resume a toast by id.
|
|
232
|
+
*/
|
|
220
233
|
resume(id) {
|
|
221
234
|
if (id == null) {
|
|
222
235
|
send("RESUME_ALL");
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
groupConnect,
|
|
3
3
|
toaster
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6TPPYHFP.mjs";
|
|
5
5
|
import "./chunk-GQHI2OMI.mjs";
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-AZ32UDL3.mjs";
|
|
6
|
+
import "./chunk-DBPKSADW.mjs";
|
|
7
|
+
import "./chunk-DUZD3NLM.mjs";
|
|
9
8
|
export {
|
|
10
9
|
groupConnect,
|
|
11
10
|
toaster
|
|
@@ -24,83 +24,17 @@ __export(toast_group_machine_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(toast_group_machine_exports);
|
|
26
26
|
var import_core2 = require("@zag-js/core");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var MAX_Z_INDEX = 2147483647;
|
|
30
|
-
|
|
31
|
-
// ../../utilities/core/src/functions.ts
|
|
32
|
-
var runIfFn = (v, ...a) => {
|
|
33
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
34
|
-
return res ?? void 0;
|
|
35
|
-
};
|
|
36
|
-
var cast = (v) => v;
|
|
37
|
-
|
|
38
|
-
// ../../utilities/core/src/guard.ts
|
|
39
|
-
var isArray = (v) => Array.isArray(v);
|
|
40
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
41
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
42
|
-
|
|
43
|
-
// ../../utilities/core/src/object.ts
|
|
44
|
-
function compact(obj) {
|
|
45
|
-
if (obj === void 0)
|
|
46
|
-
return obj;
|
|
47
|
-
return Object.fromEntries(
|
|
48
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// ../../utilities/dom/src/query.ts
|
|
53
|
-
function isDocument(el) {
|
|
54
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
55
|
-
}
|
|
56
|
-
function isWindow(value) {
|
|
57
|
-
return value?.toString() === "[object Window]";
|
|
58
|
-
}
|
|
59
|
-
function getDocument(el) {
|
|
60
|
-
if (isWindow(el))
|
|
61
|
-
return el.document;
|
|
62
|
-
if (isDocument(el))
|
|
63
|
-
return el;
|
|
64
|
-
return el?.ownerDocument ?? document;
|
|
65
|
-
}
|
|
66
|
-
function defineDomHelpers(helpers) {
|
|
67
|
-
const dom2 = {
|
|
68
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
69
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
70
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
71
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
72
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
73
|
-
};
|
|
74
|
-
return {
|
|
75
|
-
...dom2,
|
|
76
|
-
...helpers
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// ../../utilities/dom/src/listener.ts
|
|
81
|
-
var isRef = (v) => hasProp(v, "current");
|
|
82
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
83
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
84
|
-
node?.addEventListener(eventName, handler, options);
|
|
85
|
-
return () => {
|
|
86
|
-
node?.removeEventListener(eventName, handler, options);
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ../../utilities/dom/src/visibility-event.ts
|
|
91
|
-
function trackDocumentVisibility(_doc, callback) {
|
|
92
|
-
const doc = cast(_doc);
|
|
93
|
-
return addDomEvent(doc, "visibilitychange", () => {
|
|
94
|
-
const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
|
|
95
|
-
callback(!!hidden);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
27
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
28
|
+
var import_utils2 = require("@zag-js/utils");
|
|
98
29
|
|
|
99
30
|
// src/toast.machine.ts
|
|
100
31
|
var import_core = require("@zag-js/core");
|
|
32
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
33
|
+
var import_utils = require("@zag-js/utils");
|
|
101
34
|
|
|
102
35
|
// src/toast.dom.ts
|
|
103
|
-
var
|
|
36
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
37
|
+
var dom = (0, import_dom_query.createScope)({
|
|
104
38
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
105
39
|
getRootId: (ctx) => `toast:${ctx.id}`,
|
|
106
40
|
getTitleId: (ctx) => `toast:${ctx.id}:title`,
|
|
@@ -125,7 +59,7 @@ function getToastDuration(duration, type) {
|
|
|
125
59
|
var { not, and, or } = import_core.guards;
|
|
126
60
|
function createToastMachine(options = {}) {
|
|
127
61
|
const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 0, ...restProps } = options;
|
|
128
|
-
const ctx = compact(restProps);
|
|
62
|
+
const ctx = (0, import_utils.compact)(restProps);
|
|
129
63
|
const computedDuration = getToastDuration(duration, type);
|
|
130
64
|
return (0, import_core.createMachine)(
|
|
131
65
|
{
|
|
@@ -212,8 +146,9 @@ function createToastMachine(options = {}) {
|
|
|
212
146
|
trackDocumentVisibility(ctx2, _evt, { send }) {
|
|
213
147
|
if (!ctx2.pauseOnPageIdle)
|
|
214
148
|
return;
|
|
215
|
-
|
|
216
|
-
|
|
149
|
+
const doc = dom.getDoc(ctx2);
|
|
150
|
+
return (0, import_dom_event.addDomEvent)(doc, "visibilitychange", () => {
|
|
151
|
+
send(doc.visibilityState === "hidden" ? "PAUSE" : "RESUME");
|
|
217
152
|
});
|
|
218
153
|
}
|
|
219
154
|
},
|
|
@@ -261,7 +196,7 @@ function createToastMachine(options = {}) {
|
|
|
261
196
|
|
|
262
197
|
// src/toast-group.machine.ts
|
|
263
198
|
function groupMachine(userContext) {
|
|
264
|
-
const ctx = compact(userContext);
|
|
199
|
+
const ctx = (0, import_utils2.compact)(userContext);
|
|
265
200
|
return (0, import_core2.createMachine)({
|
|
266
201
|
id: "toaster",
|
|
267
202
|
initial: "active",
|
|
@@ -270,7 +205,7 @@ function groupMachine(userContext) {
|
|
|
270
205
|
max: Number.MAX_SAFE_INTEGER,
|
|
271
206
|
toasts: [],
|
|
272
207
|
gutter: "1rem",
|
|
273
|
-
zIndex: MAX_Z_INDEX,
|
|
208
|
+
zIndex: import_dom_query2.MAX_Z_INDEX,
|
|
274
209
|
pauseOnPageIdle: false,
|
|
275
210
|
pauseOnInteraction: true,
|
|
276
211
|
offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" },
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
groupMachine
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-AZ32UDL3.mjs";
|
|
3
|
+
} from "./chunk-TCF4OLIQ.mjs";
|
|
4
|
+
import "./chunk-EQTV3BNM.mjs";
|
|
5
|
+
import "./chunk-DBPKSADW.mjs";
|
|
6
|
+
import "./chunk-DUZD3NLM.mjs";
|
|
8
7
|
export {
|
|
9
8
|
groupMachine
|
|
10
9
|
};
|
package/dist/toast.anatomy.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
2
|
|
|
3
|
-
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"
|
|
4
|
-
declare const parts: Record<"
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"title" | "group" | "root" | "description" | "closeTrigger">;
|
|
4
|
+
declare const parts: Record<"title" | "group" | "root" | "description" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
|
|
5
5
|
|
|
6
6
|
export { anatomy, parts };
|
package/dist/toast.connect.d.ts
CHANGED
|
@@ -3,21 +3,54 @@ import { PropTypes, NormalizeProps } from '@zag-js/types';
|
|
|
3
3
|
import '@zag-js/core';
|
|
4
4
|
|
|
5
5
|
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
6
|
+
/**
|
|
7
|
+
* The type of the toast.
|
|
8
|
+
*/
|
|
6
9
|
type: Type;
|
|
10
|
+
/**
|
|
11
|
+
* The title of the toast.
|
|
12
|
+
*/
|
|
7
13
|
title: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The description of the toast.
|
|
16
|
+
*/
|
|
8
17
|
description: string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The current placement of the toast.
|
|
20
|
+
*/
|
|
9
21
|
placement: Placement;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the toast is visible.
|
|
24
|
+
*/
|
|
10
25
|
isVisible: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the toast is paused.
|
|
28
|
+
*/
|
|
11
29
|
isPaused: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the toast is in RTL mode.
|
|
32
|
+
*/
|
|
12
33
|
isRtl: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Function to pause the toast (keeping it visible).
|
|
36
|
+
*/
|
|
13
37
|
pause(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Function to resume the toast dismissing.
|
|
40
|
+
*/
|
|
14
41
|
resume(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Function to instantly dismiss the toast.
|
|
44
|
+
*/
|
|
15
45
|
dismiss(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Function render the toast in the DOM (based on the defined `render` property)
|
|
48
|
+
*/
|
|
49
|
+
render(): any;
|
|
16
50
|
rootProps: T["element"];
|
|
17
51
|
titleProps: T["element"];
|
|
18
52
|
descriptionProps: T["element"];
|
|
19
53
|
closeTriggerProps: T["button"];
|
|
20
|
-
render(): any;
|
|
21
54
|
};
|
|
22
55
|
|
|
23
56
|
export { connect };
|
package/dist/toast.connect.js
CHANGED
|
@@ -23,39 +23,7 @@ __export(toast_connect_exports, {
|
|
|
23
23
|
connect: () => connect
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(toast_connect_exports);
|
|
26
|
-
|
|
27
|
-
// ../../utilities/dom/src/attrs.ts
|
|
28
|
-
var dataAttr = (guard) => {
|
|
29
|
-
return guard ? "" : void 0;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// ../../utilities/dom/src/query.ts
|
|
33
|
-
function isDocument(el) {
|
|
34
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
35
|
-
}
|
|
36
|
-
function isWindow(value) {
|
|
37
|
-
return value?.toString() === "[object Window]";
|
|
38
|
-
}
|
|
39
|
-
function getDocument(el) {
|
|
40
|
-
if (isWindow(el))
|
|
41
|
-
return el.document;
|
|
42
|
-
if (isDocument(el))
|
|
43
|
-
return el;
|
|
44
|
-
return el?.ownerDocument ?? document;
|
|
45
|
-
}
|
|
46
|
-
function defineDomHelpers(helpers) {
|
|
47
|
-
const dom2 = {
|
|
48
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
49
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
50
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
51
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
52
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
53
|
-
};
|
|
54
|
-
return {
|
|
55
|
-
...dom2,
|
|
56
|
-
...helpers
|
|
57
|
-
};
|
|
58
|
-
}
|
|
26
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
59
27
|
|
|
60
28
|
// src/toast.anatomy.ts
|
|
61
29
|
var import_anatomy = require("@zag-js/anatomy");
|
|
@@ -63,7 +31,8 @@ var anatomy = (0, import_anatomy.createAnatomy)("toast").parts("group", "root",
|
|
|
63
31
|
var parts = anatomy.build();
|
|
64
32
|
|
|
65
33
|
// src/toast.dom.ts
|
|
66
|
-
var
|
|
34
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
35
|
+
var dom = (0, import_dom_query.createScope)({
|
|
67
36
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
68
37
|
getRootId: (ctx) => `toast:${ctx.id}`,
|
|
69
38
|
getTitleId: (ctx) => `toast:${ctx.id}:title`,
|
|
@@ -79,27 +48,73 @@ function connect(state, send, normalize) {
|
|
|
79
48
|
const pauseOnInteraction = state.context.pauseOnInteraction;
|
|
80
49
|
const placement = state.context.placement;
|
|
81
50
|
return {
|
|
51
|
+
/**
|
|
52
|
+
* The type of the toast.
|
|
53
|
+
*/
|
|
82
54
|
type: state.context.type,
|
|
55
|
+
/**
|
|
56
|
+
* The title of the toast.
|
|
57
|
+
*/
|
|
83
58
|
title: state.context.title,
|
|
59
|
+
/**
|
|
60
|
+
* The description of the toast.
|
|
61
|
+
*/
|
|
84
62
|
description: state.context.description,
|
|
63
|
+
/**
|
|
64
|
+
* The current placement of the toast.
|
|
65
|
+
*/
|
|
85
66
|
placement,
|
|
67
|
+
/**
|
|
68
|
+
* Whether the toast is visible.
|
|
69
|
+
*/
|
|
86
70
|
isVisible,
|
|
71
|
+
/**
|
|
72
|
+
* Whether the toast is paused.
|
|
73
|
+
*/
|
|
87
74
|
isPaused,
|
|
75
|
+
/**
|
|
76
|
+
* Whether the toast is in RTL mode.
|
|
77
|
+
*/
|
|
88
78
|
isRtl: state.context.dir === "rtl",
|
|
79
|
+
/**
|
|
80
|
+
* Function to pause the toast (keeping it visible).
|
|
81
|
+
*/
|
|
89
82
|
pause() {
|
|
90
83
|
send("PAUSE");
|
|
91
84
|
},
|
|
85
|
+
/**
|
|
86
|
+
* Function to resume the toast dismissing.
|
|
87
|
+
*/
|
|
92
88
|
resume() {
|
|
93
89
|
send("RESUME");
|
|
94
90
|
},
|
|
91
|
+
/**
|
|
92
|
+
* Function to instantly dismiss the toast.
|
|
93
|
+
*/
|
|
95
94
|
dismiss() {
|
|
96
95
|
send("DISMISS");
|
|
97
96
|
},
|
|
97
|
+
/**
|
|
98
|
+
* Function render the toast in the DOM (based on the defined `render` property)
|
|
99
|
+
*/
|
|
100
|
+
render() {
|
|
101
|
+
return state.context.render?.({
|
|
102
|
+
id: state.context.id,
|
|
103
|
+
type: state.context.type,
|
|
104
|
+
duration: state.context.duration,
|
|
105
|
+
title: state.context.title,
|
|
106
|
+
placement: state.context.placement,
|
|
107
|
+
description: state.context.description,
|
|
108
|
+
dismiss() {
|
|
109
|
+
send("DISMISS");
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
},
|
|
98
113
|
rootProps: normalize.element({
|
|
99
114
|
...parts.root.attrs,
|
|
100
115
|
dir: state.context.dir,
|
|
101
116
|
id: dom.getRootId(state.context),
|
|
102
|
-
"data-open": dataAttr(isVisible),
|
|
117
|
+
"data-open": (0, import_dom_query2.dataAttr)(isVisible),
|
|
103
118
|
"data-type": state.context.type,
|
|
104
119
|
"data-placement": placement,
|
|
105
120
|
role: "status",
|
|
@@ -155,20 +170,7 @@ function connect(state, send, normalize) {
|
|
|
155
170
|
onClick() {
|
|
156
171
|
send("DISMISS");
|
|
157
172
|
}
|
|
158
|
-
})
|
|
159
|
-
render() {
|
|
160
|
-
return state.context.render?.({
|
|
161
|
-
id: state.context.id,
|
|
162
|
-
type: state.context.type,
|
|
163
|
-
duration: state.context.duration,
|
|
164
|
-
title: state.context.title,
|
|
165
|
-
placement: state.context.placement,
|
|
166
|
-
description: state.context.description,
|
|
167
|
-
dismiss() {
|
|
168
|
-
send("DISMISS");
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
173
|
+
})
|
|
172
174
|
};
|
|
173
175
|
}
|
|
174
176
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/toast.connect.mjs
CHANGED
package/dist/toast.dom.d.ts
CHANGED
|
@@ -15,9 +15,12 @@ declare const dom: {
|
|
|
15
15
|
getActiveElement: (ctx: {
|
|
16
16
|
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
17
17
|
}) => HTMLElement | null;
|
|
18
|
-
getById: <T = HTMLElement>(ctx: {
|
|
18
|
+
getById: <T extends HTMLElement = HTMLElement>(ctx: {
|
|
19
19
|
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
20
20
|
}, id: string) => T | null;
|
|
21
|
+
queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
|
|
22
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
23
|
+
}, id: string) => T_1;
|
|
21
24
|
} & {
|
|
22
25
|
getGroupId: (placement: Placement) => string;
|
|
23
26
|
getRootId: (ctx: MachineContext) => string;
|
package/dist/toast.dom.js
CHANGED
|
@@ -23,37 +23,8 @@ __export(toast_dom_exports, {
|
|
|
23
23
|
dom: () => dom
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(toast_dom_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function isDocument(el) {
|
|
29
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
30
|
-
}
|
|
31
|
-
function isWindow(value) {
|
|
32
|
-
return value?.toString() === "[object Window]";
|
|
33
|
-
}
|
|
34
|
-
function getDocument(el) {
|
|
35
|
-
if (isWindow(el))
|
|
36
|
-
return el.document;
|
|
37
|
-
if (isDocument(el))
|
|
38
|
-
return el;
|
|
39
|
-
return el?.ownerDocument ?? document;
|
|
40
|
-
}
|
|
41
|
-
function defineDomHelpers(helpers) {
|
|
42
|
-
const dom2 = {
|
|
43
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
44
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
45
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
46
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
47
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
48
|
-
};
|
|
49
|
-
return {
|
|
50
|
-
...dom2,
|
|
51
|
-
...helpers
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/toast.dom.ts
|
|
56
|
-
var dom = defineDomHelpers({
|
|
26
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
27
|
+
var dom = (0, import_dom_query.createScope)({
|
|
57
28
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
58
29
|
getRootId: (ctx) => `toast:${ctx.id}`,
|
|
59
30
|
getTitleId: (ctx) => `toast:${ctx.id}:title`,
|