react-resizable-panels 1.0.5 → 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.
Files changed (32) hide show
  1. package/CHANGELOG.md +6 -2
  2. package/README.md +191 -1
  3. package/dist/declarations/src/index.d.ts +10 -1
  4. package/dist/declarations/src/utils/dom/calculateAvailablePanelSizeInPixels.d.ts +1 -0
  5. package/dist/declarations/src/utils/dom/getAvailableGroupSizePixels.d.ts +1 -0
  6. package/dist/declarations/src/utils/dom/getPanelElement.d.ts +1 -0
  7. package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +1 -0
  8. package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +1 -0
  9. package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +1 -0
  10. package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +1 -0
  11. package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +1 -0
  12. package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +2 -0
  13. package/dist/react-resizable-panels.browser.cjs.js +57 -0
  14. package/dist/react-resizable-panels.browser.cjs.mjs +10 -1
  15. package/dist/react-resizable-panels.browser.development.cjs.js +57 -0
  16. package/dist/react-resizable-panels.browser.development.cjs.mjs +10 -1
  17. package/dist/react-resizable-panels.browser.development.esm.js +49 -1
  18. package/dist/react-resizable-panels.browser.esm.js +49 -1
  19. package/dist/react-resizable-panels.cjs.js +57 -0
  20. package/dist/react-resizable-panels.cjs.mjs +10 -1
  21. package/dist/react-resizable-panels.development.cjs.js +57 -0
  22. package/dist/react-resizable-panels.development.cjs.mjs +10 -1
  23. package/dist/react-resizable-panels.development.esm.js +49 -1
  24. package/dist/react-resizable-panels.development.node.cjs.js +57 -0
  25. package/dist/react-resizable-panels.development.node.cjs.mjs +10 -1
  26. package/dist/react-resizable-panels.development.node.esm.js +49 -1
  27. package/dist/react-resizable-panels.esm.js +49 -1
  28. package/dist/react-resizable-panels.node.cjs.js +57 -0
  29. package/dist/react-resizable-panels.node.cjs.mjs +10 -1
  30. package/dist/react-resizable-panels.node.esm.js +49 -1
  31. package/package.json +1 -1
  32. package/src/index.ts +23 -3
package/CHANGELOG.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.6
4
+
5
+ - Export internal DOM helper methods.
6
+
3
7
  ## 1.0.5
4
8
 
5
- - Fix regression that broke server rendering (#240)
9
+ - Fix server rendering regression (#240); Panels will now render with their `defaultSize` during initial mount (if one is specified). This allows server-rendered components to store the most recent size in a cookie and use that value as the default for subsequent page visits.
6
10
 
7
11
  ## 1.0.4
8
12
 
9
- - Edge case bug fix for `isCollapsed` panel method
13
+ - Edge case bug fix for `isCollapsed` panel method; previously an uninitialized `collapsedSize` value was not being initialized to `0`, which caused `isCollapsed` to incorrectly report `false` in some cases.
10
14
 
11
15
  ## 1.0.3
12
16
 
package/README.md CHANGED
@@ -91,4 +91,194 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
91
91
 
92
92
  ---
93
93
 
94
- #### If you like this project, [buy me a coffee](http://givebrian.coffee/).
94
+ ## FAQ
95
+
96
+ ### Can panel sizes be specified in pixels?
97
+
98
+ No. Pixel-based constraints [added significant complexity](https://github.com/bvaughn/react-resizable-panels/pull/176) to the initialization and validation logic and so I've decided not to support them. You may be able to implement a version of this yourself following [a pattern like this](https://github.com/bvaughn/react-resizable-panels/issues/46#issuecomment-1368108416) but it is not officially supported by this library.
99
+
100
+ ### How can I fix layout/sizing problems with conditionally rendered panels?
101
+
102
+ The `Panel` API doesn't _require_ `id` and `order` props because they aren't necessary for static layouts. When panels are conditionally rendered though, it's best to supply these values.
103
+
104
+ ```tsx
105
+ <PanelGroup direction="horizontal">
106
+ {renderSideBar && (
107
+ <>
108
+ <Panel id="sidebar" minSize={25} order={1}>
109
+ <Sidebar />
110
+ </Panel>
111
+ <PanelResizeHandle />
112
+ </>
113
+ )}
114
+ <Panel minSize={25} order={2}>
115
+ <Main />
116
+ </Panel>
117
+ </PanelGroup>
118
+ ```
119
+
120
+ ### How can I use persistent layouts with SSR?
121
+
122
+ By default, this library uses `localStorage` to persist layouts. With server rendering, this can cause a flicker when the default layout (rendered on the server) is replaced with the persisted layout (in `localStorage`). The way to avoid this flicker is to also persist the layout with a cookie like so:
123
+
124
+ ##### Server component
125
+
126
+ ```tsx
127
+ import ResizablePanels from "@/app/ResizablePanels";
128
+ import { cookies } from "next/headers";
129
+
130
+ export function ServerComponent() {
131
+ const layout = cookies().get("react-resizable-panels:layout");
132
+
133
+ let defaultLayout;
134
+ if (layout) {
135
+ defaultLayout = JSON.parse(layout.value);
136
+ }
137
+
138
+ return <ClientComponent defaultLayout={defaultLayout} />;
139
+ }
140
+ ```
141
+
142
+ ##### Client component
143
+
144
+ ```tsx
145
+ "use client";
146
+
147
+ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
148
+
149
+ export function ClientComponent({
150
+ defaultLayout = [33, 67],
151
+ }: {
152
+ defaultLayout: number[] | undefined;
153
+ }) {
154
+ const onLayout = (sizes: number[]) => {
155
+ document.cookie = `react-resizable-panels:layout=${JSON.stringify(sizes)}`;
156
+ };
157
+
158
+ return (
159
+ <PanelGroup direction="horizontal" onLayout={onLayout}>
160
+ <Panel defaultSize={defaultLayout[0]}>{/* ... */}</Panel>
161
+ <PanelResizeHandle className="w-2 bg-blue-800" />
162
+ <Panel defaultSize={defaultLayout[1]}>{/* ... */}</Panel>
163
+ </PanelGroup>
164
+ );
165
+ }
166
+ ```
167
+
168
+ ---
169
+
170
+ ## FAQ
171
+
172
+ ### Can panel sizes be specified in pixels?
173
+
174
+ No. Pixel-based constraints [added significant complexity](https://github.com/bvaughn/react-resizable-panels/pull/176) to the initialization and validation logic and so I've decided not to support them. You may be able to implement a version of this yourself following [a pattern like this](https://github.com/bvaughn/react-resizable-panels/issues/46#issuecomment-1368108416) but it is not officially supported by this library.
175
+
176
+ ### Can a attach a ref to the DOM elements?
177
+
178
+ No. I think exposing two refs (one for the component's imperative API and one for a DOM element) would be awkward. This library does export several utility methods for accessing the underlying DOM elements though. For example:
179
+
180
+ ```tsx
181
+ export function Example() {
182
+ const refs = useRef();
183
+
184
+ useEffect(() => {
185
+ const groupElement = getPanelGroupElement("group");
186
+ const leftPanelElement = getPanelElement("left-panel");
187
+ const rightPanelElement = getPanelElement("right-panel");
188
+
189
+ // If you want to, you can store them in a ref to pass around
190
+ refs.current = {
191
+ groupElement,
192
+ leftPanelElement,
193
+ rightPanelElement,
194
+ };
195
+ }, []);
196
+
197
+ return (
198
+ <PanelGroup direction="horizontal" id="group">
199
+ <Panel id="left-panel">{/* ... */}</Panel>
200
+ <PanelResizeHandle />
201
+ <Panel id="right-panel">{/* ... */}</Panel>
202
+ </PanelGroup>
203
+ );
204
+ }
205
+ ```
206
+
207
+ ### Why don't I see any resize UI?
208
+
209
+ This likely means that you haven't applied any CSS to style the resize handles. By default, a resize handle is just an empty DOM element. To add styling, use the `className` or `style` props:
210
+
211
+ ```tsx
212
+ // Tailwind example
213
+ <PanelResizeHandle className="w-2 bg-blue-800" />
214
+ ```
215
+
216
+ ### How can I fix layout/sizing problems with conditionally rendered panels?
217
+
218
+ The `Panel` API doesn't _require_ `id` and `order` props because they aren't necessary for static layouts. When panels are conditionally rendered though, it's best to supply these values.
219
+
220
+ ```tsx
221
+ <PanelGroup direction="horizontal">
222
+ {renderSideBar && (
223
+ <>
224
+ <Panel id="sidebar" minSize={25} order={1}>
225
+ <Sidebar />
226
+ </Panel>
227
+ <PanelResizeHandle />
228
+ </>
229
+ )}
230
+ <Panel minSize={25} order={2}>
231
+ <Main />
232
+ </Panel>
233
+ </PanelGroup>
234
+ ```
235
+
236
+ ### How can I use persistent layouts with SSR?
237
+
238
+ By default, this library uses `localStorage` to persist layouts. With server rendering, this can cause a flicker when the default layout (rendered on the server) is replaced with the persisted layout (in `localStorage`). The way to avoid this flicker is to also persist the layout with a cookie like so:
239
+
240
+ ##### Server component
241
+
242
+ ```tsx
243
+ import ResizablePanels from "@/app/ResizablePanels";
244
+ import { cookies } from "next/headers";
245
+
246
+ export function ServerComponent() {
247
+ const layout = cookies().get("react-resizable-panels:layout");
248
+
249
+ let defaultLayout;
250
+ if (layout) {
251
+ defaultLayout = JSON.parse(layout.value);
252
+ }
253
+
254
+ return <ClientComponent defaultLayout={defaultLayout} />;
255
+ }
256
+ ```
257
+
258
+ ##### Client component
259
+
260
+ ```tsx
261
+ "use client";
262
+
263
+ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
264
+
265
+ export function ClientComponent({
266
+ defaultLayout = [33, 67],
267
+ }: {
268
+ defaultLayout: number[] | undefined;
269
+ }) {
270
+ const onLayout = (sizes: number[]) => {
271
+ document.cookie = `react-resizable-panels:layout=${JSON.stringify(sizes)}`;
272
+ };
273
+
274
+ return (
275
+ <PanelGroup direction="horizontal" onLayout={onLayout}>
276
+ <Panel defaultSize={defaultLayout[0]}>{/* ... */}</Panel>
277
+ <PanelResizeHandle className="w-2 bg-blue-800" />
278
+ <Panel defaultSize={defaultLayout[1]}>{/* ... */}</Panel>
279
+ </PanelGroup>
280
+ );
281
+ }
282
+ ```
283
+
284
+ A demo of this is available [here](https://github.com/bvaughn/react-resizable-panels-demo-ssr).
@@ -2,7 +2,16 @@ import { Panel } from "./Panel.js";
2
2
  import { PanelGroup } from "./PanelGroup.js";
3
3
  import { PanelResizeHandle } from "./PanelResizeHandle.js";
4
4
  import { assert } from "./utils/assert.js";
5
+ import { calculateAvailablePanelSizeInPixels } from "./utils/dom/calculateAvailablePanelSizeInPixels.js";
6
+ import { getAvailableGroupSizePixels } from "./utils/dom/getAvailableGroupSizePixels.js";
7
+ import { getPanelElement } from "./utils/dom/getPanelElement.js";
8
+ import { getPanelElementsForGroup } from "./utils/dom/getPanelElementsForGroup.js";
9
+ import { getPanelGroupElement } from "./utils/dom/getPanelGroupElement.js";
10
+ import { getResizeHandleElement } from "./utils/dom/getResizeHandleElement.js";
11
+ import { getResizeHandleElementIndex } from "./utils/dom/getResizeHandleElementIndex.js";
12
+ import { getResizeHandleElementsForGroup } from "./utils/dom/getResizeHandleElementsForGroup.js";
13
+ import { getResizeHandlePanelIds } from "./utils/dom/getResizeHandlePanelIds.js";
5
14
  import type { ImperativePanelHandle, PanelOnCollapse, PanelOnExpand, PanelOnResize, PanelProps } from "./Panel.js";
6
15
  import type { ImperativePanelGroupHandle, PanelGroupOnLayout, PanelGroupProps, PanelGroupStorage } from "./PanelGroup.js";
7
16
  import type { PanelResizeHandleOnDragging, PanelResizeHandleProps } from "./PanelResizeHandle.js";
8
- export { ImperativePanelGroupHandle, ImperativePanelHandle, PanelGroupOnLayout, PanelGroupProps, PanelGroupStorage, PanelOnCollapse, PanelOnExpand, PanelOnResize, PanelProps, PanelResizeHandleOnDragging, PanelResizeHandleProps, assert, Panel, PanelGroup, PanelResizeHandle, };
17
+ export { ImperativePanelGroupHandle, ImperativePanelHandle, PanelGroupOnLayout, PanelGroupProps, PanelGroupStorage, PanelOnCollapse, PanelOnExpand, PanelOnResize, PanelProps, PanelResizeHandleOnDragging, PanelResizeHandleProps, Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, };
@@ -0,0 +1 @@
1
+ export declare function calculateAvailablePanelSizeInPixels(groupId: string): number;
@@ -0,0 +1 @@
1
+ export declare function getAvailableGroupSizePixels(groupId: string): number;
@@ -0,0 +1 @@
1
+ export declare function getPanelElement(id: string): HTMLDivElement | null;
@@ -0,0 +1 @@
1
+ export declare function getPanelElementsForGroup(groupId: string): HTMLDivElement[];
@@ -0,0 +1 @@
1
+ export declare function getPanelGroupElement(id: string): HTMLDivElement | null;
@@ -0,0 +1 @@
1
+ export declare function getResizeHandleElement(id: string): HTMLDivElement | null;
@@ -0,0 +1 @@
1
+ export declare function getResizeHandleElementIndex(groupId: string, id: string): number | null;
@@ -0,0 +1 @@
1
+ export declare function getResizeHandleElementsForGroup(groupId: string): HTMLDivElement[];
@@ -0,0 +1,2 @@
1
+ import { PanelData } from "../../Panel.js";
2
+ export declare function getResizeHandlePanelIds(groupId: string, handleId: string, panelsArray: PanelData[]): [idBefore: string | null, idAfter: string | null];
@@ -1823,7 +1823,64 @@ function PanelResizeHandle({
1823
1823
  }
1824
1824
  PanelResizeHandle.displayName = "PanelResizeHandle";
1825
1825
 
1826
+ function calculateAvailablePanelSizeInPixels(groupId) {
1827
+ const panelGroupElement = getPanelGroupElement(groupId);
1828
+ if (panelGroupElement == null) {
1829
+ return NaN;
1830
+ }
1831
+ const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1832
+ const resizeHandles = getResizeHandleElementsForGroup(groupId);
1833
+ if (direction === "horizontal") {
1834
+ return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1835
+ return accumulated + handle.offsetWidth;
1836
+ }, 0);
1837
+ } else {
1838
+ return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1839
+ return accumulated + handle.offsetHeight;
1840
+ }, 0);
1841
+ }
1842
+ }
1843
+
1844
+ function getAvailableGroupSizePixels(groupId) {
1845
+ const panelGroupElement = getPanelGroupElement(groupId);
1846
+ if (panelGroupElement == null) {
1847
+ return NaN;
1848
+ }
1849
+ const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1850
+ const resizeHandles = getResizeHandleElementsForGroup(groupId);
1851
+ if (direction === "horizontal") {
1852
+ return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1853
+ return accumulated + handle.offsetWidth;
1854
+ }, 0);
1855
+ } else {
1856
+ return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1857
+ return accumulated + handle.offsetHeight;
1858
+ }, 0);
1859
+ }
1860
+ }
1861
+
1862
+ function getPanelElement(id) {
1863
+ const element = document.querySelector(`[data-panel-id="${id}"]`);
1864
+ if (element) {
1865
+ return element;
1866
+ }
1867
+ return null;
1868
+ }
1869
+
1870
+ function getPanelElementsForGroup(groupId) {
1871
+ return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1872
+ }
1873
+
1826
1874
  exports.Panel = Panel;
1827
1875
  exports.PanelGroup = PanelGroup;
1828
1876
  exports.PanelResizeHandle = PanelResizeHandle;
1829
1877
  exports.assert = assert;
1878
+ exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
1879
+ exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
1880
+ exports.getPanelElement = getPanelElement;
1881
+ exports.getPanelElementsForGroup = getPanelElementsForGroup;
1882
+ exports.getPanelGroupElement = getPanelGroupElement;
1883
+ exports.getResizeHandleElement = getResizeHandleElement;
1884
+ exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
1885
+ exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
1886
+ 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.browser.cjs.js";
@@ -1928,7 +1928,64 @@ function PanelResizeHandle({
1928
1928
  }
1929
1929
  PanelResizeHandle.displayName = "PanelResizeHandle";
1930
1930
 
1931
+ function calculateAvailablePanelSizeInPixels(groupId) {
1932
+ const panelGroupElement = getPanelGroupElement(groupId);
1933
+ if (panelGroupElement == null) {
1934
+ return NaN;
1935
+ }
1936
+ const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1937
+ const resizeHandles = getResizeHandleElementsForGroup(groupId);
1938
+ if (direction === "horizontal") {
1939
+ return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1940
+ return accumulated + handle.offsetWidth;
1941
+ }, 0);
1942
+ } else {
1943
+ return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1944
+ return accumulated + handle.offsetHeight;
1945
+ }, 0);
1946
+ }
1947
+ }
1948
+
1949
+ function getAvailableGroupSizePixels(groupId) {
1950
+ const panelGroupElement = getPanelGroupElement(groupId);
1951
+ if (panelGroupElement == null) {
1952
+ return NaN;
1953
+ }
1954
+ const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1955
+ const resizeHandles = getResizeHandleElementsForGroup(groupId);
1956
+ if (direction === "horizontal") {
1957
+ return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1958
+ return accumulated + handle.offsetWidth;
1959
+ }, 0);
1960
+ } else {
1961
+ return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1962
+ return accumulated + handle.offsetHeight;
1963
+ }, 0);
1964
+ }
1965
+ }
1966
+
1967
+ function getPanelElement(id) {
1968
+ const element = document.querySelector(`[data-panel-id="${id}"]`);
1969
+ if (element) {
1970
+ return element;
1971
+ }
1972
+ return null;
1973
+ }
1974
+
1975
+ function getPanelElementsForGroup(groupId) {
1976
+ return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1977
+ }
1978
+
1931
1979
  exports.Panel = Panel;
1932
1980
  exports.PanelGroup = PanelGroup;
1933
1981
  exports.PanelResizeHandle = PanelResizeHandle;
1934
1982
  exports.assert = assert;
1983
+ exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
1984
+ exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
1985
+ exports.getPanelElement = getPanelElement;
1986
+ exports.getPanelElementsForGroup = getPanelElementsForGroup;
1987
+ exports.getPanelGroupElement = getPanelGroupElement;
1988
+ exports.getResizeHandleElement = getResizeHandleElement;
1989
+ exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
1990
+ exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
1991
+ 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.browser.development.cjs.js";
@@ -1904,4 +1904,52 @@ function PanelResizeHandle({
1904
1904
  }
1905
1905
  PanelResizeHandle.displayName = "PanelResizeHandle";
1906
1906
 
1907
- export { Panel, PanelGroup, PanelResizeHandle, assert };
1907
+ function calculateAvailablePanelSizeInPixels(groupId) {
1908
+ const panelGroupElement = getPanelGroupElement(groupId);
1909
+ if (panelGroupElement == null) {
1910
+ return NaN;
1911
+ }
1912
+ const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1913
+ const resizeHandles = getResizeHandleElementsForGroup(groupId);
1914
+ if (direction === "horizontal") {
1915
+ return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1916
+ return accumulated + handle.offsetWidth;
1917
+ }, 0);
1918
+ } else {
1919
+ return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1920
+ return accumulated + handle.offsetHeight;
1921
+ }, 0);
1922
+ }
1923
+ }
1924
+
1925
+ function getAvailableGroupSizePixels(groupId) {
1926
+ const panelGroupElement = getPanelGroupElement(groupId);
1927
+ if (panelGroupElement == null) {
1928
+ return NaN;
1929
+ }
1930
+ const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1931
+ const resizeHandles = getResizeHandleElementsForGroup(groupId);
1932
+ if (direction === "horizontal") {
1933
+ return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1934
+ return accumulated + handle.offsetWidth;
1935
+ }, 0);
1936
+ } else {
1937
+ return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1938
+ return accumulated + handle.offsetHeight;
1939
+ }, 0);
1940
+ }
1941
+ }
1942
+
1943
+ function getPanelElement(id) {
1944
+ const element = document.querySelector(`[data-panel-id="${id}"]`);
1945
+ if (element) {
1946
+ return element;
1947
+ }
1948
+ return null;
1949
+ }
1950
+
1951
+ function getPanelElementsForGroup(groupId) {
1952
+ return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1953
+ }
1954
+
1955
+ export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
@@ -1799,4 +1799,52 @@ function PanelResizeHandle({
1799
1799
  }
1800
1800
  PanelResizeHandle.displayName = "PanelResizeHandle";
1801
1801
 
1802
- export { Panel, PanelGroup, PanelResizeHandle, assert };
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 };
@@ -1825,7 +1825,64 @@ function PanelResizeHandle({
1825
1825
  }
1826
1826
  PanelResizeHandle.displayName = "PanelResizeHandle";
1827
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
+
1828
1876
  exports.Panel = Panel;
1829
1877
  exports.PanelGroup = PanelGroup;
1830
1878
  exports.PanelResizeHandle = PanelResizeHandle;
1831
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";
@@ -1935,7 +1935,64 @@ function PanelResizeHandle({
1935
1935
  }
1936
1936
  PanelResizeHandle.displayName = "PanelResizeHandle";
1937
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
+
1938
1986
  exports.Panel = Panel;
1939
1987
  exports.PanelGroup = PanelGroup;
1940
1988
  exports.PanelResizeHandle = PanelResizeHandle;
1941
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";
@@ -1911,4 +1911,52 @@ function PanelResizeHandle({
1911
1911
  }
1912
1912
  PanelResizeHandle.displayName = "PanelResizeHandle";
1913
1913
 
1914
- export { Panel, PanelGroup, PanelResizeHandle, assert };
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 };
@@ -1724,7 +1724,64 @@ function PanelResizeHandle({
1724
1724
  }
1725
1725
  PanelResizeHandle.displayName = "PanelResizeHandle";
1726
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
+
1727
1775
  exports.Panel = Panel;
1728
1776
  exports.PanelGroup = PanelGroup;
1729
1777
  exports.PanelResizeHandle = PanelResizeHandle;
1730
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";
@@ -1700,4 +1700,52 @@ function PanelResizeHandle({
1700
1700
  }
1701
1701
  PanelResizeHandle.displayName = "PanelResizeHandle";
1702
1702
 
1703
- export { Panel, PanelGroup, PanelResizeHandle, assert };
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 };
@@ -1801,4 +1801,52 @@ function PanelResizeHandle({
1801
1801
  }
1802
1802
  PanelResizeHandle.displayName = "PanelResizeHandle";
1803
1803
 
1804
- export { Panel, PanelGroup, PanelResizeHandle, assert };
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 };
@@ -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";
@@ -1600,4 +1600,52 @@ function PanelResizeHandle({
1600
1600
  }
1601
1601
  PanelResizeHandle.displayName = "PanelResizeHandle";
1602
1602
 
1603
- export { Panel, PanelGroup, PanelResizeHandle, assert };
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
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
  };