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