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.
Files changed (44) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/README.md +210 -4
  3. package/dist/declarations/src/Panel.d.ts +7 -7
  4. package/dist/declarations/src/PanelGroup.d.ts +6 -6
  5. package/dist/declarations/src/PanelResizeHandle.d.ts +4 -4
  6. package/dist/declarations/src/index.d.ts +10 -1
  7. package/dist/declarations/src/utils/dom/calculateAvailablePanelSizeInPixels.d.ts +1 -0
  8. package/dist/declarations/src/utils/dom/getAvailableGroupSizePixels.d.ts +1 -0
  9. package/dist/declarations/src/utils/dom/getPanelElement.d.ts +1 -0
  10. package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +1 -0
  11. package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +1 -0
  12. package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +1 -0
  13. package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +1 -0
  14. package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +1 -0
  15. package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +2 -0
  16. package/dist/react-resizable-panels.browser.cjs.js +65 -8
  17. package/dist/react-resizable-panels.browser.cjs.mjs +10 -1
  18. package/dist/react-resizable-panels.browser.development.cjs.js +65 -8
  19. package/dist/react-resizable-panels.browser.development.cjs.mjs +10 -1
  20. package/dist/react-resizable-panels.browser.development.esm.js +57 -9
  21. package/dist/react-resizable-panels.browser.esm.js +57 -9
  22. package/dist/react-resizable-panels.cjs.js +65 -8
  23. package/dist/react-resizable-panels.cjs.mjs +10 -1
  24. package/dist/react-resizable-panels.development.cjs.js +65 -8
  25. package/dist/react-resizable-panels.development.cjs.mjs +10 -1
  26. package/dist/react-resizable-panels.development.esm.js +57 -9
  27. package/dist/react-resizable-panels.development.node.cjs.js +65 -8
  28. package/dist/react-resizable-panels.development.node.cjs.mjs +10 -1
  29. package/dist/react-resizable-panels.development.node.esm.js +57 -9
  30. package/dist/react-resizable-panels.esm.js +57 -9
  31. package/dist/react-resizable-panels.node.cjs.js +65 -8
  32. package/dist/react-resizable-panels.node.cjs.mjs +10 -1
  33. package/dist/react-resizable-panels.node.esm.js +57 -9
  34. package/package.json +1 -1
  35. package/src/Panel.ts +7 -4
  36. package/src/PanelGroup.ts +7 -4
  37. package/src/PanelResizeHandle.ts +15 -12
  38. package/src/hooks/useWindowSplitterBehavior.ts +1 -1
  39. package/src/index.ts +23 -3
  40. package/src/utils/dom/getPanelElement.ts +2 -2
  41. package/src/utils/dom/getPanelElementsForGroup.ts +1 -1
  42. package/src/utils/dom/getPanelGroupElement.ts +2 -2
  43. package/src/utils/dom/getResizeHandleElement.ts +2 -2
  44. package/src/utils/dom/getResizeHandleElementsForGroup.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,12 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.7
4
+
5
+ - Narrow `tagName` prop to only allow `HTMLElement` names (rather than the broader `Element` type) (#251)
6
+
7
+ ## 1.0.6
8
+
9
+ - Export internal DOM helper methods.
10
+
3
11
  ## 1.0.5
4
12
 
5
- - Fix regression that broke server rendering (#240)
13
+ - 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
14
 
7
15
  ## 1.0.4
8
16
 
9
- - Edge case bug fix for `isCollapsed` panel method
17
+ - 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
18
 
11
19
  ## 1.0.3
12
20
 
package/README.md CHANGED
@@ -46,7 +46,9 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
46
46
  `PanelGroup` components also expose an imperative API for manual resizing:
47
47
  | method | description
48
48
  | :-------------------------------- | :---
49
- | `setLayout(panelSizes: number[])` | Resize panel group to the specified _panelSizes_ (`[1 - 100, ...]`).
49
+ | `getId(): string` | Gets the panel group's ID.
50
+ | `getLayout(): number[]` | Gets the panel group's current _layout_ (`[1 - 100, ...]`).
51
+ | `setLayout(layout: number[])` | Resize panel group to the specified _layout_ (`[1 - 100, ...]`).
50
52
 
51
53
  ### `Panel`
52
54
 
@@ -73,9 +75,12 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
73
75
  | :--------------------------- | :---
74
76
  | `collapse()` | If panel is `collapsible`, collapse it fully.
75
77
  | `expand()` | If panel is currently _collapsed_, expand it to its most recent size.
76
- | `getCollapsed(): boolean` | Returns `true` if the panel is currently _collapsed_ (`size === 0`).
78
+ | `getId(): string` | Gets the ID of the panel.
79
+ | `getSize(): number` | Gets the current size of the panel as a percentage (`1 - 100`).
80
+ | `isCollapsed(): boolean` | Returns `true` if the panel is currently _collapsed_ (`size === 0`).
81
+ | `isExpanded(): boolean` | Returns `true` if the panel is currently _not collapsed_ (`!isCollapsed()`).
77
82
  | `getSize(): number` | Returns the most recently commited size of the panel as a percentage (`1 - 100`).
78
- | `resize(percentage: number)` | Resize panel to the specified _percentage_ (`1 - 100`).
83
+ | `resize(size: number)` | Resize panel to the specified _percentage_ (`1 - 100`).
79
84
 
80
85
  ### `PanelResizeHandle`
81
86
 
@@ -91,4 +96,205 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
91
96
 
92
97
  ---
93
98
 
94
- #### If you like this project, [buy me a coffee](http://givebrian.coffee/).
99
+ ## FAQ
100
+
101
+ ### Can panel sizes be specified in pixels?
102
+
103
+ 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.
104
+
105
+ ### How can I fix layout/sizing problems with conditionally rendered panels?
106
+
107
+ 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.
108
+
109
+ ```tsx
110
+ <PanelGroup direction="horizontal">
111
+ {renderSideBar && (
112
+ <>
113
+ <Panel id="sidebar" minSize={25} order={1}>
114
+ <Sidebar />
115
+ </Panel>
116
+ <PanelResizeHandle />
117
+ </>
118
+ )}
119
+ <Panel minSize={25} order={2}>
120
+ <Main />
121
+ </Panel>
122
+ </PanelGroup>
123
+ ```
124
+
125
+ ### How can I use persistent layouts with SSR?
126
+
127
+ 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:
128
+
129
+ ##### Server component
130
+
131
+ ```tsx
132
+ import ResizablePanels from "@/app/ResizablePanels";
133
+ import { cookies } from "next/headers";
134
+
135
+ export function ServerComponent() {
136
+ const layout = cookies().get("react-resizable-panels:layout");
137
+
138
+ let defaultLayout;
139
+ if (layout) {
140
+ defaultLayout = JSON.parse(layout.value);
141
+ }
142
+
143
+ return <ClientComponent defaultLayout={defaultLayout} />;
144
+ }
145
+ ```
146
+
147
+ ##### Client component
148
+
149
+ ```tsx
150
+ "use client";
151
+
152
+ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
153
+
154
+ export function ClientComponent({
155
+ defaultLayout = [33, 67],
156
+ }: {
157
+ defaultLayout: number[] | undefined;
158
+ }) {
159
+ const onLayout = (sizes: number[]) => {
160
+ document.cookie = `react-resizable-panels:layout=${JSON.stringify(sizes)}`;
161
+ };
162
+
163
+ return (
164
+ <PanelGroup direction="horizontal" onLayout={onLayout}>
165
+ <Panel defaultSize={defaultLayout[0]}>{/* ... */}</Panel>
166
+ <PanelResizeHandle className="w-2 bg-blue-800" />
167
+ <Panel defaultSize={defaultLayout[1]}>{/* ... */}</Panel>
168
+ </PanelGroup>
169
+ );
170
+ }
171
+ ```
172
+
173
+ ---
174
+
175
+ ## FAQ
176
+
177
+ ### Can panel sizes be specified in pixels?
178
+
179
+ 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.
180
+
181
+ ### Can a attach a ref to the DOM elements?
182
+
183
+ 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:
184
+
185
+ ```tsx
186
+ import {
187
+ getPanelElement,
188
+ getPanelGroupElement,
189
+ getResizeHandleElement,
190
+ Panel,
191
+ PanelGroup,
192
+ PanelResizeHandle,
193
+ } from "react-resizable-panels";
194
+
195
+ export function Example() {
196
+ const refs = useRef();
197
+
198
+ useEffect(() => {
199
+ const groupElement = getPanelGroupElement("group");
200
+ const leftPanelElement = getPanelElement("left-panel");
201
+ const rightPanelElement = getPanelElement("right-panel");
202
+ const resizeHandleElement = getResizeHandleElement("resize-handle");
203
+
204
+ // If you want to, you can store them in a ref to pass around
205
+ refs.current = {
206
+ groupElement,
207
+ leftPanelElement,
208
+ rightPanelElement,
209
+ resizeHandleElement,
210
+ };
211
+ }, []);
212
+
213
+ return (
214
+ <PanelGroup direction="horizontal" id="group">
215
+ <Panel id="left-panel">{/* ... */}</Panel>
216
+ <PanelResizeHandle id="resize-handle" />
217
+ <Panel id="right-panel">{/* ... */}</Panel>
218
+ </PanelGroup>
219
+ );
220
+ }
221
+ ```
222
+
223
+ ### Why don't I see any resize UI?
224
+
225
+ 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:
226
+
227
+ ```tsx
228
+ // Tailwind example
229
+ <PanelResizeHandle className="w-2 bg-blue-800" />
230
+ ```
231
+
232
+ ### How can I fix layout/sizing problems with conditionally rendered panels?
233
+
234
+ 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.
235
+
236
+ ```tsx
237
+ <PanelGroup direction="horizontal">
238
+ {renderSideBar && (
239
+ <>
240
+ <Panel id="sidebar" minSize={25} order={1}>
241
+ <Sidebar />
242
+ </Panel>
243
+ <PanelResizeHandle />
244
+ </>
245
+ )}
246
+ <Panel minSize={25} order={2}>
247
+ <Main />
248
+ </Panel>
249
+ </PanelGroup>
250
+ ```
251
+
252
+ ### How can I use persistent layouts with SSR?
253
+
254
+ 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:
255
+
256
+ ##### Server component
257
+
258
+ ```tsx
259
+ import ResizablePanels from "@/app/ResizablePanels";
260
+ import { cookies } from "next/headers";
261
+
262
+ export function ServerComponent() {
263
+ const layout = cookies().get("react-resizable-panels:layout");
264
+
265
+ let defaultLayout;
266
+ if (layout) {
267
+ defaultLayout = JSON.parse(layout.value);
268
+ }
269
+
270
+ return <ClientComponent defaultLayout={defaultLayout} />;
271
+ }
272
+ ```
273
+
274
+ ##### Client component
275
+
276
+ ```tsx
277
+ "use client";
278
+
279
+ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
280
+
281
+ export function ClientComponent({
282
+ defaultLayout = [33, 67],
283
+ }: {
284
+ defaultLayout: number[] | undefined;
285
+ }) {
286
+ const onLayout = (sizes: number[]) => {
287
+ document.cookie = `react-resizable-panels:layout=${JSON.stringify(sizes)}`;
288
+ };
289
+
290
+ return (
291
+ <PanelGroup direction="horizontal" onLayout={onLayout}>
292
+ <Panel defaultSize={defaultLayout[0]}>{/* ... */}</Panel>
293
+ <PanelResizeHandle className="w-2 bg-blue-800" />
294
+ <Panel defaultSize={defaultLayout[1]}>{/* ... */}</Panel>
295
+ </PanelGroup>
296
+ );
297
+ }
298
+ ```
299
+
300
+ A demo of this is available [here](https://github.com/bvaughn/react-resizable-panels-demo-ssr).
@@ -1,4 +1,4 @@
1
- import { ElementType, ForwardedRef, HTMLAttributes, PropsWithChildren } from "./vendor/react.js";
1
+ import { ForwardedRef, HTMLAttributes, PropsWithChildren, ReactNode } from "./vendor/react.js";
2
2
  export type PanelOnCollapse = () => void;
3
3
  export type PanelOnExpand = () => void;
4
4
  export type PanelOnResize = (size: number, prevSize: number | undefined) => void;
@@ -30,7 +30,7 @@ export type ImperativePanelHandle = {
30
30
  isExpanded: () => boolean;
31
31
  resize: (size: number) => void;
32
32
  };
33
- export type PanelProps = Omit<HTMLAttributes<ElementType>, "id" | "onResize"> & PropsWithChildren<{
33
+ export type PanelProps = Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id" | "onResize"> & PropsWithChildren<{
34
34
  className?: string;
35
35
  collapsedSize?: number | undefined;
36
36
  collapsible?: boolean | undefined;
@@ -43,15 +43,15 @@ export type PanelProps = Omit<HTMLAttributes<ElementType>, "id" | "onResize"> &
43
43
  onResize?: PanelOnResize;
44
44
  order?: number;
45
45
  style?: object;
46
- tagName?: ElementType;
46
+ tagName?: keyof HTMLElementTagNameMap;
47
47
  }>;
48
48
  export declare function PanelWithForwardedRef({ children, className: classNameFromProps, collapsedSize, collapsible, defaultSize, forwardedRef, id: idFromProps, maxSize, minSize, onCollapse, onExpand, onResize, order, style: styleFromProps, tagName: Type, ...rest }: PanelProps & {
49
49
  forwardedRef: ForwardedRef<ImperativePanelHandle>;
50
- }): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
50
+ }): ReactNode;
51
51
  export declare namespace PanelWithForwardedRef {
52
52
  var displayName: string;
53
53
  }
54
- export declare const Panel: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<ElementType>, "id" | "onResize"> & {
54
+ export declare const Panel: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id" | "onResize"> & {
55
55
  className?: string | undefined;
56
56
  collapsedSize?: number | undefined;
57
57
  collapsible?: boolean | undefined;
@@ -64,7 +64,7 @@ export declare const Panel: import("react").ForwardRefExoticComponent<Omit<HTMLA
64
64
  onResize?: PanelOnResize | undefined;
65
65
  order?: number | undefined;
66
66
  style?: object | undefined;
67
- tagName?: ElementType | undefined;
67
+ tagName?: keyof HTMLElementTagNameMap | undefined;
68
68
  } & {
69
- children?: import("react").ReactNode;
69
+ children?: ReactNode;
70
70
  } & import("react").RefAttributes<ImperativePanelHandle>>;
@@ -1,5 +1,5 @@
1
1
  import { Direction } from "./types.js";
2
- import { CSSProperties, ElementType, HTMLAttributes, PropsWithChildren } from "./vendor/react.js";
2
+ import { CSSProperties, HTMLAttributes, PropsWithChildren, ReactNode } from "./vendor/react.js";
3
3
  export type ImperativePanelGroupHandle = {
4
4
  getId: () => string;
5
5
  getLayout: () => number[];
@@ -10,7 +10,7 @@ export type PanelGroupStorage = {
10
10
  setItem(name: string, value: string): void;
11
11
  };
12
12
  export type PanelGroupOnLayout = (layout: number[]) => void;
13
- export type PanelGroupProps = Omit<HTMLAttributes<ElementType>, "id"> & PropsWithChildren<{
13
+ export type PanelGroupProps = Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id"> & PropsWithChildren<{
14
14
  autoSaveId?: string | null;
15
15
  className?: string;
16
16
  direction: Direction;
@@ -19,9 +19,9 @@ export type PanelGroupProps = Omit<HTMLAttributes<ElementType>, "id"> & PropsWit
19
19
  onLayout?: PanelGroupOnLayout | null;
20
20
  storage?: PanelGroupStorage;
21
21
  style?: CSSProperties;
22
- tagName?: ElementType;
22
+ tagName?: keyof HTMLElementTagNameMap;
23
23
  }>;
24
- export declare const PanelGroup: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<ElementType>, "id"> & {
24
+ export declare const PanelGroup: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id"> & {
25
25
  autoSaveId?: string | null | undefined;
26
26
  className?: string | undefined;
27
27
  direction: Direction;
@@ -30,7 +30,7 @@ export declare const PanelGroup: import("react").ForwardRefExoticComponent<Omit<
30
30
  onLayout?: PanelGroupOnLayout | null | undefined;
31
31
  storage?: PanelGroupStorage | undefined;
32
32
  style?: CSSProperties | undefined;
33
- tagName?: ElementType | undefined;
33
+ tagName?: keyof HTMLElementTagNameMap | undefined;
34
34
  } & {
35
- children?: import("react").ReactNode;
35
+ children?: ReactNode;
36
36
  } & import("react").RefAttributes<ImperativePanelGroupHandle>>;
@@ -1,15 +1,15 @@
1
- import { CSSProperties, ElementType, HTMLAttributes, PropsWithChildren } from "./vendor/react.js";
1
+ import { CSSProperties, HTMLAttributes, PropsWithChildren, ReactNode } from "./vendor/react.js";
2
2
  export type PanelResizeHandleOnDragging = (isDragging: boolean) => void;
3
- export type PanelResizeHandleProps = Omit<HTMLAttributes<ElementType>, "id"> & PropsWithChildren<{
3
+ export type PanelResizeHandleProps = Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id"> & PropsWithChildren<{
4
4
  className?: string;
5
5
  disabled?: boolean;
6
6
  id?: string | null;
7
7
  onDragging?: PanelResizeHandleOnDragging;
8
8
  style?: CSSProperties;
9
9
  tabIndex?: number;
10
- tagName?: ElementType;
10
+ tagName?: keyof HTMLElementTagNameMap;
11
11
  }>;
12
- export declare function PanelResizeHandle({ children, className: classNameFromProps, disabled, id: idFromProps, onDragging, style: styleFromProps, tabIndex, tagName: Type, ...rest }: PanelResizeHandleProps): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
12
+ export declare function PanelResizeHandle({ children, className: classNameFromProps, disabled, id: idFromProps, onDragging, style: styleFromProps, tabIndex, tagName: Type, ...rest }: PanelResizeHandleProps): ReactNode;
13
13
  export declare namespace PanelResizeHandle {
14
14
  var displayName: string;
15
15
  }
@@ -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): HTMLElement | null;
@@ -0,0 +1 @@
1
+ export declare function getPanelElementsForGroup(groupId: string): HTMLElement[];
@@ -0,0 +1 @@
1
+ export declare function getPanelGroupElement(id: string): HTMLElement | null;
@@ -0,0 +1 @@
1
+ export declare function getResizeHandleElement(id: string): HTMLElement | 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): HTMLElement[];
@@ -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];
@@ -1689,7 +1689,7 @@ function PanelResizeHandle({
1689
1689
  tagName: Type = "div",
1690
1690
  ...rest
1691
1691
  }) {
1692
- const divElementRef = useRef(null);
1692
+ const elementRef = useRef(null);
1693
1693
 
1694
1694
  // Use a ref to guard against users passing inline props
1695
1695
  const callbacksRef = useRef({
@@ -1717,9 +1717,9 @@ function PanelResizeHandle({
1717
1717
  const stopDraggingAndBlur = useCallback(() => {
1718
1718
  // Clicking on the drag handle shouldn't leave it focused;
1719
1719
  // That would cause the PanelGroup to think it was still active.
1720
- const divElement = divElementRef.current;
1721
- assert(divElement);
1722
- divElement.blur();
1720
+ const element = elementRef.current;
1721
+ assert(element);
1722
+ element.blur();
1723
1723
  stopDragging();
1724
1724
  const {
1725
1725
  onDragging
@@ -1746,9 +1746,9 @@ function PanelResizeHandle({
1746
1746
  const onMouseLeave = event => {
1747
1747
  resizeHandler(event);
1748
1748
  };
1749
- const divElement = divElementRef.current;
1750
- assert(divElement);
1751
- const targetDocument = divElement.ownerDocument;
1749
+ const element = elementRef.current;
1750
+ assert(element);
1751
+ const targetDocument = element.ownerDocument;
1752
1752
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1753
1753
  targetDocument.body.addEventListener("mousemove", onMove);
1754
1754
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1805,7 +1805,7 @@ function PanelResizeHandle({
1805
1805
  onDragging(true);
1806
1806
  }
1807
1807
  },
1808
- ref: divElementRef,
1808
+ ref: elementRef,
1809
1809
  role: "separator",
1810
1810
  style: {
1811
1811
  ...style,
@@ -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";
@@ -1794,7 +1794,7 @@ function PanelResizeHandle({
1794
1794
  tagName: Type = "div",
1795
1795
  ...rest
1796
1796
  }) {
1797
- const divElementRef = useRef(null);
1797
+ const elementRef = useRef(null);
1798
1798
 
1799
1799
  // Use a ref to guard against users passing inline props
1800
1800
  const callbacksRef = useRef({
@@ -1822,9 +1822,9 @@ function PanelResizeHandle({
1822
1822
  const stopDraggingAndBlur = useCallback(() => {
1823
1823
  // Clicking on the drag handle shouldn't leave it focused;
1824
1824
  // That would cause the PanelGroup to think it was still active.
1825
- const divElement = divElementRef.current;
1826
- assert(divElement);
1827
- divElement.blur();
1825
+ const element = elementRef.current;
1826
+ assert(element);
1827
+ element.blur();
1828
1828
  stopDragging();
1829
1829
  const {
1830
1830
  onDragging
@@ -1851,9 +1851,9 @@ function PanelResizeHandle({
1851
1851
  const onMouseLeave = event => {
1852
1852
  resizeHandler(event);
1853
1853
  };
1854
- const divElement = divElementRef.current;
1855
- assert(divElement);
1856
- const targetDocument = divElement.ownerDocument;
1854
+ const element = elementRef.current;
1855
+ assert(element);
1856
+ const targetDocument = element.ownerDocument;
1857
1857
  targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1858
1858
  targetDocument.body.addEventListener("mousemove", onMove);
1859
1859
  targetDocument.body.addEventListener("touchmove", onMove);
@@ -1910,7 +1910,7 @@ function PanelResizeHandle({
1910
1910
  onDragging(true);
1911
1911
  }
1912
1912
  },
1913
- ref: divElementRef,
1913
+ ref: elementRef,
1914
1914
  role: "separator",
1915
1915
  style: {
1916
1916
  ...style,
@@ -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";