@zag-js/splitter 0.10.5 → 0.11.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 +144 -0
- package/dist/index.d.ts +144 -4
- package/dist/index.js +670 -8
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +646 -3
- package/dist/index.mjs.map +1 -0
- package/package.json +9 -9
- package/dist/splitter.anatomy.d.ts +0 -3
- package/dist/splitter.anatomy.js +0 -11
- package/dist/splitter.anatomy.mjs +0 -6
- package/dist/splitter.connect.d.ts +0 -45
- package/dist/splitter.connect.js +0 -185
- package/dist/splitter.connect.mjs +0 -181
- package/dist/splitter.dom.d.ts +0 -38
- package/dist/splitter.dom.js +0 -62
- package/dist/splitter.dom.mjs +0 -58
- package/dist/splitter.machine.d.ts +0 -3
- package/dist/splitter.machine.js +0 -285
- package/dist/splitter.machine.mjs +0 -281
- package/dist/splitter.types.d.ts +0 -92
- package/dist/splitter.utils.d.ts +0 -49
- package/dist/splitter.utils.js +0 -130
- package/dist/splitter.utils.mjs +0 -122
package/dist/index.js
CHANGED
|
@@ -1,13 +1,675 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
anatomy: () => anatomy,
|
|
24
|
+
connect: () => connect,
|
|
25
|
+
machine: () => machine
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
4
28
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
29
|
+
// src/splitter.anatomy.ts
|
|
30
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
31
|
+
var anatomy = (0, import_anatomy.createAnatomy)("splitter").parts("root", "panel", "toggleTrigger", "resizeTrigger");
|
|
32
|
+
var parts = anatomy.build();
|
|
8
33
|
|
|
34
|
+
// src/splitter.connect.ts
|
|
35
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
36
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
9
37
|
|
|
38
|
+
// src/splitter.dom.ts
|
|
39
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
40
|
+
var dom = (0, import_dom_query.createScope)({
|
|
41
|
+
getRootId: (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`,
|
|
42
|
+
getResizeTriggerId: (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`,
|
|
43
|
+
getToggleTriggerId: (ctx) => ctx.ids?.toggleTrigger?.(ctx.id) ?? `splitter:${ctx.id}:toggle-btn`,
|
|
44
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`,
|
|
45
|
+
getPanelId: (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`,
|
|
46
|
+
globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
|
|
47
|
+
getRootEl: (ctx) => dom.queryById(ctx, dom.getRootId(ctx)),
|
|
48
|
+
getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
|
|
49
|
+
getPanelEl: (ctx, id) => dom.getById(ctx, dom.getPanelId(ctx, id)),
|
|
50
|
+
getCursor(ctx) {
|
|
51
|
+
const x = ctx.isHorizontal;
|
|
52
|
+
let cursor = x ? "col-resize" : "row-resize";
|
|
53
|
+
if (ctx.activeResizeState.isAtMin)
|
|
54
|
+
cursor = x ? "e-resize" : "s-resize";
|
|
55
|
+
if (ctx.activeResizeState.isAtMax)
|
|
56
|
+
cursor = x ? "w-resize" : "n-resize";
|
|
57
|
+
return cursor;
|
|
58
|
+
},
|
|
59
|
+
getPanelStyle(ctx, id) {
|
|
60
|
+
const flexGrow = ctx.panels.find((panel) => panel.id === id)?.size ?? "0";
|
|
61
|
+
return {
|
|
62
|
+
flexBasis: 0,
|
|
63
|
+
flexGrow,
|
|
64
|
+
flexShrink: 1,
|
|
65
|
+
overflow: "hidden"
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
getActiveHandleEl(ctx) {
|
|
69
|
+
const activeId = ctx.activeResizeId;
|
|
70
|
+
if (activeId == null)
|
|
71
|
+
return;
|
|
72
|
+
return dom.getById(ctx, dom.getResizeTriggerId(ctx, activeId));
|
|
73
|
+
},
|
|
74
|
+
getResizeTriggerEls(ctx) {
|
|
75
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
76
|
+
return (0, import_dom_query.queryAll)(dom.getRootEl(ctx), `[role=separator][data-ownedby='${ownerId}']`);
|
|
77
|
+
},
|
|
78
|
+
setupGlobalCursor(ctx) {
|
|
79
|
+
const styleEl = dom.getById(ctx, dom.globalCursorId(ctx));
|
|
80
|
+
const textContent = `* { cursor: ${dom.getCursor(ctx)} !important; }`;
|
|
81
|
+
if (styleEl) {
|
|
82
|
+
styleEl.textContent = textContent;
|
|
83
|
+
} else {
|
|
84
|
+
const style = dom.getDoc(ctx).createElement("style");
|
|
85
|
+
style.id = dom.globalCursorId(ctx);
|
|
86
|
+
style.textContent = textContent;
|
|
87
|
+
dom.getDoc(ctx).head.appendChild(style);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
removeGlobalCursor(ctx) {
|
|
91
|
+
dom.getById(ctx, dom.globalCursorId(ctx))?.remove();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
10
94
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
95
|
+
// src/splitter.utils.ts
|
|
96
|
+
function validateSize(key, size) {
|
|
97
|
+
if (Math.floor(size) > 100) {
|
|
98
|
+
throw new Error(`Total ${key} of panels cannot be greater than 100`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function getNormalizedPanels(ctx) {
|
|
102
|
+
let numOfPanelsWithoutSize = 0;
|
|
103
|
+
let totalSize = 0;
|
|
104
|
+
let totalMinSize = 0;
|
|
105
|
+
const panels = ctx.size.map((panel) => {
|
|
106
|
+
const minSize = panel.minSize ?? 0;
|
|
107
|
+
const maxSize = panel.maxSize ?? 100;
|
|
108
|
+
totalMinSize += minSize;
|
|
109
|
+
if (panel.size == null) {
|
|
110
|
+
numOfPanelsWithoutSize++;
|
|
111
|
+
} else {
|
|
112
|
+
totalSize += panel.size;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
...panel,
|
|
116
|
+
minSize,
|
|
117
|
+
maxSize
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
validateSize("minSize", totalMinSize);
|
|
121
|
+
validateSize("size", totalSize);
|
|
122
|
+
let end = 0;
|
|
123
|
+
let remainingSize = 0;
|
|
124
|
+
const result = panels.map((panel) => {
|
|
125
|
+
let start = end;
|
|
126
|
+
if (panel.size != null) {
|
|
127
|
+
end += panel.size;
|
|
128
|
+
remainingSize = panel.size - panel.minSize;
|
|
129
|
+
return {
|
|
130
|
+
...panel,
|
|
131
|
+
start,
|
|
132
|
+
end,
|
|
133
|
+
remainingSize
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const size = (100 - totalSize) / numOfPanelsWithoutSize;
|
|
137
|
+
end += size;
|
|
138
|
+
remainingSize = size - panel.minSize;
|
|
139
|
+
return { ...panel, size, start, end, remainingSize };
|
|
140
|
+
});
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
function getHandlePanels(ctx, id = ctx.activeResizeId) {
|
|
144
|
+
const [beforeId, afterId] = id?.split(":") ?? [];
|
|
145
|
+
if (!beforeId || !afterId)
|
|
146
|
+
return;
|
|
147
|
+
const beforeIndex = ctx.previousPanels.findIndex((panel) => panel.id === beforeId);
|
|
148
|
+
const afterIndex = ctx.previousPanels.findIndex((panel) => panel.id === afterId);
|
|
149
|
+
if (beforeIndex === -1 || afterIndex === -1)
|
|
150
|
+
return;
|
|
151
|
+
const before = ctx.previousPanels[beforeIndex];
|
|
152
|
+
const after = ctx.previousPanels[afterIndex];
|
|
153
|
+
return {
|
|
154
|
+
before: {
|
|
155
|
+
...before,
|
|
156
|
+
index: beforeIndex
|
|
157
|
+
},
|
|
158
|
+
after: {
|
|
159
|
+
...after,
|
|
160
|
+
index: afterIndex
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function getHandleBounds(ctx, id = ctx.activeResizeId) {
|
|
165
|
+
const panels = getHandlePanels(ctx, id);
|
|
166
|
+
if (!panels)
|
|
167
|
+
return;
|
|
168
|
+
const { before, after } = panels;
|
|
169
|
+
return {
|
|
170
|
+
min: Math.max(before.start + before.minSize, after.end - after.maxSize),
|
|
171
|
+
max: Math.min(after.end - after.minSize, before.maxSize + before.start)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function getPanelBounds(ctx, id) {
|
|
175
|
+
const bounds = getHandleBounds(ctx, id);
|
|
176
|
+
const panels = getHandlePanels(ctx, id);
|
|
177
|
+
if (!bounds || !panels)
|
|
178
|
+
return;
|
|
179
|
+
const { before, after } = panels;
|
|
180
|
+
const beforeMin = Math.abs(before.start - bounds.min);
|
|
181
|
+
const afterMin = after.size + (before.size - beforeMin);
|
|
182
|
+
const beforeMax = Math.abs(before.start - bounds.max);
|
|
183
|
+
const afterMax = after.size - (beforeMax - before.size);
|
|
184
|
+
return {
|
|
185
|
+
before: {
|
|
186
|
+
index: before.index,
|
|
187
|
+
min: beforeMin,
|
|
188
|
+
max: beforeMax,
|
|
189
|
+
isAtMin: beforeMin === before.size,
|
|
190
|
+
isAtMax: beforeMax === before.size,
|
|
191
|
+
up(step) {
|
|
192
|
+
return Math.min(before.size + step, beforeMax);
|
|
193
|
+
},
|
|
194
|
+
down(step) {
|
|
195
|
+
return Math.max(before.size - step, beforeMin);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
after: {
|
|
199
|
+
index: after.index,
|
|
200
|
+
min: afterMin,
|
|
201
|
+
max: afterMax,
|
|
202
|
+
isAtMin: afterMin === after.size,
|
|
203
|
+
isAtMax: afterMax === after.size,
|
|
204
|
+
up(step) {
|
|
205
|
+
return Math.min(after.size + step, afterMin);
|
|
206
|
+
},
|
|
207
|
+
down(step) {
|
|
208
|
+
return Math.max(after.size - step, afterMax);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function clamp(value, min, max) {
|
|
214
|
+
return Math.min(Math.max(value, min), max);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// src/splitter.connect.ts
|
|
218
|
+
function connect(state, send, normalize) {
|
|
219
|
+
const isHorizontal = state.context.isHorizontal;
|
|
220
|
+
const isFocused = state.hasTag("focus");
|
|
221
|
+
const isDragging = state.matches("dragging");
|
|
222
|
+
const panels = state.context.panels;
|
|
223
|
+
const api = {
|
|
224
|
+
/**
|
|
225
|
+
* Whether the splitter is focused.
|
|
226
|
+
*/
|
|
227
|
+
isFocused,
|
|
228
|
+
/**
|
|
229
|
+
* Whether the splitter is being dragged.
|
|
230
|
+
*/
|
|
231
|
+
isDragging,
|
|
232
|
+
/**
|
|
233
|
+
* The bounds of the currently dragged splitter handle.
|
|
234
|
+
*/
|
|
235
|
+
bounds: getHandleBounds(state.context),
|
|
236
|
+
/**
|
|
237
|
+
* Function to set a panel to its minimum size.
|
|
238
|
+
*/
|
|
239
|
+
setToMinSize(id) {
|
|
240
|
+
const panel = panels.find((panel2) => panel2.id === id);
|
|
241
|
+
send({ type: "SET_PANEL_SIZE", id, size: panel?.minSize, src: "setToMinSize" });
|
|
242
|
+
},
|
|
243
|
+
/**
|
|
244
|
+
* Function to set a panel to its maximum size.
|
|
245
|
+
*/
|
|
246
|
+
setToMaxSize(id) {
|
|
247
|
+
const panel = panels.find((panel2) => panel2.id === id);
|
|
248
|
+
send({ type: "SET_PANEL_SIZE", id, size: panel?.maxSize, src: "setToMaxSize" });
|
|
249
|
+
},
|
|
250
|
+
/**
|
|
251
|
+
* Function to set the size of a panel.
|
|
252
|
+
*/
|
|
253
|
+
setSize(id, size) {
|
|
254
|
+
send({ type: "SET_PANEL_SIZE", id, size });
|
|
255
|
+
},
|
|
256
|
+
/**
|
|
257
|
+
* Returns the state details for a resize trigger.
|
|
258
|
+
*/
|
|
259
|
+
getResizeTriggerState(props) {
|
|
260
|
+
const { id, disabled } = props;
|
|
261
|
+
const ids = id.split(":");
|
|
262
|
+
const panelIds = ids.map((id2) => dom.getPanelId(state.context, id2));
|
|
263
|
+
const panels2 = getHandleBounds(state.context, id);
|
|
264
|
+
return {
|
|
265
|
+
isDisabled: !!disabled,
|
|
266
|
+
isFocused: state.context.activeResizeId === id && isFocused,
|
|
267
|
+
panelIds,
|
|
268
|
+
min: panels2?.min,
|
|
269
|
+
max: panels2?.max,
|
|
270
|
+
value: 0
|
|
271
|
+
};
|
|
272
|
+
},
|
|
273
|
+
rootProps: normalize.element({
|
|
274
|
+
...parts.root.attrs,
|
|
275
|
+
"data-orientation": state.context.orientation,
|
|
276
|
+
id: dom.getRootId(state.context),
|
|
277
|
+
dir: state.context.dir,
|
|
278
|
+
style: {
|
|
279
|
+
display: "flex",
|
|
280
|
+
flexDirection: isHorizontal ? "row" : "column",
|
|
281
|
+
height: "100%",
|
|
282
|
+
width: "100%",
|
|
283
|
+
overflow: "hidden"
|
|
284
|
+
}
|
|
285
|
+
}),
|
|
286
|
+
getPanelProps(props) {
|
|
287
|
+
const { id } = props;
|
|
288
|
+
return normalize.element({
|
|
289
|
+
...parts.panel.attrs,
|
|
290
|
+
dir: state.context.dir,
|
|
291
|
+
id: dom.getPanelId(state.context, id),
|
|
292
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
293
|
+
style: dom.getPanelStyle(state.context, id)
|
|
294
|
+
});
|
|
295
|
+
},
|
|
296
|
+
getResizeTriggerProps(props) {
|
|
297
|
+
const { id, disabled, step = 1 } = props;
|
|
298
|
+
const triggerState = api.getResizeTriggerState(props);
|
|
299
|
+
return normalize.element({
|
|
300
|
+
...parts.resizeTrigger.attrs,
|
|
301
|
+
dir: state.context.dir,
|
|
302
|
+
id: dom.getResizeTriggerId(state.context, id),
|
|
303
|
+
role: "separator",
|
|
304
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
305
|
+
tabIndex: disabled ? void 0 : 0,
|
|
306
|
+
"aria-valuenow": triggerState.value,
|
|
307
|
+
"aria-valuemin": triggerState.min,
|
|
308
|
+
"aria-valuemax": triggerState.max,
|
|
309
|
+
"data-orientation": state.context.orientation,
|
|
310
|
+
"aria-orientation": state.context.orientation,
|
|
311
|
+
"aria-controls": triggerState.panelIds.join(" "),
|
|
312
|
+
"data-focus": (0, import_dom_query2.dataAttr)(triggerState.isFocused),
|
|
313
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
314
|
+
style: {
|
|
315
|
+
touchAction: "none",
|
|
316
|
+
userSelect: "none",
|
|
317
|
+
flex: "0 0 auto",
|
|
318
|
+
pointerEvents: isDragging && !triggerState.isFocused ? "none" : void 0,
|
|
319
|
+
cursor: isHorizontal ? "col-resize" : "row-resize",
|
|
320
|
+
[isHorizontal ? "minHeight" : "minWidth"]: "0"
|
|
321
|
+
},
|
|
322
|
+
onPointerDown(event) {
|
|
323
|
+
if (disabled) {
|
|
324
|
+
event.preventDefault();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
send({ type: "POINTER_DOWN", id });
|
|
328
|
+
event.preventDefault();
|
|
329
|
+
event.stopPropagation();
|
|
330
|
+
},
|
|
331
|
+
onPointerOver() {
|
|
332
|
+
if (disabled)
|
|
333
|
+
return;
|
|
334
|
+
send({ type: "POINTER_OVER", id });
|
|
335
|
+
},
|
|
336
|
+
onPointerLeave() {
|
|
337
|
+
if (disabled)
|
|
338
|
+
return;
|
|
339
|
+
send({ type: "POINTER_LEAVE", id });
|
|
340
|
+
},
|
|
341
|
+
onBlur() {
|
|
342
|
+
send("BLUR");
|
|
343
|
+
},
|
|
344
|
+
onFocus() {
|
|
345
|
+
send({ type: "FOCUS", id });
|
|
346
|
+
},
|
|
347
|
+
onDoubleClick() {
|
|
348
|
+
if (disabled)
|
|
349
|
+
return;
|
|
350
|
+
send({ type: "DOUBLE_CLICK", id });
|
|
351
|
+
},
|
|
352
|
+
onKeyDown(event) {
|
|
353
|
+
if (disabled)
|
|
354
|
+
return;
|
|
355
|
+
const moveStep = (0, import_dom_event.getEventStep)(event) * step;
|
|
356
|
+
const keyMap = {
|
|
357
|
+
Enter() {
|
|
358
|
+
send("ENTER");
|
|
359
|
+
},
|
|
360
|
+
ArrowUp() {
|
|
361
|
+
send({ type: "ARROW_UP", step: moveStep });
|
|
362
|
+
},
|
|
363
|
+
ArrowDown() {
|
|
364
|
+
send({ type: "ARROW_DOWN", step: moveStep });
|
|
365
|
+
},
|
|
366
|
+
ArrowLeft() {
|
|
367
|
+
send({ type: "ARROW_LEFT", step: moveStep });
|
|
368
|
+
},
|
|
369
|
+
ArrowRight() {
|
|
370
|
+
send({ type: "ARROW_RIGHT", step: moveStep });
|
|
371
|
+
},
|
|
372
|
+
Home() {
|
|
373
|
+
send("HOME");
|
|
374
|
+
},
|
|
375
|
+
End() {
|
|
376
|
+
send("END");
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const key = (0, import_dom_event.getEventKey)(event, state.context);
|
|
380
|
+
const exec = keyMap[key];
|
|
381
|
+
if (exec) {
|
|
382
|
+
exec(event);
|
|
383
|
+
event.preventDefault();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
return api;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/splitter.machine.ts
|
|
393
|
+
var import_core = require("@zag-js/core");
|
|
394
|
+
var import_dom_event2 = require("@zag-js/dom-event");
|
|
395
|
+
var import_dom_query3 = require("@zag-js/dom-query");
|
|
396
|
+
var import_utils = require("@zag-js/utils");
|
|
397
|
+
function machine(userContext) {
|
|
398
|
+
const ctx = (0, import_utils.compact)(userContext);
|
|
399
|
+
return (0, import_core.createMachine)(
|
|
400
|
+
{
|
|
401
|
+
id: "splitter",
|
|
402
|
+
initial: "idle",
|
|
403
|
+
context: {
|
|
404
|
+
orientation: "horizontal",
|
|
405
|
+
activeResizeId: null,
|
|
406
|
+
previousPanels: [],
|
|
407
|
+
size: [],
|
|
408
|
+
initialSize: [],
|
|
409
|
+
activeResizeState: {
|
|
410
|
+
isAtMin: false,
|
|
411
|
+
isAtMax: false
|
|
412
|
+
},
|
|
413
|
+
...ctx
|
|
414
|
+
},
|
|
415
|
+
created: ["setPreviousPanels", "setInitialSize"],
|
|
416
|
+
watch: {
|
|
417
|
+
size: ["setActiveResizeState"]
|
|
418
|
+
},
|
|
419
|
+
computed: {
|
|
420
|
+
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
421
|
+
panels: (ctx2) => getNormalizedPanels(ctx2)
|
|
422
|
+
},
|
|
423
|
+
on: {
|
|
424
|
+
SET_PANEL_SIZE: {
|
|
425
|
+
actions: "setPanelSize"
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
states: {
|
|
429
|
+
idle: {
|
|
430
|
+
entry: ["clearActiveHandleId"],
|
|
431
|
+
on: {
|
|
432
|
+
POINTER_OVER: {
|
|
433
|
+
target: "hover:temp",
|
|
434
|
+
actions: ["setActiveHandleId"]
|
|
435
|
+
},
|
|
436
|
+
FOCUS: {
|
|
437
|
+
target: "focused",
|
|
438
|
+
actions: ["setActiveHandleId"]
|
|
439
|
+
},
|
|
440
|
+
DOUBLE_CLICK: {
|
|
441
|
+
actions: ["resetStartPanel", "setPreviousPanels"]
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
"hover:temp": {
|
|
446
|
+
after: {
|
|
447
|
+
HOVER_DELAY: "hover"
|
|
448
|
+
},
|
|
449
|
+
on: {
|
|
450
|
+
POINTER_DOWN: {
|
|
451
|
+
target: "dragging",
|
|
452
|
+
actions: ["setActiveHandleId", "invokeOnResizeStart"]
|
|
453
|
+
},
|
|
454
|
+
POINTER_LEAVE: "idle"
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
hover: {
|
|
458
|
+
tags: ["focus"],
|
|
459
|
+
on: {
|
|
460
|
+
POINTER_DOWN: {
|
|
461
|
+
target: "dragging",
|
|
462
|
+
actions: ["invokeOnResizeStart"]
|
|
463
|
+
},
|
|
464
|
+
POINTER_LEAVE: "idle"
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
focused: {
|
|
468
|
+
tags: ["focus"],
|
|
469
|
+
on: {
|
|
470
|
+
BLUR: "idle",
|
|
471
|
+
POINTER_DOWN: {
|
|
472
|
+
target: "dragging",
|
|
473
|
+
actions: ["setActiveHandleId", "invokeOnResizeStart"]
|
|
474
|
+
},
|
|
475
|
+
ARROW_LEFT: {
|
|
476
|
+
guard: "isHorizontal",
|
|
477
|
+
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
478
|
+
},
|
|
479
|
+
ARROW_RIGHT: {
|
|
480
|
+
guard: "isHorizontal",
|
|
481
|
+
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
482
|
+
},
|
|
483
|
+
ARROW_UP: {
|
|
484
|
+
guard: "isVertical",
|
|
485
|
+
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
486
|
+
},
|
|
487
|
+
ARROW_DOWN: {
|
|
488
|
+
guard: "isVertical",
|
|
489
|
+
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
490
|
+
},
|
|
491
|
+
ENTER: [
|
|
492
|
+
{
|
|
493
|
+
guard: "isStartPanelAtMax",
|
|
494
|
+
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
495
|
+
},
|
|
496
|
+
{ actions: ["setStartPanelToMax", "setPreviousPanels"] }
|
|
497
|
+
],
|
|
498
|
+
HOME: {
|
|
499
|
+
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
500
|
+
},
|
|
501
|
+
END: {
|
|
502
|
+
actions: ["setStartPanelToMax", "setPreviousPanels"]
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
},
|
|
506
|
+
dragging: {
|
|
507
|
+
tags: ["focus"],
|
|
508
|
+
entry: "focusResizeHandle",
|
|
509
|
+
activities: ["trackPointerMove"],
|
|
510
|
+
on: {
|
|
511
|
+
POINTER_MOVE: {
|
|
512
|
+
actions: ["setPointerValue", "setGlobalCursor"]
|
|
513
|
+
},
|
|
514
|
+
POINTER_UP: {
|
|
515
|
+
target: "focused",
|
|
516
|
+
actions: ["invokeOnResizeEnd", "setPreviousPanels", "clearGlobalCursor", "blurResizeHandle"]
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
activities: {
|
|
524
|
+
trackPointerMove: (ctx2, _evt, { send }) => {
|
|
525
|
+
const doc = dom.getDoc(ctx2);
|
|
526
|
+
return (0, import_dom_event2.trackPointerMove)(doc, {
|
|
527
|
+
onPointerMove(info) {
|
|
528
|
+
send({ type: "POINTER_MOVE", point: info.point });
|
|
529
|
+
},
|
|
530
|
+
onPointerUp() {
|
|
531
|
+
send("POINTER_UP");
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
},
|
|
536
|
+
guards: {
|
|
537
|
+
isStartPanelAtMin: (ctx2) => ctx2.activeResizeState.isAtMin,
|
|
538
|
+
isStartPanelAtMax: (ctx2) => ctx2.activeResizeState.isAtMax,
|
|
539
|
+
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
540
|
+
isVertical: (ctx2) => !ctx2.isHorizontal
|
|
541
|
+
},
|
|
542
|
+
delays: {
|
|
543
|
+
HOVER_DELAY: 250
|
|
544
|
+
},
|
|
545
|
+
actions: {
|
|
546
|
+
setGlobalCursor(ctx2) {
|
|
547
|
+
dom.setupGlobalCursor(ctx2);
|
|
548
|
+
},
|
|
549
|
+
clearGlobalCursor(ctx2) {
|
|
550
|
+
dom.removeGlobalCursor(ctx2);
|
|
551
|
+
},
|
|
552
|
+
invokeOnResize(ctx2) {
|
|
553
|
+
ctx2.onResize?.({ size: ctx2.size, activeHandleId: ctx2.activeResizeId });
|
|
554
|
+
},
|
|
555
|
+
invokeOnResizeStart(ctx2) {
|
|
556
|
+
ctx2.onResizeStart?.({ size: ctx2.size, activeHandleId: ctx2.activeResizeId });
|
|
557
|
+
},
|
|
558
|
+
invokeOnResizeEnd(ctx2) {
|
|
559
|
+
ctx2.onResizeEnd?.({ size: ctx2.size, activeHandleId: ctx2.activeResizeId });
|
|
560
|
+
},
|
|
561
|
+
setActiveHandleId(ctx2, evt) {
|
|
562
|
+
ctx2.activeResizeId = evt.id;
|
|
563
|
+
},
|
|
564
|
+
clearActiveHandleId(ctx2) {
|
|
565
|
+
ctx2.activeResizeId = null;
|
|
566
|
+
},
|
|
567
|
+
setInitialSize(ctx2) {
|
|
568
|
+
ctx2.initialSize = ctx2.panels.slice().map((panel) => ({
|
|
569
|
+
id: panel.id,
|
|
570
|
+
size: panel.size
|
|
571
|
+
}));
|
|
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
|
+
},
|
|
580
|
+
setStartPanelToMin(ctx2) {
|
|
581
|
+
const bounds = getPanelBounds(ctx2);
|
|
582
|
+
if (!bounds)
|
|
583
|
+
return;
|
|
584
|
+
const { before, after } = bounds;
|
|
585
|
+
ctx2.size[before.index].size = before.min;
|
|
586
|
+
ctx2.size[after.index].size = after.min;
|
|
587
|
+
},
|
|
588
|
+
setStartPanelToMax(ctx2) {
|
|
589
|
+
const bounds = getPanelBounds(ctx2);
|
|
590
|
+
if (!bounds)
|
|
591
|
+
return;
|
|
592
|
+
const { before, after } = bounds;
|
|
593
|
+
ctx2.size[before.index].size = before.max;
|
|
594
|
+
ctx2.size[after.index].size = after.max;
|
|
595
|
+
},
|
|
596
|
+
expandStartPanel(ctx2, evt) {
|
|
597
|
+
const bounds = getPanelBounds(ctx2);
|
|
598
|
+
if (!bounds)
|
|
599
|
+
return;
|
|
600
|
+
const { before, after } = bounds;
|
|
601
|
+
ctx2.size[before.index].size = before.up(evt.step);
|
|
602
|
+
ctx2.size[after.index].size = after.down(evt.step);
|
|
603
|
+
},
|
|
604
|
+
shrinkStartPanel(ctx2, evt) {
|
|
605
|
+
const bounds = getPanelBounds(ctx2);
|
|
606
|
+
if (!bounds)
|
|
607
|
+
return;
|
|
608
|
+
const { before, after } = bounds;
|
|
609
|
+
ctx2.size[before.index].size = before.down(evt.step);
|
|
610
|
+
ctx2.size[after.index].size = after.up(evt.step);
|
|
611
|
+
},
|
|
612
|
+
resetStartPanel(ctx2, evt) {
|
|
613
|
+
const bounds = getPanelBounds(ctx2, evt.id);
|
|
614
|
+
if (!bounds)
|
|
615
|
+
return;
|
|
616
|
+
const { before, after } = bounds;
|
|
617
|
+
ctx2.size[before.index].size = ctx2.initialSize[before.index].size;
|
|
618
|
+
ctx2.size[after.index].size = ctx2.initialSize[after.index].size;
|
|
619
|
+
},
|
|
620
|
+
focusResizeHandle(ctx2) {
|
|
621
|
+
(0, import_dom_query3.raf)(() => {
|
|
622
|
+
dom.getActiveHandleEl(ctx2)?.focus({ preventScroll: true });
|
|
623
|
+
});
|
|
624
|
+
},
|
|
625
|
+
blurResizeHandle(ctx2) {
|
|
626
|
+
(0, import_dom_query3.raf)(() => {
|
|
627
|
+
dom.getActiveHandleEl(ctx2)?.blur();
|
|
628
|
+
});
|
|
629
|
+
},
|
|
630
|
+
setPreviousPanels(ctx2) {
|
|
631
|
+
ctx2.previousPanels = ctx2.panels.slice();
|
|
632
|
+
},
|
|
633
|
+
setActiveResizeState(ctx2) {
|
|
634
|
+
const panels = getPanelBounds(ctx2);
|
|
635
|
+
if (!panels)
|
|
636
|
+
return;
|
|
637
|
+
const { before } = panels;
|
|
638
|
+
ctx2.activeResizeState = {
|
|
639
|
+
isAtMin: before.isAtMin,
|
|
640
|
+
isAtMax: before.isAtMax
|
|
641
|
+
};
|
|
642
|
+
},
|
|
643
|
+
setPointerValue(ctx2, evt) {
|
|
644
|
+
const panels = getHandlePanels(ctx2);
|
|
645
|
+
const bounds = getHandleBounds(ctx2);
|
|
646
|
+
if (!panels || !bounds)
|
|
647
|
+
return;
|
|
648
|
+
const rootEl = dom.getRootEl(ctx2);
|
|
649
|
+
const relativePoint = (0, import_dom_event2.getRelativePoint)(evt.point, rootEl);
|
|
650
|
+
const percentValue = relativePoint.getPercentValue({
|
|
651
|
+
dir: ctx2.dir,
|
|
652
|
+
orientation: ctx2.orientation
|
|
653
|
+
});
|
|
654
|
+
let pointValue = percentValue * 100;
|
|
655
|
+
ctx2.activeResizeState = {
|
|
656
|
+
isAtMin: pointValue < bounds.min,
|
|
657
|
+
isAtMax: pointValue > bounds.max
|
|
658
|
+
};
|
|
659
|
+
pointValue = clamp(pointValue, bounds.min, bounds.max);
|
|
660
|
+
const { before, after } = panels;
|
|
661
|
+
const offset = pointValue - before.end;
|
|
662
|
+
ctx2.size[before.index].size = before.size + offset;
|
|
663
|
+
ctx2.size[after.index].size = after.size - offset;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
670
|
+
0 && (module.exports = {
|
|
671
|
+
anatomy,
|
|
672
|
+
connect,
|
|
673
|
+
machine
|
|
674
|
+
});
|
|
675
|
+
//# sourceMappingURL=index.js.map
|