react-resizable-panels 3.0.6 → 4.0.0-alpha.0

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 (34) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +253 -250
  3. package/dist/react-resizable-panels.cjs +2 -0
  4. package/dist/react-resizable-panels.cjs.map +1 -0
  5. package/dist/react-resizable-panels.d.ts +316 -2
  6. package/dist/react-resizable-panels.js +1050 -2371
  7. package/dist/react-resizable-panels.js.map +1 -0
  8. package/package.json +94 -66
  9. package/dist/declarations/src/Panel.d.ts +0 -70
  10. package/dist/declarations/src/PanelGroup.d.ts +0 -38
  11. package/dist/declarations/src/PanelResizeHandle.d.ts +0 -23
  12. package/dist/declarations/src/PanelResizeHandleRegistry.d.ts +0 -19
  13. package/dist/declarations/src/constants.d.ts +0 -15
  14. package/dist/declarations/src/hooks/usePanelGroupContext.d.ts +0 -4
  15. package/dist/declarations/src/index.d.ts +0 -23
  16. package/dist/declarations/src/types.d.ts +0 -3
  17. package/dist/declarations/src/utils/assert.d.ts +0 -1
  18. package/dist/declarations/src/utils/csp.d.ts +0 -2
  19. package/dist/declarations/src/utils/cursor.d.ts +0 -18
  20. package/dist/declarations/src/utils/dom/getPanelElement.d.ts +0 -1
  21. package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +0 -1
  22. package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +0 -1
  23. package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +0 -1
  24. package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +0 -1
  25. package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +0 -1
  26. package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +0 -2
  27. package/dist/declarations/src/utils/rects/getIntersectingRectangle.d.ts +0 -2
  28. package/dist/declarations/src/utils/rects/intersects.d.ts +0 -2
  29. package/dist/declarations/src/utils/rects/types.d.ts +0 -6
  30. package/dist/react-resizable-panels.browser.development.js +0 -2592
  31. package/dist/react-resizable-panels.browser.js +0 -2486
  32. package/dist/react-resizable-panels.development.edge-light.js +0 -2365
  33. package/dist/react-resizable-panels.development.js +0 -2599
  34. package/dist/react-resizable-panels.edge-light.js +0 -2264
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Brian Vaughn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,260 +1,263 @@
1
1
  # react-resizable-panels
2
2
 
3
- React components for resizable panel groups/layouts
4
-
5
- ```jsx
6
- import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
7
-
8
- <PanelGroup autoSaveId="example" direction="horizontal">
9
- <Panel defaultSize={25}>
10
- <SourcesExplorer />
11
- </Panel>
12
- <PanelResizeHandle />
13
- <Panel>
14
- <SourceViewer />
15
- </Panel>
16
- <PanelResizeHandle />
17
- <Panel defaultSize={25}>
18
- <Console />
19
- </Panel>
20
- </PanelGroup>;
21
- ```
22
-
23
- ## If you like this project, 🎉 [become a sponsor](https://github.com/sponsors/bvaughn/) or ☕ [buy me a coffee](http://givebrian.coffee/)
24
-
25
- ## Props
26
-
27
- ### `PanelGroup`
28
-
29
- | prop | type | description |
30
- | :----------- | :--------------------------- | :--------------------------------------------------------------- |
31
- | `autoSaveId` | `?string` | Unique id used to auto-save group arrangement via `localStorage` |
32
- | `children` | `ReactNode` | Arbitrary React element(s) |
33
- | `className` | `?string` | Class name to attach to root element |
34
- | `direction` | `"horizontal" \| "vertical"` | Group orientation |
35
- | `id` | `?string` | Group id; falls back to `useId` when not provided |
36
- | `onLayout` | `?(sizes: number[]) => void` | Called when group layout changes |
37
- | `storage` | `?PanelGroupStorage` | Custom storage API; defaults to `localStorage` <sup>1</sup> |
38
- | `style` | `?CSSProperties` | CSS style to attach to root element |
39
- | `tagName` | `?string = "div"` | HTML element tag name for root element |
40
-
41
- <sup>1</sup>: Storage API must define the following _synchronous_ methods:
42
-
43
- - `getItem: (name:string) => string`
44
- - `setItem: (name: string, value: string) => void`
45
-
46
- `PanelGroup` components also expose an imperative API for manual resizing:
47
- | method | description |
48
- | :---------------------------- | :--------------------------------------------------------------- |
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, ...]`). |
52
-
53
- ### `Panel`
54
-
55
- | prop | type | description |
56
- | :-------------- | :------------------------ | :-------------------------------------------------------------------------------------------- |
57
- | `children` | `ReactNode` | Arbitrary React element(s) |
58
- | `className` | `?string` | Class name to attach to root element |
59
- | `collapsedSize` | `?number=0` | Panel should collapse to this size |
60
- | `collapsible` | `?boolean=false` | Panel should collapse when resized beyond its `minSize` |
61
- | `defaultSize` | `?number` | Initial size of panel (numeric value between 1-100) |
62
- | `id` | `?string` | Panel id (unique within group); falls back to `useId` when not provided |
63
- | `maxSize` | `?number = 100` | Maximum allowable size of panel (numeric value between 1-100); defaults to `100` |
64
- | `minSize` | `?number = 10` | Minimum allowable size of panel (numeric value between 1-100); defaults to `10` |
65
- | `onCollapse` | `?() => void` | Called when panel is collapsed |
66
- | `onExpand` | `?() => void` | Called when panel is expanded |
67
- | `onResize` | `?(size: number) => void` | Called when panel is resized; `size` parameter is a numeric value between 1-100. <sup>1</sup> |
68
- | `order` | `?number` | Order of panel within group; required for groups with conditionally rendered panels |
69
- | `style` | `?CSSProperties` | CSS style to attach to root element |
70
- | `tagName` | `?string = "div"` | HTML element tag name for root element |
71
-
72
- <sup>1</sup>: If any `Panel` has an `onResize` callback, the `order` prop should be provided for all `Panel`s.
73
-
74
- `Panel` components also expose an imperative API for manual resizing:
75
- | method | description |
76
- | :----------------------- | :--------------------------------------------------------------------------------- |
77
- | `collapse()` | If panel is `collapsible`, collapse it fully. |
78
- | `expand()` | If panel is currently _collapsed_, expand it to its most recent size. |
79
- | `getId(): string` | Gets the ID of the panel. |
80
- | `getSize(): number` | Gets the current size of the panel as a percentage (`1 - 100`). |
81
- | `isCollapsed(): boolean` | Returns `true` if the panel is currently _collapsed_ (`size === 0`). |
82
- | `isExpanded(): boolean` | Returns `true` if the panel is currently _not collapsed_ (`!isCollapsed()`). |
83
- | `resize(size: number)` | Resize panel to the specified _percentage_ (`1 - 100`). |
84
-
85
- ### `PanelResizeHandle`
86
-
87
- | prop | type | description |
88
- | :--------------- | :-------------------------------------------- | :------------------------------------------------------------------------------ |
89
- | `children` | `?ReactNode` | Custom drag UI; can be any arbitrary React element(s) |
90
- | `className` | `?string` | Class name to attach to root element |
91
- | `hitAreaMargins` | `?{ coarse: number = 15; fine: number = 5; }` | Allow this much margin when determining resizable handle hit detection |
92
- | `disabled` | `?boolean` | Disable drag handle |
93
- | `id` | `?string` | Resize handle id (unique within group); falls back to `useId` when not provided |
94
- | `onDragging` | `?(isDragging: boolean) => void` | Called when group layout changes |
95
- | `style` | `?CSSProperties` | CSS style to attach to root element |
96
- | `tagName` | `?string = "div"` | HTML element tag name for root element |
97
-
98
- ---
99
-
100
- ## FAQ
101
-
102
- ### Can panel sizes be specified in pixels?
103
-
104
- 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.
105
-
106
- ### How can I fix layout/sizing problems with conditionally rendered panels?
107
-
108
- 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.
109
-
110
- ```tsx
111
- <PanelGroup direction="horizontal">
112
- {renderSideBar && (
113
- <>
114
- <Panel id="sidebar" minSize={25} order={1}>
115
- <Sidebar />
116
- </Panel>
117
- <PanelResizeHandle />
118
- </>
119
- )}
120
- <Panel minSize={25} order={2}>
121
- <Main />
122
- </Panel>
123
- </PanelGroup>
124
- ```
125
-
126
- ### Can I attach a ref to the DOM elements?
127
-
128
- 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:
129
-
130
- ```tsx
131
- import {
132
- getPanelElement,
133
- getPanelGroupElement,
134
- getResizeHandleElement,
135
- Panel,
136
- PanelGroup,
137
- PanelResizeHandle,
138
- } from "react-resizable-panels";
139
-
140
- export function Example() {
141
- const refs = useRef();
142
-
143
- useEffect(() => {
144
- const groupElement = getPanelGroupElement("group");
145
- const leftPanelElement = getPanelElement("left-panel");
146
- const rightPanelElement = getPanelElement("right-panel");
147
- const resizeHandleElement = getResizeHandleElement("resize-handle");
148
-
149
- // If you want to, you can store them in a ref to pass around
150
- refs.current = {
151
- groupElement,
152
- leftPanelElement,
153
- rightPanelElement,
154
- resizeHandleElement,
155
- };
156
- }, []);
157
-
158
- return (
159
- <PanelGroup direction="horizontal" id="group">
160
- <Panel id="left-panel">{/* ... */}</Panel>
161
- <PanelResizeHandle id="resize-handle" />
162
- <Panel id="right-panel">{/* ... */}</Panel>
163
- </PanelGroup>
164
- );
165
- }
166
- ```
167
-
168
- ### Why don't I see any resize UI?
169
-
170
- 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:
171
-
172
- ```tsx
173
- // Tailwind example
174
- <PanelResizeHandle className="w-2 bg-blue-800" />
175
- ```
176
-
177
- ### Can panel sizes be persistent?
178
-
179
- Yes. Panel groups with an `autoSaveId` prop will automatically save and restore their layouts on mount.
180
-
181
- ### How can I use persistent layouts with SSR?
182
-
183
- 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:
184
-
185
- #### Server component
3
+ React components for resizable panel groups/layouts.
186
4
 
187
- ```tsx
188
- import ResizablePanels from "@/app/ResizablePanels";
189
- import { cookies } from "next/headers";
5
+ ## Support
190
6
 
191
- export function ServerComponent() {
192
- const layout = cookies().get("react-resizable-panels:layout");
7
+ If you like this project there are several ways to support it:
193
8
 
194
- let defaultLayout;
195
- if (layout) {
196
- defaultLayout = JSON.parse(layout.value);
197
- }
9
+ - [Become a GitHub sponsor](https://github.com/sponsors/bvaughn/)
10
+ - or [buy me a coffee](http://givebrian.coffee/)
198
11
 
199
- return <ClientComponent defaultLayout={defaultLayout} />;
200
- }
201
- ```
202
-
203
- #### Client component
204
-
205
- ```tsx
206
- "use client";
207
-
208
- import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
209
-
210
- export function ClientComponent({
211
- defaultLayout = [33, 67],
212
- }: {
213
- defaultLayout: number[] | undefined;
214
- }) {
215
- const onLayout = (sizes: number[]) => {
216
- document.cookie = `react-resizable-panels:layout=${JSON.stringify(sizes)}`;
217
- };
218
-
219
- return (
220
- <PanelGroup direction="horizontal" onLayout={onLayout}>
221
- <Panel defaultSize={defaultLayout[0]}>{/* ... */}</Panel>
222
- <PanelResizeHandle className="w-2 bg-blue-800" />
223
- <Panel defaultSize={defaultLayout[1]}>{/* ... */}</Panel>
224
- </PanelGroup>
225
- );
226
- }
227
- ```
228
-
229
- > [!NOTE]
230
- > Be sure to specify a `defaultSize` prop for **every** `Panel` component to avoid layout flicker.
231
-
232
- A demo of this is available [here](https://github.com/bvaughn/react-resizable-panels-demo-ssr).
233
-
234
- #### How can I set the [CSP `"nonce"`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce) attribute?
235
-
236
- ```js
237
- import { setNonce } from "react-resizable-panels";
12
+ ## Installation
238
13
 
239
- setNonce("your-nonce-value-here");
240
- ```
241
-
242
- #### How can I disable global cursor styles?
14
+ Begin by installing the library from NPM:
243
15
 
244
- ```js
245
- import { disableGlobalCursorStyles } from "react-resizable-panels";
246
-
247
- disableGlobalCursorStyles();
16
+ ```sh
17
+ npm install react-resizable-panels
248
18
  ```
249
19
 
250
- #### How can I override the global cursor styles?
251
-
252
- ```js
253
- import { customizeGlobalCursorStyles, type CustomCursorStyleConfig } from "react-resizable-panels";
254
-
255
- function customCursor({ isPointerDown }: CustomCursorStyleConfig) {
256
- return isPointerDown ? "grabbing" : "grab";
257
- }
258
-
259
- customizeGlobalCursorStyles(customCursor);
260
- ```
20
+ ## TypeScript types
21
+
22
+ TypeScript definitions are included within the published `dist` folder
23
+
24
+ ## Documentation
25
+
26
+ Documentation for this project is available at [react-resizable-panels.vercel.app](https://react-resizable-panels.vercel.app/).
27
+
28
+ ### Group
29
+
30
+ #### Required props
31
+
32
+ <!-- Group:required:begin -->
33
+
34
+ <!-- Group:required:end -->
35
+
36
+ #### Optional props
37
+
38
+ <!-- Group:optional:begin -->
39
+
40
+ <table>
41
+ <thead>
42
+ <tr>
43
+ <th>Name</th>
44
+ <th>Description</th>
45
+ </tr>
46
+ </thead>
47
+ <tbody>
48
+ <tr>
49
+ <td>children</td>
50
+ <td><p>Panel and Separator components that comprise this group.</p>
51
+ </td>
52
+ </tr>
53
+ <tr>
54
+ <td>className</td>
55
+ <td><p>CSS class name.</p>
56
+ </td>
57
+ </tr>
58
+ <tr>
59
+ <td>defaultLayout</td>
60
+ <td><p>Default layout for the Group.</p>
61
+ <p>ℹ️ This value allows layouts to be remembered between page reloads.</p>
62
+ <p>⚠️ Refer to the documentation for how to avoid layout shift when using server components.</p>
63
+ </td>
64
+ </tr>
65
+ <tr>
66
+ <td>direction</td>
67
+ <td><p>Specifies the resizable direction (&quot;horizontal&quot; or &quot;vertical&quot;); defaults to &quot;horizontal&quot;</p>
68
+ </td>
69
+ </tr>
70
+ <tr>
71
+ <td>disableCursor</td>
72
+ <td><p>This library sets custom mouse cursor styles to indicate drag state.
73
+ Use this prop to disable that behavior for Panels and Separators in this group.</p>
74
+ </td>
75
+ </tr>
76
+ <tr>
77
+ <td>disabled</td>
78
+ <td><p>Disable resize functionality.</p>
79
+ </td>
80
+ </tr>
81
+ <tr>
82
+ <td>elementRef</td>
83
+ <td><p>Ref attached to the root <code>HTMLDivElement</code>.</p>
84
+ </td>
85
+ </tr>
86
+ <tr>
87
+ <td>groupRef</td>
88
+ <td><p>Exposes the following imperative API:</p>
89
+ <ul>
90
+ <li><code>getLayout(): Layout</code></li>
91
+ <li><code>setLayout(layout: Layout): void</code></li>
92
+ </ul>
93
+ <p>ℹ️ The <code>useGroupRef</code> and <code>useGroupCallbackRef</code> hooks are exported for convenience use in TypeScript projects.</p>
94
+ </td>
95
+ </tr>
96
+ <tr>
97
+ <td>id</td>
98
+ <td><p>Uniquely identifies this group within an application.
99
+ Falls back to <code>useId</code> when not provided.</p>
100
+ <p>ℹ️ This value will also be assigned to the <code>data-group-id</code> attribute.</p>
101
+ </td>
102
+ </tr>
103
+ <tr>
104
+ <td>onLayoutChange</td>
105
+ <td><p>Called when panel sizes change; receives a map of Panel id to size.</p>
106
+ </td>
107
+ </tr>
108
+ <tr>
109
+ <td>style</td>
110
+ <td><p>CSS properties.</p>
111
+ <p>⚠️ The following styles cannot be overridden: <code>display</code>, <code>flex-direction</code>, <code>flex-wrap</code>, and <code>overflow</code>.</p>
112
+ </td>
113
+ </tr>
114
+ </tbody>
115
+ </table>
116
+
117
+ <!-- Group:optional:end -->
118
+
119
+ ### Panel
120
+
121
+ #### Required props
122
+
123
+ <!-- Panel:required:begin -->
124
+
125
+ <!-- Panel:required:end -->
126
+
127
+ #### Optional props
128
+
129
+ <!-- Panel:optional:begin -->
130
+
131
+ <table>
132
+ <thead>
133
+ <tr>
134
+ <th>Name</th>
135
+ <th>Description</th>
136
+ </tr>
137
+ </thead>
138
+ <tbody>
139
+ <tr>
140
+ <td>className</td>
141
+ <td><p>CSS class name.</p>
142
+ <p>⚠️ Class is applied to nested <code>HTMLDivElement</code> to avoid styles that interfere with Flex layout.</p>
143
+ </td>
144
+ </tr>
145
+ <tr>
146
+ <td>collapsedSize</td>
147
+ <td><p>Panel size when collapsed; defaults to 0.</p>
148
+ </td>
149
+ </tr>
150
+ <tr>
151
+ <td>collapsible</td>
152
+ <td><p>This panel can be collapsed.</p>
153
+ <p>ℹ️ A collapsible panel will collapse when it&#39;s size is less than of the specified <code>minSize</code></p>
154
+ </td>
155
+ </tr>
156
+ <tr>
157
+ <td>defaultSize</td>
158
+ <td><p>Default size of Panel within its parent group; default is auto-assigned based on the total number of Panels.</p>
159
+ </td>
160
+ </tr>
161
+ <tr>
162
+ <td>elementRef</td>
163
+ <td><p>Ref attached to the root <code>HTMLDivElement</code>.</p>
164
+ </td>
165
+ </tr>
166
+ <tr>
167
+ <td>id</td>
168
+ <td><p>Uniquely identifies this panel within the parent group.
169
+ Falls back to <code>useId</code> when not provided.</p>
170
+ <p>ℹ️ This prop is used to associate persisted group layouts with the original panel.</p>
171
+ <p>ℹ️ This value will also be assigned to the <code>data-panel-id</code> attribute.</p>
172
+ </td>
173
+ </tr>
174
+ <tr>
175
+ <td>maxSize</td>
176
+ <td><p>Maximum size of Panel within its parent group; defaults to 100%.</p>
177
+ </td>
178
+ </tr>
179
+ <tr>
180
+ <td>minSize</td>
181
+ <td><p>Minimum size of Panel within its parent group; defaults to 0%.</p>
182
+ </td>
183
+ </tr>
184
+ <tr>
185
+ <td>onResize</td>
186
+ <td><p>Called when panel sizes change; receives a map of Panel id to size.</p>
187
+ </td>
188
+ </tr>
189
+ <tr>
190
+ <td>panelRef</td>
191
+ <td><p>Exposes the following imperative API:</p>
192
+ <ul>
193
+ <li><code>collapse(): void</code></li>
194
+ <li><code>expand(): void</code></li>
195
+ <li><code>getSize(): number</code></li>
196
+ <li><code>isCollapsed(): boolean</code></li>
197
+ <li><code>isExpanded(): boolean</code></li>
198
+ <li><code>resize(size: number): void</code></li>
199
+ </ul>
200
+ <p>ℹ️ The <code>usePanelRef</code> and <code>usePanelCallbackRef</code> hooks are exported for convenience use in TypeScript projects.</p>
201
+ </td>
202
+ </tr>
203
+ <tr>
204
+ <td>style</td>
205
+ <td><p>CSS properties.</p>
206
+ <p>⚠️ Style is applied to nested <code>HTMLDivElement</code> to avoid styles that interfere with Flex layout.</p>
207
+ </td>
208
+ </tr>
209
+ </tbody>
210
+ </table>
211
+
212
+ <!-- Panel:optional:end -->
213
+
214
+ ### Separator
215
+
216
+ #### Required props
217
+
218
+ <!-- Separator:required:begin -->
219
+
220
+ <!-- Separator:required:end -->
221
+
222
+ #### Optional props
223
+
224
+ <!-- Separator:optional:begin -->
225
+
226
+ <table>
227
+ <thead>
228
+ <tr>
229
+ <th>Name</th>
230
+ <th>Description</th>
231
+ </tr>
232
+ </thead>
233
+ <tbody>
234
+ <tr>
235
+ <td>className</td>
236
+ <td><p>CSS class name.</p>
237
+ <p>ℹ️ Use the <code>data-separator-state</code> attribute for custom <em>hover</em> and <em>active</em> styles</p>
238
+ <p>⚠️ The following properties cannot be overridden: <code>flex-grow</code>, <code>flex-shrink</code></p>
239
+ </td>
240
+ </tr>
241
+ <tr>
242
+ <td>elementRef</td>
243
+ <td><p>Ref attached to the root <code>HTMLDivElement</code>.</p>
244
+ </td>
245
+ </tr>
246
+ <tr>
247
+ <td>id</td>
248
+ <td><p>Uniquely identifies the separator within the parent group.
249
+ Falls back to <code>useId</code> when not provided.</p>
250
+ <p>ℹ️ This value will also be assigned to the <code>data-separator-id</code> attribute.</p>
251
+ </td>
252
+ </tr>
253
+ <tr>
254
+ <td>style</td>
255
+ <td><p>CSS properties.</p>
256
+ <p>ℹ️ Use the <code>data-separator-state</code> attribute for custom <em>hover</em> and <em>active</em> styles</p>
257
+ <p>⚠️ The following properties cannot be overridden: <code>flex-grow</code>, <code>flex-shrink</code></p>
258
+ </td>
259
+ </tr>
260
+ </tbody>
261
+ </table>
262
+
263
+ <!-- Separator:optional:end -->
@@ -0,0 +1,2 @@
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("react/jsx-runtime"),h=require("react");function be(e,t){const n=getComputedStyle(e),o=parseFloat(n.fontSize);return t*o}function we(e,t){const n=getComputedStyle(e.ownerDocument.body),o=parseFloat(n.fontSize);return t*o}function Re(e){return e/100*window.innerHeight}function Le(e){return e/100*window.innerWidth}function Pe(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function F({groupSize:e,panelElement:t,styleProp:n}){let o;const[r,i]=Pe(n);switch(i){case"%":{o=r/100*e;break}case"px":{o=r;break}case"rem":{o=we(t,r);break}case"em":{o=be(t,r);break}case"vh":{o=Re(r);break}case"vw":{o=Le(r);break}}return o}function L(e){return parseFloat(e.toFixed(3))}function X({group:e}){const{direction:t,panels:n}=e;return n.reduce((o,r)=>(o+=t==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o),0)}function oe(e){const{panels:t}=e,n=X({group:e});return t.map(o=>{const{element:r,panelConstraints:i}=o;let a=0;if(i.collapsedSize){const u=F({groupSize:n,panelElement:r,styleProp:i.collapsedSize});a=L(u/n*100)}let s;if(i.defaultSize){const u=F({groupSize:n,panelElement:r,styleProp:i.defaultSize});s=L(u/n*100)}let l=0;if(i.minSize){const u=F({groupSize:n,panelElement:r,styleProp:i.minSize});l=L(u/n*100)}let c=100;if(i.maxSize){const u=F({groupSize:n,panelElement:r,styleProp:i.maxSize});c=L(u/n*100)}return{collapsedSize:a,collapsible:i.collapsible===!0,defaultSize:s,minSize:l,maxSize:c,panelId:o.id}})}class Ce{#e={};addListener(t,n){const o=this.#e[t];return o===void 0?this.#e[t]=[n]:o.includes(n)||o.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const o=this.#e[t];if(o!==void 0)if(o.length===1)o[0].call(null,n);else{let r=!1,i=null;const a=Array.from(o);for(let s=0;s<a.length;s++){const l=a[s];try{l.call(null,n)}catch(c){i===null&&(r=!0,i=c)}}if(r)throw i}}removeAllListeners(){this.#e={}}removeListener(t,n){const o=this.#e[t];if(o!==void 0){const r=o.indexOf(n);r>=0&&o.splice(r,1)}}}let E={cursorFlags:0,interactionState:{state:"inactive"},mountedGroups:new Map};const D=new Ce;function I(){return E}function M(e){const t=typeof e=="function"?e(E):e;return E===t||(E={...E,...t},t.cursorFlags!==void 0&&D.emit("cursorFlagsChange",E.cursorFlags),t.interactionState!==void 0&&D.emit("interactionStateChange",E.interactionState),t.mountedGroups!==void 0&&D.emit("mountedGroupsChange",E.mountedGroups)),E}const Ee=e=>e,U=()=>{},le=1,ce=2,ue=4,fe=8,ie={coarse:10,precise:5};function Ge(e){const{direction:t,element:n,panels:o,separators:r}=e,i=Array.from(n.children).filter(c=>c instanceof HTMLElement).sort((c,u)=>{const f=c.getBoundingClientRect(),p=u.getBoundingClientRect();return t==="horizontal"?f.left-p.left:f.top-p.top}),a=[];let s,l;for(const c of i){const u=o.find(f=>f.element===c);if(u){if(s){const f=s.element.getBoundingClientRect(),p=c.getBoundingClientRect();a.push({group:e,panels:[s,u],separator:l,rect:t==="horizontal"?new DOMRect(f.right,p.top,p.left-f.right,p.height):new DOMRect(p.left,f.bottom,p.width,p.top-f.bottom)})}s=u}else{const f=r.find(p=>p.element===c);f?l=f:(s=void 0,l=void 0)}}return a}function Me(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function Ie(e,t,n){let o,r={x:1/0,y:1/0};for(const i of t){const a=Me(n,i.rect);switch(e){case"horizontal":{a.x<=r.x&&(o=i,r=a);break}case"vertical":{a.y<=r.y&&(o=i,r=a);break}}}return o?{distance:r,hitRegion:o}:void 0}let H;function ke(){return H===void 0&&(typeof matchMedia=="function"?H=!!matchMedia("(pointer:coarse)").matches:H=!1),H}function de(e,t){const n=[];return t.forEach((o,r)=>{if(r.disabled)return;const i=ke()?ie.coarse:ie.precise,a=Ge(r),s=Ie(r.direction,a,{x:e.clientX,y:e.clientY});s&&s.distance.x<=i&&s.distance.y<=i&&n.push(s.hitRegion)}),n}function se(e){if(e.defaultPrevented)return;const{mountedGroups:t}=I(),n=de(e,t),o=new Set,r=new Set,i=new Set,a=new Map;n.forEach(s=>{o.add(s.group),s.panels.forEach(c=>{r.add(c)}),s.separator&&i.add(s.separator);const l=t.get(s.group);l&&a.set(s.group,l.layout)}),M({interactionState:{hitRegions:n,initialLayoutMap:a,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}}),n.length&&e.preventDefault()}function Oe({cursorFlags:e,groups:t,state:n}){let o=0,r=0;switch(n){case"active":case"hover":t.forEach(i=>{if(!i.disableCursor)switch(i.direction){case"horizontal":{o++;break}case"vertical":{r++;break}}})}if(o===0&&r===0)return null;switch(n){case"active":{const i=(e&le)!==0,a=(e&ce)!==0,s=(e&ue)!==0,l=(e&fe)!==0;if(e){if(i)return s?"se-resize":l?"ne-resize":"e-resize";if(a)return s?"sw-resize":l?"nw-resize":"w-resize";if(s)return"s-resize";if(l)return"n-resize"}break}}return o>0&&r>0?"move":o>0?"ew-resize":"ns-resize"}let K=null,C;function V(){C===void 0&&(C=new CSSStyleSheet,document.adoptedStyleSheets=[C]);const{cursorFlags:e,interactionState:t}=I();switch(t.state){case"active":case"hover":{const n=Oe({cursorFlags:e,groups:t.hitRegions.map(o=>o.group),state:t.state});if(K===n)return;K=n,n?C.cssRules.length===0?C.insertRule(`*{cursor: ${n} !important;}`):C.replaceSync(`*{cursor: ${n} !important;}`):C.cssRules.length===1&&C.deleteRule(0);break}case"inactive":{K=null,C.cssRules.length===1&&C.deleteRule(0);break}}}function G(e,t="Assertion error"){if(!e)throw console.error(t),Error(t)}function Ae(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function R(e,t,n=0){return Math.abs(L(e)-L(t))<=n}function q(e,t){return R(e,t)?0:e>t?1:-1}function T({panelConstraints:e,size:t}){const{collapsedSize:n=0,collapsible:o,maxSize:r=100,minSize:i=0}=e;if(q(t,i)<0)if(o){const a=(n+i)/2;q(t,a)<0?t=n:t=i}else t=i;return t=Math.min(r,t),t=L(t),t}function Ne({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:o,prevLayout:r,trigger:i}){if(R(e,0))return t;const a=Object.values(t),s=Object.values(r),l=[...a],[c,u]=o;G(c!=null,"Invalid first pivot index"),G(u!=null,"Invalid second pivot index");let f=0;{const v=e<0?1:-1;let d=e<0?u:c,g=0;for(;;){const z=a[d];G(z!=null,`Previous layout not found for panel index ${d}`);const S=T({panelConstraints:n[d],size:100})-z;if(g+=S,d+=v,d<0||d>=n.length)break}const x=Math.min(Math.abs(e),Math.abs(g));e=e<0?0-x:x}{let d=e<0?c:u;for(;d>=0&&d<n.length;){const g=Math.abs(e)-Math.abs(f),x=a[d];G(x!=null,`Previous layout not found for panel index ${d}`);const z=x-g,b=T({panelConstraints:n[d],size:z});if(!R(x,b)&&(f+=x-b,l[d]=b,f.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?d--:d++}}if(Ae(s,l))return r;{const v=e<0?u:c,d=a[v];G(d!=null,`Previous layout not found for panel index ${v}`);const g=d+f,x=T({panelConstraints:n[v],size:g});if(l[v]=x,!R(x,g)){let z=g-x,S=e<0?u:c;for(;S>=0&&S<n.length;){const P=l[S];G(P!=null,`Previous layout not found for panel index ${S}`);const k=P+z,O=T({panelConstraints:n[S],size:k});if(R(P,O)||(z-=O-P,l[S]=O),R(z,0))break;e>0?S--:S++}}}const p=Object.values(l).reduce((v,d)=>d+v,0);if(!R(p,100,.1))return r;const m=Object.keys(r);return l.reduce((v,d,g)=>(v[m[g]]=d,v),{})}function Y(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(q(e[n],t[n])!==0)return!1;return!0}function B(e){if(e.defaultPrevented)return;const{interactionState:t,mountedGroups:n}=I();switch(t.state){case"active":{if(e.type!=="pointerleave"&&e.buttons===0){M(i=>i.interactionState.state==="inactive"?i:{cursorFlags:0,interactionState:{state:"inactive"}});return}let o=0;const r=new Map(n);t.hitRegions.forEach(i=>{const{direction:a,disableCursor:s,element:l,panels:c}=i.group;let u=0;t.state==="active"&&(a==="horizontal"?u=(e.clientX-t.pointerDownAtPoint.x)/l.offsetWidth*100:u=(e.clientY-t.pointerDownAtPoint.y)/l.offsetHeight*100);const f=t.initialLayoutMap.get(i.group),{derivedPanelConstraints:p,layout:m}=n.get(i.group)??{};if(p&&f&&m){const v=Ne({delta:u,initialLayout:f,panelConstraints:p,pivotIndices:i.panels.map(d=>c.indexOf(d)),prevLayout:m,trigger:"mouse-or-touch"});if(Y(v,m)){if(u!==0&&!s)switch(a){case"horizontal":{o|=u<0?le:ce;break}case"vertical":{o|=u<0?ue:fe;break}}}else{r.set(i.group,{derivedPanelConstraints:p,layout:v});const d=i.group.panels.map(({id:g})=>g).join(",");i.group.inMemoryLayouts[d]=v}}}),M({cursorFlags:o,mountedGroups:r}),V();break}default:{const o=de(e,n);o.length===0?t.state!=="inactive"&&M({interactionState:{state:"inactive"}}):M({interactionState:{hitRegions:o,state:"hover"}}),V();break}}}function re(e){if(e.defaultPrevented)return;e.preventDefault();const{interactionState:t}=I();switch(t.state){case"active":M({cursorFlags:0,interactionState:{state:"inactive"}}),V()}}function Te(e){let t=0,n=0;const o={};for(const i of e)if(i.defaultSize!==void 0){t++;const a=L(i.defaultSize);n+=a,o[i.panelId]=a}else o[i.panelId]=void 0;const r=e.length-t;if(r!==0){const i=L((100-n)/r);for(const a of e)a.defaultSize===void 0&&(o[a.panelId]=i)}return o}function De(e,t,n){const o=n[0];if(!o)return;const r=e.panels.find(a=>a.element===t);if(!r||!r.onResize)return;const i=X({group:e});r.onResize({asPercentage:L(o.inlineSize/i*100),inPixels:o.inlineSize})}function pe({layout:e,panelConstraints:t}){const o=[...Object.values(e)],r=o.reduce((s,l)=>s+l,0);if(o.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${o.map(s=>`${s}%`).join(", ")}`);if(!R(r,100)&&o.length>0)for(let s=0;s<t.length;s++){const l=o[s];G(l!=null,`No layout data found for index ${s}`);const c=100/r*l;o[s]=c}let i=0;for(let s=0;s<t.length;s++){const l=o[s];G(l!=null,`No layout data found for index ${s}`);const c=T({panelConstraints:t[s],size:l});l!=c&&(i+=l-c,o[s]=c)}if(!R(i,0))for(let s=0;s<t.length;s++){const l=o[s];G(l!=null,`No layout data found for index ${s}`);const c=l+i,u=T({panelConstraints:t[s],size:c});if(l!==u&&(i-=u-l,o[s]=u,R(i,0)))break}const a=Object.keys(e);return o.reduce((s,l,c)=>(s[a[c]]=l,s),{})}function _e(e){let t=!1;const n=new ResizeObserver(l=>{for(const c of l){const{borderBoxSize:u,target:f}=c;f===e.element?t&&M(p=>{const m=p.mountedGroups.get(e);return m?{mountedGroups:new Map(p.mountedGroups).set(e,{derivedPanelConstraints:oe(e),layout:m.layout})}:p}):De(e,f,u)}});n.observe(e.element),e.panels.forEach(l=>{l.onResize&&n.observe(l.element)});const o=oe(e),r=e.panels.map(({id:l})=>l).join(","),i=e.inMemoryLayouts[r]??e.defaultLayout??Te(o),a=pe({layout:i,panelConstraints:o}),s=M(l=>({mountedGroups:new Map(l.mountedGroups).set(e,{derivedPanelConstraints:o,layout:a})}));return t=!0,s.mountedGroups.size===1&&(window.addEventListener("pointerdown",se),window.addEventListener("pointerleave",B),window.addEventListener("pointermove",B),window.addEventListener("pointerup",re)),function(){const c=M(u=>{const f=new Map(u.mountedGroups);return f.delete(e),{mountedGroups:f}});t=!1,c.mountedGroups.size===0&&(window.removeEventListener("pointerdown",se),window.removeEventListener("pointerleave",B),window.removeEventListener("pointermove",B),window.removeEventListener("pointerup",re)),n.disconnect()}}function Z(e){const t=h.useId();return`${e??t}`}const _=typeof window<"u"?h.useLayoutEffect:h.useEffect;function J(e){const t=h.useRef(e);return _(()=>{t.current=e},[e]),h.useCallback(n=>t.current?.(n),[t])}function Q(...e){return J(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}const he="--react-resizable-panels--panel--pointer-events";function me(e,t){const n=e.replace(/[^a-zA-Z0-9\-_]/g,""),o=t.replace(/[^a-zA-Z0-9\-_]/g,"");return`--react-resizable-panels--${n}--${o}`}const ve=h.createContext(null);function ae(e,t){return t.sort(e==="horizontal"?(n,o)=>n.element.offsetLeft-o.element.offsetLeft:(n,o)=>n.element.offsetTop-o.element.offsetTop)}function $e({groupId:e}){const t=()=>{const{mountedGroups:n}=I();for(const[o,{derivedPanelConstraints:r,layout:i}]of n)if(o.id===e)return{derivedPanelConstraints:r,group:o,layout:i};throw Error(`Group ${e} not found`)};return{getLayout(){const{layout:n}=t();return n},setLayout(n){const{derivedPanelConstraints:o,group:r,layout:i}=t(),a=pe({layout:n,panelConstraints:o});return Y(i,a)||M(s=>({mountedGroups:new Map(s.mountedGroups).set(r,{derivedPanelConstraints:o,layout:a})})),a}}}function je(e,t){const n=h.useRef({getLayout:()=>({}),setLayout:Ee});h.useImperativeHandle(t,()=>n.current,[]),_(()=>{Object.assign(n.current,$e({groupId:e}))})}function Fe({children:e,className:t,defaultLayout:n,direction:o="horizontal",disableCursor:r,disabled:i,elementRef:a,groupRef:s,id:l,onLayoutChange:c,style:u}){const f=h.useRef({}),p=J(y=>{Y(f.current,y)||(f.current=y,c?.(y))}),m=Z(l),[v,d]=h.useState(!1),[g,x]=h.useState(null),z=h.useRef({}),[b,S]=h.useState(n??{}),[P,k]=h.useState([]),[O,te]=h.useState([]),ye=Q(x,a);je(m,s);const Se=h.useMemo(()=>({direction:o,id:m,registerPanel:y=>(k(w=>ae(o,[...w,y])),()=>{k(w=>w.filter(A=>A!==y))}),registerSeparator:y=>(te(w=>ae(o,[...w,y])),()=>{te(w=>w.filter(A=>A!==y))})}),[o,m]);_(()=>{if(g!==null&&P.length>0){const y={defaultLayout:n,direction:o,disableCursor:!!r,disabled:!!i,element:g,id:m,inMemoryLayouts:z.current,panels:P,separators:O},w=_e(y),W=I().mountedGroups.get(y);W&&(S(W.layout),p?.(W.layout));const xe=D.addListener("interactionStateChange",j=>{switch(j.state){case"active":case"hover":{d(j.hitRegions.some(N=>N.group===y));break}}}),ze=D.addListener("mountedGroupsChange",j=>{const N=j.get(y);N&&N.derivedPanelConstraints.length>0&&(S(N.layout),p?.(N.layout))});return()=>{w(),xe(),ze()}}},[n,o,r,i,g,m,p,P,O]);const ne={[he]:v?"none":void 0};for(const y in b){const w=me(m,y),A=b[y];ne[w]=A}return $.jsx(ve.Provider,{value:Se,children:$.jsx("div",{className:t,"data-group":!0,"data-group-id":m,"data-group-direction":o,ref:ye,style:{...u,...ne,display:"flex",flexDirection:o==="horizontal"?"row":"column",flexWrap:"nowrap",overflow:"hidden"},children:e})})}function ge(e){return`react-resizable-panels:${e}`}function He({id:e,storage:t}){try{const n=ge(e),o=t.getItem(n);if(o)return JSON.parse(o)}catch(n){console.error(n)}}function Be({id:e,layout:t,storage:n}){try{const o=ge(e);n.setItem(o,JSON.stringify(t))}catch(o){console.error(o)}}function We({groupId:e,storage:t=localStorage}){const n=h.useRef(null);n.current===null&&(n.current=He({id:e,storage:t}));const o=h.useCallback(r=>Be({id:e,layout:r,storage:t}),[e,t]);return{defaultLayout:n.current,onLayoutChange:o}}function Ue(){return h.useState(null)}function Ke(){return h.useRef(null)}function ee(){const e=h.useContext(ve);return G(e,"Unexpected"),e}function Ve({groupId:e,panelId:t}){const n=()=>{const{mountedGroups:a}=I();for(const[s,{derivedPanelConstraints:l,layout:c}]of a)if(s.id===e)return{derivedPanelConstraints:l,group:s,layout:c};throw Error(`Group ${e} not found`)},o=()=>{const a=n().derivedPanelConstraints.find(s=>s.panelId===t);if(a!==void 0)return a;throw Error(`Panel constraints not found for Panel ${t}`)},r=()=>{const a=n().group.panels.find(s=>s.id===t);if(a!==void 0)return a;throw Error(`Layout not found for Panel ${t}`)},i=()=>{const a=n().layout[t];if(a!==void 0)return a;throw Error(`Layout not found for Panel ${t}`)};return{collapse:()=>{const{collapsible:a,collapsedSize:s}=o();i()},expand:()=>{const{collapsible:a,collapsedSize:s,minSize:l}=o();i()},getSize:()=>{const{group:a}=n(),s=i(),{element:l}=r(),c=a.direction==="horizontal"?l.offsetWidth:l.offsetHeight;return{asPercentage:s,inPixels:c}},isCollapsed:()=>{const{collapsible:a,collapsedSize:s}=o(),l=i();return a&&R(s,l)},resize:a=>{if(i()!==a)switch(typeof a){case"number":{const{group:l}=n(),c=X({group:l});L(a/c*100);break}}}}}function qe(e,t){const{id:n}=ee(),o=h.useRef({collapse:U,expand:U,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:U});h.useImperativeHandle(t,()=>o.current,[]),_(()=>{Object.assign(o.current,Ve({groupId:n,panelId:e}))})}function Xe({children:e,className:t,collapsedSize:n=0,collapsible:o=!1,defaultSize:r,elementRef:i,id:a,maxSize:s="100",minSize:l="0",onResize:c,panelRef:u,style:f}){const p=!!a,m=Z(a),[v,d]=h.useState(null),g=Q(d,i),{id:x,registerPanel:z}=ee(),b=c!==null,S=J(k=>{c?.(k)});_(()=>{if(v!==null)return z({element:v,id:m,idIsStable:p,onResize:b?S:void 0,panelConstraints:{collapsedSize:n,collapsible:o,defaultSize:r,maxSize:s,minSize:l}})},[n,o,r,v,b,m,p,s,l,S,z]),qe(m,u);const P=me(x,m);return $.jsx("div",{"data-panel":!0,"data-panel-id":m,ref:g,style:{flexBasis:0,flexGrow:`var(${P}, 1)`,flexShrink:1,overflow:"hidden",pointerEvents:`var(${he})`},children:$.jsx("div",{className:t,style:{width:"100%",height:"100%",...f},children:e})})}function Ye(){return h.useState(null)}function Ze(){return h.useRef(null)}function Je({children:e,className:t,elementRef:n,id:o,style:r}){const i=Z(o),[a,s]=h.useState(null),[l,c]=h.useState("inactive"),u=Q(s,n),{registerSeparator:f}=ee();return _(()=>{if(a!==null){const p={element:a,id:i},m=f(p),v=D.addListener("interactionStateChange",d=>{c(d.state!=="inactive"&&d.hitRegions.some(g=>g.separator===p)?d.state:"inactive")});return()=>{m(),v()}}},[a,i,f]),$.jsx("div",{children:e,className:t,"data-separator":!0,"data-separator-id":i,"data-separator-state":l,ref:u,style:{flexBasis:"auto",...r,flexGrow:0,flexShrink:0}})}exports.Group=Fe;exports.Panel=Xe;exports.Separator=Je;exports.useDefaultLayout=We;exports.useGroupCallbackRef=Ue;exports.useGroupRef=Ke;exports.usePanelCallbackRef=Ye;exports.usePanelRef=Ze;
2
+ //# sourceMappingURL=react-resizable-panels.cjs.map