@zag-js/splitter 0.82.2 → 1.0.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.
- package/dist/index.d.mts +40 -26
- package/dist/index.d.ts +40 -26
- package/dist/index.js +385 -330
- package/dist/index.mjs +387 -332
- package/package.json +14 -9
package/dist/index.js
CHANGED
|
@@ -9,56 +9,38 @@ var types = require('@zag-js/types');
|
|
|
9
9
|
// src/splitter.anatomy.ts
|
|
10
10
|
var anatomy = anatomy$1.createAnatomy("splitter").parts("root", "panel", "resizeTrigger");
|
|
11
11
|
var parts = anatomy.build();
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const activeId = ctx.activeResizeId;
|
|
39
|
-
if (activeId == null) return;
|
|
40
|
-
return dom.getById(ctx, dom.getResizeTriggerId(ctx, activeId));
|
|
41
|
-
},
|
|
42
|
-
getResizeTriggerEls(ctx) {
|
|
43
|
-
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
44
|
-
return domQuery.queryAll(dom.getRootEl(ctx), `[role=separator][data-ownedby='${ownerId}']`);
|
|
45
|
-
},
|
|
46
|
-
setupGlobalCursor(ctx) {
|
|
47
|
-
const styleEl = dom.getById(ctx, dom.getGlobalCursorId(ctx));
|
|
48
|
-
const textContent = `* { cursor: ${dom.getCursor(ctx)} !important; }`;
|
|
49
|
-
if (styleEl) {
|
|
50
|
-
styleEl.textContent = textContent;
|
|
51
|
-
} else {
|
|
52
|
-
const style = dom.getDoc(ctx).createElement("style");
|
|
53
|
-
style.id = dom.getGlobalCursorId(ctx);
|
|
54
|
-
style.textContent = textContent;
|
|
55
|
-
dom.getDoc(ctx).head.appendChild(style);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
removeGlobalCursor(ctx) {
|
|
59
|
-
dom.getById(ctx, dom.getGlobalCursorId(ctx))?.remove();
|
|
12
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`;
|
|
13
|
+
var getResizeTriggerId = (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`;
|
|
14
|
+
var getPanelId = (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`;
|
|
15
|
+
var getGlobalCursorId = (ctx) => `splitter:${ctx.id}:global-cursor`;
|
|
16
|
+
var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
17
|
+
var getResizeTriggerEl = (ctx, id) => ctx.getById(getResizeTriggerId(ctx, id));
|
|
18
|
+
var getCursor = (state, x) => {
|
|
19
|
+
let cursor = x ? "col-resize" : "row-resize";
|
|
20
|
+
if (state.isAtMin) cursor = x ? "e-resize" : "s-resize";
|
|
21
|
+
if (state.isAtMax) cursor = x ? "w-resize" : "n-resize";
|
|
22
|
+
return cursor;
|
|
23
|
+
};
|
|
24
|
+
var getPanelStyle = (panels, id) => {
|
|
25
|
+
const flexGrow = panels.find((panel) => panel.id === id)?.size ?? "0";
|
|
26
|
+
return { flexBasis: 0, flexGrow, flexShrink: 1, overflow: "hidden" };
|
|
27
|
+
};
|
|
28
|
+
var setupGlobalCursor = (ctx, state, x) => {
|
|
29
|
+
const styleEl = ctx.getById(getGlobalCursorId(ctx));
|
|
30
|
+
const textContent = `* { cursor: ${getCursor(state, x)} !important; }`;
|
|
31
|
+
if (styleEl) {
|
|
32
|
+
styleEl.textContent = textContent;
|
|
33
|
+
} else {
|
|
34
|
+
const style = ctx.getDoc().createElement("style");
|
|
35
|
+
style.id = getGlobalCursorId(ctx);
|
|
36
|
+
style.textContent = textContent;
|
|
37
|
+
ctx.getDoc().head.appendChild(style);
|
|
60
38
|
}
|
|
61
|
-
}
|
|
39
|
+
};
|
|
40
|
+
var removeGlobalCursor = (ctx) => {
|
|
41
|
+
const styleEl = ctx.getById(getGlobalCursorId(ctx));
|
|
42
|
+
styleEl?.remove();
|
|
43
|
+
};
|
|
62
44
|
|
|
63
45
|
// src/splitter.utils.ts
|
|
64
46
|
function validateSize(key, size) {
|
|
@@ -66,11 +48,11 @@ function validateSize(key, size) {
|
|
|
66
48
|
throw new Error(`Total ${key} of panels cannot be greater than 100`);
|
|
67
49
|
}
|
|
68
50
|
}
|
|
69
|
-
function getNormalizedPanels(
|
|
51
|
+
function getNormalizedPanels(sizes) {
|
|
70
52
|
let numOfPanelsWithoutSize = 0;
|
|
71
53
|
let totalSize = 0;
|
|
72
54
|
let totalMinSize = 0;
|
|
73
|
-
const panels =
|
|
55
|
+
const panels = sizes.map((panel) => {
|
|
74
56
|
const minSize = panel.minSize ?? 0;
|
|
75
57
|
const maxSize = panel.maxSize ?? 100;
|
|
76
58
|
totalMinSize += minSize;
|
|
@@ -108,14 +90,14 @@ function getNormalizedPanels(ctx) {
|
|
|
108
90
|
});
|
|
109
91
|
return result;
|
|
110
92
|
}
|
|
111
|
-
function getHandlePanels(
|
|
93
|
+
function getHandlePanels(panels, id) {
|
|
112
94
|
const [beforeId, afterId] = id?.split(":") ?? [];
|
|
113
95
|
if (!beforeId || !afterId) return;
|
|
114
|
-
const beforeIndex =
|
|
115
|
-
const afterIndex =
|
|
96
|
+
const beforeIndex = panels.findIndex((panel) => panel.id === beforeId);
|
|
97
|
+
const afterIndex = panels.findIndex((panel) => panel.id === afterId);
|
|
116
98
|
if (beforeIndex === -1 || afterIndex === -1) return;
|
|
117
|
-
const before =
|
|
118
|
-
const after =
|
|
99
|
+
const before = panels[beforeIndex];
|
|
100
|
+
const after = panels[afterIndex];
|
|
119
101
|
return {
|
|
120
102
|
before: {
|
|
121
103
|
...before,
|
|
@@ -127,20 +109,20 @@ function getHandlePanels(ctx, id = ctx.activeResizeId) {
|
|
|
127
109
|
}
|
|
128
110
|
};
|
|
129
111
|
}
|
|
130
|
-
function getHandleBounds(
|
|
131
|
-
const
|
|
132
|
-
if (!
|
|
133
|
-
const { before, after } =
|
|
112
|
+
function getHandleBounds(panels, id) {
|
|
113
|
+
const handlePanels = getHandlePanels(panels, id);
|
|
114
|
+
if (!handlePanels) return;
|
|
115
|
+
const { before, after } = handlePanels;
|
|
134
116
|
return {
|
|
135
117
|
min: Math.max(before.start + before.minSize, after.end - after.maxSize),
|
|
136
118
|
max: Math.min(after.end - after.minSize, before.maxSize + before.start)
|
|
137
119
|
};
|
|
138
120
|
}
|
|
139
|
-
function getPanelBounds(
|
|
140
|
-
const bounds = getHandleBounds(
|
|
141
|
-
const
|
|
142
|
-
if (!bounds || !
|
|
143
|
-
const { before, after } =
|
|
121
|
+
function getPanelBounds(panels, id) {
|
|
122
|
+
const bounds = getHandleBounds(panels, id);
|
|
123
|
+
const handlePanels = getHandlePanels(panels, id);
|
|
124
|
+
if (!bounds || !handlePanels) return;
|
|
125
|
+
const { before, after } = handlePanels;
|
|
144
126
|
const beforeMin = Math.abs(before.start - bounds.min);
|
|
145
127
|
const afterMin = after.size + (before.size - beforeMin);
|
|
146
128
|
const beforeMax = Math.abs(before.start - bounds.max);
|
|
@@ -179,19 +161,21 @@ function clamp(value, min, max) {
|
|
|
179
161
|
}
|
|
180
162
|
|
|
181
163
|
// src/splitter.connect.ts
|
|
182
|
-
function connect(
|
|
183
|
-
const
|
|
164
|
+
function connect(service, normalize) {
|
|
165
|
+
const { state, send, prop, computed, context, scope } = service;
|
|
166
|
+
const horizontal = computed("isHorizontal");
|
|
184
167
|
const focused = state.hasTag("focus");
|
|
185
168
|
const dragging = state.matches("dragging");
|
|
186
|
-
const panels =
|
|
169
|
+
const panels = computed("panels");
|
|
170
|
+
const activeResizeId = context.get("activeResizeId");
|
|
187
171
|
function getResizeTriggerState(props2) {
|
|
188
172
|
const { id, disabled } = props2;
|
|
189
173
|
const ids = id.split(":");
|
|
190
|
-
const panelIds = ids.map((id2) =>
|
|
191
|
-
const panels2 = getHandleBounds(
|
|
174
|
+
const panelIds = ids.map((id2) => getPanelId(scope, id2));
|
|
175
|
+
const panels2 = getHandleBounds(computed("panels"), id);
|
|
192
176
|
return {
|
|
193
177
|
disabled: !!disabled,
|
|
194
|
-
focused:
|
|
178
|
+
focused: activeResizeId === id && focused,
|
|
195
179
|
panelIds,
|
|
196
180
|
min: panels2?.min,
|
|
197
181
|
max: panels2?.max,
|
|
@@ -202,7 +186,7 @@ function connect(state, send, normalize) {
|
|
|
202
186
|
focused,
|
|
203
187
|
dragging,
|
|
204
188
|
getResizeTriggerState,
|
|
205
|
-
bounds: getHandleBounds(
|
|
189
|
+
bounds: getHandleBounds(computed("panels"), activeResizeId),
|
|
206
190
|
setToMinSize(id) {
|
|
207
191
|
const panel = panels.find((panel2) => panel2.id === id);
|
|
208
192
|
send({ type: "SET_PANEL_SIZE", id, size: panel?.minSize, src: "setToMinSize" });
|
|
@@ -217,9 +201,9 @@ function connect(state, send, normalize) {
|
|
|
217
201
|
getRootProps() {
|
|
218
202
|
return normalize.element({
|
|
219
203
|
...parts.root.attrs,
|
|
220
|
-
"data-orientation":
|
|
221
|
-
id:
|
|
222
|
-
dir:
|
|
204
|
+
"data-orientation": prop("orientation"),
|
|
205
|
+
id: getRootId(scope),
|
|
206
|
+
dir: prop("dir"),
|
|
223
207
|
style: {
|
|
224
208
|
display: "flex",
|
|
225
209
|
flexDirection: horizontal ? "row" : "column",
|
|
@@ -233,11 +217,11 @@ function connect(state, send, normalize) {
|
|
|
233
217
|
const { id } = props2;
|
|
234
218
|
return normalize.element({
|
|
235
219
|
...parts.panel.attrs,
|
|
236
|
-
"data-orientation":
|
|
237
|
-
dir:
|
|
238
|
-
id:
|
|
239
|
-
"data-ownedby":
|
|
240
|
-
style:
|
|
220
|
+
"data-orientation": prop("orientation"),
|
|
221
|
+
dir: prop("dir"),
|
|
222
|
+
id: getPanelId(scope, id),
|
|
223
|
+
"data-ownedby": getRootId(scope),
|
|
224
|
+
style: getPanelStyle(panels, id)
|
|
241
225
|
});
|
|
242
226
|
},
|
|
243
227
|
getResizeTriggerProps(props2) {
|
|
@@ -245,16 +229,16 @@ function connect(state, send, normalize) {
|
|
|
245
229
|
const triggerState = getResizeTriggerState(props2);
|
|
246
230
|
return normalize.element({
|
|
247
231
|
...parts.resizeTrigger.attrs,
|
|
248
|
-
dir:
|
|
249
|
-
id:
|
|
232
|
+
dir: prop("dir"),
|
|
233
|
+
id: getResizeTriggerId(scope, id),
|
|
250
234
|
role: "separator",
|
|
251
|
-
"data-ownedby":
|
|
235
|
+
"data-ownedby": getRootId(scope),
|
|
252
236
|
tabIndex: disabled ? void 0 : 0,
|
|
253
237
|
"aria-valuenow": triggerState.value,
|
|
254
238
|
"aria-valuemin": triggerState.min,
|
|
255
239
|
"aria-valuemax": triggerState.max,
|
|
256
|
-
"data-orientation":
|
|
257
|
-
"aria-orientation":
|
|
240
|
+
"data-orientation": prop("orientation"),
|
|
241
|
+
"aria-orientation": prop("orientation"),
|
|
258
242
|
"aria-controls": triggerState.panelIds.join(" "),
|
|
259
243
|
"data-focus": domQuery.dataAttr(triggerState.focused),
|
|
260
244
|
"data-disabled": domQuery.dataAttr(disabled),
|
|
@@ -292,7 +276,7 @@ function connect(state, send, normalize) {
|
|
|
292
276
|
send({ type: "POINTER_LEAVE", id });
|
|
293
277
|
},
|
|
294
278
|
onBlur() {
|
|
295
|
-
send("BLUR");
|
|
279
|
+
send({ type: "BLUR" });
|
|
296
280
|
},
|
|
297
281
|
onFocus() {
|
|
298
282
|
send({ type: "FOCUS", id });
|
|
@@ -307,7 +291,7 @@ function connect(state, send, normalize) {
|
|
|
307
291
|
const moveStep = domQuery.getEventStep(event) * step;
|
|
308
292
|
const keyMap = {
|
|
309
293
|
Enter() {
|
|
310
|
-
send("ENTER");
|
|
294
|
+
send({ type: "ENTER" });
|
|
311
295
|
},
|
|
312
296
|
ArrowUp() {
|
|
313
297
|
send({ type: "ARROW_UP", step: moveStep });
|
|
@@ -322,13 +306,16 @@ function connect(state, send, normalize) {
|
|
|
322
306
|
send({ type: "ARROW_RIGHT", step: moveStep });
|
|
323
307
|
},
|
|
324
308
|
Home() {
|
|
325
|
-
send("HOME");
|
|
309
|
+
send({ type: "HOME" });
|
|
326
310
|
},
|
|
327
311
|
End() {
|
|
328
|
-
send("END");
|
|
312
|
+
send({ type: "END" });
|
|
329
313
|
}
|
|
330
314
|
};
|
|
331
|
-
const key = domQuery.getEventKey(event,
|
|
315
|
+
const key = domQuery.getEventKey(event, {
|
|
316
|
+
dir: prop("dir"),
|
|
317
|
+
orientation: prop("orientation")
|
|
318
|
+
});
|
|
332
319
|
const exec = keyMap[key];
|
|
333
320
|
if (exec) {
|
|
334
321
|
exec(event);
|
|
@@ -339,266 +326,333 @@ function connect(state, send, normalize) {
|
|
|
339
326
|
}
|
|
340
327
|
};
|
|
341
328
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
329
|
+
var machine = core.createMachine({
|
|
330
|
+
props({ props: props2 }) {
|
|
331
|
+
return {
|
|
332
|
+
orientation: "horizontal",
|
|
333
|
+
defaultSize: [],
|
|
334
|
+
...utils.compact(props2)
|
|
335
|
+
};
|
|
336
|
+
},
|
|
337
|
+
initialState() {
|
|
338
|
+
return "idle";
|
|
339
|
+
},
|
|
340
|
+
context({ prop, bindable, getContext }) {
|
|
341
|
+
return {
|
|
342
|
+
activeResizeId: bindable(() => ({
|
|
343
|
+
defaultValue: null
|
|
344
|
+
})),
|
|
345
|
+
size: bindable(() => ({
|
|
346
|
+
defaultValue: prop("defaultSize"),
|
|
347
|
+
value: prop("size"),
|
|
348
|
+
hash(a) {
|
|
349
|
+
return a.map((panel) => `${panel.id}:${panel.size}`).join(",");
|
|
357
350
|
},
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
computed: {
|
|
365
|
-
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
366
|
-
panels: (ctx2) => getNormalizedPanels(ctx2)
|
|
367
|
-
},
|
|
368
|
-
on: {
|
|
369
|
-
SET_PANEL_SIZE: {
|
|
370
|
-
actions: "setPanelSize"
|
|
351
|
+
onChange(value) {
|
|
352
|
+
const context = getContext();
|
|
353
|
+
prop("onSizeChange")?.({
|
|
354
|
+
size: value,
|
|
355
|
+
activeHandleId: context.get("activeResizeId")
|
|
356
|
+
});
|
|
371
357
|
}
|
|
372
|
-
},
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
358
|
+
})),
|
|
359
|
+
activeResizeState: bindable(() => ({
|
|
360
|
+
defaultValue: { isAtMin: false, isAtMax: false }
|
|
361
|
+
}))
|
|
362
|
+
};
|
|
363
|
+
},
|
|
364
|
+
refs({ context }) {
|
|
365
|
+
return {
|
|
366
|
+
previousPanels: getNormalizedPanels(context.get("size"))
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
watch({ track, action, context }) {
|
|
370
|
+
track([() => context.hash("size")], () => {
|
|
371
|
+
action(["setActiveResizeState"]);
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
computed: {
|
|
375
|
+
isHorizontal: ({ prop }) => prop("orientation") === "horizontal",
|
|
376
|
+
panels: ({ context }) => getNormalizedPanels(context.get("size"))
|
|
377
|
+
},
|
|
378
|
+
on: {
|
|
379
|
+
SET_PANEL_SIZE: {
|
|
380
|
+
actions: ["setPanelSize"]
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
states: {
|
|
384
|
+
idle: {
|
|
385
|
+
entry: ["clearActiveHandleId"],
|
|
386
|
+
on: {
|
|
387
|
+
POINTER_OVER: {
|
|
388
|
+
target: "hover:temp",
|
|
389
|
+
actions: ["setActiveHandleId"]
|
|
401
390
|
},
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
POINTER_DOWN: "dragging",
|
|
406
|
-
POINTER_LEAVE: "idle"
|
|
407
|
-
}
|
|
391
|
+
FOCUS: {
|
|
392
|
+
target: "focused",
|
|
393
|
+
actions: ["setActiveHandleId"]
|
|
408
394
|
},
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
on: {
|
|
412
|
-
BLUR: "idle",
|
|
413
|
-
POINTER_DOWN: {
|
|
414
|
-
target: "dragging",
|
|
415
|
-
actions: ["setActiveHandleId"]
|
|
416
|
-
},
|
|
417
|
-
ARROW_LEFT: {
|
|
418
|
-
guard: "isHorizontal",
|
|
419
|
-
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
420
|
-
},
|
|
421
|
-
ARROW_RIGHT: {
|
|
422
|
-
guard: "isHorizontal",
|
|
423
|
-
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
424
|
-
},
|
|
425
|
-
ARROW_UP: {
|
|
426
|
-
guard: "isVertical",
|
|
427
|
-
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
428
|
-
},
|
|
429
|
-
ARROW_DOWN: {
|
|
430
|
-
guard: "isVertical",
|
|
431
|
-
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
432
|
-
},
|
|
433
|
-
ENTER: [
|
|
434
|
-
{
|
|
435
|
-
guard: "isStartPanelAtMax",
|
|
436
|
-
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
437
|
-
},
|
|
438
|
-
{ actions: ["setStartPanelToMax", "setPreviousPanels"] }
|
|
439
|
-
],
|
|
440
|
-
HOME: {
|
|
441
|
-
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
442
|
-
},
|
|
443
|
-
END: {
|
|
444
|
-
actions: ["setStartPanelToMax", "setPreviousPanels"]
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
},
|
|
448
|
-
dragging: {
|
|
449
|
-
tags: ["focus"],
|
|
450
|
-
entry: "focusResizeHandle",
|
|
451
|
-
activities: ["trackPointerMove"],
|
|
452
|
-
on: {
|
|
453
|
-
POINTER_MOVE: {
|
|
454
|
-
actions: ["setPointerValue", "setGlobalCursor", "invokeOnResize"]
|
|
455
|
-
},
|
|
456
|
-
POINTER_UP: {
|
|
457
|
-
target: "focused",
|
|
458
|
-
actions: ["setPreviousPanels", "clearGlobalCursor", "blurResizeHandle", "invokeOnResizeEnd"]
|
|
459
|
-
}
|
|
460
|
-
}
|
|
395
|
+
DOUBLE_CLICK: {
|
|
396
|
+
actions: ["resetStartPanel", "setPreviousPanels"]
|
|
461
397
|
}
|
|
462
398
|
}
|
|
463
399
|
},
|
|
464
|
-
{
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
onPointerMove(info) {
|
|
470
|
-
send({ type: "POINTER_MOVE", point: info.point });
|
|
471
|
-
},
|
|
472
|
-
onPointerUp() {
|
|
473
|
-
send("POINTER_UP");
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
},
|
|
478
|
-
guards: {
|
|
479
|
-
isStartPanelAtMin: (ctx2) => ctx2.activeResizeState.isAtMin,
|
|
480
|
-
isStartPanelAtMax: (ctx2) => ctx2.activeResizeState.isAtMax,
|
|
481
|
-
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
482
|
-
isVertical: (ctx2) => !ctx2.isHorizontal
|
|
483
|
-
},
|
|
484
|
-
delays: {
|
|
485
|
-
HOVER_DELAY: 250
|
|
486
|
-
},
|
|
487
|
-
actions: {
|
|
488
|
-
setGlobalCursor(ctx2) {
|
|
489
|
-
dom.setupGlobalCursor(ctx2);
|
|
490
|
-
},
|
|
491
|
-
clearGlobalCursor(ctx2) {
|
|
492
|
-
dom.removeGlobalCursor(ctx2);
|
|
493
|
-
},
|
|
494
|
-
invokeOnResize(ctx2) {
|
|
495
|
-
ctx2.onSizeChange?.({ size: Array.from(ctx2.size), activeHandleId: ctx2.activeResizeId });
|
|
496
|
-
},
|
|
497
|
-
invokeOnResizeEnd(ctx2) {
|
|
498
|
-
ctx2.onSizeChangeEnd?.({ size: Array.from(ctx2.size), activeHandleId: ctx2.activeResizeId });
|
|
499
|
-
},
|
|
500
|
-
setActiveHandleId(ctx2, evt) {
|
|
501
|
-
ctx2.activeResizeId = evt.id;
|
|
502
|
-
},
|
|
503
|
-
clearActiveHandleId(ctx2) {
|
|
504
|
-
ctx2.activeResizeId = null;
|
|
400
|
+
"hover:temp": {
|
|
401
|
+
effects: ["waitForHoverDelay"],
|
|
402
|
+
on: {
|
|
403
|
+
HOVER_DELAY: {
|
|
404
|
+
target: "hover"
|
|
505
405
|
},
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
size: panel.size
|
|
510
|
-
}));
|
|
406
|
+
POINTER_DOWN: {
|
|
407
|
+
target: "dragging",
|
|
408
|
+
actions: ["setActiveHandleId"]
|
|
511
409
|
},
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const { before, after } = bounds;
|
|
523
|
-
ctx2.size[before.index].size = before.min;
|
|
524
|
-
ctx2.size[after.index].size = after.min;
|
|
410
|
+
POINTER_LEAVE: {
|
|
411
|
+
target: "idle"
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
hover: {
|
|
416
|
+
tags: ["focus"],
|
|
417
|
+
on: {
|
|
418
|
+
POINTER_DOWN: {
|
|
419
|
+
target: "dragging"
|
|
525
420
|
},
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
421
|
+
POINTER_LEAVE: {
|
|
422
|
+
target: "idle"
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
focused: {
|
|
427
|
+
tags: ["focus"],
|
|
428
|
+
on: {
|
|
429
|
+
BLUR: {
|
|
430
|
+
target: "idle"
|
|
532
431
|
},
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
const { before, after } = bounds;
|
|
537
|
-
ctx2.size[before.index].size = before.up(evt.step);
|
|
538
|
-
ctx2.size[after.index].size = after.down(evt.step);
|
|
432
|
+
POINTER_DOWN: {
|
|
433
|
+
target: "dragging",
|
|
434
|
+
actions: ["setActiveHandleId"]
|
|
539
435
|
},
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
const { before, after } = bounds;
|
|
544
|
-
ctx2.size[before.index].size = before.down(evt.step);
|
|
545
|
-
ctx2.size[after.index].size = after.up(evt.step);
|
|
436
|
+
ARROW_LEFT: {
|
|
437
|
+
guard: "isHorizontal",
|
|
438
|
+
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
546
439
|
},
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
const { before, after } = bounds;
|
|
551
|
-
ctx2.size[before.index].size = ctx2.initialSize[before.index].size;
|
|
552
|
-
ctx2.size[after.index].size = ctx2.initialSize[after.index].size;
|
|
440
|
+
ARROW_RIGHT: {
|
|
441
|
+
guard: "isHorizontal",
|
|
442
|
+
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
553
443
|
},
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
});
|
|
444
|
+
ARROW_UP: {
|
|
445
|
+
guard: "isVertical",
|
|
446
|
+
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
558
447
|
},
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
});
|
|
448
|
+
ARROW_DOWN: {
|
|
449
|
+
guard: "isVertical",
|
|
450
|
+
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
563
451
|
},
|
|
564
|
-
|
|
565
|
-
|
|
452
|
+
ENTER: [
|
|
453
|
+
{
|
|
454
|
+
guard: "isStartPanelAtMax",
|
|
455
|
+
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
456
|
+
},
|
|
457
|
+
{ actions: ["setStartPanelToMax", "setPreviousPanels"] }
|
|
458
|
+
],
|
|
459
|
+
HOME: {
|
|
460
|
+
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
566
461
|
},
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
462
|
+
END: {
|
|
463
|
+
actions: ["setStartPanelToMax", "setPreviousPanels"]
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
dragging: {
|
|
468
|
+
tags: ["focus"],
|
|
469
|
+
entry: ["focusResizeHandle"],
|
|
470
|
+
effects: ["trackPointerMove"],
|
|
471
|
+
on: {
|
|
472
|
+
POINTER_MOVE: {
|
|
473
|
+
actions: ["setPointerValue", "setGlobalCursor", "invokeOnResize"]
|
|
575
474
|
},
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if (!panels || !bounds) return;
|
|
580
|
-
const rootEl = dom.getRootEl(ctx2);
|
|
581
|
-
if (!rootEl) return;
|
|
582
|
-
const relativePoint = domQuery.getRelativePoint(evt.point, rootEl);
|
|
583
|
-
const percentValue = relativePoint.getPercentValue({
|
|
584
|
-
dir: ctx2.dir,
|
|
585
|
-
orientation: ctx2.orientation
|
|
586
|
-
});
|
|
587
|
-
let pointValue = percentValue * 100;
|
|
588
|
-
ctx2.activeResizeState = {
|
|
589
|
-
isAtMin: pointValue < bounds.min,
|
|
590
|
-
isAtMax: pointValue > bounds.max
|
|
591
|
-
};
|
|
592
|
-
pointValue = clamp(pointValue, bounds.min, bounds.max);
|
|
593
|
-
const { before, after } = panels;
|
|
594
|
-
const offset = pointValue - before.end;
|
|
595
|
-
ctx2.size[before.index].size = before.size + offset;
|
|
596
|
-
ctx2.size[after.index].size = after.size - offset;
|
|
475
|
+
POINTER_UP: {
|
|
476
|
+
target: "focused",
|
|
477
|
+
actions: ["setPreviousPanels", "clearGlobalCursor", "blurResizeHandle", "invokeOnResizeEnd"]
|
|
597
478
|
}
|
|
598
479
|
}
|
|
599
480
|
}
|
|
600
|
-
|
|
601
|
-
|
|
481
|
+
},
|
|
482
|
+
implementations: {
|
|
483
|
+
effects: {
|
|
484
|
+
waitForHoverDelay: ({ send }) => {
|
|
485
|
+
const id = setTimeout(() => {
|
|
486
|
+
send({ type: "HOVER_DELAY" });
|
|
487
|
+
}, 250);
|
|
488
|
+
return () => clearTimeout(id);
|
|
489
|
+
},
|
|
490
|
+
trackPointerMove: ({ scope, send }) => {
|
|
491
|
+
const doc = scope.getDoc();
|
|
492
|
+
return domQuery.trackPointerMove(doc, {
|
|
493
|
+
onPointerMove(info) {
|
|
494
|
+
send({ type: "POINTER_MOVE", point: info.point });
|
|
495
|
+
},
|
|
496
|
+
onPointerUp() {
|
|
497
|
+
send({ type: "POINTER_UP" });
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
guards: {
|
|
503
|
+
isStartPanelAtMin: ({ context }) => context.get("activeResizeState").isAtMin,
|
|
504
|
+
isStartPanelAtMax: ({ context }) => context.get("activeResizeState").isAtMax,
|
|
505
|
+
isHorizontal: ({ prop }) => prop("orientation") === "horizontal",
|
|
506
|
+
isVertical: ({ prop }) => prop("orientation") !== "horizontal"
|
|
507
|
+
},
|
|
508
|
+
actions: {
|
|
509
|
+
setGlobalCursor({ context, scope, computed }) {
|
|
510
|
+
const activeState = context.get("activeResizeState");
|
|
511
|
+
const isHorizontal = computed("isHorizontal");
|
|
512
|
+
setupGlobalCursor(scope, activeState, isHorizontal);
|
|
513
|
+
},
|
|
514
|
+
clearGlobalCursor({ scope }) {
|
|
515
|
+
removeGlobalCursor(scope);
|
|
516
|
+
},
|
|
517
|
+
invokeOnResize({ context, prop }) {
|
|
518
|
+
prop("onSizeChange")?.({
|
|
519
|
+
size: Array.from(context.get("size")),
|
|
520
|
+
activeHandleId: context.get("activeResizeId")
|
|
521
|
+
});
|
|
522
|
+
},
|
|
523
|
+
invokeOnResizeEnd({ context, prop }) {
|
|
524
|
+
prop("onSizeChangeEnd")?.({
|
|
525
|
+
size: Array.from(context.get("size")),
|
|
526
|
+
activeHandleId: context.get("activeResizeId")
|
|
527
|
+
});
|
|
528
|
+
},
|
|
529
|
+
setActiveHandleId({ context, event }) {
|
|
530
|
+
context.set("activeResizeId", event.id);
|
|
531
|
+
},
|
|
532
|
+
clearActiveHandleId({ context }) {
|
|
533
|
+
context.set("activeResizeId", null);
|
|
534
|
+
},
|
|
535
|
+
setPanelSize({ context, event }) {
|
|
536
|
+
const { id, size } = event;
|
|
537
|
+
context.set(
|
|
538
|
+
"size",
|
|
539
|
+
(prev) => prev.map((panel) => {
|
|
540
|
+
const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
|
|
541
|
+
return panel.id === id ? { ...panel, size: panelSize } : panel;
|
|
542
|
+
})
|
|
543
|
+
);
|
|
544
|
+
},
|
|
545
|
+
setStartPanelToMin({ context, computed }) {
|
|
546
|
+
const bounds = getPanelBounds(computed("panels"), context.get("activeResizeId"));
|
|
547
|
+
if (!bounds) return;
|
|
548
|
+
const { before, after } = bounds;
|
|
549
|
+
context.set("size", (prev) => {
|
|
550
|
+
const next = prev.slice();
|
|
551
|
+
next[before.index].size = before.min;
|
|
552
|
+
next[after.index].size = after.min;
|
|
553
|
+
return next;
|
|
554
|
+
});
|
|
555
|
+
},
|
|
556
|
+
setStartPanelToMax({ context, computed }) {
|
|
557
|
+
const bounds = getPanelBounds(computed("panels"), context.get("activeResizeId"));
|
|
558
|
+
if (!bounds) return;
|
|
559
|
+
const { before, after } = bounds;
|
|
560
|
+
context.set("size", (prev) => {
|
|
561
|
+
const next = prev.slice();
|
|
562
|
+
next[before.index].size = before.max;
|
|
563
|
+
next[after.index].size = after.max;
|
|
564
|
+
return next;
|
|
565
|
+
});
|
|
566
|
+
},
|
|
567
|
+
expandStartPanel({ context, event, computed }) {
|
|
568
|
+
const bounds = getPanelBounds(computed("panels"), context.get("activeResizeId"));
|
|
569
|
+
if (!bounds) return;
|
|
570
|
+
const { before, after } = bounds;
|
|
571
|
+
context.set("size", (prev) => {
|
|
572
|
+
const next = prev.slice();
|
|
573
|
+
next[before.index].size = before.up(event.step);
|
|
574
|
+
next[after.index].size = after.down(event.step);
|
|
575
|
+
return next;
|
|
576
|
+
});
|
|
577
|
+
},
|
|
578
|
+
shrinkStartPanel({ context, event, computed }) {
|
|
579
|
+
const bounds = getPanelBounds(computed("panels"), context.get("activeResizeId"));
|
|
580
|
+
if (!bounds) return;
|
|
581
|
+
const { before, after } = bounds;
|
|
582
|
+
context.set("size", (prev) => {
|
|
583
|
+
const next = prev.slice();
|
|
584
|
+
next[before.index].size = before.down(event.step);
|
|
585
|
+
next[after.index].size = after.up(event.step);
|
|
586
|
+
return next;
|
|
587
|
+
});
|
|
588
|
+
},
|
|
589
|
+
resetStartPanel({ context, computed }) {
|
|
590
|
+
const bounds = getPanelBounds(computed("panels"), context.get("activeResizeId"));
|
|
591
|
+
if (!bounds) return;
|
|
592
|
+
const { before, after } = bounds;
|
|
593
|
+
const initialSize = context.initial("size");
|
|
594
|
+
context.set("size", (prev) => {
|
|
595
|
+
const next = prev.slice();
|
|
596
|
+
next[before.index].size = initialSize[before.index].size;
|
|
597
|
+
next[after.index].size = initialSize[after.index].size;
|
|
598
|
+
return next;
|
|
599
|
+
});
|
|
600
|
+
},
|
|
601
|
+
focusResizeHandle({ scope, context }) {
|
|
602
|
+
domQuery.raf(() => {
|
|
603
|
+
const activeId = context.get("activeResizeId");
|
|
604
|
+
if (!activeId) return;
|
|
605
|
+
getResizeTriggerEl(scope, activeId)?.focus({ preventScroll: true });
|
|
606
|
+
});
|
|
607
|
+
},
|
|
608
|
+
blurResizeHandle({ scope, context }) {
|
|
609
|
+
domQuery.raf(() => {
|
|
610
|
+
const activeId = context.get("activeResizeId");
|
|
611
|
+
if (!activeId) return;
|
|
612
|
+
getResizeTriggerEl(scope, activeId)?.blur();
|
|
613
|
+
});
|
|
614
|
+
},
|
|
615
|
+
setPreviousPanels({ refs, computed }) {
|
|
616
|
+
refs.set("previousPanels", computed("panels").slice());
|
|
617
|
+
},
|
|
618
|
+
setActiveResizeState({ context, computed }) {
|
|
619
|
+
const panels = getPanelBounds(computed("panels"), context.get("activeResizeId"));
|
|
620
|
+
if (!panels) return;
|
|
621
|
+
const { before } = panels;
|
|
622
|
+
context.set("activeResizeState", {
|
|
623
|
+
isAtMin: before.isAtMin,
|
|
624
|
+
isAtMax: before.isAtMax
|
|
625
|
+
});
|
|
626
|
+
},
|
|
627
|
+
setPointerValue({ context, event, prop, scope, computed }) {
|
|
628
|
+
const panels = getHandlePanels(computed("panels"), context.get("activeResizeId"));
|
|
629
|
+
const bounds = getHandleBounds(computed("panels"), context.get("activeResizeId"));
|
|
630
|
+
if (!panels || !bounds) return;
|
|
631
|
+
const rootEl = getRootEl(scope);
|
|
632
|
+
if (!rootEl) return;
|
|
633
|
+
const relativePoint = domQuery.getRelativePoint(event.point, rootEl);
|
|
634
|
+
const percentValue = relativePoint.getPercentValue({
|
|
635
|
+
dir: prop("dir"),
|
|
636
|
+
orientation: prop("orientation")
|
|
637
|
+
});
|
|
638
|
+
let pointValue = percentValue * 100;
|
|
639
|
+
context.set("activeResizeState", {
|
|
640
|
+
isAtMin: pointValue < bounds.min,
|
|
641
|
+
isAtMax: pointValue > bounds.max
|
|
642
|
+
});
|
|
643
|
+
pointValue = clamp(pointValue, bounds.min, bounds.max);
|
|
644
|
+
const { before, after } = panels;
|
|
645
|
+
const offset = pointValue - before.end;
|
|
646
|
+
context.set("size", (prev) => {
|
|
647
|
+
const next = prev.slice();
|
|
648
|
+
next[before.index].size = before.size + offset;
|
|
649
|
+
next[after.index].size = after.size - offset;
|
|
650
|
+
return next;
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
});
|
|
602
656
|
var props = types.createProps()([
|
|
603
657
|
"dir",
|
|
604
658
|
"getRootNode",
|
|
@@ -607,7 +661,8 @@ var props = types.createProps()([
|
|
|
607
661
|
"onSizeChange",
|
|
608
662
|
"onSizeChangeEnd",
|
|
609
663
|
"orientation",
|
|
610
|
-
"size"
|
|
664
|
+
"size",
|
|
665
|
+
"defaultSize"
|
|
611
666
|
]);
|
|
612
667
|
var splitProps = utils.createSplitProps(props);
|
|
613
668
|
var panelProps = types.createProps()(["id", "snapSize"]);
|