@destyler/splitter 0.1.0 → 0.2.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.js → index.mjs} +76 -87
- package/package.json +19 -10
- /package/dist/{index.d.ts → index.d.mts} +0 -0
|
@@ -27,10 +27,9 @@ const dom = createScope({
|
|
|
27
27
|
return cursor;
|
|
28
28
|
},
|
|
29
29
|
getPanelStyle(ctx, id) {
|
|
30
|
-
const flexGrow = ctx.panels.find((panel) => panel.id === id)?.size ?? "0";
|
|
31
30
|
return {
|
|
32
31
|
flexBasis: 0,
|
|
33
|
-
flexGrow,
|
|
32
|
+
flexGrow: ctx.panels.find((panel) => panel.id === id)?.size ?? "0",
|
|
34
33
|
flexShrink: 1,
|
|
35
34
|
overflow: "hidden"
|
|
36
35
|
};
|
|
@@ -85,7 +84,7 @@ function getNormalizedPanels(ctx) {
|
|
|
85
84
|
validateSize("size", totalSize);
|
|
86
85
|
let end = 0;
|
|
87
86
|
let remainingSize = 0;
|
|
88
|
-
|
|
87
|
+
return panels.map((panel) => {
|
|
89
88
|
const start = end;
|
|
90
89
|
if (panel.size != null) {
|
|
91
90
|
end += panel.size;
|
|
@@ -108,7 +107,6 @@ function getNormalizedPanels(ctx) {
|
|
|
108
107
|
remainingSize
|
|
109
108
|
};
|
|
110
109
|
});
|
|
111
|
-
return result;
|
|
112
110
|
}
|
|
113
111
|
function getHandlePanels(ctx, id = ctx.activeResizeId) {
|
|
114
112
|
const [beforeId, afterId] = id?.split(":") ?? [];
|
|
@@ -189,8 +187,7 @@ function connect(state, send, normalize) {
|
|
|
189
187
|
const panels = state.context.panels;
|
|
190
188
|
function getResizeTriggerState(props$1) {
|
|
191
189
|
const { id, disabled } = props$1;
|
|
192
|
-
const
|
|
193
|
-
const panelIds = ids.map((id$1) => dom.getPanelId(state.context, id$1));
|
|
190
|
+
const panelIds = id.split(":").map((id$1) => dom.getPanelId(state.context, id$1));
|
|
194
191
|
const panels$1 = getHandleBounds(state.context, id);
|
|
195
192
|
return {
|
|
196
193
|
disabled: !!disabled,
|
|
@@ -207,20 +204,18 @@ function connect(state, send, normalize) {
|
|
|
207
204
|
getResizeTriggerState,
|
|
208
205
|
bounds: getHandleBounds(state.context),
|
|
209
206
|
setToMinSize(id) {
|
|
210
|
-
const panel = panels.find((panel$1) => panel$1.id === id);
|
|
211
207
|
send({
|
|
212
208
|
type: "SET_PANEL_SIZE",
|
|
213
209
|
id,
|
|
214
|
-
size: panel?.minSize,
|
|
210
|
+
size: panels.find((panel) => panel.id === id)?.minSize,
|
|
215
211
|
src: "setToMinSize"
|
|
216
212
|
});
|
|
217
213
|
},
|
|
218
214
|
setToMaxSize(id) {
|
|
219
|
-
const panel = panels.find((panel$1) => panel$1.id === id);
|
|
220
215
|
send({
|
|
221
216
|
type: "SET_PANEL_SIZE",
|
|
222
217
|
id,
|
|
223
|
-
size: panel?.maxSize,
|
|
218
|
+
size: panels.find((panel) => panel.id === id)?.maxSize,
|
|
224
219
|
src: "setToMaxSize"
|
|
225
220
|
});
|
|
226
221
|
},
|
|
@@ -335,7 +330,7 @@ function connect(state, send, normalize) {
|
|
|
335
330
|
if (event.defaultPrevented) return;
|
|
336
331
|
if (disabled) return;
|
|
337
332
|
const moveStep = getEventStep(event) * step;
|
|
338
|
-
const
|
|
333
|
+
const exec = {
|
|
339
334
|
Enter() {
|
|
340
335
|
send("ENTER");
|
|
341
336
|
},
|
|
@@ -369,9 +364,7 @@ function connect(state, send, normalize) {
|
|
|
369
364
|
End() {
|
|
370
365
|
send("END");
|
|
371
366
|
}
|
|
372
|
-
};
|
|
373
|
-
const key = getEventKey(event, state.context);
|
|
374
|
-
const exec = keyMap[key];
|
|
367
|
+
}[getEventKey(event, state.context)];
|
|
375
368
|
if (exec) {
|
|
376
369
|
exec(event);
|
|
377
370
|
event.preventDefault();
|
|
@@ -385,7 +378,6 @@ function connect(state, send, normalize) {
|
|
|
385
378
|
//#endregion
|
|
386
379
|
//#region src/machine.ts
|
|
387
380
|
function machine(userContext) {
|
|
388
|
-
const ctx = compact(userContext);
|
|
389
381
|
return createMachine({
|
|
390
382
|
id: "splitter",
|
|
391
383
|
initial: "idle",
|
|
@@ -399,13 +391,13 @@ function machine(userContext) {
|
|
|
399
391
|
isAtMin: false,
|
|
400
392
|
isAtMax: false
|
|
401
393
|
},
|
|
402
|
-
...
|
|
394
|
+
...compact(userContext)
|
|
403
395
|
},
|
|
404
396
|
created: ["setPreviousPanels", "setInitialSize"],
|
|
405
397
|
watch: { size: ["setActiveResizeState"] },
|
|
406
398
|
computed: {
|
|
407
|
-
isHorizontal: (ctx
|
|
408
|
-
panels: (ctx
|
|
399
|
+
isHorizontal: (ctx) => ctx.orientation === "horizontal",
|
|
400
|
+
panels: (ctx) => getNormalizedPanels(ctx)
|
|
409
401
|
},
|
|
410
402
|
on: { SET_PANEL_SIZE: { actions: "setPanelSize" } },
|
|
411
403
|
states: {
|
|
@@ -495,9 +487,8 @@ function machine(userContext) {
|
|
|
495
487
|
}
|
|
496
488
|
}
|
|
497
489
|
}, {
|
|
498
|
-
activities: { trackPointerMove: (ctx
|
|
499
|
-
|
|
500
|
-
return trackPointerMove(doc, {
|
|
490
|
+
activities: { trackPointerMove: (ctx, _evt, { send }) => {
|
|
491
|
+
return trackPointerMove(dom.getDoc(ctx), {
|
|
501
492
|
onPointerMove(info) {
|
|
502
493
|
send({
|
|
503
494
|
type: "POINTER_MOVE",
|
|
@@ -510,46 +501,46 @@ function machine(userContext) {
|
|
|
510
501
|
});
|
|
511
502
|
} },
|
|
512
503
|
guards: {
|
|
513
|
-
isStartPanelAtMin: (ctx
|
|
514
|
-
isStartPanelAtMax: (ctx
|
|
515
|
-
isHorizontal: (ctx
|
|
516
|
-
isVertical: (ctx
|
|
504
|
+
isStartPanelAtMin: (ctx) => ctx.activeResizeState.isAtMin,
|
|
505
|
+
isStartPanelAtMax: (ctx) => ctx.activeResizeState.isAtMax,
|
|
506
|
+
isHorizontal: (ctx) => ctx.isHorizontal,
|
|
507
|
+
isVertical: (ctx) => !ctx.isHorizontal
|
|
517
508
|
},
|
|
518
509
|
delays: { HOVER_DELAY: 250 },
|
|
519
510
|
actions: {
|
|
520
|
-
setGlobalCursor(ctx
|
|
521
|
-
dom.setupGlobalCursor(ctx
|
|
511
|
+
setGlobalCursor(ctx) {
|
|
512
|
+
dom.setupGlobalCursor(ctx);
|
|
522
513
|
},
|
|
523
|
-
clearGlobalCursor(ctx
|
|
524
|
-
dom.removeGlobalCursor(ctx
|
|
514
|
+
clearGlobalCursor(ctx) {
|
|
515
|
+
dom.removeGlobalCursor(ctx);
|
|
525
516
|
},
|
|
526
|
-
invokeOnResize(ctx
|
|
527
|
-
ctx
|
|
528
|
-
size: Array.from(ctx
|
|
529
|
-
activeHandleId: ctx
|
|
517
|
+
invokeOnResize(ctx) {
|
|
518
|
+
ctx.onSizeChange?.({
|
|
519
|
+
size: Array.from(ctx.size),
|
|
520
|
+
activeHandleId: ctx.activeResizeId
|
|
530
521
|
});
|
|
531
522
|
},
|
|
532
|
-
invokeOnResizeEnd(ctx
|
|
533
|
-
ctx
|
|
534
|
-
size: Array.from(ctx
|
|
535
|
-
activeHandleId: ctx
|
|
523
|
+
invokeOnResizeEnd(ctx) {
|
|
524
|
+
ctx.onSizeChangeEnd?.({
|
|
525
|
+
size: Array.from(ctx.size),
|
|
526
|
+
activeHandleId: ctx.activeResizeId
|
|
536
527
|
});
|
|
537
528
|
},
|
|
538
|
-
setActiveHandleId(ctx
|
|
539
|
-
ctx
|
|
529
|
+
setActiveHandleId(ctx, evt) {
|
|
530
|
+
ctx.activeResizeId = evt.id;
|
|
540
531
|
},
|
|
541
|
-
clearActiveHandleId(ctx
|
|
542
|
-
ctx
|
|
532
|
+
clearActiveHandleId(ctx) {
|
|
533
|
+
ctx.activeResizeId = null;
|
|
543
534
|
},
|
|
544
|
-
setInitialSize(ctx
|
|
545
|
-
ctx
|
|
535
|
+
setInitialSize(ctx) {
|
|
536
|
+
ctx.initialSize = ctx.panels.slice().map((panel) => ({
|
|
546
537
|
id: panel.id,
|
|
547
538
|
size: panel.size
|
|
548
539
|
}));
|
|
549
540
|
},
|
|
550
|
-
setPanelSize(ctx
|
|
541
|
+
setPanelSize(ctx, evt) {
|
|
551
542
|
const { id, size } = evt;
|
|
552
|
-
ctx
|
|
543
|
+
ctx.size = ctx.size.map((panel) => {
|
|
553
544
|
const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
|
|
554
545
|
return panel.id === id ? {
|
|
555
546
|
...panel,
|
|
@@ -557,84 +548,82 @@ function machine(userContext) {
|
|
|
557
548
|
} : panel;
|
|
558
549
|
});
|
|
559
550
|
},
|
|
560
|
-
setStartPanelToMin(ctx
|
|
561
|
-
const bounds = getPanelBounds(ctx
|
|
551
|
+
setStartPanelToMin(ctx) {
|
|
552
|
+
const bounds = getPanelBounds(ctx);
|
|
562
553
|
if (!bounds) return;
|
|
563
554
|
const { before, after } = bounds;
|
|
564
|
-
ctx
|
|
565
|
-
ctx
|
|
555
|
+
ctx.size[before.index].size = before.min;
|
|
556
|
+
ctx.size[after.index].size = after.min;
|
|
566
557
|
},
|
|
567
|
-
setStartPanelToMax(ctx
|
|
568
|
-
const bounds = getPanelBounds(ctx
|
|
558
|
+
setStartPanelToMax(ctx) {
|
|
559
|
+
const bounds = getPanelBounds(ctx);
|
|
569
560
|
if (!bounds) return;
|
|
570
561
|
const { before, after } = bounds;
|
|
571
|
-
ctx
|
|
572
|
-
ctx
|
|
562
|
+
ctx.size[before.index].size = before.max;
|
|
563
|
+
ctx.size[after.index].size = after.max;
|
|
573
564
|
},
|
|
574
|
-
expandStartPanel(ctx
|
|
575
|
-
const bounds = getPanelBounds(ctx
|
|
565
|
+
expandStartPanel(ctx, evt) {
|
|
566
|
+
const bounds = getPanelBounds(ctx);
|
|
576
567
|
if (!bounds) return;
|
|
577
568
|
const { before, after } = bounds;
|
|
578
|
-
ctx
|
|
579
|
-
ctx
|
|
569
|
+
ctx.size[before.index].size = before.up(evt.step);
|
|
570
|
+
ctx.size[after.index].size = after.down(evt.step);
|
|
580
571
|
},
|
|
581
|
-
shrinkStartPanel(ctx
|
|
582
|
-
const bounds = getPanelBounds(ctx
|
|
572
|
+
shrinkStartPanel(ctx, evt) {
|
|
573
|
+
const bounds = getPanelBounds(ctx);
|
|
583
574
|
if (!bounds) return;
|
|
584
575
|
const { before, after } = bounds;
|
|
585
|
-
ctx
|
|
586
|
-
ctx
|
|
576
|
+
ctx.size[before.index].size = before.down(evt.step);
|
|
577
|
+
ctx.size[after.index].size = after.up(evt.step);
|
|
587
578
|
},
|
|
588
|
-
resetStartPanel(ctx
|
|
589
|
-
const bounds = getPanelBounds(ctx
|
|
579
|
+
resetStartPanel(ctx, evt) {
|
|
580
|
+
const bounds = getPanelBounds(ctx, evt.id);
|
|
590
581
|
if (!bounds) return;
|
|
591
582
|
const { before, after } = bounds;
|
|
592
|
-
ctx
|
|
593
|
-
ctx
|
|
583
|
+
ctx.size[before.index].size = ctx.initialSize[before.index].size;
|
|
584
|
+
ctx.size[after.index].size = ctx.initialSize[after.index].size;
|
|
594
585
|
},
|
|
595
|
-
focusResizeHandle(ctx
|
|
586
|
+
focusResizeHandle(ctx) {
|
|
596
587
|
raf(() => {
|
|
597
|
-
dom.getActiveHandleEl(ctx
|
|
588
|
+
dom.getActiveHandleEl(ctx)?.focus({ preventScroll: true });
|
|
598
589
|
});
|
|
599
590
|
},
|
|
600
|
-
blurResizeHandle(ctx
|
|
591
|
+
blurResizeHandle(ctx) {
|
|
601
592
|
raf(() => {
|
|
602
|
-
dom.getActiveHandleEl(ctx
|
|
593
|
+
dom.getActiveHandleEl(ctx)?.blur();
|
|
603
594
|
});
|
|
604
595
|
},
|
|
605
|
-
setPreviousPanels(ctx
|
|
606
|
-
ctx
|
|
596
|
+
setPreviousPanels(ctx) {
|
|
597
|
+
ctx.previousPanels = ctx.panels.slice();
|
|
607
598
|
},
|
|
608
|
-
setActiveResizeState(ctx
|
|
609
|
-
const panels = getPanelBounds(ctx
|
|
599
|
+
setActiveResizeState(ctx) {
|
|
600
|
+
const panels = getPanelBounds(ctx);
|
|
610
601
|
if (!panels) return;
|
|
611
602
|
const { before } = panels;
|
|
612
|
-
ctx
|
|
603
|
+
ctx.activeResizeState = {
|
|
613
604
|
isAtMin: before.isAtMin,
|
|
614
605
|
isAtMax: before.isAtMax
|
|
615
606
|
};
|
|
616
607
|
},
|
|
617
|
-
setPointerValue(ctx
|
|
618
|
-
const panels = getHandlePanels(ctx
|
|
619
|
-
const bounds = getHandleBounds(ctx
|
|
608
|
+
setPointerValue(ctx, evt) {
|
|
609
|
+
const panels = getHandlePanels(ctx);
|
|
610
|
+
const bounds = getHandleBounds(ctx);
|
|
620
611
|
if (!panels || !bounds) return;
|
|
621
|
-
const rootEl = dom.getRootEl(ctx
|
|
612
|
+
const rootEl = dom.getRootEl(ctx);
|
|
622
613
|
if (!rootEl) return;
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
let pointValue = percentValue * 100;
|
|
629
|
-
ctx$1.activeResizeState = {
|
|
614
|
+
let pointValue = getRelativePoint(evt.point, rootEl).getPercentValue({
|
|
615
|
+
dir: ctx.dir,
|
|
616
|
+
orientation: ctx.orientation
|
|
617
|
+
}) * 100;
|
|
618
|
+
ctx.activeResizeState = {
|
|
630
619
|
isAtMin: pointValue < bounds.min,
|
|
631
620
|
isAtMax: pointValue > bounds.max
|
|
632
621
|
};
|
|
633
622
|
pointValue = clamp(pointValue, bounds.min, bounds.max);
|
|
634
623
|
const { before, after } = panels;
|
|
635
624
|
const offset = pointValue - before.end;
|
|
636
|
-
ctx
|
|
637
|
-
ctx
|
|
625
|
+
ctx.size[before.index].size = before.size + offset;
|
|
626
|
+
ctx.size[after.index].size = after.size - offset;
|
|
638
627
|
}
|
|
639
628
|
}
|
|
640
629
|
});
|
package/package.json
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/splitter",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "A component that divides your layout into resizable sections.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/destyler/destyler",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/destyler/destyler.git",
|
|
12
|
+
"directory": "packages/components/splitter"
|
|
13
|
+
},
|
|
8
14
|
"exports": {
|
|
9
|
-
".": "./dist/index.
|
|
15
|
+
".": "./dist/index.mjs"
|
|
10
16
|
},
|
|
11
|
-
"main": "dist/index.
|
|
12
|
-
"module": "dist/index.
|
|
13
|
-
"types": "dist/index.d.
|
|
17
|
+
"main": "dist/index.mjs",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.mts",
|
|
14
20
|
"files": [
|
|
15
21
|
"*.d.ts",
|
|
16
22
|
"dist"
|
|
17
23
|
],
|
|
18
24
|
"dependencies": {
|
|
19
|
-
"@destyler/anatomy": "0.
|
|
20
|
-
"@destyler/
|
|
21
|
-
"@destyler/
|
|
22
|
-
"@destyler/
|
|
23
|
-
"@destyler/
|
|
25
|
+
"@destyler/anatomy": "0.2.0",
|
|
26
|
+
"@destyler/dom": "0.2.0",
|
|
27
|
+
"@destyler/utils": "0.2.0",
|
|
28
|
+
"@destyler/types": "0.2.0",
|
|
29
|
+
"@destyler/xstate": "0.2.0"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
24
33
|
},
|
|
25
34
|
"scripts": {
|
|
26
35
|
"clear": "rimraf ./dist",
|
|
File without changes
|