@zag-js/toast 0.1.10 → 0.1.13
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/LICENSE +21 -0
- package/dist/index.d.ts +198 -8
- package/dist/index.js +166 -194
- package/dist/index.mjs +160 -198
- package/package.json +12 -11
- package/dist/toast-group.connect.d.ts +0 -24
- package/dist/toast-group.machine.d.ts +0 -2
- package/dist/toast.connect.d.ts +0 -17
- package/dist/toast.dom.d.ts +0 -26
- package/dist/toast.machine.d.ts +0 -2
- package/dist/toast.types.d.ts +0 -154
- package/dist/toast.utils.d.ts +0 -6
package/dist/index.mjs
CHANGED
|
@@ -1,59 +1,11 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
// ../../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
2
|
var dataAttr = (guard) => {
|
|
51
3
|
return guard ? "" : void 0;
|
|
52
4
|
};
|
|
53
5
|
var MAX_Z_INDEX = 2147483647;
|
|
54
6
|
var runIfFn = (v, ...a) => {
|
|
55
7
|
const res = typeof v === "function" ? v(...a) : v;
|
|
56
|
-
return res
|
|
8
|
+
return res ?? void 0;
|
|
57
9
|
};
|
|
58
10
|
var cast = (v) => v;
|
|
59
11
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
@@ -65,28 +17,27 @@ function isWindow(value) {
|
|
|
65
17
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
66
18
|
}
|
|
67
19
|
function getDocument(el) {
|
|
68
|
-
var _a;
|
|
69
20
|
if (isWindow(el))
|
|
70
21
|
return el.document;
|
|
71
22
|
if (isDocument(el))
|
|
72
23
|
return el;
|
|
73
|
-
return (
|
|
24
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
74
25
|
}
|
|
75
26
|
function defineDomHelpers(helpers) {
|
|
76
27
|
const dom2 = {
|
|
77
28
|
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
29
|
var _a;
|
|
84
|
-
return (_a =
|
|
30
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
85
31
|
},
|
|
32
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
33
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
86
34
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
87
35
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
88
36
|
};
|
|
89
|
-
return
|
|
37
|
+
return {
|
|
38
|
+
...dom2,
|
|
39
|
+
...helpers
|
|
40
|
+
};
|
|
90
41
|
}
|
|
91
42
|
var isRef = (v) => hasProp(v, "current");
|
|
92
43
|
function addDomEvent(target, eventName, handler, options) {
|
|
@@ -107,7 +58,7 @@ function trackDocumentVisibility(_doc, callback) {
|
|
|
107
58
|
// ../../utilities/core/dist/index.mjs
|
|
108
59
|
var runIfFn2 = (v, ...a) => {
|
|
109
60
|
const res = typeof v === "function" ? v(...a) : v;
|
|
110
|
-
return res
|
|
61
|
+
return res ?? void 0;
|
|
111
62
|
};
|
|
112
63
|
var uuid = /* @__PURE__ */ (() => {
|
|
113
64
|
let id = 0;
|
|
@@ -119,7 +70,7 @@ var uuid = /* @__PURE__ */ (() => {
|
|
|
119
70
|
function warn(...a) {
|
|
120
71
|
const m = a.length === 1 ? a[0] : a[1];
|
|
121
72
|
const c = a.length === 2 ? a[0] : true;
|
|
122
|
-
if (c &&
|
|
73
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
123
74
|
console.warn(m);
|
|
124
75
|
}
|
|
125
76
|
}
|
|
@@ -132,6 +83,7 @@ var dom = defineDomHelpers({
|
|
|
132
83
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
133
84
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
134
85
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
86
|
+
getDescriptionId: (ctx) => `toast-description:${ctx.id}`,
|
|
135
87
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
136
88
|
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
137
89
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
@@ -163,7 +115,7 @@ var defaultTimeouts = {
|
|
|
163
115
|
custom: 5e3
|
|
164
116
|
};
|
|
165
117
|
function getToastDuration(duration, type) {
|
|
166
|
-
return duration
|
|
118
|
+
return duration ?? defaultTimeouts[type];
|
|
167
119
|
}
|
|
168
120
|
function getGroupPlacementStyle(ctx, placement) {
|
|
169
121
|
const offset = ctx.offsets;
|
|
@@ -222,7 +174,7 @@ function groupConnect(state, send, normalize) {
|
|
|
222
174
|
const id = options.id ? options.id : uid;
|
|
223
175
|
if (group2.isVisible(id))
|
|
224
176
|
return;
|
|
225
|
-
send({ type: "ADD_TOAST", toast:
|
|
177
|
+
send({ type: "ADD_TOAST", toast: { ...options, id } });
|
|
226
178
|
return id;
|
|
227
179
|
},
|
|
228
180
|
upsert(options) {
|
|
@@ -273,13 +225,13 @@ function groupConnect(state, send, normalize) {
|
|
|
273
225
|
return group2.upsert(options);
|
|
274
226
|
},
|
|
275
227
|
promise(promise, options, shared = {}) {
|
|
276
|
-
const id = group2.loading(
|
|
228
|
+
const id = group2.loading({ ...shared, ...options.loading });
|
|
277
229
|
promise.then((response) => {
|
|
278
230
|
const successOptions = runIfFn2(options.success, response);
|
|
279
|
-
group2.success(
|
|
231
|
+
group2.success({ ...shared, ...successOptions, id });
|
|
280
232
|
}).catch((error) => {
|
|
281
233
|
const errorOptions = runIfFn2(options.error, error);
|
|
282
|
-
group2.error(
|
|
234
|
+
group2.error({ ...shared, ...errorOptions, id });
|
|
283
235
|
});
|
|
284
236
|
return promise;
|
|
285
237
|
},
|
|
@@ -329,153 +281,157 @@ function groupConnect(state, send, normalize) {
|
|
|
329
281
|
}
|
|
330
282
|
|
|
331
283
|
// src/toast-group.machine.ts
|
|
332
|
-
import { createMachine as createMachine2
|
|
284
|
+
import { createMachine as createMachine2 } from "@zag-js/core";
|
|
333
285
|
|
|
334
286
|
// src/toast.machine.ts
|
|
335
287
|
import { createMachine, guards } from "@zag-js/core";
|
|
336
288
|
var { not, and, or } = guards;
|
|
337
289
|
function createToastMachine(options = {}) {
|
|
338
|
-
const
|
|
290
|
+
const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 500, ...rest } = options;
|
|
339
291
|
const __duration = getToastDuration(duration, type);
|
|
340
|
-
return createMachine(
|
|
341
|
-
|
|
342
|
-
entry: "invokeOnOpen",
|
|
343
|
-
initial: type === "loading" ? "persist" : "active",
|
|
344
|
-
context: __spreadValues({
|
|
292
|
+
return createMachine(
|
|
293
|
+
{
|
|
345
294
|
id,
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
target: "persist",
|
|
358
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
guard: or("hasDurationChanged", "hasTypeChanged"),
|
|
362
|
-
target: "active:temp",
|
|
363
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
367
|
-
}
|
|
368
|
-
]
|
|
369
|
-
},
|
|
370
|
-
states: {
|
|
371
|
-
"active:temp": {
|
|
372
|
-
tags: ["visible", "updating"],
|
|
373
|
-
after: {
|
|
374
|
-
0: "active"
|
|
375
|
-
}
|
|
295
|
+
entry: "invokeOnOpen",
|
|
296
|
+
initial: type === "loading" ? "persist" : "active",
|
|
297
|
+
context: {
|
|
298
|
+
id,
|
|
299
|
+
type,
|
|
300
|
+
remaining: __duration,
|
|
301
|
+
duration: __duration,
|
|
302
|
+
removeDelay,
|
|
303
|
+
createdAt: Date.now(),
|
|
304
|
+
placement,
|
|
305
|
+
...rest
|
|
376
306
|
},
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
target: "active",
|
|
384
|
-
actions: ["setCreatedAt"]
|
|
307
|
+
on: {
|
|
308
|
+
UPDATE: [
|
|
309
|
+
{
|
|
310
|
+
guard: and("hasTypeChanged", "isChangingToLoading"),
|
|
311
|
+
target: "persist",
|
|
312
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
385
313
|
},
|
|
386
|
-
|
|
387
|
-
|
|
314
|
+
{
|
|
315
|
+
guard: or("hasDurationChanged", "hasTypeChanged"),
|
|
316
|
+
target: "active:temp",
|
|
317
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
321
|
+
}
|
|
322
|
+
]
|
|
388
323
|
},
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
324
|
+
states: {
|
|
325
|
+
"active:temp": {
|
|
326
|
+
tags: ["visible", "updating"],
|
|
327
|
+
after: {
|
|
328
|
+
0: "active"
|
|
329
|
+
}
|
|
394
330
|
},
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
331
|
+
persist: {
|
|
332
|
+
tags: ["visible", "paused"],
|
|
333
|
+
activities: "trackDocumentVisibility",
|
|
334
|
+
on: {
|
|
335
|
+
RESUME: {
|
|
336
|
+
guard: not("isLoadingType"),
|
|
337
|
+
target: "active",
|
|
338
|
+
actions: ["setCreatedAt"]
|
|
339
|
+
},
|
|
340
|
+
DISMISS: "dismissing"
|
|
400
341
|
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
342
|
+
},
|
|
343
|
+
active: {
|
|
344
|
+
tags: ["visible"],
|
|
345
|
+
activities: "trackDocumentVisibility",
|
|
346
|
+
after: {
|
|
347
|
+
VISIBLE_DURATION: "dismissing"
|
|
348
|
+
},
|
|
349
|
+
on: {
|
|
350
|
+
DISMISS: "dismissing",
|
|
351
|
+
PAUSE: {
|
|
352
|
+
target: "persist",
|
|
353
|
+
actions: "setRemainingDuration"
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
dismissing: {
|
|
358
|
+
entry: "invokeOnClosing",
|
|
359
|
+
after: {
|
|
360
|
+
REMOVE_DELAY: {
|
|
361
|
+
target: "inactive",
|
|
362
|
+
actions: "notifyParentToRemove"
|
|
363
|
+
}
|
|
409
364
|
}
|
|
365
|
+
},
|
|
366
|
+
inactive: {
|
|
367
|
+
entry: "invokeOnClose",
|
|
368
|
+
type: "final"
|
|
410
369
|
}
|
|
411
|
-
},
|
|
412
|
-
inactive: {
|
|
413
|
-
entry: "invokeOnClose",
|
|
414
|
-
type: "final"
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}, {
|
|
418
|
-
activities: {
|
|
419
|
-
trackDocumentVisibility(ctx, _evt, { send }) {
|
|
420
|
-
if (!ctx.pauseOnPageIdle)
|
|
421
|
-
return;
|
|
422
|
-
return trackDocumentVisibility(dom.getDoc(ctx), function(hidden) {
|
|
423
|
-
send(hidden ? "PAUSE" : "RESUME");
|
|
424
|
-
});
|
|
425
370
|
}
|
|
426
371
|
},
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
},
|
|
437
|
-
hasDurationChanged: (ctx, evt) => {
|
|
438
|
-
var _a2;
|
|
439
|
-
return ((_a2 = evt.toast) == null ? void 0 : _a2.duration) !== ctx.duration;
|
|
440
|
-
}
|
|
441
|
-
},
|
|
442
|
-
delays: {
|
|
443
|
-
VISIBLE_DURATION: (ctx) => ctx.remaining,
|
|
444
|
-
REMOVE_DELAY: (ctx) => ctx.removeDelay
|
|
445
|
-
},
|
|
446
|
-
actions: {
|
|
447
|
-
setRemainingDuration(ctx) {
|
|
448
|
-
ctx.remaining -= Date.now() - ctx.createdAt;
|
|
449
|
-
},
|
|
450
|
-
setCreatedAt(ctx) {
|
|
451
|
-
ctx.createdAt = Date.now();
|
|
452
|
-
},
|
|
453
|
-
notifyParentToRemove(_ctx, _evt, { self }) {
|
|
454
|
-
self.sendParent({ type: "REMOVE_TOAST", id: self.id });
|
|
455
|
-
},
|
|
456
|
-
invokeOnClosing(ctx) {
|
|
457
|
-
var _a2;
|
|
458
|
-
(_a2 = ctx.onClosing) == null ? void 0 : _a2.call(ctx);
|
|
459
|
-
},
|
|
460
|
-
invokeOnClose(ctx) {
|
|
461
|
-
var _a2;
|
|
462
|
-
(_a2 = ctx.onClose) == null ? void 0 : _a2.call(ctx);
|
|
372
|
+
{
|
|
373
|
+
activities: {
|
|
374
|
+
trackDocumentVisibility(ctx, _evt, { send }) {
|
|
375
|
+
if (!ctx.pauseOnPageIdle)
|
|
376
|
+
return;
|
|
377
|
+
return trackDocumentVisibility(dom.getDoc(ctx), function(hidden) {
|
|
378
|
+
send(hidden ? "PAUSE" : "RESUME");
|
|
379
|
+
});
|
|
380
|
+
}
|
|
463
381
|
},
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
382
|
+
guards: {
|
|
383
|
+
isChangingToLoading: (_, evt) => {
|
|
384
|
+
var _a;
|
|
385
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
|
|
386
|
+
},
|
|
387
|
+
isLoadingType: (ctx) => ctx.type === "loading",
|
|
388
|
+
hasTypeChanged: (ctx, evt) => {
|
|
389
|
+
var _a;
|
|
390
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx.type;
|
|
391
|
+
},
|
|
392
|
+
hasDurationChanged: (ctx, evt) => {
|
|
393
|
+
var _a;
|
|
394
|
+
return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
|
|
395
|
+
}
|
|
467
396
|
},
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
(
|
|
397
|
+
delays: {
|
|
398
|
+
VISIBLE_DURATION: (ctx) => ctx.remaining,
|
|
399
|
+
REMOVE_DELAY: (ctx) => ctx.removeDelay
|
|
471
400
|
},
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
401
|
+
actions: {
|
|
402
|
+
setRemainingDuration(ctx) {
|
|
403
|
+
ctx.remaining -= Date.now() - ctx.createdAt;
|
|
404
|
+
},
|
|
405
|
+
setCreatedAt(ctx) {
|
|
406
|
+
ctx.createdAt = Date.now();
|
|
407
|
+
},
|
|
408
|
+
notifyParentToRemove(_ctx, _evt, { self }) {
|
|
409
|
+
self.sendParent({ type: "REMOVE_TOAST", id: self.id });
|
|
410
|
+
},
|
|
411
|
+
invokeOnClosing(ctx) {
|
|
412
|
+
var _a;
|
|
413
|
+
(_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
|
|
414
|
+
},
|
|
415
|
+
invokeOnClose(ctx) {
|
|
416
|
+
var _a;
|
|
417
|
+
(_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
|
|
418
|
+
},
|
|
419
|
+
invokeOnOpen(ctx) {
|
|
420
|
+
var _a;
|
|
421
|
+
(_a = ctx.onOpen) == null ? void 0 : _a.call(ctx);
|
|
422
|
+
},
|
|
423
|
+
invokeOnUpdate(ctx) {
|
|
424
|
+
var _a;
|
|
425
|
+
(_a = ctx.onUpdate) == null ? void 0 : _a.call(ctx);
|
|
426
|
+
},
|
|
427
|
+
setContext(ctx, evt) {
|
|
428
|
+
const { duration: duration2, type: type2 } = evt.toast;
|
|
429
|
+
const time = getToastDuration(duration2, type2);
|
|
430
|
+
Object.assign(ctx, { ...evt.toast, duration: time, remaining: time });
|
|
431
|
+
}
|
|
476
432
|
}
|
|
477
433
|
}
|
|
478
|
-
|
|
434
|
+
);
|
|
479
435
|
}
|
|
480
436
|
|
|
481
437
|
// src/toast-group.machine.ts
|
|
@@ -483,7 +439,7 @@ function groupMachine(ctx) {
|
|
|
483
439
|
return createMachine2({
|
|
484
440
|
id: "toaster",
|
|
485
441
|
initial: "active",
|
|
486
|
-
context:
|
|
442
|
+
context: {
|
|
487
443
|
dir: "ltr",
|
|
488
444
|
max: Number.MAX_SAFE_INTEGER,
|
|
489
445
|
toasts: [],
|
|
@@ -491,8 +447,9 @@ function groupMachine(ctx) {
|
|
|
491
447
|
zIndex: MAX_Z_INDEX,
|
|
492
448
|
pauseOnPageIdle: false,
|
|
493
449
|
pauseOnInteraction: true,
|
|
494
|
-
offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" }
|
|
495
|
-
|
|
450
|
+
offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" },
|
|
451
|
+
...ctx
|
|
452
|
+
},
|
|
496
453
|
computed: {
|
|
497
454
|
count: (ctx2) => ctx2.toasts.length
|
|
498
455
|
},
|
|
@@ -521,13 +478,13 @@ function groupMachine(ctx) {
|
|
|
521
478
|
ADD_TOAST: {
|
|
522
479
|
guard: (ctx2) => ctx2.toasts.length < ctx2.max,
|
|
523
480
|
actions: (ctx2, evt, { self }) => {
|
|
524
|
-
|
|
525
|
-
|
|
481
|
+
const options = {
|
|
482
|
+
...evt.toast,
|
|
526
483
|
pauseOnPageIdle: ctx2.pauseOnPageIdle,
|
|
527
484
|
pauseOnInteraction: ctx2.pauseOnInteraction,
|
|
528
485
|
dir: ctx2.dir,
|
|
529
|
-
|
|
530
|
-
}
|
|
486
|
+
getRootNode: ctx2.getRootNode
|
|
487
|
+
};
|
|
531
488
|
const toast = createToastMachine(options);
|
|
532
489
|
const actor = self.spawn(toast);
|
|
533
490
|
ctx2.toasts.push(actor);
|
|
@@ -578,6 +535,7 @@ function connect(state, send, normalize) {
|
|
|
578
535
|
return {
|
|
579
536
|
type: state.context.type,
|
|
580
537
|
title: state.context.title,
|
|
538
|
+
description: state.context.description,
|
|
581
539
|
placement,
|
|
582
540
|
isVisible,
|
|
583
541
|
isPaused,
|
|
@@ -650,6 +608,10 @@ function connect(state, send, normalize) {
|
|
|
650
608
|
"data-part": "title",
|
|
651
609
|
id: dom.getTitleId(state.context)
|
|
652
610
|
}),
|
|
611
|
+
descriptionProps: normalize.element({
|
|
612
|
+
"data-part": "description",
|
|
613
|
+
id: dom.getDescriptionId(state.context)
|
|
614
|
+
}),
|
|
653
615
|
closeButtonProps: normalize.button({
|
|
654
616
|
id: dom.getCloseButtonId(state.context),
|
|
655
617
|
"data-part": "close-button",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/toast",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Core logic for the toast widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,20 +29,21 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.1.
|
|
33
|
-
"@zag-js/types": "0.2.
|
|
32
|
+
"@zag-js/core": "0.1.9",
|
|
33
|
+
"@zag-js/types": "0.2.4"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@zag-js/dom-utils": "0.1.
|
|
37
|
-
"@zag-js/utils": "0.1.
|
|
36
|
+
"@zag-js/dom-utils": "0.1.10",
|
|
37
|
+
"@zag-js/utils": "0.1.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build
|
|
41
|
-
"start": "
|
|
42
|
-
"build": "
|
|
40
|
+
"build-fast": "tsup src/index.ts --format=esm,cjs",
|
|
41
|
+
"start": "pnpm build --watch",
|
|
42
|
+
"build": "tsup src/index.ts --format=esm,cjs --dts",
|
|
43
43
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
44
44
|
"lint": "eslint src --ext .ts,.tsx",
|
|
45
|
-
"test
|
|
46
|
-
"test
|
|
45
|
+
"test-ci": "pnpm test --ci --runInBand",
|
|
46
|
+
"test-watch": "pnpm test --watch -u",
|
|
47
|
+
"typecheck": "tsc --noEmit"
|
|
47
48
|
}
|
|
48
|
-
}
|
|
49
|
+
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
-
import type { GroupMachineContext, GroupProps, GroupSend, GroupState, Placement, PromiseOptions, Toaster, Options } from "./toast.types";
|
|
3
|
-
export declare let toaster: Toaster;
|
|
4
|
-
export declare function groupConnect<T extends PropTypes>(state: GroupState, send: GroupSend, normalize: NormalizeProps<T>): {
|
|
5
|
-
count: number;
|
|
6
|
-
toasts: import("./toast.types").Service[];
|
|
7
|
-
toastsByPlacement: Partial<Record<Placement, import("./toast.types").Service[]>>;
|
|
8
|
-
isVisible(id: string): boolean;
|
|
9
|
-
create(options: Options): string;
|
|
10
|
-
upsert(options: Options): string;
|
|
11
|
-
dismiss(id?: string): void;
|
|
12
|
-
remove(id?: string): void;
|
|
13
|
-
dismissByPlacement(placement: Placement): void;
|
|
14
|
-
update(id: string, options: Options): string;
|
|
15
|
-
loading(options: Options): string;
|
|
16
|
-
success(options: Options): string;
|
|
17
|
-
error(options: Options): string;
|
|
18
|
-
promise<T_1>(promise: Promise<T_1>, options: PromiseOptions<T_1>, shared?: Options): Promise<T_1>;
|
|
19
|
-
pause(id?: string): void;
|
|
20
|
-
resume(id?: string): void;
|
|
21
|
-
getGroupProps(options: GroupProps): T["element"];
|
|
22
|
-
createPortal(): HTMLElement;
|
|
23
|
-
subscribe(fn: (toasts: GroupMachineContext["toasts"]) => void): () => void;
|
|
24
|
-
};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import type { GroupMachineContext, UserDefinedGroupContext } from "./toast.types";
|
|
2
|
-
export declare function groupMachine(ctx: UserDefinedGroupContext): import("@zag-js/core").Machine<GroupMachineContext, import("@zag-js/core").StateMachine.StateSchema, import("@zag-js/core").StateMachine.AnyEventObject>;
|
package/dist/toast.connect.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
-
import type { Send, State } from "./toast.types";
|
|
3
|
-
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
4
|
-
type: import("./toast.types").Type;
|
|
5
|
-
title: string;
|
|
6
|
-
placement: import("./toast.types").Placement;
|
|
7
|
-
isVisible: boolean;
|
|
8
|
-
isPaused: boolean;
|
|
9
|
-
pause(): void;
|
|
10
|
-
resume(): void;
|
|
11
|
-
dismiss(): void;
|
|
12
|
-
rootProps: T["element"];
|
|
13
|
-
progressbarProps: T["element"];
|
|
14
|
-
titleProps: T["element"];
|
|
15
|
-
closeButtonProps: T["button"];
|
|
16
|
-
render(): any;
|
|
17
|
-
};
|
package/dist/toast.dom.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { GroupMachineContext as GroupCtx, MachineContext as Ctx, Placement } from "./toast.types";
|
|
2
|
-
export declare const dom: {
|
|
3
|
-
getRootNode: (ctx: {
|
|
4
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
5
|
-
}) => Document | ShadowRoot;
|
|
6
|
-
getDoc: (ctx: {
|
|
7
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
8
|
-
}) => Document;
|
|
9
|
-
getWin: (ctx: {
|
|
10
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
11
|
-
}) => Window & typeof globalThis;
|
|
12
|
-
getActiveElement: (ctx: {
|
|
13
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
14
|
-
}) => HTMLElement;
|
|
15
|
-
getById: <T_1 = HTMLElement>(ctx: {
|
|
16
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
17
|
-
}, id: string) => T_1;
|
|
18
|
-
} & {
|
|
19
|
-
getGroupId: (placement: Placement) => string;
|
|
20
|
-
getContainerId: (ctx: Ctx) => string;
|
|
21
|
-
getTitleId: (ctx: Ctx) => string;
|
|
22
|
-
getCloseButtonId: (ctx: Ctx) => string;
|
|
23
|
-
getPortalId: (ctx: GroupCtx) => string;
|
|
24
|
-
getPortalEl: (ctx: GroupCtx) => HTMLElement;
|
|
25
|
-
createPortalEl: (ctx: GroupCtx) => HTMLElement;
|
|
26
|
-
};
|
package/dist/toast.machine.d.ts
DELETED