@destyler/splitter 0.2.3-beta.7 → 0.2.3
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 +9 -1
- package/dist/index.mjs +36 -14
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { AnyEventObject, Machine, XSend, XState } from "@destyler/xstate";
|
|
|
4
4
|
import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, Required, RequiredBy } from "@destyler/types";
|
|
5
5
|
|
|
6
6
|
//#region src/anatomy.d.ts
|
|
7
|
-
declare const anatomy: _destyler_anatomy0.AnatomyInstance<"root" | "
|
|
7
|
+
declare const anatomy: _destyler_anatomy0.AnatomyInstance<"root" | "resizeTrigger" | "panel">;
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/types.d.ts
|
|
10
10
|
type PanelId = string | number;
|
|
@@ -74,6 +74,14 @@ interface PrivateContext {
|
|
|
74
74
|
isAtMax: boolean;
|
|
75
75
|
};
|
|
76
76
|
initialSize: Array<Required<Pick<PanelSizeData, 'id' | 'size'>>>;
|
|
77
|
+
initialDragPoint: {
|
|
78
|
+
x: number;
|
|
79
|
+
y: number;
|
|
80
|
+
} | null;
|
|
81
|
+
initialDragSizes: {
|
|
82
|
+
before: number;
|
|
83
|
+
after: number;
|
|
84
|
+
} | null;
|
|
77
85
|
}
|
|
78
86
|
interface MachineContext extends PublicContext, ComputedContext, PrivateContext {}
|
|
79
87
|
interface MachineState {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createAnatomy } from "@destyler/anatomy";
|
|
2
|
-
import { createScope, dataAttr, getEventKey, getEventStep,
|
|
2
|
+
import { createScope, dataAttr, getEventKey, getEventStep, queryAll, raf, trackPointerMove } from "@destyler/dom";
|
|
3
3
|
import { compact, createSplitProps } from "@destyler/utils";
|
|
4
4
|
import { createMachine } from "@destyler/xstate";
|
|
5
5
|
import { createProps } from "@destyler/types";
|
|
@@ -286,7 +286,11 @@ function connect(state, send, normalize) {
|
|
|
286
286
|
}
|
|
287
287
|
send({
|
|
288
288
|
type: "POINTER_DOWN",
|
|
289
|
-
id
|
|
289
|
+
id,
|
|
290
|
+
point: {
|
|
291
|
+
x: event.clientX,
|
|
292
|
+
y: event.clientY
|
|
293
|
+
}
|
|
290
294
|
});
|
|
291
295
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
292
296
|
event.preventDefault();
|
|
@@ -391,6 +395,8 @@ function machine(userContext) {
|
|
|
391
395
|
isAtMin: false,
|
|
392
396
|
isAtMax: false
|
|
393
397
|
},
|
|
398
|
+
initialDragPoint: null,
|
|
399
|
+
initialDragSizes: null,
|
|
394
400
|
...compact(userContext)
|
|
395
401
|
},
|
|
396
402
|
created: ["setPreviousPanels", "setInitialSize"],
|
|
@@ -466,7 +472,7 @@ function machine(userContext) {
|
|
|
466
472
|
},
|
|
467
473
|
"dragging": {
|
|
468
474
|
tags: ["focus"],
|
|
469
|
-
entry: "focusResizeHandle",
|
|
475
|
+
entry: ["focusResizeHandle", "storeInitialDragState"],
|
|
470
476
|
activities: ["trackPointerMove"],
|
|
471
477
|
on: {
|
|
472
478
|
POINTER_MOVE: { actions: [
|
|
@@ -593,6 +599,16 @@ function machine(userContext) {
|
|
|
593
599
|
dom.getActiveHandleEl(ctx)?.blur();
|
|
594
600
|
});
|
|
595
601
|
},
|
|
602
|
+
storeInitialDragState(ctx, evt) {
|
|
603
|
+
const panels = getHandlePanels(ctx);
|
|
604
|
+
if (!panels) return;
|
|
605
|
+
const { before, after } = panels;
|
|
606
|
+
ctx.initialDragPoint = evt.point;
|
|
607
|
+
ctx.initialDragSizes = {
|
|
608
|
+
before: before.size,
|
|
609
|
+
after: after.size
|
|
610
|
+
};
|
|
611
|
+
},
|
|
596
612
|
setPreviousPanels(ctx) {
|
|
597
613
|
ctx.previousPanels = ctx.panels.slice();
|
|
598
614
|
},
|
|
@@ -611,19 +627,25 @@ function machine(userContext) {
|
|
|
611
627
|
if (!panels || !bounds) return;
|
|
612
628
|
const rootEl = dom.getRootEl(ctx);
|
|
613
629
|
if (!rootEl) return;
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
630
|
+
if (!ctx.initialDragPoint || !ctx.initialDragSizes) return;
|
|
631
|
+
const { before, after } = panels;
|
|
632
|
+
const rootSize = ctx.isHorizontal ? rootEl.offsetWidth : rootEl.offsetHeight;
|
|
633
|
+
const currentPos = ctx.isHorizontal ? evt.point.x : evt.point.y;
|
|
634
|
+
const initialPos = ctx.isHorizontal ? ctx.initialDragPoint.x : ctx.initialDragPoint.y;
|
|
635
|
+
const deltaPercent = (ctx.dir === "rtl" && ctx.isHorizontal ? initialPos - currentPos : currentPos - initialPos) / rootSize * 100;
|
|
636
|
+
let newBeforeSize = ctx.initialDragSizes.before + deltaPercent;
|
|
637
|
+
let newAfterSize = ctx.initialDragSizes.after - deltaPercent;
|
|
618
638
|
ctx.activeResizeState = {
|
|
619
|
-
isAtMin:
|
|
620
|
-
isAtMax:
|
|
639
|
+
isAtMin: newBeforeSize <= before.minSize,
|
|
640
|
+
isAtMax: newBeforeSize >= before.maxSize
|
|
621
641
|
};
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
const
|
|
625
|
-
|
|
626
|
-
|
|
642
|
+
newBeforeSize = clamp(newBeforeSize, before.minSize, before.maxSize);
|
|
643
|
+
newAfterSize = clamp(newAfterSize, after.minSize, after.maxSize);
|
|
644
|
+
const totalSize = ctx.initialDragSizes.before + ctx.initialDragSizes.after;
|
|
645
|
+
if (newBeforeSize + newAfterSize > totalSize) if (deltaPercent > 0) newAfterSize = totalSize - newBeforeSize;
|
|
646
|
+
else newBeforeSize = totalSize - newAfterSize;
|
|
647
|
+
ctx.size[before.index].size = newBeforeSize;
|
|
648
|
+
ctx.size[after.index].size = newAfterSize;
|
|
627
649
|
}
|
|
628
650
|
}
|
|
629
651
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/splitter",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.3
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"description": "A component that divides your layout into resizable sections.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@destyler/anatomy": "0.2.3
|
|
26
|
-
"@destyler/dom": "0.2.3
|
|
27
|
-
"@destyler/
|
|
28
|
-
"@destyler/
|
|
29
|
-
"@destyler/
|
|
25
|
+
"@destyler/anatomy": "0.2.3",
|
|
26
|
+
"@destyler/dom": "0.2.3",
|
|
27
|
+
"@destyler/types": "0.2.3",
|
|
28
|
+
"@destyler/utils": "0.2.3",
|
|
29
|
+
"@destyler/xstate": "0.2.3"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|