@destyler/splitter 0.2.10 → 0.2.12
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 +10 -13
- package/dist/index.mjs +114 -114
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import * as _destyler_anatomy0 from "@destyler/anatomy";
|
|
2
|
-
import * as _destyler_xstate0 from "@destyler/xstate";
|
|
3
1
|
import { AnyEventObject, Machine, XSend, XState } from "@destyler/xstate";
|
|
4
2
|
import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, Required, RequiredBy } from "@destyler/types";
|
|
5
|
-
|
|
6
3
|
//#region src/anatomy.d.ts
|
|
7
|
-
declare const anatomy:
|
|
4
|
+
export declare const anatomy: import("@destyler/anatomy").AnatomyInstance<"root" | "panel" | "resizeTrigger">;
|
|
8
5
|
//#endregion
|
|
9
6
|
//#region src/types.d.ts
|
|
10
7
|
type PanelId = string | number;
|
|
@@ -152,17 +149,17 @@ interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
152
149
|
}
|
|
153
150
|
//#endregion
|
|
154
151
|
//#region src/connect.d.ts
|
|
155
|
-
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
152
|
+
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
156
153
|
//#endregion
|
|
157
154
|
//#region src/machine.d.ts
|
|
158
|
-
declare function machine(userContext: UserDefinedContext):
|
|
155
|
+
export declare function machine(userContext: UserDefinedContext): import("@destyler/xstate").Machine<MachineContext, MachineState, import("@destyler/xstate").AnyEventObject>;
|
|
159
156
|
//#endregion
|
|
160
157
|
//#region src/props.d.ts
|
|
161
|
-
declare const props: ("orientation" | "size" | "defaultSize" | "onSizeChange" | "onSizeChangeEnd" | "ids" | "dir" | "id" | "getRootNode")[];
|
|
162
|
-
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "orientation" | "size" | "defaultSize" | "onSizeChange" | "onSizeChangeEnd" | "ids" | "dir" | "id" | "getRootNode">];
|
|
163
|
-
declare const panelProps: (keyof PanelProps)[];
|
|
164
|
-
declare const splitPanelProps: <Props extends PanelProps>(props: Props) => [PanelProps, Omit<Props, keyof PanelProps>];
|
|
165
|
-
declare const resizeTriggerProps: (keyof ResizeTriggerProps)[];
|
|
166
|
-
declare const splitResizeTriggerProps: <Props extends ResizeTriggerProps>(props: Props) => [ResizeTriggerProps, Omit<Props, keyof ResizeTriggerProps>];
|
|
158
|
+
export declare const props: ("orientation" | "size" | "defaultSize" | "onSizeChange" | "onSizeChangeEnd" | "ids" | "dir" | "id" | "getRootNode")[];
|
|
159
|
+
export declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "orientation" | "size" | "defaultSize" | "onSizeChange" | "onSizeChangeEnd" | "ids" | "dir" | "id" | "getRootNode">];
|
|
160
|
+
export declare const panelProps: (keyof PanelProps)[];
|
|
161
|
+
export declare const splitPanelProps: <Props extends PanelProps>(props: Props) => [PanelProps, Omit<Props, keyof PanelProps>];
|
|
162
|
+
export declare const resizeTriggerProps: (keyof ResizeTriggerProps)[];
|
|
163
|
+
export declare const splitResizeTriggerProps: <Props extends ResizeTriggerProps>(props: Props) => [ResizeTriggerProps, Omit<Props, keyof ResizeTriggerProps>];
|
|
167
164
|
//#endregion
|
|
168
|
-
export {
|
|
165
|
+
export type { MachineApi as Api, UserDefinedContext as Context, MachineState, PanelProps, PanelSizeData, ResizeTriggerProps, Service, SizeChangeDetails };
|
package/dist/index.mjs
CHANGED
|
@@ -3,13 +3,12 @@ import { createScope, dataAttr, getEventKey, getEventStep, queryAll, raf, trackP
|
|
|
3
3
|
import { compact, createSplitProps, isControlled, isEqual, isPropUserProvided, resolveControllableProp, withControllableProvided } from "@destyler/utils";
|
|
4
4
|
import { createMachine } from "@destyler/xstate";
|
|
5
5
|
import { createProps } from "@destyler/types";
|
|
6
|
-
|
|
7
6
|
//#region src/anatomy.ts
|
|
8
7
|
const anatomy = createAnatomy("splitter").parts("root", "panel", "resizeTrigger");
|
|
9
8
|
const parts = anatomy.build();
|
|
10
|
-
|
|
11
9
|
//#endregion
|
|
12
10
|
//#region src/dom.ts
|
|
11
|
+
const cursorStyles = /* @__PURE__ */ new WeakMap();
|
|
13
12
|
const dom = createScope({
|
|
14
13
|
getRootId: (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`,
|
|
15
14
|
getResizeTriggerId: (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`,
|
|
@@ -44,21 +43,20 @@ const dom = createScope({
|
|
|
44
43
|
return queryAll(dom.getRootEl(ctx), `[role=separator][data-ownedby='${ownerId}']`);
|
|
45
44
|
},
|
|
46
45
|
setupGlobalCursor(ctx) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
else {
|
|
51
|
-
const style = dom.getDoc(ctx).createElement("style");
|
|
46
|
+
let style = cursorStyles.get(ctx);
|
|
47
|
+
if (!style) {
|
|
48
|
+
style = dom.getDoc(ctx).createElement("style");
|
|
52
49
|
style.id = dom.getGlobalCursorId(ctx);
|
|
53
|
-
|
|
54
|
-
dom.getDoc(ctx).head.appendChild(style);
|
|
50
|
+
cursorStyles.set(ctx, style);
|
|
55
51
|
}
|
|
52
|
+
style.textContent = `* { cursor: ${dom.getCursor(ctx)} !important; }`;
|
|
53
|
+
if (!style.isConnected) dom.getDoc(ctx).head.appendChild(style);
|
|
56
54
|
},
|
|
57
55
|
removeGlobalCursor(ctx) {
|
|
58
|
-
|
|
56
|
+
cursorStyles.get(ctx)?.remove();
|
|
57
|
+
cursorStyles.delete(ctx);
|
|
59
58
|
}
|
|
60
59
|
});
|
|
61
|
-
|
|
62
60
|
//#endregion
|
|
63
61
|
//#region src/utils.ts
|
|
64
62
|
function validateSize(key, size) {
|
|
@@ -68,7 +66,9 @@ function getNormalizedPanels(ctx) {
|
|
|
68
66
|
let numOfPanelsWithoutSize = 0;
|
|
69
67
|
let totalSize = 0;
|
|
70
68
|
let totalMinSize = 0;
|
|
71
|
-
const
|
|
69
|
+
const size = ctx.size;
|
|
70
|
+
if (size === void 0) throw new TypeError("Splitter size must be initialized before normalizing panels");
|
|
71
|
+
const panels = size.map((panel) => {
|
|
72
72
|
const minSize = panel.minSize ?? 0;
|
|
73
73
|
const maxSize = panel.maxSize ?? 100;
|
|
74
74
|
totalMinSize += minSize;
|
|
@@ -111,8 +111,8 @@ function getNormalizedPanels(ctx) {
|
|
|
111
111
|
function getHandlePanels(ctx, id = ctx.activeResizeId) {
|
|
112
112
|
const [beforeId, afterId] = id?.split(":") ?? [];
|
|
113
113
|
if (!beforeId || !afterId) return;
|
|
114
|
-
const beforeIndex = ctx.previousPanels.findIndex((panel) => panel.id === beforeId);
|
|
115
|
-
const afterIndex = ctx.previousPanels.findIndex((panel) => panel.id === afterId);
|
|
114
|
+
const beforeIndex = ctx.previousPanels.findIndex((panel) => String(panel.id) === beforeId);
|
|
115
|
+
const afterIndex = ctx.previousPanels.findIndex((panel) => String(panel.id) === afterId);
|
|
116
116
|
if (beforeIndex === -1 || afterIndex === -1) return;
|
|
117
117
|
const before = ctx.previousPanels[beforeIndex];
|
|
118
118
|
const after = ctx.previousPanels[afterIndex];
|
|
@@ -177,7 +177,6 @@ function getPanelBounds(ctx, id) {
|
|
|
177
177
|
function clamp(value, min, max) {
|
|
178
178
|
return Math.min(Math.max(value, min), max);
|
|
179
179
|
}
|
|
180
|
-
|
|
181
180
|
//#endregion
|
|
182
181
|
//#region src/connect.ts
|
|
183
182
|
function connect(state, send, normalize) {
|
|
@@ -185,17 +184,18 @@ function connect(state, send, normalize) {
|
|
|
185
184
|
const focused = state.hasTag("focus");
|
|
186
185
|
const dragging = state.matches("dragging");
|
|
187
186
|
const panels = state.context.panels;
|
|
188
|
-
function getResizeTriggerState(props
|
|
189
|
-
const { id, disabled } = props
|
|
190
|
-
const
|
|
191
|
-
const
|
|
187
|
+
function getResizeTriggerState(props) {
|
|
188
|
+
const { id, disabled } = props;
|
|
189
|
+
const ids = id.split(":");
|
|
190
|
+
const panelIds = ids.map((id) => dom.getPanelId(state.context, id));
|
|
191
|
+
const panels = getHandleBounds(state.context, id);
|
|
192
192
|
return {
|
|
193
193
|
disabled: !!disabled,
|
|
194
194
|
focused: state.context.activeResizeId === id && focused,
|
|
195
195
|
panelIds,
|
|
196
|
-
min: panels
|
|
197
|
-
max: panels
|
|
198
|
-
value: 0
|
|
196
|
+
min: panels?.min,
|
|
197
|
+
max: panels?.max,
|
|
198
|
+
value: state.context.panels.find((panel) => String(panel.id) === ids[0])?.end ?? 0
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
201
|
return {
|
|
@@ -241,8 +241,8 @@ function connect(state, send, normalize) {
|
|
|
241
241
|
}
|
|
242
242
|
});
|
|
243
243
|
},
|
|
244
|
-
getPanelProps(props
|
|
245
|
-
const { id } = props
|
|
244
|
+
getPanelProps(props) {
|
|
245
|
+
const { id } = props;
|
|
246
246
|
return normalize.element({
|
|
247
247
|
...parts.panel.attrs,
|
|
248
248
|
"data-orientation": state.context.orientation,
|
|
@@ -252,9 +252,9 @@ function connect(state, send, normalize) {
|
|
|
252
252
|
"style": dom.getPanelStyle(state.context, id)
|
|
253
253
|
});
|
|
254
254
|
},
|
|
255
|
-
getResizeTriggerProps(props
|
|
256
|
-
const { id, disabled, step = 1 } = props
|
|
257
|
-
const triggerState = getResizeTriggerState(props
|
|
255
|
+
getResizeTriggerProps(props) {
|
|
256
|
+
const { id, disabled, step = 1 } = props;
|
|
257
|
+
const triggerState = getResizeTriggerState(props);
|
|
258
258
|
return normalize.element({
|
|
259
259
|
...parts.resizeTrigger.attrs,
|
|
260
260
|
"dir": state.context.dir,
|
|
@@ -280,6 +280,7 @@ function connect(state, send, normalize) {
|
|
|
280
280
|
[horizontal ? "minHeight" : "minWidth"]: "0"
|
|
281
281
|
},
|
|
282
282
|
onPointerDown(event) {
|
|
283
|
+
if (event.defaultPrevented || event.button !== 0 || event.isPrimary === false) return;
|
|
283
284
|
if (disabled) {
|
|
284
285
|
event.preventDefault();
|
|
285
286
|
return;
|
|
@@ -378,7 +379,6 @@ function connect(state, send, normalize) {
|
|
|
378
379
|
}
|
|
379
380
|
};
|
|
380
381
|
}
|
|
381
|
-
|
|
382
382
|
//#endregion
|
|
383
383
|
//#region src/machine.ts
|
|
384
384
|
function cloneSize(size) {
|
|
@@ -423,7 +423,6 @@ function machine(userContext) {
|
|
|
423
423
|
orientation: "horizontal",
|
|
424
424
|
activeResizeId: null,
|
|
425
425
|
previousPanels: [],
|
|
426
|
-
size: [],
|
|
427
426
|
initialSize: [],
|
|
428
427
|
activeResizeState: {
|
|
429
428
|
isAtMin: false,
|
|
@@ -435,16 +434,20 @@ function machine(userContext) {
|
|
|
435
434
|
size: cloneSize(initialSize)
|
|
436
435
|
},
|
|
437
436
|
created: ["setPreviousPanels", "setInitialSize"],
|
|
438
|
-
watch: { size: ["setActiveResizeState"] },
|
|
437
|
+
watch: { size: ["setPreviousPanels", "setActiveResizeState"] },
|
|
439
438
|
computed: {
|
|
440
|
-
isHorizontal: (ctx
|
|
441
|
-
panels: (ctx
|
|
439
|
+
isHorizontal: (ctx) => ctx.orientation === "horizontal",
|
|
440
|
+
panels: (ctx) => getNormalizedPanels(ctx)
|
|
442
441
|
},
|
|
443
442
|
on: { SET_PANEL_SIZE: { actions: "setPanelSize" } },
|
|
444
443
|
states: {
|
|
445
444
|
"idle": {
|
|
446
445
|
entry: ["clearActiveHandleId"],
|
|
447
446
|
on: {
|
|
447
|
+
POINTER_DOWN: {
|
|
448
|
+
target: "dragging",
|
|
449
|
+
actions: ["setActiveHandleId"]
|
|
450
|
+
},
|
|
448
451
|
POINTER_OVER: {
|
|
449
452
|
target: "hover:temp",
|
|
450
453
|
actions: ["setActiveHandleId"]
|
|
@@ -509,13 +512,13 @@ function machine(userContext) {
|
|
|
509
512
|
tags: ["focus"],
|
|
510
513
|
entry: ["focusResizeHandle", "storeInitialDragState"],
|
|
511
514
|
activities: ["trackPointerMove"],
|
|
515
|
+
exit: ["clearGlobalCursor"],
|
|
512
516
|
on: {
|
|
513
517
|
POINTER_MOVE: { actions: ["setPointerValue", "setGlobalCursor"] },
|
|
514
518
|
POINTER_UP: {
|
|
515
519
|
target: "focused",
|
|
516
520
|
actions: [
|
|
517
521
|
"setPreviousPanels",
|
|
518
|
-
"clearGlobalCursor",
|
|
519
522
|
"blurResizeHandle",
|
|
520
523
|
"invokeOnResizeEnd"
|
|
521
524
|
]
|
|
@@ -524,8 +527,9 @@ function machine(userContext) {
|
|
|
524
527
|
}
|
|
525
528
|
}
|
|
526
529
|
}, {
|
|
527
|
-
activities: { trackPointerMove: (ctx
|
|
528
|
-
|
|
530
|
+
activities: { trackPointerMove: (ctx, _evt, { send }) => {
|
|
531
|
+
const doc = dom.getDoc(ctx);
|
|
532
|
+
return trackPointerMove(doc, {
|
|
529
533
|
onPointerMove(info) {
|
|
530
534
|
send({
|
|
531
535
|
type: "POINTER_MOVE",
|
|
@@ -538,38 +542,38 @@ function machine(userContext) {
|
|
|
538
542
|
});
|
|
539
543
|
} },
|
|
540
544
|
guards: {
|
|
541
|
-
isStartPanelAtMin: (ctx
|
|
542
|
-
isStartPanelAtMax: (ctx
|
|
543
|
-
isHorizontal: (ctx
|
|
544
|
-
isVertical: (ctx
|
|
545
|
+
isStartPanelAtMin: (ctx) => ctx.activeResizeState.isAtMin,
|
|
546
|
+
isStartPanelAtMax: (ctx) => ctx.activeResizeState.isAtMax,
|
|
547
|
+
isHorizontal: (ctx) => ctx.isHorizontal,
|
|
548
|
+
isVertical: (ctx) => !ctx.isHorizontal
|
|
545
549
|
},
|
|
546
550
|
delays: { HOVER_DELAY: 250 },
|
|
547
551
|
actions: {
|
|
548
|
-
setGlobalCursor(ctx
|
|
549
|
-
dom.setupGlobalCursor(ctx
|
|
552
|
+
setGlobalCursor(ctx) {
|
|
553
|
+
dom.setupGlobalCursor(ctx);
|
|
550
554
|
},
|
|
551
|
-
clearGlobalCursor(ctx
|
|
552
|
-
dom.removeGlobalCursor(ctx
|
|
555
|
+
clearGlobalCursor(ctx) {
|
|
556
|
+
dom.removeGlobalCursor(ctx);
|
|
553
557
|
},
|
|
554
|
-
invokeOnResizeEnd(ctx
|
|
555
|
-
invoke.sizeChangeEnd(ctx
|
|
558
|
+
invokeOnResizeEnd(ctx) {
|
|
559
|
+
invoke.sizeChangeEnd(ctx);
|
|
556
560
|
},
|
|
557
|
-
setActiveHandleId(ctx
|
|
558
|
-
ctx
|
|
561
|
+
setActiveHandleId(ctx, evt) {
|
|
562
|
+
ctx.activeResizeId = evt.id;
|
|
559
563
|
},
|
|
560
|
-
clearActiveHandleId(ctx
|
|
561
|
-
ctx
|
|
564
|
+
clearActiveHandleId(ctx) {
|
|
565
|
+
ctx.activeResizeId = null;
|
|
562
566
|
},
|
|
563
|
-
setInitialSize(ctx
|
|
564
|
-
ctx
|
|
567
|
+
setInitialSize(ctx) {
|
|
568
|
+
ctx.initialSize = ctx.panels.slice().map((panel) => ({
|
|
565
569
|
id: panel.id,
|
|
566
570
|
size: panel.size
|
|
567
571
|
}));
|
|
568
572
|
},
|
|
569
|
-
setPanelSize(ctx
|
|
573
|
+
setPanelSize(ctx, evt) {
|
|
570
574
|
const { id, size } = evt;
|
|
571
|
-
const next = cloneSize(ctx
|
|
572
|
-
const index = next.findIndex((panel
|
|
575
|
+
const next = cloneSize(ctx.size ?? []);
|
|
576
|
+
const index = next.findIndex((panel) => panel.id === id);
|
|
573
577
|
if (index === -1) return;
|
|
574
578
|
const panel = next[index];
|
|
575
579
|
const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
|
|
@@ -577,13 +581,13 @@ function machine(userContext) {
|
|
|
577
581
|
...panel,
|
|
578
582
|
size: panelSize
|
|
579
583
|
};
|
|
580
|
-
set.size(ctx
|
|
584
|
+
set.size(ctx, next);
|
|
581
585
|
},
|
|
582
|
-
setStartPanelToMin(ctx
|
|
583
|
-
const bounds = getPanelBounds(ctx
|
|
586
|
+
setStartPanelToMin(ctx) {
|
|
587
|
+
const bounds = getPanelBounds(ctx);
|
|
584
588
|
if (!bounds) return;
|
|
585
589
|
const { before, after } = bounds;
|
|
586
|
-
const next = cloneSize(ctx
|
|
590
|
+
const next = cloneSize(ctx.size ?? []);
|
|
587
591
|
next[before.index] = {
|
|
588
592
|
...next[before.index],
|
|
589
593
|
size: before.min
|
|
@@ -592,13 +596,13 @@ function machine(userContext) {
|
|
|
592
596
|
...next[after.index],
|
|
593
597
|
size: after.min
|
|
594
598
|
};
|
|
595
|
-
set.size(ctx
|
|
599
|
+
set.size(ctx, next);
|
|
596
600
|
},
|
|
597
|
-
setStartPanelToMax(ctx
|
|
598
|
-
const bounds = getPanelBounds(ctx
|
|
601
|
+
setStartPanelToMax(ctx) {
|
|
602
|
+
const bounds = getPanelBounds(ctx);
|
|
599
603
|
if (!bounds) return;
|
|
600
604
|
const { before, after } = bounds;
|
|
601
|
-
const next = cloneSize(ctx
|
|
605
|
+
const next = cloneSize(ctx.size ?? []);
|
|
602
606
|
next[before.index] = {
|
|
603
607
|
...next[before.index],
|
|
604
608
|
size: before.max
|
|
@@ -607,13 +611,13 @@ function machine(userContext) {
|
|
|
607
611
|
...next[after.index],
|
|
608
612
|
size: after.max
|
|
609
613
|
};
|
|
610
|
-
set.size(ctx
|
|
614
|
+
set.size(ctx, next);
|
|
611
615
|
},
|
|
612
|
-
expandStartPanel(ctx
|
|
613
|
-
const bounds = getPanelBounds(ctx
|
|
616
|
+
expandStartPanel(ctx, evt) {
|
|
617
|
+
const bounds = getPanelBounds(ctx);
|
|
614
618
|
if (!bounds) return;
|
|
615
619
|
const { before, after } = bounds;
|
|
616
|
-
const next = cloneSize(ctx
|
|
620
|
+
const next = cloneSize(ctx.size ?? []);
|
|
617
621
|
next[before.index] = {
|
|
618
622
|
...next[before.index],
|
|
619
623
|
size: before.up(evt.step)
|
|
@@ -622,13 +626,13 @@ function machine(userContext) {
|
|
|
622
626
|
...next[after.index],
|
|
623
627
|
size: after.down(evt.step)
|
|
624
628
|
};
|
|
625
|
-
set.size(ctx
|
|
629
|
+
set.size(ctx, next);
|
|
626
630
|
},
|
|
627
|
-
shrinkStartPanel(ctx
|
|
628
|
-
const bounds = getPanelBounds(ctx
|
|
631
|
+
shrinkStartPanel(ctx, evt) {
|
|
632
|
+
const bounds = getPanelBounds(ctx);
|
|
629
633
|
if (!bounds) return;
|
|
630
634
|
const { before, after } = bounds;
|
|
631
|
-
const next = cloneSize(ctx
|
|
635
|
+
const next = cloneSize(ctx.size ?? []);
|
|
632
636
|
next[before.index] = {
|
|
633
637
|
...next[before.index],
|
|
634
638
|
size: before.down(evt.step)
|
|
@@ -637,79 +641,77 @@ function machine(userContext) {
|
|
|
637
641
|
...next[after.index],
|
|
638
642
|
size: after.up(evt.step)
|
|
639
643
|
};
|
|
640
|
-
set.size(ctx
|
|
644
|
+
set.size(ctx, next);
|
|
641
645
|
},
|
|
642
|
-
resetStartPanel(ctx
|
|
643
|
-
const bounds = getPanelBounds(ctx
|
|
646
|
+
resetStartPanel(ctx, evt) {
|
|
647
|
+
const bounds = getPanelBounds(ctx, evt.id);
|
|
644
648
|
if (!bounds) return;
|
|
645
649
|
const { before, after } = bounds;
|
|
646
|
-
const next = cloneSize(ctx
|
|
650
|
+
const next = cloneSize(ctx.size ?? []);
|
|
647
651
|
next[before.index] = {
|
|
648
652
|
...next[before.index],
|
|
649
|
-
size: ctx
|
|
653
|
+
size: ctx.initialSize[before.index].size
|
|
650
654
|
};
|
|
651
655
|
next[after.index] = {
|
|
652
656
|
...next[after.index],
|
|
653
|
-
size: ctx
|
|
657
|
+
size: ctx.initialSize[after.index].size
|
|
654
658
|
};
|
|
655
|
-
set.size(ctx
|
|
659
|
+
set.size(ctx, next);
|
|
656
660
|
},
|
|
657
|
-
focusResizeHandle(ctx
|
|
661
|
+
focusResizeHandle(ctx) {
|
|
658
662
|
raf(() => {
|
|
659
|
-
dom.getActiveHandleEl(ctx
|
|
663
|
+
dom.getActiveHandleEl(ctx)?.focus({ preventScroll: true });
|
|
660
664
|
});
|
|
661
665
|
},
|
|
662
|
-
blurResizeHandle(ctx
|
|
666
|
+
blurResizeHandle(ctx) {
|
|
663
667
|
raf(() => {
|
|
664
|
-
dom.getActiveHandleEl(ctx
|
|
668
|
+
dom.getActiveHandleEl(ctx)?.blur();
|
|
665
669
|
});
|
|
666
670
|
},
|
|
667
|
-
storeInitialDragState(ctx
|
|
668
|
-
const panels = getHandlePanels(ctx
|
|
671
|
+
storeInitialDragState(ctx, evt) {
|
|
672
|
+
const panels = getHandlePanels(ctx);
|
|
669
673
|
if (!panels) return;
|
|
670
674
|
const { before, after } = panels;
|
|
671
|
-
ctx
|
|
672
|
-
ctx
|
|
675
|
+
ctx.initialDragPoint = evt.point;
|
|
676
|
+
ctx.initialDragSizes = {
|
|
673
677
|
before: before.size,
|
|
674
678
|
after: after.size
|
|
675
679
|
};
|
|
676
680
|
},
|
|
677
|
-
setPreviousPanels(ctx
|
|
678
|
-
ctx
|
|
681
|
+
setPreviousPanels(ctx) {
|
|
682
|
+
ctx.previousPanels = ctx.panels.slice();
|
|
679
683
|
},
|
|
680
|
-
setActiveResizeState(ctx
|
|
681
|
-
const panels = getPanelBounds(ctx
|
|
684
|
+
setActiveResizeState(ctx) {
|
|
685
|
+
const panels = getPanelBounds(ctx);
|
|
682
686
|
if (!panels) return;
|
|
683
687
|
const { before } = panels;
|
|
684
|
-
ctx
|
|
688
|
+
ctx.activeResizeState = {
|
|
685
689
|
isAtMin: before.isAtMin,
|
|
686
690
|
isAtMax: before.isAtMax
|
|
687
691
|
};
|
|
688
692
|
},
|
|
689
|
-
setPointerValue(ctx
|
|
690
|
-
const panels = getHandlePanels(ctx
|
|
691
|
-
const bounds = getHandleBounds(ctx
|
|
693
|
+
setPointerValue(ctx, evt) {
|
|
694
|
+
const panels = getHandlePanels(ctx);
|
|
695
|
+
const bounds = getHandleBounds(ctx);
|
|
692
696
|
if (!panels || !bounds) return;
|
|
693
|
-
const rootEl = dom.getRootEl(ctx
|
|
697
|
+
const rootEl = dom.getRootEl(ctx);
|
|
694
698
|
if (!rootEl) return;
|
|
695
|
-
if (!ctx
|
|
699
|
+
if (!ctx.initialDragPoint || !ctx.initialDragSizes) return;
|
|
696
700
|
const { before, after } = panels;
|
|
697
|
-
const rootSize = ctx
|
|
698
|
-
const currentPos = ctx
|
|
699
|
-
const initialPos = ctx
|
|
700
|
-
const deltaPercent = (ctx
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
701
|
+
const rootSize = ctx.isHorizontal ? rootEl.offsetWidth : rootEl.offsetHeight;
|
|
702
|
+
const currentPos = ctx.isHorizontal ? evt.point.x : evt.point.y;
|
|
703
|
+
const initialPos = ctx.isHorizontal ? ctx.initialDragPoint.x : ctx.initialDragPoint.y;
|
|
704
|
+
const deltaPercent = (ctx.dir === "rtl" && ctx.isHorizontal ? initialPos - currentPos : currentPos - initialPos) / rootSize * 100;
|
|
705
|
+
const totalSize = ctx.initialDragSizes.before + ctx.initialDragSizes.after;
|
|
706
|
+
const min = Math.max(before.minSize, totalSize - after.maxSize);
|
|
707
|
+
const max = Math.min(before.maxSize, totalSize - after.minSize);
|
|
708
|
+
const newBeforeSize = clamp(ctx.initialDragSizes.before + deltaPercent, min, max);
|
|
709
|
+
const newAfterSize = totalSize - newBeforeSize;
|
|
710
|
+
ctx.activeResizeState = {
|
|
711
|
+
isAtMin: newBeforeSize === min,
|
|
712
|
+
isAtMax: newBeforeSize === max
|
|
706
713
|
};
|
|
707
|
-
|
|
708
|
-
newAfterSize = clamp(newAfterSize, after.minSize, after.maxSize);
|
|
709
|
-
const totalSize = ctx$1.initialDragSizes.before + ctx$1.initialDragSizes.after;
|
|
710
|
-
if (newBeforeSize + newAfterSize > totalSize) if (deltaPercent > 0) newAfterSize = totalSize - newBeforeSize;
|
|
711
|
-
else newBeforeSize = totalSize - newAfterSize;
|
|
712
|
-
const next = cloneSize(ctx$1.size ?? []);
|
|
714
|
+
const next = cloneSize(ctx.size ?? []);
|
|
713
715
|
next[before.index] = {
|
|
714
716
|
...next[before.index],
|
|
715
717
|
size: newBeforeSize
|
|
@@ -718,12 +720,11 @@ function machine(userContext) {
|
|
|
718
720
|
...next[after.index],
|
|
719
721
|
size: newAfterSize
|
|
720
722
|
};
|
|
721
|
-
set.size(ctx
|
|
723
|
+
set.size(ctx, next);
|
|
722
724
|
}
|
|
723
725
|
}
|
|
724
726
|
});
|
|
725
727
|
}
|
|
726
|
-
|
|
727
728
|
//#endregion
|
|
728
729
|
//#region src/props.ts
|
|
729
730
|
const props = createProps()([
|
|
@@ -746,6 +747,5 @@ const resizeTriggerProps = createProps()([
|
|
|
746
747
|
"step"
|
|
747
748
|
]);
|
|
748
749
|
const splitResizeTriggerProps = createSplitProps(resizeTriggerProps);
|
|
749
|
-
|
|
750
750
|
//#endregion
|
|
751
|
-
export { anatomy, connect, machine, panelProps, props, resizeTriggerProps, splitPanelProps, splitProps, splitResizeTriggerProps };
|
|
751
|
+
export { anatomy, connect, machine, panelProps, props, resizeTriggerProps, splitPanelProps, splitProps, splitResizeTriggerProps };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/splitter",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.12",
|
|
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.
|
|
26
|
-
"@destyler/dom": "0.2.
|
|
27
|
-
"@destyler/types": "0.2.
|
|
28
|
-
"@destyler/utils": "0.2.
|
|
29
|
-
"@destyler/xstate": "0.2.
|
|
25
|
+
"@destyler/anatomy": "0.2.12",
|
|
26
|
+
"@destyler/dom": "0.2.12",
|
|
27
|
+
"@destyler/types": "0.2.12",
|
|
28
|
+
"@destyler/utils": "0.2.12",
|
|
29
|
+
"@destyler/xstate": "0.2.12"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|