react-resizable-panels 2.0.13 → 2.0.15
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 +8 -0
- package/dist/react-resizable-panels.browser.cjs.js +15 -14
- package/dist/react-resizable-panels.browser.development.cjs.js +15 -14
- package/dist/react-resizable-panels.browser.development.esm.js +15 -14
- package/dist/react-resizable-panels.browser.esm.js +15 -14
- package/dist/react-resizable-panels.cjs.js +15 -14
- package/dist/react-resizable-panels.development.cjs.js +15 -14
- package/dist/react-resizable-panels.development.esm.js +15 -14
- package/dist/react-resizable-panels.development.node.cjs.js +15 -14
- package/dist/react-resizable-panels.development.node.esm.js +15 -14
- package/dist/react-resizable-panels.esm.js +15 -14
- package/dist/react-resizable-panels.node.cjs.js +15 -14
- package/dist/react-resizable-panels.node.esm.js +15 -14
- package/package.json +9 -9
- package/src/Panel.test.tsx +153 -0
- package/src/PanelGroup.ts +16 -7
- package/src/utils/callPanelCallbacks.ts +7 -4
- package/src/utils/numbers/fuzzyCompareNumbers.ts +10 -6
- package/.parcel-cache/0e613961dce44a82 +0 -0
- package/.parcel-cache/13776de4870b0ae4.txt +0 -2
- package/.parcel-cache/35c20fb91e350b46 +0 -0
- package/.parcel-cache/data.mdb +0 -0
- package/.parcel-cache/lock.mdb +0 -0
- package/LICENSE +0 -21
|
@@ -662,15 +662,15 @@ function assert(expectedCondition, message) {
|
|
|
662
662
|
const PRECISION = 10;
|
|
663
663
|
|
|
664
664
|
function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
|
|
665
|
-
|
|
666
|
-
expected = parseFloat(expected.toFixed(fractionDigits));
|
|
667
|
-
const delta = actual - expected;
|
|
668
|
-
if (delta === 0) {
|
|
665
|
+
if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
|
|
669
666
|
return 0;
|
|
670
667
|
} else {
|
|
671
|
-
return
|
|
668
|
+
return actual > expected ? 1 : -1;
|
|
672
669
|
}
|
|
673
670
|
}
|
|
671
|
+
function fuzzyNumbersEqual$1(actual, expected, fractionDigits = PRECISION) {
|
|
672
|
+
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
673
|
+
}
|
|
674
674
|
|
|
675
675
|
function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
676
676
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
@@ -1201,10 +1201,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
|
1201
1201
|
onResize(size, lastNotifiedSize);
|
|
1202
1202
|
}
|
|
1203
1203
|
if (collapsible && (onCollapse || onExpand)) {
|
|
1204
|
-
if (onExpand && (lastNotifiedSize == null || lastNotifiedSize
|
|
1204
|
+
if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
|
|
1205
1205
|
onExpand();
|
|
1206
1206
|
}
|
|
1207
|
-
if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize
|
|
1207
|
+
if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
|
|
1208
1208
|
onCollapse();
|
|
1209
1209
|
}
|
|
1210
1210
|
}
|
|
@@ -1639,7 +1639,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1639
1639
|
pivotIndices
|
|
1640
1640
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1641
1641
|
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1642
|
-
if (panelSize
|
|
1642
|
+
if (!fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1643
1643
|
// Store size before collapse;
|
|
1644
1644
|
// This is the size that gets restored if the expand() API is used.
|
|
1645
1645
|
panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
|
|
@@ -1678,11 +1678,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1678
1678
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1679
1679
|
const {
|
|
1680
1680
|
collapsedSize = 0,
|
|
1681
|
-
panelSize,
|
|
1681
|
+
panelSize = 0,
|
|
1682
1682
|
minSize = 0,
|
|
1683
1683
|
pivotIndices
|
|
1684
1684
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1685
|
-
if (panelSize
|
|
1685
|
+
if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1686
1686
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1687
1687
|
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1688
1688
|
const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
|
|
@@ -1747,7 +1747,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1747
1747
|
collapsible,
|
|
1748
1748
|
panelSize
|
|
1749
1749
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1750
|
-
|
|
1750
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1751
|
+
return collapsible === true && fuzzyNumbersEqual$1(panelSize, collapsedSize);
|
|
1751
1752
|
}, []);
|
|
1752
1753
|
|
|
1753
1754
|
// External APIs are safe to memoize via committed values ref
|
|
@@ -1762,7 +1763,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1762
1763
|
panelSize
|
|
1763
1764
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1764
1765
|
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1765
|
-
return !collapsible || panelSize >
|
|
1766
|
+
return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
|
|
1766
1767
|
}, []);
|
|
1767
1768
|
const registerPanel = useCallback(panelData => {
|
|
1768
1769
|
const {
|
|
@@ -1915,8 +1916,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1915
1916
|
// It's possible that the panels in this group have changed since the last render
|
|
1916
1917
|
return;
|
|
1917
1918
|
}
|
|
1918
|
-
if (prevCollapsible && nextCollapsible && prevPanelSize
|
|
1919
|
-
if (prevCollapsedSize
|
|
1919
|
+
if (prevCollapsible && nextCollapsible && fuzzyNumbersEqual$1(prevPanelSize, prevCollapsedSize)) {
|
|
1920
|
+
if (!fuzzyNumbersEqual$1(prevCollapsedSize, nextCollapsedSize)) {
|
|
1920
1921
|
resizePanel(panelData, nextCollapsedSize);
|
|
1921
1922
|
}
|
|
1922
1923
|
} else if (prevPanelSize < nextMinSize) {
|
|
@@ -638,15 +638,15 @@ function assert(expectedCondition, message) {
|
|
|
638
638
|
const PRECISION = 10;
|
|
639
639
|
|
|
640
640
|
function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
|
|
641
|
-
|
|
642
|
-
expected = parseFloat(expected.toFixed(fractionDigits));
|
|
643
|
-
const delta = actual - expected;
|
|
644
|
-
if (delta === 0) {
|
|
641
|
+
if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
|
|
645
642
|
return 0;
|
|
646
643
|
} else {
|
|
647
|
-
return
|
|
644
|
+
return actual > expected ? 1 : -1;
|
|
648
645
|
}
|
|
649
646
|
}
|
|
647
|
+
function fuzzyNumbersEqual$1(actual, expected, fractionDigits = PRECISION) {
|
|
648
|
+
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
649
|
+
}
|
|
650
650
|
|
|
651
651
|
function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
652
652
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
@@ -1177,10 +1177,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
|
1177
1177
|
onResize(size, lastNotifiedSize);
|
|
1178
1178
|
}
|
|
1179
1179
|
if (collapsible && (onCollapse || onExpand)) {
|
|
1180
|
-
if (onExpand && (lastNotifiedSize == null || lastNotifiedSize
|
|
1180
|
+
if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
|
|
1181
1181
|
onExpand();
|
|
1182
1182
|
}
|
|
1183
|
-
if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize
|
|
1183
|
+
if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
|
|
1184
1184
|
onCollapse();
|
|
1185
1185
|
}
|
|
1186
1186
|
}
|
|
@@ -1615,7 +1615,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1615
1615
|
pivotIndices
|
|
1616
1616
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1617
1617
|
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1618
|
-
if (panelSize
|
|
1618
|
+
if (!fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1619
1619
|
// Store size before collapse;
|
|
1620
1620
|
// This is the size that gets restored if the expand() API is used.
|
|
1621
1621
|
panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
|
|
@@ -1654,11 +1654,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1654
1654
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1655
1655
|
const {
|
|
1656
1656
|
collapsedSize = 0,
|
|
1657
|
-
panelSize,
|
|
1657
|
+
panelSize = 0,
|
|
1658
1658
|
minSize = 0,
|
|
1659
1659
|
pivotIndices
|
|
1660
1660
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1661
|
-
if (panelSize
|
|
1661
|
+
if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1662
1662
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1663
1663
|
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1664
1664
|
const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
|
|
@@ -1723,7 +1723,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1723
1723
|
collapsible,
|
|
1724
1724
|
panelSize
|
|
1725
1725
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1726
|
-
|
|
1726
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1727
|
+
return collapsible === true && fuzzyNumbersEqual$1(panelSize, collapsedSize);
|
|
1727
1728
|
}, []);
|
|
1728
1729
|
|
|
1729
1730
|
// External APIs are safe to memoize via committed values ref
|
|
@@ -1738,7 +1739,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1738
1739
|
panelSize
|
|
1739
1740
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1740
1741
|
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1741
|
-
return !collapsible || panelSize >
|
|
1742
|
+
return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
|
|
1742
1743
|
}, []);
|
|
1743
1744
|
const registerPanel = useCallback(panelData => {
|
|
1744
1745
|
const {
|
|
@@ -1891,8 +1892,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1891
1892
|
// It's possible that the panels in this group have changed since the last render
|
|
1892
1893
|
return;
|
|
1893
1894
|
}
|
|
1894
|
-
if (prevCollapsible && nextCollapsible && prevPanelSize
|
|
1895
|
-
if (prevCollapsedSize
|
|
1895
|
+
if (prevCollapsible && nextCollapsible && fuzzyNumbersEqual$1(prevPanelSize, prevCollapsedSize)) {
|
|
1896
|
+
if (!fuzzyNumbersEqual$1(prevCollapsedSize, nextCollapsedSize)) {
|
|
1896
1897
|
resizePanel(panelData, nextCollapsedSize);
|
|
1897
1898
|
}
|
|
1898
1899
|
} else if (prevPanelSize < nextMinSize) {
|
|
@@ -665,15 +665,15 @@ function assert(expectedCondition, message) {
|
|
|
665
665
|
const PRECISION = 10;
|
|
666
666
|
|
|
667
667
|
function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
|
|
668
|
-
|
|
669
|
-
expected = parseFloat(expected.toFixed(fractionDigits));
|
|
670
|
-
const delta = actual - expected;
|
|
671
|
-
if (delta === 0) {
|
|
668
|
+
if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
|
|
672
669
|
return 0;
|
|
673
670
|
} else {
|
|
674
|
-
return
|
|
671
|
+
return actual > expected ? 1 : -1;
|
|
675
672
|
}
|
|
676
673
|
}
|
|
674
|
+
function fuzzyNumbersEqual$1(actual, expected, fractionDigits = PRECISION) {
|
|
675
|
+
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
676
|
+
}
|
|
677
677
|
|
|
678
678
|
function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
679
679
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
@@ -1318,10 +1318,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
|
1318
1318
|
onResize(size, lastNotifiedSize);
|
|
1319
1319
|
}
|
|
1320
1320
|
if (collapsible && (onCollapse || onExpand)) {
|
|
1321
|
-
if (onExpand && (lastNotifiedSize == null || lastNotifiedSize
|
|
1321
|
+
if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
|
|
1322
1322
|
onExpand();
|
|
1323
1323
|
}
|
|
1324
|
-
if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize
|
|
1324
|
+
if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
|
|
1325
1325
|
onCollapse();
|
|
1326
1326
|
}
|
|
1327
1327
|
}
|
|
@@ -1680,7 +1680,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1680
1680
|
pivotIndices
|
|
1681
1681
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1682
1682
|
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1683
|
-
if (panelSize
|
|
1683
|
+
if (!fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1684
1684
|
// Store size before collapse;
|
|
1685
1685
|
// This is the size that gets restored if the expand() API is used.
|
|
1686
1686
|
panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
|
|
@@ -1719,11 +1719,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1719
1719
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1720
1720
|
const {
|
|
1721
1721
|
collapsedSize = 0,
|
|
1722
|
-
panelSize,
|
|
1722
|
+
panelSize = 0,
|
|
1723
1723
|
minSize = 0,
|
|
1724
1724
|
pivotIndices
|
|
1725
1725
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1726
|
-
if (panelSize
|
|
1726
|
+
if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1727
1727
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1728
1728
|
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1729
1729
|
const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
|
|
@@ -1788,7 +1788,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1788
1788
|
collapsible,
|
|
1789
1789
|
panelSize
|
|
1790
1790
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1791
|
-
|
|
1791
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1792
|
+
return collapsible === true && fuzzyNumbersEqual$1(panelSize, collapsedSize);
|
|
1792
1793
|
}, []);
|
|
1793
1794
|
|
|
1794
1795
|
// External APIs are safe to memoize via committed values ref
|
|
@@ -1803,7 +1804,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1803
1804
|
panelSize
|
|
1804
1805
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1805
1806
|
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1806
|
-
return !collapsible || panelSize >
|
|
1807
|
+
return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
|
|
1807
1808
|
}, []);
|
|
1808
1809
|
const registerPanel = useCallback(panelData => {
|
|
1809
1810
|
const {
|
|
@@ -2012,8 +2013,8 @@ function PanelGroupWithForwardedRef({
|
|
|
2012
2013
|
// It's possible that the panels in this group have changed since the last render
|
|
2013
2014
|
return;
|
|
2014
2015
|
}
|
|
2015
|
-
if (prevCollapsible && nextCollapsible && prevPanelSize
|
|
2016
|
-
if (prevCollapsedSize
|
|
2016
|
+
if (prevCollapsible && nextCollapsible && fuzzyNumbersEqual$1(prevPanelSize, prevCollapsedSize)) {
|
|
2017
|
+
if (!fuzzyNumbersEqual$1(prevCollapsedSize, nextCollapsedSize)) {
|
|
2017
2018
|
resizePanel(panelData, nextCollapsedSize);
|
|
2018
2019
|
}
|
|
2019
2020
|
} else if (prevPanelSize < nextMinSize) {
|
|
@@ -651,15 +651,15 @@ function assert(expectedCondition, message) {
|
|
|
651
651
|
const PRECISION = 10;
|
|
652
652
|
|
|
653
653
|
function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
|
|
654
|
-
|
|
655
|
-
expected = parseFloat(expected.toFixed(fractionDigits));
|
|
656
|
-
const delta = actual - expected;
|
|
657
|
-
if (delta === 0) {
|
|
654
|
+
if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
|
|
658
655
|
return 0;
|
|
659
656
|
} else {
|
|
660
|
-
return
|
|
657
|
+
return actual > expected ? 1 : -1;
|
|
661
658
|
}
|
|
662
659
|
}
|
|
660
|
+
function fuzzyNumbersEqual$1(actual, expected, fractionDigits = PRECISION) {
|
|
661
|
+
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
662
|
+
}
|
|
663
663
|
|
|
664
664
|
function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
665
665
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
@@ -1190,10 +1190,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
|
1190
1190
|
onResize(size, lastNotifiedSize);
|
|
1191
1191
|
}
|
|
1192
1192
|
if (collapsible && (onCollapse || onExpand)) {
|
|
1193
|
-
if (onExpand && (lastNotifiedSize == null || lastNotifiedSize
|
|
1193
|
+
if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
|
|
1194
1194
|
onExpand();
|
|
1195
1195
|
}
|
|
1196
|
-
if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize
|
|
1196
|
+
if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
|
|
1197
1197
|
onCollapse();
|
|
1198
1198
|
}
|
|
1199
1199
|
}
|
|
@@ -1538,7 +1538,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1538
1538
|
pivotIndices
|
|
1539
1539
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1540
1540
|
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1541
|
-
if (panelSize
|
|
1541
|
+
if (!fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1542
1542
|
// Store size before collapse;
|
|
1543
1543
|
// This is the size that gets restored if the expand() API is used.
|
|
1544
1544
|
panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
|
|
@@ -1577,11 +1577,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1577
1577
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1578
1578
|
const {
|
|
1579
1579
|
collapsedSize = 0,
|
|
1580
|
-
panelSize,
|
|
1580
|
+
panelSize = 0,
|
|
1581
1581
|
minSize = 0,
|
|
1582
1582
|
pivotIndices
|
|
1583
1583
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1584
|
-
if (panelSize
|
|
1584
|
+
if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1585
1585
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1586
1586
|
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1587
1587
|
const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
|
|
@@ -1646,7 +1646,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1646
1646
|
collapsible,
|
|
1647
1647
|
panelSize
|
|
1648
1648
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1649
|
-
|
|
1649
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1650
|
+
return collapsible === true && fuzzyNumbersEqual$1(panelSize, collapsedSize);
|
|
1650
1651
|
}, []);
|
|
1651
1652
|
|
|
1652
1653
|
// External APIs are safe to memoize via committed values ref
|
|
@@ -1661,7 +1662,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1661
1662
|
panelSize
|
|
1662
1663
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1663
1664
|
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1664
|
-
return !collapsible || panelSize >
|
|
1665
|
+
return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
|
|
1665
1666
|
}, []);
|
|
1666
1667
|
const registerPanel = useCallback(panelData => {
|
|
1667
1668
|
const {
|
|
@@ -1814,8 +1815,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1814
1815
|
// It's possible that the panels in this group have changed since the last render
|
|
1815
1816
|
return;
|
|
1816
1817
|
}
|
|
1817
|
-
if (prevCollapsible && nextCollapsible && prevPanelSize
|
|
1818
|
-
if (prevCollapsedSize
|
|
1818
|
+
if (prevCollapsible && nextCollapsible && fuzzyNumbersEqual$1(prevPanelSize, prevCollapsedSize)) {
|
|
1819
|
+
if (!fuzzyNumbersEqual$1(prevCollapsedSize, nextCollapsedSize)) {
|
|
1819
1820
|
resizePanel(panelData, nextCollapsedSize);
|
|
1820
1821
|
}
|
|
1821
1822
|
} else if (prevPanelSize < nextMinSize) {
|
|
@@ -627,15 +627,15 @@ function assert(expectedCondition, message) {
|
|
|
627
627
|
const PRECISION = 10;
|
|
628
628
|
|
|
629
629
|
function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
|
|
630
|
-
|
|
631
|
-
expected = parseFloat(expected.toFixed(fractionDigits));
|
|
632
|
-
const delta = actual - expected;
|
|
633
|
-
if (delta === 0) {
|
|
630
|
+
if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
|
|
634
631
|
return 0;
|
|
635
632
|
} else {
|
|
636
|
-
return
|
|
633
|
+
return actual > expected ? 1 : -1;
|
|
637
634
|
}
|
|
638
635
|
}
|
|
636
|
+
function fuzzyNumbersEqual$1(actual, expected, fractionDigits = PRECISION) {
|
|
637
|
+
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
638
|
+
}
|
|
639
639
|
|
|
640
640
|
function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
641
641
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
@@ -1166,10 +1166,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
|
1166
1166
|
onResize(size, lastNotifiedSize);
|
|
1167
1167
|
}
|
|
1168
1168
|
if (collapsible && (onCollapse || onExpand)) {
|
|
1169
|
-
if (onExpand && (lastNotifiedSize == null || lastNotifiedSize
|
|
1169
|
+
if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
|
|
1170
1170
|
onExpand();
|
|
1171
1171
|
}
|
|
1172
|
-
if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize
|
|
1172
|
+
if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
|
|
1173
1173
|
onCollapse();
|
|
1174
1174
|
}
|
|
1175
1175
|
}
|
|
@@ -1514,7 +1514,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1514
1514
|
pivotIndices
|
|
1515
1515
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1516
1516
|
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1517
|
-
if (panelSize
|
|
1517
|
+
if (!fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1518
1518
|
// Store size before collapse;
|
|
1519
1519
|
// This is the size that gets restored if the expand() API is used.
|
|
1520
1520
|
panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
|
|
@@ -1553,11 +1553,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1553
1553
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1554
1554
|
const {
|
|
1555
1555
|
collapsedSize = 0,
|
|
1556
|
-
panelSize,
|
|
1556
|
+
panelSize = 0,
|
|
1557
1557
|
minSize = 0,
|
|
1558
1558
|
pivotIndices
|
|
1559
1559
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1560
|
-
if (panelSize
|
|
1560
|
+
if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1561
1561
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1562
1562
|
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1563
1563
|
const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
|
|
@@ -1622,7 +1622,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1622
1622
|
collapsible,
|
|
1623
1623
|
panelSize
|
|
1624
1624
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1625
|
-
|
|
1625
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1626
|
+
return collapsible === true && fuzzyNumbersEqual$1(panelSize, collapsedSize);
|
|
1626
1627
|
}, []);
|
|
1627
1628
|
|
|
1628
1629
|
// External APIs are safe to memoize via committed values ref
|
|
@@ -1637,7 +1638,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1637
1638
|
panelSize
|
|
1638
1639
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1639
1640
|
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1640
|
-
return !collapsible || panelSize >
|
|
1641
|
+
return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
|
|
1641
1642
|
}, []);
|
|
1642
1643
|
const registerPanel = useCallback(panelData => {
|
|
1643
1644
|
const {
|
|
@@ -1790,8 +1791,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1790
1791
|
// It's possible that the panels in this group have changed since the last render
|
|
1791
1792
|
return;
|
|
1792
1793
|
}
|
|
1793
|
-
if (prevCollapsible && nextCollapsible && prevPanelSize
|
|
1794
|
-
if (prevCollapsedSize
|
|
1794
|
+
if (prevCollapsible && nextCollapsible && fuzzyNumbersEqual$1(prevPanelSize, prevCollapsedSize)) {
|
|
1795
|
+
if (!fuzzyNumbersEqual$1(prevCollapsedSize, nextCollapsedSize)) {
|
|
1795
1796
|
resizePanel(panelData, nextCollapsedSize);
|
|
1796
1797
|
}
|
|
1797
1798
|
} else if (prevPanelSize < nextMinSize) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-resizable-panels",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"description": "React components for resizable panel groups/layouts",
|
|
5
5
|
"author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,6 +60,12 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"types": "dist/react-resizable-panels.cjs.d.ts",
|
|
63
|
+
"scripts": {
|
|
64
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
65
|
+
"test": "jest --config=jest.config.js",
|
|
66
|
+
"test:watch": "jest --config=jest.config.js --watch",
|
|
67
|
+
"watch": "parcel watch --port=2345"
|
|
68
|
+
},
|
|
63
69
|
"devDependencies": {
|
|
64
70
|
"@babel/plugin-proposal-nullish-coalescing-operator": "7.18.6",
|
|
65
71
|
"@babel/plugin-proposal-optional-chaining": "7.21.0",
|
|
@@ -77,11 +83,5 @@
|
|
|
77
83
|
},
|
|
78
84
|
"browserslist": [
|
|
79
85
|
"Chrome 79"
|
|
80
|
-
]
|
|
81
|
-
|
|
82
|
-
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
83
|
-
"test": "jest --config=jest.config.js",
|
|
84
|
-
"test:watch": "jest --config=jest.config.js --watch",
|
|
85
|
-
"watch": "parcel watch --port=2345"
|
|
86
|
-
}
|
|
87
|
-
}
|
|
86
|
+
]
|
|
87
|
+
}
|
package/src/Panel.test.tsx
CHANGED
|
@@ -144,6 +144,55 @@ describe("PanelGroup", () => {
|
|
|
144
144
|
});
|
|
145
145
|
verifyExpandedPanelGroupLayout(mostRecentLayout, [30, 70]);
|
|
146
146
|
});
|
|
147
|
+
|
|
148
|
+
it("should report the correct state with collapsedSizes that have many decimal places", () => {
|
|
149
|
+
act(() => {
|
|
150
|
+
root.render(
|
|
151
|
+
<PanelGroup direction="horizontal">
|
|
152
|
+
<Panel
|
|
153
|
+
collapsedSize={3.8764385221078133}
|
|
154
|
+
collapsible
|
|
155
|
+
defaultSize={50}
|
|
156
|
+
minSize={15}
|
|
157
|
+
ref={leftPanelRef}
|
|
158
|
+
/>
|
|
159
|
+
<PanelResizeHandle />
|
|
160
|
+
<Panel collapsible defaultSize={50} ref={rightPanelRef} />
|
|
161
|
+
</PanelGroup>
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
act(() => {
|
|
166
|
+
leftPanelRef.current?.collapse();
|
|
167
|
+
});
|
|
168
|
+
expect(leftPanelRef.current?.isCollapsed()).toBe(true);
|
|
169
|
+
expect(leftPanelRef.current?.isExpanded()).toBe(false);
|
|
170
|
+
|
|
171
|
+
act(() => {
|
|
172
|
+
root.render(
|
|
173
|
+
<PanelGroup direction="horizontal">
|
|
174
|
+
<Panel
|
|
175
|
+
collapsedSize={3.8764385221078132}
|
|
176
|
+
collapsible
|
|
177
|
+
defaultSize={50}
|
|
178
|
+
minSize={15}
|
|
179
|
+
ref={leftPanelRef}
|
|
180
|
+
/>
|
|
181
|
+
<PanelResizeHandle />
|
|
182
|
+
<Panel collapsible defaultSize={50} ref={rightPanelRef} />
|
|
183
|
+
</PanelGroup>
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
expect(leftPanelRef.current?.isCollapsed()).toBe(true);
|
|
188
|
+
expect(leftPanelRef.current?.isExpanded()).toBe(false);
|
|
189
|
+
|
|
190
|
+
act(() => {
|
|
191
|
+
leftPanelRef.current?.expand();
|
|
192
|
+
});
|
|
193
|
+
expect(leftPanelRef.current?.isCollapsed()).toBe(false);
|
|
194
|
+
expect(leftPanelRef.current?.isExpanded()).toBe(true);
|
|
195
|
+
});
|
|
147
196
|
});
|
|
148
197
|
|
|
149
198
|
describe("resize", () => {
|
|
@@ -496,6 +545,44 @@ describe("PanelGroup", () => {
|
|
|
496
545
|
|
|
497
546
|
expect(onCollapse).toHaveBeenCalledTimes(1);
|
|
498
547
|
});
|
|
548
|
+
|
|
549
|
+
it("should be called with collapsedSizes that have many decimal places", () => {
|
|
550
|
+
let onCollapse = jest.fn();
|
|
551
|
+
|
|
552
|
+
let panelRef = createRef<ImperativePanelHandle>();
|
|
553
|
+
|
|
554
|
+
act(() => {
|
|
555
|
+
root.render(
|
|
556
|
+
<PanelGroup direction="horizontal">
|
|
557
|
+
<Panel
|
|
558
|
+
collapsible
|
|
559
|
+
onCollapse={onCollapse}
|
|
560
|
+
collapsedSize={3.8764385221078133}
|
|
561
|
+
minSize={10}
|
|
562
|
+
ref={panelRef}
|
|
563
|
+
/>
|
|
564
|
+
<PanelResizeHandle />
|
|
565
|
+
<Panel />
|
|
566
|
+
</PanelGroup>
|
|
567
|
+
);
|
|
568
|
+
});
|
|
569
|
+
expect(onCollapse).not.toHaveBeenCalled();
|
|
570
|
+
|
|
571
|
+
act(() => {
|
|
572
|
+
panelRef.current?.collapse();
|
|
573
|
+
});
|
|
574
|
+
expect(onCollapse).toHaveBeenCalledTimes(1);
|
|
575
|
+
|
|
576
|
+
act(() => {
|
|
577
|
+
panelRef.current?.expand();
|
|
578
|
+
});
|
|
579
|
+
expect(onCollapse).toHaveBeenCalledTimes(1);
|
|
580
|
+
|
|
581
|
+
act(() => {
|
|
582
|
+
panelRef.current?.collapse();
|
|
583
|
+
});
|
|
584
|
+
expect(onCollapse).toHaveBeenCalledTimes(2);
|
|
585
|
+
});
|
|
499
586
|
});
|
|
500
587
|
|
|
501
588
|
describe("onExpand", () => {
|
|
@@ -545,6 +632,45 @@ describe("PanelGroup", () => {
|
|
|
545
632
|
|
|
546
633
|
expect(onExpand).toHaveBeenCalledTimes(1);
|
|
547
634
|
});
|
|
635
|
+
|
|
636
|
+
it("should be called with collapsedSizes that have many decimal places", () => {
|
|
637
|
+
let onExpand = jest.fn();
|
|
638
|
+
|
|
639
|
+
let panelRef = createRef<ImperativePanelHandle>();
|
|
640
|
+
|
|
641
|
+
act(() => {
|
|
642
|
+
root.render(
|
|
643
|
+
<PanelGroup direction="horizontal">
|
|
644
|
+
<Panel
|
|
645
|
+
collapsible
|
|
646
|
+
collapsedSize={3.8764385221078133}
|
|
647
|
+
defaultSize={3.8764385221078133}
|
|
648
|
+
minSize={10}
|
|
649
|
+
onExpand={onExpand}
|
|
650
|
+
ref={panelRef}
|
|
651
|
+
/>
|
|
652
|
+
<PanelResizeHandle />
|
|
653
|
+
<Panel />
|
|
654
|
+
</PanelGroup>
|
|
655
|
+
);
|
|
656
|
+
});
|
|
657
|
+
expect(onExpand).not.toHaveBeenCalled();
|
|
658
|
+
|
|
659
|
+
act(() => {
|
|
660
|
+
panelRef.current?.resize(25);
|
|
661
|
+
});
|
|
662
|
+
expect(onExpand).toHaveBeenCalledTimes(1);
|
|
663
|
+
|
|
664
|
+
act(() => {
|
|
665
|
+
panelRef.current?.collapse();
|
|
666
|
+
});
|
|
667
|
+
expect(onExpand).toHaveBeenCalledTimes(1);
|
|
668
|
+
|
|
669
|
+
act(() => {
|
|
670
|
+
panelRef.current?.expand();
|
|
671
|
+
});
|
|
672
|
+
expect(onExpand).toHaveBeenCalledTimes(2);
|
|
673
|
+
});
|
|
548
674
|
});
|
|
549
675
|
|
|
550
676
|
describe("onResize", () => {
|
|
@@ -674,6 +800,33 @@ describe("PanelGroup", () => {
|
|
|
674
800
|
expect(onResizeRight).not.toHaveBeenCalled();
|
|
675
801
|
});
|
|
676
802
|
});
|
|
803
|
+
|
|
804
|
+
it("should support sizes with many decimal places", () => {
|
|
805
|
+
let panelRef = createRef<ImperativePanelHandle>();
|
|
806
|
+
let onResize = jest.fn();
|
|
807
|
+
|
|
808
|
+
act(() => {
|
|
809
|
+
root.render(
|
|
810
|
+
<PanelGroup direction="horizontal">
|
|
811
|
+
<Panel onResize={onResize} ref={panelRef} />
|
|
812
|
+
<PanelResizeHandle />
|
|
813
|
+
<Panel />
|
|
814
|
+
</PanelGroup>
|
|
815
|
+
);
|
|
816
|
+
});
|
|
817
|
+
expect(onResize).toHaveBeenCalledTimes(1);
|
|
818
|
+
|
|
819
|
+
act(() => {
|
|
820
|
+
panelRef.current?.resize(3.8764385221078133);
|
|
821
|
+
});
|
|
822
|
+
expect(onResize).toHaveBeenCalledTimes(2);
|
|
823
|
+
|
|
824
|
+
// An overly-high precision change should be ignored
|
|
825
|
+
act(() => {
|
|
826
|
+
panelRef.current?.resize(3.8764385221078132);
|
|
827
|
+
});
|
|
828
|
+
expect(onResize).toHaveBeenCalledTimes(2);
|
|
829
|
+
});
|
|
677
830
|
});
|
|
678
831
|
|
|
679
832
|
describe("data attributes", () => {
|