@zag-js/toast 1.47.0 → 1.49.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 +10 -17
- package/dist/index.d.ts +10 -17
- package/dist/index.js +18 -45
- package/dist/index.mjs +5 -11
- package/dist/toast-group.connect.d.mts +4 -8
- package/dist/toast-group.connect.d.ts +4 -8
- package/dist/toast-group.connect.js +73 -97
- package/dist/toast-group.connect.mjs +67 -60
- package/dist/toast-group.machine.d.mts +2 -8
- package/dist/toast-group.machine.d.ts +2 -8
- package/dist/toast-group.machine.js +292 -346
- package/dist/toast-group.machine.mjs +286 -309
- package/dist/toast.anatomy.d.mts +2 -6
- package/dist/toast.anatomy.d.ts +2 -6
- package/dist/toast.anatomy.js +8 -40
- package/dist/toast.anatomy.mjs +4 -14
- package/dist/toast.connect.d.mts +4 -8
- package/dist/toast.connect.d.ts +4 -8
- package/dist/toast.connect.js +133 -158
- package/dist/toast.connect.mjs +126 -120
- package/dist/toast.dom.d.mts +19 -23
- package/dist/toast.dom.d.ts +19 -23
- package/dist/toast.dom.js +54 -83
- package/dist/toast.dom.mjs +39 -47
- package/dist/toast.machine.d.mts +2 -8
- package/dist/toast.machine.d.ts +2 -8
- package/dist/toast.machine.js +272 -300
- package/dist/toast.machine.mjs +265 -262
- package/dist/toast.store.d.mts +2 -8
- package/dist/toast.store.d.ts +2 -8
- package/dist/toast.store.js +344 -306
- package/dist/toast.store.mjs +340 -281
- package/dist/toast.types.d.mts +372 -374
- package/dist/toast.types.d.ts +372 -374
- package/dist/toast.types.js +4 -18
- package/dist/toast.types.mjs +1 -0
- package/dist/toast.utils.d.mts +10 -14
- package/dist/toast.utils.d.ts +10 -14
- package/dist/toast.utils.js +167 -217
- package/dist/toast.utils.mjs +157 -186
- package/package.json +9 -9
package/dist/toast.store.js
CHANGED
|
@@ -1,314 +1,352 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
309
|
-
|
|
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
|
-
|
|
312
|
-
0 && (module.exports = {
|
|
313
|
-
createToastStore
|
|
314
|
-
});
|
|
352
|
+
exports.createToastStore = createToastStore;
|