react-resizable-panels 0.0.63 → 1.0.0-rc.1
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/.eslintrc.cjs +1 -0
- package/CHANGELOG.md +5 -0
- package/dist/declarations/src/Panel.d.ts +19 -34
- package/dist/declarations/src/PanelGroup.d.ts +9 -13
- package/dist/declarations/src/PanelResizeHandle.d.ts +5 -7
- package/dist/declarations/src/index.d.ts +2 -2
- package/dist/declarations/src/types.d.ts +0 -7
- package/dist/declarations/src/utils/assert.d.ts +1 -0
- package/dist/declarations/src/vendor/react.d.ts +2 -2
- package/dist/react-resizable-panels.browser.cjs.js +252 -517
- package/dist/react-resizable-panels.browser.cjs.mjs +2 -1
- package/dist/react-resizable-panels.browser.development.cjs.js +278 -573
- package/dist/react-resizable-panels.browser.development.cjs.mjs +2 -1
- package/dist/react-resizable-panels.browser.development.esm.js +278 -574
- package/dist/react-resizable-panels.browser.esm.js +252 -518
- package/dist/react-resizable-panels.cjs.js +252 -517
- package/dist/react-resizable-panels.cjs.js.map +1 -1
- package/dist/react-resizable-panels.cjs.mjs +2 -1
- package/dist/react-resizable-panels.development.cjs.js +280 -575
- package/dist/react-resizable-panels.development.cjs.mjs +2 -1
- package/dist/react-resizable-panels.development.esm.js +280 -576
- package/dist/react-resizable-panels.development.node.cjs.js +266 -501
- package/dist/react-resizable-panels.development.node.cjs.mjs +2 -1
- package/dist/react-resizable-panels.development.node.esm.js +266 -502
- package/dist/react-resizable-panels.esm.js +252 -518
- package/dist/react-resizable-panels.esm.js.map +1 -1
- package/dist/react-resizable-panels.node.cjs.js +238 -443
- package/dist/react-resizable-panels.node.cjs.mjs +2 -1
- package/dist/react-resizable-panels.node.esm.js +238 -444
- package/package.json +1 -1
- package/src/Panel.test.tsx +74 -73
- package/src/Panel.ts +44 -68
- package/src/PanelGroup.test.tsx +43 -42
- package/src/PanelGroup.ts +189 -403
- package/src/PanelGroupContext.ts +2 -3
- package/src/PanelResizeHandle.test.tsx +68 -0
- package/src/PanelResizeHandle.ts +31 -22
- package/src/hooks/useWindowSplitterBehavior.ts +2 -1
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +22 -33
- package/src/index.ts +4 -3
- package/src/types.ts +0 -9
- package/src/utils/adjustLayoutByDelta.test.ts +206 -336
- package/src/utils/adjustLayoutByDelta.ts +59 -51
- package/src/utils/assert.ts +1 -1
- package/src/utils/calculateAriaValues.test.ts +6 -11
- package/src/utils/calculateAriaValues.ts +7 -29
- package/src/utils/calculateDeltaPercentage.ts +8 -15
- package/src/utils/calculateDragOffsetPercentage.ts +11 -5
- package/src/utils/calculateUnsafeDefaultLayout.test.ts +4 -9
- package/src/utils/calculateUnsafeDefaultLayout.ts +13 -18
- package/src/utils/callPanelCallbacks.ts +11 -46
- package/src/utils/getResizeEventCursorPosition.ts +2 -0
- package/src/utils/resizePanel.test.ts +6 -52
- package/src/utils/resizePanel.ts +24 -46
- package/src/utils/test-utils.ts +6 -7
- package/src/utils/validatePanelConstraints.test.ts +12 -65
- package/src/utils/validatePanelConstraints.ts +26 -67
- package/src/utils/validatePanelGroupLayout.test.ts +27 -142
- package/src/utils/validatePanelGroupLayout.ts +17 -13
- package/src/vendor/react.ts +2 -0
- package/src/utils/computePercentagePanelConstraints.test.ts +0 -98
- package/src/utils/computePercentagePanelConstraints.ts +0 -56
- package/src/utils/convertPercentageToPixels.test.ts +0 -9
- package/src/utils/convertPercentageToPixels.ts +0 -6
- package/src/utils/convertPixelConstraintsToPercentages.test.ts +0 -47
- package/src/utils/convertPixelConstraintsToPercentages.ts +0 -72
- package/src/utils/convertPixelsToPercentage.test.ts +0 -9
- package/src/utils/convertPixelsToPercentage.ts +0 -6
- package/src/utils/getPercentageSizeFromMixedSizes.test.ts +0 -47
- package/src/utils/getPercentageSizeFromMixedSizes.ts +0 -15
- package/src/utils/shouldMonitorPixelBasedConstraints.test.ts +0 -23
- package/src/utils/shouldMonitorPixelBasedConstraints.ts +0 -13
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PanelConstraints } from "../Panel";
|
|
2
|
-
import {
|
|
2
|
+
import { assert } from "./assert";
|
|
3
3
|
import { fuzzyCompareNumbers } from "./numbers/fuzzyCompareNumbers";
|
|
4
4
|
import { fuzzyNumbersEqual } from "./numbers/fuzzyNumbersEqual";
|
|
5
5
|
import { resizePanel } from "./resizePanel";
|
|
@@ -7,14 +7,12 @@ import { resizePanel } from "./resizePanel";
|
|
|
7
7
|
// All units must be in percentages; pixel values should be pre-converted
|
|
8
8
|
export function adjustLayoutByDelta({
|
|
9
9
|
delta,
|
|
10
|
-
groupSizePixels,
|
|
11
10
|
layout: prevLayout,
|
|
12
|
-
panelConstraints,
|
|
11
|
+
panelConstraints: panelConstraintsArray,
|
|
13
12
|
pivotIndices,
|
|
14
13
|
trigger,
|
|
15
14
|
}: {
|
|
16
15
|
delta: number;
|
|
17
|
-
groupSizePixels: number;
|
|
18
16
|
layout: number[];
|
|
19
17
|
panelConstraints: PanelConstraints[];
|
|
20
18
|
pivotIndices: number[];
|
|
@@ -26,6 +24,10 @@ export function adjustLayoutByDelta({
|
|
|
26
24
|
|
|
27
25
|
const nextLayout = [...prevLayout];
|
|
28
26
|
|
|
27
|
+
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
28
|
+
assert(firstPivotIndex != null);
|
|
29
|
+
assert(secondPivotIndex != null);
|
|
30
|
+
|
|
29
31
|
let deltaApplied = 0;
|
|
30
32
|
|
|
31
33
|
//const DEBUG = [];
|
|
@@ -49,21 +51,22 @@ export function adjustLayoutByDelta({
|
|
|
49
51
|
if (trigger === "keyboard") {
|
|
50
52
|
{
|
|
51
53
|
// Check if we should expand a collapsed panel
|
|
52
|
-
const index = delta < 0 ?
|
|
53
|
-
const
|
|
54
|
+
const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
55
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
56
|
+
assert(panelConstraints);
|
|
57
|
+
|
|
54
58
|
//DEBUG.push(`edge case check 1: ${index}`);
|
|
55
59
|
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
56
|
-
if (
|
|
57
|
-
const prevSize = prevLayout[index]
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const localDelta = minSizePercentage - prevSize;
|
|
60
|
+
if (panelConstraints.collapsible) {
|
|
61
|
+
const prevSize = prevLayout[index];
|
|
62
|
+
assert(prevSize != null);
|
|
63
|
+
|
|
64
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
65
|
+
assert(panelConstraints);
|
|
66
|
+
const { collapsedSize = 0, minSize = 0 } = panelConstraints;
|
|
67
|
+
|
|
68
|
+
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
69
|
+
const localDelta = minSize - prevSize;
|
|
67
70
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
68
71
|
|
|
69
72
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
@@ -76,21 +79,23 @@ export function adjustLayoutByDelta({
|
|
|
76
79
|
|
|
77
80
|
{
|
|
78
81
|
// Check if we should collapse a panel at its minimum size
|
|
79
|
-
const index = delta < 0 ?
|
|
80
|
-
const
|
|
82
|
+
const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
83
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
84
|
+
assert(panelConstraints);
|
|
85
|
+
const { collapsible } = panelConstraints;
|
|
86
|
+
|
|
81
87
|
//DEBUG.push(`edge case check 2: ${index}`);
|
|
82
|
-
//DEBUG.push(` -> collapsible? ${
|
|
83
|
-
if (
|
|
84
|
-
const prevSize = prevLayout[index]
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const localDelta = prevSize - collapsedSizePercentage;
|
|
88
|
+
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
89
|
+
if (collapsible) {
|
|
90
|
+
const prevSize = prevLayout[index];
|
|
91
|
+
assert(prevSize != null);
|
|
92
|
+
|
|
93
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
94
|
+
assert(panelConstraints);
|
|
95
|
+
const { collapsedSize = 0, minSize = 0 } = panelConstraints;
|
|
96
|
+
|
|
97
|
+
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
98
|
+
const localDelta = prevSize - collapsedSize;
|
|
94
99
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
95
100
|
|
|
96
101
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
@@ -113,15 +118,16 @@ export function adjustLayoutByDelta({
|
|
|
113
118
|
|
|
114
119
|
const increment = delta < 0 ? 1 : -1;
|
|
115
120
|
|
|
116
|
-
let index = delta < 0 ?
|
|
121
|
+
let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
117
122
|
let maxAvailableDelta = 0;
|
|
118
123
|
|
|
119
124
|
//DEBUG.push("pre calc...");
|
|
120
125
|
while (true) {
|
|
121
126
|
const prevSize = prevLayout[index];
|
|
127
|
+
assert(prevSize != null);
|
|
128
|
+
|
|
122
129
|
const maxSafeSize = resizePanel({
|
|
123
|
-
|
|
124
|
-
panelConstraints,
|
|
130
|
+
panelConstraints: panelConstraintsArray,
|
|
125
131
|
panelIndex: index,
|
|
126
132
|
size: 100,
|
|
127
133
|
});
|
|
@@ -131,7 +137,7 @@ export function adjustLayoutByDelta({
|
|
|
131
137
|
maxAvailableDelta += delta;
|
|
132
138
|
index += increment;
|
|
133
139
|
|
|
134
|
-
if (index < 0 || index >=
|
|
140
|
+
if (index < 0 || index >= panelConstraintsArray.length) {
|
|
135
141
|
break;
|
|
136
142
|
}
|
|
137
143
|
}
|
|
@@ -146,16 +152,17 @@ export function adjustLayoutByDelta({
|
|
|
146
152
|
{
|
|
147
153
|
// Delta added to a panel needs to be subtracted from other panels (within the constraints that those panels allow).
|
|
148
154
|
|
|
149
|
-
const pivotIndex = delta < 0 ?
|
|
155
|
+
const pivotIndex = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
150
156
|
let index = pivotIndex;
|
|
151
|
-
while (index >= 0 && index <
|
|
157
|
+
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
152
158
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
153
159
|
|
|
154
|
-
const prevSize = prevLayout[index]
|
|
160
|
+
const prevSize = prevLayout[index];
|
|
161
|
+
assert(prevSize != null);
|
|
162
|
+
|
|
155
163
|
const unsafeSize = prevSize - deltaRemaining;
|
|
156
164
|
const safeSize = resizePanel({
|
|
157
|
-
|
|
158
|
-
panelConstraints,
|
|
165
|
+
panelConstraints: panelConstraintsArray,
|
|
159
166
|
panelIndex: index,
|
|
160
167
|
size: unsafeSize,
|
|
161
168
|
});
|
|
@@ -196,12 +203,14 @@ export function adjustLayoutByDelta({
|
|
|
196
203
|
|
|
197
204
|
{
|
|
198
205
|
// Now distribute the applied delta to the panels in the other direction
|
|
199
|
-
const pivotIndex = delta < 0 ?
|
|
206
|
+
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
200
207
|
|
|
201
|
-
const
|
|
208
|
+
const prevSize = prevLayout[pivotIndex];
|
|
209
|
+
assert(prevSize != null);
|
|
210
|
+
|
|
211
|
+
const unsafeSize = prevSize + deltaApplied;
|
|
202
212
|
const safeSize = resizePanel({
|
|
203
|
-
|
|
204
|
-
panelConstraints,
|
|
213
|
+
panelConstraints: panelConstraintsArray,
|
|
205
214
|
panelIndex: pivotIndex,
|
|
206
215
|
size: unsafeSize,
|
|
207
216
|
});
|
|
@@ -213,14 +222,15 @@ export function adjustLayoutByDelta({
|
|
|
213
222
|
if (!fuzzyNumbersEqual(safeSize, unsafeSize)) {
|
|
214
223
|
let deltaRemaining = unsafeSize - safeSize;
|
|
215
224
|
|
|
216
|
-
const pivotIndex = delta < 0 ?
|
|
225
|
+
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
217
226
|
let index = pivotIndex;
|
|
218
|
-
while (index >= 0 && index <
|
|
219
|
-
const prevSize = nextLayout[index]
|
|
227
|
+
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
228
|
+
const prevSize = nextLayout[index];
|
|
229
|
+
assert(prevSize != null);
|
|
230
|
+
|
|
220
231
|
const unsafeSize = prevSize + deltaRemaining;
|
|
221
232
|
const safeSize = resizePanel({
|
|
222
|
-
|
|
223
|
-
panelConstraints,
|
|
233
|
+
panelConstraints: panelConstraintsArray,
|
|
224
234
|
panelIndex: index,
|
|
225
235
|
size: unsafeSize,
|
|
226
236
|
});
|
|
@@ -248,9 +258,7 @@ export function adjustLayoutByDelta({
|
|
|
248
258
|
//DEBUG.push("");
|
|
249
259
|
|
|
250
260
|
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
251
|
-
deltaApplied = 100 - totalSize;
|
|
252
261
|
//DEBUG.push(`total size: ${totalSize}`);
|
|
253
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
254
262
|
//console.log(DEBUG.join("\n"));
|
|
255
263
|
|
|
256
264
|
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
package/src/utils/assert.ts
CHANGED
|
@@ -27,7 +27,6 @@ describe("calculateAriaValues", () => {
|
|
|
27
27
|
it("should work correctly for panels with no min/max constraints", () => {
|
|
28
28
|
expect(
|
|
29
29
|
calculateAriaValues({
|
|
30
|
-
groupSizePixels: 1_000,
|
|
31
30
|
layout: [50, 50],
|
|
32
31
|
panelsArray: [createPanelData(), createPanelData()],
|
|
33
32
|
pivotIndices: [0, 1],
|
|
@@ -40,7 +39,6 @@ describe("calculateAriaValues", () => {
|
|
|
40
39
|
|
|
41
40
|
expect(
|
|
42
41
|
calculateAriaValues({
|
|
43
|
-
groupSizePixels: 1_000,
|
|
44
42
|
layout: [20, 50, 30],
|
|
45
43
|
panelsArray: [createPanelData(), createPanelData(), createPanelData()],
|
|
46
44
|
pivotIndices: [0, 1],
|
|
@@ -53,7 +51,6 @@ describe("calculateAriaValues", () => {
|
|
|
53
51
|
|
|
54
52
|
expect(
|
|
55
53
|
calculateAriaValues({
|
|
56
|
-
groupSizePixels: 1_000,
|
|
57
54
|
layout: [20, 50, 30],
|
|
58
55
|
panelsArray: [createPanelData(), createPanelData(), createPanelData()],
|
|
59
56
|
pivotIndices: [1, 2],
|
|
@@ -68,12 +65,11 @@ describe("calculateAriaValues", () => {
|
|
|
68
65
|
it("should work correctly for panels with min/max constraints", () => {
|
|
69
66
|
expect(
|
|
70
67
|
calculateAriaValues({
|
|
71
|
-
groupSizePixels: 1_000,
|
|
72
68
|
layout: [25, 75],
|
|
73
69
|
panelsArray: [
|
|
74
70
|
createPanelData({
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
maxSize: 35,
|
|
72
|
+
minSize: 10,
|
|
77
73
|
}),
|
|
78
74
|
createPanelData(),
|
|
79
75
|
],
|
|
@@ -87,17 +83,16 @@ describe("calculateAriaValues", () => {
|
|
|
87
83
|
|
|
88
84
|
expect(
|
|
89
85
|
calculateAriaValues({
|
|
90
|
-
groupSizePixels: 1_000,
|
|
91
86
|
layout: [25, 50, 25],
|
|
92
87
|
panelsArray: [
|
|
93
88
|
createPanelData({
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
maxSize: 35,
|
|
90
|
+
minSize: 10,
|
|
96
91
|
}),
|
|
97
92
|
createPanelData(),
|
|
98
93
|
createPanelData({
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
maxSize: 35,
|
|
95
|
+
minSize: 10,
|
|
101
96
|
}),
|
|
102
97
|
],
|
|
103
98
|
pivotIndices: [1, 2],
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { PanelData } from "../Panel";
|
|
2
|
-
import {
|
|
2
|
+
import { assert } from "./assert";
|
|
3
3
|
|
|
4
4
|
export function calculateAriaValues({
|
|
5
|
-
groupSizePixels,
|
|
6
5
|
layout,
|
|
7
6
|
panelsArray,
|
|
8
7
|
pivotIndices,
|
|
9
8
|
}: {
|
|
10
|
-
groupSizePixels: number;
|
|
11
9
|
layout: number[];
|
|
12
10
|
panelsArray: PanelData[];
|
|
13
11
|
pivotIndices: number[];
|
|
@@ -17,35 +15,15 @@ export function calculateAriaValues({
|
|
|
17
15
|
let totalMinSize = 0;
|
|
18
16
|
let totalMaxSize = 0;
|
|
19
17
|
|
|
18
|
+
const firstIndex = pivotIndices[0];
|
|
19
|
+
assert(firstIndex != null);
|
|
20
|
+
|
|
20
21
|
// A panel's effective min/max sizes also need to account for other panel's sizes.
|
|
21
22
|
panelsArray.forEach((panelData, index) => {
|
|
22
23
|
const { constraints } = panelData;
|
|
23
|
-
const {
|
|
24
|
-
maxSizePercentage,
|
|
25
|
-
maxSizePixels,
|
|
26
|
-
minSizePercentage,
|
|
27
|
-
minSizePixels,
|
|
28
|
-
} = constraints;
|
|
29
|
-
|
|
30
|
-
const minSize =
|
|
31
|
-
getPercentageSizeFromMixedSizes(
|
|
32
|
-
{
|
|
33
|
-
sizePercentage: minSizePercentage,
|
|
34
|
-
sizePixels: minSizePixels,
|
|
35
|
-
},
|
|
36
|
-
groupSizePixels
|
|
37
|
-
) ?? 0;
|
|
38
|
-
|
|
39
|
-
const maxSize =
|
|
40
|
-
getPercentageSizeFromMixedSizes(
|
|
41
|
-
{
|
|
42
|
-
sizePercentage: maxSizePercentage,
|
|
43
|
-
sizePixels: maxSizePixels,
|
|
44
|
-
},
|
|
45
|
-
groupSizePixels
|
|
46
|
-
) ?? 100;
|
|
24
|
+
const { maxSize = 100, minSize = 0 } = constraints;
|
|
47
25
|
|
|
48
|
-
if (index ===
|
|
26
|
+
if (index === firstIndex) {
|
|
49
27
|
currentMinSize = minSize;
|
|
50
28
|
currentMaxSize = maxSize;
|
|
51
29
|
} else {
|
|
@@ -57,7 +35,7 @@ export function calculateAriaValues({
|
|
|
57
35
|
const valueMax = Math.min(currentMaxSize, 100 - totalMinSize);
|
|
58
36
|
const valueMin = Math.max(currentMinSize, 100 - totalMaxSize);
|
|
59
37
|
|
|
60
|
-
const valueNow = layout[
|
|
38
|
+
const valueNow = layout[firstIndex];
|
|
61
39
|
|
|
62
40
|
return {
|
|
63
41
|
valueMax,
|
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
import { DragState, ResizeEvent } from "../PanelGroupContext";
|
|
2
2
|
import { Direction } from "../types";
|
|
3
|
-
import { getPanelGroupElement } from "../utils/dom/getPanelGroupElement";
|
|
4
3
|
import { calculateDragOffsetPercentage } from "./calculateDragOffsetPercentage";
|
|
5
4
|
import { isKeyDown } from "./events";
|
|
6
5
|
|
|
7
6
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
8
7
|
export function calculateDeltaPercentage(
|
|
9
8
|
event: ResizeEvent,
|
|
10
|
-
groupId: string,
|
|
11
9
|
dragHandleId: string,
|
|
12
10
|
direction: Direction,
|
|
13
|
-
initialDragState: DragState,
|
|
14
|
-
|
|
15
|
-
percentage: number | null;
|
|
16
|
-
pixels: number | null;
|
|
17
|
-
}
|
|
11
|
+
initialDragState: DragState | null,
|
|
12
|
+
keyboardResizeBy: number | null
|
|
18
13
|
): number {
|
|
19
14
|
if (isKeyDown(event)) {
|
|
20
15
|
const isHorizontal = direction === "horizontal";
|
|
21
16
|
|
|
22
|
-
const groupElement = getPanelGroupElement(groupId)!;
|
|
23
|
-
const rect = groupElement.getBoundingClientRect();
|
|
24
|
-
const groupSizeInPixels = isHorizontal ? rect.width : rect.height;
|
|
25
|
-
|
|
26
17
|
let delta = 0;
|
|
27
18
|
if (event.shiftKey) {
|
|
28
19
|
delta = 100;
|
|
29
|
-
} else if (
|
|
30
|
-
delta =
|
|
31
|
-
} else if (keyboardResizeByOptions.pixels != null) {
|
|
32
|
-
delta = keyboardResizeByOptions.pixels / groupSizeInPixels;
|
|
20
|
+
} else if (keyboardResizeBy != null) {
|
|
21
|
+
delta = keyboardResizeBy;
|
|
33
22
|
} else {
|
|
34
23
|
delta = 10;
|
|
35
24
|
}
|
|
@@ -58,6 +47,10 @@ export function calculateDeltaPercentage(
|
|
|
58
47
|
|
|
59
48
|
return movement;
|
|
60
49
|
} else {
|
|
50
|
+
if (initialDragState == null) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
61
54
|
return calculateDragOffsetPercentage(
|
|
62
55
|
event,
|
|
63
56
|
dragHandleId,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DragState, ResizeEvent } from "../PanelGroupContext";
|
|
2
2
|
import { Direction } from "../types";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { assert } from "./assert";
|
|
4
|
+
import { getPanelGroupElement } from "./dom/getPanelGroupElement";
|
|
5
|
+
import { getResizeHandleElement } from "./dom/getResizeHandleElement";
|
|
5
6
|
import { getResizeEventCursorPosition } from "./getResizeEventCursorPosition";
|
|
6
7
|
|
|
7
8
|
export function calculateDragOffsetPercentage(
|
|
@@ -12,14 +13,19 @@ export function calculateDragOffsetPercentage(
|
|
|
12
13
|
): number {
|
|
13
14
|
const isHorizontal = direction === "horizontal";
|
|
14
15
|
|
|
15
|
-
const handleElement = getResizeHandleElement(dragHandleId)
|
|
16
|
-
|
|
16
|
+
const handleElement = getResizeHandleElement(dragHandleId);
|
|
17
|
+
assert(handleElement);
|
|
18
|
+
|
|
19
|
+
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
20
|
+
assert(groupId);
|
|
17
21
|
|
|
18
22
|
let { initialCursorPosition } = initialDragState;
|
|
19
23
|
|
|
20
24
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
21
25
|
|
|
22
|
-
const groupElement = getPanelGroupElement(groupId)
|
|
26
|
+
const groupElement = getPanelGroupElement(groupId);
|
|
27
|
+
assert(groupElement);
|
|
28
|
+
|
|
23
29
|
const groupRect = groupElement.getBoundingClientRect();
|
|
24
30
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
25
31
|
|
|
@@ -28,7 +28,6 @@ describe("calculateUnsafeDefaultLayout", () => {
|
|
|
28
28
|
it("should assign even sizes for every panel by default", () => {
|
|
29
29
|
expectToBeCloseToArray(
|
|
30
30
|
calculateUnsafeDefaultLayout({
|
|
31
|
-
groupSizePixels: 100_000,
|
|
32
31
|
panelDataArray: [createPanelData()],
|
|
33
32
|
}),
|
|
34
33
|
[100]
|
|
@@ -36,7 +35,6 @@ describe("calculateUnsafeDefaultLayout", () => {
|
|
|
36
35
|
|
|
37
36
|
expectToBeCloseToArray(
|
|
38
37
|
calculateUnsafeDefaultLayout({
|
|
39
|
-
groupSizePixels: 100_000,
|
|
40
38
|
panelDataArray: [createPanelData(), createPanelData()],
|
|
41
39
|
}),
|
|
42
40
|
[50, 50]
|
|
@@ -44,7 +42,6 @@ describe("calculateUnsafeDefaultLayout", () => {
|
|
|
44
42
|
|
|
45
43
|
expectToBeCloseToArray(
|
|
46
44
|
calculateUnsafeDefaultLayout({
|
|
47
|
-
groupSizePixels: 100_000,
|
|
48
45
|
panelDataArray: [
|
|
49
46
|
createPanelData(),
|
|
50
47
|
createPanelData(),
|
|
@@ -58,13 +55,12 @@ describe("calculateUnsafeDefaultLayout", () => {
|
|
|
58
55
|
it("should respect default panel size constraints", () => {
|
|
59
56
|
expectToBeCloseToArray(
|
|
60
57
|
calculateUnsafeDefaultLayout({
|
|
61
|
-
groupSizePixels: 100_000,
|
|
62
58
|
panelDataArray: [
|
|
63
59
|
createPanelData({
|
|
64
|
-
|
|
60
|
+
defaultSize: 15,
|
|
65
61
|
}),
|
|
66
62
|
createPanelData({
|
|
67
|
-
|
|
63
|
+
defaultSize: 85,
|
|
68
64
|
}),
|
|
69
65
|
],
|
|
70
66
|
}),
|
|
@@ -75,14 +71,13 @@ describe("calculateUnsafeDefaultLayout", () => {
|
|
|
75
71
|
it("should ignore min and max panel size constraints", () => {
|
|
76
72
|
expectToBeCloseToArray(
|
|
77
73
|
calculateUnsafeDefaultLayout({
|
|
78
|
-
groupSizePixels: 100_000,
|
|
79
74
|
panelDataArray: [
|
|
80
75
|
createPanelData({
|
|
81
|
-
|
|
76
|
+
minSize: 40,
|
|
82
77
|
}),
|
|
83
78
|
createPanelData(),
|
|
84
79
|
createPanelData({
|
|
85
|
-
|
|
80
|
+
maxSize: 10,
|
|
86
81
|
}),
|
|
87
82
|
],
|
|
88
83
|
}),
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { PanelData } from "../Panel";
|
|
2
|
-
import {
|
|
2
|
+
import { assert } from "./assert";
|
|
3
3
|
|
|
4
4
|
export function calculateUnsafeDefaultLayout({
|
|
5
|
-
groupSizePixels,
|
|
6
5
|
panelDataArray,
|
|
7
6
|
}: {
|
|
8
|
-
groupSizePixels: number;
|
|
9
7
|
panelDataArray: PanelData[];
|
|
10
8
|
}): number[] {
|
|
11
9
|
const layout = Array<number>(panelDataArray.length);
|
|
12
10
|
|
|
13
|
-
const
|
|
11
|
+
const panelConstraintsArray = panelDataArray.map(
|
|
14
12
|
(panelData) => panelData.constraints
|
|
15
13
|
);
|
|
16
14
|
|
|
@@ -19,27 +17,24 @@ export function calculateUnsafeDefaultLayout({
|
|
|
19
17
|
|
|
20
18
|
// Distribute default sizes first
|
|
21
19
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
groupSizePixels
|
|
26
|
-
);
|
|
20
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
21
|
+
assert(panelConstraints);
|
|
22
|
+
const { defaultSize } = panelConstraints;
|
|
27
23
|
|
|
28
|
-
if (
|
|
24
|
+
if (defaultSize != null) {
|
|
29
25
|
numPanelsWithSizes++;
|
|
30
|
-
layout[index] =
|
|
31
|
-
remainingSize -=
|
|
26
|
+
layout[index] = defaultSize;
|
|
27
|
+
remainingSize -= defaultSize;
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
// Remaining size should be distributed evenly between panels without default sizes
|
|
36
32
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
)
|
|
42
|
-
if (defaultSizePercentage != null) {
|
|
33
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
34
|
+
assert(panelConstraints);
|
|
35
|
+
const { defaultSize } = panelConstraints;
|
|
36
|
+
|
|
37
|
+
if (defaultSize != null) {
|
|
43
38
|
continue;
|
|
44
39
|
}
|
|
45
40
|
|
|
@@ -1,67 +1,33 @@
|
|
|
1
1
|
import { PanelData } from "../Panel";
|
|
2
|
-
import {
|
|
3
|
-
import { calculateAvailablePanelSizeInPixels } from "../utils/dom/calculateAvailablePanelSizeInPixels";
|
|
4
|
-
import { convertPercentageToPixels } from "./convertPercentageToPixels";
|
|
5
|
-
import { getPercentageSizeFromMixedSizes } from "./getPercentageSizeFromMixedSizes";
|
|
2
|
+
import { assert } from "./assert";
|
|
6
3
|
|
|
7
4
|
// Layout should be pre-converted into percentages
|
|
8
5
|
export function callPanelCallbacks(
|
|
9
|
-
groupId: string,
|
|
10
6
|
panelsArray: PanelData[],
|
|
11
7
|
layout: number[],
|
|
12
|
-
|
|
8
|
+
panelIdToLastNotifiedSizeMap: Record<string, number>
|
|
13
9
|
) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
layout.forEach((sizePercentage, index) => {
|
|
10
|
+
layout.forEach((size, index) => {
|
|
17
11
|
const panelData = panelsArray[index];
|
|
18
|
-
|
|
19
|
-
// Handle initial mount (when panels are registered too late to be in the panels array)
|
|
20
|
-
// The subsequent render+effects will handle the resize notification
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
12
|
+
assert(panelData);
|
|
23
13
|
|
|
24
14
|
const { callbacks, constraints, id: panelId } = panelData;
|
|
25
|
-
const { collapsible } = constraints;
|
|
26
|
-
|
|
27
|
-
const mixedSizes: MixedSizes = {
|
|
28
|
-
sizePercentage,
|
|
29
|
-
sizePixels: convertPercentageToPixels(sizePercentage, groupSizePixels),
|
|
30
|
-
};
|
|
15
|
+
const { collapsedSize = 0, collapsible } = constraints;
|
|
31
16
|
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
mixedSizes.sizePercentage !== lastNotifiedMixedSizes.sizePercentage ||
|
|
36
|
-
mixedSizes.sizePixels !== lastNotifiedMixedSizes.sizePixels
|
|
37
|
-
) {
|
|
38
|
-
panelIdToLastNotifiedMixedSizesMap[panelId] = mixedSizes;
|
|
17
|
+
const lastNotifiedSize = panelIdToLastNotifiedSizeMap[panelId];
|
|
18
|
+
if (lastNotifiedSize == null || size !== lastNotifiedSize) {
|
|
19
|
+
panelIdToLastNotifiedSizeMap[panelId] = size;
|
|
39
20
|
|
|
40
21
|
const { onCollapse, onExpand, onResize } = callbacks;
|
|
41
22
|
|
|
42
23
|
if (onResize) {
|
|
43
|
-
onResize(
|
|
24
|
+
onResize(size, lastNotifiedSize);
|
|
44
25
|
}
|
|
45
26
|
|
|
46
27
|
if (collapsible && (onCollapse || onExpand)) {
|
|
47
|
-
const collapsedSize =
|
|
48
|
-
getPercentageSizeFromMixedSizes(
|
|
49
|
-
{
|
|
50
|
-
sizePercentage: constraints.collapsedSizePercentage,
|
|
51
|
-
sizePixels: constraints.collapsedSizePixels,
|
|
52
|
-
},
|
|
53
|
-
groupSizePixels
|
|
54
|
-
) ?? 0;
|
|
55
|
-
|
|
56
|
-
const size = getPercentageSizeFromMixedSizes(
|
|
57
|
-
mixedSizes,
|
|
58
|
-
groupSizePixels
|
|
59
|
-
);
|
|
60
|
-
|
|
61
28
|
if (
|
|
62
29
|
onExpand &&
|
|
63
|
-
(
|
|
64
|
-
lastNotifiedMixedSizes.sizePercentage === collapsedSize) &&
|
|
30
|
+
(lastNotifiedSize == null || lastNotifiedSize === collapsedSize) &&
|
|
65
31
|
size !== collapsedSize
|
|
66
32
|
) {
|
|
67
33
|
onExpand();
|
|
@@ -69,8 +35,7 @@ export function callPanelCallbacks(
|
|
|
69
35
|
|
|
70
36
|
if (
|
|
71
37
|
onCollapse &&
|
|
72
|
-
(
|
|
73
|
-
lastNotifiedMixedSizes.sizePercentage !== collapsedSize) &&
|
|
38
|
+
(lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) &&
|
|
74
39
|
size === collapsedSize
|
|
75
40
|
) {
|
|
76
41
|
onCollapse();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ResizeEvent } from "../PanelGroupContext";
|
|
2
2
|
import { Direction } from "../types";
|
|
3
|
+
import { assert } from "./assert";
|
|
3
4
|
import { isMouseEvent, isTouchEvent } from "./events";
|
|
4
5
|
|
|
5
6
|
export function getResizeEventCursorPosition(
|
|
@@ -12,6 +13,7 @@ export function getResizeEventCursorPosition(
|
|
|
12
13
|
return isHorizontal ? event.clientX : event.clientY;
|
|
13
14
|
} else if (isTouchEvent(event)) {
|
|
14
15
|
const firstTouch = event.touches[0];
|
|
16
|
+
assert(firstTouch);
|
|
15
17
|
return isHorizontal ? firstTouch.screenX : firstTouch.screenY;
|
|
16
18
|
} else {
|
|
17
19
|
throw Error(`Unsupported event type "${event.type}"`);
|