@zag-js/splitter 0.6.0 → 0.8.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.
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-HPRMFGOY.mjs";
4
4
  import {
5
5
  dom
6
- } from "./chunk-BSW3DTW4.mjs";
6
+ } from "./chunk-G4OIUPPJ.mjs";
7
7
  import {
8
8
  getHandleBounds
9
9
  } from "./chunk-MV44GBQY.mjs";
@@ -1,11 +1,11 @@
1
1
  // src/splitter.dom.ts
2
2
  import { createScope, queryAll } from "@zag-js/dom-query";
3
3
  var dom = createScope({
4
- getRootId: (ctx) => `splitter:${ctx.id}`,
5
- getResizeTriggerId: (ctx, id) => `splitter:${ctx.id}:splitter:${id}`,
6
- getToggleTriggerId: (ctx) => `splitter:${ctx.id}:toggle-btn`,
7
- getLabelId: (ctx) => `splitter:${ctx.id}:label`,
8
- getPanelId: (ctx, id) => `splitter:${ctx.id}:panel:${id}`,
4
+ getRootId: (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`,
5
+ getResizeTriggerId: (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`,
6
+ getToggleTriggerId: (ctx) => ctx.ids?.toggleTrigger?.(ctx.id) ?? `splitter:${ctx.id}:toggle-btn`,
7
+ getLabelId: (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`,
8
+ getPanelId: (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`,
9
9
  globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
10
10
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
11
11
  getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dom
3
- } from "./chunk-BSW3DTW4.mjs";
3
+ } from "./chunk-G4OIUPPJ.mjs";
4
4
  import {
5
5
  clamp,
6
6
  getHandleBounds,
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { anatomy } from './splitter.anatomy.js';
2
2
  export { connect } from './splitter.connect.js';
3
3
  export { machine } from './splitter.machine.js';
4
- export { UserDefinedContext as Context, MachineState } from './splitter.types.js';
4
+ export { UserDefinedContext as Context, MachineState, PanelProps, ResizeTriggerProps } from './splitter.types.js';
5
5
  import '@zag-js/anatomy';
6
6
  import '@zag-js/types';
7
7
  import '@zag-js/core';
package/dist/index.js CHANGED
@@ -38,11 +38,11 @@ var import_dom_query2 = require("@zag-js/dom-query");
38
38
  // src/splitter.dom.ts
39
39
  var import_dom_query = require("@zag-js/dom-query");
40
40
  var dom = (0, import_dom_query.createScope)({
41
- getRootId: (ctx) => `splitter:${ctx.id}`,
42
- getResizeTriggerId: (ctx, id) => `splitter:${ctx.id}:splitter:${id}`,
43
- getToggleTriggerId: (ctx) => `splitter:${ctx.id}:toggle-btn`,
44
- getLabelId: (ctx) => `splitter:${ctx.id}:label`,
45
- getPanelId: (ctx, id) => `splitter:${ctx.id}:panel:${id}`,
41
+ getRootId: (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`,
42
+ getResizeTriggerId: (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`,
43
+ getToggleTriggerId: (ctx) => ctx.ids?.toggleTrigger?.(ctx.id) ?? `splitter:${ctx.id}:toggle-btn`,
44
+ getLabelId: (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`,
45
+ getPanelId: (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`,
46
46
  globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
47
47
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
48
48
  getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-CQT32RFW.mjs";
3
+ } from "./chunk-ECKRJG7O.mjs";
4
4
  import {
5
5
  anatomy
6
6
  } from "./chunk-HPRMFGOY.mjs";
7
7
  import {
8
8
  machine
9
- } from "./chunk-AWUYJLPO.mjs";
10
- import "./chunk-BSW3DTW4.mjs";
9
+ } from "./chunk-PI3URGYH.mjs";
10
+ import "./chunk-G4OIUPPJ.mjs";
11
11
  import "./chunk-MV44GBQY.mjs";
12
12
  export {
13
13
  anatomy,
@@ -34,11 +34,11 @@ var parts = anatomy.build();
34
34
  // src/splitter.dom.ts
35
35
  var import_dom_query = require("@zag-js/dom-query");
36
36
  var dom = (0, import_dom_query.createScope)({
37
- getRootId: (ctx) => `splitter:${ctx.id}`,
38
- getResizeTriggerId: (ctx, id) => `splitter:${ctx.id}:splitter:${id}`,
39
- getToggleTriggerId: (ctx) => `splitter:${ctx.id}:toggle-btn`,
40
- getLabelId: (ctx) => `splitter:${ctx.id}:label`,
41
- getPanelId: (ctx, id) => `splitter:${ctx.id}:panel:${id}`,
37
+ getRootId: (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`,
38
+ getResizeTriggerId: (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`,
39
+ getToggleTriggerId: (ctx) => ctx.ids?.toggleTrigger?.(ctx.id) ?? `splitter:${ctx.id}:toggle-btn`,
40
+ getLabelId: (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`,
41
+ getPanelId: (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`,
42
42
  globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
43
43
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
44
44
  getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-CQT32RFW.mjs";
3
+ } from "./chunk-ECKRJG7O.mjs";
4
4
  import "./chunk-HPRMFGOY.mjs";
5
- import "./chunk-BSW3DTW4.mjs";
5
+ import "./chunk-G4OIUPPJ.mjs";
6
6
  import "./chunk-MV44GBQY.mjs";
7
7
  export {
8
8
  connect
@@ -25,7 +25,7 @@ declare const dom: {
25
25
  getRootId: (ctx: MachineContext) => string;
26
26
  getResizeTriggerId: (ctx: MachineContext, id: string) => string;
27
27
  getToggleTriggerId: (ctx: MachineContext) => string;
28
- getLabelId: (ctx: MachineContext) => string;
28
+ getLabelId: (ctx: MachineContext) => string | ((id: string) => string);
29
29
  getPanelId: (ctx: MachineContext, id: string | number) => string;
30
30
  globalCursorId: (ctx: MachineContext) => string;
31
31
  getRootEl: (ctx: MachineContext) => HTMLElement | null;
@@ -25,11 +25,11 @@ __export(splitter_dom_exports, {
25
25
  module.exports = __toCommonJS(splitter_dom_exports);
26
26
  var import_dom_query = require("@zag-js/dom-query");
27
27
  var dom = (0, import_dom_query.createScope)({
28
- getRootId: (ctx) => `splitter:${ctx.id}`,
29
- getResizeTriggerId: (ctx, id) => `splitter:${ctx.id}:splitter:${id}`,
30
- getToggleTriggerId: (ctx) => `splitter:${ctx.id}:toggle-btn`,
31
- getLabelId: (ctx) => `splitter:${ctx.id}:label`,
32
- getPanelId: (ctx, id) => `splitter:${ctx.id}:panel:${id}`,
28
+ getRootId: (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`,
29
+ getResizeTriggerId: (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`,
30
+ getToggleTriggerId: (ctx) => ctx.ids?.toggleTrigger?.(ctx.id) ?? `splitter:${ctx.id}:toggle-btn`,
31
+ getLabelId: (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`,
32
+ getPanelId: (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`,
33
33
  globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
34
34
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
35
35
  getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dom
3
- } from "./chunk-BSW3DTW4.mjs";
3
+ } from "./chunk-G4OIUPPJ.mjs";
4
4
  export {
5
5
  dom
6
6
  };
@@ -31,11 +31,11 @@ var import_utils = require("@zag-js/utils");
31
31
  // src/splitter.dom.ts
32
32
  var import_dom_query = require("@zag-js/dom-query");
33
33
  var dom = (0, import_dom_query.createScope)({
34
- getRootId: (ctx) => `splitter:${ctx.id}`,
35
- getResizeTriggerId: (ctx, id) => `splitter:${ctx.id}:splitter:${id}`,
36
- getToggleTriggerId: (ctx) => `splitter:${ctx.id}:toggle-btn`,
37
- getLabelId: (ctx) => `splitter:${ctx.id}:label`,
38
- getPanelId: (ctx, id) => `splitter:${ctx.id}:panel:${id}`,
34
+ getRootId: (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`,
35
+ getResizeTriggerId: (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`,
36
+ getToggleTriggerId: (ctx) => ctx.ids?.toggleTrigger?.(ctx.id) ?? `splitter:${ctx.id}:toggle-btn`,
37
+ getLabelId: (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`,
38
+ getPanelId: (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`,
39
39
  globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
40
40
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
41
41
  getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-AWUYJLPO.mjs";
4
- import "./chunk-BSW3DTW4.mjs";
3
+ } from "./chunk-PI3URGYH.mjs";
4
+ import "./chunk-G4OIUPPJ.mjs";
5
5
  import "./chunk-MV44GBQY.mjs";
6
6
  export {
7
7
  machine
@@ -12,12 +12,38 @@ type ResizeDetails = {
12
12
  size: PanelSizeData[];
13
13
  activeHandleId: string | null;
14
14
  };
15
+ type ElementIds = Partial<{
16
+ root: string;
17
+ resizeTrigger(id: string): string;
18
+ toggleTrigger(id: string): string;
19
+ label(id: string): string;
20
+ panel(id: string | number): string;
21
+ }>;
15
22
  type PublicContext = DirectionProperty & CommonProperties & {
23
+ /**
24
+ * The orientation of the splitter. Can be `horizontal` or `vertical`
25
+ */
16
26
  orientation: "horizontal" | "vertical";
27
+ /**
28
+ * The size data of the panels
29
+ */
17
30
  size: PanelSizeData[];
31
+ /**
32
+ * Function called when the splitter is resized.
33
+ */
18
34
  onResize?: (details: ResizeDetails) => void;
35
+ /**
36
+ * Function called when the splitter resize starts.
37
+ */
19
38
  onResizeStart?: (details: ResizeDetails) => void;
39
+ /**
40
+ * Function called when the splitter resize ends.
41
+ */
20
42
  onResizeEnd?: (details: ResizeDetails) => void;
43
+ /**
44
+ * The ids of the elements in the splitter. Useful for composition.
45
+ */
46
+ ids?: ElementIds;
21
47
  };
22
48
  type UserDefinedContext = RequiredBy<PublicContext, "id">;
23
49
  type NormalizedPanelData = Array<Required<PanelSizeData> & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/splitter",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Core logic for the splitter widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@zag-js/anatomy": "0.1.4",
31
- "@zag-js/core": "0.5.0",
31
+ "@zag-js/core": "0.7.0",
32
32
  "@zag-js/types": "0.5.0",
33
33
  "@zag-js/dom-query": "0.1.4",
34
- "@zag-js/dom-event": "0.6.0",
34
+ "@zag-js/dom-event": "0.8.0",
35
35
  "@zag-js/number-utils": "0.2.3",
36
36
  "@zag-js/utils": "0.3.4"
37
37
  },