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
|
|
|
@@ -280,6 +279,114 @@ function intersects(rectOne, rectTwo, strict) {
|
|
|
280
279
|
}
|
|
281
280
|
}
|
|
282
281
|
|
|
282
|
+
// Forked from NPM stacking-order@2.0.0
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Determine which of two nodes appears in front of the other —
|
|
286
|
+
* if `a` is in front, returns 1, otherwise returns -1
|
|
287
|
+
* @param {HTMLElement} a
|
|
288
|
+
* @param {HTMLElement} b
|
|
289
|
+
*/
|
|
290
|
+
function compare(a, b) {
|
|
291
|
+
if (a === b) throw new Error("Cannot compare node with itself");
|
|
292
|
+
const ancestors = {
|
|
293
|
+
a: get_ancestors(a),
|
|
294
|
+
b: get_ancestors(b)
|
|
295
|
+
};
|
|
296
|
+
let common_ancestor;
|
|
297
|
+
|
|
298
|
+
// remove shared ancestors
|
|
299
|
+
while (ancestors.a.at(-1) === ancestors.b.at(-1)) {
|
|
300
|
+
a = ancestors.a.pop();
|
|
301
|
+
b = ancestors.b.pop();
|
|
302
|
+
common_ancestor = a;
|
|
303
|
+
}
|
|
304
|
+
assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
|
|
305
|
+
const z_indexes = {
|
|
306
|
+
a: get_z_index(find_stacking_context(ancestors.a)),
|
|
307
|
+
b: get_z_index(find_stacking_context(ancestors.b))
|
|
308
|
+
};
|
|
309
|
+
if (z_indexes.a === z_indexes.b) {
|
|
310
|
+
const children = common_ancestor.childNodes;
|
|
311
|
+
const furthest_ancestors = {
|
|
312
|
+
a: ancestors.a.at(-1),
|
|
313
|
+
b: ancestors.b.at(-1)
|
|
314
|
+
};
|
|
315
|
+
let i = children.length;
|
|
316
|
+
while (i--) {
|
|
317
|
+
const child = children[i];
|
|
318
|
+
if (child === furthest_ancestors.a) return 1;
|
|
319
|
+
if (child === furthest_ancestors.b) return -1;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return Math.sign(z_indexes.a - z_indexes.b);
|
|
323
|
+
}
|
|
324
|
+
const props = /\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;
|
|
325
|
+
|
|
326
|
+
/** @param {HTMLElement} node */
|
|
327
|
+
function is_flex_item(node) {
|
|
328
|
+
const display = getComputedStyle(get_parent(node)).display;
|
|
329
|
+
return display === "flex" || display === "inline-flex";
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** @param {HTMLElement} node */
|
|
333
|
+
function creates_stacking_context(node) {
|
|
334
|
+
const style = getComputedStyle(node);
|
|
335
|
+
|
|
336
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
|
|
337
|
+
if (style.position === "fixed") return true;
|
|
338
|
+
// Forked to fix upstream bug https://github.com/Rich-Harris/stacking-order/issues/3
|
|
339
|
+
// if (
|
|
340
|
+
// (style.zIndex !== "auto" && style.position !== "static") ||
|
|
341
|
+
// is_flex_item(node)
|
|
342
|
+
// )
|
|
343
|
+
if (style.zIndex !== "auto" && (style.position !== "static" || is_flex_item(node))) return true;
|
|
344
|
+
if (+style.opacity < 1) return true;
|
|
345
|
+
if ("transform" in style && style.transform !== "none") return true;
|
|
346
|
+
if ("webkitTransform" in style && style.webkitTransform !== "none") return true;
|
|
347
|
+
if ("mixBlendMode" in style && style.mixBlendMode !== "normal") return true;
|
|
348
|
+
if ("filter" in style && style.filter !== "none") return true;
|
|
349
|
+
if ("webkitFilter" in style && style.webkitFilter !== "none") return true;
|
|
350
|
+
if ("isolation" in style && style.isolation === "isolate") return true;
|
|
351
|
+
if (props.test(style.willChange)) return true;
|
|
352
|
+
// @ts-expect-error
|
|
353
|
+
if (style.webkitOverflowScrolling === "touch") return true;
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** @param {HTMLElement[]} nodes */
|
|
358
|
+
function find_stacking_context(nodes) {
|
|
359
|
+
let i = nodes.length;
|
|
360
|
+
while (i--) {
|
|
361
|
+
const node = nodes[i];
|
|
362
|
+
assert(node, "Missing node");
|
|
363
|
+
if (creates_stacking_context(node)) return node;
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** @param {HTMLElement} node */
|
|
369
|
+
function get_z_index(node) {
|
|
370
|
+
return node && Number(getComputedStyle(node).zIndex) || 0;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** @param {HTMLElement} node */
|
|
374
|
+
function get_ancestors(node) {
|
|
375
|
+
const ancestors = [];
|
|
376
|
+
while (node) {
|
|
377
|
+
ancestors.push(node);
|
|
378
|
+
node = get_parent(node);
|
|
379
|
+
}
|
|
380
|
+
return ancestors; // [ node, ... <body>, <html>, document ]
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** @param {HTMLElement} node */
|
|
384
|
+
function get_parent(node) {
|
|
385
|
+
var _node$parentNode;
|
|
386
|
+
// @ts-ignore
|
|
387
|
+
return ((_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.host) || node.parentNode;
|
|
388
|
+
}
|
|
389
|
+
|
|
283
390
|
const EXCEEDED_HORIZONTAL_MIN = 0b0001;
|
|
284
391
|
const EXCEEDED_HORIZONTAL_MAX = 0b0010;
|
|
285
392
|
const EXCEEDED_VERTICAL_MIN = 0b0100;
|
|
@@ -492,7 +599,7 @@ function updateListeners() {
|
|
|
492
599
|
window.removeEventListener("mouseup", handlePointerUp);
|
|
493
600
|
window.removeEventListener("touchcancel", handlePointerUp);
|
|
494
601
|
window.removeEventListener("touchend", handlePointerUp);
|
|
495
|
-
if (
|
|
602
|
+
if (registeredResizeHandlers.size > 0) {
|
|
496
603
|
if (isPointerDown) {
|
|
497
604
|
if (intersectingHandles.length > 0) {
|
|
498
605
|
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
@@ -539,7 +646,7 @@ function updateResizeHandlerStates(action, event) {
|
|
|
539
646
|
});
|
|
540
647
|
}
|
|
541
648
|
|
|
542
|
-
function assert(expectedCondition, message
|
|
649
|
+
function assert(expectedCondition, message) {
|
|
543
650
|
if (!expectedCondition) {
|
|
544
651
|
console.error(message);
|
|
545
652
|
throw Error(message);
|
|
@@ -570,7 +677,7 @@ function resizePanel({
|
|
|
570
677
|
size
|
|
571
678
|
}) {
|
|
572
679
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
573
|
-
assert(panelConstraints != null);
|
|
680
|
+
assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
|
|
574
681
|
let {
|
|
575
682
|
collapsedSize = 0,
|
|
576
683
|
collapsible,
|
|
@@ -608,8 +715,8 @@ function adjustLayoutByDelta({
|
|
|
608
715
|
}
|
|
609
716
|
const nextLayout = [...prevLayout];
|
|
610
717
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
611
|
-
assert(firstPivotIndex != null);
|
|
612
|
-
assert(secondPivotIndex != null);
|
|
718
|
+
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
719
|
+
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
613
720
|
let deltaApplied = 0;
|
|
614
721
|
|
|
615
722
|
//const DEBUG = [];
|
|
@@ -635,19 +742,18 @@ function adjustLayoutByDelta({
|
|
|
635
742
|
// Check if we should expand a collapsed panel
|
|
636
743
|
const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
637
744
|
const panelConstraints = panelConstraintsArray[index];
|
|
638
|
-
assert(panelConstraints);
|
|
745
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
746
|
+
const {
|
|
747
|
+
collapsedSize = 0,
|
|
748
|
+
collapsible,
|
|
749
|
+
minSize = 0
|
|
750
|
+
} = panelConstraints;
|
|
639
751
|
|
|
640
752
|
//DEBUG.push(`edge case check 1: ${index}`);
|
|
641
753
|
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
642
|
-
if (
|
|
754
|
+
if (collapsible) {
|
|
643
755
|
const prevSize = prevLayout[index];
|
|
644
|
-
assert(prevSize != null);
|
|
645
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
646
|
-
assert(panelConstraints);
|
|
647
|
-
const {
|
|
648
|
-
collapsedSize = 0,
|
|
649
|
-
minSize = 0
|
|
650
|
-
} = panelConstraints;
|
|
756
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
651
757
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
652
758
|
const localDelta = minSize - prevSize;
|
|
653
759
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -664,22 +770,18 @@ function adjustLayoutByDelta({
|
|
|
664
770
|
// Check if we should collapse a panel at its minimum size
|
|
665
771
|
const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
666
772
|
const panelConstraints = panelConstraintsArray[index];
|
|
667
|
-
assert(panelConstraints);
|
|
773
|
+
assert(panelConstraints, `No panel constraints found for index ${index}`);
|
|
668
774
|
const {
|
|
669
|
-
|
|
775
|
+
collapsedSize = 0,
|
|
776
|
+
collapsible,
|
|
777
|
+
minSize = 0
|
|
670
778
|
} = panelConstraints;
|
|
671
779
|
|
|
672
780
|
//DEBUG.push(`edge case check 2: ${index}`);
|
|
673
781
|
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
674
782
|
if (collapsible) {
|
|
675
783
|
const prevSize = prevLayout[index];
|
|
676
|
-
assert(prevSize != null);
|
|
677
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
678
|
-
assert(panelConstraints);
|
|
679
|
-
const {
|
|
680
|
-
collapsedSize = 0,
|
|
681
|
-
minSize = 0
|
|
682
|
-
} = panelConstraints;
|
|
784
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
683
785
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
684
786
|
const localDelta = prevSize - collapsedSize;
|
|
685
787
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -709,7 +811,7 @@ function adjustLayoutByDelta({
|
|
|
709
811
|
//DEBUG.push("pre calc...");
|
|
710
812
|
while (true) {
|
|
711
813
|
const prevSize = prevLayout[index];
|
|
712
|
-
assert(prevSize != null);
|
|
814
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
713
815
|
const maxSafeSize = resizePanel({
|
|
714
816
|
panelConstraints: panelConstraintsArray,
|
|
715
817
|
panelIndex: index,
|
|
@@ -740,7 +842,7 @@ function adjustLayoutByDelta({
|
|
|
740
842
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
741
843
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
742
844
|
const prevSize = prevLayout[index];
|
|
743
|
-
assert(prevSize != null);
|
|
845
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
744
846
|
const unsafeSize = prevSize - deltaRemaining;
|
|
745
847
|
const safeSize = resizePanel({
|
|
746
848
|
panelConstraints: panelConstraintsArray,
|
|
@@ -777,7 +879,7 @@ function adjustLayoutByDelta({
|
|
|
777
879
|
// Now distribute the applied delta to the panels in the other direction
|
|
778
880
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
779
881
|
const prevSize = prevLayout[pivotIndex];
|
|
780
|
-
assert(prevSize != null);
|
|
882
|
+
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
781
883
|
const unsafeSize = prevSize + deltaApplied;
|
|
782
884
|
const safeSize = resizePanel({
|
|
783
885
|
panelConstraints: panelConstraintsArray,
|
|
@@ -795,7 +897,7 @@ function adjustLayoutByDelta({
|
|
|
795
897
|
let index = pivotIndex;
|
|
796
898
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
797
899
|
const prevSize = nextLayout[index];
|
|
798
|
-
assert(prevSize != null);
|
|
900
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
799
901
|
const unsafeSize = prevSize + deltaRemaining;
|
|
800
902
|
const safeSize = resizePanel({
|
|
801
903
|
panelConstraints: panelConstraintsArray,
|
|
@@ -841,7 +943,7 @@ function calculateAriaValues({
|
|
|
841
943
|
let totalMinSize = 0;
|
|
842
944
|
let totalMaxSize = 0;
|
|
843
945
|
const firstIndex = pivotIndices[0];
|
|
844
|
-
assert(firstIndex != null);
|
|
946
|
+
assert(firstIndex != null, "No pivot index found");
|
|
845
947
|
|
|
846
948
|
// A panel's effective min/max sizes also need to account for other panel's sizes.
|
|
847
949
|
panelsArray.forEach((panelData, index) => {
|
|
@@ -950,7 +1052,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
950
1052
|
const resizeHandleElement = resizeHandleElements[index];
|
|
951
1053
|
if (resizeHandleElement == null) ; else {
|
|
952
1054
|
const panelData = panelDataArray[index];
|
|
953
|
-
assert(panelData);
|
|
1055
|
+
assert(panelData, `No panel data found for index "${index}"`);
|
|
954
1056
|
resizeHandleElement.setAttribute("aria-controls", panelData.id);
|
|
955
1057
|
resizeHandleElement.setAttribute("aria-valuemax", "" + Math.round(valueMax));
|
|
956
1058
|
resizeHandleElement.setAttribute("aria-valuemin", "" + Math.round(valueMin));
|
|
@@ -971,17 +1073,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
971
1073
|
return;
|
|
972
1074
|
}
|
|
973
1075
|
const eagerValues = eagerValuesRef.current;
|
|
974
|
-
assert(eagerValues);
|
|
1076
|
+
assert(eagerValues, `Eager values not found`);
|
|
975
1077
|
const {
|
|
976
1078
|
panelDataArray
|
|
977
1079
|
} = eagerValues;
|
|
978
1080
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
979
1081
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
980
1082
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
981
|
-
assert(handles);
|
|
1083
|
+
assert(handles, `No resize handles found for group id "${groupId}"`);
|
|
982
1084
|
const cleanupFunctions = handles.map(handle => {
|
|
983
1085
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
984
|
-
assert(handleId);
|
|
1086
|
+
assert(handleId, `Resize handle element has no handle id attribute`);
|
|
985
1087
|
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
986
1088
|
if (idBefore == null || idAfter == null) {
|
|
987
1089
|
return () => {};
|
|
@@ -997,7 +1099,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
997
1099
|
const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
|
|
998
1100
|
if (index >= 0) {
|
|
999
1101
|
const panelData = panelDataArray[index];
|
|
1000
|
-
assert(panelData);
|
|
1102
|
+
assert(panelData, `No panel data found for index ${index}`);
|
|
1001
1103
|
const size = layout[index];
|
|
1002
1104
|
const {
|
|
1003
1105
|
collapsedSize = 0,
|
|
@@ -1056,15 +1158,15 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
1056
1158
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
1057
1159
|
const isHorizontal = direction === "horizontal";
|
|
1058
1160
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
1059
|
-
assert(handleElement);
|
|
1161
|
+
assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
|
|
1060
1162
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1061
|
-
assert(groupId);
|
|
1163
|
+
assert(groupId, `Resize handle element has no group id attribute`);
|
|
1062
1164
|
let {
|
|
1063
1165
|
initialCursorPosition
|
|
1064
1166
|
} = initialDragState;
|
|
1065
1167
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1066
1168
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
1067
|
-
assert(groupElement);
|
|
1169
|
+
assert(groupElement, `No group element found for id "${groupId}"`);
|
|
1068
1170
|
const groupRect = groupElement.getBoundingClientRect();
|
|
1069
1171
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
1070
1172
|
const offsetPixels = cursorPosition - initialCursorPosition;
|
|
@@ -1125,7 +1227,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1125
1227
|
// Distribute default sizes first
|
|
1126
1228
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
1127
1229
|
const panelConstraints = panelConstraintsArray[index];
|
|
1128
|
-
assert(panelConstraints);
|
|
1230
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
1129
1231
|
const {
|
|
1130
1232
|
defaultSize
|
|
1131
1233
|
} = panelConstraints;
|
|
@@ -1139,7 +1241,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1139
1241
|
// Remaining size should be distributed evenly between panels without default sizes
|
|
1140
1242
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
1141
1243
|
const panelConstraints = panelConstraintsArray[index];
|
|
1142
|
-
assert(panelConstraints);
|
|
1244
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
1143
1245
|
const {
|
|
1144
1246
|
defaultSize
|
|
1145
1247
|
} = panelConstraints;
|
|
@@ -1159,7 +1261,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1159
1261
|
function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
1160
1262
|
layout.forEach((size, index) => {
|
|
1161
1263
|
const panelData = panelsArray[index];
|
|
1162
|
-
assert(panelData);
|
|
1264
|
+
assert(panelData, `Panel data not found for index ${index}`);
|
|
1163
1265
|
const {
|
|
1164
1266
|
callbacks,
|
|
1165
1267
|
constraints,
|
|
@@ -1349,7 +1451,7 @@ function validatePanelGroupLayout({
|
|
|
1349
1451
|
} else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
|
|
1350
1452
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1351
1453
|
const unsafeSize = nextLayout[index];
|
|
1352
|
-
assert(unsafeSize != null);
|
|
1454
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1353
1455
|
const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
|
|
1354
1456
|
nextLayout[index] = safeSize;
|
|
1355
1457
|
}
|
|
@@ -1359,7 +1461,7 @@ function validatePanelGroupLayout({
|
|
|
1359
1461
|
// First pass: Validate the proposed layout given each panel's constraints
|
|
1360
1462
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1361
1463
|
const unsafeSize = nextLayout[index];
|
|
1362
|
-
assert(unsafeSize != null);
|
|
1464
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1363
1465
|
const safeSize = resizePanel({
|
|
1364
1466
|
panelConstraints,
|
|
1365
1467
|
panelIndex: index,
|
|
@@ -1376,7 +1478,7 @@ function validatePanelGroupLayout({
|
|
|
1376
1478
|
if (!fuzzyNumbersEqual(remainingSize, 0)) {
|
|
1377
1479
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1378
1480
|
const prevSize = nextLayout[index];
|
|
1379
|
-
assert(prevSize != null);
|
|
1481
|
+
assert(prevSize != null, `No layout data found for index ${index}`);
|
|
1380
1482
|
const unsafeSize = prevSize + remainingSize;
|
|
1381
1483
|
const safeSize = resizePanel({
|
|
1382
1484
|
panelConstraints,
|
|
@@ -1542,7 +1644,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1542
1644
|
panelSize,
|
|
1543
1645
|
pivotIndices
|
|
1544
1646
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1545
|
-
assert(panelSize != null);
|
|
1647
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1546
1648
|
if (panelSize !== collapsedSize) {
|
|
1547
1649
|
// Store size before collapse;
|
|
1548
1650
|
// This is the size that gets restored if the expand() API is used.
|
|
@@ -1619,7 +1721,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1619
1721
|
const {
|
|
1620
1722
|
panelSize
|
|
1621
1723
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1622
|
-
assert(panelSize != null);
|
|
1724
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1623
1725
|
return panelSize;
|
|
1624
1726
|
}, []);
|
|
1625
1727
|
|
|
@@ -1663,7 +1765,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1663
1765
|
collapsible,
|
|
1664
1766
|
panelSize
|
|
1665
1767
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1666
|
-
assert(panelSize != null);
|
|
1768
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1667
1769
|
return !collapsible || panelSize > collapsedSize;
|
|
1668
1770
|
}, []);
|
|
1669
1771
|
const registerPanel = useCallback(panelData => {
|
|
@@ -1830,7 +1932,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1830
1932
|
panelSize,
|
|
1831
1933
|
pivotIndices
|
|
1832
1934
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1833
|
-
assert(panelSize != null);
|
|
1935
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1834
1936
|
const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1835
1937
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1836
1938
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1867,7 +1969,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1867
1969
|
const {
|
|
1868
1970
|
panelSize: prevPanelSize
|
|
1869
1971
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1870
|
-
|
|
1972
|
+
if (prevPanelSize == null) {
|
|
1973
|
+
// It's possible that the panels in this group have changed since the last render
|
|
1974
|
+
return;
|
|
1975
|
+
}
|
|
1871
1976
|
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1872
1977
|
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1873
1978
|
resizePanel(panelData, nextCollapsedSize);
|
|
@@ -1889,7 +1994,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1889
1994
|
return;
|
|
1890
1995
|
}
|
|
1891
1996
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1892
|
-
assert(handleElement);
|
|
1997
|
+
assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
|
|
1893
1998
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1894
1999
|
setDragState({
|
|
1895
2000
|
dragHandleId,
|
|
@@ -2018,10 +2123,10 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
2018
2123
|
{
|
|
2019
2124
|
event.preventDefault();
|
|
2020
2125
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
2021
|
-
assert(groupId);
|
|
2126
|
+
assert(groupId, `No group element found for id "${groupId}"`);
|
|
2022
2127
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
2023
2128
|
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
2024
|
-
assert(index !== null);
|
|
2129
|
+
assert(index !== null, `No resize element found for id "${handleId}"`);
|
|
2025
2130
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
2026
2131
|
const nextHandle = handles[nextIndex];
|
|
2027
2132
|
nextHandle.focus();
|
|
@@ -2093,7 +2198,7 @@ function PanelResizeHandle({
|
|
|
2093
2198
|
return;
|
|
2094
2199
|
}
|
|
2095
2200
|
const element = elementRef.current;
|
|
2096
|
-
assert(element);
|
|
2201
|
+
assert(element, "Element ref not attached");
|
|
2097
2202
|
const setResizeHandlerState = (action, isActive, event) => {
|
|
2098
2203
|
if (isActive) {
|
|
2099
2204
|
switch (action) {
|