react-resizable-panels 0.0.58 → 0.0.59

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.
@@ -176,8 +176,6 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
176
176
  PanelWithForwardedRef.displayName = "Panel";
177
177
  Panel.displayName = "forwardRef(Panel)";
178
178
 
179
- const PRECISION = 10;
180
-
181
179
  function convertPixelsToPercentage(pixels, groupSizePixels) {
182
180
  return pixels / groupSizePixels * 100;
183
181
  }
@@ -255,6 +253,8 @@ function computePercentagePanelConstraints(panelConstraintsArray, panelIndex, gr
255
253
  };
256
254
  }
257
255
 
256
+ const PRECISION = 10;
257
+
258
258
  function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
259
259
  actual = parseFloat(actual.toFixed(fractionDigits));
260
260
  expected = parseFloat(expected.toFixed(fractionDigits));
@@ -728,15 +728,10 @@ function useWindowSplitterPanelGroupBehavior({
728
728
  }, [groupId, layout, panelDataArray]);
729
729
  useEffect(() => {
730
730
  const {
731
- direction,
732
731
  panelDataArray
733
732
  } = committedValuesRef.current;
734
733
  const groupElement = getPanelGroupElement(groupId);
735
734
  assert(groupElement != null, `No group found for id "${groupId}"`);
736
- const {
737
- height,
738
- width
739
- } = groupElement.getBoundingClientRect();
740
735
  const handles = getResizeHandleElementsForGroup(groupId);
741
736
  const cleanupFunctions = handles.map(handle => {
742
737
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
@@ -756,21 +751,19 @@ function useWindowSplitterPanelGroupBehavior({
756
751
  if (index >= 0) {
757
752
  const panelData = panelDataArray[index];
758
753
  const size = layout[index];
759
- if (size != null) {
760
- var _getPercentageSizeFro;
754
+ if (size != null && panelData.constraints.collapsible) {
755
+ var _getPercentageSizeFro, _getPercentageSizeFro2;
761
756
  const groupSizePixels = getAvailableGroupSizePixels(groupId);
762
- const minSize = (_getPercentageSizeFro = getPercentageSizeFromMixedSizes({
757
+ const collapsedSize = (_getPercentageSizeFro = getPercentageSizeFromMixedSizes({
758
+ sizePercentage: panelData.constraints.collapsedSizePercentage,
759
+ sizePixels: panelData.constraints.collapsedSizePixels
760
+ }, groupSizePixels)) !== null && _getPercentageSizeFro !== void 0 ? _getPercentageSizeFro : 0;
761
+ const minSize = (_getPercentageSizeFro2 = getPercentageSizeFromMixedSizes({
763
762
  sizePercentage: panelData.constraints.minSizePercentage,
764
763
  sizePixels: panelData.constraints.minSizePixels
765
- }, groupSizePixels)) !== null && _getPercentageSizeFro !== void 0 ? _getPercentageSizeFro : 0;
766
- let delta = 0;
767
- if (size.toPrecision(PRECISION) <= minSize.toPrecision(PRECISION)) {
768
- delta = direction === "horizontal" ? width : height;
769
- } else {
770
- delta = -(direction === "horizontal" ? width : height);
771
- }
764
+ }, groupSizePixels)) !== null && _getPercentageSizeFro2 !== void 0 ? _getPercentageSizeFro2 : 0;
772
765
  const nextLayout = adjustLayoutByDelta({
773
- delta,
766
+ delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
774
767
  groupSizePixels,
775
768
  layout,
776
769
  panelConstraints: panelDataArray.map(panelData => panelData.constraints),
@@ -1249,6 +1242,7 @@ function PanelGroupWithForwardedRef({
1249
1242
  const panelIdToLastNotifiedMixedSizesMapRef = useRef({});
1250
1243
  const panelSizeBeforeCollapseRef = useRef(new Map());
1251
1244
  const prevDeltaRef = useRef(0);
1245
+ const [imperativeApiQueue, setImperativeApiQueue] = useState([]);
1252
1246
  const committedValuesRef = useRef({
1253
1247
  direction,
1254
1248
  dragState,
@@ -1357,8 +1351,12 @@ function PanelGroupWithForwardedRef({
1357
1351
  }
1358
1352
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1359
1353
  if (groupSizePixels <= 0) {
1360
- // Wait until the group has rendered a non-zero size before computing layout.
1361
- return;
1354
+ if (shouldMonitorPixelBasedConstraints(panelDataArray.map(({
1355
+ constraints
1356
+ }) => constraints))) {
1357
+ // Wait until the group has rendered a non-zero size before computing layout.
1358
+ return;
1359
+ }
1362
1360
  }
1363
1361
  if (unsafeLayout == null) {
1364
1362
  unsafeLayout = calculateUnsafeDefaultLayout({
@@ -1436,6 +1434,17 @@ function PanelGroupWithForwardedRef({
1436
1434
  onLayout,
1437
1435
  panelDataArray
1438
1436
  } = committedValuesRef.current;
1437
+
1438
+ // See issues/211
1439
+ if (panelDataArray.find(({
1440
+ id
1441
+ }) => id === panelData.id) == null) {
1442
+ setImperativeApiQueue(prev => [...prev, {
1443
+ panelData,
1444
+ type: "collapse"
1445
+ }]);
1446
+ return;
1447
+ }
1439
1448
  if (panelData.constraints.collapsible) {
1440
1449
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1441
1450
  const {
@@ -1479,6 +1488,17 @@ function PanelGroupWithForwardedRef({
1479
1488
  onLayout,
1480
1489
  panelDataArray
1481
1490
  } = committedValuesRef.current;
1491
+
1492
+ // See issues/211
1493
+ if (panelDataArray.find(({
1494
+ id
1495
+ }) => id === panelData.id) == null) {
1496
+ setImperativeApiQueue(prev => [...prev, {
1497
+ panelData,
1498
+ type: "expand"
1499
+ }]);
1500
+ return;
1501
+ }
1482
1502
  if (panelData.constraints.collapsible) {
1483
1503
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1484
1504
  const {
@@ -1674,6 +1694,18 @@ function PanelGroupWithForwardedRef({
1674
1694
  onLayout,
1675
1695
  panelDataArray
1676
1696
  } = committedValuesRef.current;
1697
+
1698
+ // See issues/211
1699
+ if (panelDataArray.find(({
1700
+ id
1701
+ }) => id === panelData.id) == null) {
1702
+ setImperativeApiQueue(prev => [...prev, {
1703
+ panelData,
1704
+ mixedSizes,
1705
+ type: "resize"
1706
+ }]);
1707
+ return;
1708
+ }
1677
1709
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1678
1710
  const {
1679
1711
  groupSizePixels,
@@ -1731,6 +1763,31 @@ function PanelGroupWithForwardedRef({
1731
1763
  return panelDataArray;
1732
1764
  });
1733
1765
  }, []);
1766
+
1767
+ // Handle imperative API calls that were made before panels were registered
1768
+ useIsomorphicLayoutEffect(() => {
1769
+ const queue = imperativeApiQueue;
1770
+ while (queue.length > 0) {
1771
+ const current = queue.shift();
1772
+ switch (current.type) {
1773
+ case "collapse":
1774
+ {
1775
+ collapsePanel(current.panelData);
1776
+ break;
1777
+ }
1778
+ case "expand":
1779
+ {
1780
+ expandPanel(current.panelData);
1781
+ break;
1782
+ }
1783
+ case "resize":
1784
+ {
1785
+ resizePanel(current.panelData, current.mixedSizes);
1786
+ break;
1787
+ }
1788
+ }
1789
+ }
1790
+ }, [collapsePanel, expandPanel, imperativeApiQueue, layout, panelDataArray, resizePanel]);
1734
1791
  const context = useMemo(() => ({
1735
1792
  collapsePanel,
1736
1793
  direction,