@zag-js/splitter 0.10.0 → 0.10.1

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.
@@ -15,6 +15,7 @@ function connect(state, send, normalize) {
15
15
  const isHorizontal = state.context.isHorizontal;
16
16
  const isFocused = state.hasTag("focus");
17
17
  const isDragging = state.matches("dragging");
18
+ const panels = state.context.panels;
18
19
  const api = {
19
20
  /**
20
21
  * Whether the splitter is focused.
@@ -29,22 +30,18 @@ function connect(state, send, normalize) {
29
30
  */
30
31
  bounds: getHandleBounds(state.context),
31
32
  /**
32
- * Function to collapse a panel.
33
+ * Function to set a panel to its minimum size.
33
34
  */
34
- collapse(id) {
35
- send({ type: "COLLAPSE", id });
35
+ setToMinSize(id) {
36
+ const panel = panels.find((panel2) => panel2.id === id);
37
+ send({ type: "SET_SIZE", id, size: panel?.minSize, src: "collapse" });
36
38
  },
37
39
  /**
38
- * Function to expand a panel.
40
+ * Function to set a panel to its maximum size.
39
41
  */
40
- expand(id) {
41
- send({ type: "EXPAND", id });
42
- },
43
- /**
44
- * Function to toggle a panel between collapsed and expanded.
45
- */
46
- toggle(id) {
47
- send({ type: "TOGGLE", id });
42
+ setToMaxSize(id) {
43
+ const panel = panels.find((panel2) => panel2.id === id);
44
+ send({ type: "SET_SIZE", id, size: panel?.maxSize, src: "expand" });
48
45
  },
49
46
  /**
50
47
  * Function to set the size of a panel.
@@ -59,13 +56,13 @@ function connect(state, send, normalize) {
59
56
  const { id, disabled } = props;
60
57
  const ids = id.split(":");
61
58
  const panelIds = ids.map((id2) => dom.getPanelId(state.context, id2));
62
- const panels = getHandleBounds(state.context, id);
59
+ const panels2 = getHandleBounds(state.context, id);
63
60
  return {
64
61
  isDisabled: !!disabled,
65
62
  isFocused: state.context.activeResizeId === id && isFocused,
66
63
  panelIds,
67
- min: panels?.min,
68
- max: panels?.max,
64
+ min: panels2?.min,
65
+ max: panels2?.max,
69
66
  value: 0
70
67
  };
71
68
  },
@@ -92,14 +89,6 @@ function connect(state, send, normalize) {
92
89
  style: dom.getPanelStyle(state.context, id)
93
90
  });
94
91
  },
95
- // toggleTriggerProps: normalize.element({
96
- // ...parts.toggleButton.attrs,
97
- // id: dom.getToggleButtonId(state.context),
98
- // "aria-label": state.context.isAtMin ? "Expand Primary Pane" : "Collapse Primary Pane",
99
- // onClick() {
100
- // send("TOGGLE")
101
- // },
102
- // }),
103
92
  getResizeTriggerProps(props) {
104
93
  const { id, disabled, step = 1 } = props;
105
94
  const triggerState = api.getResizeTriggerState(props);
@@ -55,7 +55,10 @@ function machine(userContext) {
55
55
  {
56
56
  actions: "setStartPanelToMin"
57
57
  }
58
- ]
58
+ ],
59
+ SET_SIZE: {
60
+ actions: "setPanelSize"
61
+ }
59
62
  },
60
63
  states: {
61
64
  idle: {
@@ -202,6 +205,13 @@ function machine(userContext) {
202
205
  size: panel.size
203
206
  }));
204
207
  },
208
+ setPanelSize(ctx2, evt) {
209
+ const { id, size } = evt;
210
+ ctx2.size = ctx2.size.map((panel) => {
211
+ const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
212
+ return panel.id === id ? { ...panel, size: panelSize } : panel;
213
+ });
214
+ },
205
215
  setStartPanelToMin(ctx2) {
206
216
  const bounds = getPanelBounds(ctx2);
207
217
  if (!bounds)
package/dist/index.js CHANGED
@@ -219,6 +219,7 @@ function connect(state, send, normalize) {
219
219
  const isHorizontal = state.context.isHorizontal;
220
220
  const isFocused = state.hasTag("focus");
221
221
  const isDragging = state.matches("dragging");
222
+ const panels = state.context.panels;
222
223
  const api = {
223
224
  /**
224
225
  * Whether the splitter is focused.
@@ -233,22 +234,18 @@ function connect(state, send, normalize) {
233
234
  */
234
235
  bounds: getHandleBounds(state.context),
235
236
  /**
236
- * Function to collapse a panel.
237
+ * Function to set a panel to its minimum size.
237
238
  */
238
- collapse(id) {
239
- send({ type: "COLLAPSE", id });
239
+ setToMinSize(id) {
240
+ const panel = panels.find((panel2) => panel2.id === id);
241
+ send({ type: "SET_SIZE", id, size: panel?.minSize, src: "collapse" });
240
242
  },
241
243
  /**
242
- * Function to expand a panel.
244
+ * Function to set a panel to its maximum size.
243
245
  */
244
- expand(id) {
245
- send({ type: "EXPAND", id });
246
- },
247
- /**
248
- * Function to toggle a panel between collapsed and expanded.
249
- */
250
- toggle(id) {
251
- send({ type: "TOGGLE", id });
246
+ setToMaxSize(id) {
247
+ const panel = panels.find((panel2) => panel2.id === id);
248
+ send({ type: "SET_SIZE", id, size: panel?.maxSize, src: "expand" });
252
249
  },
253
250
  /**
254
251
  * Function to set the size of a panel.
@@ -263,13 +260,13 @@ function connect(state, send, normalize) {
263
260
  const { id, disabled } = props;
264
261
  const ids = id.split(":");
265
262
  const panelIds = ids.map((id2) => dom.getPanelId(state.context, id2));
266
- const panels = getHandleBounds(state.context, id);
263
+ const panels2 = getHandleBounds(state.context, id);
267
264
  return {
268
265
  isDisabled: !!disabled,
269
266
  isFocused: state.context.activeResizeId === id && isFocused,
270
267
  panelIds,
271
- min: panels?.min,
272
- max: panels?.max,
268
+ min: panels2?.min,
269
+ max: panels2?.max,
273
270
  value: 0
274
271
  };
275
272
  },
@@ -296,14 +293,6 @@ function connect(state, send, normalize) {
296
293
  style: dom.getPanelStyle(state.context, id)
297
294
  });
298
295
  },
299
- // toggleTriggerProps: normalize.element({
300
- // ...parts.toggleButton.attrs,
301
- // id: dom.getToggleButtonId(state.context),
302
- // "aria-label": state.context.isAtMin ? "Expand Primary Pane" : "Collapse Primary Pane",
303
- // onClick() {
304
- // send("TOGGLE")
305
- // },
306
- // }),
307
296
  getResizeTriggerProps(props) {
308
297
  const { id, disabled, step = 1 } = props;
309
298
  const triggerState = api.getResizeTriggerState(props);
@@ -446,7 +435,10 @@ function machine(userContext) {
446
435
  {
447
436
  actions: "setStartPanelToMin"
448
437
  }
449
- ]
438
+ ],
439
+ SET_SIZE: {
440
+ actions: "setPanelSize"
441
+ }
450
442
  },
451
443
  states: {
452
444
  idle: {
@@ -593,6 +585,13 @@ function machine(userContext) {
593
585
  size: panel.size
594
586
  }));
595
587
  },
588
+ setPanelSize(ctx2, evt) {
589
+ const { id, size } = evt;
590
+ ctx2.size = ctx2.size.map((panel) => {
591
+ const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
592
+ return panel.id === id ? { ...panel, size: panelSize } : panel;
593
+ });
594
+ },
596
595
  setStartPanelToMin(ctx2) {
597
596
  const bounds = getPanelBounds(ctx2);
598
597
  if (!bounds)
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-FCVFZHPC.mjs";
3
+ } from "./chunk-53T2VZ2R.mjs";
4
4
  import {
5
5
  anatomy
6
6
  } from "./chunk-HPRMFGOY.mjs";
7
7
  import {
8
8
  machine
9
- } from "./chunk-64C2WGI5.mjs";
9
+ } from "./chunk-X2E2LAC5.mjs";
10
10
  import "./chunk-3GDOPT5W.mjs";
11
11
  import "./chunk-MV44GBQY.mjs";
12
12
  export {
@@ -19,17 +19,13 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
19
19
  max: number;
20
20
  } | undefined;
21
21
  /**
22
- * Function to collapse a panel.
22
+ * Function to set a panel to its minimum size.
23
23
  */
24
- collapse(id: PanelId): void;
24
+ setToMinSize(id: PanelId): void;
25
25
  /**
26
- * Function to expand a panel.
26
+ * Function to set a panel to its maximum size.
27
27
  */
28
- expand(id: PanelId): void;
29
- /**
30
- * Function to toggle a panel between collapsed and expanded.
31
- */
32
- toggle(id: PanelId): void;
28
+ setToMaxSize(id: PanelId): void;
33
29
  /**
34
30
  * Function to set the size of a panel.
35
31
  */
@@ -126,6 +126,7 @@ function connect(state, send, normalize) {
126
126
  const isHorizontal = state.context.isHorizontal;
127
127
  const isFocused = state.hasTag("focus");
128
128
  const isDragging = state.matches("dragging");
129
+ const panels = state.context.panels;
129
130
  const api = {
130
131
  /**
131
132
  * Whether the splitter is focused.
@@ -140,22 +141,18 @@ function connect(state, send, normalize) {
140
141
  */
141
142
  bounds: getHandleBounds(state.context),
142
143
  /**
143
- * Function to collapse a panel.
144
+ * Function to set a panel to its minimum size.
144
145
  */
145
- collapse(id) {
146
- send({ type: "COLLAPSE", id });
146
+ setToMinSize(id) {
147
+ const panel = panels.find((panel2) => panel2.id === id);
148
+ send({ type: "SET_SIZE", id, size: panel?.minSize, src: "collapse" });
147
149
  },
148
150
  /**
149
- * Function to expand a panel.
151
+ * Function to set a panel to its maximum size.
150
152
  */
151
- expand(id) {
152
- send({ type: "EXPAND", id });
153
- },
154
- /**
155
- * Function to toggle a panel between collapsed and expanded.
156
- */
157
- toggle(id) {
158
- send({ type: "TOGGLE", id });
153
+ setToMaxSize(id) {
154
+ const panel = panels.find((panel2) => panel2.id === id);
155
+ send({ type: "SET_SIZE", id, size: panel?.maxSize, src: "expand" });
159
156
  },
160
157
  /**
161
158
  * Function to set the size of a panel.
@@ -170,13 +167,13 @@ function connect(state, send, normalize) {
170
167
  const { id, disabled } = props;
171
168
  const ids = id.split(":");
172
169
  const panelIds = ids.map((id2) => dom.getPanelId(state.context, id2));
173
- const panels = getHandleBounds(state.context, id);
170
+ const panels2 = getHandleBounds(state.context, id);
174
171
  return {
175
172
  isDisabled: !!disabled,
176
173
  isFocused: state.context.activeResizeId === id && isFocused,
177
174
  panelIds,
178
- min: panels?.min,
179
- max: panels?.max,
175
+ min: panels2?.min,
176
+ max: panels2?.max,
180
177
  value: 0
181
178
  };
182
179
  },
@@ -203,14 +200,6 @@ function connect(state, send, normalize) {
203
200
  style: dom.getPanelStyle(state.context, id)
204
201
  });
205
202
  },
206
- // toggleTriggerProps: normalize.element({
207
- // ...parts.toggleButton.attrs,
208
- // id: dom.getToggleButtonId(state.context),
209
- // "aria-label": state.context.isAtMin ? "Expand Primary Pane" : "Collapse Primary Pane",
210
- // onClick() {
211
- // send("TOGGLE")
212
- // },
213
- // }),
214
203
  getResizeTriggerProps(props) {
215
204
  const { id, disabled, step = 1 } = props;
216
205
  const triggerState = api.getResizeTriggerState(props);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-FCVFZHPC.mjs";
3
+ } from "./chunk-53T2VZ2R.mjs";
4
4
  import "./chunk-HPRMFGOY.mjs";
5
5
  import "./chunk-3GDOPT5W.mjs";
6
6
  import "./chunk-MV44GBQY.mjs";
@@ -249,7 +249,10 @@ function machine(userContext) {
249
249
  {
250
250
  actions: "setStartPanelToMin"
251
251
  }
252
- ]
252
+ ],
253
+ SET_SIZE: {
254
+ actions: "setPanelSize"
255
+ }
253
256
  },
254
257
  states: {
255
258
  idle: {
@@ -396,6 +399,13 @@ function machine(userContext) {
396
399
  size: panel.size
397
400
  }));
398
401
  },
402
+ setPanelSize(ctx2, evt) {
403
+ const { id, size } = evt;
404
+ ctx2.size = ctx2.size.map((panel) => {
405
+ const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
406
+ return panel.id === id ? { ...panel, size: panelSize } : panel;
407
+ });
408
+ },
399
409
  setStartPanelToMin(ctx2) {
400
410
  const bounds = getPanelBounds(ctx2);
401
411
  if (!bounds)
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-64C2WGI5.mjs";
3
+ } from "./chunk-X2E2LAC5.mjs";
4
4
  import "./chunk-3GDOPT5W.mjs";
5
5
  import "./chunk-MV44GBQY.mjs";
6
6
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/splitter",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Core logic for the splitter widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -28,13 +28,13 @@
28
28
  "url": "https://github.com/chakra-ui/zag/issues"
29
29
  },
30
30
  "dependencies": {
31
- "@zag-js/anatomy": "0.10.0",
32
- "@zag-js/core": "0.10.0",
33
- "@zag-js/types": "0.10.0",
34
- "@zag-js/dom-query": "0.10.0",
35
- "@zag-js/dom-event": "0.10.0",
36
- "@zag-js/number-utils": "0.10.0",
37
- "@zag-js/utils": "0.10.0"
31
+ "@zag-js/anatomy": "0.10.1",
32
+ "@zag-js/core": "0.10.1",
33
+ "@zag-js/types": "0.10.1",
34
+ "@zag-js/dom-query": "0.10.1",
35
+ "@zag-js/dom-event": "0.10.1",
36
+ "@zag-js/number-utils": "0.10.1",
37
+ "@zag-js/utils": "0.10.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "clean-package": "2.2.0"
@@ -10,6 +10,7 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
10
10
  const isHorizontal = state.context.isHorizontal
11
11
  const isFocused = state.hasTag("focus")
12
12
  const isDragging = state.matches("dragging")
13
+ const panels = state.context.panels
13
14
 
14
15
  const api = {
15
16
  /**
@@ -25,22 +26,18 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
25
26
  */
26
27
  bounds: getHandleBounds(state.context),
27
28
  /**
28
- * Function to collapse a panel.
29
+ * Function to set a panel to its minimum size.
29
30
  */
30
- collapse(id: PanelId) {
31
- send({ type: "COLLAPSE", id })
31
+ setToMinSize(id: PanelId) {
32
+ const panel = panels.find((panel) => panel.id === id)
33
+ send({ type: "SET_SIZE", id, size: panel?.minSize, src: "collapse" })
32
34
  },
33
35
  /**
34
- * Function to expand a panel.
36
+ * Function to set a panel to its maximum size.
35
37
  */
36
- expand(id: PanelId) {
37
- send({ type: "EXPAND", id })
38
- },
39
- /**
40
- * Function to toggle a panel between collapsed and expanded.
41
- */
42
- toggle(id: PanelId) {
43
- send({ type: "TOGGLE", id })
38
+ setToMaxSize(id: PanelId) {
39
+ const panel = panels.find((panel) => panel.id === id)
40
+ send({ type: "SET_SIZE", id, size: panel?.maxSize, src: "expand" })
44
41
  },
45
42
  /**
46
43
  * Function to set the size of a panel.
@@ -92,15 +89,6 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
92
89
  })
93
90
  },
94
91
 
95
- // toggleTriggerProps: normalize.element({
96
- // ...parts.toggleButton.attrs,
97
- // id: dom.getToggleButtonId(state.context),
98
- // "aria-label": state.context.isAtMin ? "Expand Primary Pane" : "Collapse Primary Pane",
99
- // onClick() {
100
- // send("TOGGLE")
101
- // },
102
- // }),
103
-
104
92
  getResizeTriggerProps(props: ResizeTriggerProps) {
105
93
  const { id, disabled, step = 1 } = props
106
94
  const triggerState = api.getResizeTriggerState(props)
@@ -52,6 +52,9 @@ export function machine(userContext: UserDefinedContext) {
52
52
  actions: "setStartPanelToMin",
53
53
  },
54
54
  ],
55
+ SET_SIZE: {
56
+ actions: "setPanelSize",
57
+ },
55
58
  },
56
59
  states: {
57
60
  idle: {
@@ -202,6 +205,13 @@ export function machine(userContext: UserDefinedContext) {
202
205
  size: panel.size,
203
206
  }))
204
207
  },
208
+ setPanelSize(ctx, evt) {
209
+ const { id, size } = evt
210
+ ctx.size = ctx.size.map((panel) => {
211
+ const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100)
212
+ return panel.id === id ? { ...panel, size: panelSize } : panel
213
+ })
214
+ },
205
215
  setStartPanelToMin(ctx) {
206
216
  const bounds = getPanelBounds(ctx)
207
217
  if (!bounds) return