@zag-js/splitter 0.2.6 → 0.2.7
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-HPRMFGOY.mjs +9 -0
- package/dist/{chunk-F2ZDEPE3.mjs → chunk-IOEWCDUH.mjs} +171 -125
- package/dist/chunk-SQ3UMXCZ.mjs +131 -0
- package/dist/chunk-T56NFB6E.mjs +102 -0
- package/dist/chunk-X2M4RMIJ.mjs +206 -0
- package/dist/index.js +466 -321
- package/dist/index.mjs +5 -4
- package/dist/splitter.anatomy.d.ts +2 -2
- package/dist/splitter.anatomy.js +1 -8
- package/dist/splitter.anatomy.mjs +1 -1
- package/dist/splitter.connect.d.ts +18 -13
- package/dist/splitter.connect.js +214 -196
- package/dist/splitter.connect.mjs +4 -3
- package/dist/splitter.dom.d.ts +15 -13
- package/dist/splitter.dom.js +54 -49
- package/dist/splitter.dom.mjs +1 -1
- package/dist/splitter.machine.js +340 -172
- package/dist/splitter.machine.mjs +3 -2
- package/dist/splitter.types.d.ts +50 -78
- package/dist/splitter.utils.d.ts +54 -0
- package/dist/splitter.utils.js +159 -0
- package/dist/splitter.utils.mjs +14 -0
- package/package.json +4 -4
- package/dist/chunk-7IDNY7GP.mjs +0 -217
- package/dist/chunk-A3GF7W2N.mjs +0 -97
- package/dist/chunk-DX6NGFGC.mjs +0 -16
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dom
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-T56NFB6E.mjs";
|
|
4
|
+
import {
|
|
5
|
+
clamp,
|
|
6
|
+
getHandleBounds,
|
|
7
|
+
getHandlePanels,
|
|
8
|
+
getNormalizedPanels,
|
|
9
|
+
getPanelBounds
|
|
10
|
+
} from "./chunk-SQ3UMXCZ.mjs";
|
|
4
11
|
|
|
5
12
|
// src/splitter.machine.ts
|
|
6
|
-
import { createMachine
|
|
13
|
+
import { createMachine } from "@zag-js/core";
|
|
7
14
|
|
|
8
15
|
// ../../utilities/core/src/functions.ts
|
|
9
16
|
var runIfFn = (v, ...a) => {
|
|
@@ -82,6 +89,22 @@ function getPointRelativeToNode(point, element) {
|
|
|
82
89
|
const y = point.y - offset.top;
|
|
83
90
|
return { x, y };
|
|
84
91
|
}
|
|
92
|
+
var clampPercent = (value) => Math.max(0, Math.min(100, value));
|
|
93
|
+
function getPointPercentRelativeToNode(point, element) {
|
|
94
|
+
const relativePoint = getPointRelativeToNode(point, element);
|
|
95
|
+
const x = relativePoint.x / element.offsetWidth * 100;
|
|
96
|
+
const y = relativePoint.y / element.offsetHeight * 100;
|
|
97
|
+
return { x: clampPercent(x), y: clampPercent(y) };
|
|
98
|
+
}
|
|
99
|
+
function normalizePointValue(point, options) {
|
|
100
|
+
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
101
|
+
const { x, y } = point;
|
|
102
|
+
let result = { x, y };
|
|
103
|
+
if (orientation === "horizontal" && dir === "rtl") {
|
|
104
|
+
result = { x: 100 - x, y };
|
|
105
|
+
}
|
|
106
|
+
return orientation === "horizontal" ? result.x : result.y;
|
|
107
|
+
}
|
|
85
108
|
|
|
86
109
|
// ../../utilities/dom/src/listener.ts
|
|
87
110
|
var isRef = (v) => hasProp(v, "current");
|
|
@@ -243,54 +266,7 @@ function trackPointerMove(doc, opts) {
|
|
|
243
266
|
);
|
|
244
267
|
}
|
|
245
268
|
|
|
246
|
-
// ../../utilities/number/src/number.ts
|
|
247
|
-
function round(v, t) {
|
|
248
|
-
let num = valueOf(v);
|
|
249
|
-
const p = 10 ** (t != null ? t : 10);
|
|
250
|
-
num = Math.round(num * p) / p;
|
|
251
|
-
return t ? num.toFixed(t) : v.toString();
|
|
252
|
-
}
|
|
253
|
-
function clamp(v, o) {
|
|
254
|
-
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
255
|
-
}
|
|
256
|
-
function countDecimals(value) {
|
|
257
|
-
if (!Number.isFinite(value))
|
|
258
|
-
return 0;
|
|
259
|
-
let e = 1, p = 0;
|
|
260
|
-
while (Math.round(value * e) / e !== value) {
|
|
261
|
-
e *= 10;
|
|
262
|
-
p += 1;
|
|
263
|
-
}
|
|
264
|
-
return p;
|
|
265
|
-
}
|
|
266
|
-
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
267
|
-
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
268
|
-
function snapToStep(value, step) {
|
|
269
|
-
const num = valueOf(value);
|
|
270
|
-
const p = countDecimals(step);
|
|
271
|
-
const v = Math.round(num / step) * step;
|
|
272
|
-
return round(v, p);
|
|
273
|
-
}
|
|
274
|
-
function valueOf(v) {
|
|
275
|
-
if (typeof v === "number")
|
|
276
|
-
return v;
|
|
277
|
-
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
278
|
-
return !Number.isNaN(num) ? num : 0;
|
|
279
|
-
}
|
|
280
|
-
function decimalOperation(a, op, b) {
|
|
281
|
-
let result = op === "+" ? a + b : a - b;
|
|
282
|
-
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
283
|
-
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
284
|
-
a = Math.round(a * multiplier);
|
|
285
|
-
b = Math.round(b * multiplier);
|
|
286
|
-
result = op === "+" ? a + b : a - b;
|
|
287
|
-
result /= multiplier;
|
|
288
|
-
}
|
|
289
|
-
return result;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
269
|
// src/splitter.machine.ts
|
|
293
|
-
var { not } = guards;
|
|
294
270
|
function machine(userContext) {
|
|
295
271
|
const ctx = compact(userContext);
|
|
296
272
|
return createMachine(
|
|
@@ -299,32 +275,38 @@ function machine(userContext) {
|
|
|
299
275
|
initial: "unknown",
|
|
300
276
|
context: {
|
|
301
277
|
orientation: "horizontal",
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
278
|
+
activeResizeId: null,
|
|
279
|
+
previousPanels: [],
|
|
280
|
+
size: [],
|
|
281
|
+
initialSize: [],
|
|
282
|
+
activeResizeState: {
|
|
283
|
+
isAtMin: false,
|
|
284
|
+
isAtMax: false
|
|
285
|
+
},
|
|
307
286
|
...ctx
|
|
308
287
|
},
|
|
288
|
+
created: ["setPreviousPanels", "setInitialSize"],
|
|
289
|
+
watch: {
|
|
290
|
+
size: ["setActiveResizeState"]
|
|
291
|
+
},
|
|
309
292
|
computed: {
|
|
310
293
|
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
311
|
-
|
|
312
|
-
isAtMax: (ctx2) => ctx2.value === ctx2.max
|
|
294
|
+
panels: (ctx2) => getNormalizedPanels(ctx2)
|
|
313
295
|
},
|
|
314
296
|
on: {
|
|
315
297
|
COLLAPSE: {
|
|
316
|
-
actions: "
|
|
298
|
+
actions: "setStartPanelToMin"
|
|
317
299
|
},
|
|
318
300
|
EXPAND: {
|
|
319
|
-
actions: "
|
|
301
|
+
actions: "setStartPanelToMax"
|
|
320
302
|
},
|
|
321
303
|
TOGGLE: [
|
|
322
304
|
{
|
|
323
|
-
guard: "
|
|
324
|
-
actions: "
|
|
305
|
+
guard: "isStartPanelAtMin",
|
|
306
|
+
actions: "setStartPanelToMax"
|
|
325
307
|
},
|
|
326
308
|
{
|
|
327
|
-
actions: "
|
|
309
|
+
actions: "setStartPanelToMin"
|
|
328
310
|
}
|
|
329
311
|
]
|
|
330
312
|
},
|
|
@@ -335,13 +317,19 @@ function machine(userContext) {
|
|
|
335
317
|
}
|
|
336
318
|
},
|
|
337
319
|
idle: {
|
|
320
|
+
entry: ["clearActiveHandleId"],
|
|
338
321
|
on: {
|
|
339
322
|
POINTER_OVER: {
|
|
340
|
-
|
|
341
|
-
|
|
323
|
+
target: "hover:temp",
|
|
324
|
+
actions: ["setActiveHandleId"]
|
|
342
325
|
},
|
|
343
|
-
|
|
344
|
-
|
|
326
|
+
FOCUS: {
|
|
327
|
+
target: "focused",
|
|
328
|
+
actions: ["setActiveHandleId"]
|
|
329
|
+
},
|
|
330
|
+
DOUBLE_CLICK: {
|
|
331
|
+
actions: ["resetStartPanel", "setPreviousPanels"]
|
|
332
|
+
}
|
|
345
333
|
}
|
|
346
334
|
},
|
|
347
335
|
"hover:temp": {
|
|
@@ -351,7 +339,7 @@ function machine(userContext) {
|
|
|
351
339
|
on: {
|
|
352
340
|
POINTER_DOWN: {
|
|
353
341
|
target: "dragging",
|
|
354
|
-
actions: ["
|
|
342
|
+
actions: ["setActiveHandleId", "invokeOnResizeStart"]
|
|
355
343
|
},
|
|
356
344
|
POINTER_LEAVE: "idle"
|
|
357
345
|
}
|
|
@@ -361,7 +349,7 @@ function machine(userContext) {
|
|
|
361
349
|
on: {
|
|
362
350
|
POINTER_DOWN: {
|
|
363
351
|
target: "dragging",
|
|
364
|
-
actions: ["
|
|
352
|
+
actions: ["invokeOnResizeStart"]
|
|
365
353
|
},
|
|
366
354
|
POINTER_LEAVE: "idle"
|
|
367
355
|
}
|
|
@@ -372,57 +360,50 @@ function machine(userContext) {
|
|
|
372
360
|
BLUR: "idle",
|
|
373
361
|
POINTER_DOWN: {
|
|
374
362
|
target: "dragging",
|
|
375
|
-
actions: ["
|
|
363
|
+
actions: ["setActiveHandleId", "invokeOnResizeStart"]
|
|
376
364
|
},
|
|
377
365
|
ARROW_LEFT: {
|
|
378
366
|
guard: "isHorizontal",
|
|
379
|
-
actions: "
|
|
367
|
+
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
380
368
|
},
|
|
381
369
|
ARROW_RIGHT: {
|
|
382
370
|
guard: "isHorizontal",
|
|
383
|
-
actions: "
|
|
371
|
+
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
384
372
|
},
|
|
385
373
|
ARROW_UP: {
|
|
386
374
|
guard: "isVertical",
|
|
387
|
-
actions: "
|
|
375
|
+
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
388
376
|
},
|
|
389
377
|
ARROW_DOWN: {
|
|
390
378
|
guard: "isVertical",
|
|
391
|
-
actions: "
|
|
379
|
+
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
392
380
|
},
|
|
393
381
|
ENTER: [
|
|
394
382
|
{
|
|
395
|
-
guard: "
|
|
396
|
-
actions: "
|
|
383
|
+
guard: "isStartPanelAtMax",
|
|
384
|
+
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
397
385
|
},
|
|
398
|
-
{ actions: "
|
|
386
|
+
{ actions: ["setStartPanelToMax", "setPreviousPanels"] }
|
|
399
387
|
],
|
|
400
388
|
HOME: {
|
|
401
|
-
actions: "
|
|
389
|
+
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
402
390
|
},
|
|
403
391
|
END: {
|
|
404
|
-
actions: "
|
|
405
|
-
}
|
|
406
|
-
DOUBLE_CLICK: [
|
|
407
|
-
{
|
|
408
|
-
guard: "isCollapsed",
|
|
409
|
-
actions: "setToMax"
|
|
410
|
-
},
|
|
411
|
-
{ actions: "setToMin" }
|
|
412
|
-
]
|
|
392
|
+
actions: ["setStartPanelToMax", "setPreviousPanels"]
|
|
393
|
+
}
|
|
413
394
|
}
|
|
414
395
|
},
|
|
415
396
|
dragging: {
|
|
416
397
|
tags: ["focus"],
|
|
417
|
-
entry: "
|
|
418
|
-
activities: "trackPointerMove",
|
|
398
|
+
entry: "focusResizeHandle",
|
|
399
|
+
activities: ["trackPointerMove"],
|
|
419
400
|
on: {
|
|
401
|
+
POINTER_MOVE: {
|
|
402
|
+
actions: ["setPointerValue", "setGlobalCursor"]
|
|
403
|
+
},
|
|
420
404
|
POINTER_UP: {
|
|
421
405
|
target: "focused",
|
|
422
|
-
actions: ["
|
|
423
|
-
},
|
|
424
|
-
POINTER_MOVE: {
|
|
425
|
-
actions: "setPointerValue"
|
|
406
|
+
actions: ["invokeOnResizeEnd", "setPreviousPanels", "clearGlobalCursor", "blurResizeHandle"]
|
|
426
407
|
}
|
|
427
408
|
}
|
|
428
409
|
}
|
|
@@ -435,70 +416,135 @@ function machine(userContext) {
|
|
|
435
416
|
return trackPointerMove(doc, {
|
|
436
417
|
onPointerMove(info) {
|
|
437
418
|
send({ type: "POINTER_MOVE", point: info.point });
|
|
438
|
-
doc.documentElement.style.cursor = dom.getCursor(ctx2);
|
|
439
419
|
},
|
|
440
420
|
onPointerUp() {
|
|
441
421
|
send("POINTER_UP");
|
|
442
|
-
doc.documentElement.style.cursor = "";
|
|
443
422
|
}
|
|
444
423
|
});
|
|
445
424
|
}
|
|
446
425
|
},
|
|
447
426
|
guards: {
|
|
448
|
-
|
|
427
|
+
isStartPanelAtMin: (ctx2) => ctx2.activeResizeState.isAtMin,
|
|
428
|
+
isStartPanelAtMax: (ctx2) => ctx2.activeResizeState.isAtMax,
|
|
449
429
|
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
450
|
-
isVertical: (ctx2) => !ctx2.isHorizontal
|
|
451
|
-
isFixed: (ctx2) => !!ctx2.fixed
|
|
430
|
+
isVertical: (ctx2) => !ctx2.isHorizontal
|
|
452
431
|
},
|
|
453
432
|
delays: {
|
|
454
433
|
HOVER_DELAY: 250
|
|
455
434
|
},
|
|
456
435
|
actions: {
|
|
457
|
-
|
|
436
|
+
setGlobalCursor(ctx2) {
|
|
437
|
+
dom.setupGlobalCursor(ctx2);
|
|
438
|
+
},
|
|
439
|
+
clearGlobalCursor(ctx2) {
|
|
440
|
+
dom.removeGlobalCursor(ctx2);
|
|
441
|
+
},
|
|
442
|
+
invokeOnResize(ctx2) {
|
|
458
443
|
var _a;
|
|
459
|
-
|
|
460
|
-
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
461
|
-
}
|
|
444
|
+
(_a = ctx2.onResize) == null ? void 0 : _a.call(ctx2, { size: ctx2.size, activeHandleId: ctx2.activeResizeId });
|
|
462
445
|
},
|
|
463
|
-
|
|
446
|
+
invokeOnResizeStart(ctx2) {
|
|
464
447
|
var _a;
|
|
465
|
-
(_a = ctx2.
|
|
448
|
+
(_a = ctx2.onResizeStart) == null ? void 0 : _a.call(ctx2, { size: ctx2.size, activeHandleId: ctx2.activeResizeId });
|
|
466
449
|
},
|
|
467
|
-
|
|
450
|
+
invokeOnResizeEnd(ctx2) {
|
|
468
451
|
var _a;
|
|
469
|
-
(_a = ctx2.
|
|
452
|
+
(_a = ctx2.onResizeEnd) == null ? void 0 : _a.call(ctx2, { size: ctx2.size, activeHandleId: ctx2.activeResizeId });
|
|
470
453
|
},
|
|
471
|
-
|
|
472
|
-
ctx2.
|
|
454
|
+
setActiveHandleId(ctx2, evt) {
|
|
455
|
+
ctx2.activeResizeId = evt.id;
|
|
473
456
|
},
|
|
474
|
-
|
|
475
|
-
ctx2.
|
|
457
|
+
clearActiveHandleId(ctx2) {
|
|
458
|
+
ctx2.activeResizeId = null;
|
|
476
459
|
},
|
|
477
|
-
|
|
478
|
-
ctx2.
|
|
460
|
+
setInitialSize(ctx2) {
|
|
461
|
+
ctx2.initialSize = ctx2.panels.slice().map((panel) => ({
|
|
462
|
+
id: panel.id,
|
|
463
|
+
size: panel.size
|
|
464
|
+
}));
|
|
479
465
|
},
|
|
480
|
-
|
|
481
|
-
|
|
466
|
+
setStartPanelToMin(ctx2) {
|
|
467
|
+
const bounds = getPanelBounds(ctx2);
|
|
468
|
+
if (!bounds)
|
|
469
|
+
return;
|
|
470
|
+
const { before, after } = bounds;
|
|
471
|
+
ctx2.size[before.index].size = before.min;
|
|
472
|
+
ctx2.size[after.index].size = after.min;
|
|
473
|
+
},
|
|
474
|
+
setStartPanelToMax(ctx2) {
|
|
475
|
+
const bounds = getPanelBounds(ctx2);
|
|
476
|
+
if (!bounds)
|
|
477
|
+
return;
|
|
478
|
+
const { before, after } = bounds;
|
|
479
|
+
ctx2.size[before.index].size = before.max;
|
|
480
|
+
ctx2.size[after.index].size = after.max;
|
|
482
481
|
},
|
|
483
|
-
|
|
482
|
+
expandStartPanel(ctx2, evt) {
|
|
483
|
+
const bounds = getPanelBounds(ctx2);
|
|
484
|
+
if (!bounds)
|
|
485
|
+
return;
|
|
486
|
+
const { before, after } = bounds;
|
|
487
|
+
ctx2.size[before.index].size = before.up(evt.step);
|
|
488
|
+
ctx2.size[after.index].size = after.down(evt.step);
|
|
489
|
+
},
|
|
490
|
+
shrinkStartPanel(ctx2, evt) {
|
|
491
|
+
const bounds = getPanelBounds(ctx2);
|
|
492
|
+
if (!bounds)
|
|
493
|
+
return;
|
|
494
|
+
const { before, after } = bounds;
|
|
495
|
+
ctx2.size[before.index].size = before.down(evt.step);
|
|
496
|
+
ctx2.size[after.index].size = after.up(evt.step);
|
|
497
|
+
},
|
|
498
|
+
resetStartPanel(ctx2, evt) {
|
|
499
|
+
const bounds = getPanelBounds(ctx2, evt.id);
|
|
500
|
+
if (!bounds)
|
|
501
|
+
return;
|
|
502
|
+
const { before, after } = bounds;
|
|
503
|
+
ctx2.size[before.index].size = ctx2.initialSize[before.index].size;
|
|
504
|
+
ctx2.size[after.index].size = ctx2.initialSize[after.index].size;
|
|
505
|
+
},
|
|
506
|
+
focusResizeHandle(ctx2) {
|
|
484
507
|
raf(() => {
|
|
485
508
|
var _a;
|
|
486
|
-
|
|
509
|
+
(_a = dom.getActiveHandleEl(ctx2)) == null ? void 0 : _a.focus();
|
|
487
510
|
});
|
|
488
511
|
},
|
|
512
|
+
blurResizeHandle(ctx2) {
|
|
513
|
+
raf(() => {
|
|
514
|
+
var _a;
|
|
515
|
+
(_a = dom.getActiveHandleEl(ctx2)) == null ? void 0 : _a.blur();
|
|
516
|
+
});
|
|
517
|
+
},
|
|
518
|
+
setPreviousPanels(ctx2) {
|
|
519
|
+
ctx2.previousPanels = ctx2.panels.slice();
|
|
520
|
+
},
|
|
521
|
+
setActiveResizeState(ctx2) {
|
|
522
|
+
const panels = getPanelBounds(ctx2);
|
|
523
|
+
if (!panels)
|
|
524
|
+
return;
|
|
525
|
+
const { before } = panels;
|
|
526
|
+
ctx2.activeResizeState = {
|
|
527
|
+
isAtMin: before.isAtMin,
|
|
528
|
+
isAtMax: before.isAtMax
|
|
529
|
+
};
|
|
530
|
+
},
|
|
489
531
|
setPointerValue(ctx2, evt) {
|
|
490
|
-
const
|
|
491
|
-
|
|
532
|
+
const panels = getHandlePanels(ctx2);
|
|
533
|
+
const bounds = getHandleBounds(ctx2);
|
|
534
|
+
const rootEl = dom.getRootEl(ctx2);
|
|
535
|
+
if (!panels || !rootEl || !bounds)
|
|
492
536
|
return;
|
|
493
|
-
const
|
|
494
|
-
let
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
|
|
537
|
+
const percent = getPointPercentRelativeToNode(evt.point, rootEl);
|
|
538
|
+
let pointValue = normalizePointValue(percent, ctx2);
|
|
539
|
+
ctx2.activeResizeState = {
|
|
540
|
+
isAtMin: pointValue < bounds.min,
|
|
541
|
+
isAtMax: pointValue > bounds.max
|
|
542
|
+
};
|
|
543
|
+
pointValue = clamp(pointValue, bounds.min, bounds.max);
|
|
544
|
+
const { before, after } = panels;
|
|
545
|
+
const offset = pointValue - before.end;
|
|
546
|
+
ctx2.size[before.index].size = before.size + offset;
|
|
547
|
+
ctx2.size[after.index].size = after.size - offset;
|
|
502
548
|
}
|
|
503
549
|
}
|
|
504
550
|
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// src/splitter.utils.ts
|
|
2
|
+
function validateSize(key, size) {
|
|
3
|
+
if (Math.floor(size) > 100) {
|
|
4
|
+
throw new Error(`Total ${key} of panels cannot be greater than 100`);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function getNormalizedPanels(ctx) {
|
|
8
|
+
let numOfPanelsWithoutSize = 0;
|
|
9
|
+
let totalSize = 0;
|
|
10
|
+
let totalMinSize = 0;
|
|
11
|
+
const panels = ctx.size.map((panel) => {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const minSize = (_a = panel.minSize) != null ? _a : 10;
|
|
14
|
+
const maxSize = (_b = panel.maxSize) != null ? _b : 100;
|
|
15
|
+
totalMinSize += minSize;
|
|
16
|
+
if (panel.size == null) {
|
|
17
|
+
numOfPanelsWithoutSize++;
|
|
18
|
+
} else {
|
|
19
|
+
totalSize += panel.size;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
...panel,
|
|
23
|
+
minSize,
|
|
24
|
+
maxSize
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
validateSize("minSize", totalMinSize);
|
|
28
|
+
validateSize("size", totalSize);
|
|
29
|
+
let end = 0;
|
|
30
|
+
let remainingSize = 0;
|
|
31
|
+
const result = panels.map((panel) => {
|
|
32
|
+
let start = end;
|
|
33
|
+
if (panel.size != null) {
|
|
34
|
+
end += panel.size;
|
|
35
|
+
remainingSize = panel.size - panel.minSize;
|
|
36
|
+
return {
|
|
37
|
+
...panel,
|
|
38
|
+
start,
|
|
39
|
+
end,
|
|
40
|
+
remainingSize
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const size = (100 - totalSize) / numOfPanelsWithoutSize;
|
|
44
|
+
end += size;
|
|
45
|
+
remainingSize = size - panel.minSize;
|
|
46
|
+
return { ...panel, size, start, end, remainingSize };
|
|
47
|
+
});
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
function getHandlePanels(ctx, id = ctx.activeResizeId) {
|
|
51
|
+
var _a;
|
|
52
|
+
const [beforeId, afterId] = (_a = id == null ? void 0 : id.split(":")) != null ? _a : [];
|
|
53
|
+
if (!beforeId || !afterId)
|
|
54
|
+
return;
|
|
55
|
+
const beforeIndex = ctx.previousPanels.findIndex((panel) => panel.id === beforeId);
|
|
56
|
+
const afterIndex = ctx.previousPanels.findIndex((panel) => panel.id === afterId);
|
|
57
|
+
if (beforeIndex === -1 || afterIndex === -1)
|
|
58
|
+
return;
|
|
59
|
+
const before = ctx.previousPanels[beforeIndex];
|
|
60
|
+
const after = ctx.previousPanels[afterIndex];
|
|
61
|
+
return {
|
|
62
|
+
before: {
|
|
63
|
+
...before,
|
|
64
|
+
index: beforeIndex
|
|
65
|
+
},
|
|
66
|
+
after: {
|
|
67
|
+
...after,
|
|
68
|
+
index: afterIndex
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function getHandleBounds(ctx, id = ctx.activeResizeId) {
|
|
73
|
+
const panels = getHandlePanels(ctx, id);
|
|
74
|
+
if (!panels)
|
|
75
|
+
return;
|
|
76
|
+
const { before, after } = panels;
|
|
77
|
+
return {
|
|
78
|
+
min: Math.max(before.start + before.minSize, after.end - after.maxSize),
|
|
79
|
+
max: Math.min(after.end - after.minSize, before.maxSize + before.start)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function getPanelBounds(ctx, id) {
|
|
83
|
+
const bounds = getHandleBounds(ctx, id);
|
|
84
|
+
const panels = getHandlePanels(ctx, id);
|
|
85
|
+
if (!bounds || !panels)
|
|
86
|
+
return;
|
|
87
|
+
const { before, after } = panels;
|
|
88
|
+
const beforeMin = Math.abs(before.start - bounds.min);
|
|
89
|
+
const afterMin = after.size + (before.size - beforeMin);
|
|
90
|
+
const beforeMax = Math.abs(before.start - bounds.max);
|
|
91
|
+
const afterMax = after.size - (beforeMax - before.size);
|
|
92
|
+
return {
|
|
93
|
+
before: {
|
|
94
|
+
index: before.index,
|
|
95
|
+
min: beforeMin,
|
|
96
|
+
max: beforeMax,
|
|
97
|
+
isAtMin: beforeMin === before.size,
|
|
98
|
+
isAtMax: beforeMax === before.size,
|
|
99
|
+
up(step) {
|
|
100
|
+
return Math.min(before.size + step, beforeMax);
|
|
101
|
+
},
|
|
102
|
+
down(step) {
|
|
103
|
+
return Math.max(before.size - step, beforeMin);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
after: {
|
|
107
|
+
index: after.index,
|
|
108
|
+
min: afterMin,
|
|
109
|
+
max: afterMax,
|
|
110
|
+
isAtMin: afterMin === after.size,
|
|
111
|
+
isAtMax: afterMax === after.size,
|
|
112
|
+
up(step) {
|
|
113
|
+
return Math.min(after.size + step, afterMin);
|
|
114
|
+
},
|
|
115
|
+
down(step) {
|
|
116
|
+
return Math.max(after.size - step, afterMax);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function clamp(value, min, max) {
|
|
122
|
+
return Math.min(Math.max(value, min), max);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export {
|
|
126
|
+
getNormalizedPanels,
|
|
127
|
+
getHandlePanels,
|
|
128
|
+
getHandleBounds,
|
|
129
|
+
getPanelBounds,
|
|
130
|
+
clamp
|
|
131
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// ../../utilities/dom/src/query.ts
|
|
2
|
+
function isDocument(el) {
|
|
3
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
4
|
+
}
|
|
5
|
+
function isWindow(value) {
|
|
6
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
7
|
+
}
|
|
8
|
+
function getDocument(el) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (isWindow(el))
|
|
11
|
+
return el.document;
|
|
12
|
+
if (isDocument(el))
|
|
13
|
+
return el;
|
|
14
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
15
|
+
}
|
|
16
|
+
function defineDomHelpers(helpers) {
|
|
17
|
+
const dom2 = {
|
|
18
|
+
getRootNode: (ctx) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
21
|
+
},
|
|
22
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
23
|
+
getWin: (ctx) => {
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
26
|
+
},
|
|
27
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
28
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
...dom2,
|
|
32
|
+
...helpers
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
37
|
+
function queryAll(root, selector) {
|
|
38
|
+
var _a;
|
|
39
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/splitter.dom.ts
|
|
43
|
+
var dom = defineDomHelpers({
|
|
44
|
+
getRootId: (ctx) => `splitter:${ctx.id}`,
|
|
45
|
+
getResizeTriggerId: (ctx, id) => `splitter:${ctx.id}:splitter:${id}`,
|
|
46
|
+
getToggleTriggerId: (ctx) => `splitter:${ctx.id}:toggle-btn`,
|
|
47
|
+
getLabelId: (ctx) => `splitter:${ctx.id}:label`,
|
|
48
|
+
getPanelId: (ctx, id) => `splitter:${ctx.id}:panel:${id}`,
|
|
49
|
+
globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
|
|
50
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
51
|
+
getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
|
|
52
|
+
getPanelEl: (ctx, id) => dom.getById(ctx, dom.getPanelId(ctx, id)),
|
|
53
|
+
getCursor(ctx) {
|
|
54
|
+
const x = ctx.isHorizontal;
|
|
55
|
+
let cursor = x ? "col-resize" : "row-resize";
|
|
56
|
+
if (ctx.activeResizeState.isAtMin)
|
|
57
|
+
cursor = x ? "e-resize" : "s-resize";
|
|
58
|
+
if (ctx.activeResizeState.isAtMax)
|
|
59
|
+
cursor = x ? "w-resize" : "n-resize";
|
|
60
|
+
return cursor;
|
|
61
|
+
},
|
|
62
|
+
getPanelStyle(ctx, id) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const flexGrow = (_b = (_a = ctx.panels.find((panel) => panel.id === id)) == null ? void 0 : _a.size) != null ? _b : "0";
|
|
65
|
+
return {
|
|
66
|
+
flexBasis: 0,
|
|
67
|
+
flexGrow,
|
|
68
|
+
flexShrink: 1,
|
|
69
|
+
overflow: "hidden"
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
getActiveHandleEl(ctx) {
|
|
73
|
+
const activeId = ctx.activeResizeId;
|
|
74
|
+
if (activeId == null)
|
|
75
|
+
return;
|
|
76
|
+
return dom.getById(ctx, dom.getResizeTriggerId(ctx, activeId));
|
|
77
|
+
},
|
|
78
|
+
getResizeTriggerEls(ctx) {
|
|
79
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
80
|
+
return queryAll(dom.getRootEl(ctx), `[role=separator][data-ownedby='${ownerId}']`);
|
|
81
|
+
},
|
|
82
|
+
setupGlobalCursor(ctx) {
|
|
83
|
+
const styleEl = dom.getById(ctx, dom.globalCursorId(ctx));
|
|
84
|
+
const textContent = `* { cursor: ${dom.getCursor(ctx)} !important; }`;
|
|
85
|
+
if (styleEl) {
|
|
86
|
+
styleEl.textContent = textContent;
|
|
87
|
+
} else {
|
|
88
|
+
const style = dom.getDoc(ctx).createElement("style");
|
|
89
|
+
style.id = dom.globalCursorId(ctx);
|
|
90
|
+
style.textContent = textContent;
|
|
91
|
+
dom.getDoc(ctx).head.appendChild(style);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
removeGlobalCursor(ctx) {
|
|
95
|
+
var _a;
|
|
96
|
+
(_a = dom.getById(ctx, dom.globalCursorId(ctx))) == null ? void 0 : _a.remove();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
dom
|
|
102
|
+
};
|