@zag-js/toast 0.2.6 → 0.2.7
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-2E56V7D3.mjs +104 -0
- package/dist/chunk-6MVNQK7B.mjs +144 -0
- package/dist/chunk-GQHI2OMI.mjs +9 -0
- package/dist/chunk-IEPKBUZZ.mjs +116 -0
- package/dist/chunk-KHVXQ4ZE.mjs +75 -0
- package/dist/chunk-LOJTIJID.mjs +66 -0
- package/dist/chunk-YVNTR4MK.mjs +202 -0
- package/dist/chunk-YVYADWQR.mjs +19 -0
- package/dist/index.d.ts +11 -1043
- package/dist/index.js +44 -32
- package/dist/index.mjs +23 -656
- package/dist/toast-group.connect.d.ts +28 -0
- package/dist/toast-group.connect.js +296 -0
- package/dist/toast-group.connect.mjs +12 -0
- package/dist/toast-group.machine.d.ts +7 -0
- package/dist/toast-group.machine.js +401 -0
- package/dist/toast-group.machine.mjs +10 -0
- package/dist/toast.anatomy.d.ts +6 -0
- package/dist/toast.anatomy.js +34 -0
- package/dist/toast.anatomy.mjs +8 -0
- package/dist/toast.connect.d.ts +23 -0
- package/dist/toast.connect.js +212 -0
- package/dist/toast.connect.mjs +8 -0
- package/dist/toast.dom.d.ts +36 -0
- package/dist/toast.dom.js +101 -0
- package/dist/toast.dom.mjs +6 -0
- package/dist/toast.machine.d.ts +7 -0
- package/dist/toast.machine.js +305 -0
- package/dist/toast.machine.mjs +9 -0
- package/dist/toast.types.d.ts +150 -0
- package/dist/toast.types.js +18 -0
- package/dist/toast.types.mjs +0 -0
- package/dist/toast.utils.d.ts +10 -0
- package/dist/toast.utils.js +93 -0
- package/dist/toast.utils.mjs +12 -0
- package/package.json +21 -11
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/toast-group.machine.ts
|
|
21
|
+
var toast_group_machine_exports = {};
|
|
22
|
+
__export(toast_group_machine_exports, {
|
|
23
|
+
groupMachine: () => groupMachine
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(toast_group_machine_exports);
|
|
26
|
+
var import_core2 = require("@zag-js/core");
|
|
27
|
+
|
|
28
|
+
// ../../utilities/dom/src/constants.ts
|
|
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 != null ? 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 == null ? void 0 : value.toString()) === "[object Window]";
|
|
58
|
+
}
|
|
59
|
+
function getDocument(el) {
|
|
60
|
+
var _a;
|
|
61
|
+
if (isWindow(el))
|
|
62
|
+
return el.document;
|
|
63
|
+
if (isDocument(el))
|
|
64
|
+
return el;
|
|
65
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
66
|
+
}
|
|
67
|
+
function defineDomHelpers(helpers) {
|
|
68
|
+
const dom2 = {
|
|
69
|
+
getRootNode: (ctx) => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
72
|
+
},
|
|
73
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
74
|
+
getWin: (ctx) => {
|
|
75
|
+
var _a;
|
|
76
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
77
|
+
},
|
|
78
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
79
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
80
|
+
createEmitter: (ctx, target) => {
|
|
81
|
+
const win = dom2.getWin(ctx);
|
|
82
|
+
return function emit(evt, detail, options) {
|
|
83
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
84
|
+
const eventName = `zag:${evt}`;
|
|
85
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
86
|
+
const event = new win.CustomEvent(eventName, init);
|
|
87
|
+
target.dispatchEvent(event);
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
createListener: (target) => {
|
|
91
|
+
return function listen(evt, handler) {
|
|
92
|
+
const eventName = `zag:${evt}`;
|
|
93
|
+
const listener = (e) => handler(e);
|
|
94
|
+
target.addEventListener(eventName, listener);
|
|
95
|
+
return () => target.removeEventListener(eventName, listener);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
...dom2,
|
|
101
|
+
...helpers
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ../../utilities/dom/src/listener.ts
|
|
106
|
+
var isRef = (v) => hasProp(v, "current");
|
|
107
|
+
function addDomEvent(target, eventName, handler, options) {
|
|
108
|
+
const node = isRef(target) ? target.current : runIfFn(target);
|
|
109
|
+
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
110
|
+
return () => {
|
|
111
|
+
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ../../utilities/dom/src/visibility-event.ts
|
|
116
|
+
function trackDocumentVisibility(_doc, callback) {
|
|
117
|
+
const doc = cast(_doc);
|
|
118
|
+
return addDomEvent(doc, "visibilitychange", () => {
|
|
119
|
+
const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
|
|
120
|
+
callback(!!hidden);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/toast.machine.ts
|
|
125
|
+
var import_core = require("@zag-js/core");
|
|
126
|
+
|
|
127
|
+
// src/toast.dom.ts
|
|
128
|
+
var dom = defineDomHelpers({
|
|
129
|
+
getGroupId: (placement) => `toast-group:${placement}`,
|
|
130
|
+
getRootId: (ctx) => `toast:${ctx.id}`,
|
|
131
|
+
getTitleId: (ctx) => `toast:${ctx.id}:title`,
|
|
132
|
+
getDescriptionId: (ctx) => `toast:${ctx.id}:description`,
|
|
133
|
+
getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
|
|
134
|
+
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
135
|
+
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
136
|
+
createPortalEl: (ctx) => {
|
|
137
|
+
const existing = dom.getPortalEl(ctx);
|
|
138
|
+
if (existing)
|
|
139
|
+
return existing;
|
|
140
|
+
const portal = dom.getDoc(ctx).createElement("toast-portal");
|
|
141
|
+
portal.id = dom.getPortalId(ctx);
|
|
142
|
+
return portal;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// src/toast.utils.ts
|
|
147
|
+
var defaultTimeouts = {
|
|
148
|
+
info: 5e3,
|
|
149
|
+
error: 5e3,
|
|
150
|
+
success: 2e3,
|
|
151
|
+
loading: Infinity,
|
|
152
|
+
custom: 5e3
|
|
153
|
+
};
|
|
154
|
+
function getToastDuration(duration, type) {
|
|
155
|
+
return duration != null ? duration : defaultTimeouts[type];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/toast.machine.ts
|
|
159
|
+
var { not, and, or } = import_core.guards;
|
|
160
|
+
function createToastMachine(options = {}) {
|
|
161
|
+
const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 0, ...restProps } = options;
|
|
162
|
+
const ctx = compact(restProps);
|
|
163
|
+
const computedDuration = getToastDuration(duration, type);
|
|
164
|
+
return (0, import_core.createMachine)(
|
|
165
|
+
{
|
|
166
|
+
id,
|
|
167
|
+
entry: "invokeOnOpen",
|
|
168
|
+
initial: type === "loading" ? "persist" : "active",
|
|
169
|
+
context: {
|
|
170
|
+
id,
|
|
171
|
+
type,
|
|
172
|
+
remaining: computedDuration,
|
|
173
|
+
duration: computedDuration,
|
|
174
|
+
removeDelay,
|
|
175
|
+
createdAt: Date.now(),
|
|
176
|
+
placement,
|
|
177
|
+
...ctx
|
|
178
|
+
},
|
|
179
|
+
on: {
|
|
180
|
+
UPDATE: [
|
|
181
|
+
{
|
|
182
|
+
guard: and("hasTypeChanged", "isChangingToLoading"),
|
|
183
|
+
target: "persist",
|
|
184
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
guard: or("hasDurationChanged", "hasTypeChanged"),
|
|
188
|
+
target: "active:temp",
|
|
189
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
},
|
|
196
|
+
states: {
|
|
197
|
+
"active:temp": {
|
|
198
|
+
tags: ["visible", "updating"],
|
|
199
|
+
after: {
|
|
200
|
+
0: "active"
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
persist: {
|
|
204
|
+
tags: ["visible", "paused"],
|
|
205
|
+
activities: "trackDocumentVisibility",
|
|
206
|
+
on: {
|
|
207
|
+
RESUME: {
|
|
208
|
+
guard: not("isLoadingType"),
|
|
209
|
+
target: "active",
|
|
210
|
+
actions: ["setCreatedAt"]
|
|
211
|
+
},
|
|
212
|
+
DISMISS: "dismissing"
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
active: {
|
|
216
|
+
tags: ["visible"],
|
|
217
|
+
activities: "trackDocumentVisibility",
|
|
218
|
+
after: {
|
|
219
|
+
VISIBLE_DURATION: "dismissing"
|
|
220
|
+
},
|
|
221
|
+
on: {
|
|
222
|
+
DISMISS: "dismissing",
|
|
223
|
+
PAUSE: {
|
|
224
|
+
target: "persist",
|
|
225
|
+
actions: "setRemainingDuration"
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
dismissing: {
|
|
230
|
+
entry: "invokeOnClosing",
|
|
231
|
+
after: {
|
|
232
|
+
REMOVE_DELAY: {
|
|
233
|
+
target: "inactive",
|
|
234
|
+
actions: "notifyParentToRemove"
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
inactive: {
|
|
239
|
+
entry: "invokeOnClose",
|
|
240
|
+
type: "final"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
activities: {
|
|
246
|
+
trackDocumentVisibility(ctx2, _evt, { send }) {
|
|
247
|
+
if (!ctx2.pauseOnPageIdle)
|
|
248
|
+
return;
|
|
249
|
+
return trackDocumentVisibility(dom.getDoc(ctx2), function(hidden) {
|
|
250
|
+
send(hidden ? "PAUSE" : "RESUME");
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
guards: {
|
|
255
|
+
isChangingToLoading: (_, evt) => {
|
|
256
|
+
var _a;
|
|
257
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
|
|
258
|
+
},
|
|
259
|
+
isLoadingType: (ctx2) => ctx2.type === "loading",
|
|
260
|
+
hasTypeChanged: (ctx2, evt) => {
|
|
261
|
+
var _a;
|
|
262
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx2.type;
|
|
263
|
+
},
|
|
264
|
+
hasDurationChanged: (ctx2, evt) => {
|
|
265
|
+
var _a;
|
|
266
|
+
return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx2.duration;
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
delays: {
|
|
270
|
+
VISIBLE_DURATION: (ctx2) => ctx2.remaining,
|
|
271
|
+
REMOVE_DELAY: (ctx2) => ctx2.removeDelay
|
|
272
|
+
},
|
|
273
|
+
actions: {
|
|
274
|
+
setRemainingDuration(ctx2) {
|
|
275
|
+
ctx2.remaining -= Date.now() - ctx2.createdAt;
|
|
276
|
+
},
|
|
277
|
+
setCreatedAt(ctx2) {
|
|
278
|
+
ctx2.createdAt = Date.now();
|
|
279
|
+
},
|
|
280
|
+
notifyParentToRemove(_ctx, _evt, { self }) {
|
|
281
|
+
self.sendParent({ type: "REMOVE_TOAST", id: self.id });
|
|
282
|
+
},
|
|
283
|
+
invokeOnClosing(ctx2) {
|
|
284
|
+
var _a;
|
|
285
|
+
(_a = ctx2.onClosing) == null ? void 0 : _a.call(ctx2);
|
|
286
|
+
},
|
|
287
|
+
invokeOnClose(ctx2) {
|
|
288
|
+
var _a;
|
|
289
|
+
(_a = ctx2.onClose) == null ? void 0 : _a.call(ctx2);
|
|
290
|
+
},
|
|
291
|
+
invokeOnOpen(ctx2) {
|
|
292
|
+
var _a;
|
|
293
|
+
(_a = ctx2.onOpen) == null ? void 0 : _a.call(ctx2);
|
|
294
|
+
},
|
|
295
|
+
invokeOnUpdate(ctx2) {
|
|
296
|
+
var _a;
|
|
297
|
+
(_a = ctx2.onUpdate) == null ? void 0 : _a.call(ctx2);
|
|
298
|
+
},
|
|
299
|
+
setContext(ctx2, evt) {
|
|
300
|
+
const { duration: duration2, type: type2 } = evt.toast;
|
|
301
|
+
const time = getToastDuration(duration2, type2);
|
|
302
|
+
Object.assign(ctx2, { ...evt.toast, duration: time, remaining: time });
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/toast-group.machine.ts
|
|
310
|
+
function groupMachine(userContext) {
|
|
311
|
+
const ctx = compact(userContext);
|
|
312
|
+
return (0, import_core2.createMachine)({
|
|
313
|
+
id: "toaster",
|
|
314
|
+
initial: "active",
|
|
315
|
+
context: {
|
|
316
|
+
dir: "ltr",
|
|
317
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
318
|
+
toasts: [],
|
|
319
|
+
gutter: "1rem",
|
|
320
|
+
zIndex: MAX_Z_INDEX,
|
|
321
|
+
pauseOnPageIdle: false,
|
|
322
|
+
pauseOnInteraction: true,
|
|
323
|
+
offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" },
|
|
324
|
+
...ctx
|
|
325
|
+
},
|
|
326
|
+
computed: {
|
|
327
|
+
count: (ctx2) => ctx2.toasts.length
|
|
328
|
+
},
|
|
329
|
+
on: {
|
|
330
|
+
SETUP: {},
|
|
331
|
+
PAUSE_TOAST: {
|
|
332
|
+
actions: (_ctx, evt, { self }) => {
|
|
333
|
+
self.sendChild("PAUSE", evt.id);
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
PAUSE_ALL: {
|
|
337
|
+
actions: (ctx2) => {
|
|
338
|
+
ctx2.toasts.forEach((toast) => toast.send("PAUSE"));
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
RESUME_TOAST: {
|
|
342
|
+
actions: (_ctx, evt, { self }) => {
|
|
343
|
+
self.sendChild("RESUME", evt.id);
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
RESUME_ALL: {
|
|
347
|
+
actions: (ctx2) => {
|
|
348
|
+
ctx2.toasts.forEach((toast) => toast.send("RESUME"));
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
ADD_TOAST: {
|
|
352
|
+
guard: (ctx2) => ctx2.toasts.length < ctx2.max,
|
|
353
|
+
actions: (ctx2, evt, { self }) => {
|
|
354
|
+
const options = {
|
|
355
|
+
...evt.toast,
|
|
356
|
+
pauseOnPageIdle: ctx2.pauseOnPageIdle,
|
|
357
|
+
pauseOnInteraction: ctx2.pauseOnInteraction,
|
|
358
|
+
dir: ctx2.dir,
|
|
359
|
+
getRootNode: ctx2.getRootNode
|
|
360
|
+
};
|
|
361
|
+
const toast = createToastMachine(options);
|
|
362
|
+
const actor = self.spawn(toast);
|
|
363
|
+
ctx2.toasts.push(actor);
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
UPDATE_TOAST: {
|
|
367
|
+
actions: (_ctx, evt, { self }) => {
|
|
368
|
+
self.sendChild({ type: "UPDATE", toast: evt.toast }, evt.id);
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
DISMISS_TOAST: {
|
|
372
|
+
actions: (_ctx, evt, { self }) => {
|
|
373
|
+
self.sendChild("DISMISS", evt.id);
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
DISMISS_ALL: {
|
|
377
|
+
actions: (ctx2) => {
|
|
378
|
+
ctx2.toasts.forEach((toast) => toast.send("DISMISS"));
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
REMOVE_TOAST: {
|
|
382
|
+
actions: (ctx2, evt, { self }) => {
|
|
383
|
+
self.stopChild(evt.id);
|
|
384
|
+
const index = ctx2.toasts.findIndex((toast) => toast.id === evt.id);
|
|
385
|
+
ctx2.toasts.splice(index, 1);
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
REMOVE_ALL: {
|
|
389
|
+
actions: (ctx2, _evt, { self }) => {
|
|
390
|
+
ctx2.toasts.forEach((toast) => self.stopChild(toast.id));
|
|
391
|
+
while (ctx2.toasts.length)
|
|
392
|
+
ctx2.toasts.pop();
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
399
|
+
0 && (module.exports = {
|
|
400
|
+
groupMachine
|
|
401
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"group" | "title" | "root" | "description" | "closeTrigger">;
|
|
4
|
+
declare const parts: Record<"group" | "title" | "root" | "description" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
+
|
|
6
|
+
export { anatomy, parts };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/toast.anatomy.ts
|
|
21
|
+
var toast_anatomy_exports = {};
|
|
22
|
+
__export(toast_anatomy_exports, {
|
|
23
|
+
anatomy: () => anatomy,
|
|
24
|
+
parts: () => parts
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(toast_anatomy_exports);
|
|
27
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
28
|
+
var anatomy = (0, import_anatomy.createAnatomy)("toast").parts("group", "root", "title", "description", "closeTrigger");
|
|
29
|
+
var parts = anatomy.build();
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
anatomy,
|
|
33
|
+
parts
|
|
34
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { State, Send, Type, Placement } from './toast.types.js';
|
|
2
|
+
import { PropTypes, NormalizeProps } from '@zag-js/types';
|
|
3
|
+
import '@zag-js/core';
|
|
4
|
+
|
|
5
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
6
|
+
type: Type;
|
|
7
|
+
title: string | undefined;
|
|
8
|
+
description: string | undefined;
|
|
9
|
+
placement: Placement;
|
|
10
|
+
isVisible: boolean;
|
|
11
|
+
isPaused: boolean;
|
|
12
|
+
isRtl: boolean;
|
|
13
|
+
pause(): void;
|
|
14
|
+
resume(): void;
|
|
15
|
+
dismiss(): void;
|
|
16
|
+
rootProps: T["element"];
|
|
17
|
+
titleProps: T["element"];
|
|
18
|
+
descriptionProps: T["element"];
|
|
19
|
+
closeTriggerProps: T["button"];
|
|
20
|
+
render(): any;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { connect };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/toast.connect.ts
|
|
21
|
+
var toast_connect_exports = {};
|
|
22
|
+
__export(toast_connect_exports, {
|
|
23
|
+
connect: () => connect
|
|
24
|
+
});
|
|
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 == null ? void 0 : value.toString()) === "[object Window]";
|
|
38
|
+
}
|
|
39
|
+
function getDocument(el) {
|
|
40
|
+
var _a;
|
|
41
|
+
if (isWindow(el))
|
|
42
|
+
return el.document;
|
|
43
|
+
if (isDocument(el))
|
|
44
|
+
return el;
|
|
45
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
46
|
+
}
|
|
47
|
+
function defineDomHelpers(helpers) {
|
|
48
|
+
const dom2 = {
|
|
49
|
+
getRootNode: (ctx) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
52
|
+
},
|
|
53
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
54
|
+
getWin: (ctx) => {
|
|
55
|
+
var _a;
|
|
56
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
57
|
+
},
|
|
58
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
59
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
60
|
+
createEmitter: (ctx, target) => {
|
|
61
|
+
const win = dom2.getWin(ctx);
|
|
62
|
+
return function emit(evt, detail, options) {
|
|
63
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
64
|
+
const eventName = `zag:${evt}`;
|
|
65
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
66
|
+
const event = new win.CustomEvent(eventName, init);
|
|
67
|
+
target.dispatchEvent(event);
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
createListener: (target) => {
|
|
71
|
+
return function listen(evt, handler) {
|
|
72
|
+
const eventName = `zag:${evt}`;
|
|
73
|
+
const listener = (e) => handler(e);
|
|
74
|
+
target.addEventListener(eventName, listener);
|
|
75
|
+
return () => target.removeEventListener(eventName, listener);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
...dom2,
|
|
81
|
+
...helpers
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/toast.anatomy.ts
|
|
86
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
87
|
+
var anatomy = (0, import_anatomy.createAnatomy)("toast").parts("group", "root", "title", "description", "closeTrigger");
|
|
88
|
+
var parts = anatomy.build();
|
|
89
|
+
|
|
90
|
+
// src/toast.dom.ts
|
|
91
|
+
var dom = defineDomHelpers({
|
|
92
|
+
getGroupId: (placement) => `toast-group:${placement}`,
|
|
93
|
+
getRootId: (ctx) => `toast:${ctx.id}`,
|
|
94
|
+
getTitleId: (ctx) => `toast:${ctx.id}:title`,
|
|
95
|
+
getDescriptionId: (ctx) => `toast:${ctx.id}:description`,
|
|
96
|
+
getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
|
|
97
|
+
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
98
|
+
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
99
|
+
createPortalEl: (ctx) => {
|
|
100
|
+
const existing = dom.getPortalEl(ctx);
|
|
101
|
+
if (existing)
|
|
102
|
+
return existing;
|
|
103
|
+
const portal = dom.getDoc(ctx).createElement("toast-portal");
|
|
104
|
+
portal.id = dom.getPortalId(ctx);
|
|
105
|
+
return portal;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// src/toast.connect.ts
|
|
110
|
+
function connect(state, send, normalize) {
|
|
111
|
+
const isVisible = state.hasTag("visible");
|
|
112
|
+
const isPaused = state.hasTag("paused");
|
|
113
|
+
const pauseOnInteraction = state.context.pauseOnInteraction;
|
|
114
|
+
const placement = state.context.placement;
|
|
115
|
+
return {
|
|
116
|
+
type: state.context.type,
|
|
117
|
+
title: state.context.title,
|
|
118
|
+
description: state.context.description,
|
|
119
|
+
placement,
|
|
120
|
+
isVisible,
|
|
121
|
+
isPaused,
|
|
122
|
+
isRtl: state.context.dir === "rtl",
|
|
123
|
+
pause() {
|
|
124
|
+
send("PAUSE");
|
|
125
|
+
},
|
|
126
|
+
resume() {
|
|
127
|
+
send("RESUME");
|
|
128
|
+
},
|
|
129
|
+
dismiss() {
|
|
130
|
+
send("DISMISS");
|
|
131
|
+
},
|
|
132
|
+
rootProps: normalize.element({
|
|
133
|
+
...parts.root.attrs,
|
|
134
|
+
dir: state.context.dir,
|
|
135
|
+
id: dom.getRootId(state.context),
|
|
136
|
+
"data-open": dataAttr(isVisible),
|
|
137
|
+
"data-type": state.context.type,
|
|
138
|
+
"data-placement": placement,
|
|
139
|
+
role: "status",
|
|
140
|
+
"aria-atomic": "true",
|
|
141
|
+
tabIndex: 0,
|
|
142
|
+
style: {
|
|
143
|
+
position: "relative",
|
|
144
|
+
pointerEvents: "auto",
|
|
145
|
+
margin: "calc(var(--toast-gutter) / 2)",
|
|
146
|
+
"--remove-delay": `${state.context.removeDelay}ms`,
|
|
147
|
+
"--duration": `${state.context.duration}ms`
|
|
148
|
+
},
|
|
149
|
+
onKeyDown(event) {
|
|
150
|
+
if (event.key == "Escape") {
|
|
151
|
+
send("DISMISS");
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
onFocus() {
|
|
156
|
+
if (pauseOnInteraction) {
|
|
157
|
+
send("PAUSE");
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
onBlur() {
|
|
161
|
+
if (pauseOnInteraction) {
|
|
162
|
+
send("RESUME");
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
onPointerEnter() {
|
|
166
|
+
if (pauseOnInteraction) {
|
|
167
|
+
send("PAUSE");
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
onPointerLeave() {
|
|
171
|
+
if (pauseOnInteraction) {
|
|
172
|
+
send("RESUME");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}),
|
|
176
|
+
titleProps: normalize.element({
|
|
177
|
+
...parts.title.attrs,
|
|
178
|
+
id: dom.getTitleId(state.context)
|
|
179
|
+
}),
|
|
180
|
+
descriptionProps: normalize.element({
|
|
181
|
+
...parts.description.attrs,
|
|
182
|
+
id: dom.getDescriptionId(state.context)
|
|
183
|
+
}),
|
|
184
|
+
closeTriggerProps: normalize.button({
|
|
185
|
+
id: dom.getCloseTriggerId(state.context),
|
|
186
|
+
...parts.closeTrigger.attrs,
|
|
187
|
+
type: "button",
|
|
188
|
+
"aria-label": "Dismiss notification",
|
|
189
|
+
onClick() {
|
|
190
|
+
send("DISMISS");
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
render() {
|
|
194
|
+
var _a, _b;
|
|
195
|
+
return (_b = (_a = state.context).render) == null ? void 0 : _b.call(_a, {
|
|
196
|
+
id: state.context.id,
|
|
197
|
+
type: state.context.type,
|
|
198
|
+
duration: state.context.duration,
|
|
199
|
+
title: state.context.title,
|
|
200
|
+
placement: state.context.placement,
|
|
201
|
+
description: state.context.description,
|
|
202
|
+
dismiss() {
|
|
203
|
+
send("DISMISS");
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
210
|
+
0 && (module.exports = {
|
|
211
|
+
connect
|
|
212
|
+
});
|