react-resizable-panels 0.0.26 → 0.0.27
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/CHANGELOG.md +3 -0
- package/README.md +14 -12
- package/dist/react-resizable-panels.d.ts +9 -2
- package/dist/react-resizable-panels.d.ts.map +1 -1
- package/dist/react-resizable-panels.js +59 -18
- package/dist/react-resizable-panels.js.map +1 -1
- package/dist/react-resizable-panels.module.js +60 -19
- package/dist/react-resizable-panels.module.js.map +1 -1
- package/package.json +1 -1
- package/src/Panel.ts +22 -4
- package/src/PanelGroup.ts +12 -1
- package/src/types.ts +6 -1
- package/src/utils/coordinates.ts +58 -14
- package/src/utils/group.ts +8 -0
package/src/utils/coordinates.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { PRECISION } from "../constants";
|
|
2
|
+
import { Direction, PanelData, ResizeEvent } from "../types";
|
|
3
|
+
import {
|
|
4
|
+
getPanelGroup,
|
|
5
|
+
getResizeHandle,
|
|
6
|
+
getResizeHandlePanelIds,
|
|
7
|
+
} from "./group";
|
|
3
8
|
|
|
4
9
|
export type Coordinates = {
|
|
5
10
|
movement: number;
|
|
@@ -41,33 +46,72 @@ export function getMovement(
|
|
|
41
46
|
event: ResizeEvent,
|
|
42
47
|
groupId: string,
|
|
43
48
|
handleId: string,
|
|
49
|
+
panelsArray: PanelData[],
|
|
44
50
|
direction: Direction,
|
|
51
|
+
sizes: number[],
|
|
45
52
|
initialOffset: number
|
|
46
53
|
): number {
|
|
47
|
-
|
|
54
|
+
if (isKeyDown(event)) {
|
|
55
|
+
const isHorizontal = direction === "horizontal";
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
const groupElement = getPanelGroup(groupId);
|
|
58
|
+
const rect = groupElement.getBoundingClientRect();
|
|
59
|
+
const groupSizeInPixels = isHorizontal ? rect.width : rect.height;
|
|
52
60
|
|
|
53
|
-
if (isKeyDown(event)) {
|
|
54
61
|
const denominator = event.shiftKey ? 10 : 100;
|
|
55
|
-
const delta =
|
|
62
|
+
const delta = groupSizeInPixels / denominator;
|
|
56
63
|
|
|
64
|
+
let movement = 0;
|
|
57
65
|
switch (event.key) {
|
|
58
66
|
case "ArrowDown":
|
|
59
|
-
|
|
67
|
+
movement = isHorizontal ? 0 : delta;
|
|
68
|
+
break;
|
|
60
69
|
case "ArrowLeft":
|
|
61
|
-
|
|
70
|
+
movement = isHorizontal ? -delta : 0;
|
|
71
|
+
break;
|
|
62
72
|
case "ArrowRight":
|
|
63
|
-
|
|
73
|
+
movement = isHorizontal ? delta : 0;
|
|
74
|
+
break;
|
|
64
75
|
case "ArrowUp":
|
|
65
|
-
|
|
76
|
+
movement = isHorizontal ? 0 : -delta;
|
|
77
|
+
break;
|
|
66
78
|
case "End":
|
|
67
|
-
|
|
79
|
+
movement = groupSizeInPixels;
|
|
80
|
+
break;
|
|
68
81
|
case "Home":
|
|
69
|
-
|
|
82
|
+
movement = -groupSizeInPixels;
|
|
83
|
+
break;
|
|
70
84
|
}
|
|
85
|
+
|
|
86
|
+
// If the Panel being resized is collapsible,
|
|
87
|
+
// we need to special case resizing around the minSize boundary.
|
|
88
|
+
// If contracting, Panels should shrink to their minSize and then snap to fully collapsed.
|
|
89
|
+
// If expanding from collapsed, they should snap back to their minSize.
|
|
90
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(
|
|
91
|
+
groupId,
|
|
92
|
+
handleId,
|
|
93
|
+
panelsArray
|
|
94
|
+
);
|
|
95
|
+
const targetPanelId = movement < 0 ? idBefore : idAfter;
|
|
96
|
+
const targetPanelIndex = panelsArray.findIndex(
|
|
97
|
+
(panel) => panel.id === targetPanelId
|
|
98
|
+
);
|
|
99
|
+
const targetPanel = panelsArray[targetPanelIndex];
|
|
100
|
+
if (targetPanel.collapsible) {
|
|
101
|
+
const prevSize = sizes[targetPanelIndex];
|
|
102
|
+
if (
|
|
103
|
+
prevSize === 0 ||
|
|
104
|
+
prevSize.toPrecision(PRECISION) ===
|
|
105
|
+
targetPanel.minSize.toPrecision(PRECISION)
|
|
106
|
+
) {
|
|
107
|
+
movement =
|
|
108
|
+
movement < 0
|
|
109
|
+
? -targetPanel.minSize * groupSizeInPixels
|
|
110
|
+
: targetPanel.minSize * groupSizeInPixels;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return movement;
|
|
71
115
|
} else {
|
|
72
116
|
return getDragOffset(event, handleId, direction, initialOffset);
|
|
73
117
|
}
|
package/src/utils/group.ts
CHANGED
|
@@ -178,9 +178,17 @@ function safeResizePanel(
|
|
|
178
178
|
prevSize: number
|
|
179
179
|
): number {
|
|
180
180
|
const nextSizeUnsafe = prevSize + delta;
|
|
181
|
+
|
|
182
|
+
if (panel.collapsible) {
|
|
183
|
+
if (nextSizeUnsafe <= 0) {
|
|
184
|
+
return 0;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
181
188
|
const nextSize = Math.min(
|
|
182
189
|
panel.maxSize,
|
|
183
190
|
Math.max(panel.minSize, nextSizeUnsafe)
|
|
184
191
|
);
|
|
192
|
+
|
|
185
193
|
return nextSize;
|
|
186
194
|
}
|