@zag-js/toast 0.0.0-dev-20220413175519 → 0.0.0-dev-20220415160434
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.js +48 -775
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +47 -774
- package/dist/index.mjs.map +3 -3
- package/dist/toast-group.connect.d.ts +2 -2
- package/dist/toast-group.connect.d.ts.map +1 -1
- package/dist/toast.types.d.ts +5 -8
- package/dist/toast.types.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -55,38 +55,12 @@ __export(src_exports, {
|
|
|
55
55
|
});
|
|
56
56
|
module.exports = __toCommonJS(src_exports);
|
|
57
57
|
|
|
58
|
-
// ../../utilities/core/
|
|
59
|
-
function clear(v) {
|
|
60
|
-
while (v.length > 0)
|
|
61
|
-
v.pop();
|
|
62
|
-
return v;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// ../../utilities/core/src/functions.ts
|
|
58
|
+
// ../../utilities/core/dist/index.mjs
|
|
66
59
|
var runIfFn = (v, ...a) => {
|
|
67
60
|
const res = typeof v === "function" ? v(...a) : v;
|
|
68
61
|
return res != null ? res : void 0;
|
|
69
62
|
};
|
|
70
|
-
var cast = (v) => v;
|
|
71
|
-
var noop = () => {
|
|
72
|
-
};
|
|
73
|
-
var uuid = /* @__PURE__ */ (() => {
|
|
74
|
-
let id = 0;
|
|
75
|
-
return () => {
|
|
76
|
-
id++;
|
|
77
|
-
return id.toString(36);
|
|
78
|
-
};
|
|
79
|
-
})();
|
|
80
|
-
|
|
81
|
-
// ../../utilities/core/src/guard.ts
|
|
82
63
|
var isDom = () => !!(typeof window !== "undefined");
|
|
83
|
-
var isArray = (v) => Array.isArray(v);
|
|
84
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
85
|
-
var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
|
|
86
|
-
var isString = (v) => typeof v === "string";
|
|
87
|
-
var isFunction = (v) => typeof v === "function";
|
|
88
|
-
|
|
89
|
-
// ../../utilities/core/src/warning.ts
|
|
90
64
|
function warn(...a) {
|
|
91
65
|
const m = a.length === 1 ? a[0] : a[1];
|
|
92
66
|
const c = a.length === 2 ? a[0] : true;
|
|
@@ -94,721 +68,11 @@ function warn(...a) {
|
|
|
94
68
|
console.warn(m);
|
|
95
69
|
}
|
|
96
70
|
}
|
|
97
|
-
function invariant(...a) {
|
|
98
|
-
const m = a.length === 1 ? a[0] : a[1];
|
|
99
|
-
const c = a.length === 2 ? a[0] : true;
|
|
100
|
-
if (c && void 0 !== "production") {
|
|
101
|
-
throw new Error(m);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ../../../node_modules/@zag-js/core/src/index.ts
|
|
106
|
-
var import_vanilla3 = require("valtio/vanilla");
|
|
107
|
-
|
|
108
|
-
// ../../core/src/action-utils.ts
|
|
109
|
-
function isGuardHelper(value) {
|
|
110
|
-
return isObject(value) && value.predicate != null;
|
|
111
|
-
}
|
|
112
|
-
function determineActionsFn(values, guardMap) {
|
|
113
|
-
return (context, event) => {
|
|
114
|
-
if (isGuardHelper(values))
|
|
115
|
-
return values.predicate(guardMap != null ? guardMap : {})(context, event);
|
|
116
|
-
return values;
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// ../../core/src/guard-utils.ts
|
|
121
|
-
function or(...conditions) {
|
|
122
|
-
return {
|
|
123
|
-
predicate: (guards2) => (ctx, event) => conditions.map((condition) => {
|
|
124
|
-
var _a;
|
|
125
|
-
if (isString(condition)) {
|
|
126
|
-
return !!((_a = guards2[condition]) == null ? void 0 : _a.call(guards2, ctx, event));
|
|
127
|
-
}
|
|
128
|
-
if (isFunction(condition)) {
|
|
129
|
-
return condition(ctx, event);
|
|
130
|
-
}
|
|
131
|
-
return condition.predicate(guards2)(ctx, event);
|
|
132
|
-
}).some(Boolean)
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
function and(...conditions) {
|
|
136
|
-
return {
|
|
137
|
-
predicate: (guards2) => (ctx, event) => conditions.map((condition) => {
|
|
138
|
-
var _a;
|
|
139
|
-
if (isString(condition)) {
|
|
140
|
-
return !!((_a = guards2[condition]) == null ? void 0 : _a.call(guards2, ctx, event));
|
|
141
|
-
}
|
|
142
|
-
if (isFunction(condition)) {
|
|
143
|
-
return condition(ctx, event);
|
|
144
|
-
}
|
|
145
|
-
return condition.predicate(guards2)(ctx, event);
|
|
146
|
-
}).every(Boolean)
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function not(condition) {
|
|
150
|
-
return {
|
|
151
|
-
predicate: (guardMap) => (ctx, event) => {
|
|
152
|
-
var _a;
|
|
153
|
-
if (isString(condition)) {
|
|
154
|
-
return !((_a = guardMap[condition]) == null ? void 0 : _a.call(guardMap, ctx, event));
|
|
155
|
-
}
|
|
156
|
-
if (isFunction(condition)) {
|
|
157
|
-
return !condition(ctx, event);
|
|
158
|
-
}
|
|
159
|
-
return !condition.predicate(guardMap)(ctx, event);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
var guards = { or, and, not };
|
|
164
|
-
function isGuardHelper2(value) {
|
|
165
|
-
return isObject(value) && value.predicate != null;
|
|
166
|
-
}
|
|
167
|
-
var TruthyGuard = () => true;
|
|
168
|
-
function determineGuardFn(guard, guardMap) {
|
|
169
|
-
guard = guard != null ? guard : TruthyGuard;
|
|
170
|
-
return (context, event) => {
|
|
171
|
-
if (isString(guard)) {
|
|
172
|
-
const value = guardMap == null ? void 0 : guardMap[guard];
|
|
173
|
-
return isFunction(value) ? value(context, event) : value;
|
|
174
|
-
}
|
|
175
|
-
if (isGuardHelper2(guard)) {
|
|
176
|
-
return guard.predicate(guardMap != null ? guardMap : {})(context, event);
|
|
177
|
-
}
|
|
178
|
-
return guard == null ? void 0 : guard(context, event);
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// ../../../node_modules/klona/json/index.mjs
|
|
183
|
-
function klona(val) {
|
|
184
|
-
var k, out, tmp;
|
|
185
|
-
if (Array.isArray(val)) {
|
|
186
|
-
out = Array(k = val.length);
|
|
187
|
-
while (k--)
|
|
188
|
-
out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
|
|
189
|
-
return out;
|
|
190
|
-
}
|
|
191
|
-
if (Object.prototype.toString.call(val) === "[object Object]") {
|
|
192
|
-
out = {};
|
|
193
|
-
for (k in val) {
|
|
194
|
-
if (k === "__proto__") {
|
|
195
|
-
Object.defineProperty(out, k, {
|
|
196
|
-
value: klona(val[k]),
|
|
197
|
-
configurable: true,
|
|
198
|
-
enumerable: true,
|
|
199
|
-
writable: true
|
|
200
|
-
});
|
|
201
|
-
} else {
|
|
202
|
-
out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return out;
|
|
206
|
-
}
|
|
207
|
-
return val;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// ../../core/src/machine.ts
|
|
211
|
-
var import_utils9 = require("valtio/utils");
|
|
212
|
-
var import_vanilla2 = require("valtio/vanilla");
|
|
213
|
-
|
|
214
|
-
// ../../core/src/create-proxy.ts
|
|
215
|
-
var import_vanilla = require("valtio/vanilla");
|
|
216
|
-
function createProxy(config) {
|
|
217
|
-
var _a;
|
|
218
|
-
const state = (0, import_vanilla.proxy)({
|
|
219
|
-
value: "",
|
|
220
|
-
previousValue: "",
|
|
221
|
-
event: cast({}),
|
|
222
|
-
context: (_a = config.context) != null ? _a : cast({}),
|
|
223
|
-
done: false,
|
|
224
|
-
tags: [],
|
|
225
|
-
hasTag(tag) {
|
|
226
|
-
return this.tags.includes(tag);
|
|
227
|
-
},
|
|
228
|
-
matches(...value) {
|
|
229
|
-
return value.includes(this.value);
|
|
230
|
-
},
|
|
231
|
-
can(event) {
|
|
232
|
-
return cast(this).nextEvents.includes(event);
|
|
233
|
-
},
|
|
234
|
-
get nextEvents() {
|
|
235
|
-
var _a2, _b, _c, _d;
|
|
236
|
-
const stateEvents = (_c = (_b = (_a2 = config.states) == null ? void 0 : _a2[this.value]) == null ? void 0 : _b["on"]) != null ? _c : {};
|
|
237
|
-
const globalEvents = (_d = config == null ? void 0 : config.on) != null ? _d : {};
|
|
238
|
-
return Object.keys(__spreadValues(__spreadValues({}, stateEvents), globalEvents));
|
|
239
|
-
},
|
|
240
|
-
get changed() {
|
|
241
|
-
if (this.event.value === "machine.init" /* Init */ || !this.previousValue)
|
|
242
|
-
return false;
|
|
243
|
-
return this.value !== this.previousValue;
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
return cast(state);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// ../../core/src/delay-utils.ts
|
|
250
|
-
function determineDelayFn(delay, delaysMap) {
|
|
251
|
-
return (context, event) => {
|
|
252
|
-
if (isNumber(delay))
|
|
253
|
-
return delay;
|
|
254
|
-
if (isFunction(delay)) {
|
|
255
|
-
return delay(context, event);
|
|
256
|
-
}
|
|
257
|
-
if (isString(delay)) {
|
|
258
|
-
const value = Number.parseFloat(delay);
|
|
259
|
-
if (!Number.isNaN(value)) {
|
|
260
|
-
return value;
|
|
261
|
-
}
|
|
262
|
-
if (delaysMap) {
|
|
263
|
-
const valueOrFn = delaysMap == null ? void 0 : delaysMap[delay];
|
|
264
|
-
if (valueOrFn == null) {
|
|
265
|
-
const msg = `[machine] Cannot determine delay for ${delay}. It doesn't exist in options.delays`;
|
|
266
|
-
throw new Error(msg);
|
|
267
|
-
}
|
|
268
|
-
return isFunction(valueOrFn) ? valueOrFn(context, event) : valueOrFn;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// ../../core/src/utils.ts
|
|
275
|
-
function toEvent(event) {
|
|
276
|
-
const obj = isString(event) ? { type: event } : event;
|
|
277
|
-
return obj;
|
|
278
|
-
}
|
|
279
|
-
function toArray(value) {
|
|
280
|
-
if (!value)
|
|
281
|
-
return [];
|
|
282
|
-
return isArray(value) ? value : [value];
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// ../../core/src/transition-utils.ts
|
|
286
|
-
function toTarget(target) {
|
|
287
|
-
return isString(target) ? { target } : target;
|
|
288
|
-
}
|
|
289
|
-
function determineTransitionFn(transitions, guardMap) {
|
|
290
|
-
return (context, event) => {
|
|
291
|
-
return toArray(transitions).map(toTarget).find((transition) => {
|
|
292
|
-
var _a;
|
|
293
|
-
const determineGuard = determineGuardFn(transition.guard, guardMap);
|
|
294
|
-
const guard = determineGuard(context, event);
|
|
295
|
-
return (_a = guard != null ? guard : transition.target) != null ? _a : transition.actions;
|
|
296
|
-
});
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
function toTransition(transition, current) {
|
|
300
|
-
const _transition = isString(transition) ? toTarget(transition) : transition;
|
|
301
|
-
const fn = (t2) => {
|
|
302
|
-
const isTargetless = t2.actions && !t2.target;
|
|
303
|
-
if (isTargetless && current)
|
|
304
|
-
t2.target = current;
|
|
305
|
-
return t2;
|
|
306
|
-
};
|
|
307
|
-
if (isArray(_transition)) {
|
|
308
|
-
return _transition.map(fn);
|
|
309
|
-
}
|
|
310
|
-
if (isObject(_transition)) {
|
|
311
|
-
return fn(cast(_transition));
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
71
|
|
|
315
|
-
//
|
|
316
|
-
var
|
|
317
|
-
constructor(config, options) {
|
|
318
|
-
this.config = config;
|
|
319
|
-
this.status = "Not Started" /* NotStarted */;
|
|
320
|
-
this.type = "machine" /* Machine */;
|
|
321
|
-
this.activityEvents = /* @__PURE__ */ new Map();
|
|
322
|
-
this.delayedEvents = /* @__PURE__ */ new Map();
|
|
323
|
-
this.stateListeners = /* @__PURE__ */ new Set();
|
|
324
|
-
this.eventListeners = /* @__PURE__ */ new Set();
|
|
325
|
-
this.doneListeners = /* @__PURE__ */ new Set();
|
|
326
|
-
this.contextWatchers = /* @__PURE__ */ new Set();
|
|
327
|
-
this.removeStateListener = noop;
|
|
328
|
-
this.removeEventListener = noop;
|
|
329
|
-
this.children = /* @__PURE__ */ new Map();
|
|
330
|
-
this.start = (init) => {
|
|
331
|
-
if (this.status === "Running" /* Running */) {
|
|
332
|
-
return this;
|
|
333
|
-
}
|
|
334
|
-
this.status = "Running" /* Running */;
|
|
335
|
-
const event = toEvent("machine.init" /* Init */);
|
|
336
|
-
if (init) {
|
|
337
|
-
const resolved = isObject(init) ? init : { context: this.config.context, value: init };
|
|
338
|
-
this.setState(resolved.value);
|
|
339
|
-
this.setContext(resolved.context);
|
|
340
|
-
}
|
|
341
|
-
const transition = {
|
|
342
|
-
target: !!init ? void 0 : this.config.initial
|
|
343
|
-
};
|
|
344
|
-
const info = this.getNextStateInfo(transition, event);
|
|
345
|
-
info.target = cast(info.target || transition.target);
|
|
346
|
-
this.initialState = info;
|
|
347
|
-
this.performStateChangeEffects(info.target, info, event);
|
|
348
|
-
this.removeStateListener = (0, import_vanilla2.subscribe)(this.state, () => {
|
|
349
|
-
this.stateListeners.forEach((listener) => {
|
|
350
|
-
listener(this.stateSnapshot);
|
|
351
|
-
});
|
|
352
|
-
}, this.sync);
|
|
353
|
-
this.removeEventListener = (0, import_utils9.subscribeKey)(this.state, "event", (value) => {
|
|
354
|
-
if (this.config.onEvent) {
|
|
355
|
-
this.executeActions(this.config.onEvent, value);
|
|
356
|
-
}
|
|
357
|
-
for (const listener of this.eventListeners) {
|
|
358
|
-
listener(value);
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
this.setupContextWatchers();
|
|
362
|
-
this.executeActivities(toEvent("machine.start" /* Start */), toArray(this.config.activities), "machine.start" /* Start */);
|
|
363
|
-
this.executeActions(this.config.entry, toEvent("machine.start" /* Start */));
|
|
364
|
-
return this;
|
|
365
|
-
};
|
|
366
|
-
this.setupContextWatchers = () => {
|
|
367
|
-
var _a;
|
|
368
|
-
for (const [key, fn] of Object.entries((_a = this.config.watch) != null ? _a : {})) {
|
|
369
|
-
this.contextWatchers.add((0, import_utils9.subscribeKey)(this.state.context, key, () => {
|
|
370
|
-
this.executeActions(fn, this.state.event);
|
|
371
|
-
}));
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
this.setupComputed = () => {
|
|
375
|
-
var _a;
|
|
376
|
-
const computed = cast((_a = this.config.computed) != null ? _a : {});
|
|
377
|
-
const deriveFns = Object.fromEntries(Object.entries(computed).map(([key, fn]) => [key, (get) => fn(get(this.state.context))]));
|
|
378
|
-
(0, import_utils9.derive)(deriveFns, { proxy: this.state.context });
|
|
379
|
-
};
|
|
380
|
-
this.detachComputed = () => {
|
|
381
|
-
(0, import_utils9.underive)(this.state.context, { delete: true });
|
|
382
|
-
};
|
|
383
|
-
this.stop = () => {
|
|
384
|
-
if (this.status === "Stopped" /* Stopped */)
|
|
385
|
-
return;
|
|
386
|
-
this.setState(null);
|
|
387
|
-
this.setEvent("machine.stop" /* Stop */);
|
|
388
|
-
if (this.config.context) {
|
|
389
|
-
this.setContext(this.config.context);
|
|
390
|
-
}
|
|
391
|
-
this.stopStateListeners();
|
|
392
|
-
this.stopChildren();
|
|
393
|
-
this.stopActivities();
|
|
394
|
-
this.stopDelayedEvents();
|
|
395
|
-
this.stopContextWatchers();
|
|
396
|
-
this.stopEventListeners();
|
|
397
|
-
this.detachComputed();
|
|
398
|
-
this.status = "Stopped" /* Stopped */;
|
|
399
|
-
this.executeActions(this.config.exit, toEvent("machine.stop" /* Stop */));
|
|
400
|
-
return this;
|
|
401
|
-
};
|
|
402
|
-
this.stopEventListeners = () => {
|
|
403
|
-
this.eventListeners.clear();
|
|
404
|
-
this.removeEventListener();
|
|
405
|
-
};
|
|
406
|
-
this.stopStateListeners = () => {
|
|
407
|
-
this.removeStateListener();
|
|
408
|
-
this.stateListeners.clear();
|
|
409
|
-
};
|
|
410
|
-
this.stopContextWatchers = () => {
|
|
411
|
-
this.contextWatchers.forEach((fn) => fn());
|
|
412
|
-
this.contextWatchers.clear();
|
|
413
|
-
};
|
|
414
|
-
this.stopDelayedEvents = () => {
|
|
415
|
-
this.delayedEvents.forEach((state) => {
|
|
416
|
-
state.forEach((stop) => stop());
|
|
417
|
-
});
|
|
418
|
-
this.delayedEvents.clear();
|
|
419
|
-
};
|
|
420
|
-
this.stopActivities = (state) => {
|
|
421
|
-
var _a, _b;
|
|
422
|
-
if (state) {
|
|
423
|
-
(_a = this.activityEvents.get(state)) == null ? void 0 : _a.forEach((stop) => stop());
|
|
424
|
-
(_b = this.activityEvents.get(state)) == null ? void 0 : _b.clear();
|
|
425
|
-
this.activityEvents.delete(state);
|
|
426
|
-
} else {
|
|
427
|
-
this.activityEvents.forEach((state2) => {
|
|
428
|
-
state2.forEach((stop) => stop());
|
|
429
|
-
state2.clear();
|
|
430
|
-
});
|
|
431
|
-
this.activityEvents.clear();
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
this.sendChild = (evt, to) => {
|
|
435
|
-
const event = toEvent(evt);
|
|
436
|
-
const id = runIfFn(to, this.contextSnapshot);
|
|
437
|
-
const child = this.children.get(id);
|
|
438
|
-
if (!child) {
|
|
439
|
-
invariant(`[machine/send-child] Cannot send '${event.type}' event to unknown child`);
|
|
440
|
-
}
|
|
441
|
-
child.send(event);
|
|
442
|
-
};
|
|
443
|
-
this.stopChild = (id) => {
|
|
444
|
-
if (!this.children.has(id)) {
|
|
445
|
-
invariant("[machine/stop-child] Cannot stop unknown child");
|
|
446
|
-
}
|
|
447
|
-
this.children.get(id).stop();
|
|
448
|
-
this.children.delete(id);
|
|
449
|
-
};
|
|
450
|
-
this.removeChild = (id) => {
|
|
451
|
-
this.children.delete(id);
|
|
452
|
-
};
|
|
453
|
-
this.stopChildren = () => {
|
|
454
|
-
this.children.forEach((child) => child.stop());
|
|
455
|
-
this.children.clear();
|
|
456
|
-
};
|
|
457
|
-
this.setParent = (parent) => {
|
|
458
|
-
this.parent = parent;
|
|
459
|
-
};
|
|
460
|
-
this.spawn = (src, id) => {
|
|
461
|
-
const actor = runIfFn(src);
|
|
462
|
-
if (id)
|
|
463
|
-
actor.id = id;
|
|
464
|
-
actor.type = "machine.actor" /* Actor */;
|
|
465
|
-
actor.setParent(this);
|
|
466
|
-
this.children.set(actor.id, cast(actor));
|
|
467
|
-
actor.onDone(() => {
|
|
468
|
-
this.removeChild(actor.id);
|
|
469
|
-
}).start();
|
|
470
|
-
return cast((0, import_vanilla2.ref)(actor));
|
|
471
|
-
};
|
|
472
|
-
this.addActivityCleanup = (state, cleanup) => {
|
|
473
|
-
var _a;
|
|
474
|
-
if (!state)
|
|
475
|
-
return;
|
|
476
|
-
if (!this.activityEvents.has(state)) {
|
|
477
|
-
this.activityEvents.set(state, /* @__PURE__ */ new Set([cleanup]));
|
|
478
|
-
} else {
|
|
479
|
-
(_a = this.activityEvents.get(state)) == null ? void 0 : _a.add(cleanup);
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
this.setState = (target) => {
|
|
483
|
-
this.state.previousValue = this.state.value;
|
|
484
|
-
this.state.value = target;
|
|
485
|
-
const stateNode = this.getStateNode(target);
|
|
486
|
-
if (target == null) {
|
|
487
|
-
clear(this.state.tags);
|
|
488
|
-
} else {
|
|
489
|
-
this.state.tags = toArray(stateNode == null ? void 0 : stateNode.tags);
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
this.setContext = (context) => {
|
|
493
|
-
for (const key in context) {
|
|
494
|
-
this.state.context[key] = context[key];
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
this.withContext = (context) => {
|
|
498
|
-
this.detachComputed();
|
|
499
|
-
const newContext = __spreadValues(__spreadValues({}, this.config.context), context);
|
|
500
|
-
return new Machine(__spreadProps(__spreadValues({}, this.config), { context: newContext }), this.options);
|
|
501
|
-
};
|
|
502
|
-
this.withOptions = (options) => {
|
|
503
|
-
this.detachComputed();
|
|
504
|
-
return new Machine(this.config, __spreadValues(__spreadValues({}, this.options), options));
|
|
505
|
-
};
|
|
506
|
-
this.setActions = (actions) => {
|
|
507
|
-
this.actionMap = __spreadValues(__spreadValues({}, this.actionMap), actions);
|
|
508
|
-
};
|
|
509
|
-
this.clone = () => {
|
|
510
|
-
this.detachComputed();
|
|
511
|
-
return new Machine(this.config, this.options);
|
|
512
|
-
};
|
|
513
|
-
this.getStateNode = (state) => {
|
|
514
|
-
var _a;
|
|
515
|
-
if (!state)
|
|
516
|
-
return;
|
|
517
|
-
return (_a = this.config.states) == null ? void 0 : _a[state];
|
|
518
|
-
};
|
|
519
|
-
this.getNextStateInfo = (transitions, event) => {
|
|
520
|
-
var _a;
|
|
521
|
-
const transition = this.determineTransition(transitions, event);
|
|
522
|
-
const target = (_a = transition == null ? void 0 : transition.target) != null ? _a : this.state.value;
|
|
523
|
-
const stateNode = this.getStateNode(target);
|
|
524
|
-
return {
|
|
525
|
-
transition,
|
|
526
|
-
stateNode,
|
|
527
|
-
target
|
|
528
|
-
};
|
|
529
|
-
};
|
|
530
|
-
this.getActionFromDelayedTransition = (transition) => {
|
|
531
|
-
const event = toEvent("machine.after" /* After */);
|
|
532
|
-
const determineDelay = determineDelayFn(transition.delay, this.delayMap);
|
|
533
|
-
const delay = determineDelay(this.contextSnapshot, event);
|
|
534
|
-
let id;
|
|
535
|
-
return {
|
|
536
|
-
entry: () => {
|
|
537
|
-
id = globalThis.setTimeout(() => {
|
|
538
|
-
const current = this.state.value;
|
|
539
|
-
const next = this.getNextStateInfo(transition, event);
|
|
540
|
-
this.performStateChangeEffects(current, next, event);
|
|
541
|
-
}, delay);
|
|
542
|
-
},
|
|
543
|
-
exit: () => {
|
|
544
|
-
globalThis.clearTimeout(id);
|
|
545
|
-
}
|
|
546
|
-
};
|
|
547
|
-
};
|
|
548
|
-
this.getDelayedEventActions = (state) => {
|
|
549
|
-
const stateNode = this.getStateNode(state);
|
|
550
|
-
const event = toEvent("machine.after" /* After */);
|
|
551
|
-
if (!stateNode || !stateNode.after)
|
|
552
|
-
return;
|
|
553
|
-
const entries = [];
|
|
554
|
-
const exits = [];
|
|
555
|
-
if (isArray(stateNode.after)) {
|
|
556
|
-
const transition = this.determineTransition(stateNode.after, event);
|
|
557
|
-
if (!transition)
|
|
558
|
-
return;
|
|
559
|
-
const actions = this.getActionFromDelayedTransition(transition);
|
|
560
|
-
entries.push(actions.entry);
|
|
561
|
-
exits.push(actions.exit);
|
|
562
|
-
} else if (isObject(stateNode.after)) {
|
|
563
|
-
for (const delay in stateNode.after) {
|
|
564
|
-
const transition = stateNode.after[delay];
|
|
565
|
-
let resolvedTransition = {};
|
|
566
|
-
if (isArray(transition)) {
|
|
567
|
-
const picked = this.determineTransition(transition, event);
|
|
568
|
-
if (picked)
|
|
569
|
-
resolvedTransition = picked;
|
|
570
|
-
} else if (isString(transition)) {
|
|
571
|
-
resolvedTransition = { target: transition, delay };
|
|
572
|
-
} else {
|
|
573
|
-
resolvedTransition = __spreadProps(__spreadValues({}, transition), { delay });
|
|
574
|
-
}
|
|
575
|
-
const actions = this.getActionFromDelayedTransition(resolvedTransition);
|
|
576
|
-
entries.push(actions.entry);
|
|
577
|
-
exits.push(actions.exit);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return { entries, exits };
|
|
581
|
-
};
|
|
582
|
-
this.executeActions = (actions, event) => {
|
|
583
|
-
var _a;
|
|
584
|
-
const _actions = determineActionsFn(actions, this.guardMap)(this.contextSnapshot, event);
|
|
585
|
-
for (const action of toArray(_actions)) {
|
|
586
|
-
const fn = isString(action) ? (_a = this.actionMap) == null ? void 0 : _a[action] : action;
|
|
587
|
-
warn(isString(action) && !fn, `[machine/exec-action] No implementation found for action: \`${action}\``);
|
|
588
|
-
fn == null ? void 0 : fn(this.state.context, event, this.meta);
|
|
589
|
-
}
|
|
590
|
-
};
|
|
591
|
-
this.executeActivities = (event, activities, state) => {
|
|
592
|
-
var _a;
|
|
593
|
-
for (const activity of activities) {
|
|
594
|
-
const fn = isString(activity) ? (_a = this.activityMap) == null ? void 0 : _a[activity] : activity;
|
|
595
|
-
if (!fn) {
|
|
596
|
-
warn(`[machine/exec-activity] No implementation found for activity: \`${activity}\``);
|
|
597
|
-
continue;
|
|
598
|
-
}
|
|
599
|
-
const cleanup = fn(this.state.context, event, this.meta);
|
|
600
|
-
if (cleanup) {
|
|
601
|
-
this.addActivityCleanup(state != null ? state : this.state.value, cleanup);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
this.createEveryActivities = (every, callbackfn) => {
|
|
606
|
-
if (!every)
|
|
607
|
-
return;
|
|
608
|
-
const event = toEvent("machine.every" /* Every */);
|
|
609
|
-
if (isArray(every)) {
|
|
610
|
-
const picked = toArray(every).find((t2) => {
|
|
611
|
-
const determineDelay2 = determineDelayFn(t2.delay, this.delayMap);
|
|
612
|
-
t2.delay = determineDelay2(this.contextSnapshot, event);
|
|
613
|
-
const determineGuard = determineGuardFn(t2.guard, this.guardMap);
|
|
614
|
-
const guard = determineGuard(this.contextSnapshot, event);
|
|
615
|
-
return guard != null ? guard : t2.delay;
|
|
616
|
-
});
|
|
617
|
-
if (!picked)
|
|
618
|
-
return;
|
|
619
|
-
const determineDelay = determineDelayFn(picked.delay, this.delayMap);
|
|
620
|
-
const delay = determineDelay(this.contextSnapshot, event);
|
|
621
|
-
const activity = () => {
|
|
622
|
-
const id = globalThis.setInterval(() => {
|
|
623
|
-
this.executeActions(picked.actions, event);
|
|
624
|
-
}, delay);
|
|
625
|
-
return () => {
|
|
626
|
-
globalThis.clearInterval(id);
|
|
627
|
-
};
|
|
628
|
-
};
|
|
629
|
-
callbackfn(activity);
|
|
630
|
-
} else {
|
|
631
|
-
for (const interval in every) {
|
|
632
|
-
const actions = every == null ? void 0 : every[interval];
|
|
633
|
-
const determineDelay = determineDelayFn(interval, this.delayMap);
|
|
634
|
-
const delay = determineDelay(this.contextSnapshot, event);
|
|
635
|
-
const activity = () => {
|
|
636
|
-
const id = globalThis.setInterval(() => {
|
|
637
|
-
this.executeActions(actions, event);
|
|
638
|
-
}, delay);
|
|
639
|
-
return () => {
|
|
640
|
-
globalThis.clearInterval(id);
|
|
641
|
-
};
|
|
642
|
-
};
|
|
643
|
-
callbackfn(activity);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
this.setEvent = (event) => {
|
|
648
|
-
this.state.event = (0, import_vanilla2.ref)(toEvent(event));
|
|
649
|
-
};
|
|
650
|
-
this.performExitEffects = (current, event) => {
|
|
651
|
-
const currentState = this.state.value;
|
|
652
|
-
const stateNode = current ? this.getStateNode(current) : void 0;
|
|
653
|
-
this.stopActivities(currentState);
|
|
654
|
-
const _exit = determineActionsFn(stateNode == null ? void 0 : stateNode.exit, this.guardMap)(this.contextSnapshot, event);
|
|
655
|
-
const exitActions = toArray(_exit);
|
|
656
|
-
const afterExitActions = this.delayedEvents.get(currentState);
|
|
657
|
-
if (afterExitActions) {
|
|
658
|
-
exitActions.push(...afterExitActions);
|
|
659
|
-
}
|
|
660
|
-
this.executeActions(exitActions, event);
|
|
661
|
-
this.eventListeners.clear();
|
|
662
|
-
};
|
|
663
|
-
this.performEntryEffects = (next, event) => {
|
|
664
|
-
const stateNode = this.getStateNode(next);
|
|
665
|
-
const activities = toArray(stateNode == null ? void 0 : stateNode.activities);
|
|
666
|
-
this.createEveryActivities(stateNode == null ? void 0 : stateNode.every, (activity) => {
|
|
667
|
-
activities.unshift(activity);
|
|
668
|
-
});
|
|
669
|
-
if (activities.length > 0) {
|
|
670
|
-
this.executeActivities(event, activities);
|
|
671
|
-
}
|
|
672
|
-
const _entry = determineActionsFn(stateNode == null ? void 0 : stateNode.entry, this.guardMap)(this.contextSnapshot, event);
|
|
673
|
-
const entryActions = toArray(_entry);
|
|
674
|
-
const afterActions = this.getDelayedEventActions(next);
|
|
675
|
-
if ((stateNode == null ? void 0 : stateNode.after) && afterActions) {
|
|
676
|
-
this.delayedEvents.set(next, afterActions == null ? void 0 : afterActions.exits);
|
|
677
|
-
entryActions.push(...afterActions.entries);
|
|
678
|
-
}
|
|
679
|
-
this.executeActions(entryActions, event);
|
|
680
|
-
if ((stateNode == null ? void 0 : stateNode.type) === "final") {
|
|
681
|
-
this.state.done = true;
|
|
682
|
-
this.doneListeners.forEach((listener) => {
|
|
683
|
-
listener(this.stateSnapshot);
|
|
684
|
-
});
|
|
685
|
-
this.stop();
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
|
-
this.performTransitionEffects = (transition, event) => {
|
|
689
|
-
const t2 = this.determineTransition(transition, event);
|
|
690
|
-
this.executeActions(t2 == null ? void 0 : t2.actions, event);
|
|
691
|
-
};
|
|
692
|
-
this.performStateChangeEffects = (current, next, event) => {
|
|
693
|
-
var _a, _b;
|
|
694
|
-
this.setEvent(event);
|
|
695
|
-
next.target = (_b = (_a = next.target) != null ? _a : this.state.value) != null ? _b : void 0;
|
|
696
|
-
const ok = next.target && next.target !== this.state.value;
|
|
697
|
-
if (ok) {
|
|
698
|
-
this.performExitEffects(current, event);
|
|
699
|
-
}
|
|
700
|
-
this.performTransitionEffects(next == null ? void 0 : next.transition, event);
|
|
701
|
-
this.setState(next.target);
|
|
702
|
-
if (ok) {
|
|
703
|
-
this.performEntryEffects(next.target, event);
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
this.determineTransition = (transition, event) => {
|
|
707
|
-
const fn = determineTransitionFn(transition, this.guardMap);
|
|
708
|
-
return fn == null ? void 0 : fn(this.contextSnapshot, event);
|
|
709
|
-
};
|
|
710
|
-
this.sendParent = (evt) => {
|
|
711
|
-
var _a;
|
|
712
|
-
if (!this.parent) {
|
|
713
|
-
invariant("[machine/send-parent] Cannot send event to an unknown parent");
|
|
714
|
-
}
|
|
715
|
-
const event = toEvent(evt);
|
|
716
|
-
(_a = this.parent) == null ? void 0 : _a.send(event);
|
|
717
|
-
};
|
|
718
|
-
this.send = (evt) => {
|
|
719
|
-
const event = toEvent(evt);
|
|
720
|
-
this.transition(this.state.value, event);
|
|
721
|
-
};
|
|
722
|
-
this.transition = (state, evt) => {
|
|
723
|
-
var _a, _b, _c;
|
|
724
|
-
const stateNode = isString(state) ? this.getStateNode(state) : state == null ? void 0 : state.stateNode;
|
|
725
|
-
const event = toEvent(evt);
|
|
726
|
-
if (!stateNode && !this.config.on) {
|
|
727
|
-
const msg = this.status === "Stopped" /* Stopped */ ? "[machine/transition] Cannot transition a stopped machine" : "[machine/transition] State does not have a definition";
|
|
728
|
-
warn(msg);
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
const transitionConfig = (_c = (_a = stateNode == null ? void 0 : stateNode.on) == null ? void 0 : _a[event.type]) != null ? _c : (_b = this.config.on) == null ? void 0 : _b[event.type];
|
|
732
|
-
const transition = toTransition(transitionConfig, this.state.value);
|
|
733
|
-
if (!transition)
|
|
734
|
-
return;
|
|
735
|
-
const info = this.getNextStateInfo(transition, event);
|
|
736
|
-
this.performStateChangeEffects(this.state.value, info, event);
|
|
737
|
-
return info.stateNode;
|
|
738
|
-
};
|
|
739
|
-
this.subscribe = (listener) => {
|
|
740
|
-
this.stateListeners.add(listener);
|
|
741
|
-
if (this.status === "Running" /* Running */) {
|
|
742
|
-
listener(this.stateSnapshot);
|
|
743
|
-
}
|
|
744
|
-
return () => {
|
|
745
|
-
this.stateListeners.delete(listener);
|
|
746
|
-
};
|
|
747
|
-
};
|
|
748
|
-
this.onDone = (listener) => {
|
|
749
|
-
this.doneListeners.add(listener);
|
|
750
|
-
return this;
|
|
751
|
-
};
|
|
752
|
-
this.onTransition = (listener) => {
|
|
753
|
-
this.stateListeners.add(listener);
|
|
754
|
-
if (this.status === "Running" /* Running */) {
|
|
755
|
-
listener(this.stateSnapshot);
|
|
756
|
-
}
|
|
757
|
-
return this;
|
|
758
|
-
};
|
|
759
|
-
this.onEvent = (listener) => {
|
|
760
|
-
listener(this.state.event);
|
|
761
|
-
this.eventListeners.add(listener);
|
|
762
|
-
return this;
|
|
763
|
-
};
|
|
764
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
765
|
-
this.options = klona(options);
|
|
766
|
-
this.id = (_a = config.id) != null ? _a : `machine-${uuid()}`;
|
|
767
|
-
this.guardMap = (_c = (_b = this.options) == null ? void 0 : _b.guards) != null ? _c : {};
|
|
768
|
-
this.actionMap = (_e = (_d = this.options) == null ? void 0 : _d.actions) != null ? _e : {};
|
|
769
|
-
this.delayMap = (_g = (_f = this.options) == null ? void 0 : _f.delays) != null ? _g : {};
|
|
770
|
-
this.activityMap = (_i = (_h = this.options) == null ? void 0 : _h.activities) != null ? _i : {};
|
|
771
|
-
this.sync = (_k = (_j = this.options) == null ? void 0 : _j.sync) != null ? _k : false;
|
|
772
|
-
this.state = createProxy(klona(config));
|
|
773
|
-
this.setupComputed();
|
|
774
|
-
const event = toEvent("machine.created" /* Created */);
|
|
775
|
-
this.executeActions(config == null ? void 0 : config.created, event);
|
|
776
|
-
}
|
|
777
|
-
get stateSnapshot() {
|
|
778
|
-
return cast((0, import_vanilla2.snapshot)(this.state));
|
|
779
|
-
}
|
|
780
|
-
get contextSnapshot() {
|
|
781
|
-
return this.stateSnapshot.context;
|
|
782
|
-
}
|
|
783
|
-
get self() {
|
|
784
|
-
const _self = this;
|
|
785
|
-
return {
|
|
786
|
-
id: this.id,
|
|
787
|
-
send: this.send.bind(this),
|
|
788
|
-
sendParent: this.sendParent.bind(this),
|
|
789
|
-
sendChild: this.sendChild.bind(this),
|
|
790
|
-
stop: this.stop.bind(this),
|
|
791
|
-
stopChild: this.stopChild.bind(this),
|
|
792
|
-
spawn: this.spawn.bind(this),
|
|
793
|
-
get state() {
|
|
794
|
-
return _self.stateSnapshot;
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
get meta() {
|
|
799
|
-
return {
|
|
800
|
-
state: this.stateSnapshot,
|
|
801
|
-
guards: this.guardMap,
|
|
802
|
-
send: this.send.bind(this),
|
|
803
|
-
listen: this.onEvent.bind(this),
|
|
804
|
-
self: this.self,
|
|
805
|
-
getState: () => this.stateSnapshot
|
|
806
|
-
};
|
|
807
|
-
}
|
|
808
|
-
};
|
|
809
|
-
var createMachine = (config, options) => new Machine(config, options);
|
|
72
|
+
// src/toast-group.connect.ts
|
|
73
|
+
var import_core = require("@zag-js/core");
|
|
810
74
|
|
|
811
|
-
// ../../types/
|
|
75
|
+
// ../../types/dist/index.mjs
|
|
812
76
|
function createNormalizer(fn) {
|
|
813
77
|
return { button: fn, label: fn, input: fn, output: fn, element: fn };
|
|
814
78
|
}
|
|
@@ -963,14 +227,14 @@ function groupConnect(state, send, normalize = normalizeProp) {
|
|
|
963
227
|
options.type = "error";
|
|
964
228
|
return group2.upsert(options);
|
|
965
229
|
},
|
|
966
|
-
promise(promise,
|
|
967
|
-
const id = group2.loading(
|
|
230
|
+
promise(promise, options, shared = {}) {
|
|
231
|
+
const id = group2.loading(__spreadValues(__spreadValues({}, shared), options.loading));
|
|
968
232
|
promise.then((response) => {
|
|
969
|
-
const
|
|
970
|
-
group2.success(__spreadProps(__spreadValues(__spreadValues({},
|
|
233
|
+
const successOptions = runIfFn(options.success, response);
|
|
234
|
+
group2.success(__spreadProps(__spreadValues(__spreadValues({}, shared), successOptions), { id }));
|
|
971
235
|
}).catch((error) => {
|
|
972
|
-
const
|
|
973
|
-
group2.error(__spreadProps(__spreadValues(__spreadValues({},
|
|
236
|
+
const errorOptions = runIfFn(options.error, error);
|
|
237
|
+
group2.error(__spreadProps(__spreadValues(__spreadValues({}, shared), errorOptions), { id }));
|
|
974
238
|
});
|
|
975
239
|
return promise;
|
|
976
240
|
},
|
|
@@ -1010,7 +274,7 @@ function groupConnect(state, send, normalize = normalizeProp) {
|
|
|
1010
274
|
return portal;
|
|
1011
275
|
},
|
|
1012
276
|
subscribe(fn) {
|
|
1013
|
-
return (0,
|
|
277
|
+
return (0, import_core.subscribe)(state.context.toasts, () => fn(state.context.toasts));
|
|
1014
278
|
}
|
|
1015
279
|
};
|
|
1016
280
|
if (!state.matches("unknown")) {
|
|
@@ -1019,23 +283,37 @@ function groupConnect(state, send, normalize = normalizeProp) {
|
|
|
1019
283
|
return group2;
|
|
1020
284
|
}
|
|
1021
285
|
|
|
1022
|
-
//
|
|
286
|
+
// src/toast-group.machine.ts
|
|
287
|
+
var import_core3 = require("@zag-js/core");
|
|
288
|
+
|
|
289
|
+
// ../../utilities/dom/dist/index.mjs
|
|
1023
290
|
var dataAttr = (guard) => {
|
|
1024
291
|
return guard ? "" : void 0;
|
|
1025
292
|
};
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
293
|
+
var cast = (v) => v;
|
|
294
|
+
var noop = () => {
|
|
295
|
+
};
|
|
296
|
+
function getListenerElements() {
|
|
297
|
+
;
|
|
298
|
+
globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
|
|
299
|
+
return globalThis.__listenerElements__;
|
|
300
|
+
}
|
|
301
|
+
function getListenerCache() {
|
|
302
|
+
;
|
|
303
|
+
globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
|
|
304
|
+
return globalThis.__listenerCache__;
|
|
305
|
+
}
|
|
1030
306
|
function globalEventBus(node, type, handler, options) {
|
|
1031
307
|
var _a;
|
|
1032
308
|
if (!node)
|
|
1033
309
|
return noop;
|
|
1034
310
|
const hash = JSON.stringify({ type, options });
|
|
311
|
+
const listenerElements = getListenerElements();
|
|
312
|
+
const listenerCache = getListenerCache();
|
|
1035
313
|
const group2 = listenerElements.get(node);
|
|
1036
314
|
if (!listenerElements.has(node)) {
|
|
1037
|
-
const
|
|
1038
|
-
listenerElements.set(node,
|
|
315
|
+
const group22 = /* @__PURE__ */ new Map([[hash, /* @__PURE__ */ new Set([handler])]]);
|
|
316
|
+
listenerElements.set(node, group22);
|
|
1039
317
|
} else if (group2 == null ? void 0 : group2.has(hash)) {
|
|
1040
318
|
(_a = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a.add(handler);
|
|
1041
319
|
} else {
|
|
@@ -1045,8 +323,8 @@ function globalEventBus(node, type, handler, options) {
|
|
|
1045
323
|
var _a2, _b;
|
|
1046
324
|
function listener(event) {
|
|
1047
325
|
var _a3;
|
|
1048
|
-
const
|
|
1049
|
-
(_a3 =
|
|
326
|
+
const group22 = listenerElements.get(node2);
|
|
327
|
+
(_a3 = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _a3.forEach((fn) => fn(event));
|
|
1050
328
|
}
|
|
1051
329
|
if (!(listenerCache == null ? void 0 : listenerCache.has(node2))) {
|
|
1052
330
|
listenerCache.set(node2, /* @__PURE__ */ new Map([[hash, listener]]));
|
|
@@ -1063,22 +341,20 @@ function globalEventBus(node, type, handler, options) {
|
|
|
1063
341
|
var _a2, _b, _c, _d;
|
|
1064
342
|
if (!listenerElements.has(node))
|
|
1065
343
|
return;
|
|
1066
|
-
const
|
|
1067
|
-
(_a2 =
|
|
1068
|
-
if (((_b =
|
|
344
|
+
const group22 = listenerElements.get(node);
|
|
345
|
+
(_a2 = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _a2.delete(handler);
|
|
346
|
+
if (((_b = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _b.size) === 0) {
|
|
1069
347
|
const listener = (_c = listenerCache.get(node)) == null ? void 0 : _c.get(hash);
|
|
1070
348
|
node.removeEventListener(type, listener, options);
|
|
1071
|
-
|
|
349
|
+
group22 == null ? void 0 : group22.delete(hash);
|
|
1072
350
|
(_d = listenerCache.get(node)) == null ? void 0 : _d.delete(hash);
|
|
1073
|
-
if ((
|
|
351
|
+
if ((group22 == null ? void 0 : group22.size) === 0) {
|
|
1074
352
|
listenerElements.delete(node);
|
|
1075
353
|
listenerCache.delete(node);
|
|
1076
354
|
}
|
|
1077
355
|
}
|
|
1078
356
|
};
|
|
1079
357
|
}
|
|
1080
|
-
|
|
1081
|
-
// ../../utilities/dom/src/listener.ts
|
|
1082
358
|
var t = (v) => Object.prototype.toString.call(v).slice(8, -1);
|
|
1083
359
|
var isRef = (v) => t(v) === "Object" && "current" in v;
|
|
1084
360
|
var runIfFn2 = (fn) => t(fn) === "Function" ? fn() : fn;
|
|
@@ -1086,11 +362,7 @@ function addDomEvent(target, event, listener, options) {
|
|
|
1086
362
|
const node = isRef(target) ? target.current : runIfFn2(target);
|
|
1087
363
|
return globalEventBus(node, event, listener, options);
|
|
1088
364
|
}
|
|
1089
|
-
|
|
1090
|
-
// ../../utilities/dom/src/constants.ts
|
|
1091
365
|
var MAX_Z_INDEX = 2147483647;
|
|
1092
|
-
|
|
1093
|
-
// ../../utilities/dom/src/visibility-event.ts
|
|
1094
366
|
function trackDocumentVisibility(_doc, callback) {
|
|
1095
367
|
const doc = cast(_doc);
|
|
1096
368
|
return addDomEvent(doc, "visibilitychange", () => {
|
|
@@ -1100,11 +372,12 @@ function trackDocumentVisibility(_doc, callback) {
|
|
|
1100
372
|
}
|
|
1101
373
|
|
|
1102
374
|
// src/toast.machine.ts
|
|
1103
|
-
var
|
|
375
|
+
var import_core2 = require("@zag-js/core");
|
|
376
|
+
var { not, and, or } = import_core2.guards;
|
|
1104
377
|
function createToastMachine(options = {}) {
|
|
1105
378
|
const _a = options, { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 500 } = _a, rest = __objRest(_a, ["type", "duration", "id", "placement", "removeDelay"]);
|
|
1106
379
|
const __duration = getToastDuration(duration, type);
|
|
1107
|
-
return createMachine({
|
|
380
|
+
return (0, import_core2.createMachine)({
|
|
1108
381
|
id,
|
|
1109
382
|
entry: "invokeOnOpen",
|
|
1110
383
|
initial: type === "loading" ? "persist" : "active",
|
|
@@ -1120,12 +393,12 @@ function createToastMachine(options = {}) {
|
|
|
1120
393
|
on: {
|
|
1121
394
|
UPDATE: [
|
|
1122
395
|
{
|
|
1123
|
-
guard:
|
|
396
|
+
guard: and("hasTypeChanged", "isChangingToLoading"),
|
|
1124
397
|
target: "persist",
|
|
1125
398
|
actions: ["setContext", "invokeOnUpdate"]
|
|
1126
399
|
},
|
|
1127
400
|
{
|
|
1128
|
-
guard:
|
|
401
|
+
guard: or("hasDurationChanged", "hasTypeChanged"),
|
|
1129
402
|
target: "active:temp",
|
|
1130
403
|
actions: ["setContext", "invokeOnUpdate"]
|
|
1131
404
|
},
|
|
@@ -1146,7 +419,7 @@ function createToastMachine(options = {}) {
|
|
|
1146
419
|
activities: "trackDocumentVisibility",
|
|
1147
420
|
on: {
|
|
1148
421
|
RESUME: {
|
|
1149
|
-
guard:
|
|
422
|
+
guard: not("isLoadingType"),
|
|
1150
423
|
target: "active",
|
|
1151
424
|
actions: ["setCreatedAt"]
|
|
1152
425
|
},
|
|
@@ -1246,7 +519,7 @@ function createToastMachine(options = {}) {
|
|
|
1246
519
|
}
|
|
1247
520
|
|
|
1248
521
|
// src/toast-group.machine.ts
|
|
1249
|
-
var groupMachine = createMachine({
|
|
522
|
+
var groupMachine = (0, import_core3.createMachine)({
|
|
1250
523
|
id: "toaster",
|
|
1251
524
|
initial: "active",
|
|
1252
525
|
context: {
|
|
@@ -1268,7 +541,7 @@ var groupMachine = createMachine({
|
|
|
1268
541
|
actions: (ctx, evt) => {
|
|
1269
542
|
ctx.uid = evt.id;
|
|
1270
543
|
if (evt.doc)
|
|
1271
|
-
ctx.doc = (0,
|
|
544
|
+
ctx.doc = (0, import_core3.ref)(evt.doc);
|
|
1272
545
|
}
|
|
1273
546
|
},
|
|
1274
547
|
PAUSE_TOAST: {
|
|
@@ -1299,7 +572,7 @@ var groupMachine = createMachine({
|
|
|
1299
572
|
pauseOnPageIdle: ctx.pauseOnPageIdle,
|
|
1300
573
|
pauseOnInteraction: ctx.pauseOnInteraction,
|
|
1301
574
|
dir: ctx.dir,
|
|
1302
|
-
doc: (0,
|
|
575
|
+
doc: (0, import_core3.ref)((_a = ctx.doc) != null ? _a : document)
|
|
1303
576
|
});
|
|
1304
577
|
const toast = createToastMachine(options);
|
|
1305
578
|
const actor = self.spawn(toast);
|