@zag-js/splitter 0.1.15 → 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
@@ -31,7 +31,7 @@ var dataAttr = (guard) => {
31
31
  };
32
32
  var runIfFn = (v, ...a) => {
33
33
  const res = typeof v === "function" ? v(...a) : v;
34
- return res ?? void 0;
34
+ return res != null ? res : void 0;
35
35
  };
36
36
  var callAll = (...fns) => (...a) => {
37
37
  fns.forEach(function(fn) {
@@ -43,8 +43,9 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
43
43
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
44
44
  var isDom = () => typeof window !== "undefined";
45
45
  function getPlatform() {
46
+ var _a;
46
47
  const agent = navigator.userAgentData;
47
- return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
48
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
48
49
  }
49
50
  var pt = (v) => isDom() && v.test(getPlatform());
50
51
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
@@ -58,22 +59,44 @@ function isWindow(value) {
58
59
  return (value == null ? void 0 : value.toString()) === "[object Window]";
59
60
  }
60
61
  function getDocument(el) {
62
+ var _a;
61
63
  if (isWindow(el))
62
64
  return el.document;
63
65
  if (isDocument(el))
64
66
  return el;
65
- return (el == null ? void 0 : el.ownerDocument) ?? document;
67
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
66
68
  }
67
69
  function defineDomHelpers(helpers) {
68
70
  const dom2 = {
69
71
  getRootNode: (ctx) => {
70
- var _a;
71
- return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
72
+ var _a, _b;
73
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
72
74
  },
73
75
  getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
74
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
76
+ getWin: (ctx) => {
77
+ var _a;
78
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
79
+ },
75
80
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
76
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
81
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
82
+ createEmitter: (ctx, target) => {
83
+ const win = dom2.getWin(ctx);
84
+ return function emit(evt, detail, options) {
85
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
86
+ const eventName = `zag:${evt}`;
87
+ const init = { bubbles, cancelable, composed, detail };
88
+ const event = new win.CustomEvent(eventName, init);
89
+ target.dispatchEvent(event);
90
+ };
91
+ },
92
+ createListener: (target) => {
93
+ return function listen(evt, handler) {
94
+ const eventName = `zag:${evt}`;
95
+ const listener = (e) => handler(e);
96
+ target.addEventListener(eventName, listener);
97
+ return () => target.removeEventListener(eventName, listener);
98
+ };
99
+ }
77
100
  };
78
101
  return {
79
102
  ...dom2,
@@ -128,9 +151,10 @@ var sameKeyMap = {
128
151
  Right: "ArrowRight"
129
152
  };
130
153
  function getEventKey(event, options = {}) {
154
+ var _a;
131
155
  const { dir = "ltr", orientation = "horizontal" } = options;
132
156
  let { key } = event;
133
- key = sameKeyMap[key] ?? key;
157
+ key = (_a = sameKeyMap[key]) != null ? _a : key;
134
158
  const isRtl = dir === "rtl" && orientation === "horizontal";
135
159
  if (isRtl && key in rtlKeyMap) {
136
160
  key = rtlKeyMap[key];
@@ -167,7 +191,8 @@ function addDomEvent(target, eventName, handler, options) {
167
191
  };
168
192
  }
169
193
  function addPointerEvent(target, event, listener, options) {
170
- const type = getEventName(event) ?? event;
194
+ var _a;
195
+ const type = (_a = getEventName(event)) != null ? _a : event;
171
196
  return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
172
197
  }
173
198
  function wrapHandler(fn, filter = false) {
@@ -178,7 +203,8 @@ function wrapHandler(fn, filter = false) {
178
203
  }
179
204
  function filterPrimaryPointer(fn) {
180
205
  return (event) => {
181
- const win = event.view ?? window;
206
+ var _a;
207
+ const win = (_a = event.view) != null ? _a : window;
182
208
  const isMouseEvent2 = event instanceof win.MouseEvent;
183
209
  const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
184
210
  if (isPrimary)
@@ -233,7 +259,7 @@ var state = "default";
233
259
  var savedUserSelect = "";
234
260
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
235
261
  function disableTextSelection({ target, doc } = {}) {
236
- const _document = doc ?? document;
262
+ const _document = doc != null ? doc : document;
237
263
  if (isIos()) {
238
264
  if (state === "default") {
239
265
  savedUserSelect = _document.documentElement.style.webkitUserSelect;
@@ -247,7 +273,7 @@ function disableTextSelection({ target, doc } = {}) {
247
273
  return () => restoreTextSelection({ target, doc: _document });
248
274
  }
249
275
  function restoreTextSelection({ target, doc } = {}) {
250
- const _document = doc ?? document;
276
+ const _document = doc != null ? doc : document;
251
277
  if (isIos()) {
252
278
  if (state !== "disabled")
253
279
  return;
@@ -267,7 +293,7 @@ function restoreTextSelection({ target, doc } = {}) {
267
293
  if (target && modifiedElementMap.has(target)) {
268
294
  let targetOldUserSelect = modifiedElementMap.get(target);
269
295
  if (target.style.userSelect === "none") {
270
- target.style.userSelect = targetOldUserSelect ?? "";
296
+ target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
271
297
  }
272
298
  if (target.getAttribute("style") === "") {
273
299
  target.removeAttribute("style");
@@ -302,28 +328,28 @@ function trackPointerMove(doc, opts) {
302
328
  // src/splitter.dom.ts
303
329
  var dom = defineDomHelpers({
304
330
  getRootId: (ctx) => {
305
- var _a;
306
- return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `splitter:${ctx.id}`;
331
+ var _a, _b;
332
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `splitter:${ctx.id}`;
307
333
  },
308
334
  getSplitterId: (ctx) => {
309
- var _a;
310
- return ((_a = ctx.ids) == null ? void 0 : _a.splitter) ?? `splitter:${ctx.id}:splitter`;
335
+ var _a, _b;
336
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.splitter) != null ? _b : `splitter:${ctx.id}:splitter`;
311
337
  },
312
338
  getToggleButtonId: (ctx) => {
313
- var _a;
314
- return ((_a = ctx.ids) == null ? void 0 : _a.toggleBtn) ?? `splitter:${ctx.id}:toggle-btn`;
339
+ var _a, _b;
340
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.toggleBtn) != null ? _b : `splitter:${ctx.id}:toggle-btn`;
315
341
  },
316
342
  getLabelId: (ctx) => {
317
- var _a;
318
- return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `splitter:${ctx.id}:label`;
343
+ var _a, _b;
344
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `splitter:${ctx.id}:label`;
319
345
  },
320
346
  getPrimaryPaneId: (ctx) => {
321
- var _a;
322
- return ((_a = ctx.ids) == null ? void 0 : _a.primaryPane) ?? `splitter:${ctx.id}:primary`;
347
+ var _a, _b;
348
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.primaryPane) != null ? _b : `splitter:${ctx.id}:primary`;
323
349
  },
324
350
  getSecondaryPaneId: (ctx) => {
325
- var _a;
326
- return ((_a = ctx.ids) == null ? void 0 : _a.secondaryPane) ?? `splitter:${ctx.id}:secondary`;
351
+ var _a, _b;
352
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.secondaryPane) != null ? _b : `splitter:${ctx.id}:secondary`;
327
353
  },
328
354
  getSplitterEl: (ctx) => dom.getById(ctx, dom.getSplitterId(ctx)),
329
355
  getPrimaryPaneEl: (ctx) => dom.getById(ctx, dom.getPrimaryPaneId(ctx)),
@@ -511,7 +537,7 @@ var import_core = require("@zag-js/core");
511
537
  // ../../utilities/number/dist/index.mjs
512
538
  function round(v, t) {
513
539
  let num = valueOf(v);
514
- const p = 10 ** (t ?? 10);
540
+ const p = 10 ** (t != null ? t : 10);
515
541
  num = Math.round(num * p) / p;
516
542
  return t ? num.toFixed(t) : v.toString();
517
543
  }
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ var dataAttr = (guard) => {
4
4
  };
5
5
  var runIfFn = (v, ...a) => {
6
6
  const res = typeof v === "function" ? v(...a) : v;
7
- return res ?? void 0;
7
+ return res != null ? res : void 0;
8
8
  };
9
9
  var callAll = (...fns) => (...a) => {
10
10
  fns.forEach(function(fn) {
@@ -16,8 +16,9 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
16
16
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
17
17
  var isDom = () => typeof window !== "undefined";
18
18
  function getPlatform() {
19
+ var _a;
19
20
  const agent = navigator.userAgentData;
20
- return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
21
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
21
22
  }
22
23
  var pt = (v) => isDom() && v.test(getPlatform());
23
24
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
@@ -31,22 +32,44 @@ function isWindow(value) {
31
32
  return (value == null ? void 0 : value.toString()) === "[object Window]";
32
33
  }
33
34
  function getDocument(el) {
35
+ var _a;
34
36
  if (isWindow(el))
35
37
  return el.document;
36
38
  if (isDocument(el))
37
39
  return el;
38
- return (el == null ? void 0 : el.ownerDocument) ?? document;
40
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
39
41
  }
40
42
  function defineDomHelpers(helpers) {
41
43
  const dom2 = {
42
44
  getRootNode: (ctx) => {
43
- var _a;
44
- return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
45
+ var _a, _b;
46
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
45
47
  },
46
48
  getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
47
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
49
+ getWin: (ctx) => {
50
+ var _a;
51
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
52
+ },
48
53
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
49
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
54
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
55
+ createEmitter: (ctx, target) => {
56
+ const win = dom2.getWin(ctx);
57
+ return function emit(evt, detail, options) {
58
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
59
+ const eventName = `zag:${evt}`;
60
+ const init = { bubbles, cancelable, composed, detail };
61
+ const event = new win.CustomEvent(eventName, init);
62
+ target.dispatchEvent(event);
63
+ };
64
+ },
65
+ createListener: (target) => {
66
+ return function listen(evt, handler) {
67
+ const eventName = `zag:${evt}`;
68
+ const listener = (e) => handler(e);
69
+ target.addEventListener(eventName, listener);
70
+ return () => target.removeEventListener(eventName, listener);
71
+ };
72
+ }
50
73
  };
51
74
  return {
52
75
  ...dom2,
@@ -101,9 +124,10 @@ var sameKeyMap = {
101
124
  Right: "ArrowRight"
102
125
  };
103
126
  function getEventKey(event, options = {}) {
127
+ var _a;
104
128
  const { dir = "ltr", orientation = "horizontal" } = options;
105
129
  let { key } = event;
106
- key = sameKeyMap[key] ?? key;
130
+ key = (_a = sameKeyMap[key]) != null ? _a : key;
107
131
  const isRtl = dir === "rtl" && orientation === "horizontal";
108
132
  if (isRtl && key in rtlKeyMap) {
109
133
  key = rtlKeyMap[key];
@@ -140,7 +164,8 @@ function addDomEvent(target, eventName, handler, options) {
140
164
  };
141
165
  }
142
166
  function addPointerEvent(target, event, listener, options) {
143
- const type = getEventName(event) ?? event;
167
+ var _a;
168
+ const type = (_a = getEventName(event)) != null ? _a : event;
144
169
  return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
145
170
  }
146
171
  function wrapHandler(fn, filter = false) {
@@ -151,7 +176,8 @@ function wrapHandler(fn, filter = false) {
151
176
  }
152
177
  function filterPrimaryPointer(fn) {
153
178
  return (event) => {
154
- const win = event.view ?? window;
179
+ var _a;
180
+ const win = (_a = event.view) != null ? _a : window;
155
181
  const isMouseEvent2 = event instanceof win.MouseEvent;
156
182
  const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
157
183
  if (isPrimary)
@@ -206,7 +232,7 @@ var state = "default";
206
232
  var savedUserSelect = "";
207
233
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
208
234
  function disableTextSelection({ target, doc } = {}) {
209
- const _document = doc ?? document;
235
+ const _document = doc != null ? doc : document;
210
236
  if (isIos()) {
211
237
  if (state === "default") {
212
238
  savedUserSelect = _document.documentElement.style.webkitUserSelect;
@@ -220,7 +246,7 @@ function disableTextSelection({ target, doc } = {}) {
220
246
  return () => restoreTextSelection({ target, doc: _document });
221
247
  }
222
248
  function restoreTextSelection({ target, doc } = {}) {
223
- const _document = doc ?? document;
249
+ const _document = doc != null ? doc : document;
224
250
  if (isIos()) {
225
251
  if (state !== "disabled")
226
252
  return;
@@ -240,7 +266,7 @@ function restoreTextSelection({ target, doc } = {}) {
240
266
  if (target && modifiedElementMap.has(target)) {
241
267
  let targetOldUserSelect = modifiedElementMap.get(target);
242
268
  if (target.style.userSelect === "none") {
243
- target.style.userSelect = targetOldUserSelect ?? "";
269
+ target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
244
270
  }
245
271
  if (target.getAttribute("style") === "") {
246
272
  target.removeAttribute("style");
@@ -275,28 +301,28 @@ function trackPointerMove(doc, opts) {
275
301
  // src/splitter.dom.ts
276
302
  var dom = defineDomHelpers({
277
303
  getRootId: (ctx) => {
278
- var _a;
279
- return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `splitter:${ctx.id}`;
304
+ var _a, _b;
305
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `splitter:${ctx.id}`;
280
306
  },
281
307
  getSplitterId: (ctx) => {
282
- var _a;
283
- return ((_a = ctx.ids) == null ? void 0 : _a.splitter) ?? `splitter:${ctx.id}:splitter`;
308
+ var _a, _b;
309
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.splitter) != null ? _b : `splitter:${ctx.id}:splitter`;
284
310
  },
285
311
  getToggleButtonId: (ctx) => {
286
- var _a;
287
- return ((_a = ctx.ids) == null ? void 0 : _a.toggleBtn) ?? `splitter:${ctx.id}:toggle-btn`;
312
+ var _a, _b;
313
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.toggleBtn) != null ? _b : `splitter:${ctx.id}:toggle-btn`;
288
314
  },
289
315
  getLabelId: (ctx) => {
290
- var _a;
291
- return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `splitter:${ctx.id}:label`;
316
+ var _a, _b;
317
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `splitter:${ctx.id}:label`;
292
318
  },
293
319
  getPrimaryPaneId: (ctx) => {
294
- var _a;
295
- return ((_a = ctx.ids) == null ? void 0 : _a.primaryPane) ?? `splitter:${ctx.id}:primary`;
320
+ var _a, _b;
321
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.primaryPane) != null ? _b : `splitter:${ctx.id}:primary`;
296
322
  },
297
323
  getSecondaryPaneId: (ctx) => {
298
- var _a;
299
- return ((_a = ctx.ids) == null ? void 0 : _a.secondaryPane) ?? `splitter:${ctx.id}:secondary`;
324
+ var _a, _b;
325
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.secondaryPane) != null ? _b : `splitter:${ctx.id}:secondary`;
300
326
  },
301
327
  getSplitterEl: (ctx) => dom.getById(ctx, dom.getSplitterId(ctx)),
302
328
  getPrimaryPaneEl: (ctx) => dom.getById(ctx, dom.getPrimaryPaneId(ctx)),
@@ -484,7 +510,7 @@ import { createMachine, guards } from "@zag-js/core";
484
510
  // ../../utilities/number/dist/index.mjs
485
511
  function round(v, t) {
486
512
  let num = valueOf(v);
487
- const p = 10 ** (t ?? 10);
513
+ const p = 10 ** (t != null ? t : 10);
488
514
  num = Math.round(num * p) / p;
489
515
  return t ? num.toFixed(t) : v.toString();
490
516
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/splitter",
3
- "version": "0.1.15",
3
+ "version": "0.2.0",
4
4
  "description": "Core logic for the splitter widget implemented as a state machine",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -30,12 +30,12 @@
30
30
  "url": "https://github.com/chakra-ui/zag/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@zag-js/core": "0.1.12",
34
- "@zag-js/types": "0.2.7"
33
+ "@zag-js/core": "0.2.0",
34
+ "@zag-js/types": "0.3.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@zag-js/dom-utils": "0.1.13",
38
- "@zag-js/number-utils": "0.1.6"
37
+ "@zag-js/dom-utils": "0.2.0",
38
+ "@zag-js/number-utils": "0.2.0"
39
39
  },
40
40
  "scripts": {
41
41
  "build-fast": "tsup src/index.ts --format=esm,cjs",