react-resizable-panels 2.0.8 → 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 +9 -0
- package/dist/declarations/src/utils/assert.d.ts +1 -1
- package/dist/react-resizable-panels.browser.cjs.js +158 -53
- package/dist/react-resizable-panels.browser.development.cjs.js +160 -55
- package/dist/react-resizable-panels.browser.development.esm.js +159 -54
- package/dist/react-resizable-panels.browser.esm.js +157 -52
- package/dist/react-resizable-panels.cjs.js +158 -53
- package/dist/react-resizable-panels.development.cjs.js +160 -55
- package/dist/react-resizable-panels.development.esm.js +159 -54
- package/dist/react-resizable-panels.development.node.cjs.js +156 -51
- package/dist/react-resizable-panels.development.node.esm.js +155 -50
- package/dist/react-resizable-panels.esm.js +157 -52
- package/dist/react-resizable-panels.node.cjs.js +154 -49
- package/dist/react-resizable-panels.node.esm.js +153 -48
- package/package.json +1 -4
- 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/PanelResizeHandleRegistry.ts +2 -2
- 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 +133 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { compare } from 'stacking-order';
|
|
3
2
|
|
|
4
3
|
// This module exists to work around Webpack issue https://github.com/webpack/webpack/issues/14814
|
|
5
4
|
|
|
@@ -286,6 +285,114 @@ function intersects(rectOne, rectTwo, strict) {
|
|
|
286
285
|
}
|
|
287
286
|
}
|
|
288
287
|
|
|
288
|
+
// Forked from NPM stacking-order@2.0.0
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Determine which of two nodes appears in front of the other —
|
|
292
|
+
* if `a` is in front, returns 1, otherwise returns -1
|
|
293
|
+
* @param {HTMLElement} a
|
|
294
|
+
* @param {HTMLElement} b
|
|
295
|
+
*/
|
|
296
|
+
function compare(a, b) {
|
|
297
|
+
if (a === b) throw new Error("Cannot compare node with itself");
|
|
298
|
+
const ancestors = {
|
|
299
|
+
a: get_ancestors(a),
|
|
300
|
+
b: get_ancestors(b)
|
|
301
|
+
};
|
|
302
|
+
let common_ancestor;
|
|
303
|
+
|
|
304
|
+
// remove shared ancestors
|
|
305
|
+
while (ancestors.a.at(-1) === ancestors.b.at(-1)) {
|
|
306
|
+
a = ancestors.a.pop();
|
|
307
|
+
b = ancestors.b.pop();
|
|
308
|
+
common_ancestor = a;
|
|
309
|
+
}
|
|
310
|
+
assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
|
|
311
|
+
const z_indexes = {
|
|
312
|
+
a: get_z_index(find_stacking_context(ancestors.a)),
|
|
313
|
+
b: get_z_index(find_stacking_context(ancestors.b))
|
|
314
|
+
};
|
|
315
|
+
if (z_indexes.a === z_indexes.b) {
|
|
316
|
+
const children = common_ancestor.childNodes;
|
|
317
|
+
const furthest_ancestors = {
|
|
318
|
+
a: ancestors.a.at(-1),
|
|
319
|
+
b: ancestors.b.at(-1)
|
|
320
|
+
};
|
|
321
|
+
let i = children.length;
|
|
322
|
+
while (i--) {
|
|
323
|
+
const child = children[i];
|
|
324
|
+
if (child === furthest_ancestors.a) return 1;
|
|
325
|
+
if (child === furthest_ancestors.b) return -1;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return Math.sign(z_indexes.a - z_indexes.b);
|
|
329
|
+
}
|
|
330
|
+
const props = /\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;
|
|
331
|
+
|
|
332
|
+
/** @param {HTMLElement} node */
|
|
333
|
+
function is_flex_item(node) {
|
|
334
|
+
const display = getComputedStyle(get_parent(node)).display;
|
|
335
|
+
return display === "flex" || display === "inline-flex";
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** @param {HTMLElement} node */
|
|
339
|
+
function creates_stacking_context(node) {
|
|
340
|
+
const style = getComputedStyle(node);
|
|
341
|
+
|
|
342
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
|
|
343
|
+
if (style.position === "fixed") return true;
|
|
344
|
+
// Forked to fix upstream bug https://github.com/Rich-Harris/stacking-order/issues/3
|
|
345
|
+
// if (
|
|
346
|
+
// (style.zIndex !== "auto" && style.position !== "static") ||
|
|
347
|
+
// is_flex_item(node)
|
|
348
|
+
// )
|
|
349
|
+
if (style.zIndex !== "auto" && (style.position !== "static" || is_flex_item(node))) return true;
|
|
350
|
+
if (+style.opacity < 1) return true;
|
|
351
|
+
if ("transform" in style && style.transform !== "none") return true;
|
|
352
|
+
if ("webkitTransform" in style && style.webkitTransform !== "none") return true;
|
|
353
|
+
if ("mixBlendMode" in style && style.mixBlendMode !== "normal") return true;
|
|
354
|
+
if ("filter" in style && style.filter !== "none") return true;
|
|
355
|
+
if ("webkitFilter" in style && style.webkitFilter !== "none") return true;
|
|
356
|
+
if ("isolation" in style && style.isolation === "isolate") return true;
|
|
357
|
+
if (props.test(style.willChange)) return true;
|
|
358
|
+
// @ts-expect-error
|
|
359
|
+
if (style.webkitOverflowScrolling === "touch") return true;
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** @param {HTMLElement[]} nodes */
|
|
364
|
+
function find_stacking_context(nodes) {
|
|
365
|
+
let i = nodes.length;
|
|
366
|
+
while (i--) {
|
|
367
|
+
const node = nodes[i];
|
|
368
|
+
assert(node, "Missing node");
|
|
369
|
+
if (creates_stacking_context(node)) return node;
|
|
370
|
+
}
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** @param {HTMLElement} node */
|
|
375
|
+
function get_z_index(node) {
|
|
376
|
+
return node && Number(getComputedStyle(node).zIndex) || 0;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** @param {HTMLElement} node */
|
|
380
|
+
function get_ancestors(node) {
|
|
381
|
+
const ancestors = [];
|
|
382
|
+
while (node) {
|
|
383
|
+
ancestors.push(node);
|
|
384
|
+
node = get_parent(node);
|
|
385
|
+
}
|
|
386
|
+
return ancestors; // [ node, ... <body>, <html>, document ]
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** @param {HTMLElement} node */
|
|
390
|
+
function get_parent(node) {
|
|
391
|
+
var _node$parentNode;
|
|
392
|
+
// @ts-ignore
|
|
393
|
+
return ((_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.host) || node.parentNode;
|
|
394
|
+
}
|
|
395
|
+
|
|
289
396
|
const EXCEEDED_HORIZONTAL_MIN = 0b0001;
|
|
290
397
|
const EXCEEDED_HORIZONTAL_MAX = 0b0010;
|
|
291
398
|
const EXCEEDED_VERTICAL_MIN = 0b0100;
|
|
@@ -498,7 +605,7 @@ function updateListeners() {
|
|
|
498
605
|
window.removeEventListener("mouseup", handlePointerUp);
|
|
499
606
|
window.removeEventListener("touchcancel", handlePointerUp);
|
|
500
607
|
window.removeEventListener("touchend", handlePointerUp);
|
|
501
|
-
if (
|
|
608
|
+
if (registeredResizeHandlers.size > 0) {
|
|
502
609
|
if (isPointerDown) {
|
|
503
610
|
if (intersectingHandles.length > 0) {
|
|
504
611
|
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
@@ -545,7 +652,7 @@ function updateResizeHandlerStates(action, event) {
|
|
|
545
652
|
});
|
|
546
653
|
}
|
|
547
654
|
|
|
548
|
-
function assert(expectedCondition, message
|
|
655
|
+
function assert(expectedCondition, message) {
|
|
549
656
|
if (!expectedCondition) {
|
|
550
657
|
console.error(message);
|
|
551
658
|
throw Error(message);
|
|
@@ -576,7 +683,7 @@ function resizePanel({
|
|
|
576
683
|
size
|
|
577
684
|
}) {
|
|
578
685
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
579
|
-
assert(panelConstraints != null);
|
|
686
|
+
assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
|
|
580
687
|
let {
|
|
581
688
|
collapsedSize = 0,
|
|
582
689
|
collapsible,
|
|
@@ -614,8 +721,8 @@ function adjustLayoutByDelta({
|
|
|
614
721
|
}
|
|
615
722
|
const nextLayout = [...prevLayout];
|
|
616
723
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
617
|
-
assert(firstPivotIndex != null);
|
|
618
|
-
assert(secondPivotIndex != null);
|
|
724
|
+
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
725
|
+
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
619
726
|
let deltaApplied = 0;
|
|
620
727
|
|
|
621
728
|
//const DEBUG = [];
|
|
@@ -641,19 +748,18 @@ function adjustLayoutByDelta({
|
|
|
641
748
|
// Check if we should expand a collapsed panel
|
|
642
749
|
const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
643
750
|
const panelConstraints = panelConstraintsArray[index];
|
|
644
|
-
assert(panelConstraints);
|
|
751
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
752
|
+
const {
|
|
753
|
+
collapsedSize = 0,
|
|
754
|
+
collapsible,
|
|
755
|
+
minSize = 0
|
|
756
|
+
} = panelConstraints;
|
|
645
757
|
|
|
646
758
|
//DEBUG.push(`edge case check 1: ${index}`);
|
|
647
759
|
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
648
|
-
if (
|
|
760
|
+
if (collapsible) {
|
|
649
761
|
const prevSize = prevLayout[index];
|
|
650
|
-
assert(prevSize != null);
|
|
651
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
652
|
-
assert(panelConstraints);
|
|
653
|
-
const {
|
|
654
|
-
collapsedSize = 0,
|
|
655
|
-
minSize = 0
|
|
656
|
-
} = panelConstraints;
|
|
762
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
657
763
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
658
764
|
const localDelta = minSize - prevSize;
|
|
659
765
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -670,22 +776,18 @@ function adjustLayoutByDelta({
|
|
|
670
776
|
// Check if we should collapse a panel at its minimum size
|
|
671
777
|
const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
672
778
|
const panelConstraints = panelConstraintsArray[index];
|
|
673
|
-
assert(panelConstraints);
|
|
779
|
+
assert(panelConstraints, `No panel constraints found for index ${index}`);
|
|
674
780
|
const {
|
|
675
|
-
|
|
781
|
+
collapsedSize = 0,
|
|
782
|
+
collapsible,
|
|
783
|
+
minSize = 0
|
|
676
784
|
} = panelConstraints;
|
|
677
785
|
|
|
678
786
|
//DEBUG.push(`edge case check 2: ${index}`);
|
|
679
787
|
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
680
788
|
if (collapsible) {
|
|
681
789
|
const prevSize = prevLayout[index];
|
|
682
|
-
assert(prevSize != null);
|
|
683
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
684
|
-
assert(panelConstraints);
|
|
685
|
-
const {
|
|
686
|
-
collapsedSize = 0,
|
|
687
|
-
minSize = 0
|
|
688
|
-
} = panelConstraints;
|
|
790
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
689
791
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
690
792
|
const localDelta = prevSize - collapsedSize;
|
|
691
793
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -715,7 +817,7 @@ function adjustLayoutByDelta({
|
|
|
715
817
|
//DEBUG.push("pre calc...");
|
|
716
818
|
while (true) {
|
|
717
819
|
const prevSize = prevLayout[index];
|
|
718
|
-
assert(prevSize != null);
|
|
820
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
719
821
|
const maxSafeSize = resizePanel({
|
|
720
822
|
panelConstraints: panelConstraintsArray,
|
|
721
823
|
panelIndex: index,
|
|
@@ -746,7 +848,7 @@ function adjustLayoutByDelta({
|
|
|
746
848
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
747
849
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
748
850
|
const prevSize = prevLayout[index];
|
|
749
|
-
assert(prevSize != null);
|
|
851
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
750
852
|
const unsafeSize = prevSize - deltaRemaining;
|
|
751
853
|
const safeSize = resizePanel({
|
|
752
854
|
panelConstraints: panelConstraintsArray,
|
|
@@ -783,7 +885,7 @@ function adjustLayoutByDelta({
|
|
|
783
885
|
// Now distribute the applied delta to the panels in the other direction
|
|
784
886
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
785
887
|
const prevSize = prevLayout[pivotIndex];
|
|
786
|
-
assert(prevSize != null);
|
|
888
|
+
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
787
889
|
const unsafeSize = prevSize + deltaApplied;
|
|
788
890
|
const safeSize = resizePanel({
|
|
789
891
|
panelConstraints: panelConstraintsArray,
|
|
@@ -801,7 +903,7 @@ function adjustLayoutByDelta({
|
|
|
801
903
|
let index = pivotIndex;
|
|
802
904
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
803
905
|
const prevSize = nextLayout[index];
|
|
804
|
-
assert(prevSize != null);
|
|
906
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
805
907
|
const unsafeSize = prevSize + deltaRemaining;
|
|
806
908
|
const safeSize = resizePanel({
|
|
807
909
|
panelConstraints: panelConstraintsArray,
|
|
@@ -847,7 +949,7 @@ function calculateAriaValues({
|
|
|
847
949
|
let totalMinSize = 0;
|
|
848
950
|
let totalMaxSize = 0;
|
|
849
951
|
const firstIndex = pivotIndices[0];
|
|
850
|
-
assert(firstIndex != null);
|
|
952
|
+
assert(firstIndex != null, "No pivot index found");
|
|
851
953
|
|
|
852
954
|
// A panel's effective min/max sizes also need to account for other panel's sizes.
|
|
853
955
|
panelsArray.forEach((panelData, index) => {
|
|
@@ -966,7 +1068,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
966
1068
|
}
|
|
967
1069
|
} else {
|
|
968
1070
|
const panelData = panelDataArray[index];
|
|
969
|
-
assert(panelData);
|
|
1071
|
+
assert(panelData, `No panel data found for index "${index}"`);
|
|
970
1072
|
resizeHandleElement.setAttribute("aria-controls", panelData.id);
|
|
971
1073
|
resizeHandleElement.setAttribute("aria-valuemax", "" + Math.round(valueMax));
|
|
972
1074
|
resizeHandleElement.setAttribute("aria-valuemin", "" + Math.round(valueMin));
|
|
@@ -987,17 +1089,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
987
1089
|
return;
|
|
988
1090
|
}
|
|
989
1091
|
const eagerValues = eagerValuesRef.current;
|
|
990
|
-
assert(eagerValues);
|
|
1092
|
+
assert(eagerValues, `Eager values not found`);
|
|
991
1093
|
const {
|
|
992
1094
|
panelDataArray
|
|
993
1095
|
} = eagerValues;
|
|
994
1096
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
995
1097
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
996
1098
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
997
|
-
assert(handles);
|
|
1099
|
+
assert(handles, `No resize handles found for group id "${groupId}"`);
|
|
998
1100
|
const cleanupFunctions = handles.map(handle => {
|
|
999
1101
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
1000
|
-
assert(handleId);
|
|
1102
|
+
assert(handleId, `Resize handle element has no handle id attribute`);
|
|
1001
1103
|
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
1002
1104
|
if (idBefore == null || idAfter == null) {
|
|
1003
1105
|
return () => {};
|
|
@@ -1013,7 +1115,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1013
1115
|
const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
|
|
1014
1116
|
if (index >= 0) {
|
|
1015
1117
|
const panelData = panelDataArray[index];
|
|
1016
|
-
assert(panelData);
|
|
1118
|
+
assert(panelData, `No panel data found for index ${index}`);
|
|
1017
1119
|
const size = layout[index];
|
|
1018
1120
|
const {
|
|
1019
1121
|
collapsedSize = 0,
|
|
@@ -1072,15 +1174,15 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
1072
1174
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
1073
1175
|
const isHorizontal = direction === "horizontal";
|
|
1074
1176
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
1075
|
-
assert(handleElement);
|
|
1177
|
+
assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
|
|
1076
1178
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1077
|
-
assert(groupId);
|
|
1179
|
+
assert(groupId, `Resize handle element has no group id attribute`);
|
|
1078
1180
|
let {
|
|
1079
1181
|
initialCursorPosition
|
|
1080
1182
|
} = initialDragState;
|
|
1081
1183
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1082
1184
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
1083
|
-
assert(groupElement);
|
|
1185
|
+
assert(groupElement, `No group element found for id "${groupId}"`);
|
|
1084
1186
|
const groupRect = groupElement.getBoundingClientRect();
|
|
1085
1187
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
1086
1188
|
const offsetPixels = cursorPosition - initialCursorPosition;
|
|
@@ -1141,7 +1243,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1141
1243
|
// Distribute default sizes first
|
|
1142
1244
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
1143
1245
|
const panelConstraints = panelConstraintsArray[index];
|
|
1144
|
-
assert(panelConstraints);
|
|
1246
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
1145
1247
|
const {
|
|
1146
1248
|
defaultSize
|
|
1147
1249
|
} = panelConstraints;
|
|
@@ -1155,7 +1257,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1155
1257
|
// Remaining size should be distributed evenly between panels without default sizes
|
|
1156
1258
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
1157
1259
|
const panelConstraints = panelConstraintsArray[index];
|
|
1158
|
-
assert(panelConstraints);
|
|
1260
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
1159
1261
|
const {
|
|
1160
1262
|
defaultSize
|
|
1161
1263
|
} = panelConstraints;
|
|
@@ -1175,7 +1277,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1175
1277
|
function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
1176
1278
|
layout.forEach((size, index) => {
|
|
1177
1279
|
const panelData = panelsArray[index];
|
|
1178
|
-
assert(panelData);
|
|
1280
|
+
assert(panelData, `Panel data not found for index ${index}`);
|
|
1179
1281
|
const {
|
|
1180
1282
|
callbacks,
|
|
1181
1283
|
constraints,
|
|
@@ -1359,7 +1461,7 @@ function validatePanelConstraints({
|
|
|
1359
1461
|
{
|
|
1360
1462
|
const warnings = [];
|
|
1361
1463
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1362
|
-
assert(panelConstraints);
|
|
1464
|
+
assert(panelConstraints, `No panel constraints found for index ${panelIndex}`);
|
|
1363
1465
|
const {
|
|
1364
1466
|
collapsedSize = 0,
|
|
1365
1467
|
collapsible = false,
|
|
@@ -1413,7 +1515,7 @@ function validatePanelGroupLayout({
|
|
|
1413
1515
|
}
|
|
1414
1516
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1415
1517
|
const unsafeSize = nextLayout[index];
|
|
1416
|
-
assert(unsafeSize != null);
|
|
1518
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1417
1519
|
const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
|
|
1418
1520
|
nextLayout[index] = safeSize;
|
|
1419
1521
|
}
|
|
@@ -1423,7 +1525,7 @@ function validatePanelGroupLayout({
|
|
|
1423
1525
|
// First pass: Validate the proposed layout given each panel's constraints
|
|
1424
1526
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1425
1527
|
const unsafeSize = nextLayout[index];
|
|
1426
|
-
assert(unsafeSize != null);
|
|
1528
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1427
1529
|
const safeSize = resizePanel({
|
|
1428
1530
|
panelConstraints,
|
|
1429
1531
|
panelIndex: index,
|
|
@@ -1440,7 +1542,7 @@ function validatePanelGroupLayout({
|
|
|
1440
1542
|
if (!fuzzyNumbersEqual(remainingSize, 0)) {
|
|
1441
1543
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1442
1544
|
const prevSize = nextLayout[index];
|
|
1443
|
-
assert(prevSize != null);
|
|
1545
|
+
assert(prevSize != null, `No layout data found for index ${index}`);
|
|
1444
1546
|
const unsafeSize = prevSize + remainingSize;
|
|
1445
1547
|
const safeSize = resizePanel({
|
|
1446
1548
|
panelConstraints,
|
|
@@ -1617,7 +1719,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1617
1719
|
const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
|
|
1618
1720
|
for (let panelIndex = 0; panelIndex < panelConstraints.length; panelIndex++) {
|
|
1619
1721
|
const panelData = panelDataArray[panelIndex];
|
|
1620
|
-
assert(panelData);
|
|
1722
|
+
assert(panelData, `Panel data not found for index ${panelIndex}`);
|
|
1621
1723
|
const isValid = validatePanelConstraints({
|
|
1622
1724
|
panelConstraints,
|
|
1623
1725
|
panelId: panelData.id,
|
|
@@ -1648,7 +1750,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1648
1750
|
panelSize,
|
|
1649
1751
|
pivotIndices
|
|
1650
1752
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1651
|
-
assert(panelSize != null);
|
|
1753
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1652
1754
|
if (panelSize !== collapsedSize) {
|
|
1653
1755
|
// Store size before collapse;
|
|
1654
1756
|
// This is the size that gets restored if the expand() API is used.
|
|
@@ -1725,7 +1827,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1725
1827
|
const {
|
|
1726
1828
|
panelSize
|
|
1727
1829
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1728
|
-
assert(panelSize != null);
|
|
1830
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1729
1831
|
return panelSize;
|
|
1730
1832
|
}, []);
|
|
1731
1833
|
|
|
@@ -1769,7 +1871,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1769
1871
|
collapsible,
|
|
1770
1872
|
panelSize
|
|
1771
1873
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1772
|
-
assert(panelSize != null);
|
|
1874
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1773
1875
|
return !collapsible || panelSize > collapsedSize;
|
|
1774
1876
|
}, []);
|
|
1775
1877
|
const registerPanel = useCallback(panelData => {
|
|
@@ -1936,7 +2038,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1936
2038
|
panelSize,
|
|
1937
2039
|
pivotIndices
|
|
1938
2040
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1939
|
-
assert(panelSize != null);
|
|
2041
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1940
2042
|
const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1941
2043
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1942
2044
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1973,7 +2075,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1973
2075
|
const {
|
|
1974
2076
|
panelSize: prevPanelSize
|
|
1975
2077
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1976
|
-
|
|
2078
|
+
if (prevPanelSize == null) {
|
|
2079
|
+
// It's possible that the panels in this group have changed since the last render
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
1977
2082
|
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1978
2083
|
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1979
2084
|
resizePanel(panelData, nextCollapsedSize);
|
|
@@ -1995,7 +2100,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1995
2100
|
return;
|
|
1996
2101
|
}
|
|
1997
2102
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1998
|
-
assert(handleElement);
|
|
2103
|
+
assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
|
|
1999
2104
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
2000
2105
|
setDragState({
|
|
2001
2106
|
dragHandleId,
|
|
@@ -2124,10 +2229,10 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
2124
2229
|
{
|
|
2125
2230
|
event.preventDefault();
|
|
2126
2231
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
2127
|
-
assert(groupId);
|
|
2232
|
+
assert(groupId, `No group element found for id "${groupId}"`);
|
|
2128
2233
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
2129
2234
|
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
2130
|
-
assert(index !== null);
|
|
2235
|
+
assert(index !== null, `No resize element found for id "${handleId}"`);
|
|
2131
2236
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
2132
2237
|
const nextHandle = handles[nextIndex];
|
|
2133
2238
|
nextHandle.focus();
|
|
@@ -2199,7 +2304,7 @@ function PanelResizeHandle({
|
|
|
2199
2304
|
return;
|
|
2200
2305
|
}
|
|
2201
2306
|
const element = elementRef.current;
|
|
2202
|
-
assert(element);
|
|
2307
|
+
assert(element, "Element ref not attached");
|
|
2203
2308
|
const setResizeHandlerState = (action, isActive, event) => {
|
|
2204
2309
|
if (isActive) {
|
|
2205
2310
|
switch (action) {
|