react-resizable-panels 0.0.56 → 0.0.57

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.
@@ -61,7 +61,7 @@ function useUniqueId(idFromParams = null) {
61
61
  if (idRef.current === null) {
62
62
  idRef.current = "" + counter++;
63
63
  }
64
- return idFromParams ?? idRef.current;
64
+ return idFromParams !== null && idFromParams !== void 0 ? idFromParams : idRef.current;
65
65
  }
66
66
 
67
67
  function PanelWithForwardedRef({
@@ -185,9 +185,9 @@ function PanelWithForwardedRef({
185
185
  },
186
186
  // CSS selectors
187
187
  "data-panel": "",
188
+ "data-panel-id": panelId,
188
189
  // e2e test attributes
189
190
  "data-panel-collapsible": undefined,
190
- "data-panel-id": undefined,
191
191
  "data-panel-size": undefined
192
192
  });
193
193
  }
@@ -215,6 +215,16 @@ function convertPixelConstraintsToPercentages(panelConstraints, groupSizePixels)
215
215
  minSizePercentage = 0,
216
216
  minSizePixels
217
217
  } = panelConstraints;
218
+ const hasPixelConstraints = collapsedSizePixels != null || defaultSizePixels != null || minSizePixels != null || maxSizePixels != null;
219
+ if (hasPixelConstraints && groupSizePixels <= 0) {
220
+ console.warn(`WARNING: Invalid group size: ${groupSizePixels}px`);
221
+ return {
222
+ collapsedSizePercentage: 0,
223
+ defaultSizePercentage,
224
+ maxSizePercentage: 0,
225
+ minSizePercentage: 0
226
+ };
227
+ }
218
228
  if (collapsedSizePixels != null) {
219
229
  collapsedSizePercentage = convertPixelsToPercentage(collapsedSizePixels, groupSizePixels);
220
230
  }
@@ -289,6 +299,16 @@ function resizePanel({
289
299
  panelIndex,
290
300
  size
291
301
  }) {
302
+ const hasPixelConstraints = panelConstraints.some(({
303
+ collapsedSizePixels,
304
+ defaultSizePixels,
305
+ minSizePixels,
306
+ maxSizePixels
307
+ }) => collapsedSizePixels != null || defaultSizePixels != null || minSizePixels != null || maxSizePixels != null);
308
+ if (hasPixelConstraints && groupSizePixels <= 0) {
309
+ console.warn(`WARNING: Invalid group size: ${groupSizePixels}px`);
310
+ return 0;
311
+ }
292
312
  let {
293
313
  collapsible
294
314
  } = panelConstraints[panelIndex];
@@ -345,7 +365,6 @@ function adjustLayoutByDelta({
345
365
  } = panelConstraints[pivotIndex];
346
366
  const {
347
367
  collapsedSizePercentage,
348
- maxSizePercentage,
349
368
  minSizePercentage
350
369
  } = computePercentagePanelConstraints(panelConstraints, pivotIndex, groupSizePixels);
351
370
  const isCollapsed = collapsible && fuzzyNumbersEqual(initialSize, collapsedSizePercentage);
@@ -507,6 +526,7 @@ function calculateAriaValues({
507
526
 
508
527
  // A panel's effective min/max sizes also need to account for other panel's sizes.
509
528
  panelsArray.forEach((panelData, index) => {
529
+ var _getPercentageSizeFro, _getPercentageSizeFro2;
510
530
  const {
511
531
  constraints
512
532
  } = panelData;
@@ -516,14 +536,14 @@ function calculateAriaValues({
516
536
  minSizePercentage,
517
537
  minSizePixels
518
538
  } = constraints;
519
- const minSize = getPercentageSizeFromMixedSizes({
539
+ const minSize = (_getPercentageSizeFro = getPercentageSizeFromMixedSizes({
520
540
  sizePercentage: minSizePercentage,
521
541
  sizePixels: minSizePixels
522
- }, groupSizePixels) ?? 0;
523
- const maxSize = getPercentageSizeFromMixedSizes({
542
+ }, groupSizePixels)) !== null && _getPercentageSizeFro !== void 0 ? _getPercentageSizeFro : 0;
543
+ const maxSize = (_getPercentageSizeFro2 = getPercentageSizeFromMixedSizes({
524
544
  sizePercentage: maxSizePercentage,
525
545
  sizePixels: maxSizePixels
526
- }, groupSizePixels) ?? 100;
546
+ }, groupSizePixels)) !== null && _getPercentageSizeFro2 !== void 0 ? _getPercentageSizeFro2 : 100;
527
547
  if (index === pivotIndices[0]) {
528
548
  currentMinSize = minSize;
529
549
  currentMaxSize = maxSize;
@@ -549,7 +569,7 @@ function getResizeHandleElementsForGroup(groupId) {
549
569
  function getResizeHandleElementIndex(groupId, id) {
550
570
  const handles = getResizeHandleElementsForGroup(groupId);
551
571
  const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
552
- return index ?? null;
572
+ return index !== null && index !== void 0 ? index : null;
553
573
  }
554
574
 
555
575
  function determinePivotIndices(groupId, dragHandleId) {
@@ -558,7 +578,7 @@ function determinePivotIndices(groupId, dragHandleId) {
558
578
  }
559
579
 
560
580
  function getPanelGroupElement(id) {
561
- const element = document.querySelector(`[data-panel-group-id="${id}"]`);
581
+ const element = document.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
562
582
  if (element) {
563
583
  return element;
564
584
  }
@@ -610,11 +630,12 @@ function getResizeHandleElement(id) {
610
630
  }
611
631
 
612
632
  function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
633
+ var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
613
634
  const handle = getResizeHandleElement(handleId);
614
635
  const handles = getResizeHandleElementsForGroup(groupId);
615
636
  const index = handle ? handles.indexOf(handle) : -1;
616
- const idBefore = panelsArray[index]?.id ?? null;
617
- const idAfter = panelsArray[index + 1]?.id ?? null;
637
+ const idBefore = (_panelsArray$index$id = (_panelsArray$index = panelsArray[index]) === null || _panelsArray$index === void 0 ? void 0 : _panelsArray$index.id) !== null && _panelsArray$index$id !== void 0 ? _panelsArray$index$id : null;
638
+ const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
618
639
  return [idBefore, idAfter];
619
640
  }
620
641
 
@@ -692,11 +713,12 @@ function useWindowSplitterPanelGroupBehavior({
692
713
  const panelData = panelDataArray[index];
693
714
  const size = layout[index];
694
715
  if (size != null) {
716
+ var _getPercentageSizeFro;
695
717
  const groupSizePixels = getAvailableGroupSizePixels(groupId);
696
- const minSize = getPercentageSizeFromMixedSizes({
718
+ const minSize = (_getPercentageSizeFro = getPercentageSizeFromMixedSizes({
697
719
  sizePercentage: panelData.constraints.minSizePercentage,
698
720
  sizePixels: panelData.constraints.minSizePixels
699
- }, groupSizePixels) ?? 0;
721
+ }, groupSizePixels)) !== null && _getPercentageSizeFro !== void 0 ? _getPercentageSizeFro : 0;
700
722
  let delta = 0;
701
723
  if (size.toPrecision(PRECISION) <= minSize.toPrecision(PRECISION)) {
702
724
  delta = direction === "horizontal" ? width : height;
@@ -901,10 +923,11 @@ function callPanelCallbacks(groupId, panelsArray, layout, panelIdToLastNotifiedM
901
923
  onResize(mixedSizes, lastNotifiedMixedSizes);
902
924
  }
903
925
  if (collapsible && (onCollapse || onExpand)) {
904
- const collapsedSize = getPercentageSizeFromMixedSizes({
926
+ var _getPercentageSizeFro;
927
+ const collapsedSize = (_getPercentageSizeFro = getPercentageSizeFromMixedSizes({
905
928
  sizePercentage: constraints.collapsedSizePercentage,
906
929
  sizePixels: constraints.collapsedSizePixels
907
- }, groupSizePixels) ?? 0;
930
+ }, groupSizePixels)) !== null && _getPercentageSizeFro !== void 0 ? _getPercentageSizeFro : 0;
908
931
  const size = getPercentageSizeFromMixedSizes(mixedSizes, groupSizePixels);
909
932
  if (onExpand && (lastNotifiedMixedSizes == null || lastNotifiedMixedSizes.sizePercentage === collapsedSize) && size !== collapsedSize) {
910
933
  onExpand();
@@ -1070,8 +1093,9 @@ function loadSerializedPanelGroupState(autoSaveId, storage) {
1070
1093
  function loadPanelLayout(autoSaveId, panels, storage) {
1071
1094
  const state = loadSerializedPanelGroupState(autoSaveId, storage);
1072
1095
  if (state) {
1096
+ var _state$key;
1073
1097
  const key = getSerializationKey(panels);
1074
- return state[key] ?? null;
1098
+ return (_state$key = state[key]) !== null && _state$key !== void 0 ? _state$key : null;
1075
1099
  }
1076
1100
  return null;
1077
1101
  }
@@ -1287,6 +1311,10 @@ function PanelGroupWithForwardedRef({
1287
1311
  unsafeLayout = loadPanelLayout(autoSaveId, panelDataArray, storage);
1288
1312
  }
1289
1313
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1314
+ if (groupSizePixels <= 0) {
1315
+ // Wait until the group has rendered a non-zero size before computing layout.
1316
+ return;
1317
+ }
1290
1318
  if (unsafeLayout == null) {
1291
1319
  unsafeLayout = calculateUnsafeDefaultLayout({
1292
1320
  groupSizePixels,
@@ -1530,7 +1558,7 @@ function PanelGroupWithForwardedRef({
1530
1558
  } = committedValuesRef.current;
1531
1559
  const {
1532
1560
  initialLayout
1533
- } = dragState ?? {};
1561
+ } = dragState !== null && dragState !== void 0 ? dragState : {};
1534
1562
  const pivotIndices = determinePivotIndices(groupId, dragHandleId);
1535
1563
  let delta = calculateDeltaPercentage(event, groupId, dragHandleId, direction, dragState, {
1536
1564
  percentage: keyboardResizeByPercentage,
@@ -1550,7 +1578,7 @@ function PanelGroupWithForwardedRef({
1550
1578
  const nextLayout = adjustLayoutByDelta({
1551
1579
  delta,
1552
1580
  groupSizePixels,
1553
- layout: initialLayout ?? prevLayout,
1581
+ layout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
1554
1582
  panelConstraints,
1555
1583
  pivotIndices,
1556
1584
  trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
@@ -1693,9 +1721,8 @@ function PanelGroupWithForwardedRef({
1693
1721
  },
1694
1722
  // CSS selectors
1695
1723
  "data-panel-group": "",
1696
- // e2e test attributes
1697
- "data-panel-group-direction": undefined,
1698
- "data-panel-group-id": undefined
1724
+ "data-panel-group-direction": direction,
1725
+ "data-panel-group-id": groupId
1699
1726
  }));
1700
1727
  }
1701
1728
  const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwardedRef, {
@@ -1807,7 +1834,7 @@ function PanelResizeHandle({
1807
1834
  stopDragging
1808
1835
  } = panelGroupContext;
1809
1836
  const resizeHandleId = useUniqueId(idFromProps);
1810
- const isDragging = dragState?.dragHandleId === resizeHandleId;
1837
+ const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
1811
1838
  const [isFocused, setIsFocused] = useState(false);
1812
1839
  const [resizeHandler, setResizeHandler] = useState(null);
1813
1840
  const stopDraggingAndBlur = useCallback(() => {
@@ -1871,13 +1898,6 @@ function PanelResizeHandle({
1871
1898
  return createElement(Type, {
1872
1899
  children,
1873
1900
  className: classNameFromProps,
1874
- // CSS selectors
1875
- "data-resize-handle": "",
1876
- "data-resize-handle-active": isDragging ? "pointer" : isFocused ? "keyboard" : undefined,
1877
- "data-panel-group-direction": direction,
1878
- "data-panel-group-id": groupId,
1879
- "data-panel-resize-handle-enabled": !disabled,
1880
- "data-panel-resize-handle-id": resizeHandleId,
1881
1901
  onBlur: () => setIsFocused(false),
1882
1902
  onFocus: () => setIsFocused(true),
1883
1903
  onMouseDown: event => {
@@ -1907,7 +1927,14 @@ function PanelResizeHandle({
1907
1927
  ...style,
1908
1928
  ...styleFromProps
1909
1929
  },
1910
- tabIndex: 0
1930
+ tabIndex: 0,
1931
+ // CSS selectors
1932
+ "data-panel-group-direction": direction,
1933
+ "data-panel-group-id": groupId,
1934
+ "data-resize-handle": "",
1935
+ "data-resize-handle-active": isDragging ? "pointer" : isFocused ? "keyboard" : undefined,
1936
+ "data-panel-resize-handle-enabled": !disabled,
1937
+ "data-panel-resize-handle-id": resizeHandleId
1911
1938
  });
1912
1939
  }
1913
1940
  PanelResizeHandle.displayName = "PanelResizeHandle";