react-resizable-panels 2.0.9 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/declarations/src/utils/assert.d.ts +1 -1
- package/dist/react-resizable-panels.browser.cjs.js +50 -52
- package/dist/react-resizable-panels.browser.development.cjs.js +52 -54
- package/dist/react-resizable-panels.browser.development.esm.js +52 -54
- package/dist/react-resizable-panels.browser.esm.js +50 -52
- package/dist/react-resizable-panels.cjs.js +50 -52
- package/dist/react-resizable-panels.development.cjs.js +52 -54
- package/dist/react-resizable-panels.development.esm.js +52 -54
- package/dist/react-resizable-panels.development.node.cjs.js +48 -50
- package/dist/react-resizable-panels.development.node.esm.js +48 -50
- package/dist/react-resizable-panels.esm.js +50 -52
- package/dist/react-resizable-panels.node.cjs.js +46 -48
- package/dist/react-resizable-panels.node.esm.js +46 -48
- package/package.json +1 -1
- package/src/Panel.test.tsx +23 -23
- package/src/PanelGroup.test.tsx +32 -3
- package/src/PanelGroup.ts +25 -7
- package/src/PanelResizeHandle.test.tsx +3 -3
- package/src/PanelResizeHandle.ts +1 -1
- package/src/hooks/useWindowSplitterBehavior.ts +5 -2
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +5 -5
- package/src/utils/adjustLayoutByDelta.ts +47 -20
- package/src/utils/assert.ts +1 -1
- package/src/utils/calculateAriaValues.ts +1 -1
- package/src/utils/calculateDragOffsetPercentage.ts +6 -3
- package/src/utils/calculateUnsafeDefaultLayout.ts +2 -2
- package/src/utils/callPanelCallbacks.ts +1 -1
- package/src/utils/resizePanel.ts +4 -1
- package/src/utils/test-utils.ts +1 -1
- package/src/utils/validatePanelConstraints.ts +4 -1
- package/src/utils/validatePanelGroupLayout.ts +3 -3
- package/src/vendor/stacking-order.ts +5 -2
package/src/Panel.test.tsx
CHANGED
|
@@ -88,7 +88,7 @@ describe("PanelGroup", () => {
|
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
it("should expand and collapse the first panel in a group", () => {
|
|
91
|
-
assert(mostRecentLayout);
|
|
91
|
+
assert(mostRecentLayout, "");
|
|
92
92
|
|
|
93
93
|
verifyExpandedPanelGroupLayout(mostRecentLayout, [50, 50]);
|
|
94
94
|
expect(leftPanelRef.current?.isCollapsed()).toBe(false);
|
|
@@ -108,7 +108,7 @@ describe("PanelGroup", () => {
|
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
it("should expand and collapse the last panel in a group", () => {
|
|
111
|
-
assert(mostRecentLayout);
|
|
111
|
+
assert(mostRecentLayout, "");
|
|
112
112
|
|
|
113
113
|
verifyExpandedPanelGroupLayout(mostRecentLayout, [50, 50]);
|
|
114
114
|
expect(leftPanelRef.current?.isCollapsed()).toBe(false);
|
|
@@ -128,7 +128,7 @@ describe("PanelGroup", () => {
|
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
it("should re-expand to the most recent size before collapsing", () => {
|
|
131
|
-
assert(mostRecentLayout);
|
|
131
|
+
assert(mostRecentLayout, "");
|
|
132
132
|
|
|
133
133
|
verifyExpandedPanelGroupLayout(mostRecentLayout, [50, 50]);
|
|
134
134
|
act(() => {
|
|
@@ -178,7 +178,7 @@ describe("PanelGroup", () => {
|
|
|
178
178
|
});
|
|
179
179
|
|
|
180
180
|
it("should resize the first panel in a group", () => {
|
|
181
|
-
assert(mostRecentLayout);
|
|
181
|
+
assert(mostRecentLayout, "");
|
|
182
182
|
|
|
183
183
|
verifyExpandedPanelGroupLayout(mostRecentLayout, [20, 60, 20]);
|
|
184
184
|
act(() => {
|
|
@@ -188,7 +188,7 @@ describe("PanelGroup", () => {
|
|
|
188
188
|
});
|
|
189
189
|
|
|
190
190
|
it("should resize the middle panel in a group", () => {
|
|
191
|
-
assert(mostRecentLayout);
|
|
191
|
+
assert(mostRecentLayout, "");
|
|
192
192
|
|
|
193
193
|
verifyExpandedPanelGroupLayout(mostRecentLayout, [20, 60, 20]);
|
|
194
194
|
act(() => {
|
|
@@ -198,7 +198,7 @@ describe("PanelGroup", () => {
|
|
|
198
198
|
});
|
|
199
199
|
|
|
200
200
|
it("should resize the last panel in a group", () => {
|
|
201
|
-
assert(mostRecentLayout);
|
|
201
|
+
assert(mostRecentLayout, "");
|
|
202
202
|
|
|
203
203
|
verifyExpandedPanelGroupLayout(mostRecentLayout, [20, 60, 20]);
|
|
204
204
|
act(() => {
|
|
@@ -261,7 +261,7 @@ describe("PanelGroup", () => {
|
|
|
261
261
|
});
|
|
262
262
|
|
|
263
263
|
const element = getPanelElement("panel", container);
|
|
264
|
-
assert(element);
|
|
264
|
+
assert(element, "");
|
|
265
265
|
expect(element.tabIndex).toBe(123);
|
|
266
266
|
expect(element.getAttribute("data-test-name")).toBe("foo");
|
|
267
267
|
expect(element.title).toBe("bar");
|
|
@@ -296,9 +296,9 @@ describe("PanelGroup", () => {
|
|
|
296
296
|
let leftElement = getPanelElement("left", container);
|
|
297
297
|
let middleElement = getPanelElement("middle", container);
|
|
298
298
|
let rightElement = getPanelElement("right", container);
|
|
299
|
-
assert(leftElement);
|
|
300
|
-
assert(middleElement);
|
|
301
|
-
assert(rightElement);
|
|
299
|
+
assert(leftElement, "");
|
|
300
|
+
assert(middleElement, "");
|
|
301
|
+
assert(rightElement, "");
|
|
302
302
|
expect(leftElement.getAttribute("data-panel-size")).toBe("10.0");
|
|
303
303
|
expect(middleElement.getAttribute("data-panel-size")).toBe("80.0");
|
|
304
304
|
expect(rightElement.getAttribute("data-panel-size")).toBe("10.0");
|
|
@@ -348,9 +348,9 @@ describe("PanelGroup", () => {
|
|
|
348
348
|
let leftElement = getPanelElement("left", container);
|
|
349
349
|
let middleElement = getPanelElement("middle", container);
|
|
350
350
|
let rightElement = getPanelElement("right", container);
|
|
351
|
-
assert(leftElement);
|
|
352
|
-
assert(middleElement);
|
|
353
|
-
assert(rightElement);
|
|
351
|
+
assert(leftElement, "");
|
|
352
|
+
assert(middleElement, "");
|
|
353
|
+
assert(rightElement, "");
|
|
354
354
|
expect(leftElement.getAttribute("data-panel-size")).toBe("10.0");
|
|
355
355
|
expect(middleElement.getAttribute("data-panel-size")).toBe("80.0");
|
|
356
356
|
expect(rightElement.getAttribute("data-panel-size")).toBe("10.0");
|
|
@@ -388,9 +388,9 @@ describe("PanelGroup", () => {
|
|
|
388
388
|
let leftElement = getPanelElement("left", container);
|
|
389
389
|
let middleElement = getPanelElement("middle", container);
|
|
390
390
|
let rightElement = getPanelElement("right", container);
|
|
391
|
-
assert(leftElement);
|
|
392
|
-
assert(middleElement);
|
|
393
|
-
assert(rightElement);
|
|
391
|
+
assert(leftElement, "");
|
|
392
|
+
assert(middleElement, "");
|
|
393
|
+
assert(rightElement, "");
|
|
394
394
|
expect(leftElement.getAttribute("data-panel-size")).toBe("15.0");
|
|
395
395
|
expect(middleElement.getAttribute("data-panel-size")).toBe("70.0");
|
|
396
396
|
expect(rightElement.getAttribute("data-panel-size")).toBe("15.0");
|
|
@@ -428,9 +428,9 @@ describe("PanelGroup", () => {
|
|
|
428
428
|
let leftElement = getPanelElement("left", container);
|
|
429
429
|
let middleElement = getPanelElement("middle", container);
|
|
430
430
|
let rightElement = getPanelElement("right", container);
|
|
431
|
-
assert(leftElement);
|
|
432
|
-
assert(middleElement);
|
|
433
|
-
assert(rightElement);
|
|
431
|
+
assert(leftElement, "");
|
|
432
|
+
assert(middleElement, "");
|
|
433
|
+
assert(rightElement, "");
|
|
434
434
|
expect(leftElement.getAttribute("data-panel-size")).toBe("25.0");
|
|
435
435
|
expect(middleElement.getAttribute("data-panel-size")).toBe("50.0");
|
|
436
436
|
expect(rightElement.getAttribute("data-panel-size")).toBe("25.0");
|
|
@@ -691,8 +691,8 @@ describe("PanelGroup", () => {
|
|
|
691
691
|
const leftElement = getPanelElement("left-panel", container);
|
|
692
692
|
const rightElement = getPanelElement("right-panel", container);
|
|
693
693
|
|
|
694
|
-
assert(leftElement);
|
|
695
|
-
assert(rightElement);
|
|
694
|
+
assert(leftElement, "");
|
|
695
|
+
assert(rightElement, "");
|
|
696
696
|
|
|
697
697
|
verifyAttribute(leftElement, "data-panel", "");
|
|
698
698
|
verifyAttribute(leftElement, "data-panel-id", "left-panel");
|
|
@@ -723,8 +723,8 @@ describe("PanelGroup", () => {
|
|
|
723
723
|
const leftElement = getPanelElement("left-panel", container);
|
|
724
724
|
const rightElement = getPanelElement("right-panel", container);
|
|
725
725
|
|
|
726
|
-
assert(leftElement);
|
|
727
|
-
assert(rightElement);
|
|
726
|
+
assert(leftElement, "");
|
|
727
|
+
assert(rightElement, "");
|
|
728
728
|
|
|
729
729
|
verifyAttribute(leftElement, "data-panel-size", "75.0");
|
|
730
730
|
verifyAttribute(rightElement, "data-panel-size", "25.0");
|
package/src/PanelGroup.test.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-expect-error This is an experimental API
|
|
2
2
|
// eslint-disable-next-line no-restricted-imports
|
|
3
|
-
import { unstable_Activity as Activity } from "react";
|
|
3
|
+
import { unstable_Activity as Activity, Fragment } from "react";
|
|
4
4
|
import { Root, createRoot } from "react-dom/client";
|
|
5
5
|
import { act } from "react-dom/test-utils";
|
|
6
6
|
import {
|
|
@@ -130,6 +130,35 @@ describe("PanelGroup", () => {
|
|
|
130
130
|
expect(rightPanelElement?.getAttribute("data-panel-size")).toBe("40.0");
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
+
// github.com/bvaughn/react-resizable-panels/issues/303
|
|
134
|
+
it("should recalculate layout after panels are changed", () => {
|
|
135
|
+
let mostRecentLayout: number[] | null = null;
|
|
136
|
+
|
|
137
|
+
const onLayout = (layout: number[]) => {
|
|
138
|
+
mostRecentLayout = layout;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
act(() => {
|
|
142
|
+
root.render(
|
|
143
|
+
<PanelGroup direction="vertical" onLayout={onLayout}>
|
|
144
|
+
<Panel id="foo" minSize={30} order={0} />
|
|
145
|
+
<PanelResizeHandle />
|
|
146
|
+
<Panel id="bar" minSize={70} order={1} />
|
|
147
|
+
</PanelGroup>
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
expect(mostRecentLayout).toEqual([30, 70]);
|
|
151
|
+
|
|
152
|
+
act(() => {
|
|
153
|
+
root.render(
|
|
154
|
+
<PanelGroup direction="vertical" onLayout={onLayout}>
|
|
155
|
+
<Panel id="bar" minSize={70} order={0} />
|
|
156
|
+
</PanelGroup>
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
expect(mostRecentLayout).toEqual([100]);
|
|
160
|
+
});
|
|
161
|
+
|
|
133
162
|
describe("imperative handle API", () => {
|
|
134
163
|
it("should report the most recently rendered group id", () => {
|
|
135
164
|
const ref = createRef<ImperativePanelGroupHandle>();
|
|
@@ -194,7 +223,7 @@ describe("PanelGroup", () => {
|
|
|
194
223
|
});
|
|
195
224
|
|
|
196
225
|
const element = getPanelGroupElement("group", container);
|
|
197
|
-
assert(element);
|
|
226
|
+
assert(element, "");
|
|
198
227
|
expect(element.tabIndex).toBe(123);
|
|
199
228
|
expect(element.getAttribute("data-test-name")).toBe("foo");
|
|
200
229
|
expect(element.title).toBe("bar");
|
|
@@ -268,7 +297,7 @@ describe("PanelGroup", () => {
|
|
|
268
297
|
});
|
|
269
298
|
|
|
270
299
|
const element = getPanelGroupElement("test-group", container);
|
|
271
|
-
assert(element);
|
|
300
|
+
assert(element, "");
|
|
272
301
|
|
|
273
302
|
verifyAttribute(element, "data-panel-group", "");
|
|
274
303
|
verifyAttribute(element, "data-panel-group-direction", "horizontal");
|
package/src/PanelGroup.ts
CHANGED
|
@@ -302,7 +302,7 @@ function PanelGroupWithForwardedRef({
|
|
|
302
302
|
panelIndex++
|
|
303
303
|
) {
|
|
304
304
|
const panelData = panelDataArray[panelIndex];
|
|
305
|
-
assert(panelData);
|
|
305
|
+
assert(panelData, `Panel data not found for index ${panelIndex}`);
|
|
306
306
|
|
|
307
307
|
const isValid = validatePanelConstraints({
|
|
308
308
|
panelConstraints,
|
|
@@ -336,7 +336,10 @@ function PanelGroupWithForwardedRef({
|
|
|
336
336
|
pivotIndices,
|
|
337
337
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
338
338
|
|
|
339
|
-
assert(
|
|
339
|
+
assert(
|
|
340
|
+
panelSize != null,
|
|
341
|
+
`Panel size not found for panel "${panelData.id}"`
|
|
342
|
+
);
|
|
340
343
|
|
|
341
344
|
if (panelSize !== collapsedSize) {
|
|
342
345
|
// Store size before collapse;
|
|
@@ -443,7 +446,10 @@ function PanelGroupWithForwardedRef({
|
|
|
443
446
|
|
|
444
447
|
const { panelSize } = panelDataHelper(panelDataArray, panelData, layout);
|
|
445
448
|
|
|
446
|
-
assert(
|
|
449
|
+
assert(
|
|
450
|
+
panelSize != null,
|
|
451
|
+
`Panel size not found for panel "${panelData.id}"`
|
|
452
|
+
);
|
|
447
453
|
|
|
448
454
|
return panelSize;
|
|
449
455
|
}, []);
|
|
@@ -489,7 +495,10 @@ function PanelGroupWithForwardedRef({
|
|
|
489
495
|
panelSize,
|
|
490
496
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
491
497
|
|
|
492
|
-
assert(
|
|
498
|
+
assert(
|
|
499
|
+
panelSize != null,
|
|
500
|
+
`Panel size not found for panel "${panelData.id}"`
|
|
501
|
+
);
|
|
493
502
|
|
|
494
503
|
return !collapsible || panelSize > collapsedSize;
|
|
495
504
|
}, []);
|
|
@@ -699,7 +708,10 @@ function PanelGroupWithForwardedRef({
|
|
|
699
708
|
prevLayout
|
|
700
709
|
);
|
|
701
710
|
|
|
702
|
-
assert(
|
|
711
|
+
assert(
|
|
712
|
+
panelSize != null,
|
|
713
|
+
`Panel size not found for panel "${panelData.id}"`
|
|
714
|
+
);
|
|
703
715
|
|
|
704
716
|
const isLastPanel =
|
|
705
717
|
findPanelDataIndex(panelDataArray, panelData) ===
|
|
@@ -756,7 +768,10 @@ function PanelGroupWithForwardedRef({
|
|
|
756
768
|
panelData,
|
|
757
769
|
layout
|
|
758
770
|
);
|
|
759
|
-
|
|
771
|
+
if (prevPanelSize == null) {
|
|
772
|
+
// It's possible that the panels in this group have changed since the last render
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
760
775
|
|
|
761
776
|
if (
|
|
762
777
|
prevCollapsible &&
|
|
@@ -788,7 +803,10 @@ function PanelGroupWithForwardedRef({
|
|
|
788
803
|
dragHandleId,
|
|
789
804
|
panelGroupElementRef.current
|
|
790
805
|
);
|
|
791
|
-
assert(
|
|
806
|
+
assert(
|
|
807
|
+
handleElement,
|
|
808
|
+
`Drag handle element not found for id "${dragHandleId}"`
|
|
809
|
+
);
|
|
792
810
|
|
|
793
811
|
const initialCursorPosition = getResizeEventCursorPosition(
|
|
794
812
|
direction,
|
|
@@ -66,7 +66,7 @@ describe("PanelResizeHandle", () => {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
const element = getResizeHandleElement("handle", container);
|
|
69
|
-
assert(element);
|
|
69
|
+
assert(element, "");
|
|
70
70
|
expect(element.tabIndex).toBe(123);
|
|
71
71
|
expect(element.getAttribute("data-test-name")).toBe("foo");
|
|
72
72
|
expect(element.title).toBe("bar");
|
|
@@ -94,8 +94,8 @@ describe("PanelResizeHandle", () => {
|
|
|
94
94
|
const leftElement = getResizeHandleElement("handle-left", container);
|
|
95
95
|
const rightElement = getResizeHandleElement("handle-right", container);
|
|
96
96
|
|
|
97
|
-
assert(leftElement);
|
|
98
|
-
assert(rightElement);
|
|
97
|
+
assert(leftElement, "");
|
|
98
|
+
assert(rightElement, "");
|
|
99
99
|
|
|
100
100
|
// JSDom doesn't properly handle bounding rects
|
|
101
101
|
mockBoundingClientRect(leftElement, {
|
package/src/PanelResizeHandle.ts
CHANGED
|
@@ -49,7 +49,7 @@ export function useWindowSplitterResizeHandlerBehavior({
|
|
|
49
49
|
event.preventDefault();
|
|
50
50
|
|
|
51
51
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
52
|
-
assert(groupId);
|
|
52
|
+
assert(groupId, `No group element found for id "${groupId}"`);
|
|
53
53
|
|
|
54
54
|
const handles = getResizeHandleElementsForGroup(
|
|
55
55
|
groupId,
|
|
@@ -61,7 +61,10 @@ export function useWindowSplitterResizeHandlerBehavior({
|
|
|
61
61
|
panelGroupElement
|
|
62
62
|
);
|
|
63
63
|
|
|
64
|
-
assert(
|
|
64
|
+
assert(
|
|
65
|
+
index !== null,
|
|
66
|
+
`No resize element found for id "${handleId}"`
|
|
67
|
+
);
|
|
65
68
|
|
|
66
69
|
const nextIndex = event.shiftKey
|
|
67
70
|
? index > 0
|
|
@@ -72,7 +72,7 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
72
72
|
}
|
|
73
73
|
} else {
|
|
74
74
|
const panelData = panelDataArray[index];
|
|
75
|
-
assert(panelData);
|
|
75
|
+
assert(panelData, `No panel data found for index "${index}"`);
|
|
76
76
|
|
|
77
77
|
resizeHandleElement.setAttribute("aria-controls", panelData.id);
|
|
78
78
|
resizeHandleElement.setAttribute(
|
|
@@ -105,18 +105,18 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
const eagerValues = eagerValuesRef.current;
|
|
108
|
-
assert(eagerValues);
|
|
108
|
+
assert(eagerValues, `Eager values not found`);
|
|
109
109
|
|
|
110
110
|
const { panelDataArray } = eagerValues;
|
|
111
111
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
112
112
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
113
113
|
|
|
114
114
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
115
|
-
assert(handles);
|
|
115
|
+
assert(handles, `No resize handles found for group id "${groupId}"`);
|
|
116
116
|
|
|
117
117
|
const cleanupFunctions = handles.map((handle) => {
|
|
118
118
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
119
|
-
assert(handleId);
|
|
119
|
+
assert(handleId, `Resize handle element has no handle id attribute`);
|
|
120
120
|
|
|
121
121
|
const [idBefore, idAfter] = getResizeHandlePanelIds(
|
|
122
122
|
groupId,
|
|
@@ -142,7 +142,7 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
142
142
|
);
|
|
143
143
|
if (index >= 0) {
|
|
144
144
|
const panelData = panelDataArray[index];
|
|
145
|
-
assert(panelData);
|
|
145
|
+
assert(panelData, `No panel data found for index ${index}`);
|
|
146
146
|
|
|
147
147
|
const size = layout[index];
|
|
148
148
|
|
|
@@ -25,8 +25,8 @@ export function adjustLayoutByDelta({
|
|
|
25
25
|
const nextLayout = [...prevLayout];
|
|
26
26
|
|
|
27
27
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
28
|
-
assert(firstPivotIndex != null);
|
|
29
|
-
assert(secondPivotIndex != null);
|
|
28
|
+
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
29
|
+
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
30
30
|
|
|
31
31
|
let deltaApplied = 0;
|
|
32
32
|
|
|
@@ -53,17 +53,25 @@ export function adjustLayoutByDelta({
|
|
|
53
53
|
// Check if we should expand a collapsed panel
|
|
54
54
|
const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
55
55
|
const panelConstraints = panelConstraintsArray[index];
|
|
56
|
-
assert(
|
|
56
|
+
assert(
|
|
57
|
+
panelConstraints,
|
|
58
|
+
`Panel constraints not found for index ${index}`
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const {
|
|
62
|
+
collapsedSize = 0,
|
|
63
|
+
collapsible,
|
|
64
|
+
minSize = 0,
|
|
65
|
+
} = panelConstraints;
|
|
57
66
|
|
|
58
67
|
//DEBUG.push(`edge case check 1: ${index}`);
|
|
59
68
|
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
60
|
-
if (
|
|
69
|
+
if (collapsible) {
|
|
61
70
|
const prevSize = prevLayout[index];
|
|
62
|
-
assert(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const { collapsedSize = 0, minSize = 0 } = panelConstraints;
|
|
71
|
+
assert(
|
|
72
|
+
prevSize != null,
|
|
73
|
+
`Previous layout not found for panel index ${index}`
|
|
74
|
+
);
|
|
67
75
|
|
|
68
76
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
69
77
|
const localDelta = minSize - prevSize;
|
|
@@ -81,18 +89,25 @@ export function adjustLayoutByDelta({
|
|
|
81
89
|
// Check if we should collapse a panel at its minimum size
|
|
82
90
|
const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
83
91
|
const panelConstraints = panelConstraintsArray[index];
|
|
84
|
-
assert(
|
|
85
|
-
|
|
92
|
+
assert(
|
|
93
|
+
panelConstraints,
|
|
94
|
+
`No panel constraints found for index ${index}`
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const {
|
|
98
|
+
collapsedSize = 0,
|
|
99
|
+
collapsible,
|
|
100
|
+
minSize = 0,
|
|
101
|
+
} = panelConstraints;
|
|
86
102
|
|
|
87
103
|
//DEBUG.push(`edge case check 2: ${index}`);
|
|
88
104
|
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
89
105
|
if (collapsible) {
|
|
90
106
|
const prevSize = prevLayout[index];
|
|
91
|
-
assert(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const { collapsedSize = 0, minSize = 0 } = panelConstraints;
|
|
107
|
+
assert(
|
|
108
|
+
prevSize != null,
|
|
109
|
+
`Previous layout not found for panel index ${index}`
|
|
110
|
+
);
|
|
96
111
|
|
|
97
112
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
98
113
|
const localDelta = prevSize - collapsedSize;
|
|
@@ -124,7 +139,10 @@ export function adjustLayoutByDelta({
|
|
|
124
139
|
//DEBUG.push("pre calc...");
|
|
125
140
|
while (true) {
|
|
126
141
|
const prevSize = prevLayout[index];
|
|
127
|
-
assert(
|
|
142
|
+
assert(
|
|
143
|
+
prevSize != null,
|
|
144
|
+
`Previous layout not found for panel index ${index}`
|
|
145
|
+
);
|
|
128
146
|
|
|
129
147
|
const maxSafeSize = resizePanel({
|
|
130
148
|
panelConstraints: panelConstraintsArray,
|
|
@@ -158,7 +176,10 @@ export function adjustLayoutByDelta({
|
|
|
158
176
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
159
177
|
|
|
160
178
|
const prevSize = prevLayout[index];
|
|
161
|
-
assert(
|
|
179
|
+
assert(
|
|
180
|
+
prevSize != null,
|
|
181
|
+
`Previous layout not found for panel index ${index}`
|
|
182
|
+
);
|
|
162
183
|
|
|
163
184
|
const unsafeSize = prevSize - deltaRemaining;
|
|
164
185
|
const safeSize = resizePanel({
|
|
@@ -206,7 +227,10 @@ export function adjustLayoutByDelta({
|
|
|
206
227
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
207
228
|
|
|
208
229
|
const prevSize = prevLayout[pivotIndex];
|
|
209
|
-
assert(
|
|
230
|
+
assert(
|
|
231
|
+
prevSize != null,
|
|
232
|
+
`Previous layout not found for panel index ${pivotIndex}`
|
|
233
|
+
);
|
|
210
234
|
|
|
211
235
|
const unsafeSize = prevSize + deltaApplied;
|
|
212
236
|
const safeSize = resizePanel({
|
|
@@ -226,7 +250,10 @@ export function adjustLayoutByDelta({
|
|
|
226
250
|
let index = pivotIndex;
|
|
227
251
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
228
252
|
const prevSize = nextLayout[index];
|
|
229
|
-
assert(
|
|
253
|
+
assert(
|
|
254
|
+
prevSize != null,
|
|
255
|
+
`Previous layout not found for panel index ${index}`
|
|
256
|
+
);
|
|
230
257
|
|
|
231
258
|
const unsafeSize = prevSize + deltaRemaining;
|
|
232
259
|
const safeSize = resizePanel({
|
package/src/utils/assert.ts
CHANGED
|
@@ -16,7 +16,7 @@ export function calculateAriaValues({
|
|
|
16
16
|
let totalMaxSize = 0;
|
|
17
17
|
|
|
18
18
|
const firstIndex = pivotIndices[0];
|
|
19
|
-
assert(firstIndex != null);
|
|
19
|
+
assert(firstIndex != null, "No pivot index found");
|
|
20
20
|
|
|
21
21
|
// A panel's effective min/max sizes also need to account for other panel's sizes.
|
|
22
22
|
panelsArray.forEach((panelData, index) => {
|
|
@@ -15,17 +15,20 @@ export function calculateDragOffsetPercentage(
|
|
|
15
15
|
const isHorizontal = direction === "horizontal";
|
|
16
16
|
|
|
17
17
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
18
|
-
assert(
|
|
18
|
+
assert(
|
|
19
|
+
handleElement,
|
|
20
|
+
`No resize handle element found for id "${dragHandleId}"`
|
|
21
|
+
);
|
|
19
22
|
|
|
20
23
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
21
|
-
assert(groupId);
|
|
24
|
+
assert(groupId, `Resize handle element has no group id attribute`);
|
|
22
25
|
|
|
23
26
|
let { initialCursorPosition } = initialDragState;
|
|
24
27
|
|
|
25
28
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
26
29
|
|
|
27
30
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
28
|
-
assert(groupElement);
|
|
31
|
+
assert(groupElement, `No group element found for id "${groupId}"`);
|
|
29
32
|
|
|
30
33
|
const groupRect = groupElement.getBoundingClientRect();
|
|
31
34
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -18,7 +18,7 @@ export function calculateUnsafeDefaultLayout({
|
|
|
18
18
|
// Distribute default sizes first
|
|
19
19
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
20
20
|
const panelConstraints = panelConstraintsArray[index];
|
|
21
|
-
assert(panelConstraints);
|
|
21
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
22
22
|
const { defaultSize } = panelConstraints;
|
|
23
23
|
|
|
24
24
|
if (defaultSize != null) {
|
|
@@ -31,7 +31,7 @@ export function calculateUnsafeDefaultLayout({
|
|
|
31
31
|
// Remaining size should be distributed evenly between panels without default sizes
|
|
32
32
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
33
33
|
const panelConstraints = panelConstraintsArray[index];
|
|
34
|
-
assert(panelConstraints);
|
|
34
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
35
35
|
const { defaultSize } = panelConstraints;
|
|
36
36
|
|
|
37
37
|
if (defaultSize != null) {
|
|
@@ -9,7 +9,7 @@ export function callPanelCallbacks(
|
|
|
9
9
|
) {
|
|
10
10
|
layout.forEach((size, index) => {
|
|
11
11
|
const panelData = panelsArray[index];
|
|
12
|
-
assert(panelData);
|
|
12
|
+
assert(panelData, `Panel data not found for index ${index}`);
|
|
13
13
|
|
|
14
14
|
const { callbacks, constraints, id: panelId } = panelData;
|
|
15
15
|
const { collapsedSize = 0, collapsible } = constraints;
|
package/src/utils/resizePanel.ts
CHANGED
|
@@ -14,7 +14,10 @@ export function resizePanel({
|
|
|
14
14
|
size: number;
|
|
15
15
|
}) {
|
|
16
16
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
17
|
-
assert(
|
|
17
|
+
assert(
|
|
18
|
+
panelConstraints != null,
|
|
19
|
+
`Panel constraints not found for index ${panelIndex}`
|
|
20
|
+
);
|
|
18
21
|
|
|
19
22
|
let {
|
|
20
23
|
collapsedSize = 0,
|
package/src/utils/test-utils.ts
CHANGED
|
@@ -38,7 +38,7 @@ export function expectToBeCloseToArray(
|
|
|
38
38
|
try {
|
|
39
39
|
actualNumbers.forEach((actualNumber, index) => {
|
|
40
40
|
const expectedNumber = expectedNumbers[index];
|
|
41
|
-
assert(expectedNumber != null);
|
|
41
|
+
assert(expectedNumber != null, `Expected number not found`);
|
|
42
42
|
|
|
43
43
|
expect(actualNumber).toBeCloseTo(expectedNumber, 1);
|
|
44
44
|
});
|
|
@@ -15,7 +15,10 @@ export function validatePanelConstraints({
|
|
|
15
15
|
const warnings = [];
|
|
16
16
|
|
|
17
17
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
18
|
-
assert(
|
|
18
|
+
assert(
|
|
19
|
+
panelConstraints,
|
|
20
|
+
`No panel constraints found for index ${panelIndex}`
|
|
21
|
+
);
|
|
19
22
|
|
|
20
23
|
const {
|
|
21
24
|
collapsedSize = 0,
|
|
@@ -37,7 +37,7 @@ export function validatePanelGroupLayout({
|
|
|
37
37
|
}
|
|
38
38
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
39
39
|
const unsafeSize = nextLayout[index];
|
|
40
|
-
assert(unsafeSize != null);
|
|
40
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
41
41
|
const safeSize = (100 / nextLayoutTotalSize) * unsafeSize;
|
|
42
42
|
nextLayout[index] = safeSize;
|
|
43
43
|
}
|
|
@@ -48,7 +48,7 @@ export function validatePanelGroupLayout({
|
|
|
48
48
|
// First pass: Validate the proposed layout given each panel's constraints
|
|
49
49
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
50
50
|
const unsafeSize = nextLayout[index];
|
|
51
|
-
assert(unsafeSize != null);
|
|
51
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
52
52
|
|
|
53
53
|
const safeSize = resizePanel({
|
|
54
54
|
panelConstraints,
|
|
@@ -68,7 +68,7 @@ export function validatePanelGroupLayout({
|
|
|
68
68
|
if (!fuzzyNumbersEqual(remainingSize, 0)) {
|
|
69
69
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
70
70
|
const prevSize = nextLayout[index];
|
|
71
|
-
assert(prevSize != null);
|
|
71
|
+
assert(prevSize != null, `No layout data found for index ${index}`);
|
|
72
72
|
const unsafeSize = prevSize + remainingSize;
|
|
73
73
|
const safeSize = resizePanel({
|
|
74
74
|
panelConstraints,
|
|
@@ -27,7 +27,10 @@ export function compare(a: HTMLElement, b: HTMLElement): number {
|
|
|
27
27
|
common_ancestor = a;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
assert(
|
|
30
|
+
assert(
|
|
31
|
+
common_ancestor,
|
|
32
|
+
"Stacking order can only be calculated for elements with a common ancestor"
|
|
33
|
+
);
|
|
31
34
|
|
|
32
35
|
const z_indexes = {
|
|
33
36
|
a: get_z_index(find_stacking_context(ancestors.a)),
|
|
@@ -99,7 +102,7 @@ function find_stacking_context(nodes: HTMLElement[]) {
|
|
|
99
102
|
|
|
100
103
|
while (i--) {
|
|
101
104
|
const node = nodes[i];
|
|
102
|
-
assert(node);
|
|
105
|
+
assert(node, "Missing node");
|
|
103
106
|
if (creates_stacking_context(node)) return node;
|
|
104
107
|
}
|
|
105
108
|
|