@zag-js/splitter 0.1.9 → 0.1.10

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
@@ -40,7 +40,23 @@ __export(src_exports, {
40
40
  module.exports = __toCommonJS(src_exports);
41
41
 
42
42
  // ../../utilities/dom/dist/index.mjs
43
+ var __defProp2 = Object.defineProperty;
44
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
45
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
46
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
43
47
  var __pow = Math.pow;
48
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
49
+ var __spreadValues2 = (a, b) => {
50
+ for (var prop in b || (b = {}))
51
+ if (__hasOwnProp2.call(b, prop))
52
+ __defNormalProp2(a, prop, b[prop]);
53
+ if (__getOwnPropSymbols2)
54
+ for (var prop of __getOwnPropSymbols2(b)) {
55
+ if (__propIsEnum2.call(b, prop))
56
+ __defNormalProp2(a, prop, b[prop]);
57
+ }
58
+ return a;
59
+ };
44
60
  var dataAttr = (guard) => {
45
61
  return guard ? "" : void 0;
46
62
  };
@@ -67,6 +83,36 @@ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
67
83
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
68
84
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
69
85
  var isIos = () => isApple() && !isMac();
86
+ function isDocument(el) {
87
+ return el.nodeType === Node.DOCUMENT_NODE;
88
+ }
89
+ function isWindow(value) {
90
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
91
+ }
92
+ function getDocument(el) {
93
+ var _a;
94
+ if (isWindow(el))
95
+ return el.document;
96
+ if (isDocument(el))
97
+ return el;
98
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
99
+ }
100
+ function defineDomHelpers(helpers) {
101
+ const dom2 = {
102
+ getRootNode: (ctx) => {
103
+ var _a, _b;
104
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
105
+ },
106
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
107
+ getWin: (ctx) => {
108
+ var _a;
109
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
110
+ },
111
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
112
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
113
+ };
114
+ return __spreadValues2(__spreadValues2({}, dom2), helpers);
115
+ }
70
116
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
71
117
  var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
72
118
  var supportsMouseEvent = () => isDom() && window.onmousedown === null;
@@ -286,41 +332,33 @@ function trackPointerMove(opts) {
286
332
  }
287
333
 
288
334
  // src/splitter.dom.ts
289
- var dom = {
290
- getDoc: (ctx) => {
291
- var _a;
292
- return (_a = ctx.doc) != null ? _a : document;
293
- },
294
- getRootNode: (ctx) => {
295
- var _a;
296
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
297
- },
335
+ var dom = defineDomHelpers({
298
336
  getRootId: (ctx) => {
299
337
  var _a, _b;
300
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `splitter:${ctx.uid}`;
338
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `splitter:${ctx.id}`;
301
339
  },
302
340
  getSplitterId: (ctx) => {
303
341
  var _a, _b;
304
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.splitter) != null ? _b : `splitter:${ctx.uid}:splitter`;
342
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.splitter) != null ? _b : `splitter:${ctx.id}:splitter`;
305
343
  },
306
344
  getToggleButtonId: (ctx) => {
307
345
  var _a, _b;
308
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.toggleBtn) != null ? _b : `splitter:${ctx.uid}:toggle-btn`;
346
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.toggleBtn) != null ? _b : `splitter:${ctx.id}:toggle-btn`;
309
347
  },
310
348
  getLabelId: (ctx) => {
311
349
  var _a, _b;
312
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `splitter:${ctx.uid}:label`;
350
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `splitter:${ctx.id}:label`;
313
351
  },
314
352
  getPrimaryPaneId: (ctx) => {
315
353
  var _a, _b;
316
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.primaryPane) != null ? _b : `splitter:${ctx.uid}:primary`;
354
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.primaryPane) != null ? _b : `splitter:${ctx.id}:primary`;
317
355
  },
318
356
  getSecondaryPaneId: (ctx) => {
319
357
  var _a, _b;
320
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.secondaryPane) != null ? _b : `splitter:${ctx.uid}:secondary`;
358
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.secondaryPane) != null ? _b : `splitter:${ctx.id}:secondary`;
321
359
  },
322
- getSplitterEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getSplitterId(ctx)),
323
- getPrimaryPaneEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getPrimaryPaneId(ctx)),
360
+ getSplitterEl: (ctx) => dom.getById(ctx, dom.getSplitterId(ctx)),
361
+ getPrimaryPaneEl: (ctx) => dom.getById(ctx, dom.getPrimaryPaneId(ctx)),
324
362
  getCursor(ctx) {
325
363
  if (ctx.disabled || ctx.fixed)
326
364
  return "default";
@@ -332,7 +370,7 @@ var dom = {
332
370
  cursor = x ? "w-resize" : "n-resize";
333
371
  return cursor;
334
372
  }
335
- };
373
+ });
336
374
 
337
375
  // src/splitter.connect.ts
338
376
  function connect(state2, send, normalize) {
@@ -551,12 +589,11 @@ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigit
551
589
 
552
590
  // src/splitter.machine.ts
553
591
  var { not } = import_core.guards;
554
- function machine(ctx = {}) {
592
+ function machine(ctx) {
555
593
  return (0, import_core.createMachine)({
556
594
  id: "splitter",
557
595
  initial: "unknown",
558
596
  context: __spreadValues({
559
- uid: "",
560
597
  orientation: "horizontal",
561
598
  min: 224,
562
599
  max: 340,
@@ -589,10 +626,7 @@ function machine(ctx = {}) {
589
626
  states: {
590
627
  unknown: {
591
628
  on: {
592
- SETUP: {
593
- target: "idle",
594
- actions: "setupDocument"
595
- }
629
+ SETUP: "idle"
596
630
  }
597
631
  },
598
632
  idle: {
@@ -729,13 +763,6 @@ function machine(ctx = {}) {
729
763
  var _a;
730
764
  (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
731
765
  },
732
- setupDocument(ctx2, evt) {
733
- if (evt.doc)
734
- ctx2.doc = (0, import_core.ref)(evt.doc);
735
- if (evt.root)
736
- ctx2.rootNode = (0, import_core.ref)(evt.root);
737
- ctx2.uid = evt.id;
738
- },
739
766
  setToMin(ctx2) {
740
767
  ctx2.value = ctx2.min;
741
768
  },
package/dist/index.mjs CHANGED
@@ -16,7 +16,23 @@ var __spreadValues = (a, b) => {
16
16
  };
17
17
 
18
18
  // ../../utilities/dom/dist/index.mjs
19
+ var __defProp2 = Object.defineProperty;
20
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
21
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
22
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
19
23
  var __pow = Math.pow;
24
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
25
+ var __spreadValues2 = (a, b) => {
26
+ for (var prop in b || (b = {}))
27
+ if (__hasOwnProp2.call(b, prop))
28
+ __defNormalProp2(a, prop, b[prop]);
29
+ if (__getOwnPropSymbols2)
30
+ for (var prop of __getOwnPropSymbols2(b)) {
31
+ if (__propIsEnum2.call(b, prop))
32
+ __defNormalProp2(a, prop, b[prop]);
33
+ }
34
+ return a;
35
+ };
20
36
  var dataAttr = (guard) => {
21
37
  return guard ? "" : void 0;
22
38
  };
@@ -43,6 +59,36 @@ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
43
59
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
44
60
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
45
61
  var isIos = () => isApple() && !isMac();
62
+ function isDocument(el) {
63
+ return el.nodeType === Node.DOCUMENT_NODE;
64
+ }
65
+ function isWindow(value) {
66
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
67
+ }
68
+ function getDocument(el) {
69
+ var _a;
70
+ if (isWindow(el))
71
+ return el.document;
72
+ if (isDocument(el))
73
+ return el;
74
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
75
+ }
76
+ function defineDomHelpers(helpers) {
77
+ const dom2 = {
78
+ getRootNode: (ctx) => {
79
+ var _a, _b;
80
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
81
+ },
82
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
83
+ getWin: (ctx) => {
84
+ var _a;
85
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
86
+ },
87
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
88
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
89
+ };
90
+ return __spreadValues2(__spreadValues2({}, dom2), helpers);
91
+ }
46
92
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
47
93
  var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
48
94
  var supportsMouseEvent = () => isDom() && window.onmousedown === null;
@@ -262,41 +308,33 @@ function trackPointerMove(opts) {
262
308
  }
263
309
 
264
310
  // src/splitter.dom.ts
265
- var dom = {
266
- getDoc: (ctx) => {
267
- var _a;
268
- return (_a = ctx.doc) != null ? _a : document;
269
- },
270
- getRootNode: (ctx) => {
271
- var _a;
272
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
273
- },
311
+ var dom = defineDomHelpers({
274
312
  getRootId: (ctx) => {
275
313
  var _a, _b;
276
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `splitter:${ctx.uid}`;
314
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `splitter:${ctx.id}`;
277
315
  },
278
316
  getSplitterId: (ctx) => {
279
317
  var _a, _b;
280
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.splitter) != null ? _b : `splitter:${ctx.uid}:splitter`;
318
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.splitter) != null ? _b : `splitter:${ctx.id}:splitter`;
281
319
  },
282
320
  getToggleButtonId: (ctx) => {
283
321
  var _a, _b;
284
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.toggleBtn) != null ? _b : `splitter:${ctx.uid}:toggle-btn`;
322
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.toggleBtn) != null ? _b : `splitter:${ctx.id}:toggle-btn`;
285
323
  },
286
324
  getLabelId: (ctx) => {
287
325
  var _a, _b;
288
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `splitter:${ctx.uid}:label`;
326
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `splitter:${ctx.id}:label`;
289
327
  },
290
328
  getPrimaryPaneId: (ctx) => {
291
329
  var _a, _b;
292
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.primaryPane) != null ? _b : `splitter:${ctx.uid}:primary`;
330
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.primaryPane) != null ? _b : `splitter:${ctx.id}:primary`;
293
331
  },
294
332
  getSecondaryPaneId: (ctx) => {
295
333
  var _a, _b;
296
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.secondaryPane) != null ? _b : `splitter:${ctx.uid}:secondary`;
334
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.secondaryPane) != null ? _b : `splitter:${ctx.id}:secondary`;
297
335
  },
298
- getSplitterEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getSplitterId(ctx)),
299
- getPrimaryPaneEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getPrimaryPaneId(ctx)),
336
+ getSplitterEl: (ctx) => dom.getById(ctx, dom.getSplitterId(ctx)),
337
+ getPrimaryPaneEl: (ctx) => dom.getById(ctx, dom.getPrimaryPaneId(ctx)),
300
338
  getCursor(ctx) {
301
339
  if (ctx.disabled || ctx.fixed)
302
340
  return "default";
@@ -308,7 +346,7 @@ var dom = {
308
346
  cursor = x ? "w-resize" : "n-resize";
309
347
  return cursor;
310
348
  }
311
- };
349
+ });
312
350
 
313
351
  // src/splitter.connect.ts
314
352
  function connect(state2, send, normalize) {
@@ -475,7 +513,7 @@ function connect(state2, send, normalize) {
475
513
  }
476
514
 
477
515
  // src/splitter.machine.ts
478
- import { createMachine, guards, ref } from "@zag-js/core";
516
+ import { createMachine, guards } from "@zag-js/core";
479
517
 
480
518
  // ../../utilities/number/dist/index.mjs
481
519
  var __pow2 = Math.pow;
@@ -527,12 +565,11 @@ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigit
527
565
 
528
566
  // src/splitter.machine.ts
529
567
  var { not } = guards;
530
- function machine(ctx = {}) {
568
+ function machine(ctx) {
531
569
  return createMachine({
532
570
  id: "splitter",
533
571
  initial: "unknown",
534
572
  context: __spreadValues({
535
- uid: "",
536
573
  orientation: "horizontal",
537
574
  min: 224,
538
575
  max: 340,
@@ -565,10 +602,7 @@ function machine(ctx = {}) {
565
602
  states: {
566
603
  unknown: {
567
604
  on: {
568
- SETUP: {
569
- target: "idle",
570
- actions: "setupDocument"
571
- }
605
+ SETUP: "idle"
572
606
  }
573
607
  },
574
608
  idle: {
@@ -705,13 +739,6 @@ function machine(ctx = {}) {
705
739
  var _a;
706
740
  (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
707
741
  },
708
- setupDocument(ctx2, evt) {
709
- if (evt.doc)
710
- ctx2.doc = ref(evt.doc);
711
- if (evt.root)
712
- ctx2.rootNode = ref(evt.root);
713
- ctx2.uid = evt.id;
714
- },
715
742
  setToMin(ctx2) {
716
743
  ctx2.value = ctx2.min;
717
744
  },
@@ -1,7 +1,21 @@
1
1
  import type { MachineContext as Ctx } from "./splitter.types";
2
2
  export declare const dom: {
3
- getDoc: (ctx: Ctx) => Document;
4
- getRootNode: (ctx: Ctx) => Document | ShadowRoot;
3
+ getRootNode: (ctx: {
4
+ getRootNode?: () => Node | Document | ShadowRoot;
5
+ }) => Document | ShadowRoot;
6
+ getDoc: (ctx: {
7
+ getRootNode?: () => Node | Document | ShadowRoot;
8
+ }) => Document;
9
+ getWin: (ctx: {
10
+ getRootNode?: () => Node | Document | ShadowRoot;
11
+ }) => Window & typeof globalThis;
12
+ getActiveElement: (ctx: {
13
+ getRootNode?: () => Node | Document | ShadowRoot;
14
+ }) => HTMLElement;
15
+ getById: <T_1 = HTMLElement>(ctx: {
16
+ getRootNode?: () => Node | Document | ShadowRoot;
17
+ }, id: string) => T_1;
18
+ } & {
5
19
  getRootId: (ctx: Ctx) => string;
6
20
  getSplitterId: (ctx: Ctx) => string;
7
21
  getToggleButtonId: (ctx: Ctx) => string;
@@ -10,5 +24,5 @@ export declare const dom: {
10
24
  getSecondaryPaneId: (ctx: Ctx) => string;
11
25
  getSplitterEl: (ctx: Ctx) => HTMLElement;
12
26
  getPrimaryPaneEl: (ctx: Ctx) => HTMLElement;
13
- getCursor(ctx: Ctx): any;
27
+ getCursor(ctx: Ctx): "default" | (string & {}) | "col-resize" | "e-resize" | "n-resize" | "row-resize" | "s-resize" | "w-resize";
14
28
  };
@@ -1,2 +1,2 @@
1
1
  import type { MachineContext, MachineState, UserDefinedContext } from "./splitter.types";
2
- export declare function machine(ctx?: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
2
+ export declare function machine(ctx: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
@@ -1,5 +1,5 @@
1
1
  import type { StateMachine as S } from "@zag-js/core";
2
- import type { Context, DirectionProperty } from "@zag-js/types";
2
+ import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
3
3
  declare type ElementIds = Partial<{
4
4
  root: string;
5
5
  splitter: string;
@@ -8,7 +8,7 @@ declare type ElementIds = Partial<{
8
8
  primaryPane: string;
9
9
  secondaryPane: string;
10
10
  }>;
11
- declare type PublicContext = DirectionProperty & {
11
+ declare type PublicContext = DirectionProperty & CommonProperties & {
12
12
  /**
13
13
  * The ids of the elements in the splitter. Useful for composition.
14
14
  */
@@ -65,7 +65,7 @@ declare type PublicContext = DirectionProperty & {
65
65
  */
66
66
  snapOffset: number;
67
67
  };
68
- export declare type UserDefinedContext = Partial<PublicContext>;
68
+ export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
69
69
  declare type ComputedContext = Readonly<{
70
70
  /**
71
71
  * @computed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/splitter",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Core logic for the splitter widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -30,10 +30,12 @@
30
30
  "url": "https://github.com/chakra-ui/zag/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@zag-js/core": "0.1.7",
34
- "@zag-js/dom-utils": "0.1.6",
35
- "@zag-js/number-utils": "0.1.2",
36
- "@zag-js/types": "0.2.1"
33
+ "@zag-js/core": "0.1.8",
34
+ "@zag-js/types": "0.2.2"
35
+ },
36
+ "devDependencies": {
37
+ "@zag-js/dom-utils": "0.1.7",
38
+ "@zag-js/number-utils": "0.1.2"
37
39
  },
38
40
  "scripts": {
39
41
  "build:fast": "zag build",