@zag-js/splitter 0.10.0 → 0.10.2
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/{chunk-FCVFZHPC.mjs → chunk-2ZKYBJFK.mjs} +14 -25
- package/dist/{chunk-64C2WGI5.mjs → chunk-E3EBKL5P.mjs} +11 -16
- package/dist/{chunk-MV44GBQY.mjs → chunk-MXEXJMQ6.mjs} +1 -1
- package/dist/index.js +24 -40
- package/dist/index.mjs +3 -3
- package/dist/splitter.connect.d.ts +4 -8
- package/dist/splitter.connect.js +13 -24
- package/dist/splitter.connect.mjs +2 -2
- package/dist/splitter.machine.js +11 -16
- package/dist/splitter.machine.mjs +2 -2
- package/dist/splitter.utils.js +1 -1
- package/dist/splitter.utils.mjs +1 -1
- package/package.json +8 -8
- package/src/splitter.connect.ts +10 -22
- package/src/splitter.machine.ts +9 -14
- package/src/splitter.utils.ts +1 -1
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-3GDOPT5W.mjs";
|
|
7
7
|
import {
|
|
8
8
|
getHandleBounds
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-MXEXJMQ6.mjs";
|
|
10
10
|
|
|
11
11
|
// src/splitter.connect.ts
|
|
12
12
|
import { getEventKey, getEventStep } from "@zag-js/dom-event";
|
|
@@ -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,28 +30,24 @@ function connect(state, send, normalize) {
|
|
|
29
30
|
*/
|
|
30
31
|
bounds: getHandleBounds(state.context),
|
|
31
32
|
/**
|
|
32
|
-
* Function to
|
|
33
|
+
* Function to set a panel to its minimum size.
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
setToMinSize(id) {
|
|
36
|
+
const panel = panels.find((panel2) => panel2.id === id);
|
|
37
|
+
send({ type: "SET_PANEL_SIZE", id, size: panel?.minSize, src: "setToMinSize" });
|
|
36
38
|
},
|
|
37
39
|
/**
|
|
38
|
-
* Function to
|
|
40
|
+
* Function to set a panel to its maximum size.
|
|
39
41
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
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_PANEL_SIZE", id, size: panel?.maxSize, src: "setToMaxSize" });
|
|
48
45
|
},
|
|
49
46
|
/**
|
|
50
47
|
* Function to set the size of a panel.
|
|
51
48
|
*/
|
|
52
49
|
setSize(id, size) {
|
|
53
|
-
send({ type: "
|
|
50
|
+
send({ type: "SET_PANEL_SIZE", id, size });
|
|
54
51
|
},
|
|
55
52
|
/**
|
|
56
53
|
* Returns the state details for a resize trigger.
|
|
@@ -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
|
|
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:
|
|
68
|
-
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);
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
getHandlePanels,
|
|
8
8
|
getNormalizedPanels,
|
|
9
9
|
getPanelBounds
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-MXEXJMQ6.mjs";
|
|
11
11
|
|
|
12
12
|
// src/splitter.machine.ts
|
|
13
13
|
import { createMachine } from "@zag-js/core";
|
|
@@ -41,21 +41,9 @@ function machine(userContext) {
|
|
|
41
41
|
panels: (ctx2) => getNormalizedPanels(ctx2)
|
|
42
42
|
},
|
|
43
43
|
on: {
|
|
44
|
-
|
|
45
|
-
actions: "
|
|
46
|
-
}
|
|
47
|
-
EXPAND: {
|
|
48
|
-
actions: "setStartPanelToMax"
|
|
49
|
-
},
|
|
50
|
-
TOGGLE: [
|
|
51
|
-
{
|
|
52
|
-
guard: "isStartPanelAtMin",
|
|
53
|
-
actions: "setStartPanelToMax"
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
actions: "setStartPanelToMin"
|
|
57
|
-
}
|
|
58
|
-
]
|
|
44
|
+
SET_PANEL_SIZE: {
|
|
45
|
+
actions: "setPanelSize"
|
|
46
|
+
}
|
|
59
47
|
},
|
|
60
48
|
states: {
|
|
61
49
|
idle: {
|
|
@@ -202,6 +190,13 @@ function machine(userContext) {
|
|
|
202
190
|
size: panel.size
|
|
203
191
|
}));
|
|
204
192
|
},
|
|
193
|
+
setPanelSize(ctx2, evt) {
|
|
194
|
+
const { id, size } = evt;
|
|
195
|
+
ctx2.size = ctx2.size.map((panel) => {
|
|
196
|
+
const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
|
|
197
|
+
return panel.id === id ? { ...panel, size: panelSize } : panel;
|
|
198
|
+
});
|
|
199
|
+
},
|
|
205
200
|
setStartPanelToMin(ctx2) {
|
|
206
201
|
const bounds = getPanelBounds(ctx2);
|
|
207
202
|
if (!bounds)
|
|
@@ -9,7 +9,7 @@ function getNormalizedPanels(ctx) {
|
|
|
9
9
|
let totalSize = 0;
|
|
10
10
|
let totalMinSize = 0;
|
|
11
11
|
const panels = ctx.size.map((panel) => {
|
|
12
|
-
const minSize = panel.minSize ??
|
|
12
|
+
const minSize = panel.minSize ?? 0;
|
|
13
13
|
const maxSize = panel.maxSize ?? 100;
|
|
14
14
|
totalMinSize += minSize;
|
|
15
15
|
if (panel.size == null) {
|
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ function getNormalizedPanels(ctx) {
|
|
|
103
103
|
let totalSize = 0;
|
|
104
104
|
let totalMinSize = 0;
|
|
105
105
|
const panels = ctx.size.map((panel) => {
|
|
106
|
-
const minSize = panel.minSize ??
|
|
106
|
+
const minSize = panel.minSize ?? 0;
|
|
107
107
|
const maxSize = panel.maxSize ?? 100;
|
|
108
108
|
totalMinSize += minSize;
|
|
109
109
|
if (panel.size == null) {
|
|
@@ -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,28 +234,24 @@ function connect(state, send, normalize) {
|
|
|
233
234
|
*/
|
|
234
235
|
bounds: getHandleBounds(state.context),
|
|
235
236
|
/**
|
|
236
|
-
* Function to
|
|
237
|
+
* Function to set a panel to its minimum size.
|
|
237
238
|
*/
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
setToMinSize(id) {
|
|
240
|
+
const panel = panels.find((panel2) => panel2.id === id);
|
|
241
|
+
send({ type: "SET_PANEL_SIZE", id, size: panel?.minSize, src: "setToMinSize" });
|
|
240
242
|
},
|
|
241
243
|
/**
|
|
242
|
-
* Function to
|
|
244
|
+
* Function to set a panel to its maximum size.
|
|
243
245
|
*/
|
|
244
|
-
|
|
245
|
-
|
|
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_PANEL_SIZE", id, size: panel?.maxSize, src: "setToMaxSize" });
|
|
252
249
|
},
|
|
253
250
|
/**
|
|
254
251
|
* Function to set the size of a panel.
|
|
255
252
|
*/
|
|
256
253
|
setSize(id, size) {
|
|
257
|
-
send({ type: "
|
|
254
|
+
send({ type: "SET_PANEL_SIZE", id, size });
|
|
258
255
|
},
|
|
259
256
|
/**
|
|
260
257
|
* Returns the state details for a resize trigger.
|
|
@@ -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
|
|
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:
|
|
272
|
-
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);
|
|
@@ -432,21 +421,9 @@ function machine(userContext) {
|
|
|
432
421
|
panels: (ctx2) => getNormalizedPanels(ctx2)
|
|
433
422
|
},
|
|
434
423
|
on: {
|
|
435
|
-
|
|
436
|
-
actions: "
|
|
437
|
-
}
|
|
438
|
-
EXPAND: {
|
|
439
|
-
actions: "setStartPanelToMax"
|
|
440
|
-
},
|
|
441
|
-
TOGGLE: [
|
|
442
|
-
{
|
|
443
|
-
guard: "isStartPanelAtMin",
|
|
444
|
-
actions: "setStartPanelToMax"
|
|
445
|
-
},
|
|
446
|
-
{
|
|
447
|
-
actions: "setStartPanelToMin"
|
|
448
|
-
}
|
|
449
|
-
]
|
|
424
|
+
SET_PANEL_SIZE: {
|
|
425
|
+
actions: "setPanelSize"
|
|
426
|
+
}
|
|
450
427
|
},
|
|
451
428
|
states: {
|
|
452
429
|
idle: {
|
|
@@ -593,6 +570,13 @@ function machine(userContext) {
|
|
|
593
570
|
size: panel.size
|
|
594
571
|
}));
|
|
595
572
|
},
|
|
573
|
+
setPanelSize(ctx2, evt) {
|
|
574
|
+
const { id, size } = evt;
|
|
575
|
+
ctx2.size = ctx2.size.map((panel) => {
|
|
576
|
+
const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
|
|
577
|
+
return panel.id === id ? { ...panel, size: panelSize } : panel;
|
|
578
|
+
});
|
|
579
|
+
},
|
|
596
580
|
setStartPanelToMin(ctx2) {
|
|
597
581
|
const bounds = getPanelBounds(ctx2);
|
|
598
582
|
if (!bounds)
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2ZKYBJFK.mjs";
|
|
4
4
|
import {
|
|
5
5
|
anatomy
|
|
6
6
|
} from "./chunk-HPRMFGOY.mjs";
|
|
7
7
|
import {
|
|
8
8
|
machine
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-E3EBKL5P.mjs";
|
|
10
10
|
import "./chunk-3GDOPT5W.mjs";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-MXEXJMQ6.mjs";
|
|
12
12
|
export {
|
|
13
13
|
anatomy,
|
|
14
14
|
connect,
|
|
@@ -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
|
|
22
|
+
* Function to set a panel to its minimum size.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
setToMinSize(id: PanelId): void;
|
|
25
25
|
/**
|
|
26
|
-
* Function to
|
|
26
|
+
* Function to set a panel to its maximum size.
|
|
27
27
|
*/
|
|
28
|
-
|
|
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
|
*/
|
package/dist/splitter.connect.js
CHANGED
|
@@ -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,28 +141,24 @@ function connect(state, send, normalize) {
|
|
|
140
141
|
*/
|
|
141
142
|
bounds: getHandleBounds(state.context),
|
|
142
143
|
/**
|
|
143
|
-
* Function to
|
|
144
|
+
* Function to set a panel to its minimum size.
|
|
144
145
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
setToMinSize(id) {
|
|
147
|
+
const panel = panels.find((panel2) => panel2.id === id);
|
|
148
|
+
send({ type: "SET_PANEL_SIZE", id, size: panel?.minSize, src: "setToMinSize" });
|
|
147
149
|
},
|
|
148
150
|
/**
|
|
149
|
-
* Function to
|
|
151
|
+
* Function to set a panel to its maximum size.
|
|
150
152
|
*/
|
|
151
|
-
|
|
152
|
-
|
|
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_PANEL_SIZE", id, size: panel?.maxSize, src: "setToMaxSize" });
|
|
159
156
|
},
|
|
160
157
|
/**
|
|
161
158
|
* Function to set the size of a panel.
|
|
162
159
|
*/
|
|
163
160
|
setSize(id, size) {
|
|
164
|
-
send({ type: "
|
|
161
|
+
send({ type: "SET_PANEL_SIZE", id, size });
|
|
165
162
|
},
|
|
166
163
|
/**
|
|
167
164
|
* Returns the state details for a resize trigger.
|
|
@@ -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
|
|
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:
|
|
179
|
-
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);
|
package/dist/splitter.machine.js
CHANGED
|
@@ -96,7 +96,7 @@ function getNormalizedPanels(ctx) {
|
|
|
96
96
|
let totalSize = 0;
|
|
97
97
|
let totalMinSize = 0;
|
|
98
98
|
const panels = ctx.size.map((panel) => {
|
|
99
|
-
const minSize = panel.minSize ??
|
|
99
|
+
const minSize = panel.minSize ?? 0;
|
|
100
100
|
const maxSize = panel.maxSize ?? 100;
|
|
101
101
|
totalMinSize += minSize;
|
|
102
102
|
if (panel.size == null) {
|
|
@@ -235,21 +235,9 @@ function machine(userContext) {
|
|
|
235
235
|
panels: (ctx2) => getNormalizedPanels(ctx2)
|
|
236
236
|
},
|
|
237
237
|
on: {
|
|
238
|
-
|
|
239
|
-
actions: "
|
|
240
|
-
}
|
|
241
|
-
EXPAND: {
|
|
242
|
-
actions: "setStartPanelToMax"
|
|
243
|
-
},
|
|
244
|
-
TOGGLE: [
|
|
245
|
-
{
|
|
246
|
-
guard: "isStartPanelAtMin",
|
|
247
|
-
actions: "setStartPanelToMax"
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
actions: "setStartPanelToMin"
|
|
251
|
-
}
|
|
252
|
-
]
|
|
238
|
+
SET_PANEL_SIZE: {
|
|
239
|
+
actions: "setPanelSize"
|
|
240
|
+
}
|
|
253
241
|
},
|
|
254
242
|
states: {
|
|
255
243
|
idle: {
|
|
@@ -396,6 +384,13 @@ function machine(userContext) {
|
|
|
396
384
|
size: panel.size
|
|
397
385
|
}));
|
|
398
386
|
},
|
|
387
|
+
setPanelSize(ctx2, evt) {
|
|
388
|
+
const { id, size } = evt;
|
|
389
|
+
ctx2.size = ctx2.size.map((panel) => {
|
|
390
|
+
const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
|
|
391
|
+
return panel.id === id ? { ...panel, size: panelSize } : panel;
|
|
392
|
+
});
|
|
393
|
+
},
|
|
399
394
|
setStartPanelToMin(ctx2) {
|
|
400
395
|
const bounds = getPanelBounds(ctx2);
|
|
401
396
|
if (!bounds)
|
package/dist/splitter.utils.js
CHANGED
|
@@ -37,7 +37,7 @@ function getNormalizedPanels(ctx) {
|
|
|
37
37
|
let totalSize = 0;
|
|
38
38
|
let totalMinSize = 0;
|
|
39
39
|
const panels = ctx.size.map((panel) => {
|
|
40
|
-
const minSize = panel.minSize ??
|
|
40
|
+
const minSize = panel.minSize ?? 0;
|
|
41
41
|
const maxSize = panel.maxSize ?? 100;
|
|
42
42
|
totalMinSize += minSize;
|
|
43
43
|
if (panel.size == null) {
|
package/dist/splitter.utils.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/splitter",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
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.
|
|
32
|
-
"@zag-js/core": "0.10.
|
|
33
|
-
"@zag-js/types": "0.10.
|
|
34
|
-
"@zag-js/dom-query": "0.10.
|
|
35
|
-
"@zag-js/dom-event": "0.10.
|
|
36
|
-
"@zag-js/number-utils": "0.10.
|
|
37
|
-
"@zag-js/utils": "0.10.
|
|
31
|
+
"@zag-js/anatomy": "0.10.2",
|
|
32
|
+
"@zag-js/core": "0.10.2",
|
|
33
|
+
"@zag-js/types": "0.10.2",
|
|
34
|
+
"@zag-js/dom-query": "0.10.2",
|
|
35
|
+
"@zag-js/dom-event": "0.10.2",
|
|
36
|
+
"@zag-js/number-utils": "0.10.2",
|
|
37
|
+
"@zag-js/utils": "0.10.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"clean-package": "2.2.0"
|
package/src/splitter.connect.ts
CHANGED
|
@@ -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,28 +26,24 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
|
|
|
25
26
|
*/
|
|
26
27
|
bounds: getHandleBounds(state.context),
|
|
27
28
|
/**
|
|
28
|
-
* Function to
|
|
29
|
+
* Function to set a panel to its minimum size.
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
setToMinSize(id: PanelId) {
|
|
32
|
+
const panel = panels.find((panel) => panel.id === id)
|
|
33
|
+
send({ type: "SET_PANEL_SIZE", id, size: panel?.minSize, src: "setToMinSize" })
|
|
32
34
|
},
|
|
33
35
|
/**
|
|
34
|
-
* Function to
|
|
36
|
+
* Function to set a panel to its maximum size.
|
|
35
37
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
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_PANEL_SIZE", id, size: panel?.maxSize, src: "setToMaxSize" })
|
|
44
41
|
},
|
|
45
42
|
/**
|
|
46
43
|
* Function to set the size of a panel.
|
|
47
44
|
*/
|
|
48
45
|
setSize(id: PanelId, size: number) {
|
|
49
|
-
send({ type: "
|
|
46
|
+
send({ type: "SET_PANEL_SIZE", id, size })
|
|
50
47
|
},
|
|
51
48
|
/**
|
|
52
49
|
* Returns the state details for a resize trigger.
|
|
@@ -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)
|
package/src/splitter.machine.ts
CHANGED
|
@@ -37,21 +37,9 @@ export function machine(userContext: UserDefinedContext) {
|
|
|
37
37
|
},
|
|
38
38
|
|
|
39
39
|
on: {
|
|
40
|
-
|
|
41
|
-
actions: "
|
|
40
|
+
SET_PANEL_SIZE: {
|
|
41
|
+
actions: "setPanelSize",
|
|
42
42
|
},
|
|
43
|
-
EXPAND: {
|
|
44
|
-
actions: "setStartPanelToMax",
|
|
45
|
-
},
|
|
46
|
-
TOGGLE: [
|
|
47
|
-
{
|
|
48
|
-
guard: "isStartPanelAtMin",
|
|
49
|
-
actions: "setStartPanelToMax",
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
actions: "setStartPanelToMin",
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
43
|
},
|
|
56
44
|
states: {
|
|
57
45
|
idle: {
|
|
@@ -202,6 +190,13 @@ export function machine(userContext: UserDefinedContext) {
|
|
|
202
190
|
size: panel.size,
|
|
203
191
|
}))
|
|
204
192
|
},
|
|
193
|
+
setPanelSize(ctx, evt) {
|
|
194
|
+
const { id, size } = evt
|
|
195
|
+
ctx.size = ctx.size.map((panel) => {
|
|
196
|
+
const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100)
|
|
197
|
+
return panel.id === id ? { ...panel, size: panelSize } : panel
|
|
198
|
+
})
|
|
199
|
+
},
|
|
205
200
|
setStartPanelToMin(ctx) {
|
|
206
201
|
const bounds = getPanelBounds(ctx)
|
|
207
202
|
if (!bounds) return
|
package/src/splitter.utils.ts
CHANGED
|
@@ -12,7 +12,7 @@ export function getNormalizedPanels(ctx: Ctx): NormalizedPanelData {
|
|
|
12
12
|
let totalMinSize = 0
|
|
13
13
|
|
|
14
14
|
const panels = ctx.size.map((panel) => {
|
|
15
|
-
const minSize = panel.minSize ??
|
|
15
|
+
const minSize = panel.minSize ?? 0
|
|
16
16
|
const maxSize = panel.maxSize ?? 100
|
|
17
17
|
|
|
18
18
|
totalMinSize += minSize
|