react-resizable-panels 3.0.6 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +302 -238
- package/dist/react-resizable-panels.cjs +2 -0
- package/dist/react-resizable-panels.cjs.map +1 -0
- package/dist/react-resizable-panels.d.ts +410 -2
- package/dist/react-resizable-panels.js +1684 -2344
- package/dist/react-resizable-panels.js.map +1 -0
- package/package.json +102 -66
- package/dist/declarations/src/Panel.d.ts +0 -70
- package/dist/declarations/src/PanelGroup.d.ts +0 -38
- package/dist/declarations/src/PanelResizeHandle.d.ts +0 -23
- package/dist/declarations/src/PanelResizeHandleRegistry.d.ts +0 -19
- package/dist/declarations/src/constants.d.ts +0 -15
- package/dist/declarations/src/hooks/usePanelGroupContext.d.ts +0 -4
- package/dist/declarations/src/index.d.ts +0 -23
- package/dist/declarations/src/types.d.ts +0 -3
- package/dist/declarations/src/utils/assert.d.ts +0 -1
- package/dist/declarations/src/utils/csp.d.ts +0 -2
- package/dist/declarations/src/utils/cursor.d.ts +0 -18
- package/dist/declarations/src/utils/dom/getPanelElement.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +0 -2
- package/dist/declarations/src/utils/rects/getIntersectingRectangle.d.ts +0 -2
- package/dist/declarations/src/utils/rects/intersects.d.ts +0 -2
- package/dist/declarations/src/utils/rects/types.d.ts +0 -6
- package/dist/react-resizable-panels.browser.development.js +0 -2592
- package/dist/react-resizable-panels.browser.js +0 -2486
- package/dist/react-resizable-panels.development.edge-light.js +0 -2365
- package/dist/react-resizable-panels.development.js +0 -2599
- 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,324 @@
|
|
|
1
|
-
|
|
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?
|
|
1
|
+
<img src="https://react-resizable-panels.vercel.app/og.svg" alt="react-resizable-panels logo" width="400" height="210" />
|
|
169
2
|
|
|
170
|
-
|
|
3
|
+
`react-resizable-panels`: React components for resizable panel groups/layouts.
|
|
171
4
|
|
|
172
|
-
|
|
173
|
-
// Tailwind example
|
|
174
|
-
<PanelResizeHandle className="w-2 bg-blue-800" />
|
|
175
|
-
```
|
|
5
|
+
## Support
|
|
176
6
|
|
|
177
|
-
|
|
7
|
+
If you like this project there are several ways to support it:
|
|
178
8
|
|
|
179
|
-
|
|
9
|
+
- [Become a GitHub sponsor](https://github.com/sponsors/bvaughn/)
|
|
10
|
+
- or [buy me a coffee](http://givebrian.coffee/)
|
|
180
11
|
|
|
181
|
-
|
|
12
|
+
## Installation
|
|
182
13
|
|
|
183
|
-
|
|
14
|
+
Begin by installing the library from NPM:
|
|
184
15
|
|
|
185
|
-
|
|
16
|
+
```sh
|
|
17
|
+
npm install react-resizable-panels
|
|
18
|
+
```
|
|
186
19
|
|
|
187
|
-
|
|
188
|
-
import ResizablePanels from "@/app/ResizablePanels";
|
|
189
|
-
import { cookies } from "next/headers";
|
|
20
|
+
## TypeScript types
|
|
190
21
|
|
|
191
|
-
|
|
192
|
-
const layout = cookies().get("react-resizable-panels:layout");
|
|
22
|
+
TypeScript definitions are included within the published `dist` folder
|
|
193
23
|
|
|
194
|
-
|
|
195
|
-
if (layout) {
|
|
196
|
-
defaultLayout = JSON.parse(layout.value);
|
|
197
|
-
}
|
|
24
|
+
## FAQs
|
|
198
25
|
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
```
|
|
26
|
+
Frequently asked questions can be found [here](https://react-resizable-panels.vercel.app/common-questions).
|
|
202
27
|
|
|
203
|
-
|
|
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
|
-
```
|
|
28
|
+
## Documentation
|
|
228
29
|
|
|
229
|
-
|
|
230
|
-
> Be sure to specify a `defaultSize` prop for **every** `Panel` component to avoid layout flicker.
|
|
30
|
+
Documentation for this project is available at [react-resizable-panels.vercel.app](https://react-resizable-panels.vercel.app/).
|
|
231
31
|
|
|
232
|
-
|
|
32
|
+
### Group
|
|
233
33
|
|
|
234
|
-
|
|
34
|
+
<!-- Group:description:begin -->
|
|
35
|
+
A Group wraps a set of resizable Panel components.
|
|
36
|
+
Group content can be resized _horizontally_ or _vertically_.
|
|
235
37
|
|
|
236
|
-
|
|
237
|
-
import { setNonce } from "react-resizable-panels";
|
|
38
|
+
Group elements always include the following attributes:
|
|
238
39
|
|
|
239
|
-
|
|
40
|
+
```html
|
|
41
|
+
<div data-group data-testid="group-id-prop" id="group-id-prop">
|
|
240
42
|
```
|
|
241
43
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
44
|
+
ℹ️ [Test id](https://testing-library.com/docs/queries/bytestid/) can be used to narrow selection when unit testing.
|
|
45
|
+
<!-- Group:description:end -->
|
|
46
|
+
|
|
47
|
+
#### Required props
|
|
48
|
+
|
|
49
|
+
<!-- Group:required-props:begin -->
|
|
50
|
+
None
|
|
51
|
+
<!-- Group:required-props:end -->
|
|
52
|
+
|
|
53
|
+
#### Optional props
|
|
54
|
+
|
|
55
|
+
<!-- Group:optional-props:begin -->
|
|
56
|
+
|
|
57
|
+
<table>
|
|
58
|
+
<thead>
|
|
59
|
+
<tr>
|
|
60
|
+
<th>Name</th>
|
|
61
|
+
<th>Description</th>
|
|
62
|
+
</tr>
|
|
63
|
+
</thead>
|
|
64
|
+
<tbody>
|
|
65
|
+
<tr>
|
|
66
|
+
<td>className</td>
|
|
67
|
+
<td><p>CSS class name.</p>
|
|
68
|
+
</td>
|
|
69
|
+
</tr>
|
|
70
|
+
<tr>
|
|
71
|
+
<td>id</td>
|
|
72
|
+
<td><p>Uniquely identifies this group within an application.
|
|
73
|
+
Falls back to <code>useId</code> when not provided.</p>
|
|
74
|
+
<p>ℹ️ This value will also be assigned to the <code>data-group</code> attribute.</p>
|
|
75
|
+
</td>
|
|
76
|
+
</tr>
|
|
77
|
+
<tr>
|
|
78
|
+
<td>style</td>
|
|
79
|
+
<td><p>CSS properties.</p>
|
|
80
|
+
<p>⚠️ The following styles cannot be overridden: <code>display</code>, <code>flex-direction</code>, <code>flex-wrap</code>, and <code>overflow</code>.</p>
|
|
81
|
+
</td>
|
|
82
|
+
</tr>
|
|
83
|
+
<tr>
|
|
84
|
+
<td>children</td>
|
|
85
|
+
<td><p>Panel and Separator components that comprise this group.</p>
|
|
86
|
+
</td>
|
|
87
|
+
</tr>
|
|
88
|
+
<tr>
|
|
89
|
+
<td>defaultLayout</td>
|
|
90
|
+
<td><p>Default layout for the Group.</p>
|
|
91
|
+
<p>ℹ️ This value allows layouts to be remembered between page reloads.</p>
|
|
92
|
+
<p>⚠️ Refer to the documentation for how to avoid layout shift when using server components.</p>
|
|
93
|
+
</td>
|
|
94
|
+
</tr>
|
|
95
|
+
<tr>
|
|
96
|
+
<td>disableCursor</td>
|
|
97
|
+
<td><p>This library sets custom mouse cursor styles to indicate drag state.
|
|
98
|
+
Use this prop to disable that behavior for Panels and Separators in this group.</p>
|
|
99
|
+
</td>
|
|
100
|
+
</tr>
|
|
101
|
+
<tr>
|
|
102
|
+
<td>disabled</td>
|
|
103
|
+
<td><p>Disable resize functionality.</p>
|
|
104
|
+
</td>
|
|
105
|
+
</tr>
|
|
106
|
+
<tr>
|
|
107
|
+
<td>elementRef</td>
|
|
108
|
+
<td><p>Ref attached to the root <code>HTMLDivElement</code>.</p>
|
|
109
|
+
</td>
|
|
110
|
+
</tr>
|
|
111
|
+
<tr>
|
|
112
|
+
<td>groupRef</td>
|
|
113
|
+
<td><p>Exposes the following imperative API:</p>
|
|
114
|
+
<ul>
|
|
115
|
+
<li><code>getLayout(): Layout</code></li>
|
|
116
|
+
<li><code>setLayout(layout: Layout): void</code></li>
|
|
117
|
+
</ul>
|
|
118
|
+
<p>ℹ️ The <code>useGroupRef</code> and <code>useGroupCallbackRef</code> hooks are exported for convenience use in TypeScript projects.</p>
|
|
119
|
+
</td>
|
|
120
|
+
</tr>
|
|
121
|
+
<tr>
|
|
122
|
+
<td>onLayoutChange</td>
|
|
123
|
+
<td><p>Called when panel sizes change; receives a map of Panel id to size.</p>
|
|
124
|
+
</td>
|
|
125
|
+
</tr>
|
|
126
|
+
<tr>
|
|
127
|
+
<td>orientation</td>
|
|
128
|
+
<td><p>Specifies the resizable orientation ("horizontal" or "vertical"); defaults to "horizontal"</p>
|
|
129
|
+
</td>
|
|
130
|
+
</tr>
|
|
131
|
+
</tbody>
|
|
132
|
+
</table>
|
|
133
|
+
|
|
134
|
+
<!-- Group:optional-props:end -->
|
|
135
|
+
|
|
136
|
+
### Panel
|
|
137
|
+
|
|
138
|
+
<!-- Panel:description:begin -->
|
|
139
|
+
A Panel wraps resizable content and can be configured with min/max size constraints and collapsible behavior.
|
|
140
|
+
|
|
141
|
+
Panel size props can be in the following formats:
|
|
142
|
+
- Percentage of the parent Group (0..100)
|
|
143
|
+
- Pixels
|
|
144
|
+
- Relative font units (em, rem)
|
|
145
|
+
- Viewport relative units (vh, vw)
|
|
146
|
+
|
|
147
|
+
ℹ️ Numeric values are assumed to be pixels.
|
|
148
|
+
Strings without explicit units are assumed to be percentages (0%..100%).
|
|
149
|
+
Percentages may also be specified as strings ending with "%" (e.g. "33%")
|
|
150
|
+
Pixels may also be specified as strings ending with the unit "px".
|
|
151
|
+
Other units should be specified as strings ending with their CSS property units (e.g. 1rem, 50vh)
|
|
152
|
+
|
|
153
|
+
Panel elements always include the following attributes:
|
|
154
|
+
|
|
155
|
+
```html
|
|
156
|
+
<div data-panel data-testid="panel-id-prop" id="panel-id-prop">
|
|
248
157
|
```
|
|
249
158
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
159
|
+
ℹ️ [Test id](https://testing-library.com/docs/queries/bytestid/) can be used to narrow selection when unit testing.
|
|
160
|
+
|
|
161
|
+
⚠️ Panel elements must be direct DOM children of their parent Group elements.
|
|
162
|
+
<!-- Panel:description:end -->
|
|
163
|
+
|
|
164
|
+
#### Required props
|
|
165
|
+
|
|
166
|
+
<!-- Panel:required-props:begin -->
|
|
167
|
+
None
|
|
168
|
+
<!-- Panel:required-props:end -->
|
|
169
|
+
|
|
170
|
+
#### Optional props
|
|
171
|
+
|
|
172
|
+
<!-- Panel:optional-props:begin -->
|
|
173
|
+
|
|
174
|
+
<table>
|
|
175
|
+
<thead>
|
|
176
|
+
<tr>
|
|
177
|
+
<th>Name</th>
|
|
178
|
+
<th>Description</th>
|
|
179
|
+
</tr>
|
|
180
|
+
</thead>
|
|
181
|
+
<tbody>
|
|
182
|
+
<tr>
|
|
183
|
+
<td>className</td>
|
|
184
|
+
<td><p>CSS class name.</p>
|
|
185
|
+
<p>⚠️ Class is applied to nested <code>HTMLDivElement</code> to avoid styles that interfere with Flex layout.</p>
|
|
186
|
+
</td>
|
|
187
|
+
</tr>
|
|
188
|
+
<tr>
|
|
189
|
+
<td>id</td>
|
|
190
|
+
<td><p>Uniquely identifies this panel within the parent group.
|
|
191
|
+
Falls back to <code>useId</code> when not provided.</p>
|
|
192
|
+
<p>ℹ️ This prop is used to associate persisted group layouts with the original panel.</p>
|
|
193
|
+
<p>ℹ️ This value will also be assigned to the <code>data-panel</code> attribute.</p>
|
|
194
|
+
</td>
|
|
195
|
+
</tr>
|
|
196
|
+
<tr>
|
|
197
|
+
<td>style</td>
|
|
198
|
+
<td><p>CSS properties.</p>
|
|
199
|
+
<p>⚠️ Style is applied to nested <code>HTMLDivElement</code> to avoid styles that interfere with Flex layout.</p>
|
|
200
|
+
</td>
|
|
201
|
+
</tr>
|
|
202
|
+
<tr>
|
|
203
|
+
<td>collapsedSize</td>
|
|
204
|
+
<td><p>Panel size when collapsed; defaults to 0%.</p>
|
|
205
|
+
</td>
|
|
206
|
+
</tr>
|
|
207
|
+
<tr>
|
|
208
|
+
<td>collapsible</td>
|
|
209
|
+
<td><p>This panel can be collapsed.</p>
|
|
210
|
+
<p>ℹ️ A collapsible panel will collapse when it's size is less than of the specified <code>minSize</code></p>
|
|
211
|
+
</td>
|
|
212
|
+
</tr>
|
|
213
|
+
<tr>
|
|
214
|
+
<td>defaultSize</td>
|
|
215
|
+
<td><p>Default size of Panel within its parent group; default is auto-assigned based on the total number of Panels.</p>
|
|
216
|
+
</td>
|
|
217
|
+
</tr>
|
|
218
|
+
<tr>
|
|
219
|
+
<td>elementRef</td>
|
|
220
|
+
<td><p>Ref attached to the root <code>HTMLDivElement</code>.</p>
|
|
221
|
+
</td>
|
|
222
|
+
</tr>
|
|
223
|
+
<tr>
|
|
224
|
+
<td>maxSize</td>
|
|
225
|
+
<td><p>Maximum size of Panel within its parent group; defaults to 100%.</p>
|
|
226
|
+
</td>
|
|
227
|
+
</tr>
|
|
228
|
+
<tr>
|
|
229
|
+
<td>minSize</td>
|
|
230
|
+
<td><p>Minimum size of Panel within its parent group; defaults to 0%.</p>
|
|
231
|
+
</td>
|
|
232
|
+
</tr>
|
|
233
|
+
<tr>
|
|
234
|
+
<td>onResize</td>
|
|
235
|
+
<td><p>Called when panel sizes change.
|
|
236
|
+
@param panelSize Panel size (both as a percentage of the parent Group and in pixels)
|
|
237
|
+
@param id Panel id (if one was provided as a prop)
|
|
238
|
+
@param prevPanelSize Previous panel size (will be undefined on mount)</p>
|
|
239
|
+
</td>
|
|
240
|
+
</tr>
|
|
241
|
+
<tr>
|
|
242
|
+
<td>panelRef</td>
|
|
243
|
+
<td><p>Exposes the following imperative API:</p>
|
|
244
|
+
<ul>
|
|
245
|
+
<li><code>collapse(): void</code></li>
|
|
246
|
+
<li><code>expand(): void</code></li>
|
|
247
|
+
<li><code>getSize(): number</code></li>
|
|
248
|
+
<li><code>isCollapsed(): boolean</code></li>
|
|
249
|
+
<li><code>resize(size: number): void</code></li>
|
|
250
|
+
</ul>
|
|
251
|
+
<p>ℹ️ The <code>usePanelRef</code> and <code>usePanelCallbackRef</code> hooks are exported for convenience use in TypeScript projects.</p>
|
|
252
|
+
</td>
|
|
253
|
+
</tr>
|
|
254
|
+
</tbody>
|
|
255
|
+
</table>
|
|
256
|
+
|
|
257
|
+
<!-- Panel:optional-props:end -->
|
|
258
|
+
|
|
259
|
+
### Separator
|
|
260
|
+
|
|
261
|
+
<!-- Separator:description:begin -->
|
|
262
|
+
Separators are not _required_ but they are _recommended_ as they improve keyboard accessibility.
|
|
263
|
+
|
|
264
|
+
⚠️ Separator elements must be direct DOM children of their parent Group elements.
|
|
265
|
+
|
|
266
|
+
Separator elements always include the following attributes:
|
|
267
|
+
|
|
268
|
+
```html
|
|
269
|
+
<div data-separator data-testid="separator-id-prop" id="separator-id-prop" role="separator">
|
|
260
270
|
```
|
|
271
|
+
|
|
272
|
+
ℹ️ [Test id](https://testing-library.com/docs/queries/bytestid/) can be used to narrow selection when unit testing.
|
|
273
|
+
|
|
274
|
+
ℹ️ In addition to the attributes shown above, separator also renders all required [WAI-ARIA properties](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/separator_role#associated_wai-aria_roles_states_and_properties).
|
|
275
|
+
<!-- Separator:description:end -->
|
|
276
|
+
|
|
277
|
+
#### Required props
|
|
278
|
+
|
|
279
|
+
<!-- Separator:required-props:begin -->
|
|
280
|
+
None
|
|
281
|
+
<!-- Separator:required-props:end -->
|
|
282
|
+
|
|
283
|
+
#### Optional props
|
|
284
|
+
|
|
285
|
+
<!-- Separator:optional-props:begin -->
|
|
286
|
+
|
|
287
|
+
<table>
|
|
288
|
+
<thead>
|
|
289
|
+
<tr>
|
|
290
|
+
<th>Name</th>
|
|
291
|
+
<th>Description</th>
|
|
292
|
+
</tr>
|
|
293
|
+
</thead>
|
|
294
|
+
<tbody>
|
|
295
|
+
<tr>
|
|
296
|
+
<td>className</td>
|
|
297
|
+
<td><p>CSS class name.</p>
|
|
298
|
+
<p>ℹ️ Use the <code>data-separator</code> attribute for custom <em>hover</em> and <em>active</em> styles</p>
|
|
299
|
+
<p>⚠️ The following properties cannot be overridden: <code>flex-grow</code>, <code>flex-shrink</code></p>
|
|
300
|
+
</td>
|
|
301
|
+
</tr>
|
|
302
|
+
<tr>
|
|
303
|
+
<td>id</td>
|
|
304
|
+
<td><p>Uniquely identifies the separator within the parent group.
|
|
305
|
+
Falls back to <code>useId</code> when not provided.</p>
|
|
306
|
+
<p>ℹ️ This value will also be assigned to the <code>data-separator</code> attribute.</p>
|
|
307
|
+
</td>
|
|
308
|
+
</tr>
|
|
309
|
+
<tr>
|
|
310
|
+
<td>style</td>
|
|
311
|
+
<td><p>CSS properties.</p>
|
|
312
|
+
<p>ℹ️ Use the <code>data-separator</code> attribute for custom <em>hover</em> and <em>active</em> styles</p>
|
|
313
|
+
<p>⚠️ The following properties cannot be overridden: <code>flex-grow</code>, <code>flex-shrink</code></p>
|
|
314
|
+
</td>
|
|
315
|
+
</tr>
|
|
316
|
+
<tr>
|
|
317
|
+
<td>elementRef</td>
|
|
318
|
+
<td><p>Ref attached to the root <code>HTMLDivElement</code>.</p>
|
|
319
|
+
</td>
|
|
320
|
+
</tr>
|
|
321
|
+
</tbody>
|
|
322
|
+
</table>
|
|
323
|
+
|
|
324
|
+
<!-- Separator:optional-props:end -->
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),x=require("react");function z(e,t="Assertion error"){if(!e)throw Error(t)}function V({group:e}){const{orientation:t,panels:n}=e;return n.reduce((o,i)=>(o+=t==="horizontal"?i.element.offsetWidth:i.element.offsetHeight,o),0)}function oe(e,t){return t.sort(e==="horizontal"?Be:Ue)}function Be(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function Ue(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function we(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function Le(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 Ke({orientation:e,rects:t,targetRect:n}){const o={x:n.x+n.width/2,y:n.y+n.height/2};let i,a=Number.MAX_VALUE;for(const l of t){const{x:r,y:s}=Le(o,l),u=e==="horizontal"?r:s;u<a&&(a=u,i=l)}return z(i,"No rect found"),i}function Re(e){const{element:t,orientation:n,panels:o,separators:i}=e,a=oe(n,Array.from(t.children).filter(we).map(f=>({element:f}))).map(({element:f})=>f),l=[];let r=!1,s,u=[];for(const f of a)if(f.hasAttribute("data-panel")){const p=o.find(m=>m.element===f);if(p){if(s){const m=s.element.getBoundingClientRect(),h=f.getBoundingClientRect();let c;if(r){const d=n==="horizontal"?new DOMRect(m.right,m.top,0,m.height):new DOMRect(m.left,m.bottom,m.width,0),y=n==="horizontal"?new DOMRect(h.left,h.top,0,h.height):new DOMRect(h.left,h.top,h.width,0);switch(u.length){case 0:{c=[d,y];break}case 1:{const g=u[0],v=Ke({orientation:n,rects:[m,h],targetRect:g.element.getBoundingClientRect()});c=[g,v===m?y:d];break}default:{c=u;break}}}else u.length?c=u:c=[n==="horizontal"?new DOMRect(m.right,h.top,h.left-m.right,h.height):new DOMRect(h.left,m.bottom,h.width,h.top-m.bottom)];for(const d of c)l.push({group:e,groupSize:V({group:e}),panels:[s,p],separator:"width"in d?void 0:d,rect:"width"in d?d:d.element.getBoundingClientRect()})}r=!1,s=p,u=[]}}else if(f.hasAttribute("data-separator")){const p=i.find(m=>m.element===f);p?u.push(p):(s=void 0,u=[])}else r=!0;return l}function qe(e,t){const n=getComputedStyle(e),o=parseFloat(n.fontSize);return t*o}function Xe(e,t){const n=getComputedStyle(e.ownerDocument.body),o=parseFloat(n.fontSize);return t*o}function Ye(e){return e/100*window.innerHeight}function Ze(e){return e/100*window.innerWidth}function Je(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 J({groupSize:e,panelElement:t,styleProp:n}){let o;const[i,a]=Je(n);switch(a){case"%":{o=i/100*e;break}case"px":{o=i;break}case"rem":{o=Xe(t,i);break}case"em":{o=qe(t,i);break}case"vh":{o=Ye(i);break}case"vw":{o=Ze(i);break}}return o}function G(e){return parseFloat(e.toFixed(3))}function fe(e){const{panels:t}=e,n=V({group:e});return n===0?t.map(o=>({collapsedSize:0,collapsible:o.panelConstraints.collapsible===!0,defaultSize:void 0,minSize:0,maxSize:100,panelId:o.id})):t.map(o=>{const{element:i,panelConstraints:a}=o;let l=0;if(a.collapsedSize){const f=J({groupSize:n,panelElement:i,styleProp:a.collapsedSize});l=G(f/n*100)}let r;if(a.defaultSize){const f=J({groupSize:n,panelElement:i,styleProp:a.defaultSize});r=G(f/n*100)}let s=0;if(a.minSize){const f=J({groupSize:n,panelElement:i,styleProp:a.minSize});s=G(f/n*100)}let u=100;if(a.maxSize){const f=J({groupSize:n,panelElement:i,styleProp:a.maxSize});u=G(f/n*100)}return{collapsedSize:l,collapsible:a.collapsible===!0,defaultSize:r,minSize:s,maxSize:u,panelId:o.id}})}class Qe{#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 i=!1,a=null;const l=Array.from(o);for(let r=0;r<l.length;r++){const s=l[r];try{s.call(null,n)}catch(u){a===null&&(i=!0,a=u)}}if(i)throw a}}removeAllListeners(){this.#e={}}removeListener(t,n){const o=this.#e[t];if(o!==void 0){const i=o.indexOf(n);i>=0&&o.splice(i,1)}}}function C(e,t,n=0){return Math.abs(G(e)-G(t))<=n}let E={cursorFlags:0,interactionState:{state:"inactive"},mountedGroups:new Map};const T=new Qe;function D(){return E}function k(e){const t=typeof e=="function"?e(E):e;if(E===t)return E;const n=E;return E={...E,...t},t.cursorFlags!==void 0&&T.emit("cursorFlagsChange",E.cursorFlags),t.interactionState!==void 0&&T.emit("interactionStateChange",E.interactionState),t.mountedGroups!==void 0&&(E.mountedGroups.forEach((o,i)=>{o.derivedPanelConstraints.forEach(a=>{if(a.collapsible){const{layout:l}=n.mountedGroups.get(i)??{};if(l){const r=C(a.collapsedSize,o.layout[a.panelId]),s=C(a.collapsedSize,l[a.panelId]);r&&!s&&(i.inMemoryLastExpandedPanelSizes[a.panelId]=l[a.panelId])}}})}),T.emit("mountedGroupsChange",E.mountedGroups)),E}function et(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 X(e,t){return C(e,t)?0:e>t?1:-1}function H({panelConstraints:e,size:t}){const{collapsedSize:n=0,collapsible:o,maxSize:i=100,minSize:a=0}=e;if(X(t,a)<0)if(o){const l=(n+a)/2;X(t,l)<0?t=n:t=a}else t=a;return t=Math.min(i,t),t=G(t),t}function Y({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:o,prevLayout:i,trigger:a}){if(C(e,0))return t;const l=Object.values(t),r=Object.values(i),s=[...l],[u,f]=o;z(u!=null,"Invalid first pivot index"),z(f!=null,"Invalid second pivot index");let p=0;if(a==="keyboard"){{const c=e<0?f:u,d=n[c];z(d,`Panel constraints not found for index ${c}`);const{collapsedSize:y=0,collapsible:g,minSize:v=0}=d;if(g){const b=l[c];if(z(b!=null,`Previous layout not found for panel index ${c}`),C(b,y)){const S=v-b;X(S,Math.abs(e))>0&&(e=e<0?0-S:S)}}}{const c=e<0?u:f,d=n[c];z(d,`No panel constraints found for index ${c}`);const{collapsedSize:y=0,collapsible:g,minSize:v=0}=d;if(g){const b=l[c];if(z(b!=null,`Previous layout not found for panel index ${c}`),C(b,v)){const S=b-y;X(S,Math.abs(e))>0&&(e=e<0?0-S:S)}}}}{const c=e<0?1:-1;let d=e<0?f:u,y=0;for(;;){const v=l[d];z(v!=null,`Previous layout not found for panel index ${d}`);const S=H({panelConstraints:n[d],size:100})-v;if(y+=S,d+=c,d<0||d>=n.length)break}const g=Math.min(Math.abs(e),Math.abs(y));e=e<0?0-g:g}{let d=e<0?u:f;for(;d>=0&&d<n.length;){const y=Math.abs(e)-Math.abs(p),g=l[d];z(g!=null,`Previous layout not found for panel index ${d}`);const v=g-y,b=H({panelConstraints:n[d],size:v});if(!C(g,b)&&(p+=g-b,s[d]=b,p.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?d--:d++}}if(et(r,s))return i;{const c=e<0?f:u,d=l[c];z(d!=null,`Previous layout not found for panel index ${c}`);const y=d+p,g=H({panelConstraints:n[c],size:y});if(s[c]=g,!C(g,y)){let v=y-g,S=e<0?f:u;for(;S>=0&&S<n.length;){const w=s[S];z(w!=null,`Previous layout not found for panel index ${S}`);const L=w+v,M=H({panelConstraints:n[S],size:L});if(C(w,M)||(v-=M-w,s[S]=M),C(v,0))break;e>0?S--:S++}}}const m=Object.values(s).reduce((c,d)=>d+c,0);if(!C(m,100,.1))return i;const h=Object.keys(i);return s.reduce((c,d,y)=>(c[h[y]]=d,c),{})}function ee(e){const{mountedGroups:t}=D();for(const[n]of t)if(n.separators.some(o=>o.element===e))return n;throw Error("Could not find parent Group for separator element")}function W(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||X(e[n],t[n])!==0)return!1;return!0}function N({layout:e,panelConstraints:t}){const o=[...Object.values(e)],i=o.reduce((r,s)=>r+s,0);if(o.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${o.map(r=>`${r}%`).join(", ")}`);if(!C(i,100)&&o.length>0)for(let r=0;r<t.length;r++){const s=o[r];z(s!=null,`No layout data found for index ${r}`);const u=100/i*s;o[r]=u}let a=0;for(let r=0;r<t.length;r++){const s=o[r];z(s!=null,`No layout data found for index ${r}`);const u=H({panelConstraints:t[r],size:s});s!=u&&(a+=s-u,o[r]=u)}if(!C(a,0))for(let r=0;r<t.length;r++){const s=o[r];z(s!=null,`No layout data found for index ${r}`);const u=s+a,f=H({panelConstraints:t[r],size:u});if(s!==f&&(a-=f-s,o[r]=f,C(a,0)))break}const l=Object.keys(e);return o.reduce((r,s,u)=>(r[l[u]]=s,r),{})}function Pe({groupId:e}){const t=()=>{const{mountedGroups:n}=D();for(const[o,i]of n)if(o.id===e)return{group:o,...i};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){const{defaultLayoutDeferred:n,layout:o}=t();return n?{}:o},setLayout(n){const{defaultLayoutDeferred:o,derivedPanelConstraints:i,group:a,layout:l,separatorToPanels:r}=t(),s=N({layout:n,panelConstraints:i});return o?l:(W(l,s)||k(u=>({mountedGroups:new Map(u.mountedGroups).set(a,{defaultLayoutDeferred:o,derivedPanelConstraints:i,layout:s,separatorToPanels:r})})),s)}}}function Ce(e){const{mountedGroups:t}=D(),n=t.get(e);return z(n,`Mounted Group ${e.id} not found`),n}function O(e,t){const n=ee(e),o=Ce(n),i=n.separators.find(p=>p.element===e);z(i,"Matching separator not found");const a=o.separatorToPanels.get(i);z(a,"Matching panels not found");const l=a.map(p=>n.panels.indexOf(p)),s=Pe({groupId:n.id}).getLayout(),u=Y({delta:t,initialLayout:s,panelConstraints:o.derivedPanelConstraints,pivotIndices:l,prevLayout:s,trigger:"keyboard"}),f=N({layout:u,panelConstraints:o.derivedPanelConstraints});W(s,f)||k(p=>({mountedGroups:new Map(p.mountedGroups).set(n,{defaultLayoutDeferred:o.defaultLayoutDeferred,derivedPanelConstraints:o.derivedPanelConstraints,layout:f,separatorToPanels:o.separatorToPanels})}))}function de(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=ee(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&O(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&O(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&O(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&O(t,-5);break}case"End":{e.preventDefault(),O(t,100);break}case"Enter":{e.preventDefault();const o=ee(t),{derivedPanelConstraints:i,layout:a,separatorToPanels:l}=Ce(o),r=o.separators.find(p=>p.element===t);z(r,"Matching separator not found");const s=l.get(r);z(s,"Matching panels not found");const u=s[0],f=i.find(p=>p.panelId===u.id);if(z(f,"Panel metadata not found"),f.collapsible){const p=a[u.id],m=f.collapsedSize===p?o.inMemoryLastExpandedPanelSizes[u.id]??f.minSize:f.collapsedSize;O(t,m-p)}break}case"F6":{e.preventDefault();const i=ee(t).separators.map(s=>s.element),a=Array.from(i).findIndex(s=>s===e.currentTarget);z(a!==null,"Index not found");const l=e.shiftKey?a>0?a-1:i.length-1:a+1<i.length?a+1:0;i[l].focus();break}case"Home":{e.preventDefault(),O(t,-100);break}}}const tt=e=>e,te=()=>{},Me=1,Ee=2,ke=4,Ie=8,pe={coarse:10,precise:5};function nt(e,t,n){let o,i={x:1/0,y:1/0};for(const a of t){const l=Le(n,a.rect);switch(e){case"horizontal":{l.x<=i.x&&(o=a,i=l);break}case"vertical":{l.y<=i.y&&(o=a,i=l);break}}}return o?{distance:i,hitRegion:o}:void 0}let Q;function ot(){return Q===void 0&&(typeof matchMedia=="function"?Q=!!matchMedia("(pointer:coarse)").matches:Q=!1),Q}function rt(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function it(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:ye(e),b:ye(t)};let o;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),o=e;z(o,"Stacking order can only be calculated for elements with a common ancestor");const i={a:he(me(n.a)),b:he(me(n.b))};if(i.a===i.b){const a=o.childNodes,l={a:n.a.at(-1),b:n.b.at(-1)};let r=a.length;for(;r--;){const s=a[r];if(s===l.a)return 1;if(s===l.b)return-1}}return Math.sign(i.a-i.b)}const st=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function at(e){const t=getComputedStyle(Ge(e)??e).display;return t==="flex"||t==="inline-flex"}function lt(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||at(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||st.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function me(e){let t=e.length;for(;t--;){const n=e[t];if(z(n,"Missing node"),lt(n))return n}return null}function he(e){return e&&Number(getComputedStyle(e).zIndex)||0}function ye(e){const t=[];for(;e;)t.push(e),e=Ge(e);return t}function Ge(e){const{parentNode:t}=e;return rt(t)?t.host:t}function ut(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function ct({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!we(n)||n.contains(e)||e.contains(n))return!0;if(it(n,e)>0){let o=n;for(;o;){if(o.contains(e))return!0;if(ut(o.getBoundingClientRect(),t))return!1;o=o.parentElement}}return!0}function De(e,t){const n=[];return t.forEach((o,i)=>{if(i.disabled)return;const a=ot()?pe.coarse:pe.precise,l=Re(i),r=nt(i.orientation,l,{x:e.clientX,y:e.clientY});r&&r.distance.x<=a&&r.distance.y<=a&&ct({groupElement:i.element,hitRegion:r.hitRegion.rect,pointerEventTarget:e.target})&&n.push(r.hitRegion)}),n}function ge(e){if(e.defaultPrevented)return;if(e.pointerType==="mouse"&&e.button>0)return;const{mountedGroups:t}=D(),n=De(e,t),o=new Set,i=new Set,a=new Set,l=new Map;let r=!1;n.forEach(s=>{o.add(s.group),s.panels.forEach(f=>{i.add(f)}),s.separator&&(a.add(s.separator),r||(r=!0,s.separator.element.focus()));const u=t.get(s.group);u&&l.set(s.group,u.layout)}),k({interactionState:{hitRegions:n,initialLayoutMap:l,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}}),n.length&&e.preventDefault()}function ft({cursorFlags:e,groups:t,state:n}){let o=0,i=0;switch(n){case"active":case"hover":t.forEach(a=>{if(!a.disableCursor)switch(a.orientation){case"horizontal":{o++;break}case"vertical":{i++;break}}})}if(o===0&&i===0)return null;switch(n){case"active":{const a=(e&Me)!==0,l=(e&Ee)!==0,r=(e&ke)!==0,s=(e&Ie)!==0;if(e){if(a)return r?"se-resize":s?"ne-resize":"e-resize";if(l)return r?"sw-resize":s?"nw-resize":"w-resize";if(r)return"s-resize";if(s)return"n-resize"}break}}return o>0&&i>0?"move":o>0?"ew-resize":"ns-resize"}const Se=new WeakMap;function re(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=Se.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets=[n]);const{cursorFlags:o,interactionState:i}=D();switch(i.state){case"active":case"hover":{const a=ft({cursorFlags:o,groups:i.hitRegions.map(r=>r.group),state:i.state}),l=`*{cursor: ${a} !important; ${i.state==="active"?"touch-action: none;":""} }`;if(t===l)return;t=l,a?n.cssRules.length===0?n.insertRule(l):n.replaceSync(l):n.cssRules.length===1&&n.deleteRule(0);break}case"inactive":{t=void 0,n.cssRules.length===1&&n.deleteRule(0);break}}Se.set(e,{prevStyle:t,styleSheet:n})}function Oe({document:e,event:t,hitRegions:n,initialLayoutMap:o,mountedGroups:i,pointerDownAtPoint:a}){let l=0;const r=new Map(i);n.forEach(s=>{const{group:u,groupSize:f}=s,{disableCursor:p,orientation:m,panels:h}=u;let c=0;a?m==="horizontal"?c=(t.clientX-a.x)/f*100:c=(t.clientY-a.y)/f*100:m==="horizontal"?c=t.clientX<0?-100:100:c=t.clientY<0?-100:100;const d=o.get(u),{defaultLayoutDeferred:y,derivedPanelConstraints:g,layout:v,separatorToPanels:b}=i.get(u)??{defaultLayoutDeferred:!1};if(g&&d&&v&&b){const S=Y({delta:c,initialLayout:d,panelConstraints:g,pivotIndices:s.panels.map(w=>h.indexOf(w)),prevLayout:v,trigger:"mouse-or-touch"});if(W(S,v)){if(c!==0&&!p)switch(m){case"horizontal":{l|=c<0?Me:Ee;break}case"vertical":{l|=c<0?ke:Ie;break}}}else{r.set(s.group,{defaultLayoutDeferred:y,derivedPanelConstraints:g,layout:S,separatorToPanels:b});const w=s.group.panels.map(({id:L})=>L).join(",");s.group.inMemoryLayouts[w]=S}}}),k({cursorFlags:l,mountedGroups:r}),re(e)}function ve(e){const{interactionState:t,mountedGroups:n}=D();switch(t.state){case"active":Oe({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n})}}function xe(e){if(e.defaultPrevented)return;const{interactionState:t,mountedGroups:n}=D();switch(t.state){case"active":{if(e.buttons===0){k(o=>o.interactionState.state==="inactive"?o:{cursorFlags:0,interactionState:{state:"inactive"}});return}Oe({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint});break}default:{const o=De(e,n);o.length===0?t.state!=="inactive"&&k({interactionState:{state:"inactive"}}):k({interactionState:{hitRegions:o,state:"hover"}}),re(e.currentTarget);break}}}function be(e){if(e.defaultPrevented)return;if(e.pointerType==="mouse"&&e.button>0)return;e.preventDefault();const{interactionState:t}=D();switch(t.state){case"active":k({cursorFlags:0,interactionState:{state:"inactive"}}),re(e.currentTarget)}}function ze(e){let t=0,n=0;const o={};for(const a of e)if(a.defaultSize!==void 0){t++;const l=G(a.defaultSize);n+=l,o[a.panelId]=l}else o[a.panelId]=void 0;const i=e.length-t;if(i!==0){const a=G((100-n)/i);for(const l of e)l.defaultSize===void 0&&(o[l.panelId]=a)}return o}function dt(e,t,n){if(!n[0])return;const i=e.panels.find(u=>u.element===t);if(!i||!i.onResize)return;const a=V({group:e}),l=e.orientation==="horizontal"?i.element.offsetWidth:i.element.offsetHeight,r=i.mutableValues.prevSize,s={asPercentage:G(l/a*100),inPixels:l};i.mutableValues.prevSize=s,i.onResize(s,i.id,r)}function pt(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const o in e)if(e[o]!==t[o])return!1;return!0}function mt(e,t){const n=e.map(i=>i.id),o=Object.keys(t);if(n.length!==o.length)return!1;for(const i of n)if(!o.includes(i))return!1;return!0}const F=new Map;function ht(e){let t=!0;z(e.element.ownerDocument.defaultView,"Cannot register an unmounted Group");const n=e.element.ownerDocument.defaultView.ResizeObserver,o=new Set,i=new Set,a=new n(c=>{for(const d of c){const{borderBoxSize:y,target:g}=d;if(g===e.element){if(t){if(V({group:e})===0)return;k(b=>{const S=b.mountedGroups.get(e);if(S){const w=fe(e),L=S.defaultLayoutDeferred?ze(w):S.layout,M=N({layout:L,panelConstraints:w});return!S.defaultLayoutDeferred&&W(L,M)&&pt(S.derivedPanelConstraints,w)?b:{mountedGroups:new Map(b.mountedGroups).set(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:w,layout:M,separatorToPanels:S.separatorToPanels})}}return b})}}else dt(e,g,y)}});a.observe(e.element),e.panels.forEach(c=>{z(!o.has(c.id),`Panel ids must be unique; id "${c.id}" was used more than once`),o.add(c.id),c.onResize&&a.observe(c.element)});const l=V({group:e}),r=fe(e),s=e.panels.map(({id:c})=>c).join(",");let u=e.defaultLayout;u&&(mt(e.panels,u)||(u=void 0));const f=e.inMemoryLayouts[s]??u??ze(r),p=N({layout:f,panelConstraints:r}),m=Re(e),h=e.element.ownerDocument;return k(c=>{const d=new Map;return F.set(h,(F.get(h)??0)+1),m.forEach(y=>{y.separator&&d.set(y.separator,y.panels)}),{mountedGroups:new Map(c.mountedGroups).set(e,{defaultLayoutDeferred:l===0,derivedPanelConstraints:r,layout:p,separatorToPanels:d})}}),e.separators.forEach(c=>{z(!i.has(c.id),`Separator ids must be unique; id "${c.id}" was used more than once`),i.add(c.id),c.element.addEventListener("keydown",de)}),F.get(h)===1&&(h.addEventListener("pointerdown",ge,!0),h.addEventListener("pointerleave",ve),h.addEventListener("pointermove",xe),h.addEventListener("pointerup",be,!0)),function(){t=!1,F.set(h,Math.max(0,(F.get(h)??0)-1)),k(d=>{const y=new Map(d.mountedGroups);return y.delete(e),{mountedGroups:y}}),e.separators.forEach(d=>{d.element.removeEventListener("keydown",de)}),F.get(h)||(h.removeEventListener("pointerdown",ge,!0),h.removeEventListener("pointerleave",ve),h.removeEventListener("pointermove",xe),h.removeEventListener("pointerup",be,!0)),a.disconnect()}}function yt(){const[e,t]=x.useState({}),n=x.useCallback(()=>t({}),[]);return[e,n]}function ie(e){const t=x.useId();return`${e??t}`}const _=typeof window<"u"?x.useLayoutEffect:x.useEffect;function se(e){const t=x.useRef(e);return _(()=>{t.current=e},[e]),x.useCallback((...n)=>t.current?.(...n),[t])}function ae(...e){return se(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function gt(e){const t=x.useRef({...e});return _(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const Te="--react-resizable-panels--panel--pointer-events";function Ne(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 _e=x.createContext(null);function St(e,t){const n=x.useRef({getLayout:()=>({}),setLayout:tt});x.useImperativeHandle(t,()=>n.current,[]),_(()=>{Object.assign(n.current,Pe({groupId:e}))})}function Ae({children:e,className:t,defaultLayout:n,disableCursor:o,disabled:i,elementRef:a,groupRef:l,id:r,onLayoutChange:s,orientation:u="horizontal",style:f,...p}){const m=x.useRef({}),h=se(R=>{W(m.current,R)||(m.current=R,s?.(R))}),c=ie(r),d=x.useRef(null),[y,g]=x.useState(!1),[v,b]=x.useState(n??{}),[S,w]=yt(),L=x.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],separators:[]}),M=ae(d,a);St(c,l);const B=x.useMemo(()=>({id:c,orientation:u,registerPanel:R=>{const P=L.current;return P.panels=oe(u,[...P.panels,R]),w(),()=>{P.panels=P.panels.filter(I=>I!==R),w()}},registerSeparator:R=>{const P=L.current;return P.separators=oe(u,[...P.separators,R]),w(),()=>{P.separators=P.separators.filter(I=>I!==R),w()}}}),[c,w,u]),U=gt({defaultLayout:n,disableCursor:o}),A=x.useRef(null);_(()=>{const R=d.current;if(R===null)return;const P=L.current,I={defaultLayout:U.defaultLayout,disableCursor:!!U.disableCursor,disabled:!!i,element:R,id:c,inMemoryLastExpandedPanelSizes:L.current.lastExpandedPanelSizes,inMemoryLayouts:L.current.layouts,orientation:u,panels:P.panels,separators:P.separators};A.current=I;const Fe=ht(I),ue=D().mountedGroups.get(I);if(ue){const{defaultLayoutDeferred:$,derivedPanelConstraints:j,layout:Z}=ue;!$&&j.length>0&&(b(Z),h?.(Z))}const He=T.addListener("interactionStateChange",$=>{switch($.state){case"active":{g($.hitRegions.some(j=>j.group===I));break}default:{g(!1);break}}}),Ve=T.addListener("mountedGroupsChange",$=>{const j=$.get(I);if(j){const{defaultLayoutDeferred:Z,derivedPanelConstraints:We,layout:ce}=j;if(Z||We.length===0)return;b(ce),h?.(ce)}});return()=>{A.current=null,Fe(),He(),Ve()}},[i,c,h,u,S,U]),x.useEffect(()=>{const R=A.current;R&&(R.defaultLayout=n,R.disableCursor=!!o)});const K={[Te]:y?"none":void 0};for(const R in v){const P=Ne(c,R),I=v[R];K[P]=I}return q.jsx(_e.Provider,{value:B,children:q.jsx("div",{...p,"aria-orientation":u,className:t,"data-group":!0,"data-testid":c,id:c,ref:M,style:{height:"100%",width:"100%",overflow:"hidden",...f,...K,display:"flex",flexDirection:u==="horizontal"?"row":"column",flexWrap:"nowrap"},children:e})})}Ae.displayName="Group";function vt(e,t=10){let n=null;return o=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(o)},t)}}function ne(e,t){return`react-resizable-panels:${[e,...t].join(":")}`}function xt({debounceSaveMs:e=100,panelIds:t,storage:n=localStorage,...o}){const i=t!==void 0,a="id"in o?o.id:o.groupId,l=ne(a,t??[]),r=x.useSyncExternalStore(bt,()=>n.getItem(l),()=>n.getItem(l)),s=x.useMemo(()=>r?JSON.parse(r):void 0,[r]),u=x.useMemo(()=>{const f=p=>{let m;i?m=ne(a,Object.keys(p)):m=ne(a,[]);try{n.setItem(m,JSON.stringify(p))}catch(h){console.error(h)}};return e>0?vt(f,e):f},[e,i,a,n]);return{defaultLayout:s,onLayoutChange:u}}function bt(){return function(){}}function zt(){return x.useState(null)}function wt(){return x.useRef(null)}function le(){const e=x.useContext(_e);return z(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function Lt({groupId:e,panelId:t}){const n=()=>{const{mountedGroups:r}=D();for(const[s,{defaultLayoutDeferred:u,derivedPanelConstraints:f,layout:p,separatorToPanels:m}]of r)if(s.id===e)return{defaultLayoutDeferred:u,derivedPanelConstraints:f,group:s,layout:p,separatorToPanels:m};throw Error(`Group ${e} not found`)},o=()=>{const r=n().derivedPanelConstraints.find(s=>s.panelId===t);if(r!==void 0)return r;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{const r=n().group.panels.find(s=>s.id===t);if(r!==void 0)return r;throw Error(`Layout not found for Panel ${t}`)},a=()=>{const r=n().layout[t];if(r!==void 0)return r;throw Error(`Layout not found for Panel ${t}`)},l=r=>{const s=a();if(r===s)return;const{defaultLayoutDeferred:u,derivedPanelConstraints:f,group:p,layout:m,separatorToPanels:h}=n(),c=p.panels.findIndex(v=>v.id===t),d=c===p.panels.length-1,y=Y({delta:d?s-r:r-s,initialLayout:m,panelConstraints:f,pivotIndices:d?[c-1,c]:[c,c+1],prevLayout:m,trigger:"imperative-api"}),g=N({layout:y,panelConstraints:f});W(m,g)||k(v=>({mountedGroups:new Map(v.mountedGroups).set(p,{defaultLayoutDeferred:u,derivedPanelConstraints:f,layout:g,separatorToPanels:h})}))};return{collapse:()=>{const{collapsible:r,collapsedSize:s}=o(),{mutableValues:u}=i(),f=a();r&&f!==s&&(u.expandToSize=f,l(s))},expand:()=>{const{collapsible:r,collapsedSize:s,minSize:u}=o(),{mutableValues:f}=i(),p=a();if(r&&p===s){let m=f.expandToSize??u;m===0&&(m=1),l(m)}},getSize:()=>{const{group:r}=n(),s=a(),{element:u}=i(),f=r.orientation==="horizontal"?u.offsetWidth:u.offsetHeight;return{asPercentage:s,inPixels:f}},isCollapsed:()=>{const{collapsible:r,collapsedSize:s}=o(),u=a();return r&&C(s,u)},resize:r=>{if(a()!==r){let u;switch(typeof r){case"number":{const{group:f}=n(),p=V({group:f});u=G(r/p*100);break}case"string":{u=parseFloat(r);break}}l(u)}}}}function Rt(e,t){const{id:n}=le(),o=x.useRef({collapse:te,expand:te,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:te});x.useImperativeHandle(t,()=>o.current,[]),_(()=>{Object.assign(o.current,Lt({groupId:n,panelId:e}))})}function $e({children:e,className:t,collapsedSize:n="0%",collapsible:o=!1,defaultSize:i,elementRef:a,id:l,maxSize:r="100%",minSize:s="0%",onResize:u,panelRef:f,style:p,...m}){const h=!!l,c=ie(l),d=x.useRef(null),y=ae(d,a),{id:g,registerPanel:v}=le(),b=u!==null,S=se((L,M,B)=>{u?.(L,l,B)});_(()=>{const L=d.current;if(L!==null)return v({element:L,id:c,idIsStable:h,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:b?S:void 0,panelConstraints:{collapsedSize:n,collapsible:o,defaultSize:i,maxSize:r,minSize:s}})},[n,o,i,b,c,h,r,s,S,v]),Rt(c,f);const w=Ne(g,c);return q.jsx("div",{...m,"data-panel":!0,"data-testid":c,id:c,ref:y,style:{...Pt,flexBasis:0,flexGrow:`var(${w}, 1)`,flexShrink:1,overflow:"hidden",pointerEvents:`var(${Te})`},children:q.jsx("div",{className:t,style:{width:"100%",height:"100%",...p},children:e})})}$e.displayName="Panel";const Pt={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function Ct(){return x.useState(null)}function Mt(){return x.useRef(null)}function Et({layout:e,panelConstraints:t,panelId:n,panelIndex:o}){let i,a;const l=e[n],r=t.find(s=>s.panelId===n);if(r){const s=r.maxSize,u=a=r.collapsible?r.collapsedSize:r.minSize,f=[o,o+1];a=N({layout:Y({delta:u-l,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e,trigger:"keyboard"}),panelConstraints:t})[n],i=N({layout:Y({delta:s-l,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e,trigger:"keyboard"}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:a,valueNow:l}}function je({children:e,className:t,elementRef:n,id:o,style:i,...a}){const l=ie(o),[r,s]=x.useState({}),[u,f]=x.useState("inactive"),p=x.useRef(null),m=ae(p,n),{id:h,orientation:c,registerSeparator:d}=le(),y=c==="horizontal"?"vertical":"horizontal";return _(()=>{const g=p.current;if(g!==null){const v={element:g,id:l},b=d(v),S=T.addListener("interactionStateChange",L=>{f(L.state!=="inactive"&&L.hitRegions.some(M=>M.separator===v)?L.state:"inactive")}),w=T.addListener("mountedGroupsChange",L=>{L.forEach(({derivedPanelConstraints:M,layout:B,separatorToPanels:U},A)=>{if(A.id===h){const K=U.get(v);if(K){const R=K[0],P=A.panels.indexOf(R);s(Et({layout:B,panelConstraints:M,panelId:R.id,panelIndex:P}))}}})});return()=>{S(),w(),b()}}},[h,l,d]),q.jsx("div",{...a,"aria-controls":r.valueControls,"aria-orientation":y,"aria-valuemax":r.valueMax,"aria-valuemin":r.valueMin,"aria-valuenow":r.valueNow,children:e,className:t,"data-separator":u,"data-testid":l,id:l,ref:m,role:"separator",style:{flexBasis:"auto",...i,flexGrow:0,flexShrink:0},tabIndex:0})}je.displayName="Separator";exports.Group=Ae;exports.Panel=$e;exports.Separator=je;exports.useDefaultLayout=xt;exports.useGroupCallbackRef=zt;exports.useGroupRef=wt;exports.usePanelCallbackRef=Ct;exports.usePanelRef=Mt;
|
|
2
|
+
//# sourceMappingURL=react-resizable-panels.cjs.map
|