react-resizable-panels 2.1.6 → 2.1.7
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/react-resizable-panels.browser.cjs.js +7 -7
- package/dist/react-resizable-panels.browser.development.cjs.js +7 -7
- package/dist/react-resizable-panels.browser.development.esm.js +7 -7
- package/dist/react-resizable-panels.browser.esm.js +7 -7
- package/dist/react-resizable-panels.cjs.js +7 -7
- package/dist/react-resizable-panels.development.cjs.js +7 -7
- package/dist/react-resizable-panels.development.esm.js +7 -7
- package/dist/react-resizable-panels.development.node.cjs.js +7 -7
- package/dist/react-resizable-panels.development.node.esm.js +7 -7
- package/dist/react-resizable-panels.esm.js +7 -7
- package/dist/react-resizable-panels.node.cjs.js +7 -7
- package/dist/react-resizable-panels.node.esm.js +7 -7
- package/package.json +7 -1
- package/.eslintrc.cjs +0 -27
- package/CHANGELOG.md +0 -574
- package/jest.config.js +0 -10
- package/src/Panel.test.tsx +0 -1084
- package/src/Panel.ts +0 -259
- package/src/PanelGroup.test.tsx +0 -443
- package/src/PanelGroup.ts +0 -999
- package/src/PanelGroupContext.ts +0 -42
- package/src/PanelResizeHandle.test.tsx +0 -367
- package/src/PanelResizeHandle.ts +0 -246
- package/src/PanelResizeHandleRegistry.ts +0 -336
- package/src/constants.ts +0 -1
- package/src/env-conditions/browser.ts +0 -1
- package/src/env-conditions/development.ts +0 -1
- package/src/env-conditions/node.ts +0 -1
- package/src/env-conditions/production.ts +0 -1
- package/src/env-conditions/unknown.ts +0 -1
- package/src/hooks/useForceUpdate.ts +0 -7
- package/src/hooks/useIsomorphicEffect.ts +0 -8
- package/src/hooks/useUniqueId.ts +0 -19
- package/src/hooks/useWindowSplitterBehavior.ts +0 -90
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +0 -201
- package/src/index.ts +0 -77
- package/src/types.ts +0 -5
- package/src/utils/adjustLayoutByDelta.test.ts +0 -2061
- package/src/utils/adjustLayoutByDelta.ts +0 -308
- package/src/utils/arrays.ts +0 -13
- package/src/utils/assert.ts +0 -10
- package/src/utils/calculateAriaValues.test.ts +0 -106
- package/src/utils/calculateAriaValues.ts +0 -45
- package/src/utils/calculateDeltaPercentage.ts +0 -63
- package/src/utils/calculateDragOffsetPercentage.ts +0 -40
- package/src/utils/calculateUnsafeDefaultLayout.test.ts +0 -87
- package/src/utils/calculateUnsafeDefaultLayout.ts +0 -50
- package/src/utils/callPanelCallbacks.ts +0 -49
- package/src/utils/compareLayouts.test.ts +0 -9
- package/src/utils/compareLayouts.ts +0 -12
- package/src/utils/computePanelFlexBoxStyle.test.ts +0 -123
- package/src/utils/computePanelFlexBoxStyle.ts +0 -50
- package/src/utils/csp.ts +0 -9
- package/src/utils/cursor.ts +0 -103
- package/src/utils/debounce.ts +0 -18
- package/src/utils/determinePivotIndices.ts +0 -15
- package/src/utils/dom/getPanelElement.ts +0 -10
- package/src/utils/dom/getPanelElementsForGroup.ts +0 -8
- package/src/utils/dom/getPanelGroupElement.ts +0 -21
- package/src/utils/dom/getResizeHandleElement.ts +0 -10
- package/src/utils/dom/getResizeHandleElementIndex.ts +0 -13
- package/src/utils/dom/getResizeHandleElementsForGroup.ts +0 -10
- package/src/utils/dom/getResizeHandlePanelIds.ts +0 -19
- package/src/utils/events/getResizeEventCoordinates.ts +0 -23
- package/src/utils/events/getResizeEventCursorPosition.ts +0 -14
- package/src/utils/events/index.ts +0 -13
- package/src/utils/getInputType.ts +0 -5
- package/src/utils/initializeDefaultStorage.ts +0 -26
- package/src/utils/numbers/fuzzyCompareNumbers.test.ts +0 -16
- package/src/utils/numbers/fuzzyCompareNumbers.ts +0 -21
- package/src/utils/numbers/fuzzyLayoutsEqual.ts +0 -22
- package/src/utils/numbers/fuzzyNumbersEqual.ts +0 -9
- package/src/utils/rects/getIntersectingRectangle.test.ts +0 -198
- package/src/utils/rects/getIntersectingRectangle.ts +0 -28
- package/src/utils/rects/intersects.test.ts +0 -197
- package/src/utils/rects/intersects.ts +0 -23
- package/src/utils/rects/types.ts +0 -6
- package/src/utils/resizePanel.test.ts +0 -59
- package/src/utils/resizePanel.ts +0 -47
- package/src/utils/serialization.ts +0 -87
- package/src/utils/test-utils.ts +0 -205
- package/src/utils/validatePanelConstraints.test.ts +0 -143
- package/src/utils/validatePanelConstraints.ts +0 -69
- package/src/utils/validatePanelGroupLayout.test.ts +0 -148
- package/src/utils/validatePanelGroupLayout.ts +0 -95
- package/src/vendor/react.ts +0 -73
- package/src/vendor/stacking-order.ts +0 -139
|
@@ -1,22 +0,0 @@
|
|
|
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,198 +0,0 @@
|
|
|
1
|
-
import { getIntersectingRectangle } from "./getIntersectingRectangle";
|
|
2
|
-
import { Rectangle } from "./types";
|
|
3
|
-
|
|
4
|
-
const emptyRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
5
|
-
const rect = { x: 25, y: 25, width: 50, height: 50 };
|
|
6
|
-
|
|
7
|
-
function forkRect(partial: Partial<Rectangle>, baseRect: Rectangle = rect) {
|
|
8
|
-
return { ...rect, ...partial };
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
describe("getIntersectingRectangle", () => {
|
|
12
|
-
let strict: boolean = false;
|
|
13
|
-
|
|
14
|
-
function verify(rectOne: Rectangle, rectTwo: Rectangle, expected: Rectangle) {
|
|
15
|
-
const actual = getIntersectingRectangle(rectOne, rectTwo, strict);
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
expect(actual).toEqual(expected);
|
|
19
|
-
} catch (thrown) {
|
|
20
|
-
console.log(
|
|
21
|
-
"Expect",
|
|
22
|
-
strict ? "strict mode" : "loose mode",
|
|
23
|
-
"\n",
|
|
24
|
-
rectOne,
|
|
25
|
-
"\n",
|
|
26
|
-
rectTwo,
|
|
27
|
-
"\n\nto intersect as:\n",
|
|
28
|
-
expected,
|
|
29
|
-
"\n\nbut got:\n",
|
|
30
|
-
actual
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
throw thrown;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe("loose", () => {
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
strict = false;
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("should support empty rects", () => {
|
|
43
|
-
verify(emptyRect, emptyRect, emptyRect);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should support fully overlapping rects", () => {
|
|
47
|
-
verify(rect, forkRect({ x: 35, width: 30 }), {
|
|
48
|
-
x: 35,
|
|
49
|
-
y: 25,
|
|
50
|
-
width: 30,
|
|
51
|
-
height: 50,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
verify(rect, forkRect({ y: 35, height: 30 }), {
|
|
55
|
-
x: 25,
|
|
56
|
-
y: 35,
|
|
57
|
-
width: 50,
|
|
58
|
-
height: 30,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
verify(
|
|
62
|
-
rect,
|
|
63
|
-
forkRect({
|
|
64
|
-
x: 35,
|
|
65
|
-
y: 35,
|
|
66
|
-
width: 30,
|
|
67
|
-
height: 30,
|
|
68
|
-
}),
|
|
69
|
-
|
|
70
|
-
{
|
|
71
|
-
x: 35,
|
|
72
|
-
y: 35,
|
|
73
|
-
width: 30,
|
|
74
|
-
height: 30,
|
|
75
|
-
}
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("should support partially overlapping rects", () => {
|
|
80
|
-
verify(rect, forkRect({ x: 10, y: 10 }), {
|
|
81
|
-
x: 25,
|
|
82
|
-
y: 25,
|
|
83
|
-
width: 35,
|
|
84
|
-
height: 35,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
verify(rect, forkRect({ x: 45, y: 30 }), {
|
|
88
|
-
x: 45,
|
|
89
|
-
y: 30,
|
|
90
|
-
width: 30,
|
|
91
|
-
height: 45,
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should support non-overlapping rects", () => {
|
|
96
|
-
verify(rect, forkRect({ x: 100, y: 100 }), emptyRect);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should support all negative coordinates", () => {
|
|
100
|
-
verify(
|
|
101
|
-
{
|
|
102
|
-
x: -100,
|
|
103
|
-
y: -100,
|
|
104
|
-
width: 50,
|
|
105
|
-
height: 50,
|
|
106
|
-
},
|
|
107
|
-
{ x: -80, y: -80, width: 50, height: 50 },
|
|
108
|
-
{
|
|
109
|
-
x: -80,
|
|
110
|
-
y: -80,
|
|
111
|
-
width: 30,
|
|
112
|
-
height: 30,
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe("strict", () => {
|
|
119
|
-
beforeEach(() => {
|
|
120
|
-
strict = true;
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should support empty rects", () => {
|
|
124
|
-
verify(emptyRect, emptyRect, emptyRect);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("should support fully overlapping rects", () => {
|
|
128
|
-
verify(rect, forkRect({ x: 35, width: 30 }), {
|
|
129
|
-
x: 35,
|
|
130
|
-
y: 25,
|
|
131
|
-
width: 30,
|
|
132
|
-
height: 50,
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
verify(rect, forkRect({ y: 35, height: 30 }), {
|
|
136
|
-
x: 25,
|
|
137
|
-
y: 35,
|
|
138
|
-
width: 50,
|
|
139
|
-
height: 30,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
verify(
|
|
143
|
-
rect,
|
|
144
|
-
forkRect({
|
|
145
|
-
x: 35,
|
|
146
|
-
y: 35,
|
|
147
|
-
width: 30,
|
|
148
|
-
height: 30,
|
|
149
|
-
}),
|
|
150
|
-
|
|
151
|
-
{
|
|
152
|
-
x: 35,
|
|
153
|
-
y: 35,
|
|
154
|
-
width: 30,
|
|
155
|
-
height: 30,
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it("should support partially overlapping rects", () => {
|
|
161
|
-
verify(rect, forkRect({ x: 10, y: 10 }), {
|
|
162
|
-
x: 25,
|
|
163
|
-
y: 25,
|
|
164
|
-
width: 35,
|
|
165
|
-
height: 35,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
verify(rect, forkRect({ x: 45, y: 30 }), {
|
|
169
|
-
x: 45,
|
|
170
|
-
y: 30,
|
|
171
|
-
width: 30,
|
|
172
|
-
height: 45,
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("should support non-overlapping rects", () => {
|
|
177
|
-
verify(rect, forkRect({ x: 100, y: 100 }), emptyRect);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("should support all negative coordinates", () => {
|
|
181
|
-
verify(
|
|
182
|
-
{
|
|
183
|
-
x: -100,
|
|
184
|
-
y: -100,
|
|
185
|
-
width: 50,
|
|
186
|
-
height: 50,
|
|
187
|
-
},
|
|
188
|
-
{ x: -80, y: -80, width: 50, height: 50 },
|
|
189
|
-
{
|
|
190
|
-
x: -80,
|
|
191
|
-
y: -80,
|
|
192
|
-
width: 30,
|
|
193
|
-
height: 30,
|
|
194
|
-
}
|
|
195
|
-
);
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { intersects } from "./intersects";
|
|
2
|
-
import { Rectangle } from "./types";
|
|
3
|
-
|
|
4
|
-
export function getIntersectingRectangle(
|
|
5
|
-
rectOne: Rectangle,
|
|
6
|
-
rectTwo: Rectangle,
|
|
7
|
-
strict: boolean
|
|
8
|
-
): Rectangle {
|
|
9
|
-
if (!intersects(rectOne, rectTwo, strict)) {
|
|
10
|
-
return {
|
|
11
|
-
x: 0,
|
|
12
|
-
y: 0,
|
|
13
|
-
width: 0,
|
|
14
|
-
height: 0,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
x: Math.max(rectOne.x, rectTwo.x),
|
|
20
|
-
y: Math.max(rectOne.y, rectTwo.y),
|
|
21
|
-
width:
|
|
22
|
-
Math.min(rectOne.x + rectOne.width, rectTwo.x + rectTwo.width) -
|
|
23
|
-
Math.max(rectOne.x, rectTwo.x),
|
|
24
|
-
height:
|
|
25
|
-
Math.min(rectOne.y + rectOne.height, rectTwo.y + rectTwo.height) -
|
|
26
|
-
Math.max(rectOne.y, rectTwo.y),
|
|
27
|
-
};
|
|
28
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { intersects } from "./intersects";
|
|
2
|
-
import { Rectangle } from "./types";
|
|
3
|
-
|
|
4
|
-
const emptyRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
5
|
-
const rect = { x: 25, y: 25, width: 50, height: 50 };
|
|
6
|
-
|
|
7
|
-
function forkRect(partial: Partial<Rectangle>, baseRect: Rectangle = rect) {
|
|
8
|
-
return { ...rect, ...partial };
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
describe("intersects", () => {
|
|
12
|
-
let strict: boolean = false;
|
|
13
|
-
|
|
14
|
-
function verify(rectOne: Rectangle, rectTwo: Rectangle, expected: boolean) {
|
|
15
|
-
const actual = intersects(rectOne, rectTwo, strict);
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
expect(actual).toBe(expected);
|
|
19
|
-
} catch (thrown) {
|
|
20
|
-
console.log(
|
|
21
|
-
"Expected",
|
|
22
|
-
rectOne,
|
|
23
|
-
"to",
|
|
24
|
-
expected ? "intersect" : "not intersect",
|
|
25
|
-
rectTwo,
|
|
26
|
-
strict ? "in strict mode" : "in loose mode"
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
throw thrown;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
describe("loose", () => {
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
strict = false;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should handle empty rects", () => {
|
|
39
|
-
verify(emptyRect, emptyRect, true);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("should support fully overlapping rects", () => {
|
|
43
|
-
verify(rect, rect, true);
|
|
44
|
-
|
|
45
|
-
verify(rect, forkRect({ x: 35, width: 30 }), true);
|
|
46
|
-
verify(rect, forkRect({ y: 35, height: 30 }), true);
|
|
47
|
-
verify(
|
|
48
|
-
rect,
|
|
49
|
-
forkRect({
|
|
50
|
-
x: 35,
|
|
51
|
-
y: 35,
|
|
52
|
-
width: 30,
|
|
53
|
-
height: 30,
|
|
54
|
-
}),
|
|
55
|
-
true
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
verify(rect, forkRect({ x: 10, width: 100 }), true);
|
|
59
|
-
verify(rect, forkRect({ y: 10, height: 100 }), true);
|
|
60
|
-
verify(
|
|
61
|
-
rect,
|
|
62
|
-
forkRect({
|
|
63
|
-
x: 10,
|
|
64
|
-
y: 10,
|
|
65
|
-
width: 100,
|
|
66
|
-
height: 100,
|
|
67
|
-
}),
|
|
68
|
-
true
|
|
69
|
-
);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should support partially overlapping rects", () => {
|
|
73
|
-
const cases: Partial<Rectangle>[] = [
|
|
74
|
-
{ x: 0 },
|
|
75
|
-
{ y: 0 },
|
|
76
|
-
|
|
77
|
-
// Loose mode only
|
|
78
|
-
{ x: -25 },
|
|
79
|
-
{ x: 75 },
|
|
80
|
-
{ y: -25 },
|
|
81
|
-
{ y: 75 },
|
|
82
|
-
{ x: -25, y: -25 },
|
|
83
|
-
{ x: 75, y: 75 },
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
cases.forEach((partial) => {
|
|
87
|
-
verify(forkRect(partial), rect, true);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("should support non-overlapping rects", () => {
|
|
92
|
-
const cases: Partial<Rectangle>[] = [
|
|
93
|
-
{ x: 100 },
|
|
94
|
-
{ x: -100 },
|
|
95
|
-
{ y: 100 },
|
|
96
|
-
{ y: -100 },
|
|
97
|
-
{ x: -100, y: -100 },
|
|
98
|
-
{ x: 100, y: 100 },
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
cases.forEach((partial) => {
|
|
102
|
-
verify(forkRect(partial), rect, false);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("should support all negative coordinates", () => {
|
|
107
|
-
expect(
|
|
108
|
-
intersects(
|
|
109
|
-
{ x: -100, y: -100, width: 50, height: 50 },
|
|
110
|
-
{ x: -110, y: -90, width: 50, height: 50 },
|
|
111
|
-
false
|
|
112
|
-
)
|
|
113
|
-
).toBe(true);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe("strict", () => {
|
|
118
|
-
beforeEach(() => {
|
|
119
|
-
strict = true;
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("should handle empty rects", () => {
|
|
123
|
-
verify(emptyRect, emptyRect, false);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should support fully overlapping rects", () => {
|
|
127
|
-
verify(rect, rect, true);
|
|
128
|
-
|
|
129
|
-
verify(rect, forkRect({ x: 35, width: 30 }), true);
|
|
130
|
-
verify(rect, forkRect({ y: 35, height: 30 }), true);
|
|
131
|
-
verify(
|
|
132
|
-
rect,
|
|
133
|
-
forkRect({
|
|
134
|
-
x: 35,
|
|
135
|
-
y: 35,
|
|
136
|
-
width: 30,
|
|
137
|
-
height: 30,
|
|
138
|
-
}),
|
|
139
|
-
true
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
verify(rect, forkRect({ x: 10, width: 100 }), true);
|
|
143
|
-
verify(rect, forkRect({ y: 10, height: 100 }), true);
|
|
144
|
-
verify(
|
|
145
|
-
rect,
|
|
146
|
-
forkRect({
|
|
147
|
-
x: 10,
|
|
148
|
-
y: 10,
|
|
149
|
-
width: 100,
|
|
150
|
-
height: 100,
|
|
151
|
-
}),
|
|
152
|
-
true
|
|
153
|
-
);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("should support partially overlapping rects", () => {
|
|
157
|
-
const cases: Partial<Rectangle>[] = [{ x: 0 }, { y: 0 }];
|
|
158
|
-
|
|
159
|
-
cases.forEach((partial) => {
|
|
160
|
-
verify(forkRect(partial), rect, true);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("should support non-overlapping rects", () => {
|
|
165
|
-
const cases: Partial<Rectangle>[] = [
|
|
166
|
-
{ x: 100 },
|
|
167
|
-
{ x: -100 },
|
|
168
|
-
{ y: 100 },
|
|
169
|
-
{ y: -100 },
|
|
170
|
-
{ x: -100, y: -100 },
|
|
171
|
-
{ x: 100, y: 100 },
|
|
172
|
-
|
|
173
|
-
// Strict mode only
|
|
174
|
-
{ x: -25 },
|
|
175
|
-
{ x: 75 },
|
|
176
|
-
{ y: -25 },
|
|
177
|
-
{ y: 75 },
|
|
178
|
-
{ x: -25, y: -25 },
|
|
179
|
-
{ x: 75, y: 75 },
|
|
180
|
-
];
|
|
181
|
-
|
|
182
|
-
cases.forEach((partial) => {
|
|
183
|
-
verify(forkRect(partial), rect, false);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("should support all negative coordinates", () => {
|
|
188
|
-
expect(
|
|
189
|
-
intersects(
|
|
190
|
-
{ x: -100, y: -100, width: 50, height: 50 },
|
|
191
|
-
{ x: -110, y: -90, width: 50, height: 50 },
|
|
192
|
-
true
|
|
193
|
-
)
|
|
194
|
-
).toBe(true);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Rectangle } from "./types";
|
|
2
|
-
|
|
3
|
-
export function intersects(
|
|
4
|
-
rectOne: Rectangle,
|
|
5
|
-
rectTwo: Rectangle,
|
|
6
|
-
strict: boolean
|
|
7
|
-
): boolean {
|
|
8
|
-
if (strict) {
|
|
9
|
-
return (
|
|
10
|
-
rectOne.x < rectTwo.x + rectTwo.width &&
|
|
11
|
-
rectOne.x + rectOne.width > rectTwo.x &&
|
|
12
|
-
rectOne.y < rectTwo.y + rectTwo.height &&
|
|
13
|
-
rectOne.y + rectOne.height > rectTwo.y
|
|
14
|
-
);
|
|
15
|
-
} else {
|
|
16
|
-
return (
|
|
17
|
-
rectOne.x <= rectTwo.x + rectTwo.width &&
|
|
18
|
-
rectOne.x + rectOne.width >= rectTwo.x &&
|
|
19
|
-
rectOne.y <= rectTwo.y + rectTwo.height &&
|
|
20
|
-
rectOne.y + rectOne.height >= rectTwo.y
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/utils/rects/types.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { resizePanel } from "./resizePanel";
|
|
2
|
-
|
|
3
|
-
describe("resizePanel", () => {
|
|
4
|
-
it("should not collapse (or expand) until a panel size dips below the halfway point between min size and collapsed size", () => {
|
|
5
|
-
expect(
|
|
6
|
-
resizePanel({
|
|
7
|
-
panelConstraints: [
|
|
8
|
-
{
|
|
9
|
-
collapsible: true,
|
|
10
|
-
collapsedSize: 10,
|
|
11
|
-
minSize: 20,
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
panelIndex: 0,
|
|
15
|
-
size: 15,
|
|
16
|
-
})
|
|
17
|
-
).toBe(20);
|
|
18
|
-
|
|
19
|
-
expect(
|
|
20
|
-
resizePanel({
|
|
21
|
-
panelConstraints: [
|
|
22
|
-
{
|
|
23
|
-
collapsible: true,
|
|
24
|
-
collapsedSize: 10,
|
|
25
|
-
minSize: 20,
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
panelIndex: 0,
|
|
29
|
-
size: 14,
|
|
30
|
-
})
|
|
31
|
-
).toBe(10);
|
|
32
|
-
|
|
33
|
-
expect(
|
|
34
|
-
resizePanel({
|
|
35
|
-
panelConstraints: [
|
|
36
|
-
{
|
|
37
|
-
collapsible: true,
|
|
38
|
-
minSize: 20,
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
panelIndex: 0,
|
|
42
|
-
size: 10,
|
|
43
|
-
})
|
|
44
|
-
).toBe(20);
|
|
45
|
-
|
|
46
|
-
expect(
|
|
47
|
-
resizePanel({
|
|
48
|
-
panelConstraints: [
|
|
49
|
-
{
|
|
50
|
-
collapsible: true,
|
|
51
|
-
minSize: 20,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
panelIndex: 0,
|
|
55
|
-
size: 9,
|
|
56
|
-
})
|
|
57
|
-
).toBe(0);
|
|
58
|
-
});
|
|
59
|
-
});
|
package/src/utils/resizePanel.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { PanelConstraints } from "../Panel";
|
|
2
|
-
import { PRECISION } from "../constants";
|
|
3
|
-
import { assert } from "./assert";
|
|
4
|
-
import { fuzzyCompareNumbers } from "./numbers/fuzzyCompareNumbers";
|
|
5
|
-
|
|
6
|
-
// Panel size must be in percentages; pixel values should be pre-converted
|
|
7
|
-
export function resizePanel({
|
|
8
|
-
panelConstraints: panelConstraintsArray,
|
|
9
|
-
panelIndex,
|
|
10
|
-
size,
|
|
11
|
-
}: {
|
|
12
|
-
panelConstraints: PanelConstraints[];
|
|
13
|
-
panelIndex: number;
|
|
14
|
-
size: number;
|
|
15
|
-
}) {
|
|
16
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
17
|
-
assert(
|
|
18
|
-
panelConstraints != null,
|
|
19
|
-
`Panel constraints not found for index ${panelIndex}`
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
let {
|
|
23
|
-
collapsedSize = 0,
|
|
24
|
-
collapsible,
|
|
25
|
-
maxSize = 100,
|
|
26
|
-
minSize = 0,
|
|
27
|
-
} = panelConstraints;
|
|
28
|
-
|
|
29
|
-
if (fuzzyCompareNumbers(size, minSize) < 0) {
|
|
30
|
-
if (collapsible) {
|
|
31
|
-
// Collapsible panels should snap closed or open only once they cross the halfway point between collapsed and min size.
|
|
32
|
-
const halfwayPoint = (collapsedSize + minSize) / 2;
|
|
33
|
-
if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
|
|
34
|
-
size = collapsedSize;
|
|
35
|
-
} else {
|
|
36
|
-
size = minSize;
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
size = minSize;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
size = Math.min(maxSize, size);
|
|
44
|
-
size = parseFloat(size.toFixed(PRECISION));
|
|
45
|
-
|
|
46
|
-
return size;
|
|
47
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { PanelData } from "../Panel";
|
|
2
|
-
import { PanelGroupStorage } from "../PanelGroup";
|
|
3
|
-
|
|
4
|
-
export type PanelConfigurationState = {
|
|
5
|
-
expandToSizes: {
|
|
6
|
-
[panelId: string]: number;
|
|
7
|
-
};
|
|
8
|
-
layout: number[];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type SerializedPanelGroupState = {
|
|
12
|
-
[panelIds: string]: PanelConfigurationState;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
function getPanelGroupKey(autoSaveId: string): string {
|
|
16
|
-
return `react-resizable-panels:${autoSaveId}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Note that Panel ids might be user-provided (stable) or useId generated (non-deterministic)
|
|
20
|
-
// so they should not be used as part of the serialization key.
|
|
21
|
-
// Using the min/max size attributes should work well enough as a backup.
|
|
22
|
-
// Pre-sorting by minSize allows remembering layouts even if panels are re-ordered/dragged.
|
|
23
|
-
function getPanelKey(panels: PanelData[]): string {
|
|
24
|
-
return panels
|
|
25
|
-
.map((panel) => {
|
|
26
|
-
const { constraints, id, idIsFromProps, order } = panel;
|
|
27
|
-
if (idIsFromProps) {
|
|
28
|
-
return id;
|
|
29
|
-
} else {
|
|
30
|
-
return order
|
|
31
|
-
? `${order}:${JSON.stringify(constraints)}`
|
|
32
|
-
: JSON.stringify(constraints);
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
.sort((a, b) => a.localeCompare(b))
|
|
36
|
-
.join(",");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function loadSerializedPanelGroupState(
|
|
40
|
-
autoSaveId: string,
|
|
41
|
-
storage: PanelGroupStorage
|
|
42
|
-
): SerializedPanelGroupState | null {
|
|
43
|
-
try {
|
|
44
|
-
const panelGroupKey = getPanelGroupKey(autoSaveId);
|
|
45
|
-
const serialized = storage.getItem(panelGroupKey);
|
|
46
|
-
if (serialized) {
|
|
47
|
-
const parsed = JSON.parse(serialized);
|
|
48
|
-
if (typeof parsed === "object" && parsed != null) {
|
|
49
|
-
return parsed as SerializedPanelGroupState;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
} catch (error) {}
|
|
53
|
-
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function loadPanelGroupState(
|
|
58
|
-
autoSaveId: string,
|
|
59
|
-
panels: PanelData[],
|
|
60
|
-
storage: PanelGroupStorage
|
|
61
|
-
): PanelConfigurationState | null {
|
|
62
|
-
const state = loadSerializedPanelGroupState(autoSaveId, storage) ?? {};
|
|
63
|
-
const panelKey = getPanelKey(panels);
|
|
64
|
-
return state[panelKey] ?? null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function savePanelGroupState(
|
|
68
|
-
autoSaveId: string,
|
|
69
|
-
panels: PanelData[],
|
|
70
|
-
panelSizesBeforeCollapse: Map<string, number>,
|
|
71
|
-
sizes: number[],
|
|
72
|
-
storage: PanelGroupStorage
|
|
73
|
-
): void {
|
|
74
|
-
const panelGroupKey = getPanelGroupKey(autoSaveId);
|
|
75
|
-
const panelKey = getPanelKey(panels);
|
|
76
|
-
const state = loadSerializedPanelGroupState(autoSaveId, storage) ?? {};
|
|
77
|
-
state[panelKey] = {
|
|
78
|
-
expandToSizes: Object.fromEntries(panelSizesBeforeCollapse.entries()),
|
|
79
|
-
layout: sizes,
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
storage.setItem(panelGroupKey, JSON.stringify(state));
|
|
84
|
-
} catch (error) {
|
|
85
|
-
console.error(error);
|
|
86
|
-
}
|
|
87
|
-
}
|