react-resizable-panels 1.0.5 → 1.0.7
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 +10 -2
- package/README.md +210 -4
- package/dist/declarations/src/Panel.d.ts +7 -7
- package/dist/declarations/src/PanelGroup.d.ts +6 -6
- package/dist/declarations/src/PanelResizeHandle.d.ts +4 -4
- package/dist/declarations/src/index.d.ts +10 -1
- package/dist/declarations/src/utils/dom/calculateAvailablePanelSizeInPixels.d.ts +1 -0
- package/dist/declarations/src/utils/dom/getAvailableGroupSizePixels.d.ts +1 -0
- package/dist/declarations/src/utils/dom/getPanelElement.d.ts +1 -0
- package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +1 -0
- package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +1 -0
- package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +1 -0
- package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +1 -0
- package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +1 -0
- package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +2 -0
- package/dist/react-resizable-panels.browser.cjs.js +65 -8
- package/dist/react-resizable-panels.browser.cjs.mjs +10 -1
- package/dist/react-resizable-panels.browser.development.cjs.js +65 -8
- package/dist/react-resizable-panels.browser.development.cjs.mjs +10 -1
- package/dist/react-resizable-panels.browser.development.esm.js +57 -9
- package/dist/react-resizable-panels.browser.esm.js +57 -9
- package/dist/react-resizable-panels.cjs.js +65 -8
- package/dist/react-resizable-panels.cjs.mjs +10 -1
- package/dist/react-resizable-panels.development.cjs.js +65 -8
- package/dist/react-resizable-panels.development.cjs.mjs +10 -1
- package/dist/react-resizable-panels.development.esm.js +57 -9
- package/dist/react-resizable-panels.development.node.cjs.js +65 -8
- package/dist/react-resizable-panels.development.node.cjs.mjs +10 -1
- package/dist/react-resizable-panels.development.node.esm.js +57 -9
- package/dist/react-resizable-panels.esm.js +57 -9
- package/dist/react-resizable-panels.node.cjs.js +65 -8
- package/dist/react-resizable-panels.node.cjs.mjs +10 -1
- package/dist/react-resizable-panels.node.esm.js +57 -9
- package/package.json +1 -1
- package/src/Panel.ts +7 -4
- package/src/PanelGroup.ts +7 -4
- package/src/PanelResizeHandle.ts +15 -12
- package/src/hooks/useWindowSplitterBehavior.ts +1 -1
- package/src/index.ts +23 -3
- package/src/utils/dom/getPanelElement.ts +2 -2
- package/src/utils/dom/getPanelElementsForGroup.ts +1 -1
- package/src/utils/dom/getPanelGroupElement.ts +2 -2
- package/src/utils/dom/getResizeHandleElement.ts +2 -2
- package/src/utils/dom/getResizeHandleElementsForGroup.ts +1 -1
|
@@ -1566,7 +1566,7 @@ function PanelResizeHandle({
|
|
|
1566
1566
|
tagName: Type = "div",
|
|
1567
1567
|
...rest
|
|
1568
1568
|
}) {
|
|
1569
|
-
const
|
|
1569
|
+
const elementRef = useRef(null);
|
|
1570
1570
|
|
|
1571
1571
|
// Use a ref to guard against users passing inline props
|
|
1572
1572
|
const callbacksRef = useRef({
|
|
@@ -1594,9 +1594,9 @@ function PanelResizeHandle({
|
|
|
1594
1594
|
const stopDraggingAndBlur = useCallback(() => {
|
|
1595
1595
|
// Clicking on the drag handle shouldn't leave it focused;
|
|
1596
1596
|
// That would cause the PanelGroup to think it was still active.
|
|
1597
|
-
const
|
|
1598
|
-
assert(
|
|
1599
|
-
|
|
1597
|
+
const element = elementRef.current;
|
|
1598
|
+
assert(element);
|
|
1599
|
+
element.blur();
|
|
1600
1600
|
stopDragging();
|
|
1601
1601
|
const {
|
|
1602
1602
|
onDragging
|
|
@@ -1623,9 +1623,9 @@ function PanelResizeHandle({
|
|
|
1623
1623
|
const onMouseLeave = event => {
|
|
1624
1624
|
resizeHandler(event);
|
|
1625
1625
|
};
|
|
1626
|
-
const
|
|
1627
|
-
assert(
|
|
1628
|
-
const targetDocument =
|
|
1626
|
+
const element = elementRef.current;
|
|
1627
|
+
assert(element);
|
|
1628
|
+
const targetDocument = element.ownerDocument;
|
|
1629
1629
|
targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
|
|
1630
1630
|
targetDocument.body.addEventListener("mousemove", onMove);
|
|
1631
1631
|
targetDocument.body.addEventListener("touchmove", onMove);
|
|
@@ -1682,7 +1682,7 @@ function PanelResizeHandle({
|
|
|
1682
1682
|
onDragging(true);
|
|
1683
1683
|
}
|
|
1684
1684
|
},
|
|
1685
|
-
ref:
|
|
1685
|
+
ref: elementRef,
|
|
1686
1686
|
role: "separator",
|
|
1687
1687
|
style: {
|
|
1688
1688
|
...style,
|
|
@@ -1700,4 +1700,52 @@ function PanelResizeHandle({
|
|
|
1700
1700
|
}
|
|
1701
1701
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1702
1702
|
|
|
1703
|
-
|
|
1703
|
+
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1704
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1705
|
+
if (panelGroupElement == null) {
|
|
1706
|
+
return NaN;
|
|
1707
|
+
}
|
|
1708
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1709
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1710
|
+
if (direction === "horizontal") {
|
|
1711
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1712
|
+
return accumulated + handle.offsetWidth;
|
|
1713
|
+
}, 0);
|
|
1714
|
+
} else {
|
|
1715
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1716
|
+
return accumulated + handle.offsetHeight;
|
|
1717
|
+
}, 0);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
function getAvailableGroupSizePixels(groupId) {
|
|
1722
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1723
|
+
if (panelGroupElement == null) {
|
|
1724
|
+
return NaN;
|
|
1725
|
+
}
|
|
1726
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1727
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1728
|
+
if (direction === "horizontal") {
|
|
1729
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1730
|
+
return accumulated + handle.offsetWidth;
|
|
1731
|
+
}, 0);
|
|
1732
|
+
} else {
|
|
1733
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1734
|
+
return accumulated + handle.offsetHeight;
|
|
1735
|
+
}, 0);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
function getPanelElement(id) {
|
|
1740
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1741
|
+
if (element) {
|
|
1742
|
+
return element;
|
|
1743
|
+
}
|
|
1744
|
+
return null;
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
function getPanelElementsForGroup(groupId) {
|
|
1748
|
+
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|
|
@@ -1667,7 +1667,7 @@ function PanelResizeHandle({
|
|
|
1667
1667
|
tagName: Type = "div",
|
|
1668
1668
|
...rest
|
|
1669
1669
|
}) {
|
|
1670
|
-
const
|
|
1670
|
+
const elementRef = useRef(null);
|
|
1671
1671
|
|
|
1672
1672
|
// Use a ref to guard against users passing inline props
|
|
1673
1673
|
const callbacksRef = useRef({
|
|
@@ -1695,9 +1695,9 @@ function PanelResizeHandle({
|
|
|
1695
1695
|
const stopDraggingAndBlur = useCallback(() => {
|
|
1696
1696
|
// Clicking on the drag handle shouldn't leave it focused;
|
|
1697
1697
|
// That would cause the PanelGroup to think it was still active.
|
|
1698
|
-
const
|
|
1699
|
-
assert(
|
|
1700
|
-
|
|
1698
|
+
const element = elementRef.current;
|
|
1699
|
+
assert(element);
|
|
1700
|
+
element.blur();
|
|
1701
1701
|
stopDragging();
|
|
1702
1702
|
const {
|
|
1703
1703
|
onDragging
|
|
@@ -1724,9 +1724,9 @@ function PanelResizeHandle({
|
|
|
1724
1724
|
const onMouseLeave = event => {
|
|
1725
1725
|
resizeHandler(event);
|
|
1726
1726
|
};
|
|
1727
|
-
const
|
|
1728
|
-
assert(
|
|
1729
|
-
const targetDocument =
|
|
1727
|
+
const element = elementRef.current;
|
|
1728
|
+
assert(element);
|
|
1729
|
+
const targetDocument = element.ownerDocument;
|
|
1730
1730
|
targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
|
|
1731
1731
|
targetDocument.body.addEventListener("mousemove", onMove);
|
|
1732
1732
|
targetDocument.body.addEventListener("touchmove", onMove);
|
|
@@ -1783,7 +1783,7 @@ function PanelResizeHandle({
|
|
|
1783
1783
|
onDragging(true);
|
|
1784
1784
|
}
|
|
1785
1785
|
},
|
|
1786
|
-
ref:
|
|
1786
|
+
ref: elementRef,
|
|
1787
1787
|
role: "separator",
|
|
1788
1788
|
style: {
|
|
1789
1789
|
...style,
|
|
@@ -1801,4 +1801,52 @@ function PanelResizeHandle({
|
|
|
1801
1801
|
}
|
|
1802
1802
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1803
1803
|
|
|
1804
|
-
|
|
1804
|
+
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1805
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1806
|
+
if (panelGroupElement == null) {
|
|
1807
|
+
return NaN;
|
|
1808
|
+
}
|
|
1809
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1810
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1811
|
+
if (direction === "horizontal") {
|
|
1812
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1813
|
+
return accumulated + handle.offsetWidth;
|
|
1814
|
+
}, 0);
|
|
1815
|
+
} else {
|
|
1816
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1817
|
+
return accumulated + handle.offsetHeight;
|
|
1818
|
+
}, 0);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
function getAvailableGroupSizePixels(groupId) {
|
|
1823
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1824
|
+
if (panelGroupElement == null) {
|
|
1825
|
+
return NaN;
|
|
1826
|
+
}
|
|
1827
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1828
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1829
|
+
if (direction === "horizontal") {
|
|
1830
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1831
|
+
return accumulated + handle.offsetWidth;
|
|
1832
|
+
}, 0);
|
|
1833
|
+
} else {
|
|
1834
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1835
|
+
return accumulated + handle.offsetHeight;
|
|
1836
|
+
}, 0);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
function getPanelElement(id) {
|
|
1841
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1842
|
+
if (element) {
|
|
1843
|
+
return element;
|
|
1844
|
+
}
|
|
1845
|
+
return null;
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
function getPanelElementsForGroup(groupId) {
|
|
1849
|
+
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|
|
@@ -1490,7 +1490,7 @@ function PanelResizeHandle({
|
|
|
1490
1490
|
tagName: Type = "div",
|
|
1491
1491
|
...rest
|
|
1492
1492
|
}) {
|
|
1493
|
-
const
|
|
1493
|
+
const elementRef = useRef(null);
|
|
1494
1494
|
|
|
1495
1495
|
// Use a ref to guard against users passing inline props
|
|
1496
1496
|
const callbacksRef = useRef({
|
|
@@ -1518,9 +1518,9 @@ function PanelResizeHandle({
|
|
|
1518
1518
|
const stopDraggingAndBlur = useCallback(() => {
|
|
1519
1519
|
// Clicking on the drag handle shouldn't leave it focused;
|
|
1520
1520
|
// That would cause the PanelGroup to think it was still active.
|
|
1521
|
-
const
|
|
1522
|
-
assert(
|
|
1523
|
-
|
|
1521
|
+
const element = elementRef.current;
|
|
1522
|
+
assert(element);
|
|
1523
|
+
element.blur();
|
|
1524
1524
|
stopDragging();
|
|
1525
1525
|
const {
|
|
1526
1526
|
onDragging
|
|
@@ -1547,9 +1547,9 @@ function PanelResizeHandle({
|
|
|
1547
1547
|
const onMouseLeave = event => {
|
|
1548
1548
|
resizeHandler(event);
|
|
1549
1549
|
};
|
|
1550
|
-
const
|
|
1551
|
-
assert(
|
|
1552
|
-
const targetDocument =
|
|
1550
|
+
const element = elementRef.current;
|
|
1551
|
+
assert(element);
|
|
1552
|
+
const targetDocument = element.ownerDocument;
|
|
1553
1553
|
targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
|
|
1554
1554
|
targetDocument.body.addEventListener("mousemove", onMove);
|
|
1555
1555
|
targetDocument.body.addEventListener("touchmove", onMove);
|
|
@@ -1606,7 +1606,7 @@ function PanelResizeHandle({
|
|
|
1606
1606
|
onDragging(true);
|
|
1607
1607
|
}
|
|
1608
1608
|
},
|
|
1609
|
-
ref:
|
|
1609
|
+
ref: elementRef,
|
|
1610
1610
|
role: "separator",
|
|
1611
1611
|
style: {
|
|
1612
1612
|
...style,
|
|
@@ -1624,7 +1624,64 @@ function PanelResizeHandle({
|
|
|
1624
1624
|
}
|
|
1625
1625
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1626
1626
|
|
|
1627
|
+
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1628
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1629
|
+
if (panelGroupElement == null) {
|
|
1630
|
+
return NaN;
|
|
1631
|
+
}
|
|
1632
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1633
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1634
|
+
if (direction === "horizontal") {
|
|
1635
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1636
|
+
return accumulated + handle.offsetWidth;
|
|
1637
|
+
}, 0);
|
|
1638
|
+
} else {
|
|
1639
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1640
|
+
return accumulated + handle.offsetHeight;
|
|
1641
|
+
}, 0);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
function getAvailableGroupSizePixels(groupId) {
|
|
1646
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1647
|
+
if (panelGroupElement == null) {
|
|
1648
|
+
return NaN;
|
|
1649
|
+
}
|
|
1650
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1651
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1652
|
+
if (direction === "horizontal") {
|
|
1653
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1654
|
+
return accumulated + handle.offsetWidth;
|
|
1655
|
+
}, 0);
|
|
1656
|
+
} else {
|
|
1657
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1658
|
+
return accumulated + handle.offsetHeight;
|
|
1659
|
+
}, 0);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
function getPanelElement(id) {
|
|
1664
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1665
|
+
if (element) {
|
|
1666
|
+
return element;
|
|
1667
|
+
}
|
|
1668
|
+
return null;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
function getPanelElementsForGroup(groupId) {
|
|
1672
|
+
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1627
1675
|
exports.Panel = Panel;
|
|
1628
1676
|
exports.PanelGroup = PanelGroup;
|
|
1629
1677
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1630
1678
|
exports.assert = assert;
|
|
1679
|
+
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1680
|
+
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1681
|
+
exports.getPanelElement = getPanelElement;
|
|
1682
|
+
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1683
|
+
exports.getPanelGroupElement = getPanelGroupElement;
|
|
1684
|
+
exports.getResizeHandleElement = getResizeHandleElement;
|
|
1685
|
+
exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
|
|
1686
|
+
exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
|
|
1687
|
+
exports.getResizeHandlePanelIds = getResizeHandlePanelIds;
|
|
@@ -2,5 +2,14 @@ export {
|
|
|
2
2
|
Panel,
|
|
3
3
|
PanelGroup,
|
|
4
4
|
PanelResizeHandle,
|
|
5
|
-
assert
|
|
5
|
+
assert,
|
|
6
|
+
calculateAvailablePanelSizeInPixels,
|
|
7
|
+
getAvailableGroupSizePixels,
|
|
8
|
+
getPanelElement,
|
|
9
|
+
getPanelElementsForGroup,
|
|
10
|
+
getPanelGroupElement,
|
|
11
|
+
getResizeHandleElement,
|
|
12
|
+
getResizeHandleElementIndex,
|
|
13
|
+
getResizeHandleElementsForGroup,
|
|
14
|
+
getResizeHandlePanelIds
|
|
6
15
|
} from "./react-resizable-panels.node.cjs.js";
|
|
@@ -1466,7 +1466,7 @@ function PanelResizeHandle({
|
|
|
1466
1466
|
tagName: Type = "div",
|
|
1467
1467
|
...rest
|
|
1468
1468
|
}) {
|
|
1469
|
-
const
|
|
1469
|
+
const elementRef = useRef(null);
|
|
1470
1470
|
|
|
1471
1471
|
// Use a ref to guard against users passing inline props
|
|
1472
1472
|
const callbacksRef = useRef({
|
|
@@ -1494,9 +1494,9 @@ function PanelResizeHandle({
|
|
|
1494
1494
|
const stopDraggingAndBlur = useCallback(() => {
|
|
1495
1495
|
// Clicking on the drag handle shouldn't leave it focused;
|
|
1496
1496
|
// That would cause the PanelGroup to think it was still active.
|
|
1497
|
-
const
|
|
1498
|
-
assert(
|
|
1499
|
-
|
|
1497
|
+
const element = elementRef.current;
|
|
1498
|
+
assert(element);
|
|
1499
|
+
element.blur();
|
|
1500
1500
|
stopDragging();
|
|
1501
1501
|
const {
|
|
1502
1502
|
onDragging
|
|
@@ -1523,9 +1523,9 @@ function PanelResizeHandle({
|
|
|
1523
1523
|
const onMouseLeave = event => {
|
|
1524
1524
|
resizeHandler(event);
|
|
1525
1525
|
};
|
|
1526
|
-
const
|
|
1527
|
-
assert(
|
|
1528
|
-
const targetDocument =
|
|
1526
|
+
const element = elementRef.current;
|
|
1527
|
+
assert(element);
|
|
1528
|
+
const targetDocument = element.ownerDocument;
|
|
1529
1529
|
targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
|
|
1530
1530
|
targetDocument.body.addEventListener("mousemove", onMove);
|
|
1531
1531
|
targetDocument.body.addEventListener("touchmove", onMove);
|
|
@@ -1582,7 +1582,7 @@ function PanelResizeHandle({
|
|
|
1582
1582
|
onDragging(true);
|
|
1583
1583
|
}
|
|
1584
1584
|
},
|
|
1585
|
-
ref:
|
|
1585
|
+
ref: elementRef,
|
|
1586
1586
|
role: "separator",
|
|
1587
1587
|
style: {
|
|
1588
1588
|
...style,
|
|
@@ -1600,4 +1600,52 @@ function PanelResizeHandle({
|
|
|
1600
1600
|
}
|
|
1601
1601
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1602
1602
|
|
|
1603
|
-
|
|
1603
|
+
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1604
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1605
|
+
if (panelGroupElement == null) {
|
|
1606
|
+
return NaN;
|
|
1607
|
+
}
|
|
1608
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1609
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1610
|
+
if (direction === "horizontal") {
|
|
1611
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1612
|
+
return accumulated + handle.offsetWidth;
|
|
1613
|
+
}, 0);
|
|
1614
|
+
} else {
|
|
1615
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1616
|
+
return accumulated + handle.offsetHeight;
|
|
1617
|
+
}, 0);
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
function getAvailableGroupSizePixels(groupId) {
|
|
1622
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1623
|
+
if (panelGroupElement == null) {
|
|
1624
|
+
return NaN;
|
|
1625
|
+
}
|
|
1626
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1627
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1628
|
+
if (direction === "horizontal") {
|
|
1629
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1630
|
+
return accumulated + handle.offsetWidth;
|
|
1631
|
+
}, 0);
|
|
1632
|
+
} else {
|
|
1633
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1634
|
+
return accumulated + handle.offsetHeight;
|
|
1635
|
+
}, 0);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
function getPanelElement(id) {
|
|
1640
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1641
|
+
if (element) {
|
|
1642
|
+
return element;
|
|
1643
|
+
}
|
|
1644
|
+
return null;
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
function getPanelElementsForGroup(groupId) {
|
|
1648
|
+
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|
package/package.json
CHANGED
package/src/Panel.ts
CHANGED
|
@@ -4,10 +4,10 @@ import { PanelGroupContext } from "./PanelGroupContext";
|
|
|
4
4
|
import useIsomorphicLayoutEffect from "./hooks/useIsomorphicEffect";
|
|
5
5
|
import useUniqueId from "./hooks/useUniqueId";
|
|
6
6
|
import {
|
|
7
|
-
ElementType,
|
|
8
7
|
ForwardedRef,
|
|
9
8
|
HTMLAttributes,
|
|
10
9
|
PropsWithChildren,
|
|
10
|
+
ReactNode,
|
|
11
11
|
createElement,
|
|
12
12
|
forwardRef,
|
|
13
13
|
useContext,
|
|
@@ -54,7 +54,10 @@ export type ImperativePanelHandle = {
|
|
|
54
54
|
resize: (size: number) => void;
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
export type PanelProps = Omit<
|
|
57
|
+
export type PanelProps = Omit<
|
|
58
|
+
HTMLAttributes<keyof HTMLElementTagNameMap>,
|
|
59
|
+
"id" | "onResize"
|
|
60
|
+
> &
|
|
58
61
|
PropsWithChildren<{
|
|
59
62
|
className?: string;
|
|
60
63
|
collapsedSize?: number | undefined;
|
|
@@ -68,7 +71,7 @@ export type PanelProps = Omit<HTMLAttributes<ElementType>, "id" | "onResize"> &
|
|
|
68
71
|
onResize?: PanelOnResize;
|
|
69
72
|
order?: number;
|
|
70
73
|
style?: object;
|
|
71
|
-
tagName?:
|
|
74
|
+
tagName?: keyof HTMLElementTagNameMap;
|
|
72
75
|
}>;
|
|
73
76
|
|
|
74
77
|
export function PanelWithForwardedRef({
|
|
@@ -90,7 +93,7 @@ export function PanelWithForwardedRef({
|
|
|
90
93
|
...rest
|
|
91
94
|
}: PanelProps & {
|
|
92
95
|
forwardedRef: ForwardedRef<ImperativePanelHandle>;
|
|
93
|
-
}) {
|
|
96
|
+
}): ReactNode {
|
|
94
97
|
const context = useContext(PanelGroupContext);
|
|
95
98
|
if (context === null) {
|
|
96
99
|
throw Error(
|
package/src/PanelGroup.ts
CHANGED
|
@@ -28,10 +28,10 @@ import { validatePanelConstraints } from "./utils/validatePanelConstraints";
|
|
|
28
28
|
import { validatePanelGroupLayout } from "./utils/validatePanelGroupLayout";
|
|
29
29
|
import {
|
|
30
30
|
CSSProperties,
|
|
31
|
-
ElementType,
|
|
32
31
|
ForwardedRef,
|
|
33
32
|
HTMLAttributes,
|
|
34
33
|
PropsWithChildren,
|
|
34
|
+
ReactNode,
|
|
35
35
|
createElement,
|
|
36
36
|
forwardRef,
|
|
37
37
|
useCallback,
|
|
@@ -68,7 +68,10 @@ const defaultStorage: PanelGroupStorage = {
|
|
|
68
68
|
},
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
export type PanelGroupProps = Omit<
|
|
71
|
+
export type PanelGroupProps = Omit<
|
|
72
|
+
HTMLAttributes<keyof HTMLElementTagNameMap>,
|
|
73
|
+
"id"
|
|
74
|
+
> &
|
|
72
75
|
PropsWithChildren<{
|
|
73
76
|
autoSaveId?: string | null;
|
|
74
77
|
className?: string;
|
|
@@ -78,7 +81,7 @@ export type PanelGroupProps = Omit<HTMLAttributes<ElementType>, "id"> &
|
|
|
78
81
|
onLayout?: PanelGroupOnLayout | null;
|
|
79
82
|
storage?: PanelGroupStorage;
|
|
80
83
|
style?: CSSProperties;
|
|
81
|
-
tagName?:
|
|
84
|
+
tagName?: keyof HTMLElementTagNameMap;
|
|
82
85
|
}>;
|
|
83
86
|
|
|
84
87
|
const debounceMap: {
|
|
@@ -100,7 +103,7 @@ function PanelGroupWithForwardedRef({
|
|
|
100
103
|
...rest
|
|
101
104
|
}: PanelGroupProps & {
|
|
102
105
|
forwardedRef: ForwardedRef<ImperativePanelGroupHandle>;
|
|
103
|
-
}) {
|
|
106
|
+
}): ReactNode {
|
|
104
107
|
const groupId = useUniqueId(idFromProps);
|
|
105
108
|
|
|
106
109
|
const [dragState, setDragState] = useState<DragState | null>(null);
|
package/src/PanelResizeHandle.ts
CHANGED
|
@@ -2,10 +2,10 @@ import useUniqueId from "./hooks/useUniqueId";
|
|
|
2
2
|
import {
|
|
3
3
|
createElement,
|
|
4
4
|
CSSProperties,
|
|
5
|
-
ElementType,
|
|
6
5
|
HTMLAttributes,
|
|
7
6
|
PropsWithChildren,
|
|
8
7
|
MouseEvent as ReactMouseEvent,
|
|
8
|
+
ReactNode,
|
|
9
9
|
TouchEvent,
|
|
10
10
|
useCallback,
|
|
11
11
|
useContext,
|
|
@@ -25,7 +25,10 @@ import { getCursorStyle } from "./utils/cursor";
|
|
|
25
25
|
|
|
26
26
|
export type PanelResizeHandleOnDragging = (isDragging: boolean) => void;
|
|
27
27
|
|
|
28
|
-
export type PanelResizeHandleProps = Omit<
|
|
28
|
+
export type PanelResizeHandleProps = Omit<
|
|
29
|
+
HTMLAttributes<keyof HTMLElementTagNameMap>,
|
|
30
|
+
"id"
|
|
31
|
+
> &
|
|
29
32
|
PropsWithChildren<{
|
|
30
33
|
className?: string;
|
|
31
34
|
disabled?: boolean;
|
|
@@ -33,7 +36,7 @@ export type PanelResizeHandleProps = Omit<HTMLAttributes<ElementType>, "id"> &
|
|
|
33
36
|
onDragging?: PanelResizeHandleOnDragging;
|
|
34
37
|
style?: CSSProperties;
|
|
35
38
|
tabIndex?: number;
|
|
36
|
-
tagName?:
|
|
39
|
+
tagName?: keyof HTMLElementTagNameMap;
|
|
37
40
|
}>;
|
|
38
41
|
|
|
39
42
|
export function PanelResizeHandle({
|
|
@@ -46,8 +49,8 @@ export function PanelResizeHandle({
|
|
|
46
49
|
tabIndex = 0,
|
|
47
50
|
tagName: Type = "div",
|
|
48
51
|
...rest
|
|
49
|
-
}: PanelResizeHandleProps) {
|
|
50
|
-
const
|
|
52
|
+
}: PanelResizeHandleProps): ReactNode {
|
|
53
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
51
54
|
|
|
52
55
|
// Use a ref to guard against users passing inline props
|
|
53
56
|
const callbacksRef = useRef<{
|
|
@@ -85,9 +88,9 @@ export function PanelResizeHandle({
|
|
|
85
88
|
const stopDraggingAndBlur = useCallback(() => {
|
|
86
89
|
// Clicking on the drag handle shouldn't leave it focused;
|
|
87
90
|
// That would cause the PanelGroup to think it was still active.
|
|
88
|
-
const
|
|
89
|
-
assert(
|
|
90
|
-
|
|
91
|
+
const element = elementRef.current;
|
|
92
|
+
assert(element);
|
|
93
|
+
element.blur();
|
|
91
94
|
|
|
92
95
|
stopDragging();
|
|
93
96
|
|
|
@@ -119,10 +122,10 @@ export function PanelResizeHandle({
|
|
|
119
122
|
resizeHandler(event);
|
|
120
123
|
};
|
|
121
124
|
|
|
122
|
-
const
|
|
123
|
-
assert(
|
|
125
|
+
const element = elementRef.current;
|
|
126
|
+
assert(element);
|
|
124
127
|
|
|
125
|
-
const targetDocument =
|
|
128
|
+
const targetDocument = element.ownerDocument;
|
|
126
129
|
|
|
127
130
|
targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
|
|
128
131
|
targetDocument.body.addEventListener("mousemove", onMove);
|
|
@@ -186,7 +189,7 @@ export function PanelResizeHandle({
|
|
|
186
189
|
onDragging(true);
|
|
187
190
|
}
|
|
188
191
|
},
|
|
189
|
-
ref:
|
|
192
|
+
ref: elementRef,
|
|
190
193
|
role: "separator",
|
|
191
194
|
style: {
|
|
192
195
|
...style,
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,15 @@ import { Panel } from "./Panel";
|
|
|
2
2
|
import { PanelGroup } from "./PanelGroup";
|
|
3
3
|
import { PanelResizeHandle } from "./PanelResizeHandle";
|
|
4
4
|
import { assert } from "./utils/assert";
|
|
5
|
+
import { calculateAvailablePanelSizeInPixels } from "./utils/dom/calculateAvailablePanelSizeInPixels";
|
|
6
|
+
import { getAvailableGroupSizePixels } from "./utils/dom/getAvailableGroupSizePixels";
|
|
7
|
+
import { getPanelElement } from "./utils/dom/getPanelElement";
|
|
8
|
+
import { getPanelElementsForGroup } from "./utils/dom/getPanelElementsForGroup";
|
|
9
|
+
import { getPanelGroupElement } from "./utils/dom/getPanelGroupElement";
|
|
10
|
+
import { getResizeHandleElement } from "./utils/dom/getResizeHandleElement";
|
|
11
|
+
import { getResizeHandleElementIndex } from "./utils/dom/getResizeHandleElementIndex";
|
|
12
|
+
import { getResizeHandleElementsForGroup } from "./utils/dom/getResizeHandleElementsForGroup";
|
|
13
|
+
import { getResizeHandlePanelIds } from "./utils/dom/getResizeHandlePanelIds";
|
|
5
14
|
|
|
6
15
|
import type {
|
|
7
16
|
ImperativePanelHandle,
|
|
@@ -35,11 +44,22 @@ export {
|
|
|
35
44
|
PanelResizeHandleOnDragging,
|
|
36
45
|
PanelResizeHandleProps,
|
|
37
46
|
|
|
38
|
-
// Utiltiy methods
|
|
39
|
-
assert,
|
|
40
|
-
|
|
41
47
|
// React components
|
|
42
48
|
Panel,
|
|
43
49
|
PanelGroup,
|
|
44
50
|
PanelResizeHandle,
|
|
51
|
+
|
|
52
|
+
// Utility methods
|
|
53
|
+
assert,
|
|
54
|
+
|
|
55
|
+
// DOM helpers
|
|
56
|
+
calculateAvailablePanelSizeInPixels,
|
|
57
|
+
getAvailableGroupSizePixels,
|
|
58
|
+
getPanelElement,
|
|
59
|
+
getPanelElementsForGroup,
|
|
60
|
+
getPanelGroupElement,
|
|
61
|
+
getResizeHandleElement,
|
|
62
|
+
getResizeHandleElementIndex,
|
|
63
|
+
getResizeHandleElementsForGroup,
|
|
64
|
+
getResizeHandlePanelIds,
|
|
45
65
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function getPanelElement(id: string):
|
|
1
|
+
export function getPanelElement(id: string): HTMLElement | null {
|
|
2
2
|
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
3
3
|
if (element) {
|
|
4
|
-
return element as
|
|
4
|
+
return element as HTMLElement;
|
|
5
5
|
}
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export function getPanelGroupElement(id: string):
|
|
1
|
+
export function getPanelGroupElement(id: string): HTMLElement | null {
|
|
2
2
|
const element = document.querySelector(
|
|
3
3
|
`[data-panel-group][data-panel-group-id="${id}"]`
|
|
4
4
|
);
|
|
5
5
|
if (element) {
|
|
6
|
-
return element as
|
|
6
|
+
return element as HTMLElement;
|
|
7
7
|
}
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export function getResizeHandleElement(id: string):
|
|
1
|
+
export function getResizeHandleElement(id: string): HTMLElement | null {
|
|
2
2
|
const element = document.querySelector(
|
|
3
3
|
`[data-panel-resize-handle-id="${id}"]`
|
|
4
4
|
);
|
|
5
5
|
if (element) {
|
|
6
|
-
return element as
|
|
6
|
+
return element as HTMLElement;
|
|
7
7
|
}
|
|
8
8
|
return null;
|
|
9
9
|
}
|