@zag-js/toast 0.1.8 → 0.1.9

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 CHANGED
@@ -56,12 +56,39 @@ __export(src_exports, {
56
56
  });
57
57
  module.exports = __toCommonJS(src_exports);
58
58
 
59
- // ../../utilities/core/dist/index.mjs
60
- var isDom = () => typeof window !== "undefined";
59
+ // ../../utilities/dom/dist/index.mjs
60
+ var dataAttr = (guard) => {
61
+ return guard ? "" : void 0;
62
+ };
63
+ var MAX_Z_INDEX = 2147483647;
61
64
  var runIfFn = (v, ...a) => {
62
65
  const res = typeof v === "function" ? v(...a) : v;
63
66
  return res != null ? res : void 0;
64
67
  };
68
+ var cast = (v) => v;
69
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
70
+ var isDom = () => typeof window !== "undefined";
71
+ var isRef = (v) => hasProp(v, "current");
72
+ function addDomEvent(target, eventName, handler, options) {
73
+ const node = isRef(target) ? target.current : runIfFn(target);
74
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
75
+ return () => {
76
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
77
+ };
78
+ }
79
+ function trackDocumentVisibility(_doc, callback) {
80
+ const doc = cast(_doc);
81
+ return addDomEvent(doc, "visibilitychange", () => {
82
+ const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
83
+ callback(!!hidden);
84
+ });
85
+ }
86
+
87
+ // ../../utilities/core/dist/index.mjs
88
+ var runIfFn2 = (v, ...a) => {
89
+ const res = typeof v === "function" ? v(...a) : v;
90
+ return res != null ? res : void 0;
91
+ };
65
92
  var uuid = /* @__PURE__ */ (() => {
66
93
  let id = 0;
67
94
  return () => {
@@ -80,16 +107,6 @@ function warn(...a) {
80
107
  // src/toast-group.connect.ts
81
108
  var import_core = require("@zag-js/core");
82
109
 
83
- // ../../types/dist/index.mjs
84
- function createNormalizer(fn) {
85
- return new Proxy({}, {
86
- get() {
87
- return fn;
88
- }
89
- });
90
- }
91
- var normalizeProp = createNormalizer((v) => v);
92
-
93
110
  // src/toast.dom.ts
94
111
  var dom = {
95
112
  getDoc: (ctx) => {
@@ -178,7 +195,7 @@ function getGroupPlacementStyle(ctx, placement) {
178
195
 
179
196
  // src/toast-group.connect.ts
180
197
  var toaster = {};
181
- function groupConnect(state, send, normalize = normalizeProp) {
198
+ function groupConnect(state, send, normalize) {
182
199
  const group2 = {
183
200
  count: state.context.count,
184
201
  toasts: state.context.toasts,
@@ -246,10 +263,10 @@ function groupConnect(state, send, normalize = normalizeProp) {
246
263
  promise(promise, options, shared = {}) {
247
264
  const id = group2.loading(__spreadValues(__spreadValues({}, shared), options.loading));
248
265
  promise.then((response) => {
249
- const successOptions = runIfFn(options.success, response);
266
+ const successOptions = runIfFn2(options.success, response);
250
267
  group2.success(__spreadProps(__spreadValues(__spreadValues({}, shared), successOptions), { id }));
251
268
  }).catch((error) => {
252
- const errorOptions = runIfFn(options.error, error);
269
+ const errorOptions = runIfFn2(options.error, error);
253
270
  group2.error(__spreadProps(__spreadValues(__spreadValues({}, shared), errorOptions), { id }));
254
271
  });
255
272
  return promise;
@@ -302,33 +319,6 @@ function groupConnect(state, send, normalize = normalizeProp) {
302
319
  // src/toast-group.machine.ts
303
320
  var import_core3 = require("@zag-js/core");
304
321
 
305
- // ../../utilities/dom/dist/index.mjs
306
- var dataAttr = (guard) => {
307
- return guard ? "" : void 0;
308
- };
309
- var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
310
- var runIfFn2 = (v, ...a) => {
311
- const res = typeof v === "function" ? v(...a) : v;
312
- return res != null ? res : void 0;
313
- };
314
- var cast = (v) => v;
315
- var isRef = (v) => hasProp(v, "current");
316
- function addDomEvent(target, eventName, handler, options) {
317
- const node = isRef(target) ? target.current : runIfFn2(target);
318
- node == null ? void 0 : node.addEventListener(eventName, handler, options);
319
- return () => {
320
- node == null ? void 0 : node.removeEventListener(eventName, handler, options);
321
- };
322
- }
323
- var MAX_Z_INDEX = 2147483647;
324
- function trackDocumentVisibility(_doc, callback) {
325
- const doc = cast(_doc);
326
- return addDomEvent(doc, "visibilitychange", () => {
327
- const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
328
- callback(!!hidden);
329
- });
330
- }
331
-
332
322
  // src/toast.machine.ts
333
323
  var import_core2 = require("@zag-js/core");
334
324
  var { not, and, or } = import_core2.guards;
@@ -574,7 +564,7 @@ function groupMachine(ctx = {}) {
574
564
  }
575
565
 
576
566
  // src/toast.connect.ts
577
- function connect(state, send, normalize = normalizeProp) {
567
+ function connect(state, send, normalize) {
578
568
  const isVisible = state.hasTag("visible");
579
569
  const isPaused = state.hasTag("paused");
580
570
  const isUpdating = state.hasTag("updating");
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __defProp = Object.defineProperty;
3
2
  var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -31,12 +30,39 @@ var __objRest = (source, exclude) => {
31
30
  return target;
32
31
  };
33
32
 
34
- // ../../utilities/core/dist/index.mjs
35
- var isDom = () => typeof window !== "undefined";
33
+ // ../../utilities/dom/dist/index.mjs
34
+ var dataAttr = (guard) => {
35
+ return guard ? "" : void 0;
36
+ };
37
+ var MAX_Z_INDEX = 2147483647;
36
38
  var runIfFn = (v, ...a) => {
37
39
  const res = typeof v === "function" ? v(...a) : v;
38
40
  return res != null ? res : void 0;
39
41
  };
42
+ var cast = (v) => v;
43
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
44
+ var isDom = () => typeof window !== "undefined";
45
+ var isRef = (v) => hasProp(v, "current");
46
+ function addDomEvent(target, eventName, handler, options) {
47
+ const node = isRef(target) ? target.current : runIfFn(target);
48
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
49
+ return () => {
50
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
51
+ };
52
+ }
53
+ function trackDocumentVisibility(_doc, callback) {
54
+ const doc = cast(_doc);
55
+ return addDomEvent(doc, "visibilitychange", () => {
56
+ const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
57
+ callback(!!hidden);
58
+ });
59
+ }
60
+
61
+ // ../../utilities/core/dist/index.mjs
62
+ var runIfFn2 = (v, ...a) => {
63
+ const res = typeof v === "function" ? v(...a) : v;
64
+ return res != null ? res : void 0;
65
+ };
40
66
  var uuid = /* @__PURE__ */ (() => {
41
67
  let id = 0;
42
68
  return () => {
@@ -55,16 +81,6 @@ function warn(...a) {
55
81
  // src/toast-group.connect.ts
56
82
  import { subscribe } from "@zag-js/core";
57
83
 
58
- // ../../types/dist/index.mjs
59
- function createNormalizer(fn) {
60
- return new Proxy({}, {
61
- get() {
62
- return fn;
63
- }
64
- });
65
- }
66
- var normalizeProp = createNormalizer((v) => v);
67
-
68
84
  // src/toast.dom.ts
69
85
  var dom = {
70
86
  getDoc: (ctx) => {
@@ -153,7 +169,7 @@ function getGroupPlacementStyle(ctx, placement) {
153
169
 
154
170
  // src/toast-group.connect.ts
155
171
  var toaster = {};
156
- function groupConnect(state, send, normalize = normalizeProp) {
172
+ function groupConnect(state, send, normalize) {
157
173
  const group2 = {
158
174
  count: state.context.count,
159
175
  toasts: state.context.toasts,
@@ -221,10 +237,10 @@ function groupConnect(state, send, normalize = normalizeProp) {
221
237
  promise(promise, options, shared = {}) {
222
238
  const id = group2.loading(__spreadValues(__spreadValues({}, shared), options.loading));
223
239
  promise.then((response) => {
224
- const successOptions = runIfFn(options.success, response);
240
+ const successOptions = runIfFn2(options.success, response);
225
241
  group2.success(__spreadProps(__spreadValues(__spreadValues({}, shared), successOptions), { id }));
226
242
  }).catch((error) => {
227
- const errorOptions = runIfFn(options.error, error);
243
+ const errorOptions = runIfFn2(options.error, error);
228
244
  group2.error(__spreadProps(__spreadValues(__spreadValues({}, shared), errorOptions), { id }));
229
245
  });
230
246
  return promise;
@@ -277,33 +293,6 @@ function groupConnect(state, send, normalize = normalizeProp) {
277
293
  // src/toast-group.machine.ts
278
294
  import { createMachine as createMachine2, ref } from "@zag-js/core";
279
295
 
280
- // ../../utilities/dom/dist/index.mjs
281
- var dataAttr = (guard) => {
282
- return guard ? "" : void 0;
283
- };
284
- var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
285
- var runIfFn2 = (v, ...a) => {
286
- const res = typeof v === "function" ? v(...a) : v;
287
- return res != null ? res : void 0;
288
- };
289
- var cast = (v) => v;
290
- var isRef = (v) => hasProp(v, "current");
291
- function addDomEvent(target, eventName, handler, options) {
292
- const node = isRef(target) ? target.current : runIfFn2(target);
293
- node == null ? void 0 : node.addEventListener(eventName, handler, options);
294
- return () => {
295
- node == null ? void 0 : node.removeEventListener(eventName, handler, options);
296
- };
297
- }
298
- var MAX_Z_INDEX = 2147483647;
299
- function trackDocumentVisibility(_doc, callback) {
300
- const doc = cast(_doc);
301
- return addDomEvent(doc, "visibilitychange", () => {
302
- const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
303
- callback(!!hidden);
304
- });
305
- }
306
-
307
296
  // src/toast.machine.ts
308
297
  import { createMachine, guards } from "@zag-js/core";
309
298
  var { not, and, or } = guards;
@@ -549,7 +538,7 @@ function groupMachine(ctx = {}) {
549
538
  }
550
539
 
551
540
  // src/toast.connect.ts
552
- function connect(state, send, normalize = normalizeProp) {
541
+ function connect(state, send, normalize) {
553
542
  const isVisible = state.hasTag("visible");
554
543
  const isPaused = state.hasTag("paused");
555
544
  const isUpdating = state.hasTag("updating");
@@ -1,7 +1,7 @@
1
- import { PropTypes, ReactPropTypes } from "@zag-js/types";
2
- import { GroupMachineContext, GroupProps, GroupSend, GroupState, Placement, PromiseOptions, Toaster, Options } from "./toast.types";
1
+ import type { NormalizeProps, PropTypes } from "@zag-js/types";
2
+ import type { GroupMachineContext, GroupProps, GroupSend, GroupState, Placement, PromiseOptions, Toaster, Options } from "./toast.types";
3
3
  export declare let toaster: Toaster;
4
- export declare function groupConnect<T extends PropTypes = ReactPropTypes>(state: GroupState, send: GroupSend, normalize?: import("@zag-js/types").NormalizeProps): {
4
+ export declare function groupConnect<T extends PropTypes>(state: GroupState, send: GroupSend, normalize: NormalizeProps<T>): {
5
5
  count: number;
6
6
  toasts: import("./toast.types").Service[];
7
7
  toastsByPlacement: Partial<Record<Placement, import("./toast.types").Service[]>>;
@@ -1,6 +1,6 @@
1
- import { PropTypes, ReactPropTypes } from "@zag-js/types";
1
+ import type { NormalizeProps, PropTypes } from "@zag-js/types";
2
2
  import type { Send, State } from "./toast.types";
3
- export declare function connect<T extends PropTypes = ReactPropTypes>(state: State, send: Send, normalize?: import("@zag-js/types").NormalizeProps): {
3
+ export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
4
4
  type: import("./toast.types").Type;
5
5
  title: string;
6
6
  placement: import("./toast.types").Placement;
@@ -1,4 +1,4 @@
1
- import { GroupMachineContext as GroupCtx, MachineContext as Ctx, Placement } from "./toast.types";
1
+ import type { GroupMachineContext as GroupCtx, MachineContext as Ctx, Placement } from "./toast.types";
2
2
  export declare const dom: {
3
3
  getDoc: (ctx: Ctx | GroupCtx) => Document;
4
4
  getRootNode: (ctx: Ctx | GroupCtx) => Document | ShadowRoot;
@@ -1,2 +1,2 @@
1
- import { MachineContext, MachineState, Options } from "./toast.types";
1
+ import type { MachineContext, MachineState, Options } from "./toast.types";
2
2
  export declare function createToastMachine(options?: Options): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
@@ -1,5 +1,5 @@
1
- import { Style } from "@zag-js/types";
2
- import { GroupMachineContext, MachineContext, Placement, Service, Type } from "./toast.types";
1
+ import type { Style } from "@zag-js/types";
2
+ import type { GroupMachineContext, MachineContext, Placement, Service, Type } from "./toast.types";
3
3
  export declare function getToastsByPlacement(toasts: Service[]): Partial<Record<Placement, Service[]>>;
4
4
  export declare const defaultTimeouts: Record<Type, number>;
5
5
  export declare function getToastDuration(duration: number | undefined, type: MachineContext["type"]): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/toast",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Core logic for the toast widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,9 +29,9 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.1.6",
33
- "@zag-js/dom-utils": "0.1.5",
34
- "@zag-js/types": "0.2.0",
32
+ "@zag-js/core": "0.1.7",
33
+ "@zag-js/dom-utils": "0.1.6",
34
+ "@zag-js/types": "0.2.1",
35
35
  "@zag-js/utils": "0.1.2"
36
36
  },
37
37
  "scripts": {