@zag-js/toast 0.1.16 → 0.2.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.js CHANGED
@@ -34,7 +34,7 @@ var dataAttr = (guard) => {
34
34
  var MAX_Z_INDEX = 2147483647;
35
35
  var runIfFn = (v, ...a) => {
36
36
  const res = typeof v === "function" ? v(...a) : v;
37
- return res ?? void 0;
37
+ return res != null ? res : void 0;
38
38
  };
39
39
  var cast = (v) => v;
40
40
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
@@ -46,22 +46,44 @@ function isWindow(value) {
46
46
  return (value == null ? void 0 : value.toString()) === "[object Window]";
47
47
  }
48
48
  function getDocument(el) {
49
+ var _a;
49
50
  if (isWindow(el))
50
51
  return el.document;
51
52
  if (isDocument(el))
52
53
  return el;
53
- return (el == null ? void 0 : el.ownerDocument) ?? document;
54
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
54
55
  }
55
56
  function defineDomHelpers(helpers) {
56
57
  const dom2 = {
57
58
  getRootNode: (ctx) => {
58
- var _a;
59
- return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
59
+ var _a, _b;
60
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
60
61
  },
61
62
  getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
62
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
63
+ getWin: (ctx) => {
64
+ var _a;
65
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
66
+ },
63
67
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
64
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
68
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
69
+ createEmitter: (ctx, target) => {
70
+ const win = dom2.getWin(ctx);
71
+ return function emit(evt, detail, options) {
72
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
73
+ const eventName = `zag:${evt}`;
74
+ const init = { bubbles, cancelable, composed, detail };
75
+ const event = new win.CustomEvent(eventName, init);
76
+ target.dispatchEvent(event);
77
+ };
78
+ },
79
+ createListener: (target) => {
80
+ return function listen(evt, handler) {
81
+ const eventName = `zag:${evt}`;
82
+ const listener = (e) => handler(e);
83
+ target.addEventListener(eventName, listener);
84
+ return () => target.removeEventListener(eventName, listener);
85
+ };
86
+ }
65
87
  };
66
88
  return {
67
89
  ...dom2,
@@ -87,7 +109,7 @@ function trackDocumentVisibility(_doc, callback) {
87
109
  // ../../utilities/core/dist/index.mjs
88
110
  var runIfFn2 = (v, ...a) => {
89
111
  const res = typeof v === "function" ? v(...a) : v;
90
- return res ?? void 0;
112
+ return res != null ? res : void 0;
91
113
  };
92
114
  var uuid = /* @__PURE__ */ (() => {
93
115
  let id = 0;
@@ -144,7 +166,7 @@ var defaultTimeouts = {
144
166
  custom: 5e3
145
167
  };
146
168
  function getToastDuration(duration, type) {
147
- return duration ?? defaultTimeouts[type];
169
+ return duration != null ? duration : defaultTimeouts[type];
148
170
  }
149
171
  function getGroupPlacementStyle(ctx, placement) {
150
172
  const offset = ctx.offsets;
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ var dataAttr = (guard) => {
5
5
  var MAX_Z_INDEX = 2147483647;
6
6
  var runIfFn = (v, ...a) => {
7
7
  const res = typeof v === "function" ? v(...a) : v;
8
- return res ?? void 0;
8
+ return res != null ? res : void 0;
9
9
  };
10
10
  var cast = (v) => v;
11
11
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
@@ -17,22 +17,44 @@ function isWindow(value) {
17
17
  return (value == null ? void 0 : value.toString()) === "[object Window]";
18
18
  }
19
19
  function getDocument(el) {
20
+ var _a;
20
21
  if (isWindow(el))
21
22
  return el.document;
22
23
  if (isDocument(el))
23
24
  return el;
24
- return (el == null ? void 0 : el.ownerDocument) ?? document;
25
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
25
26
  }
26
27
  function defineDomHelpers(helpers) {
27
28
  const dom2 = {
28
29
  getRootNode: (ctx) => {
29
- var _a;
30
- return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
30
+ var _a, _b;
31
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
31
32
  },
32
33
  getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
33
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
34
+ getWin: (ctx) => {
35
+ var _a;
36
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
37
+ },
34
38
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
35
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
39
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
40
+ createEmitter: (ctx, target) => {
41
+ const win = dom2.getWin(ctx);
42
+ return function emit(evt, detail, options) {
43
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
44
+ const eventName = `zag:${evt}`;
45
+ const init = { bubbles, cancelable, composed, detail };
46
+ const event = new win.CustomEvent(eventName, init);
47
+ target.dispatchEvent(event);
48
+ };
49
+ },
50
+ createListener: (target) => {
51
+ return function listen(evt, handler) {
52
+ const eventName = `zag:${evt}`;
53
+ const listener = (e) => handler(e);
54
+ target.addEventListener(eventName, listener);
55
+ return () => target.removeEventListener(eventName, listener);
56
+ };
57
+ }
36
58
  };
37
59
  return {
38
60
  ...dom2,
@@ -58,7 +80,7 @@ function trackDocumentVisibility(_doc, callback) {
58
80
  // ../../utilities/core/dist/index.mjs
59
81
  var runIfFn2 = (v, ...a) => {
60
82
  const res = typeof v === "function" ? v(...a) : v;
61
- return res ?? void 0;
83
+ return res != null ? res : void 0;
62
84
  };
63
85
  var uuid = /* @__PURE__ */ (() => {
64
86
  let id = 0;
@@ -115,7 +137,7 @@ var defaultTimeouts = {
115
137
  custom: 5e3
116
138
  };
117
139
  function getToastDuration(duration, type) {
118
- return duration ?? defaultTimeouts[type];
140
+ return duration != null ? duration : defaultTimeouts[type];
119
141
  }
120
142
  function getGroupPlacementStyle(ctx, placement) {
121
143
  const offset = ctx.offsets;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/toast",
3
- "version": "0.1.16",
3
+ "version": "0.2.0",
4
4
  "description": "Core logic for the toast widget implemented as a state machine",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -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.12",
33
- "@zag-js/types": "0.2.7"
32
+ "@zag-js/core": "0.2.0",
33
+ "@zag-js/types": "0.3.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@zag-js/dom-utils": "0.1.13",
37
- "@zag-js/utils": "0.1.6"
36
+ "@zag-js/dom-utils": "0.2.0",
37
+ "@zag-js/utils": "0.2.0"
38
38
  },
39
39
  "scripts": {
40
40
  "build-fast": "tsup src/index.ts --format=esm,cjs",