@zag-js/toast 1.8.2 → 1.9.1
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/index.js +16 -1
- package/dist/index.mjs +16 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -125,7 +125,7 @@ interface ToastStoreProps {
|
|
|
125
125
|
*/
|
|
126
126
|
placement?: Placement | undefined;
|
|
127
127
|
/**
|
|
128
|
-
* The maximum number of toasts
|
|
128
|
+
* The maximum number of toasts. When the number of toasts exceeds this limit, the new toasts are queued.
|
|
129
129
|
* @default 24
|
|
130
130
|
*/
|
|
131
131
|
max?: number | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -125,7 +125,7 @@ interface ToastStoreProps {
|
|
|
125
125
|
*/
|
|
126
126
|
placement?: Placement | undefined;
|
|
127
127
|
/**
|
|
128
|
-
* The maximum number of toasts
|
|
128
|
+
* The maximum number of toasts. When the number of toasts exceeds this limit, the new toasts are queued.
|
|
129
129
|
* @default 24
|
|
130
130
|
*/
|
|
131
131
|
max?: number | undefined;
|
package/dist/index.js
CHANGED
|
@@ -835,6 +835,7 @@ function createToastStore(props) {
|
|
|
835
835
|
let subscribers = [];
|
|
836
836
|
let toasts = [];
|
|
837
837
|
let dismissedToasts = /* @__PURE__ */ new Set();
|
|
838
|
+
let toastQueue = [];
|
|
838
839
|
const subscribe = (subscriber) => {
|
|
839
840
|
subscribers.push(subscriber);
|
|
840
841
|
return () => {
|
|
@@ -847,10 +848,22 @@ function createToastStore(props) {
|
|
|
847
848
|
return data;
|
|
848
849
|
};
|
|
849
850
|
const addToast = (data) => {
|
|
850
|
-
if (toasts.length >= attrs.max)
|
|
851
|
+
if (toasts.length >= attrs.max) {
|
|
852
|
+
toastQueue.push(data);
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
851
855
|
publish(data);
|
|
852
856
|
toasts.unshift(data);
|
|
853
857
|
};
|
|
858
|
+
const processQueue = () => {
|
|
859
|
+
while (toastQueue.length > 0 && toasts.length < attrs.max) {
|
|
860
|
+
const nextToast = toastQueue.shift();
|
|
861
|
+
if (nextToast) {
|
|
862
|
+
publish(nextToast);
|
|
863
|
+
toasts.unshift(nextToast);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
};
|
|
854
867
|
const create = (data) => {
|
|
855
868
|
const id = data.id ?? `toast:${utils.uuid()}`;
|
|
856
869
|
const exists = toasts.find((toast) => toast.id === id);
|
|
@@ -882,9 +895,11 @@ function createToastStore(props) {
|
|
|
882
895
|
subscribers.forEach((subscriber) => subscriber({ id: toast.id, dismiss: true }));
|
|
883
896
|
});
|
|
884
897
|
toasts = [];
|
|
898
|
+
toastQueue = [];
|
|
885
899
|
} else {
|
|
886
900
|
subscribers.forEach((subscriber) => subscriber({ id, dismiss: true }));
|
|
887
901
|
toasts = toasts.filter((toast) => toast.id !== id);
|
|
902
|
+
processQueue();
|
|
888
903
|
}
|
|
889
904
|
return id;
|
|
890
905
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -833,6 +833,7 @@ function createToastStore(props) {
|
|
|
833
833
|
let subscribers = [];
|
|
834
834
|
let toasts = [];
|
|
835
835
|
let dismissedToasts = /* @__PURE__ */ new Set();
|
|
836
|
+
let toastQueue = [];
|
|
836
837
|
const subscribe = (subscriber) => {
|
|
837
838
|
subscribers.push(subscriber);
|
|
838
839
|
return () => {
|
|
@@ -845,10 +846,22 @@ function createToastStore(props) {
|
|
|
845
846
|
return data;
|
|
846
847
|
};
|
|
847
848
|
const addToast = (data) => {
|
|
848
|
-
if (toasts.length >= attrs.max)
|
|
849
|
+
if (toasts.length >= attrs.max) {
|
|
850
|
+
toastQueue.push(data);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
849
853
|
publish(data);
|
|
850
854
|
toasts.unshift(data);
|
|
851
855
|
};
|
|
856
|
+
const processQueue = () => {
|
|
857
|
+
while (toastQueue.length > 0 && toasts.length < attrs.max) {
|
|
858
|
+
const nextToast = toastQueue.shift();
|
|
859
|
+
if (nextToast) {
|
|
860
|
+
publish(nextToast);
|
|
861
|
+
toasts.unshift(nextToast);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
};
|
|
852
865
|
const create = (data) => {
|
|
853
866
|
const id = data.id ?? `toast:${uuid()}`;
|
|
854
867
|
const exists = toasts.find((toast) => toast.id === id);
|
|
@@ -880,9 +893,11 @@ function createToastStore(props) {
|
|
|
880
893
|
subscribers.forEach((subscriber) => subscriber({ id: toast.id, dismiss: true }));
|
|
881
894
|
});
|
|
882
895
|
toasts = [];
|
|
896
|
+
toastQueue = [];
|
|
883
897
|
} else {
|
|
884
898
|
subscribers.forEach((subscriber) => subscriber({ id, dismiss: true }));
|
|
885
899
|
toasts = toasts.filter((toast) => toast.id !== id);
|
|
900
|
+
processQueue();
|
|
886
901
|
}
|
|
887
902
|
return id;
|
|
888
903
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/toast",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
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/
|
|
30
|
-
"@zag-js/
|
|
31
|
-
"@zag-js/
|
|
32
|
-
"@zag-js/
|
|
33
|
-
"@zag-js/
|
|
34
|
-
"@zag-js/types": "1.
|
|
29
|
+
"@zag-js/anatomy": "1.9.1",
|
|
30
|
+
"@zag-js/core": "1.9.1",
|
|
31
|
+
"@zag-js/dom-query": "1.9.1",
|
|
32
|
+
"@zag-js/dismissable": "1.9.1",
|
|
33
|
+
"@zag-js/utils": "1.9.1",
|
|
34
|
+
"@zag-js/types": "1.9.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"clean-package": "2.2.0"
|