react-resizable-panels 0.0.63 → 1.0.0-rc.2
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 +253 -518
- package/dist/react-resizable-panels.browser.cjs.mjs +2 -1
- package/dist/react-resizable-panels.browser.development.cjs.js +279 -574
- package/dist/react-resizable-panels.browser.development.cjs.mjs +2 -1
- package/dist/react-resizable-panels.browser.development.esm.js +279 -575
- package/dist/react-resizable-panels.browser.esm.js +253 -519
- package/dist/react-resizable-panels.cjs.d.ts +88 -1
- package/dist/react-resizable-panels.cjs.d.ts.map +1 -1
- package/dist/react-resizable-panels.cjs.js +1481 -1983
- 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 +281 -576
- package/dist/react-resizable-panels.development.cjs.mjs +2 -1
- package/dist/react-resizable-panels.development.esm.js +281 -577
- package/dist/react-resizable-panels.development.node.cjs.js +267 -502
- package/dist/react-resizable-panels.development.node.cjs.mjs +2 -1
- package/dist/react-resizable-panels.development.node.esm.js +267 -503
- package/dist/react-resizable-panels.esm.js +1476 -1959
- package/dist/react-resizable-panels.esm.js.map +1 -1
- package/dist/react-resizable-panels.node.cjs.js +239 -444
- package/dist/react-resizable-panels.node.cjs.mjs +2 -1
- package/dist/react-resizable-panels.node.esm.js +239 -445
- 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 +221 -411
- 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
|
@@ -5,39 +5,34 @@ describe("validatePanelGroupLayout", () => {
|
|
|
5
5
|
it("should accept requested layout if there are no constraints provided", () => {
|
|
6
6
|
expect(
|
|
7
7
|
validatePanelGroupLayout({
|
|
8
|
-
groupSizePixels: NaN,
|
|
9
8
|
layout: [10, 60, 30],
|
|
10
9
|
panelConstraints: [{}, {}, {}],
|
|
11
10
|
})
|
|
12
11
|
).toEqual([10, 60, 30]);
|
|
13
12
|
});
|
|
14
13
|
|
|
15
|
-
it("should
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
);
|
|
14
|
+
it("should normalize layouts that do not total 100%", () => {
|
|
15
|
+
let layout;
|
|
16
|
+
verifyExpectedWarnings(() => {
|
|
17
|
+
layout = validatePanelGroupLayout({
|
|
18
|
+
layout: [10, 20, 20],
|
|
19
|
+
panelConstraints: [{}, {}, {}],
|
|
20
|
+
});
|
|
21
|
+
}, "Invalid layout total size");
|
|
22
|
+
expect(layout).toEqual([20, 40, 40]);
|
|
25
23
|
|
|
26
|
-
verifyExpectedWarnings(
|
|
27
|
-
(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"Invalid layout total size"
|
|
34
|
-
);
|
|
24
|
+
verifyExpectedWarnings(() => {
|
|
25
|
+
layout = validatePanelGroupLayout({
|
|
26
|
+
layout: [50, 100, 50],
|
|
27
|
+
panelConstraints: [{}, {}, {}],
|
|
28
|
+
});
|
|
29
|
+
}, "Invalid layout total size");
|
|
30
|
+
expect(layout).toEqual([25, 50, 25]);
|
|
35
31
|
});
|
|
36
32
|
|
|
37
33
|
it("should reject layouts that do not match the number of panels", () => {
|
|
38
34
|
expect(() =>
|
|
39
35
|
validatePanelGroupLayout({
|
|
40
|
-
groupSizePixels: NaN,
|
|
41
36
|
layout: [10, 20, 30],
|
|
42
37
|
panelConstraints: [{}, {}],
|
|
43
38
|
})
|
|
@@ -45,7 +40,6 @@ describe("validatePanelGroupLayout", () => {
|
|
|
45
40
|
|
|
46
41
|
expect(() =>
|
|
47
42
|
validatePanelGroupLayout({
|
|
48
|
-
groupSizePixels: NaN,
|
|
49
43
|
layout: [50, 50],
|
|
50
44
|
panelConstraints: [{}, {}, {}],
|
|
51
45
|
})
|
|
@@ -56,11 +50,10 @@ describe("validatePanelGroupLayout", () => {
|
|
|
56
50
|
it("should adjust the layout to account for minimum percentage sizes", () => {
|
|
57
51
|
expect(
|
|
58
52
|
validatePanelGroupLayout({
|
|
59
|
-
groupSizePixels: NaN,
|
|
60
53
|
layout: [25, 75],
|
|
61
54
|
panelConstraints: [
|
|
62
55
|
{
|
|
63
|
-
|
|
56
|
+
minSize: 35,
|
|
64
57
|
},
|
|
65
58
|
{},
|
|
66
59
|
],
|
|
@@ -68,33 +61,17 @@ describe("validatePanelGroupLayout", () => {
|
|
|
68
61
|
).toEqual([35, 65]);
|
|
69
62
|
});
|
|
70
63
|
|
|
71
|
-
it("should adjust the layout to account for minimum pixel sizes", () => {
|
|
72
|
-
expect(
|
|
73
|
-
validatePanelGroupLayout({
|
|
74
|
-
groupSizePixels: 400,
|
|
75
|
-
layout: [20, 80],
|
|
76
|
-
panelConstraints: [
|
|
77
|
-
{
|
|
78
|
-
minSizePixels: 100,
|
|
79
|
-
},
|
|
80
|
-
{},
|
|
81
|
-
],
|
|
82
|
-
})
|
|
83
|
-
).toEqual([25, 75]);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
64
|
it("should account for multiple panels with minimum size constraints", () => {
|
|
87
65
|
expect(
|
|
88
66
|
validatePanelGroupLayout({
|
|
89
|
-
groupSizePixels: NaN,
|
|
90
67
|
layout: [20, 60, 20],
|
|
91
68
|
panelConstraints: [
|
|
92
69
|
{
|
|
93
|
-
|
|
70
|
+
minSize: 25,
|
|
94
71
|
},
|
|
95
72
|
{},
|
|
96
73
|
{
|
|
97
|
-
|
|
74
|
+
minSize: 25,
|
|
98
75
|
},
|
|
99
76
|
],
|
|
100
77
|
})
|
|
@@ -106,38 +83,21 @@ describe("validatePanelGroupLayout", () => {
|
|
|
106
83
|
it("should adjust the layout to account for maximum percentage sizes", () => {
|
|
107
84
|
expect(
|
|
108
85
|
validatePanelGroupLayout({
|
|
109
|
-
groupSizePixels: NaN,
|
|
110
86
|
layout: [25, 75],
|
|
111
|
-
panelConstraints: [{}, {
|
|
87
|
+
panelConstraints: [{}, { maxSize: 65 }],
|
|
112
88
|
})
|
|
113
89
|
).toEqual([35, 65]);
|
|
114
90
|
});
|
|
115
91
|
|
|
116
|
-
it("should adjust the layout to account for maximum pixel sizes", () => {
|
|
117
|
-
expect(
|
|
118
|
-
validatePanelGroupLayout({
|
|
119
|
-
groupSizePixels: 400,
|
|
120
|
-
layout: [20, 80],
|
|
121
|
-
panelConstraints: [
|
|
122
|
-
{},
|
|
123
|
-
{
|
|
124
|
-
maxSizePixels: 100,
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
})
|
|
128
|
-
).toEqual([75, 25]);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
92
|
it("should account for multiple panels with maximum size constraints", () => {
|
|
132
93
|
expect(
|
|
133
94
|
validatePanelGroupLayout({
|
|
134
|
-
groupSizePixels: NaN,
|
|
135
95
|
layout: [20, 60, 20],
|
|
136
96
|
panelConstraints: [
|
|
137
97
|
{
|
|
138
|
-
|
|
98
|
+
maxSize: 15,
|
|
139
99
|
},
|
|
140
|
-
{
|
|
100
|
+
{ maxSize: 50 },
|
|
141
101
|
{},
|
|
142
102
|
],
|
|
143
103
|
})
|
|
@@ -149,9 +109,8 @@ describe("validatePanelGroupLayout", () => {
|
|
|
149
109
|
it("should not collapse a panel that's at or above the minimum size", () => {
|
|
150
110
|
expect(
|
|
151
111
|
validatePanelGroupLayout({
|
|
152
|
-
groupSizePixels: NaN,
|
|
153
112
|
layout: [25, 75],
|
|
154
|
-
panelConstraints: [{ collapsible: true,
|
|
113
|
+
panelConstraints: [{ collapsible: true, minSize: 25 }, {}],
|
|
155
114
|
})
|
|
156
115
|
).toEqual([25, 75]);
|
|
157
116
|
});
|
|
@@ -159,13 +118,12 @@ describe("validatePanelGroupLayout", () => {
|
|
|
159
118
|
it("should collapse a panel once it drops below the halfway point between collapsed and minimum percentage sizes", () => {
|
|
160
119
|
expect(
|
|
161
120
|
validatePanelGroupLayout({
|
|
162
|
-
groupSizePixels: NaN,
|
|
163
121
|
layout: [15, 85],
|
|
164
122
|
panelConstraints: [
|
|
165
123
|
{
|
|
166
124
|
collapsible: true,
|
|
167
|
-
|
|
168
|
-
|
|
125
|
+
collapsedSize: 10,
|
|
126
|
+
minSize: 20,
|
|
169
127
|
},
|
|
170
128
|
{},
|
|
171
129
|
],
|
|
@@ -174,90 +132,17 @@ describe("validatePanelGroupLayout", () => {
|
|
|
174
132
|
|
|
175
133
|
expect(
|
|
176
134
|
validatePanelGroupLayout({
|
|
177
|
-
groupSizePixels: NaN,
|
|
178
135
|
layout: [14, 86],
|
|
179
136
|
panelConstraints: [
|
|
180
137
|
{
|
|
181
138
|
collapsible: true,
|
|
182
|
-
|
|
183
|
-
|
|
139
|
+
collapsedSize: 10,
|
|
140
|
+
minSize: 20,
|
|
184
141
|
},
|
|
185
142
|
{},
|
|
186
143
|
],
|
|
187
144
|
})
|
|
188
145
|
).toEqual([10, 90]);
|
|
189
146
|
});
|
|
190
|
-
|
|
191
|
-
it("should collapse a panel once it drops below the halfway point between collapsed and minimum pixel sizes", () => {
|
|
192
|
-
expect(
|
|
193
|
-
validatePanelGroupLayout({
|
|
194
|
-
groupSizePixels: 400,
|
|
195
|
-
layout: [20, 80],
|
|
196
|
-
panelConstraints: [
|
|
197
|
-
{
|
|
198
|
-
collapsible: true,
|
|
199
|
-
collapsedSizePixels: 0,
|
|
200
|
-
minSizePixels: 100,
|
|
201
|
-
},
|
|
202
|
-
{},
|
|
203
|
-
],
|
|
204
|
-
})
|
|
205
|
-
).toEqual([25, 75]);
|
|
206
|
-
|
|
207
|
-
expect(
|
|
208
|
-
validatePanelGroupLayout({
|
|
209
|
-
groupSizePixels: 400,
|
|
210
|
-
layout: [10, 90],
|
|
211
|
-
panelConstraints: [
|
|
212
|
-
{
|
|
213
|
-
collapsible: true,
|
|
214
|
-
collapsedSizePixels: 0,
|
|
215
|
-
minSizePixels: 100,
|
|
216
|
-
},
|
|
217
|
-
{},
|
|
218
|
-
],
|
|
219
|
-
})
|
|
220
|
-
).toEqual([0, 100]);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe("combination of minimum and maximum size constraints", () => {
|
|
225
|
-
it("three panel min/max configuration", () => {
|
|
226
|
-
expect(
|
|
227
|
-
validatePanelGroupLayout({
|
|
228
|
-
groupSizePixels: NaN,
|
|
229
|
-
layout: [25, 50, 25],
|
|
230
|
-
panelConstraints: [
|
|
231
|
-
{ minSizePercentage: 10, maxSizePercentage: 25 },
|
|
232
|
-
{ maxSizePercentage: 75 },
|
|
233
|
-
{ minSizePercentage: 10, maxSizePercentage: 50 },
|
|
234
|
-
],
|
|
235
|
-
})
|
|
236
|
-
).toEqual([25, 50, 25]);
|
|
237
|
-
|
|
238
|
-
expect(
|
|
239
|
-
validatePanelGroupLayout({
|
|
240
|
-
groupSizePixels: NaN,
|
|
241
|
-
layout: [5, 80, 15],
|
|
242
|
-
panelConstraints: [
|
|
243
|
-
{ minSizePercentage: 10, maxSizePercentage: 25 },
|
|
244
|
-
{ maxSizePercentage: 75 },
|
|
245
|
-
{ minSizePercentage: 10, maxSizePercentage: 50 },
|
|
246
|
-
],
|
|
247
|
-
})
|
|
248
|
-
).toEqual([10, 75, 15]);
|
|
249
|
-
|
|
250
|
-
expect(
|
|
251
|
-
validatePanelGroupLayout({
|
|
252
|
-
groupSizePixels: NaN,
|
|
253
|
-
layout: [30, 10, 60],
|
|
254
|
-
panelConstraints: [
|
|
255
|
-
{ minSizePercentage: 10, maxSizePercentage: 25 },
|
|
256
|
-
{ maxSizePercentage: 75 },
|
|
257
|
-
{ minSizePercentage: 10, maxSizePercentage: 50 },
|
|
258
|
-
],
|
|
259
|
-
})
|
|
260
|
-
).toEqual([25, 25, 50]);
|
|
261
|
-
});
|
|
262
147
|
});
|
|
263
148
|
});
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { isDevelopment } from "#is-development";
|
|
2
2
|
import { PanelConstraints } from "../Panel";
|
|
3
|
+
import { assert } from "./assert";
|
|
3
4
|
import { fuzzyNumbersEqual } from "./numbers/fuzzyNumbersEqual";
|
|
4
5
|
import { resizePanel } from "./resizePanel";
|
|
5
6
|
|
|
6
7
|
// All units must be in percentages; pixel values should be pre-converted
|
|
7
8
|
export function validatePanelGroupLayout({
|
|
8
|
-
groupSizePixels,
|
|
9
9
|
layout: prevLayout,
|
|
10
10
|
panelConstraints,
|
|
11
11
|
}: {
|
|
12
|
-
groupSizePixels: number;
|
|
13
12
|
layout: number[];
|
|
14
13
|
panelConstraints: PanelConstraints[];
|
|
15
14
|
}): number[] {
|
|
16
15
|
const nextLayout = [...prevLayout];
|
|
16
|
+
const nextLayoutTotalSize = nextLayout.reduce(
|
|
17
|
+
(accumulated, current) => accumulated + current,
|
|
18
|
+
0
|
|
19
|
+
);
|
|
17
20
|
|
|
18
21
|
// Validate layout expectations
|
|
19
22
|
if (nextLayout.length !== panelConstraints.length) {
|
|
@@ -22,31 +25,32 @@ export function validatePanelGroupLayout({
|
|
|
22
25
|
.map((size) => `${size}%`)
|
|
23
26
|
.join(", ")}`
|
|
24
27
|
);
|
|
25
|
-
} else if (
|
|
26
|
-
!fuzzyNumbersEqual(
|
|
27
|
-
nextLayout.reduce((accumulated, current) => accumulated + current, 0),
|
|
28
|
-
100
|
|
29
|
-
)
|
|
30
|
-
) {
|
|
28
|
+
} else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
|
|
31
29
|
// This is not ideal so we should warn about it, but it may be recoverable in some cases
|
|
32
30
|
// (especially if the amount is small)
|
|
33
31
|
if (isDevelopment) {
|
|
34
32
|
console.warn(
|
|
35
33
|
`WARNING: Invalid layout total size: ${nextLayout
|
|
36
34
|
.map((size) => `${size}%`)
|
|
37
|
-
.join(", ")}
|
|
35
|
+
.join(", ")}. Layout normalization will be applied.`
|
|
38
36
|
);
|
|
39
37
|
}
|
|
38
|
+
for (let index = 0; index < panelConstraints.length; index++) {
|
|
39
|
+
const unsafeSize = nextLayout[index];
|
|
40
|
+
assert(unsafeSize != null);
|
|
41
|
+
const safeSize = (100 / nextLayoutTotalSize) * unsafeSize;
|
|
42
|
+
nextLayout[index] = safeSize;
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
let remainingSize = 0;
|
|
43
47
|
|
|
44
48
|
// First pass: Validate the proposed layout given each panel's constraints
|
|
45
49
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
46
|
-
const unsafeSize = nextLayout[index]
|
|
50
|
+
const unsafeSize = nextLayout[index];
|
|
51
|
+
assert(unsafeSize != null);
|
|
47
52
|
|
|
48
53
|
const safeSize = resizePanel({
|
|
49
|
-
groupSizePixels,
|
|
50
54
|
panelConstraints,
|
|
51
55
|
panelIndex: index,
|
|
52
56
|
size: unsafeSize,
|
|
@@ -63,10 +67,10 @@ export function validatePanelGroupLayout({
|
|
|
63
67
|
// (It's not worth taking multiple additional passes to evenly distribute)
|
|
64
68
|
if (!fuzzyNumbersEqual(remainingSize, 0)) {
|
|
65
69
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
66
|
-
const prevSize = nextLayout[index]
|
|
70
|
+
const prevSize = nextLayout[index];
|
|
71
|
+
assert(prevSize != null);
|
|
67
72
|
const unsafeSize = prevSize + remainingSize;
|
|
68
73
|
const safeSize = resizePanel({
|
|
69
|
-
groupSizePixels,
|
|
70
74
|
panelConstraints,
|
|
71
75
|
panelIndex: index,
|
|
72
76
|
size: unsafeSize,
|
package/src/vendor/react.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
CSSProperties,
|
|
13
13
|
ElementType,
|
|
14
14
|
ForwardedRef,
|
|
15
|
+
HTMLAttributes,
|
|
15
16
|
MouseEvent,
|
|
16
17
|
PropsWithChildren,
|
|
17
18
|
ReactNode,
|
|
@@ -57,6 +58,7 @@ export type {
|
|
|
57
58
|
CSSProperties,
|
|
58
59
|
ElementType,
|
|
59
60
|
ForwardedRef,
|
|
61
|
+
HTMLAttributes,
|
|
60
62
|
MouseEvent,
|
|
61
63
|
PropsWithChildren,
|
|
62
64
|
ReactNode,
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { PanelConstraints } from "../Panel";
|
|
2
|
-
import { computePercentagePanelConstraints } from "./computePercentagePanelConstraints";
|
|
3
|
-
|
|
4
|
-
describe("computePercentagePanelConstraints", () => {
|
|
5
|
-
it("should compute reasonable defaults with no constraints", () => {
|
|
6
|
-
expect(computePercentagePanelConstraints([{}, {}], 0, 100))
|
|
7
|
-
.toMatchInlineSnapshot(`
|
|
8
|
-
{
|
|
9
|
-
"collapsedSizePercentage": 0,
|
|
10
|
-
"defaultSizePercentage": undefined,
|
|
11
|
-
"maxSizePercentage": 100,
|
|
12
|
-
"minSizePercentage": 0,
|
|
13
|
-
}
|
|
14
|
-
`);
|
|
15
|
-
|
|
16
|
-
expect(computePercentagePanelConstraints([{}, {}], 1, 100))
|
|
17
|
-
.toMatchInlineSnapshot(`
|
|
18
|
-
{
|
|
19
|
-
"collapsedSizePercentage": 0,
|
|
20
|
-
"defaultSizePercentage": undefined,
|
|
21
|
-
"maxSizePercentage": 100,
|
|
22
|
-
"minSizePercentage": 0,
|
|
23
|
-
}
|
|
24
|
-
`);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("should compute percentage based constraints based on a mix of pixels and percentages", () => {
|
|
28
|
-
const constraints: PanelConstraints[] = [
|
|
29
|
-
{
|
|
30
|
-
maxSizePixels: 20,
|
|
31
|
-
minSizePixels: 10,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
minSizePixels: 10,
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
minSizePixels: 10,
|
|
38
|
-
},
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
expect(computePercentagePanelConstraints(constraints, 0, 100))
|
|
42
|
-
.toMatchInlineSnapshot(`
|
|
43
|
-
{
|
|
44
|
-
"collapsedSizePercentage": 0,
|
|
45
|
-
"defaultSizePercentage": undefined,
|
|
46
|
-
"maxSizePercentage": 20,
|
|
47
|
-
"minSizePercentage": 10,
|
|
48
|
-
}
|
|
49
|
-
`);
|
|
50
|
-
|
|
51
|
-
expect(computePercentagePanelConstraints(constraints, 1, 100))
|
|
52
|
-
.toMatchInlineSnapshot(`
|
|
53
|
-
{
|
|
54
|
-
"collapsedSizePercentage": 0,
|
|
55
|
-
"defaultSizePercentage": undefined,
|
|
56
|
-
"maxSizePercentage": 80,
|
|
57
|
-
"minSizePercentage": 10,
|
|
58
|
-
}
|
|
59
|
-
`);
|
|
60
|
-
|
|
61
|
-
expect(computePercentagePanelConstraints(constraints, 2, 100))
|
|
62
|
-
.toMatchInlineSnapshot(`
|
|
63
|
-
{
|
|
64
|
-
"collapsedSizePercentage": 0,
|
|
65
|
-
"defaultSizePercentage": undefined,
|
|
66
|
-
"maxSizePercentage": 80,
|
|
67
|
-
"minSizePercentage": 10,
|
|
68
|
-
}
|
|
69
|
-
`);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should compute reasonable percentage based constraints from pixels if group size is negative", () => {
|
|
73
|
-
jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
74
|
-
|
|
75
|
-
expect(
|
|
76
|
-
computePercentagePanelConstraints(
|
|
77
|
-
[
|
|
78
|
-
{
|
|
79
|
-
minSizePixels: 25,
|
|
80
|
-
maxSizePixels: 100,
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
|
|
84
|
-
0,
|
|
85
|
-
-100
|
|
86
|
-
)
|
|
87
|
-
).toMatchInlineSnapshot(`
|
|
88
|
-
{
|
|
89
|
-
"collapsedSizePercentage": 0,
|
|
90
|
-
"defaultSizePercentage": undefined,
|
|
91
|
-
"maxSizePercentage": 0,
|
|
92
|
-
"minSizePercentage": 0,
|
|
93
|
-
}
|
|
94
|
-
`);
|
|
95
|
-
|
|
96
|
-
expect(console.warn).toHaveBeenCalledTimes(1);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { PanelConstraints } from "../Panel";
|
|
2
|
-
import { convertPixelConstraintsToPercentages } from "./convertPixelConstraintsToPercentages";
|
|
3
|
-
|
|
4
|
-
export function computePercentagePanelConstraints(
|
|
5
|
-
panelConstraintsArray: PanelConstraints[],
|
|
6
|
-
panelIndex: number,
|
|
7
|
-
groupSizePixels: number
|
|
8
|
-
): {
|
|
9
|
-
collapsedSizePercentage: number;
|
|
10
|
-
defaultSizePercentage: number | undefined;
|
|
11
|
-
maxSizePercentage: number;
|
|
12
|
-
minSizePercentage: number;
|
|
13
|
-
} {
|
|
14
|
-
// All panel constraints, excluding the current one
|
|
15
|
-
let totalMinConstraints = 0;
|
|
16
|
-
let totalMaxConstraints = 0;
|
|
17
|
-
|
|
18
|
-
for (let index = 0; index < panelConstraintsArray.length; index++) {
|
|
19
|
-
if (index !== panelIndex) {
|
|
20
|
-
const { collapsible } = panelConstraintsArray[index]!;
|
|
21
|
-
const { collapsedSizePercentage, maxSizePercentage, minSizePercentage } =
|
|
22
|
-
convertPixelConstraintsToPercentages(
|
|
23
|
-
panelConstraintsArray[index]!,
|
|
24
|
-
groupSizePixels
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
totalMaxConstraints += maxSizePercentage;
|
|
28
|
-
totalMinConstraints += collapsible
|
|
29
|
-
? collapsedSizePercentage
|
|
30
|
-
: minSizePercentage;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const {
|
|
35
|
-
collapsedSizePercentage,
|
|
36
|
-
defaultSizePercentage,
|
|
37
|
-
maxSizePercentage,
|
|
38
|
-
minSizePercentage,
|
|
39
|
-
} = convertPixelConstraintsToPercentages(
|
|
40
|
-
panelConstraintsArray[panelIndex]!,
|
|
41
|
-
groupSizePixels
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
collapsedSizePercentage,
|
|
46
|
-
defaultSizePercentage,
|
|
47
|
-
maxSizePercentage:
|
|
48
|
-
panelConstraintsArray.length > 1
|
|
49
|
-
? Math.min(maxSizePercentage, 100 - totalMinConstraints)
|
|
50
|
-
: maxSizePercentage,
|
|
51
|
-
minSizePercentage:
|
|
52
|
-
panelConstraintsArray.length > 1
|
|
53
|
-
? Math.max(minSizePercentage, 100 - totalMaxConstraints)
|
|
54
|
-
: minSizePercentage,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { convertPercentageToPixels } from "./convertPercentageToPixels";
|
|
2
|
-
|
|
3
|
-
describe("convertPercentageToPixels", () => {
|
|
4
|
-
it("should convert percentages to pixels", () => {
|
|
5
|
-
expect(convertPercentageToPixels(0, 100_000)).toBe(0);
|
|
6
|
-
expect(convertPercentageToPixels(50, 100_000)).toBe(50_000);
|
|
7
|
-
expect(convertPercentageToPixels(100, 100_000)).toBe(100_000);
|
|
8
|
-
});
|
|
9
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { convertPixelConstraintsToPercentages } from "./convertPixelConstraintsToPercentages";
|
|
2
|
-
|
|
3
|
-
describe("convertPixelConstraintsToPercentages", () => {
|
|
4
|
-
it("should respect percentage panel constraints if group size is negative", () => {
|
|
5
|
-
jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
6
|
-
|
|
7
|
-
expect(
|
|
8
|
-
convertPixelConstraintsToPercentages(
|
|
9
|
-
{
|
|
10
|
-
minSizePercentage: 25,
|
|
11
|
-
defaultSizePercentage: 50,
|
|
12
|
-
maxSizePercentage: 75,
|
|
13
|
-
},
|
|
14
|
-
-100
|
|
15
|
-
)
|
|
16
|
-
).toEqual({
|
|
17
|
-
collapsedSizePercentage: 0,
|
|
18
|
-
defaultSizePercentage: 50,
|
|
19
|
-
maxSizePercentage: 75,
|
|
20
|
-
minSizePercentage: 25,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
expect(console.warn).toHaveBeenCalledTimes(0);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// Edge case test (issues/206)
|
|
27
|
-
it("should ignore pixel panel constraints if group size is negative", () => {
|
|
28
|
-
jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
29
|
-
|
|
30
|
-
expect(
|
|
31
|
-
convertPixelConstraintsToPercentages(
|
|
32
|
-
{
|
|
33
|
-
minSizePixels: 25,
|
|
34
|
-
maxSizePixels: 75,
|
|
35
|
-
},
|
|
36
|
-
-100
|
|
37
|
-
)
|
|
38
|
-
).toEqual({
|
|
39
|
-
collapsedSizePercentage: 0,
|
|
40
|
-
defaultSizePercentage: undefined,
|
|
41
|
-
maxSizePercentage: 0,
|
|
42
|
-
minSizePercentage: 0,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
expect(console.warn).toHaveBeenCalledTimes(1);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { PanelConstraints } from "../Panel";
|
|
2
|
-
import { convertPixelsToPercentage } from "./convertPixelsToPercentage";
|
|
3
|
-
|
|
4
|
-
export function convertPixelConstraintsToPercentages(
|
|
5
|
-
panelConstraints: PanelConstraints,
|
|
6
|
-
groupSizePixels: number
|
|
7
|
-
): {
|
|
8
|
-
collapsedSizePercentage: number;
|
|
9
|
-
defaultSizePercentage: number | undefined;
|
|
10
|
-
maxSizePercentage: number;
|
|
11
|
-
minSizePercentage: number;
|
|
12
|
-
} {
|
|
13
|
-
let {
|
|
14
|
-
collapsedSizePercentage = 0,
|
|
15
|
-
collapsedSizePixels,
|
|
16
|
-
defaultSizePercentage,
|
|
17
|
-
defaultSizePixels,
|
|
18
|
-
maxSizePercentage = 100,
|
|
19
|
-
maxSizePixels,
|
|
20
|
-
minSizePercentage = 0,
|
|
21
|
-
minSizePixels,
|
|
22
|
-
} = panelConstraints;
|
|
23
|
-
|
|
24
|
-
const hasPixelConstraints =
|
|
25
|
-
collapsedSizePixels != null ||
|
|
26
|
-
defaultSizePixels != null ||
|
|
27
|
-
minSizePixels != null ||
|
|
28
|
-
maxSizePixels != null;
|
|
29
|
-
|
|
30
|
-
if (hasPixelConstraints && groupSizePixels <= 0) {
|
|
31
|
-
console.warn(`WARNING: Invalid group size: ${groupSizePixels}px`);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
collapsedSizePercentage: 0,
|
|
35
|
-
defaultSizePercentage,
|
|
36
|
-
maxSizePercentage: 0,
|
|
37
|
-
minSizePercentage: 0,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (collapsedSizePixels != null) {
|
|
42
|
-
collapsedSizePercentage = convertPixelsToPercentage(
|
|
43
|
-
collapsedSizePixels,
|
|
44
|
-
groupSizePixels
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
if (defaultSizePixels != null) {
|
|
48
|
-
defaultSizePercentage = convertPixelsToPercentage(
|
|
49
|
-
defaultSizePixels,
|
|
50
|
-
groupSizePixels
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
if (minSizePixels != null) {
|
|
54
|
-
minSizePercentage = convertPixelsToPercentage(
|
|
55
|
-
minSizePixels,
|
|
56
|
-
groupSizePixels
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
if (maxSizePixels != null) {
|
|
60
|
-
maxSizePercentage = convertPixelsToPercentage(
|
|
61
|
-
maxSizePixels,
|
|
62
|
-
groupSizePixels
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
collapsedSizePercentage,
|
|
68
|
-
defaultSizePercentage,
|
|
69
|
-
maxSizePercentage,
|
|
70
|
-
minSizePercentage,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { convertPixelsToPercentage } from "./convertPixelsToPercentage";
|
|
2
|
-
|
|
3
|
-
describe("convertPixelsToPercentage", () => {
|
|
4
|
-
it("should convert pixels to percentages", () => {
|
|
5
|
-
expect(convertPixelsToPercentage(0, 100_000)).toBe(0);
|
|
6
|
-
expect(convertPixelsToPercentage(50_000, 100_000)).toBe(50);
|
|
7
|
-
expect(convertPixelsToPercentage(100_000, 100_000)).toBe(100);
|
|
8
|
-
});
|
|
9
|
-
});
|