@zag-js/toast 0.0.0-dev-20220730094117 → 0.0.0-dev-20220823145853

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 (3) hide show
  1. package/dist/index.js +128 -125
  2. package/dist/index.mjs +128 -125
  3. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -318,146 +318,149 @@ var { not, and, or } = import_core2.guards;
318
318
  function createToastMachine(options = {}) {
319
319
  const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 500, ...rest } = options;
320
320
  const __duration = getToastDuration(duration, type);
321
- return (0, import_core2.createMachine)({
322
- id,
323
- entry: "invokeOnOpen",
324
- initial: type === "loading" ? "persist" : "active",
325
- context: {
321
+ return (0, import_core2.createMachine)(
322
+ {
326
323
  id,
327
- type,
328
- remaining: __duration,
329
- duration: __duration,
330
- removeDelay,
331
- createdAt: Date.now(),
332
- placement,
333
- ...rest
334
- },
335
- on: {
336
- UPDATE: [
337
- {
338
- guard: and("hasTypeChanged", "isChangingToLoading"),
339
- target: "persist",
340
- actions: ["setContext", "invokeOnUpdate"]
341
- },
342
- {
343
- guard: or("hasDurationChanged", "hasTypeChanged"),
344
- target: "active:temp",
345
- actions: ["setContext", "invokeOnUpdate"]
346
- },
347
- {
348
- actions: ["setContext", "invokeOnUpdate"]
349
- }
350
- ]
351
- },
352
- states: {
353
- "active:temp": {
354
- tags: ["visible", "updating"],
355
- after: {
356
- 0: "active"
357
- }
324
+ entry: "invokeOnOpen",
325
+ initial: type === "loading" ? "persist" : "active",
326
+ context: {
327
+ id,
328
+ type,
329
+ remaining: __duration,
330
+ duration: __duration,
331
+ removeDelay,
332
+ createdAt: Date.now(),
333
+ placement,
334
+ ...rest
358
335
  },
359
- persist: {
360
- tags: ["visible", "paused"],
361
- activities: "trackDocumentVisibility",
362
- on: {
363
- RESUME: {
364
- guard: not("isLoadingType"),
365
- target: "active",
366
- actions: ["setCreatedAt"]
336
+ on: {
337
+ UPDATE: [
338
+ {
339
+ guard: and("hasTypeChanged", "isChangingToLoading"),
340
+ target: "persist",
341
+ actions: ["setContext", "invokeOnUpdate"]
367
342
  },
368
- DISMISS: "dismissing"
369
- }
343
+ {
344
+ guard: or("hasDurationChanged", "hasTypeChanged"),
345
+ target: "active:temp",
346
+ actions: ["setContext", "invokeOnUpdate"]
347
+ },
348
+ {
349
+ actions: ["setContext", "invokeOnUpdate"]
350
+ }
351
+ ]
370
352
  },
371
- active: {
372
- tags: ["visible"],
373
- activities: "trackDocumentVisibility",
374
- after: {
375
- VISIBLE_DURATION: "dismissing"
353
+ states: {
354
+ "active:temp": {
355
+ tags: ["visible", "updating"],
356
+ after: {
357
+ 0: "active"
358
+ }
376
359
  },
377
- on: {
378
- DISMISS: "dismissing",
379
- PAUSE: {
380
- target: "persist",
381
- actions: "setRemainingDuration"
360
+ persist: {
361
+ tags: ["visible", "paused"],
362
+ activities: "trackDocumentVisibility",
363
+ on: {
364
+ RESUME: {
365
+ guard: not("isLoadingType"),
366
+ target: "active",
367
+ actions: ["setCreatedAt"]
368
+ },
369
+ DISMISS: "dismissing"
382
370
  }
383
- }
384
- },
385
- dismissing: {
386
- entry: "invokeOnClosing",
387
- after: {
388
- REMOVE_DELAY: {
389
- target: "inactive",
390
- actions: "notifyParentToRemove"
371
+ },
372
+ active: {
373
+ tags: ["visible"],
374
+ activities: "trackDocumentVisibility",
375
+ after: {
376
+ VISIBLE_DURATION: "dismissing"
377
+ },
378
+ on: {
379
+ DISMISS: "dismissing",
380
+ PAUSE: {
381
+ target: "persist",
382
+ actions: "setRemainingDuration"
383
+ }
391
384
  }
385
+ },
386
+ dismissing: {
387
+ entry: "invokeOnClosing",
388
+ after: {
389
+ REMOVE_DELAY: {
390
+ target: "inactive",
391
+ actions: "notifyParentToRemove"
392
+ }
393
+ }
394
+ },
395
+ inactive: {
396
+ entry: "invokeOnClose",
397
+ type: "final"
392
398
  }
393
- },
394
- inactive: {
395
- entry: "invokeOnClose",
396
- type: "final"
397
- }
398
- }
399
- }, {
400
- activities: {
401
- trackDocumentVisibility(ctx, _evt, { send }) {
402
- if (!ctx.pauseOnPageIdle)
403
- return;
404
- return trackDocumentVisibility(dom.getDoc(ctx), function(hidden) {
405
- send(hidden ? "PAUSE" : "RESUME");
406
- });
407
- }
408
- },
409
- guards: {
410
- isChangingToLoading: (_, evt) => {
411
- var _a;
412
- return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
413
- },
414
- isLoadingType: (ctx) => ctx.type === "loading",
415
- hasTypeChanged: (ctx, evt) => {
416
- var _a;
417
- return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx.type;
418
- },
419
- hasDurationChanged: (ctx, evt) => {
420
- var _a;
421
- return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
422
399
  }
423
400
  },
424
- delays: {
425
- VISIBLE_DURATION: (ctx) => ctx.remaining,
426
- REMOVE_DELAY: (ctx) => ctx.removeDelay
427
- },
428
- actions: {
429
- setRemainingDuration(ctx) {
430
- ctx.remaining -= Date.now() - ctx.createdAt;
431
- },
432
- setCreatedAt(ctx) {
433
- ctx.createdAt = Date.now();
434
- },
435
- notifyParentToRemove(_ctx, _evt, { self }) {
436
- self.sendParent({ type: "REMOVE_TOAST", id: self.id });
437
- },
438
- invokeOnClosing(ctx) {
439
- var _a;
440
- (_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
441
- },
442
- invokeOnClose(ctx) {
443
- var _a;
444
- (_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
401
+ {
402
+ activities: {
403
+ trackDocumentVisibility(ctx, _evt, { send }) {
404
+ if (!ctx.pauseOnPageIdle)
405
+ return;
406
+ return trackDocumentVisibility(dom.getDoc(ctx), function(hidden) {
407
+ send(hidden ? "PAUSE" : "RESUME");
408
+ });
409
+ }
445
410
  },
446
- invokeOnOpen(ctx) {
447
- var _a;
448
- (_a = ctx.onOpen) == null ? void 0 : _a.call(ctx);
411
+ guards: {
412
+ isChangingToLoading: (_, evt) => {
413
+ var _a;
414
+ return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
415
+ },
416
+ isLoadingType: (ctx) => ctx.type === "loading",
417
+ hasTypeChanged: (ctx, evt) => {
418
+ var _a;
419
+ return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx.type;
420
+ },
421
+ hasDurationChanged: (ctx, evt) => {
422
+ var _a;
423
+ return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
424
+ }
449
425
  },
450
- invokeOnUpdate(ctx) {
451
- var _a;
452
- (_a = ctx.onUpdate) == null ? void 0 : _a.call(ctx);
426
+ delays: {
427
+ VISIBLE_DURATION: (ctx) => ctx.remaining,
428
+ REMOVE_DELAY: (ctx) => ctx.removeDelay
453
429
  },
454
- setContext(ctx, evt) {
455
- const { duration: duration2, type: type2 } = evt.toast;
456
- const time = getToastDuration(duration2, type2);
457
- Object.assign(ctx, { ...evt.toast, duration: time, remaining: time });
430
+ actions: {
431
+ setRemainingDuration(ctx) {
432
+ ctx.remaining -= Date.now() - ctx.createdAt;
433
+ },
434
+ setCreatedAt(ctx) {
435
+ ctx.createdAt = Date.now();
436
+ },
437
+ notifyParentToRemove(_ctx, _evt, { self }) {
438
+ self.sendParent({ type: "REMOVE_TOAST", id: self.id });
439
+ },
440
+ invokeOnClosing(ctx) {
441
+ var _a;
442
+ (_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
443
+ },
444
+ invokeOnClose(ctx) {
445
+ var _a;
446
+ (_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
447
+ },
448
+ invokeOnOpen(ctx) {
449
+ var _a;
450
+ (_a = ctx.onOpen) == null ? void 0 : _a.call(ctx);
451
+ },
452
+ invokeOnUpdate(ctx) {
453
+ var _a;
454
+ (_a = ctx.onUpdate) == null ? void 0 : _a.call(ctx);
455
+ },
456
+ setContext(ctx, evt) {
457
+ const { duration: duration2, type: type2 } = evt.toast;
458
+ const time = getToastDuration(duration2, type2);
459
+ Object.assign(ctx, { ...evt.toast, duration: time, remaining: time });
460
+ }
458
461
  }
459
462
  }
460
- });
463
+ );
461
464
  }
462
465
 
463
466
  // src/toast-group.machine.ts
package/dist/index.mjs CHANGED
@@ -289,146 +289,149 @@ var { not, and, or } = guards;
289
289
  function createToastMachine(options = {}) {
290
290
  const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 500, ...rest } = options;
291
291
  const __duration = getToastDuration(duration, type);
292
- return createMachine({
293
- id,
294
- entry: "invokeOnOpen",
295
- initial: type === "loading" ? "persist" : "active",
296
- context: {
292
+ return createMachine(
293
+ {
297
294
  id,
298
- type,
299
- remaining: __duration,
300
- duration: __duration,
301
- removeDelay,
302
- createdAt: Date.now(),
303
- placement,
304
- ...rest
305
- },
306
- on: {
307
- UPDATE: [
308
- {
309
- guard: and("hasTypeChanged", "isChangingToLoading"),
310
- target: "persist",
311
- actions: ["setContext", "invokeOnUpdate"]
312
- },
313
- {
314
- guard: or("hasDurationChanged", "hasTypeChanged"),
315
- target: "active:temp",
316
- actions: ["setContext", "invokeOnUpdate"]
317
- },
318
- {
319
- actions: ["setContext", "invokeOnUpdate"]
320
- }
321
- ]
322
- },
323
- states: {
324
- "active:temp": {
325
- tags: ["visible", "updating"],
326
- after: {
327
- 0: "active"
328
- }
295
+ entry: "invokeOnOpen",
296
+ initial: type === "loading" ? "persist" : "active",
297
+ context: {
298
+ id,
299
+ type,
300
+ remaining: __duration,
301
+ duration: __duration,
302
+ removeDelay,
303
+ createdAt: Date.now(),
304
+ placement,
305
+ ...rest
329
306
  },
330
- persist: {
331
- tags: ["visible", "paused"],
332
- activities: "trackDocumentVisibility",
333
- on: {
334
- RESUME: {
335
- guard: not("isLoadingType"),
336
- target: "active",
337
- actions: ["setCreatedAt"]
307
+ on: {
308
+ UPDATE: [
309
+ {
310
+ guard: and("hasTypeChanged", "isChangingToLoading"),
311
+ target: "persist",
312
+ actions: ["setContext", "invokeOnUpdate"]
338
313
  },
339
- DISMISS: "dismissing"
340
- }
314
+ {
315
+ guard: or("hasDurationChanged", "hasTypeChanged"),
316
+ target: "active:temp",
317
+ actions: ["setContext", "invokeOnUpdate"]
318
+ },
319
+ {
320
+ actions: ["setContext", "invokeOnUpdate"]
321
+ }
322
+ ]
341
323
  },
342
- active: {
343
- tags: ["visible"],
344
- activities: "trackDocumentVisibility",
345
- after: {
346
- VISIBLE_DURATION: "dismissing"
324
+ states: {
325
+ "active:temp": {
326
+ tags: ["visible", "updating"],
327
+ after: {
328
+ 0: "active"
329
+ }
347
330
  },
348
- on: {
349
- DISMISS: "dismissing",
350
- PAUSE: {
351
- target: "persist",
352
- actions: "setRemainingDuration"
331
+ persist: {
332
+ tags: ["visible", "paused"],
333
+ activities: "trackDocumentVisibility",
334
+ on: {
335
+ RESUME: {
336
+ guard: not("isLoadingType"),
337
+ target: "active",
338
+ actions: ["setCreatedAt"]
339
+ },
340
+ DISMISS: "dismissing"
353
341
  }
354
- }
355
- },
356
- dismissing: {
357
- entry: "invokeOnClosing",
358
- after: {
359
- REMOVE_DELAY: {
360
- target: "inactive",
361
- actions: "notifyParentToRemove"
342
+ },
343
+ active: {
344
+ tags: ["visible"],
345
+ activities: "trackDocumentVisibility",
346
+ after: {
347
+ VISIBLE_DURATION: "dismissing"
348
+ },
349
+ on: {
350
+ DISMISS: "dismissing",
351
+ PAUSE: {
352
+ target: "persist",
353
+ actions: "setRemainingDuration"
354
+ }
362
355
  }
356
+ },
357
+ dismissing: {
358
+ entry: "invokeOnClosing",
359
+ after: {
360
+ REMOVE_DELAY: {
361
+ target: "inactive",
362
+ actions: "notifyParentToRemove"
363
+ }
364
+ }
365
+ },
366
+ inactive: {
367
+ entry: "invokeOnClose",
368
+ type: "final"
363
369
  }
364
- },
365
- inactive: {
366
- entry: "invokeOnClose",
367
- type: "final"
368
- }
369
- }
370
- }, {
371
- activities: {
372
- trackDocumentVisibility(ctx, _evt, { send }) {
373
- if (!ctx.pauseOnPageIdle)
374
- return;
375
- return trackDocumentVisibility(dom.getDoc(ctx), function(hidden) {
376
- send(hidden ? "PAUSE" : "RESUME");
377
- });
378
- }
379
- },
380
- guards: {
381
- isChangingToLoading: (_, evt) => {
382
- var _a;
383
- return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
384
- },
385
- isLoadingType: (ctx) => ctx.type === "loading",
386
- hasTypeChanged: (ctx, evt) => {
387
- var _a;
388
- return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx.type;
389
- },
390
- hasDurationChanged: (ctx, evt) => {
391
- var _a;
392
- return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
393
370
  }
394
371
  },
395
- delays: {
396
- VISIBLE_DURATION: (ctx) => ctx.remaining,
397
- REMOVE_DELAY: (ctx) => ctx.removeDelay
398
- },
399
- actions: {
400
- setRemainingDuration(ctx) {
401
- ctx.remaining -= Date.now() - ctx.createdAt;
402
- },
403
- setCreatedAt(ctx) {
404
- ctx.createdAt = Date.now();
405
- },
406
- notifyParentToRemove(_ctx, _evt, { self }) {
407
- self.sendParent({ type: "REMOVE_TOAST", id: self.id });
408
- },
409
- invokeOnClosing(ctx) {
410
- var _a;
411
- (_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
412
- },
413
- invokeOnClose(ctx) {
414
- var _a;
415
- (_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
372
+ {
373
+ activities: {
374
+ trackDocumentVisibility(ctx, _evt, { send }) {
375
+ if (!ctx.pauseOnPageIdle)
376
+ return;
377
+ return trackDocumentVisibility(dom.getDoc(ctx), function(hidden) {
378
+ send(hidden ? "PAUSE" : "RESUME");
379
+ });
380
+ }
416
381
  },
417
- invokeOnOpen(ctx) {
418
- var _a;
419
- (_a = ctx.onOpen) == null ? void 0 : _a.call(ctx);
382
+ guards: {
383
+ isChangingToLoading: (_, evt) => {
384
+ var _a;
385
+ return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
386
+ },
387
+ isLoadingType: (ctx) => ctx.type === "loading",
388
+ hasTypeChanged: (ctx, evt) => {
389
+ var _a;
390
+ return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx.type;
391
+ },
392
+ hasDurationChanged: (ctx, evt) => {
393
+ var _a;
394
+ return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
395
+ }
420
396
  },
421
- invokeOnUpdate(ctx) {
422
- var _a;
423
- (_a = ctx.onUpdate) == null ? void 0 : _a.call(ctx);
397
+ delays: {
398
+ VISIBLE_DURATION: (ctx) => ctx.remaining,
399
+ REMOVE_DELAY: (ctx) => ctx.removeDelay
424
400
  },
425
- setContext(ctx, evt) {
426
- const { duration: duration2, type: type2 } = evt.toast;
427
- const time = getToastDuration(duration2, type2);
428
- Object.assign(ctx, { ...evt.toast, duration: time, remaining: time });
401
+ actions: {
402
+ setRemainingDuration(ctx) {
403
+ ctx.remaining -= Date.now() - ctx.createdAt;
404
+ },
405
+ setCreatedAt(ctx) {
406
+ ctx.createdAt = Date.now();
407
+ },
408
+ notifyParentToRemove(_ctx, _evt, { self }) {
409
+ self.sendParent({ type: "REMOVE_TOAST", id: self.id });
410
+ },
411
+ invokeOnClosing(ctx) {
412
+ var _a;
413
+ (_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
414
+ },
415
+ invokeOnClose(ctx) {
416
+ var _a;
417
+ (_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
418
+ },
419
+ invokeOnOpen(ctx) {
420
+ var _a;
421
+ (_a = ctx.onOpen) == null ? void 0 : _a.call(ctx);
422
+ },
423
+ invokeOnUpdate(ctx) {
424
+ var _a;
425
+ (_a = ctx.onUpdate) == null ? void 0 : _a.call(ctx);
426
+ },
427
+ setContext(ctx, evt) {
428
+ const { duration: duration2, type: type2 } = evt.toast;
429
+ const time = getToastDuration(duration2, type2);
430
+ Object.assign(ctx, { ...evt.toast, duration: time, remaining: time });
431
+ }
429
432
  }
430
433
  }
431
- });
434
+ );
432
435
  }
433
436
 
434
437
  // src/toast-group.machine.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/toast",
3
- "version": "0.0.0-dev-20220730094117",
3
+ "version": "0.0.0-dev-20220823145853",
4
4
  "description": "Core logic for the toast widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,12 +29,12 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.1.9",
33
- "@zag-js/types": "0.2.3"
32
+ "@zag-js/core": "0.0.0-dev-20220823145853",
33
+ "@zag-js/types": "0.0.0-dev-20220823145853"
34
34
  },
35
35
  "devDependencies": {
36
- "@zag-js/dom-utils": "0.1.8",
37
- "@zag-js/utils": "0.1.3"
36
+ "@zag-js/dom-utils": "0.0.0-dev-20220823145853",
37
+ "@zag-js/utils": "0.0.0-dev-20220823145853"
38
38
  },
39
39
  "scripts": {
40
40
  "build-fast": "tsup src/index.ts --format=esm,cjs",