react-resizable-panels 2.0.11 → 2.0.13
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/.parcel-cache/0e613961dce44a82 +0 -0
- package/.parcel-cache/13776de4870b0ae4.txt +2 -0
- package/.parcel-cache/35c20fb91e350b46 +0 -0
- package/.parcel-cache/data.mdb +0 -0
- package/.parcel-cache/lock.mdb +0 -0
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/dist/react-resizable-panels.browser.cjs.js +84 -47
- package/dist/react-resizable-panels.browser.development.cjs.js +84 -47
- package/dist/react-resizable-panels.browser.development.esm.js +84 -47
- package/dist/react-resizable-panels.browser.esm.js +84 -47
- package/dist/react-resizable-panels.cjs.js +84 -47
- package/dist/react-resizable-panels.development.cjs.js +84 -47
- package/dist/react-resizable-panels.development.esm.js +84 -47
- package/dist/react-resizable-panels.development.node.cjs.js +84 -47
- package/dist/react-resizable-panels.development.node.esm.js +84 -47
- package/dist/react-resizable-panels.esm.js +84 -47
- package/dist/react-resizable-panels.node.cjs.js +84 -47
- package/dist/react-resizable-panels.node.esm.js +84 -47
- package/package.json +9 -9
- package/src/PanelGroup.ts +8 -4
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +2 -1
- package/src/utils/adjustLayoutByDelta.test.ts +268 -115
- package/src/utils/adjustLayoutByDelta.ts +51 -39
- package/src/utils/numbers/fuzzyLayoutsEqual.ts +22 -0
- package/src/vendor/stacking-order.ts +10 -4
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
import { PanelConstraints } from "../Panel";
|
|
2
2
|
import { assert } from "./assert";
|
|
3
3
|
import { fuzzyCompareNumbers } from "./numbers/fuzzyCompareNumbers";
|
|
4
|
+
import { fuzzyLayoutsEqual } from "./numbers/fuzzyLayoutsEqual";
|
|
4
5
|
import { fuzzyNumbersEqual } from "./numbers/fuzzyNumbersEqual";
|
|
5
6
|
import { resizePanel } from "./resizePanel";
|
|
6
7
|
|
|
7
8
|
// All units must be in percentages; pixel values should be pre-converted
|
|
8
9
|
export function adjustLayoutByDelta({
|
|
9
10
|
delta,
|
|
10
|
-
|
|
11
|
+
initialLayout,
|
|
11
12
|
panelConstraints: panelConstraintsArray,
|
|
12
13
|
pivotIndices,
|
|
14
|
+
prevLayout,
|
|
13
15
|
trigger,
|
|
14
16
|
}: {
|
|
15
17
|
delta: number;
|
|
16
|
-
|
|
18
|
+
initialLayout: number[];
|
|
17
19
|
panelConstraints: PanelConstraints[];
|
|
18
20
|
pivotIndices: number[];
|
|
21
|
+
prevLayout: number[];
|
|
19
22
|
trigger: "imperative-api" | "keyboard" | "mouse-or-touch";
|
|
20
23
|
}): number[] {
|
|
21
24
|
if (fuzzyNumbersEqual(delta, 0)) {
|
|
22
|
-
return
|
|
25
|
+
return initialLayout;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
const nextLayout = [...
|
|
28
|
+
const nextLayout = [...initialLayout];
|
|
26
29
|
|
|
27
30
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
28
31
|
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
@@ -30,12 +33,14 @@ export function adjustLayoutByDelta({
|
|
|
30
33
|
|
|
31
34
|
let deltaApplied = 0;
|
|
32
35
|
|
|
33
|
-
//const DEBUG = [];
|
|
34
|
-
//DEBUG.push(`adjustLayoutByDelta()
|
|
35
|
-
//DEBUG.push(`
|
|
36
|
-
//DEBUG.push(`
|
|
37
|
-
//DEBUG.push(`
|
|
38
|
-
//DEBUG.push("");
|
|
36
|
+
// const DEBUG = [];
|
|
37
|
+
// DEBUG.push(`adjustLayoutByDelta()`);
|
|
38
|
+
// DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
|
|
39
|
+
// DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
|
|
40
|
+
// DEBUG.push(` delta: ${delta}`);
|
|
41
|
+
// DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
42
|
+
// DEBUG.push(` trigger: ${trigger}`);
|
|
43
|
+
// DEBUG.push("");
|
|
39
44
|
|
|
40
45
|
// A resizing panel affects the panels before or after it.
|
|
41
46
|
//
|
|
@@ -64,10 +69,10 @@ export function adjustLayoutByDelta({
|
|
|
64
69
|
minSize = 0,
|
|
65
70
|
} = panelConstraints;
|
|
66
71
|
|
|
67
|
-
//DEBUG.push(`edge case check 1: ${index}`);
|
|
68
|
-
//DEBUG.push(` -> collapsible? ${
|
|
72
|
+
// DEBUG.push(`edge case check 1: ${index}`);
|
|
73
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
69
74
|
if (collapsible) {
|
|
70
|
-
const prevSize =
|
|
75
|
+
const prevSize = initialLayout[index];
|
|
71
76
|
assert(
|
|
72
77
|
prevSize != null,
|
|
73
78
|
`Previous layout not found for panel index ${index}`
|
|
@@ -75,11 +80,11 @@ export function adjustLayoutByDelta({
|
|
|
75
80
|
|
|
76
81
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
77
82
|
const localDelta = minSize - prevSize;
|
|
78
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
83
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
79
84
|
|
|
80
85
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
81
86
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
82
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
87
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
90
|
}
|
|
@@ -100,10 +105,10 @@ export function adjustLayoutByDelta({
|
|
|
100
105
|
minSize = 0,
|
|
101
106
|
} = panelConstraints;
|
|
102
107
|
|
|
103
|
-
//DEBUG.push(`edge case check 2: ${index}`);
|
|
104
|
-
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
108
|
+
// DEBUG.push(`edge case check 2: ${index}`);
|
|
109
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
105
110
|
if (collapsible) {
|
|
106
|
-
const prevSize =
|
|
111
|
+
const prevSize = initialLayout[index];
|
|
107
112
|
assert(
|
|
108
113
|
prevSize != null,
|
|
109
114
|
`Previous layout not found for panel index ${index}`
|
|
@@ -111,17 +116,17 @@ export function adjustLayoutByDelta({
|
|
|
111
116
|
|
|
112
117
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
113
118
|
const localDelta = prevSize - collapsedSize;
|
|
114
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
119
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
115
120
|
|
|
116
121
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
117
122
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
118
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
123
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
|
-
//DEBUG.push("");
|
|
129
|
+
// DEBUG.push("");
|
|
125
130
|
}
|
|
126
131
|
|
|
127
132
|
{
|
|
@@ -136,9 +141,9 @@ export function adjustLayoutByDelta({
|
|
|
136
141
|
let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
137
142
|
let maxAvailableDelta = 0;
|
|
138
143
|
|
|
139
|
-
//DEBUG.push("pre calc...");
|
|
144
|
+
// DEBUG.push("pre calc...");
|
|
140
145
|
while (true) {
|
|
141
|
-
const prevSize =
|
|
146
|
+
const prevSize = initialLayout[index];
|
|
142
147
|
assert(
|
|
143
148
|
prevSize != null,
|
|
144
149
|
`Previous layout not found for panel index ${index}`
|
|
@@ -150,7 +155,7 @@ export function adjustLayoutByDelta({
|
|
|
150
155
|
size: 100,
|
|
151
156
|
});
|
|
152
157
|
const delta = maxSafeSize - prevSize;
|
|
153
|
-
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
158
|
+
// DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
154
159
|
|
|
155
160
|
maxAvailableDelta += delta;
|
|
156
161
|
index += increment;
|
|
@@ -160,11 +165,11 @@ export function adjustLayoutByDelta({
|
|
|
160
165
|
}
|
|
161
166
|
}
|
|
162
167
|
|
|
163
|
-
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
168
|
+
// DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
164
169
|
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
165
170
|
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
166
|
-
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
167
|
-
//DEBUG.push("");
|
|
171
|
+
// DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
172
|
+
// DEBUG.push("");
|
|
168
173
|
}
|
|
169
174
|
|
|
170
175
|
{
|
|
@@ -175,7 +180,7 @@ export function adjustLayoutByDelta({
|
|
|
175
180
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
176
181
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
177
182
|
|
|
178
|
-
const prevSize =
|
|
183
|
+
const prevSize = initialLayout[index];
|
|
179
184
|
assert(
|
|
180
185
|
prevSize != null,
|
|
181
186
|
`Previous layout not found for panel index ${index}`
|
|
@@ -211,14 +216,16 @@ export function adjustLayoutByDelta({
|
|
|
211
216
|
}
|
|
212
217
|
}
|
|
213
218
|
}
|
|
214
|
-
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
215
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
216
|
-
//DEBUG.push("");
|
|
219
|
+
// DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
220
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
221
|
+
// DEBUG.push("");
|
|
217
222
|
|
|
218
223
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
219
224
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
220
|
-
if (
|
|
221
|
-
//
|
|
225
|
+
if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
|
|
226
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
227
|
+
// console.log(DEBUG.join("\n"));
|
|
228
|
+
|
|
222
229
|
return prevLayout;
|
|
223
230
|
}
|
|
224
231
|
|
|
@@ -226,7 +233,7 @@ export function adjustLayoutByDelta({
|
|
|
226
233
|
// Now distribute the applied delta to the panels in the other direction
|
|
227
234
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
228
235
|
|
|
229
|
-
const prevSize =
|
|
236
|
+
const prevSize = initialLayout[pivotIndex];
|
|
230
237
|
assert(
|
|
231
238
|
prevSize != null,
|
|
232
239
|
`Previous layout not found for panel index ${pivotIndex}`
|
|
@@ -280,17 +287,22 @@ export function adjustLayoutByDelta({
|
|
|
280
287
|
}
|
|
281
288
|
}
|
|
282
289
|
}
|
|
283
|
-
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
284
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
285
|
-
//DEBUG.push("");
|
|
290
|
+
// DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
291
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
292
|
+
// DEBUG.push("");
|
|
286
293
|
|
|
287
294
|
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
288
|
-
//DEBUG.push(`total size: ${totalSize}`);
|
|
289
|
-
//console.log(DEBUG.join("\n"));
|
|
295
|
+
// DEBUG.push(`total size: ${totalSize}`);
|
|
290
296
|
|
|
297
|
+
// If our new layout doesn't add up to 100%, that means the requested delta can't be applied
|
|
298
|
+
// In that case, fall back to our most recent valid layout
|
|
291
299
|
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
300
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
301
|
+
// console.log(DEBUG.join("\n"));
|
|
302
|
+
|
|
292
303
|
return prevLayout;
|
|
293
304
|
}
|
|
294
305
|
|
|
306
|
+
// console.log(DEBUG.join("\n"));
|
|
295
307
|
return nextLayout;
|
|
296
308
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { fuzzyNumbersEqual } from "./fuzzyNumbersEqual";
|
|
2
|
+
|
|
3
|
+
export function fuzzyLayoutsEqual(
|
|
4
|
+
actual: number[],
|
|
5
|
+
expected: number[],
|
|
6
|
+
fractionDigits?: number
|
|
7
|
+
): boolean {
|
|
8
|
+
if (actual.length !== expected.length) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
for (let index = 0; index < actual.length; index++) {
|
|
13
|
+
const actualSize = actual[index] as number;
|
|
14
|
+
const expectedSize = expected[index] as number;
|
|
15
|
+
|
|
16
|
+
if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Forked from NPM stacking-order@2.0.0
|
|
2
2
|
// Background at https://github.com/Rich-Harris/stacking-order/issues/3
|
|
3
|
+
// Background at https://github.com/Rich-Harris/stacking-order/issues/6
|
|
3
4
|
|
|
4
5
|
import { assert } from "..";
|
|
5
6
|
|
|
@@ -61,7 +62,8 @@ const props =
|
|
|
61
62
|
|
|
62
63
|
/** @param {HTMLElement} node */
|
|
63
64
|
function is_flex_item(node: HTMLElement) {
|
|
64
|
-
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
const display = getComputedStyle(get_parent(node) ?? node).display;
|
|
65
67
|
return display === "flex" || display === "inline-flex";
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -115,11 +117,12 @@ function get_z_index(node: HTMLElement | null) {
|
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
/** @param {HTMLElement} node */
|
|
118
|
-
function get_ancestors(node: HTMLElement) {
|
|
120
|
+
function get_ancestors(node: HTMLElement | null) {
|
|
119
121
|
const ancestors = [];
|
|
120
122
|
|
|
121
123
|
while (node) {
|
|
122
124
|
ancestors.push(node);
|
|
125
|
+
// @ts-ignore
|
|
123
126
|
node = get_parent(node);
|
|
124
127
|
}
|
|
125
128
|
|
|
@@ -128,6 +131,9 @@ function get_ancestors(node: HTMLElement) {
|
|
|
128
131
|
|
|
129
132
|
/** @param {HTMLElement} node */
|
|
130
133
|
function get_parent(node: HTMLElement) {
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
const { parentNode } = node;
|
|
135
|
+
if (parentNode && parentNode instanceof ShadowRoot) {
|
|
136
|
+
return parentNode.host
|
|
137
|
+
}
|
|
138
|
+
return parentNode;
|
|
133
139
|
}
|