@zag-js/toast 1.47.0 → 1.48.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.
Files changed (41) hide show
  1. package/dist/index.d.mts +10 -17
  2. package/dist/index.d.ts +10 -17
  3. package/dist/index.js +18 -45
  4. package/dist/index.mjs +5 -11
  5. package/dist/toast-group.connect.d.mts +4 -8
  6. package/dist/toast-group.connect.d.ts +4 -8
  7. package/dist/toast-group.connect.js +73 -97
  8. package/dist/toast-group.connect.mjs +68 -61
  9. package/dist/toast-group.machine.d.mts +2 -8
  10. package/dist/toast-group.machine.d.ts +2 -8
  11. package/dist/toast-group.machine.js +292 -346
  12. package/dist/toast-group.machine.mjs +287 -310
  13. package/dist/toast.anatomy.d.mts +2 -6
  14. package/dist/toast.anatomy.d.ts +2 -6
  15. package/dist/toast.anatomy.js +8 -40
  16. package/dist/toast.anatomy.mjs +4 -14
  17. package/dist/toast.connect.d.mts +4 -8
  18. package/dist/toast.connect.d.ts +4 -8
  19. package/dist/toast.connect.js +133 -158
  20. package/dist/toast.connect.mjs +128 -122
  21. package/dist/toast.dom.d.mts +19 -23
  22. package/dist/toast.dom.d.ts +19 -23
  23. package/dist/toast.dom.js +54 -83
  24. package/dist/toast.dom.mjs +39 -47
  25. package/dist/toast.machine.d.mts +2 -8
  26. package/dist/toast.machine.d.ts +2 -8
  27. package/dist/toast.machine.js +272 -300
  28. package/dist/toast.machine.mjs +267 -264
  29. package/dist/toast.store.d.mts +2 -8
  30. package/dist/toast.store.d.ts +2 -8
  31. package/dist/toast.store.js +344 -306
  32. package/dist/toast.store.mjs +340 -281
  33. package/dist/toast.types.d.mts +372 -374
  34. package/dist/toast.types.d.ts +372 -374
  35. package/dist/toast.types.js +4 -18
  36. package/dist/toast.types.mjs +1 -0
  37. package/dist/toast.utils.d.mts +10 -14
  38. package/dist/toast.utils.d.ts +10 -14
  39. package/dist/toast.utils.js +167 -217
  40. package/dist/toast.utils.mjs +157 -186
  41. package/package.json +9 -9
@@ -1,314 +1,352 @@
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.store.ts
21
- var toast_store_exports = {};
22
- __export(toast_store_exports, {
23
- createToastStore: () => createToastStore
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
24
4
  });
25
- module.exports = __toCommonJS(toast_store_exports);
26
- var import_utils = require("@zag-js/utils");
27
- var withDefaults = (options, defaults) => {
28
- return { ...defaults, ...(0, import_utils.compact)(options) };
5
+ let _zag_js_utils = require("@zag-js/utils");
6
+ // src/toast.store.ts
7
+ const withDefaults = (options, defaults) => {
8
+ return {
9
+ ...defaults,
10
+ ...(0, _zag_js_utils.compact)(options)
11
+ };
29
12
  };
30
- var priorities = {
31
- error: [1, 2],
32
- warning: [3, 6],
33
- loading: [4, 5],
34
- success: [5, 7],
35
- info: [6, 8]
13
+ const priorities = {
14
+ error: [1, 2],
15
+ warning: [3, 6],
16
+ loading: [4, 5],
17
+ success: [5, 7],
18
+ info: [6, 8]
36
19
  };
37
- var DEFAULT_TYPE = "info";
38
- var getPriorityForType = (type, hasAction) => {
39
- const key = type ?? DEFAULT_TYPE;
40
- const [actionable, nonActionable] = (0, import_utils.hasProp)(priorities, key) ? priorities[key] : priorities[DEFAULT_TYPE];
41
- return hasAction ? actionable : nonActionable;
20
+ const DEFAULT_TYPE = "info";
21
+ const getPriorityForType = (type, hasAction) => {
22
+ const key = type ?? DEFAULT_TYPE;
23
+ const [actionable, nonActionable] = (0, _zag_js_utils.hasProp)(priorities, key) ? priorities[key] : priorities[DEFAULT_TYPE];
24
+ return hasAction ? actionable : nonActionable;
42
25
  };
43
- var sortToastsByPriority = (toastArray) => {
44
- return toastArray.sort((a, b) => {
45
- const priorityA = a.priority ?? getPriorityForType(a.type, !!a.action);
46
- const priorityB = b.priority ?? getPriorityForType(b.type, !!b.action);
47
- return priorityA - priorityB;
48
- });
26
+ const sortToastsByPriority = (toastArray) => {
27
+ return toastArray.sort((a, b) => {
28
+ return (a.priority ?? getPriorityForType(a.type, !!a.action)) - (b.priority ?? getPriorityForType(b.type, !!b.action));
29
+ });
49
30
  };
50
31
  function createToastStore(props = {}) {
51
- const attrs = withDefaults(props, {
52
- placement: "bottom",
53
- overlap: false,
54
- max: 24,
55
- gap: 16,
56
- offsets: "1rem",
57
- hotkey: ["altKey", "KeyT"],
58
- removeDelay: 200,
59
- pauseOnPageIdle: true
60
- });
61
- let subscribers = [];
62
- let toasts = [];
63
- let dismissedToasts = /* @__PURE__ */ new Set();
64
- let toastQueue = [];
65
- const closingToasts = /* @__PURE__ */ new Set();
66
- const promiseTokens = /* @__PURE__ */ new Map();
67
- let paused = false;
68
- const layoutSubscribers = /* @__PURE__ */ new Set();
69
- const subscribe = (subscriber) => {
70
- subscribers.push(subscriber);
71
- let active = true;
72
- return () => {
73
- if (!active) return;
74
- active = false;
75
- const index = subscribers.indexOf(subscriber);
76
- if (index !== -1) subscribers.splice(index, 1);
77
- };
78
- };
79
- const notifications = [];
80
- let publishing = false;
81
- const publish = (...data) => {
82
- notifications.push(...data);
83
- if (publishing) return data;
84
- publishing = true;
85
- try {
86
- while (notifications.length) {
87
- const next = notifications.shift();
88
- subscribers.slice().forEach((subscriber) => subscriber(next));
89
- }
90
- } finally {
91
- publishing = false;
92
- notifications.length = 0;
93
- }
94
- return data;
95
- };
96
- const addToast = (data) => {
97
- if (toasts.length >= attrs.max) {
98
- toastQueue.push(data);
99
- return;
100
- }
101
- toasts.unshift(data);
102
- publish(data);
103
- };
104
- const processQueue = () => {
105
- toastQueue = sortToastsByPriority(toastQueue);
106
- while (toastQueue.length > 0 && toasts.length < attrs.max) {
107
- const nextToast = toastQueue.shift();
108
- if (nextToast) {
109
- const toast = { ...nextToast, paused: paused || nextToast.paused };
110
- toasts.unshift(toast);
111
- publish(toast);
112
- }
113
- }
114
- };
115
- const create = (data) => {
116
- const id = data.id ?? `toast:${(0, import_utils.uuid)()}`;
117
- const exists = toasts.find((toast) => toast.id === id) ?? toastQueue.find((toast) => toast.id === id);
118
- if (closingToasts.has(id)) return id;
119
- if ((0, import_utils.hasProp)(data, "promise") && data.promise !== exists?.promise) promiseTokens.delete(id);
120
- dismissedToasts.delete(id);
121
- if (exists) {
122
- const next = { ...exists, ...data, id };
123
- if (toasts.some((toast) => toast.id === id)) {
124
- toasts = toasts.map((toast) => toast.id === id ? next : toast);
125
- publish(next);
126
- } else {
127
- toastQueue = toastQueue.map((toast) => toast.id === id ? next : toast);
128
- }
129
- } else {
130
- const newToast = {
131
- id,
132
- duration: attrs.duration,
133
- removeDelay: attrs.removeDelay,
134
- type: DEFAULT_TYPE,
135
- ...data,
136
- gap: attrs.gap,
137
- paused
138
- };
139
- const priority = newToast.priority ?? getPriorityForType(newToast.type, !!newToast.action);
140
- addToast({ ...newToast, priority });
141
- }
142
- return id;
143
- };
144
- const remove = (id) => {
145
- const removed = id == null ? [...toasts, ...toastQueue] : [...toasts, ...toastQueue].filter((toast) => toast.id === id);
146
- const visible = id == null ? toasts : toasts.filter((toast) => toast.id === id);
147
- removed.forEach((toast) => {
148
- dismissedToasts.add(toast.id);
149
- closingToasts.delete(toast.id);
150
- promiseTokens.delete(toast.id);
151
- });
152
- if (id != null) dismissedToasts.add(id);
153
- toasts = id == null ? [] : toasts.filter((toast) => toast.id !== id);
154
- toastQueue = id == null ? [] : toastQueue.filter((toast) => toast.id !== id);
155
- if (id != null && !visible.length) publish({ id, dismiss: true });
156
- publish(...visible.map((toast) => ({ id: toast.id, dismiss: true })));
157
- processQueue();
158
- return id;
159
- };
160
- const error = (data) => {
161
- return create({ ...data, type: "error" });
162
- };
163
- const success = (data) => {
164
- return create({ ...data, type: "success" });
165
- };
166
- const info = (data) => {
167
- return create({ ...data, type: "info" });
168
- };
169
- const warning = (data) => {
170
- return create({ ...data, type: "warning" });
171
- };
172
- const loading = (data) => {
173
- return create({ ...data, type: "loading" });
174
- };
175
- const getVisibleToasts = () => {
176
- return toasts.filter((toast) => !dismissedToasts.has(toast.id));
177
- };
178
- const getCount = () => {
179
- return toasts.length;
180
- };
181
- const promise = (promise2, options, shared = {}) => {
182
- if (!options || !options.loading) {
183
- (0, import_utils.warn)("[zag-js > toast] toaster.promise() requires at least a 'loading' option to be specified");
184
- return;
185
- }
186
- const id = create({
187
- ...shared,
188
- ...options.loading,
189
- promise: promise2,
190
- type: "loading"
191
- });
192
- const token = /* @__PURE__ */ Symbol();
193
- const current = toasts.find((toast) => toast.id === id) ?? toastQueue.find((toast) => toast.id === id);
194
- if (current?.promise === promise2 && !closingToasts.has(id)) promiseTokens.set(id, token);
195
- const isCurrent = () => promiseTokens.get(id) === token && !closingToasts.has(id);
196
- let removable = true;
197
- let result;
198
- const prom = (0, import_utils.runIfFn)(promise2).then(async (response) => {
199
- result = ["resolve", response];
200
- if (isHttpResponse(response) && !response.ok) {
201
- removable = false;
202
- const errorOptions = (0, import_utils.runIfFn)(options.error, `HTTP Error! status: ${response.status}`);
203
- if (isCurrent()) create({ ...shared, ...errorOptions, id, type: "error" });
204
- } else if (options.success !== void 0) {
205
- removable = false;
206
- const successOptions = (0, import_utils.runIfFn)(options.success, response);
207
- if (isCurrent()) create({ ...shared, ...successOptions, id, type: successOptions.type ?? "success" });
208
- }
209
- }).catch(async (error2) => {
210
- result = ["reject", error2];
211
- if (options.error !== void 0) {
212
- removable = false;
213
- const errorOptions = (0, import_utils.runIfFn)(options.error, error2);
214
- if (isCurrent()) create({ ...shared, ...errorOptions, id, type: "error" });
215
- }
216
- }).finally(() => {
217
- if (removable && isCurrent()) {
218
- remove(id);
219
- }
220
- if (promiseTokens.get(id) === token) promiseTokens.delete(id);
221
- options.finally?.();
222
- });
223
- const unwrap = () => new Promise(
224
- (resolve, reject) => prom.then(() => result[0] === "reject" ? reject(result[1]) : resolve(result[1])).catch(reject)
225
- );
226
- return { id, unwrap };
227
- };
228
- const update = (id, data) => {
229
- if (closingToasts.has(id)) return id;
230
- if (typeof data !== "function") return create({ ...data, id });
231
- const current = toasts.find((toast) => toast.id === id) ?? toastQueue.find((toast) => toast.id === id);
232
- if (!current) return id;
233
- const next = { ...data({ ...current }), id };
234
- if (closingToasts.has(id)) return id;
235
- if (toasts.some((toast) => toast.id === id)) return create(next);
236
- if (!toastQueue.some((toast) => toast.id === id)) return id;
237
- return create(next);
238
- };
239
- const changeToasts = (data, id) => {
240
- const changed = [];
241
- toasts = toasts.map((toast) => {
242
- if (id != null && toast.id !== id || closingToasts.has(toast.id)) return toast;
243
- const next = { ...toast, ...data };
244
- changed.push(next);
245
- return next;
246
- });
247
- toastQueue = toastQueue.map((toast) => id == null || toast.id === id ? { ...toast, ...data } : toast);
248
- publish(...changed);
249
- };
250
- const pause = (id) => {
251
- if (id == null) paused = true;
252
- changeToasts({ paused: true }, id);
253
- };
254
- const resume = (id) => {
255
- if (id == null) paused = false;
256
- changeToasts({ paused: false }, id);
257
- };
258
- const dismiss = (id) => {
259
- const queued = toastQueue.filter((toast) => id == null || toast.id === id);
260
- toastQueue = toastQueue.filter((toast) => id != null && toast.id !== id);
261
- queued.forEach((toast) => {
262
- dismissedToasts.add(toast.id);
263
- promiseTokens.delete(toast.id);
264
- });
265
- const changed = toasts.filter((toast) => (id == null || toast.id === id) && !closingToasts.has(toast.id));
266
- changed.forEach((toast) => closingToasts.add(toast.id));
267
- toasts = toasts.map((toast) => closingToasts.has(toast.id) ? { ...toast, message: "DISMISS" } : toast);
268
- publish(...changed.map((toast) => ({ ...toast, message: "DISMISS" })));
269
- };
270
- const isVisible = (id) => {
271
- return !dismissedToasts.has(id) && !!toasts.find((toast) => toast.id === id);
272
- };
273
- const isDismissed = (id) => {
274
- return dismissedToasts.has(id);
275
- };
276
- const subscribeLayout = (subscriber) => {
277
- layoutSubscribers.add(subscriber);
278
- return () => {
279
- layoutSubscribers.delete(subscriber);
280
- };
281
- };
282
- const expand = () => layoutSubscribers.forEach((subscriber) => subscriber(true));
283
- const collapse = () => layoutSubscribers.forEach((subscriber) => subscriber(false));
284
- return {
285
- attrs,
286
- subscribe,
287
- create,
288
- update,
289
- remove,
290
- dismiss,
291
- error,
292
- success,
293
- info,
294
- warning,
295
- loading,
296
- getVisibleToasts,
297
- getCount,
298
- promise,
299
- pause,
300
- resume,
301
- isVisible,
302
- isDismissed,
303
- expand,
304
- collapse,
305
- subscribeLayout
306
- };
32
+ const attrs = withDefaults(props, {
33
+ placement: "bottom",
34
+ overlap: false,
35
+ max: 24,
36
+ gap: 16,
37
+ offsets: "1rem",
38
+ hotkey: ["altKey", "KeyT"],
39
+ removeDelay: 200,
40
+ pauseOnPageIdle: true
41
+ });
42
+ let subscribers = [];
43
+ let toasts = [];
44
+ let dismissedToasts = /* @__PURE__ */ new Set();
45
+ let toastQueue = [];
46
+ const closingToasts = /* @__PURE__ */ new Set();
47
+ const promiseTokens = /* @__PURE__ */ new Map();
48
+ let paused = false;
49
+ const layoutSubscribers = /* @__PURE__ */ new Set();
50
+ const subscribe = (subscriber) => {
51
+ subscribers.push(subscriber);
52
+ let active = true;
53
+ return () => {
54
+ if (!active) return;
55
+ active = false;
56
+ const index = subscribers.indexOf(subscriber);
57
+ if (index !== -1) subscribers.splice(index, 1);
58
+ };
59
+ };
60
+ const notifications = [];
61
+ let publishing = false;
62
+ const publish = (...data) => {
63
+ notifications.push(...data);
64
+ if (publishing) return data;
65
+ publishing = true;
66
+ try {
67
+ while (notifications.length) {
68
+ const next = notifications.shift();
69
+ subscribers.slice().forEach((subscriber) => subscriber(next));
70
+ }
71
+ } finally {
72
+ publishing = false;
73
+ notifications.length = 0;
74
+ }
75
+ return data;
76
+ };
77
+ const addToast = (data) => {
78
+ if (toasts.length >= attrs.max) {
79
+ toastQueue.push(data);
80
+ return;
81
+ }
82
+ toasts.unshift(data);
83
+ publish(data);
84
+ };
85
+ const processQueue = () => {
86
+ toastQueue = sortToastsByPriority(toastQueue);
87
+ while (toastQueue.length > 0 && toasts.length < attrs.max) {
88
+ const nextToast = toastQueue.shift();
89
+ if (nextToast) {
90
+ const toast = {
91
+ ...nextToast,
92
+ paused: paused || nextToast.paused
93
+ };
94
+ toasts.unshift(toast);
95
+ publish(toast);
96
+ }
97
+ }
98
+ };
99
+ const create = (data) => {
100
+ const id = data.id ?? `toast:${(0, _zag_js_utils.uuid)()}`;
101
+ const exists = toasts.find((toast) => toast.id === id) ?? toastQueue.find((toast) => toast.id === id);
102
+ if (closingToasts.has(id)) return id;
103
+ if ((0, _zag_js_utils.hasProp)(data, "promise") && data.promise !== exists?.promise) promiseTokens.delete(id);
104
+ dismissedToasts.delete(id);
105
+ if (exists) {
106
+ const next = {
107
+ ...exists,
108
+ ...data,
109
+ id
110
+ };
111
+ if (toasts.some((toast) => toast.id === id)) {
112
+ toasts = toasts.map((toast) => toast.id === id ? next : toast);
113
+ publish(next);
114
+ } else toastQueue = toastQueue.map((toast) => toast.id === id ? next : toast);
115
+ } else {
116
+ const newToast = {
117
+ id,
118
+ duration: attrs.duration,
119
+ removeDelay: attrs.removeDelay,
120
+ type: DEFAULT_TYPE,
121
+ ...data,
122
+ gap: attrs.gap,
123
+ paused
124
+ };
125
+ const priority = newToast.priority ?? getPriorityForType(newToast.type, !!newToast.action);
126
+ addToast({
127
+ ...newToast,
128
+ priority
129
+ });
130
+ }
131
+ return id;
132
+ };
133
+ const remove = (id) => {
134
+ const removed = id == null ? [...toasts, ...toastQueue] : [...toasts, ...toastQueue].filter((toast) => toast.id === id);
135
+ const visible = id == null ? toasts : toasts.filter((toast) => toast.id === id);
136
+ removed.forEach((toast) => {
137
+ dismissedToasts.add(toast.id);
138
+ closingToasts.delete(toast.id);
139
+ promiseTokens.delete(toast.id);
140
+ });
141
+ if (id != null) dismissedToasts.add(id);
142
+ toasts = id == null ? [] : toasts.filter((toast) => toast.id !== id);
143
+ toastQueue = id == null ? [] : toastQueue.filter((toast) => toast.id !== id);
144
+ if (id != null && !visible.length) publish({
145
+ id,
146
+ dismiss: true
147
+ });
148
+ publish(...visible.map((toast) => ({
149
+ id: toast.id,
150
+ dismiss: true
151
+ })));
152
+ processQueue();
153
+ return id;
154
+ };
155
+ const error = (data) => {
156
+ return create({
157
+ ...data,
158
+ type: "error"
159
+ });
160
+ };
161
+ const success = (data) => {
162
+ return create({
163
+ ...data,
164
+ type: "success"
165
+ });
166
+ };
167
+ const info = (data) => {
168
+ return create({
169
+ ...data,
170
+ type: "info"
171
+ });
172
+ };
173
+ const warning = (data) => {
174
+ return create({
175
+ ...data,
176
+ type: "warning"
177
+ });
178
+ };
179
+ const loading = (data) => {
180
+ return create({
181
+ ...data,
182
+ type: "loading"
183
+ });
184
+ };
185
+ const getVisibleToasts = () => {
186
+ return toasts.filter((toast) => !dismissedToasts.has(toast.id));
187
+ };
188
+ const getCount = () => {
189
+ return toasts.length;
190
+ };
191
+ const promise = (promise, options, shared = {}) => {
192
+ if (!options || !options.loading) {
193
+ (0, _zag_js_utils.warn)("[zag-js > toast] toaster.promise() requires at least a 'loading' option to be specified");
194
+ return;
195
+ }
196
+ const id = create({
197
+ ...shared,
198
+ ...options.loading,
199
+ promise,
200
+ type: "loading"
201
+ });
202
+ const token = Symbol();
203
+ if ((toasts.find((toast) => toast.id === id) ?? toastQueue.find((toast) => toast.id === id))?.promise === promise && !closingToasts.has(id)) promiseTokens.set(id, token);
204
+ const isCurrent = () => promiseTokens.get(id) === token && !closingToasts.has(id);
205
+ let removable = true;
206
+ let result;
207
+ const prom = (0, _zag_js_utils.runIfFn)(promise).then(async (response) => {
208
+ result = ["resolve", response];
209
+ if (isHttpResponse(response) && !response.ok) {
210
+ removable = false;
211
+ const errorOptions = (0, _zag_js_utils.runIfFn)(options.error, `HTTP Error! status: ${response.status}`);
212
+ if (isCurrent()) create({
213
+ ...shared,
214
+ ...errorOptions,
215
+ id,
216
+ type: "error"
217
+ });
218
+ } else if (options.success !== void 0) {
219
+ removable = false;
220
+ const successOptions = (0, _zag_js_utils.runIfFn)(options.success, response);
221
+ if (isCurrent()) create({
222
+ ...shared,
223
+ ...successOptions,
224
+ id,
225
+ type: successOptions.type ?? "success"
226
+ });
227
+ }
228
+ }).catch(async (error) => {
229
+ result = ["reject", error];
230
+ if (options.error !== void 0) {
231
+ removable = false;
232
+ const errorOptions = (0, _zag_js_utils.runIfFn)(options.error, error);
233
+ if (isCurrent()) create({
234
+ ...shared,
235
+ ...errorOptions,
236
+ id,
237
+ type: "error"
238
+ });
239
+ }
240
+ }).finally(() => {
241
+ if (removable && isCurrent()) remove(id);
242
+ if (promiseTokens.get(id) === token) promiseTokens.delete(id);
243
+ options.finally?.();
244
+ });
245
+ const unwrap = () => new Promise((resolve, reject) => prom.then(() => result[0] === "reject" ? reject(result[1]) : resolve(result[1])).catch(reject));
246
+ return {
247
+ id,
248
+ unwrap
249
+ };
250
+ };
251
+ const update = (id, data) => {
252
+ if (closingToasts.has(id)) return id;
253
+ if (typeof data !== "function") return create({
254
+ ...data,
255
+ id
256
+ });
257
+ const current = toasts.find((toast) => toast.id === id) ?? toastQueue.find((toast) => toast.id === id);
258
+ if (!current) return id;
259
+ const next = {
260
+ ...data({ ...current }),
261
+ id
262
+ };
263
+ if (closingToasts.has(id)) return id;
264
+ if (toasts.some((toast) => toast.id === id)) return create(next);
265
+ if (!toastQueue.some((toast) => toast.id === id)) return id;
266
+ return create(next);
267
+ };
268
+ const changeToasts = (data, id) => {
269
+ const changed = [];
270
+ toasts = toasts.map((toast) => {
271
+ if (id != null && toast.id !== id || closingToasts.has(toast.id)) return toast;
272
+ const next = {
273
+ ...toast,
274
+ ...data
275
+ };
276
+ changed.push(next);
277
+ return next;
278
+ });
279
+ toastQueue = toastQueue.map((toast) => id == null || toast.id === id ? {
280
+ ...toast,
281
+ ...data
282
+ } : toast);
283
+ publish(...changed);
284
+ };
285
+ const pause = (id) => {
286
+ if (id == null) paused = true;
287
+ changeToasts({ paused: true }, id);
288
+ };
289
+ const resume = (id) => {
290
+ if (id == null) paused = false;
291
+ changeToasts({ paused: false }, id);
292
+ };
293
+ const dismiss = (id) => {
294
+ const queued = toastQueue.filter((toast) => id == null || toast.id === id);
295
+ toastQueue = toastQueue.filter((toast) => id != null && toast.id !== id);
296
+ queued.forEach((toast) => {
297
+ dismissedToasts.add(toast.id);
298
+ promiseTokens.delete(toast.id);
299
+ });
300
+ const changed = toasts.filter((toast) => (id == null || toast.id === id) && !closingToasts.has(toast.id));
301
+ changed.forEach((toast) => closingToasts.add(toast.id));
302
+ toasts = toasts.map((toast) => closingToasts.has(toast.id) ? {
303
+ ...toast,
304
+ message: "DISMISS"
305
+ } : toast);
306
+ publish(...changed.map((toast) => ({
307
+ ...toast,
308
+ message: "DISMISS"
309
+ })));
310
+ };
311
+ const isVisible = (id) => {
312
+ return !dismissedToasts.has(id) && !!toasts.find((toast) => toast.id === id);
313
+ };
314
+ const isDismissed = (id) => {
315
+ return dismissedToasts.has(id);
316
+ };
317
+ const subscribeLayout = (subscriber) => {
318
+ layoutSubscribers.add(subscriber);
319
+ return () => {
320
+ layoutSubscribers.delete(subscriber);
321
+ };
322
+ };
323
+ const expand = () => layoutSubscribers.forEach((subscriber) => subscriber(true));
324
+ const collapse = () => layoutSubscribers.forEach((subscriber) => subscriber(false));
325
+ return {
326
+ attrs,
327
+ subscribe,
328
+ create,
329
+ update,
330
+ remove,
331
+ dismiss,
332
+ error,
333
+ success,
334
+ info,
335
+ warning,
336
+ loading,
337
+ getVisibleToasts,
338
+ getCount,
339
+ promise,
340
+ pause,
341
+ resume,
342
+ isVisible,
343
+ isDismissed,
344
+ expand,
345
+ collapse,
346
+ subscribeLayout
347
+ };
307
348
  }
308
- var isHttpResponse = (data) => {
309
- return data && typeof data === "object" && "ok" in data && typeof data.ok === "boolean" && "status" in data && typeof data.status === "number";
349
+ const isHttpResponse = (data) => {
350
+ return data && typeof data === "object" && "ok" in data && typeof data.ok === "boolean" && "status" in data && typeof data.status === "number";
310
351
  };
311
- // Annotate the CommonJS export names for ESM import in node:
312
- 0 && (module.exports = {
313
- createToastStore
314
- });
352
+ exports.createToastStore = createToastStore;