@zag-js/toast 0.1.7 → 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.d.ts +0 -1
- package/dist/index.js +85 -182
- package/dist/index.mjs +84 -182
- package/dist/toast-group.connect.d.ts +3 -4
- package/dist/toast-group.machine.d.ts +1 -2
- package/dist/toast.connect.d.ts +2 -3
- package/dist/toast.dom.d.ts +17 -4
- package/dist/toast.machine.d.ts +1 -2
- package/dist/toast.types.d.ts +4 -5
- package/dist/toast.utils.d.ts +2 -3
- package/package.json +6 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -7
- package/dist/index.mjs.map +0 -7
- package/dist/toast-group.connect.d.ts.map +0 -1
- package/dist/toast-group.machine.d.ts.map +0 -1
- package/dist/toast.connect.d.ts.map +0 -1
- package/dist/toast.dom.d.ts.map +0 -1
- package/dist/toast.machine.d.ts.map +0 -1
- package/dist/toast.types.d.ts.map +0 -1
- package/dist/toast.utils.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -55,13 +56,85 @@ __export(src_exports, {
|
|
|
55
56
|
});
|
|
56
57
|
module.exports = __toCommonJS(src_exports);
|
|
57
58
|
|
|
58
|
-
// ../../utilities/
|
|
59
|
-
var
|
|
60
|
-
var
|
|
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
|
+
};
|
|
76
|
+
var dataAttr = (guard) => {
|
|
77
|
+
return guard ? "" : void 0;
|
|
78
|
+
};
|
|
79
|
+
var MAX_Z_INDEX = 2147483647;
|
|
61
80
|
var runIfFn = (v, ...a) => {
|
|
62
81
|
const res = typeof v === "function" ? v(...a) : v;
|
|
63
82
|
return res != null ? res : void 0;
|
|
64
83
|
};
|
|
84
|
+
var cast = (v) => v;
|
|
85
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
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
|
+
}
|
|
117
|
+
var isRef = (v) => hasProp(v, "current");
|
|
118
|
+
function addDomEvent(target, eventName, handler, options) {
|
|
119
|
+
const node = isRef(target) ? target.current : runIfFn(target);
|
|
120
|
+
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
121
|
+
return () => {
|
|
122
|
+
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function trackDocumentVisibility(_doc, callback) {
|
|
126
|
+
const doc = cast(_doc);
|
|
127
|
+
return addDomEvent(doc, "visibilitychange", () => {
|
|
128
|
+
const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
|
|
129
|
+
callback(!!hidden);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ../../utilities/core/dist/index.mjs
|
|
134
|
+
var runIfFn2 = (v, ...a) => {
|
|
135
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
136
|
+
return res != null ? res : void 0;
|
|
137
|
+
};
|
|
65
138
|
var uuid = /* @__PURE__ */ (() => {
|
|
66
139
|
let id = 0;
|
|
67
140
|
return () => {
|
|
@@ -80,31 +153,13 @@ function warn(...a) {
|
|
|
80
153
|
// src/toast-group.connect.ts
|
|
81
154
|
var import_core = require("@zag-js/core");
|
|
82
155
|
|
|
83
|
-
// ../../types/dist/index.mjs
|
|
84
|
-
function createNormalizer(fn) {
|
|
85
|
-
return new Proxy({}, {
|
|
86
|
-
get() {
|
|
87
|
-
return fn;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
var normalizeProp = createNormalizer((v) => v);
|
|
92
|
-
|
|
93
156
|
// src/toast.dom.ts
|
|
94
|
-
var dom = {
|
|
95
|
-
getDoc: (ctx) => {
|
|
96
|
-
var _a;
|
|
97
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
98
|
-
},
|
|
99
|
-
getRootNode: (ctx) => {
|
|
100
|
-
var _a;
|
|
101
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
102
|
-
},
|
|
157
|
+
var dom = defineDomHelpers({
|
|
103
158
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
104
159
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
105
160
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
106
161
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
107
|
-
getPortalId: (ctx) => `toast-portal:${ctx.
|
|
162
|
+
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
108
163
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
109
164
|
createPortalEl: (ctx) => {
|
|
110
165
|
const existing = dom.getPortalEl(ctx);
|
|
@@ -114,7 +169,7 @@ var dom = {
|
|
|
114
169
|
portal.id = dom.getPortalId(ctx);
|
|
115
170
|
return portal;
|
|
116
171
|
}
|
|
117
|
-
};
|
|
172
|
+
});
|
|
118
173
|
|
|
119
174
|
// src/toast.utils.ts
|
|
120
175
|
function getToastsByPlacement(toasts) {
|
|
@@ -178,7 +233,7 @@ function getGroupPlacementStyle(ctx, placement) {
|
|
|
178
233
|
|
|
179
234
|
// src/toast-group.connect.ts
|
|
180
235
|
var toaster = {};
|
|
181
|
-
function groupConnect(state, send, normalize
|
|
236
|
+
function groupConnect(state, send, normalize) {
|
|
182
237
|
const group2 = {
|
|
183
238
|
count: state.context.count,
|
|
184
239
|
toasts: state.context.toasts,
|
|
@@ -246,10 +301,10 @@ function groupConnect(state, send, normalize = normalizeProp) {
|
|
|
246
301
|
promise(promise, options, shared = {}) {
|
|
247
302
|
const id = group2.loading(__spreadValues(__spreadValues({}, shared), options.loading));
|
|
248
303
|
promise.then((response) => {
|
|
249
|
-
const successOptions =
|
|
304
|
+
const successOptions = runIfFn2(options.success, response);
|
|
250
305
|
group2.success(__spreadProps(__spreadValues(__spreadValues({}, shared), successOptions), { id }));
|
|
251
306
|
}).catch((error) => {
|
|
252
|
-
const errorOptions =
|
|
307
|
+
const errorOptions = runIfFn2(options.error, error);
|
|
253
308
|
group2.error(__spreadProps(__spreadValues(__spreadValues({}, shared), errorOptions), { id }));
|
|
254
309
|
});
|
|
255
310
|
return promise;
|
|
@@ -302,148 +357,6 @@ function groupConnect(state, send, normalize = normalizeProp) {
|
|
|
302
357
|
// src/toast-group.machine.ts
|
|
303
358
|
var import_core3 = require("@zag-js/core");
|
|
304
359
|
|
|
305
|
-
// ../../utilities/dom/dist/index.mjs
|
|
306
|
-
var dataAttr = (guard) => {
|
|
307
|
-
return guard ? "" : void 0;
|
|
308
|
-
};
|
|
309
|
-
var isDom2 = () => typeof window !== "undefined";
|
|
310
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
311
|
-
var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
|
|
312
|
-
var runIfFn2 = (v, ...a) => {
|
|
313
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
314
|
-
return res != null ? res : void 0;
|
|
315
|
-
};
|
|
316
|
-
var cast = (v) => v;
|
|
317
|
-
var noop = () => {
|
|
318
|
-
};
|
|
319
|
-
function getListenerElements() {
|
|
320
|
-
;
|
|
321
|
-
globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
|
|
322
|
-
return globalThis.__listenerElements__;
|
|
323
|
-
}
|
|
324
|
-
function getListenerCache() {
|
|
325
|
-
;
|
|
326
|
-
globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
|
|
327
|
-
return globalThis.__listenerCache__;
|
|
328
|
-
}
|
|
329
|
-
function addGlobalEventListener(node, type, handler, options) {
|
|
330
|
-
var _a;
|
|
331
|
-
if (!node)
|
|
332
|
-
return noop;
|
|
333
|
-
const hash = JSON.stringify({ type, options });
|
|
334
|
-
const listenerElements = getListenerElements();
|
|
335
|
-
const listenerCache = getListenerCache();
|
|
336
|
-
const group2 = listenerElements.get(node);
|
|
337
|
-
if (!listenerElements.has(node)) {
|
|
338
|
-
const group22 = /* @__PURE__ */ new Map([[hash, /* @__PURE__ */ new Set([handler])]]);
|
|
339
|
-
listenerElements.set(node, group22);
|
|
340
|
-
} else if (group2 == null ? void 0 : group2.has(hash)) {
|
|
341
|
-
(_a = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a.add(handler);
|
|
342
|
-
} else {
|
|
343
|
-
group2 == null ? void 0 : group2.set(hash, /* @__PURE__ */ new Set([handler]));
|
|
344
|
-
}
|
|
345
|
-
function attach(node2) {
|
|
346
|
-
var _a2, _b;
|
|
347
|
-
function listener(event) {
|
|
348
|
-
var _a3;
|
|
349
|
-
const group22 = listenerElements.get(node2);
|
|
350
|
-
(_a3 = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _a3.forEach((fn) => fn(event));
|
|
351
|
-
}
|
|
352
|
-
if (!(listenerCache == null ? void 0 : listenerCache.has(node2))) {
|
|
353
|
-
listenerCache.set(node2, /* @__PURE__ */ new Map([[hash, listener]]));
|
|
354
|
-
node2.addEventListener(type, listener, options);
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
if (!((_a2 = listenerCache == null ? void 0 : listenerCache.get(node2)) == null ? void 0 : _a2.has(hash))) {
|
|
358
|
-
(_b = listenerCache.get(node2)) == null ? void 0 : _b.set(hash, listener);
|
|
359
|
-
node2.addEventListener(type, listener, options);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
attach(node);
|
|
363
|
-
return function remove() {
|
|
364
|
-
var _a2, _b, _c, _d;
|
|
365
|
-
if (!listenerElements.has(node))
|
|
366
|
-
return;
|
|
367
|
-
const group22 = listenerElements.get(node);
|
|
368
|
-
(_a2 = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _a2.delete(handler);
|
|
369
|
-
if (((_b = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _b.size) === 0) {
|
|
370
|
-
const listener = (_c = listenerCache.get(node)) == null ? void 0 : _c.get(hash);
|
|
371
|
-
node.removeEventListener(type, listener, options);
|
|
372
|
-
group22 == null ? void 0 : group22.delete(hash);
|
|
373
|
-
(_d = listenerCache.get(node)) == null ? void 0 : _d.delete(hash);
|
|
374
|
-
if ((group22 == null ? void 0 : group22.size) === 0) {
|
|
375
|
-
listenerElements.delete(node);
|
|
376
|
-
listenerCache.delete(node);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
var isRef = (v) => hasProp(v, "current");
|
|
382
|
-
function addDomEvent(target, event, listener, options) {
|
|
383
|
-
const node = isRef(target) ? target.current : runIfFn2(target);
|
|
384
|
-
return addGlobalEventListener(node, event, listener, options);
|
|
385
|
-
}
|
|
386
|
-
var MAX_Z_INDEX = 2147483647;
|
|
387
|
-
function itemById(v, id) {
|
|
388
|
-
return v.find((node) => node.id === id);
|
|
389
|
-
}
|
|
390
|
-
function indexOfId(v, id) {
|
|
391
|
-
const item = itemById(v, id);
|
|
392
|
-
return item ? v.indexOf(item) : -1;
|
|
393
|
-
}
|
|
394
|
-
var getValueText = (item) => {
|
|
395
|
-
var _a, _b;
|
|
396
|
-
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
|
|
397
|
-
};
|
|
398
|
-
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
|
|
399
|
-
var wrap = (v, idx) => {
|
|
400
|
-
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
|
|
401
|
-
};
|
|
402
|
-
function findByText(v, text, currentId) {
|
|
403
|
-
const index = currentId ? indexOfId(v, currentId) : -1;
|
|
404
|
-
let items = currentId ? wrap(v, index) : v;
|
|
405
|
-
const isSingleKey = text.length === 1;
|
|
406
|
-
if (isSingleKey) {
|
|
407
|
-
items = items.filter((item) => item.id !== currentId);
|
|
408
|
-
}
|
|
409
|
-
return items.find((item) => match(getValueText(item), text));
|
|
410
|
-
}
|
|
411
|
-
function findByTypeahead(_items, options) {
|
|
412
|
-
const { state: state2, activeId, key, timeout = 350 } = options;
|
|
413
|
-
const search = state2.keysSoFar + key;
|
|
414
|
-
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
|
|
415
|
-
const query2 = isRepeated ? search[0] : search;
|
|
416
|
-
let items = _items.slice();
|
|
417
|
-
const next = findByText(items, query2, activeId);
|
|
418
|
-
function cleanup() {
|
|
419
|
-
clearTimeout(state2.timer);
|
|
420
|
-
state2.timer = -1;
|
|
421
|
-
}
|
|
422
|
-
function update(value) {
|
|
423
|
-
state2.keysSoFar = value;
|
|
424
|
-
cleanup();
|
|
425
|
-
if (value !== "") {
|
|
426
|
-
state2.timer = +setTimeout(() => {
|
|
427
|
-
update("");
|
|
428
|
-
cleanup();
|
|
429
|
-
}, timeout);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
update(search);
|
|
433
|
-
return next;
|
|
434
|
-
}
|
|
435
|
-
findByTypeahead.defaultOptions = {
|
|
436
|
-
keysSoFar: "",
|
|
437
|
-
timer: -1
|
|
438
|
-
};
|
|
439
|
-
function trackDocumentVisibility(_doc, callback) {
|
|
440
|
-
const doc = cast(_doc);
|
|
441
|
-
return addDomEvent(doc, "visibilitychange", () => {
|
|
442
|
-
const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
|
|
443
|
-
callback(!!hidden);
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
|
|
447
360
|
// src/toast.machine.ts
|
|
448
361
|
var import_core2 = require("@zag-js/core");
|
|
449
362
|
var { not, and, or } = import_core2.guards;
|
|
@@ -592,14 +505,13 @@ function createToastMachine(options = {}) {
|
|
|
592
505
|
}
|
|
593
506
|
|
|
594
507
|
// src/toast-group.machine.ts
|
|
595
|
-
function groupMachine(ctx
|
|
508
|
+
function groupMachine(ctx) {
|
|
596
509
|
return (0, import_core3.createMachine)({
|
|
597
510
|
id: "toaster",
|
|
598
511
|
initial: "active",
|
|
599
512
|
context: __spreadValues({
|
|
600
513
|
dir: "ltr",
|
|
601
514
|
max: Number.MAX_SAFE_INTEGER,
|
|
602
|
-
uid: "",
|
|
603
515
|
toasts: [],
|
|
604
516
|
gutter: "1rem",
|
|
605
517
|
zIndex: MAX_Z_INDEX,
|
|
@@ -611,15 +523,7 @@ function groupMachine(ctx = {}) {
|
|
|
611
523
|
count: (ctx2) => ctx2.toasts.length
|
|
612
524
|
},
|
|
613
525
|
on: {
|
|
614
|
-
SETUP: {
|
|
615
|
-
actions: (ctx2, evt) => {
|
|
616
|
-
ctx2.uid = evt.id;
|
|
617
|
-
if (evt.doc)
|
|
618
|
-
ctx2.doc = (0, import_core3.ref)(evt.doc);
|
|
619
|
-
if (evt.root)
|
|
620
|
-
ctx2.rootNode = (0, import_core3.ref)(evt.root);
|
|
621
|
-
}
|
|
622
|
-
},
|
|
526
|
+
SETUP: {},
|
|
623
527
|
PAUSE_TOAST: {
|
|
624
528
|
actions: (_ctx, evt, { self }) => {
|
|
625
529
|
self.sendChild("PAUSE", evt.id);
|
|
@@ -689,7 +593,7 @@ function groupMachine(ctx = {}) {
|
|
|
689
593
|
}
|
|
690
594
|
|
|
691
595
|
// src/toast.connect.ts
|
|
692
|
-
function connect(state, send, normalize
|
|
596
|
+
function connect(state, send, normalize) {
|
|
693
597
|
const isVisible = state.hasTag("visible");
|
|
694
598
|
const isPaused = state.hasTag("paused");
|
|
695
599
|
const isUpdating = state.hasTag("updating");
|
|
@@ -810,4 +714,3 @@ function api() {
|
|
|
810
714
|
return toaster;
|
|
811
715
|
}
|
|
812
716
|
}
|
|
813
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -30,13 +30,85 @@ var __objRest = (source, exclude) => {
|
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
// ../../utilities/
|
|
34
|
-
var
|
|
35
|
-
var
|
|
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
|
+
};
|
|
50
|
+
var dataAttr = (guard) => {
|
|
51
|
+
return guard ? "" : void 0;
|
|
52
|
+
};
|
|
53
|
+
var MAX_Z_INDEX = 2147483647;
|
|
36
54
|
var runIfFn = (v, ...a) => {
|
|
37
55
|
const res = typeof v === "function" ? v(...a) : v;
|
|
38
56
|
return res != null ? res : void 0;
|
|
39
57
|
};
|
|
58
|
+
var cast = (v) => v;
|
|
59
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
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
|
+
}
|
|
91
|
+
var isRef = (v) => hasProp(v, "current");
|
|
92
|
+
function addDomEvent(target, eventName, handler, options) {
|
|
93
|
+
const node = isRef(target) ? target.current : runIfFn(target);
|
|
94
|
+
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
95
|
+
return () => {
|
|
96
|
+
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function trackDocumentVisibility(_doc, callback) {
|
|
100
|
+
const doc = cast(_doc);
|
|
101
|
+
return addDomEvent(doc, "visibilitychange", () => {
|
|
102
|
+
const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
|
|
103
|
+
callback(!!hidden);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ../../utilities/core/dist/index.mjs
|
|
108
|
+
var runIfFn2 = (v, ...a) => {
|
|
109
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
110
|
+
return res != null ? res : void 0;
|
|
111
|
+
};
|
|
40
112
|
var uuid = /* @__PURE__ */ (() => {
|
|
41
113
|
let id = 0;
|
|
42
114
|
return () => {
|
|
@@ -55,31 +127,13 @@ function warn(...a) {
|
|
|
55
127
|
// src/toast-group.connect.ts
|
|
56
128
|
import { subscribe } from "@zag-js/core";
|
|
57
129
|
|
|
58
|
-
// ../../types/dist/index.mjs
|
|
59
|
-
function createNormalizer(fn) {
|
|
60
|
-
return new Proxy({}, {
|
|
61
|
-
get() {
|
|
62
|
-
return fn;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
var normalizeProp = createNormalizer((v) => v);
|
|
67
|
-
|
|
68
130
|
// src/toast.dom.ts
|
|
69
|
-
var dom = {
|
|
70
|
-
getDoc: (ctx) => {
|
|
71
|
-
var _a;
|
|
72
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
73
|
-
},
|
|
74
|
-
getRootNode: (ctx) => {
|
|
75
|
-
var _a;
|
|
76
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
77
|
-
},
|
|
131
|
+
var dom = defineDomHelpers({
|
|
78
132
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
79
133
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
80
134
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
81
135
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
82
|
-
getPortalId: (ctx) => `toast-portal:${ctx.
|
|
136
|
+
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
83
137
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
84
138
|
createPortalEl: (ctx) => {
|
|
85
139
|
const existing = dom.getPortalEl(ctx);
|
|
@@ -89,7 +143,7 @@ var dom = {
|
|
|
89
143
|
portal.id = dom.getPortalId(ctx);
|
|
90
144
|
return portal;
|
|
91
145
|
}
|
|
92
|
-
};
|
|
146
|
+
});
|
|
93
147
|
|
|
94
148
|
// src/toast.utils.ts
|
|
95
149
|
function getToastsByPlacement(toasts) {
|
|
@@ -153,7 +207,7 @@ function getGroupPlacementStyle(ctx, placement) {
|
|
|
153
207
|
|
|
154
208
|
// src/toast-group.connect.ts
|
|
155
209
|
var toaster = {};
|
|
156
|
-
function groupConnect(state, send, normalize
|
|
210
|
+
function groupConnect(state, send, normalize) {
|
|
157
211
|
const group2 = {
|
|
158
212
|
count: state.context.count,
|
|
159
213
|
toasts: state.context.toasts,
|
|
@@ -221,10 +275,10 @@ function groupConnect(state, send, normalize = normalizeProp) {
|
|
|
221
275
|
promise(promise, options, shared = {}) {
|
|
222
276
|
const id = group2.loading(__spreadValues(__spreadValues({}, shared), options.loading));
|
|
223
277
|
promise.then((response) => {
|
|
224
|
-
const successOptions =
|
|
278
|
+
const successOptions = runIfFn2(options.success, response);
|
|
225
279
|
group2.success(__spreadProps(__spreadValues(__spreadValues({}, shared), successOptions), { id }));
|
|
226
280
|
}).catch((error) => {
|
|
227
|
-
const errorOptions =
|
|
281
|
+
const errorOptions = runIfFn2(options.error, error);
|
|
228
282
|
group2.error(__spreadProps(__spreadValues(__spreadValues({}, shared), errorOptions), { id }));
|
|
229
283
|
});
|
|
230
284
|
return promise;
|
|
@@ -277,148 +331,6 @@ function groupConnect(state, send, normalize = normalizeProp) {
|
|
|
277
331
|
// src/toast-group.machine.ts
|
|
278
332
|
import { createMachine as createMachine2, ref } from "@zag-js/core";
|
|
279
333
|
|
|
280
|
-
// ../../utilities/dom/dist/index.mjs
|
|
281
|
-
var dataAttr = (guard) => {
|
|
282
|
-
return guard ? "" : void 0;
|
|
283
|
-
};
|
|
284
|
-
var isDom2 = () => typeof window !== "undefined";
|
|
285
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
286
|
-
var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
|
|
287
|
-
var runIfFn2 = (v, ...a) => {
|
|
288
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
289
|
-
return res != null ? res : void 0;
|
|
290
|
-
};
|
|
291
|
-
var cast = (v) => v;
|
|
292
|
-
var noop = () => {
|
|
293
|
-
};
|
|
294
|
-
function getListenerElements() {
|
|
295
|
-
;
|
|
296
|
-
globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
|
|
297
|
-
return globalThis.__listenerElements__;
|
|
298
|
-
}
|
|
299
|
-
function getListenerCache() {
|
|
300
|
-
;
|
|
301
|
-
globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
|
|
302
|
-
return globalThis.__listenerCache__;
|
|
303
|
-
}
|
|
304
|
-
function addGlobalEventListener(node, type, handler, options) {
|
|
305
|
-
var _a;
|
|
306
|
-
if (!node)
|
|
307
|
-
return noop;
|
|
308
|
-
const hash = JSON.stringify({ type, options });
|
|
309
|
-
const listenerElements = getListenerElements();
|
|
310
|
-
const listenerCache = getListenerCache();
|
|
311
|
-
const group2 = listenerElements.get(node);
|
|
312
|
-
if (!listenerElements.has(node)) {
|
|
313
|
-
const group22 = /* @__PURE__ */ new Map([[hash, /* @__PURE__ */ new Set([handler])]]);
|
|
314
|
-
listenerElements.set(node, group22);
|
|
315
|
-
} else if (group2 == null ? void 0 : group2.has(hash)) {
|
|
316
|
-
(_a = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a.add(handler);
|
|
317
|
-
} else {
|
|
318
|
-
group2 == null ? void 0 : group2.set(hash, /* @__PURE__ */ new Set([handler]));
|
|
319
|
-
}
|
|
320
|
-
function attach(node2) {
|
|
321
|
-
var _a2, _b;
|
|
322
|
-
function listener(event) {
|
|
323
|
-
var _a3;
|
|
324
|
-
const group22 = listenerElements.get(node2);
|
|
325
|
-
(_a3 = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _a3.forEach((fn) => fn(event));
|
|
326
|
-
}
|
|
327
|
-
if (!(listenerCache == null ? void 0 : listenerCache.has(node2))) {
|
|
328
|
-
listenerCache.set(node2, /* @__PURE__ */ new Map([[hash, listener]]));
|
|
329
|
-
node2.addEventListener(type, listener, options);
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
if (!((_a2 = listenerCache == null ? void 0 : listenerCache.get(node2)) == null ? void 0 : _a2.has(hash))) {
|
|
333
|
-
(_b = listenerCache.get(node2)) == null ? void 0 : _b.set(hash, listener);
|
|
334
|
-
node2.addEventListener(type, listener, options);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
attach(node);
|
|
338
|
-
return function remove() {
|
|
339
|
-
var _a2, _b, _c, _d;
|
|
340
|
-
if (!listenerElements.has(node))
|
|
341
|
-
return;
|
|
342
|
-
const group22 = listenerElements.get(node);
|
|
343
|
-
(_a2 = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _a2.delete(handler);
|
|
344
|
-
if (((_b = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _b.size) === 0) {
|
|
345
|
-
const listener = (_c = listenerCache.get(node)) == null ? void 0 : _c.get(hash);
|
|
346
|
-
node.removeEventListener(type, listener, options);
|
|
347
|
-
group22 == null ? void 0 : group22.delete(hash);
|
|
348
|
-
(_d = listenerCache.get(node)) == null ? void 0 : _d.delete(hash);
|
|
349
|
-
if ((group22 == null ? void 0 : group22.size) === 0) {
|
|
350
|
-
listenerElements.delete(node);
|
|
351
|
-
listenerCache.delete(node);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
var isRef = (v) => hasProp(v, "current");
|
|
357
|
-
function addDomEvent(target, event, listener, options) {
|
|
358
|
-
const node = isRef(target) ? target.current : runIfFn2(target);
|
|
359
|
-
return addGlobalEventListener(node, event, listener, options);
|
|
360
|
-
}
|
|
361
|
-
var MAX_Z_INDEX = 2147483647;
|
|
362
|
-
function itemById(v, id) {
|
|
363
|
-
return v.find((node) => node.id === id);
|
|
364
|
-
}
|
|
365
|
-
function indexOfId(v, id) {
|
|
366
|
-
const item = itemById(v, id);
|
|
367
|
-
return item ? v.indexOf(item) : -1;
|
|
368
|
-
}
|
|
369
|
-
var getValueText = (item) => {
|
|
370
|
-
var _a, _b;
|
|
371
|
-
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
|
|
372
|
-
};
|
|
373
|
-
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
|
|
374
|
-
var wrap = (v, idx) => {
|
|
375
|
-
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
|
|
376
|
-
};
|
|
377
|
-
function findByText(v, text, currentId) {
|
|
378
|
-
const index = currentId ? indexOfId(v, currentId) : -1;
|
|
379
|
-
let items = currentId ? wrap(v, index) : v;
|
|
380
|
-
const isSingleKey = text.length === 1;
|
|
381
|
-
if (isSingleKey) {
|
|
382
|
-
items = items.filter((item) => item.id !== currentId);
|
|
383
|
-
}
|
|
384
|
-
return items.find((item) => match(getValueText(item), text));
|
|
385
|
-
}
|
|
386
|
-
function findByTypeahead(_items, options) {
|
|
387
|
-
const { state: state2, activeId, key, timeout = 350 } = options;
|
|
388
|
-
const search = state2.keysSoFar + key;
|
|
389
|
-
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
|
|
390
|
-
const query2 = isRepeated ? search[0] : search;
|
|
391
|
-
let items = _items.slice();
|
|
392
|
-
const next = findByText(items, query2, activeId);
|
|
393
|
-
function cleanup() {
|
|
394
|
-
clearTimeout(state2.timer);
|
|
395
|
-
state2.timer = -1;
|
|
396
|
-
}
|
|
397
|
-
function update(value) {
|
|
398
|
-
state2.keysSoFar = value;
|
|
399
|
-
cleanup();
|
|
400
|
-
if (value !== "") {
|
|
401
|
-
state2.timer = +setTimeout(() => {
|
|
402
|
-
update("");
|
|
403
|
-
cleanup();
|
|
404
|
-
}, timeout);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
update(search);
|
|
408
|
-
return next;
|
|
409
|
-
}
|
|
410
|
-
findByTypeahead.defaultOptions = {
|
|
411
|
-
keysSoFar: "",
|
|
412
|
-
timer: -1
|
|
413
|
-
};
|
|
414
|
-
function trackDocumentVisibility(_doc, callback) {
|
|
415
|
-
const doc = cast(_doc);
|
|
416
|
-
return addDomEvent(doc, "visibilitychange", () => {
|
|
417
|
-
const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
|
|
418
|
-
callback(!!hidden);
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
|
|
422
334
|
// src/toast.machine.ts
|
|
423
335
|
import { createMachine, guards } from "@zag-js/core";
|
|
424
336
|
var { not, and, or } = guards;
|
|
@@ -567,14 +479,13 @@ function createToastMachine(options = {}) {
|
|
|
567
479
|
}
|
|
568
480
|
|
|
569
481
|
// src/toast-group.machine.ts
|
|
570
|
-
function groupMachine(ctx
|
|
482
|
+
function groupMachine(ctx) {
|
|
571
483
|
return createMachine2({
|
|
572
484
|
id: "toaster",
|
|
573
485
|
initial: "active",
|
|
574
486
|
context: __spreadValues({
|
|
575
487
|
dir: "ltr",
|
|
576
488
|
max: Number.MAX_SAFE_INTEGER,
|
|
577
|
-
uid: "",
|
|
578
489
|
toasts: [],
|
|
579
490
|
gutter: "1rem",
|
|
580
491
|
zIndex: MAX_Z_INDEX,
|
|
@@ -586,15 +497,7 @@ function groupMachine(ctx = {}) {
|
|
|
586
497
|
count: (ctx2) => ctx2.toasts.length
|
|
587
498
|
},
|
|
588
499
|
on: {
|
|
589
|
-
SETUP: {
|
|
590
|
-
actions: (ctx2, evt) => {
|
|
591
|
-
ctx2.uid = evt.id;
|
|
592
|
-
if (evt.doc)
|
|
593
|
-
ctx2.doc = ref(evt.doc);
|
|
594
|
-
if (evt.root)
|
|
595
|
-
ctx2.rootNode = ref(evt.root);
|
|
596
|
-
}
|
|
597
|
-
},
|
|
500
|
+
SETUP: {},
|
|
598
501
|
PAUSE_TOAST: {
|
|
599
502
|
actions: (_ctx, evt, { self }) => {
|
|
600
503
|
self.sendChild("PAUSE", evt.id);
|
|
@@ -664,7 +567,7 @@ function groupMachine(ctx = {}) {
|
|
|
664
567
|
}
|
|
665
568
|
|
|
666
569
|
// src/toast.connect.ts
|
|
667
|
-
function connect(state, send, normalize
|
|
570
|
+
function connect(state, send, normalize) {
|
|
668
571
|
const isVisible = state.hasTag("visible");
|
|
669
572
|
const isPaused = state.hasTag("paused");
|
|
670
573
|
const isUpdating = state.hasTag("updating");
|
|
@@ -791,4 +694,3 @@ export {
|
|
|
791
694
|
createToastMachine as createMachine,
|
|
792
695
|
group
|
|
793
696
|
};
|
|
794
|
-
//# sourceMappingURL=index.mjs.map
|