@zag-js/toast 1.38.1 → 1.39.0
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.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/toast.anatomy.d.mts +2 -2
- package/dist/toast.anatomy.d.ts +2 -2
- package/dist/toast.store.js +26 -4
- package/dist/toast.store.mjs +26 -4
- package/dist/toast.types.d.mts +10 -3
- package/dist/toast.types.d.ts +10 -3
- package/dist/toast.utils.js +1 -0
- package/dist/toast.utils.mjs +1 -0
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _zag_js_core from '@zag-js/core';
|
|
2
2
|
import { ToastGroupSchema } from './toast.types.mjs';
|
|
3
|
-
export { ActionOptions, ToastApi as Api, ToastGroupApi as GroupApi, ToastGroupMachine as GroupMachine, ToastGroupProps as GroupProps, ToastGroupService as GroupService, IntlTranslations, ToastMachine as Machine, Options, Placement, PromiseOptions, ToastProps as Props, ToastService as Service, Status, StatusChangeDetails, ToastStore as Store, ToastStoreProps as StoreProps, ToastHeight, Type } from './toast.types.mjs';
|
|
3
|
+
export { ActionOptions, ToastApi as Api, ToastGroupApi as GroupApi, ToastGroupMachine as GroupMachine, ToastGroupProps as GroupProps, ToastGroupService as GroupService, IntlTranslations, ToastMachine as Machine, Options, Placement, PromiseOptions, ToastProps as Props, ToastService as Service, Status, StatusChangeDetails, ToastStore as Store, ToastStoreProps as StoreProps, ToastHeight, ToastQueuePriority, Type } from './toast.types.mjs';
|
|
4
4
|
import { groupConnect } from './toast-group.connect.mjs';
|
|
5
5
|
export { anatomy } from './toast.anatomy.mjs';
|
|
6
6
|
export { connect } from './toast.connect.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _zag_js_core from '@zag-js/core';
|
|
2
2
|
import { ToastGroupSchema } from './toast.types.js';
|
|
3
|
-
export { ActionOptions, ToastApi as Api, ToastGroupApi as GroupApi, ToastGroupMachine as GroupMachine, ToastGroupProps as GroupProps, ToastGroupService as GroupService, IntlTranslations, ToastMachine as Machine, Options, Placement, PromiseOptions, ToastProps as Props, ToastService as Service, Status, StatusChangeDetails, ToastStore as Store, ToastStoreProps as StoreProps, ToastHeight, Type } from './toast.types.js';
|
|
3
|
+
export { ActionOptions, ToastApi as Api, ToastGroupApi as GroupApi, ToastGroupMachine as GroupMachine, ToastGroupProps as GroupProps, ToastGroupService as GroupService, IntlTranslations, ToastMachine as Machine, Options, Placement, PromiseOptions, ToastProps as Props, ToastService as Service, Status, StatusChangeDetails, ToastStore as Store, ToastStoreProps as StoreProps, ToastHeight, ToastQueuePriority, Type } from './toast.types.js';
|
|
4
4
|
import { groupConnect } from './toast-group.connect.js';
|
|
5
5
|
export { anatomy } from './toast.anatomy.js';
|
|
6
6
|
export { connect } from './toast.connect.js';
|
package/dist/toast.anatomy.d.mts
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" | "description" | "group" | "root" | "actionTrigger" | "closeTrigger">;
|
|
4
|
+
declare const parts: Record<"title" | "description" | "group" | "root" | "actionTrigger" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
|
|
5
5
|
|
|
6
6
|
export { anatomy, parts };
|
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" | "description" | "group" | "root" | "actionTrigger" | "closeTrigger">;
|
|
4
|
+
declare const parts: Record<"title" | "description" | "group" | "root" | "actionTrigger" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
|
|
5
5
|
|
|
6
6
|
export { anatomy, parts };
|
package/dist/toast.store.js
CHANGED
|
@@ -27,6 +27,25 @@ var import_utils = require("@zag-js/utils");
|
|
|
27
27
|
var withDefaults = (options, defaults) => {
|
|
28
28
|
return { ...defaults, ...(0, import_utils.compact)(options) };
|
|
29
29
|
};
|
|
30
|
+
var priorities = {
|
|
31
|
+
error: [1, 2],
|
|
32
|
+
warning: [3, 6],
|
|
33
|
+
loading: [4, 5],
|
|
34
|
+
success: [5, 7],
|
|
35
|
+
info: [6, 8]
|
|
36
|
+
};
|
|
37
|
+
var DEFAULT_TYPE = "info";
|
|
38
|
+
var getPriorityForType = (type, hasAction) => {
|
|
39
|
+
const [actionable, nonActionable] = priorities[type ?? DEFAULT_TYPE];
|
|
40
|
+
return hasAction ? actionable : nonActionable;
|
|
41
|
+
};
|
|
42
|
+
var sortToastsByPriority = (toastArray) => {
|
|
43
|
+
return toastArray.sort((a, b) => {
|
|
44
|
+
const priorityA = a.priority ?? getPriorityForType(a.type, !!a.action);
|
|
45
|
+
const priorityB = b.priority ?? getPriorityForType(b.type, !!b.action);
|
|
46
|
+
return priorityA - priorityB;
|
|
47
|
+
});
|
|
48
|
+
};
|
|
30
49
|
function createToastStore(props = {}) {
|
|
31
50
|
const attrs = withDefaults(props, {
|
|
32
51
|
placement: "bottom",
|
|
@@ -62,6 +81,7 @@ function createToastStore(props = {}) {
|
|
|
62
81
|
toasts.unshift(data);
|
|
63
82
|
};
|
|
64
83
|
const processQueue = () => {
|
|
84
|
+
toastQueue = sortToastsByPriority(toastQueue);
|
|
65
85
|
while (toastQueue.length > 0 && toasts.length < attrs.max) {
|
|
66
86
|
const nextToast = toastQueue.shift();
|
|
67
87
|
if (nextToast) {
|
|
@@ -82,15 +102,17 @@ function createToastStore(props = {}) {
|
|
|
82
102
|
return toast;
|
|
83
103
|
});
|
|
84
104
|
} else {
|
|
85
|
-
|
|
105
|
+
const newToast = {
|
|
86
106
|
id,
|
|
87
107
|
duration: attrs.duration,
|
|
88
108
|
removeDelay: attrs.removeDelay,
|
|
89
|
-
type:
|
|
109
|
+
type: DEFAULT_TYPE,
|
|
90
110
|
...data,
|
|
91
111
|
stacked: !attrs.overlap,
|
|
92
112
|
gap: attrs.gap
|
|
93
|
-
}
|
|
113
|
+
};
|
|
114
|
+
const priority = newToast.priority ?? getPriorityForType(newToast.type, !!newToast.action);
|
|
115
|
+
addToast({ ...newToast, priority });
|
|
94
116
|
}
|
|
95
117
|
return id;
|
|
96
118
|
};
|
|
@@ -152,7 +174,7 @@ function createToastStore(props = {}) {
|
|
|
152
174
|
} else if (options.success !== void 0) {
|
|
153
175
|
removable = false;
|
|
154
176
|
const successOptions = (0, import_utils.runIfFn)(options.success, response);
|
|
155
|
-
create({ ...shared, ...successOptions, id, type: "success" });
|
|
177
|
+
create({ ...shared, ...successOptions, id, type: successOptions.type ?? "success" });
|
|
156
178
|
}
|
|
157
179
|
}).catch(async (error2) => {
|
|
158
180
|
result = ["reject", error2];
|
package/dist/toast.store.mjs
CHANGED
|
@@ -3,6 +3,25 @@ import { compact, runIfFn, uuid, warn } from "@zag-js/utils";
|
|
|
3
3
|
var withDefaults = (options, defaults) => {
|
|
4
4
|
return { ...defaults, ...compact(options) };
|
|
5
5
|
};
|
|
6
|
+
var priorities = {
|
|
7
|
+
error: [1, 2],
|
|
8
|
+
warning: [3, 6],
|
|
9
|
+
loading: [4, 5],
|
|
10
|
+
success: [5, 7],
|
|
11
|
+
info: [6, 8]
|
|
12
|
+
};
|
|
13
|
+
var DEFAULT_TYPE = "info";
|
|
14
|
+
var getPriorityForType = (type, hasAction) => {
|
|
15
|
+
const [actionable, nonActionable] = priorities[type ?? DEFAULT_TYPE];
|
|
16
|
+
return hasAction ? actionable : nonActionable;
|
|
17
|
+
};
|
|
18
|
+
var sortToastsByPriority = (toastArray) => {
|
|
19
|
+
return toastArray.sort((a, b) => {
|
|
20
|
+
const priorityA = a.priority ?? getPriorityForType(a.type, !!a.action);
|
|
21
|
+
const priorityB = b.priority ?? getPriorityForType(b.type, !!b.action);
|
|
22
|
+
return priorityA - priorityB;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
6
25
|
function createToastStore(props = {}) {
|
|
7
26
|
const attrs = withDefaults(props, {
|
|
8
27
|
placement: "bottom",
|
|
@@ -38,6 +57,7 @@ function createToastStore(props = {}) {
|
|
|
38
57
|
toasts.unshift(data);
|
|
39
58
|
};
|
|
40
59
|
const processQueue = () => {
|
|
60
|
+
toastQueue = sortToastsByPriority(toastQueue);
|
|
41
61
|
while (toastQueue.length > 0 && toasts.length < attrs.max) {
|
|
42
62
|
const nextToast = toastQueue.shift();
|
|
43
63
|
if (nextToast) {
|
|
@@ -58,15 +78,17 @@ function createToastStore(props = {}) {
|
|
|
58
78
|
return toast;
|
|
59
79
|
});
|
|
60
80
|
} else {
|
|
61
|
-
|
|
81
|
+
const newToast = {
|
|
62
82
|
id,
|
|
63
83
|
duration: attrs.duration,
|
|
64
84
|
removeDelay: attrs.removeDelay,
|
|
65
|
-
type:
|
|
85
|
+
type: DEFAULT_TYPE,
|
|
66
86
|
...data,
|
|
67
87
|
stacked: !attrs.overlap,
|
|
68
88
|
gap: attrs.gap
|
|
69
|
-
}
|
|
89
|
+
};
|
|
90
|
+
const priority = newToast.priority ?? getPriorityForType(newToast.type, !!newToast.action);
|
|
91
|
+
addToast({ ...newToast, priority });
|
|
70
92
|
}
|
|
71
93
|
return id;
|
|
72
94
|
};
|
|
@@ -128,7 +150,7 @@ function createToastStore(props = {}) {
|
|
|
128
150
|
} else if (options.success !== void 0) {
|
|
129
151
|
removable = false;
|
|
130
152
|
const successOptions = runIfFn(options.success, response);
|
|
131
|
-
create({ ...shared, ...successOptions, id, type: "success" });
|
|
153
|
+
create({ ...shared, ...successOptions, id, type: successOptions.type ?? "success" });
|
|
132
154
|
}
|
|
133
155
|
}).catch(async (error2) => {
|
|
134
156
|
result = ["reject", error2];
|
package/dist/toast.types.d.mts
CHANGED
|
@@ -2,7 +2,8 @@ import { PropTypes, CommonProperties, Direction, DirectionProperty, Required, Re
|
|
|
2
2
|
import { Service, EventObject, Machine } from '@zag-js/core';
|
|
3
3
|
import { AnimationFrame } from '@zag-js/dom-query';
|
|
4
4
|
|
|
5
|
-
type Type = "success" | "error" | "loading" | "info" | (string & {});
|
|
5
|
+
type Type = "success" | "error" | "loading" | "info" | "warning" | (string & {});
|
|
6
|
+
type ToastQueuePriority = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
6
7
|
type Placement = "top-start" | "top" | "top-end" | "bottom-start" | "bottom" | "bottom-end";
|
|
7
8
|
type Status = "visible" | "dismissing" | "unmounted";
|
|
8
9
|
interface StatusChangeDetails {
|
|
@@ -64,6 +65,10 @@ interface Options<T = any> {
|
|
|
64
65
|
* The type of the toast
|
|
65
66
|
*/
|
|
66
67
|
type?: Type | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* The priority of the toast (1 = highest, 8 = lowest)
|
|
70
|
+
*/
|
|
71
|
+
priority?: ToastQueuePriority | undefined;
|
|
67
72
|
/**
|
|
68
73
|
* Function called when the toast is visible
|
|
69
74
|
*/
|
|
@@ -300,7 +305,9 @@ interface ToastStore<V = any> {
|
|
|
300
305
|
type MaybeFunction<Value, Args> = Value | ((arg: Args) => Value);
|
|
301
306
|
interface PromiseOptions<V, O = any> {
|
|
302
307
|
loading: Omit<Options<O>, "type">;
|
|
303
|
-
success?: MaybeFunction<Omit<Options<O>, "type"
|
|
308
|
+
success?: MaybeFunction<Omit<Options<O>, "type"> & {
|
|
309
|
+
type?: "success" | "warning";
|
|
310
|
+
}, V> | undefined;
|
|
304
311
|
error?: MaybeFunction<Omit<Options<O>, "type">, unknown> | undefined;
|
|
305
312
|
finally?: (() => void | Promise<void>) | undefined;
|
|
306
313
|
}
|
|
@@ -375,4 +382,4 @@ interface ToastApi<T extends PropTypes = PropTypes, O = any> {
|
|
|
375
382
|
getActionTriggerProps: () => T["button"];
|
|
376
383
|
}
|
|
377
384
|
|
|
378
|
-
export type { ActionOptions, GroupProps, IntlTranslations, Options, Placement, PromiseOptions, Status, StatusChangeDetails, ToastApi, ToastGroupApi, ToastGroupMachine, ToastGroupProps, ToastGroupSchema, ToastGroupService, ToastHeight, ToastMachine, ToastProps, ToastSchema, ToastService, ToastStore, ToastStoreProps, Type };
|
|
385
|
+
export type { ActionOptions, GroupProps, IntlTranslations, Options, Placement, PromiseOptions, Status, StatusChangeDetails, ToastApi, ToastGroupApi, ToastGroupMachine, ToastGroupProps, ToastGroupSchema, ToastGroupService, ToastHeight, ToastMachine, ToastProps, ToastQueuePriority, ToastSchema, ToastService, ToastStore, ToastStoreProps, Type };
|
package/dist/toast.types.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { PropTypes, CommonProperties, Direction, DirectionProperty, Required, Re
|
|
|
2
2
|
import { Service, EventObject, Machine } from '@zag-js/core';
|
|
3
3
|
import { AnimationFrame } from '@zag-js/dom-query';
|
|
4
4
|
|
|
5
|
-
type Type = "success" | "error" | "loading" | "info" | (string & {});
|
|
5
|
+
type Type = "success" | "error" | "loading" | "info" | "warning" | (string & {});
|
|
6
|
+
type ToastQueuePriority = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
6
7
|
type Placement = "top-start" | "top" | "top-end" | "bottom-start" | "bottom" | "bottom-end";
|
|
7
8
|
type Status = "visible" | "dismissing" | "unmounted";
|
|
8
9
|
interface StatusChangeDetails {
|
|
@@ -64,6 +65,10 @@ interface Options<T = any> {
|
|
|
64
65
|
* The type of the toast
|
|
65
66
|
*/
|
|
66
67
|
type?: Type | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* The priority of the toast (1 = highest, 8 = lowest)
|
|
70
|
+
*/
|
|
71
|
+
priority?: ToastQueuePriority | undefined;
|
|
67
72
|
/**
|
|
68
73
|
* Function called when the toast is visible
|
|
69
74
|
*/
|
|
@@ -300,7 +305,9 @@ interface ToastStore<V = any> {
|
|
|
300
305
|
type MaybeFunction<Value, Args> = Value | ((arg: Args) => Value);
|
|
301
306
|
interface PromiseOptions<V, O = any> {
|
|
302
307
|
loading: Omit<Options<O>, "type">;
|
|
303
|
-
success?: MaybeFunction<Omit<Options<O>, "type"
|
|
308
|
+
success?: MaybeFunction<Omit<Options<O>, "type"> & {
|
|
309
|
+
type?: "success" | "warning";
|
|
310
|
+
}, V> | undefined;
|
|
304
311
|
error?: MaybeFunction<Omit<Options<O>, "type">, unknown> | undefined;
|
|
305
312
|
finally?: (() => void | Promise<void>) | undefined;
|
|
306
313
|
}
|
|
@@ -375,4 +382,4 @@ interface ToastApi<T extends PropTypes = PropTypes, O = any> {
|
|
|
375
382
|
getActionTriggerProps: () => T["button"];
|
|
376
383
|
}
|
|
377
384
|
|
|
378
|
-
export type { ActionOptions, GroupProps, IntlTranslations, Options, Placement, PromiseOptions, Status, StatusChangeDetails, ToastApi, ToastGroupApi, ToastGroupMachine, ToastGroupProps, ToastGroupSchema, ToastGroupService, ToastHeight, ToastMachine, ToastProps, ToastSchema, ToastService, ToastStore, ToastStoreProps, Type };
|
|
385
|
+
export type { ActionOptions, GroupProps, IntlTranslations, Options, Placement, PromiseOptions, Status, StatusChangeDetails, ToastApi, ToastGroupApi, ToastGroupMachine, ToastGroupProps, ToastGroupSchema, ToastGroupService, ToastHeight, ToastMachine, ToastProps, ToastQueuePriority, ToastSchema, ToastService, ToastStore, ToastStoreProps, Type };
|
package/dist/toast.utils.js
CHANGED
package/dist/toast.utils.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/toast",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.39.0",
|
|
4
4
|
"description": "Core logic for the toast widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@zag-js/anatomy": "1.
|
|
30
|
-
"@zag-js/core": "1.
|
|
31
|
-
"@zag-js/dom-query": "1.
|
|
32
|
-
"@zag-js/dismissable": "1.
|
|
33
|
-
"@zag-js/utils": "1.
|
|
34
|
-
"@zag-js/types": "1.
|
|
29
|
+
"@zag-js/anatomy": "1.39.0",
|
|
30
|
+
"@zag-js/core": "1.39.0",
|
|
31
|
+
"@zag-js/dom-query": "1.39.0",
|
|
32
|
+
"@zag-js/dismissable": "1.39.0",
|
|
33
|
+
"@zag-js/utils": "1.39.0",
|
|
34
|
+
"@zag-js/types": "1.39.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"clean-package": "2.2.0"
|