react-resizable-panels 1.0.4 → 1.0.6
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 -1
- package/README.md +202 -15
- 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 +66 -5
- package/dist/react-resizable-panels.browser.cjs.mjs +10 -1
- package/dist/react-resizable-panels.browser.development.cjs.js +66 -5
- package/dist/react-resizable-panels.browser.development.cjs.mjs +10 -1
- package/dist/react-resizable-panels.browser.development.esm.js +58 -6
- package/dist/react-resizable-panels.browser.esm.js +58 -6
- package/dist/react-resizable-panels.cjs.js +66 -5
- package/dist/react-resizable-panels.cjs.mjs +10 -1
- package/dist/react-resizable-panels.development.cjs.js +66 -5
- package/dist/react-resizable-panels.development.cjs.mjs +10 -1
- package/dist/react-resizable-panels.development.esm.js +58 -6
- package/dist/react-resizable-panels.development.node.cjs.js +66 -5
- package/dist/react-resizable-panels.development.node.cjs.mjs +10 -1
- package/dist/react-resizable-panels.development.node.esm.js +58 -6
- package/dist/react-resizable-panels.esm.js +58 -6
- package/dist/react-resizable-panels.node.cjs.js +66 -5
- package/dist/react-resizable-panels.node.cjs.mjs +10 -1
- package/dist/react-resizable-panels.node.esm.js +58 -6
- package/package.json +1 -1
- package/src/Panel.ts +1 -1
- package/src/PanelGroup.ts +2 -1
- package/src/PanelGroupContext.ts +4 -1
- package/src/index.ts +23 -3
- package/src/utils/computePanelFlexBoxStyle.ts +7 -3
|
@@ -139,7 +139,7 @@ function PanelWithForwardedRef({
|
|
|
139
139
|
resizePanel(panelDataRef.current, size);
|
|
140
140
|
}
|
|
141
141
|
}), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
|
|
142
|
-
const style = getPanelStyle(panelDataRef.current);
|
|
142
|
+
const style = getPanelStyle(panelDataRef.current, defaultSize);
|
|
143
143
|
return createElement(Type, {
|
|
144
144
|
...rest,
|
|
145
145
|
children,
|
|
@@ -834,6 +834,7 @@ function compareLayouts(a, b) {
|
|
|
834
834
|
|
|
835
835
|
// the % of the group's overall space this panel should occupy.
|
|
836
836
|
function computePanelFlexBoxStyle({
|
|
837
|
+
defaultSize,
|
|
837
838
|
dragState,
|
|
838
839
|
layout,
|
|
839
840
|
panelData,
|
|
@@ -842,10 +843,12 @@ function computePanelFlexBoxStyle({
|
|
|
842
843
|
}) {
|
|
843
844
|
const size = layout[panelIndex];
|
|
844
845
|
let flexGrow;
|
|
845
|
-
if (
|
|
846
|
-
flexGrow = "1";
|
|
847
|
-
} else if (size == null) {
|
|
846
|
+
if (size == null) {
|
|
848
847
|
// Initial render (before panels have registered themselves)
|
|
848
|
+
// In order to support server rendering, fall back to default size if provided
|
|
849
|
+
flexGrow = defaultSize !== null && defaultSize !== void 0 ? defaultSize : "1";
|
|
850
|
+
} else if (panelData.length === 1) {
|
|
851
|
+
// Special case: Single panel group should always fill full width/height
|
|
849
852
|
flexGrow = "1";
|
|
850
853
|
} else {
|
|
851
854
|
flexGrow = size.toPrecision(precision);
|
|
@@ -1282,12 +1285,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1282
1285
|
}, []);
|
|
1283
1286
|
|
|
1284
1287
|
// This API should never read from committedValuesRef
|
|
1285
|
-
const getPanelStyle = useCallback(panelData => {
|
|
1288
|
+
const getPanelStyle = useCallback((panelData, defaultSize) => {
|
|
1286
1289
|
const {
|
|
1287
1290
|
panelDataArray
|
|
1288
1291
|
} = eagerValuesRef.current;
|
|
1289
1292
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1290
1293
|
return computePanelFlexBoxStyle({
|
|
1294
|
+
defaultSize,
|
|
1291
1295
|
dragState,
|
|
1292
1296
|
layout,
|
|
1293
1297
|
panelData: panelDataArray,
|
|
@@ -1795,4 +1799,52 @@ function PanelResizeHandle({
|
|
|
1795
1799
|
}
|
|
1796
1800
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1797
1801
|
|
|
1798
|
-
|
|
1802
|
+
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1803
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1804
|
+
if (panelGroupElement == null) {
|
|
1805
|
+
return NaN;
|
|
1806
|
+
}
|
|
1807
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1808
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1809
|
+
if (direction === "horizontal") {
|
|
1810
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1811
|
+
return accumulated + handle.offsetWidth;
|
|
1812
|
+
}, 0);
|
|
1813
|
+
} else {
|
|
1814
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1815
|
+
return accumulated + handle.offsetHeight;
|
|
1816
|
+
}, 0);
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
function getAvailableGroupSizePixels(groupId) {
|
|
1821
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1822
|
+
if (panelGroupElement == null) {
|
|
1823
|
+
return NaN;
|
|
1824
|
+
}
|
|
1825
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1826
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1827
|
+
if (direction === "horizontal") {
|
|
1828
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1829
|
+
return accumulated + handle.offsetWidth;
|
|
1830
|
+
}, 0);
|
|
1831
|
+
} else {
|
|
1832
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1833
|
+
return accumulated + handle.offsetHeight;
|
|
1834
|
+
}, 0);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
function getPanelElement(id) {
|
|
1839
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1840
|
+
if (element) {
|
|
1841
|
+
return element;
|
|
1842
|
+
}
|
|
1843
|
+
return null;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
function getPanelElementsForGroup(groupId) {
|
|
1847
|
+
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|
|
@@ -165,7 +165,7 @@ function PanelWithForwardedRef({
|
|
|
165
165
|
resizePanel(panelDataRef.current, size);
|
|
166
166
|
}
|
|
167
167
|
}), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
|
|
168
|
-
const style = getPanelStyle(panelDataRef.current);
|
|
168
|
+
const style = getPanelStyle(panelDataRef.current, defaultSize);
|
|
169
169
|
return createElement(Type, {
|
|
170
170
|
...rest,
|
|
171
171
|
children,
|
|
@@ -860,6 +860,7 @@ function compareLayouts(a, b) {
|
|
|
860
860
|
|
|
861
861
|
// the % of the group's overall space this panel should occupy.
|
|
862
862
|
function computePanelFlexBoxStyle({
|
|
863
|
+
defaultSize,
|
|
863
864
|
dragState,
|
|
864
865
|
layout,
|
|
865
866
|
panelData,
|
|
@@ -868,10 +869,12 @@ function computePanelFlexBoxStyle({
|
|
|
868
869
|
}) {
|
|
869
870
|
const size = layout[panelIndex];
|
|
870
871
|
let flexGrow;
|
|
871
|
-
if (
|
|
872
|
-
flexGrow = "1";
|
|
873
|
-
} else if (size == null) {
|
|
872
|
+
if (size == null) {
|
|
874
873
|
// Initial render (before panels have registered themselves)
|
|
874
|
+
// In order to support server rendering, fall back to default size if provided
|
|
875
|
+
flexGrow = defaultSize !== null && defaultSize !== void 0 ? defaultSize : "1";
|
|
876
|
+
} else if (panelData.length === 1) {
|
|
877
|
+
// Special case: Single panel group should always fill full width/height
|
|
875
878
|
flexGrow = "1";
|
|
876
879
|
} else {
|
|
877
880
|
flexGrow = size.toPrecision(precision);
|
|
@@ -1308,12 +1311,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1308
1311
|
}, []);
|
|
1309
1312
|
|
|
1310
1313
|
// This API should never read from committedValuesRef
|
|
1311
|
-
const getPanelStyle = useCallback(panelData => {
|
|
1314
|
+
const getPanelStyle = useCallback((panelData, defaultSize) => {
|
|
1312
1315
|
const {
|
|
1313
1316
|
panelDataArray
|
|
1314
1317
|
} = eagerValuesRef.current;
|
|
1315
1318
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1316
1319
|
return computePanelFlexBoxStyle({
|
|
1320
|
+
defaultSize,
|
|
1317
1321
|
dragState,
|
|
1318
1322
|
layout,
|
|
1319
1323
|
panelData: panelDataArray,
|
|
@@ -1821,7 +1825,64 @@ function PanelResizeHandle({
|
|
|
1821
1825
|
}
|
|
1822
1826
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1823
1827
|
|
|
1828
|
+
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1829
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1830
|
+
if (panelGroupElement == null) {
|
|
1831
|
+
return NaN;
|
|
1832
|
+
}
|
|
1833
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1834
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1835
|
+
if (direction === "horizontal") {
|
|
1836
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1837
|
+
return accumulated + handle.offsetWidth;
|
|
1838
|
+
}, 0);
|
|
1839
|
+
} else {
|
|
1840
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1841
|
+
return accumulated + handle.offsetHeight;
|
|
1842
|
+
}, 0);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
function getAvailableGroupSizePixels(groupId) {
|
|
1847
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1848
|
+
if (panelGroupElement == null) {
|
|
1849
|
+
return NaN;
|
|
1850
|
+
}
|
|
1851
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1852
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1853
|
+
if (direction === "horizontal") {
|
|
1854
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1855
|
+
return accumulated + handle.offsetWidth;
|
|
1856
|
+
}, 0);
|
|
1857
|
+
} else {
|
|
1858
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1859
|
+
return accumulated + handle.offsetHeight;
|
|
1860
|
+
}, 0);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
function getPanelElement(id) {
|
|
1865
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1866
|
+
if (element) {
|
|
1867
|
+
return element;
|
|
1868
|
+
}
|
|
1869
|
+
return null;
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
function getPanelElementsForGroup(groupId) {
|
|
1873
|
+
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1824
1876
|
exports.Panel = Panel;
|
|
1825
1877
|
exports.PanelGroup = PanelGroup;
|
|
1826
1878
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1827
1879
|
exports.assert = assert;
|
|
1880
|
+
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1881
|
+
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1882
|
+
exports.getPanelElement = getPanelElement;
|
|
1883
|
+
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1884
|
+
exports.getPanelGroupElement = getPanelGroupElement;
|
|
1885
|
+
exports.getResizeHandleElement = getResizeHandleElement;
|
|
1886
|
+
exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
|
|
1887
|
+
exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
|
|
1888
|
+
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.cjs.js";
|
|
@@ -176,7 +176,7 @@ function PanelWithForwardedRef({
|
|
|
176
176
|
resizePanel(panelDataRef.current, size);
|
|
177
177
|
}
|
|
178
178
|
}), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
|
|
179
|
-
const style = getPanelStyle(panelDataRef.current);
|
|
179
|
+
const style = getPanelStyle(panelDataRef.current, defaultSize);
|
|
180
180
|
return createElement(Type, {
|
|
181
181
|
...rest,
|
|
182
182
|
children,
|
|
@@ -881,6 +881,7 @@ function compareLayouts(a, b) {
|
|
|
881
881
|
|
|
882
882
|
// the % of the group's overall space this panel should occupy.
|
|
883
883
|
function computePanelFlexBoxStyle({
|
|
884
|
+
defaultSize,
|
|
884
885
|
dragState,
|
|
885
886
|
layout,
|
|
886
887
|
panelData,
|
|
@@ -889,10 +890,12 @@ function computePanelFlexBoxStyle({
|
|
|
889
890
|
}) {
|
|
890
891
|
const size = layout[panelIndex];
|
|
891
892
|
let flexGrow;
|
|
892
|
-
if (
|
|
893
|
-
flexGrow = "1";
|
|
894
|
-
} else if (size == null) {
|
|
893
|
+
if (size == null) {
|
|
895
894
|
// Initial render (before panels have registered themselves)
|
|
895
|
+
// In order to support server rendering, fall back to default size if provided
|
|
896
|
+
flexGrow = defaultSize !== null && defaultSize !== void 0 ? defaultSize : "1";
|
|
897
|
+
} else if (panelData.length === 1) {
|
|
898
|
+
// Special case: Single panel group should always fill full width/height
|
|
896
899
|
flexGrow = "1";
|
|
897
900
|
} else {
|
|
898
901
|
flexGrow = size.toPrecision(precision);
|
|
@@ -1418,12 +1421,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1418
1421
|
}, []);
|
|
1419
1422
|
|
|
1420
1423
|
// This API should never read from committedValuesRef
|
|
1421
|
-
const getPanelStyle = useCallback(panelData => {
|
|
1424
|
+
const getPanelStyle = useCallback((panelData, defaultSize) => {
|
|
1422
1425
|
const {
|
|
1423
1426
|
panelDataArray
|
|
1424
1427
|
} = eagerValuesRef.current;
|
|
1425
1428
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1426
1429
|
return computePanelFlexBoxStyle({
|
|
1430
|
+
defaultSize,
|
|
1427
1431
|
dragState,
|
|
1428
1432
|
layout,
|
|
1429
1433
|
panelData: panelDataArray,
|
|
@@ -1931,7 +1935,64 @@ function PanelResizeHandle({
|
|
|
1931
1935
|
}
|
|
1932
1936
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1933
1937
|
|
|
1938
|
+
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1939
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1940
|
+
if (panelGroupElement == null) {
|
|
1941
|
+
return NaN;
|
|
1942
|
+
}
|
|
1943
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1944
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1945
|
+
if (direction === "horizontal") {
|
|
1946
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1947
|
+
return accumulated + handle.offsetWidth;
|
|
1948
|
+
}, 0);
|
|
1949
|
+
} else {
|
|
1950
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1951
|
+
return accumulated + handle.offsetHeight;
|
|
1952
|
+
}, 0);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
function getAvailableGroupSizePixels(groupId) {
|
|
1957
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1958
|
+
if (panelGroupElement == null) {
|
|
1959
|
+
return NaN;
|
|
1960
|
+
}
|
|
1961
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1962
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1963
|
+
if (direction === "horizontal") {
|
|
1964
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1965
|
+
return accumulated + handle.offsetWidth;
|
|
1966
|
+
}, 0);
|
|
1967
|
+
} else {
|
|
1968
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1969
|
+
return accumulated + handle.offsetHeight;
|
|
1970
|
+
}, 0);
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
function getPanelElement(id) {
|
|
1975
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1976
|
+
if (element) {
|
|
1977
|
+
return element;
|
|
1978
|
+
}
|
|
1979
|
+
return null;
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
function getPanelElementsForGroup(groupId) {
|
|
1983
|
+
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1934
1986
|
exports.Panel = Panel;
|
|
1935
1987
|
exports.PanelGroup = PanelGroup;
|
|
1936
1988
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1937
1989
|
exports.assert = assert;
|
|
1990
|
+
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1991
|
+
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1992
|
+
exports.getPanelElement = getPanelElement;
|
|
1993
|
+
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1994
|
+
exports.getPanelGroupElement = getPanelGroupElement;
|
|
1995
|
+
exports.getResizeHandleElement = getResizeHandleElement;
|
|
1996
|
+
exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
|
|
1997
|
+
exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
|
|
1998
|
+
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.development.cjs.js";
|
|
@@ -152,7 +152,7 @@ function PanelWithForwardedRef({
|
|
|
152
152
|
resizePanel(panelDataRef.current, size);
|
|
153
153
|
}
|
|
154
154
|
}), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
|
|
155
|
-
const style = getPanelStyle(panelDataRef.current);
|
|
155
|
+
const style = getPanelStyle(panelDataRef.current, defaultSize);
|
|
156
156
|
return createElement(Type, {
|
|
157
157
|
...rest,
|
|
158
158
|
children,
|
|
@@ -857,6 +857,7 @@ function compareLayouts(a, b) {
|
|
|
857
857
|
|
|
858
858
|
// the % of the group's overall space this panel should occupy.
|
|
859
859
|
function computePanelFlexBoxStyle({
|
|
860
|
+
defaultSize,
|
|
860
861
|
dragState,
|
|
861
862
|
layout,
|
|
862
863
|
panelData,
|
|
@@ -865,10 +866,12 @@ function computePanelFlexBoxStyle({
|
|
|
865
866
|
}) {
|
|
866
867
|
const size = layout[panelIndex];
|
|
867
868
|
let flexGrow;
|
|
868
|
-
if (
|
|
869
|
-
flexGrow = "1";
|
|
870
|
-
} else if (size == null) {
|
|
869
|
+
if (size == null) {
|
|
871
870
|
// Initial render (before panels have registered themselves)
|
|
871
|
+
// In order to support server rendering, fall back to default size if provided
|
|
872
|
+
flexGrow = defaultSize !== null && defaultSize !== void 0 ? defaultSize : "1";
|
|
873
|
+
} else if (panelData.length === 1) {
|
|
874
|
+
// Special case: Single panel group should always fill full width/height
|
|
872
875
|
flexGrow = "1";
|
|
873
876
|
} else {
|
|
874
877
|
flexGrow = size.toPrecision(precision);
|
|
@@ -1394,12 +1397,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1394
1397
|
}, []);
|
|
1395
1398
|
|
|
1396
1399
|
// This API should never read from committedValuesRef
|
|
1397
|
-
const getPanelStyle = useCallback(panelData => {
|
|
1400
|
+
const getPanelStyle = useCallback((panelData, defaultSize) => {
|
|
1398
1401
|
const {
|
|
1399
1402
|
panelDataArray
|
|
1400
1403
|
} = eagerValuesRef.current;
|
|
1401
1404
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1402
1405
|
return computePanelFlexBoxStyle({
|
|
1406
|
+
defaultSize,
|
|
1403
1407
|
dragState,
|
|
1404
1408
|
layout,
|
|
1405
1409
|
panelData: panelDataArray,
|
|
@@ -1907,4 +1911,52 @@ function PanelResizeHandle({
|
|
|
1907
1911
|
}
|
|
1908
1912
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1909
1913
|
|
|
1910
|
-
|
|
1914
|
+
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1915
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1916
|
+
if (panelGroupElement == null) {
|
|
1917
|
+
return NaN;
|
|
1918
|
+
}
|
|
1919
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1920
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1921
|
+
if (direction === "horizontal") {
|
|
1922
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1923
|
+
return accumulated + handle.offsetWidth;
|
|
1924
|
+
}, 0);
|
|
1925
|
+
} else {
|
|
1926
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1927
|
+
return accumulated + handle.offsetHeight;
|
|
1928
|
+
}, 0);
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
function getAvailableGroupSizePixels(groupId) {
|
|
1933
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1934
|
+
if (panelGroupElement == null) {
|
|
1935
|
+
return NaN;
|
|
1936
|
+
}
|
|
1937
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1938
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1939
|
+
if (direction === "horizontal") {
|
|
1940
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1941
|
+
return accumulated + handle.offsetWidth;
|
|
1942
|
+
}, 0);
|
|
1943
|
+
} else {
|
|
1944
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1945
|
+
return accumulated + handle.offsetHeight;
|
|
1946
|
+
}, 0);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
function getPanelElement(id) {
|
|
1951
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1952
|
+
if (element) {
|
|
1953
|
+
return element;
|
|
1954
|
+
}
|
|
1955
|
+
return null;
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
function getPanelElementsForGroup(groupId) {
|
|
1959
|
+
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|
|
@@ -148,7 +148,7 @@ function PanelWithForwardedRef({
|
|
|
148
148
|
resizePanel(panelDataRef.current, size);
|
|
149
149
|
}
|
|
150
150
|
}), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
|
|
151
|
-
const style = getPanelStyle(panelDataRef.current);
|
|
151
|
+
const style = getPanelStyle(panelDataRef.current, defaultSize);
|
|
152
152
|
return createElement(Type, {
|
|
153
153
|
...rest,
|
|
154
154
|
children,
|
|
@@ -732,6 +732,7 @@ function compareLayouts(a, b) {
|
|
|
732
732
|
|
|
733
733
|
// the % of the group's overall space this panel should occupy.
|
|
734
734
|
function computePanelFlexBoxStyle({
|
|
735
|
+
defaultSize,
|
|
735
736
|
dragState,
|
|
736
737
|
layout,
|
|
737
738
|
panelData,
|
|
@@ -740,10 +741,12 @@ function computePanelFlexBoxStyle({
|
|
|
740
741
|
}) {
|
|
741
742
|
const size = layout[panelIndex];
|
|
742
743
|
let flexGrow;
|
|
743
|
-
if (
|
|
744
|
-
flexGrow = "1";
|
|
745
|
-
} else if (size == null) {
|
|
744
|
+
if (size == null) {
|
|
746
745
|
// Initial render (before panels have registered themselves)
|
|
746
|
+
// In order to support server rendering, fall back to default size if provided
|
|
747
|
+
flexGrow = defaultSize !== null && defaultSize !== void 0 ? defaultSize : "1";
|
|
748
|
+
} else if (panelData.length === 1) {
|
|
749
|
+
// Special case: Single panel group should always fill full width/height
|
|
747
750
|
flexGrow = "1";
|
|
748
751
|
} else {
|
|
749
752
|
flexGrow = size.toPrecision(precision);
|
|
@@ -1255,12 +1258,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1255
1258
|
}, []);
|
|
1256
1259
|
|
|
1257
1260
|
// This API should never read from committedValuesRef
|
|
1258
|
-
const getPanelStyle = useCallback(panelData => {
|
|
1261
|
+
const getPanelStyle = useCallback((panelData, defaultSize) => {
|
|
1259
1262
|
const {
|
|
1260
1263
|
panelDataArray
|
|
1261
1264
|
} = eagerValuesRef.current;
|
|
1262
1265
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1263
1266
|
return computePanelFlexBoxStyle({
|
|
1267
|
+
defaultSize,
|
|
1264
1268
|
dragState,
|
|
1265
1269
|
layout,
|
|
1266
1270
|
panelData: panelDataArray,
|
|
@@ -1720,7 +1724,64 @@ function PanelResizeHandle({
|
|
|
1720
1724
|
}
|
|
1721
1725
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1722
1726
|
|
|
1727
|
+
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1728
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1729
|
+
if (panelGroupElement == null) {
|
|
1730
|
+
return NaN;
|
|
1731
|
+
}
|
|
1732
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1733
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1734
|
+
if (direction === "horizontal") {
|
|
1735
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1736
|
+
return accumulated + handle.offsetWidth;
|
|
1737
|
+
}, 0);
|
|
1738
|
+
} else {
|
|
1739
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1740
|
+
return accumulated + handle.offsetHeight;
|
|
1741
|
+
}, 0);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
function getAvailableGroupSizePixels(groupId) {
|
|
1746
|
+
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1747
|
+
if (panelGroupElement == null) {
|
|
1748
|
+
return NaN;
|
|
1749
|
+
}
|
|
1750
|
+
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1751
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1752
|
+
if (direction === "horizontal") {
|
|
1753
|
+
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1754
|
+
return accumulated + handle.offsetWidth;
|
|
1755
|
+
}, 0);
|
|
1756
|
+
} else {
|
|
1757
|
+
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1758
|
+
return accumulated + handle.offsetHeight;
|
|
1759
|
+
}, 0);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
function getPanelElement(id) {
|
|
1764
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1765
|
+
if (element) {
|
|
1766
|
+
return element;
|
|
1767
|
+
}
|
|
1768
|
+
return null;
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
function getPanelElementsForGroup(groupId) {
|
|
1772
|
+
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1723
1775
|
exports.Panel = Panel;
|
|
1724
1776
|
exports.PanelGroup = PanelGroup;
|
|
1725
1777
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1726
1778
|
exports.assert = assert;
|
|
1779
|
+
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1780
|
+
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1781
|
+
exports.getPanelElement = getPanelElement;
|
|
1782
|
+
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1783
|
+
exports.getPanelGroupElement = getPanelGroupElement;
|
|
1784
|
+
exports.getResizeHandleElement = getResizeHandleElement;
|
|
1785
|
+
exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
|
|
1786
|
+
exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
|
|
1787
|
+
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.development.node.cjs.js";
|
|
@@ -124,7 +124,7 @@ function PanelWithForwardedRef({
|
|
|
124
124
|
resizePanel(panelDataRef.current, size);
|
|
125
125
|
}
|
|
126
126
|
}), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
|
|
127
|
-
const style = getPanelStyle(panelDataRef.current);
|
|
127
|
+
const style = getPanelStyle(panelDataRef.current, defaultSize);
|
|
128
128
|
return createElement(Type, {
|
|
129
129
|
...rest,
|
|
130
130
|
children,
|
|
@@ -708,6 +708,7 @@ function compareLayouts(a, b) {
|
|
|
708
708
|
|
|
709
709
|
// the % of the group's overall space this panel should occupy.
|
|
710
710
|
function computePanelFlexBoxStyle({
|
|
711
|
+
defaultSize,
|
|
711
712
|
dragState,
|
|
712
713
|
layout,
|
|
713
714
|
panelData,
|
|
@@ -716,10 +717,12 @@ function computePanelFlexBoxStyle({
|
|
|
716
717
|
}) {
|
|
717
718
|
const size = layout[panelIndex];
|
|
718
719
|
let flexGrow;
|
|
719
|
-
if (
|
|
720
|
-
flexGrow = "1";
|
|
721
|
-
} else if (size == null) {
|
|
720
|
+
if (size == null) {
|
|
722
721
|
// Initial render (before panels have registered themselves)
|
|
722
|
+
// In order to support server rendering, fall back to default size if provided
|
|
723
|
+
flexGrow = defaultSize !== null && defaultSize !== void 0 ? defaultSize : "1";
|
|
724
|
+
} else if (panelData.length === 1) {
|
|
725
|
+
// Special case: Single panel group should always fill full width/height
|
|
723
726
|
flexGrow = "1";
|
|
724
727
|
} else {
|
|
725
728
|
flexGrow = size.toPrecision(precision);
|
|
@@ -1231,12 +1234,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1231
1234
|
}, []);
|
|
1232
1235
|
|
|
1233
1236
|
// This API should never read from committedValuesRef
|
|
1234
|
-
const getPanelStyle = useCallback(panelData => {
|
|
1237
|
+
const getPanelStyle = useCallback((panelData, defaultSize) => {
|
|
1235
1238
|
const {
|
|
1236
1239
|
panelDataArray
|
|
1237
1240
|
} = eagerValuesRef.current;
|
|
1238
1241
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1239
1242
|
return computePanelFlexBoxStyle({
|
|
1243
|
+
defaultSize,
|
|
1240
1244
|
dragState,
|
|
1241
1245
|
layout,
|
|
1242
1246
|
panelData: panelDataArray,
|
|
@@ -1696,4 +1700,52 @@ function PanelResizeHandle({
|
|
|
1696
1700
|
}
|
|
1697
1701
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1698
1702
|
|
|
1699
|
-
|
|
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 };
|