react-resizable-panels 0.0.22 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +12 -10
- package/dist/react-resizable-panels.d.ts +32 -7
- package/dist/react-resizable-panels.d.ts.map +1 -1
- package/dist/react-resizable-panels.js +95 -54
- package/dist/react-resizable-panels.js.map +1 -1
- package/dist/react-resizable-panels.module.js +94 -53
- package/dist/react-resizable-panels.module.js.map +1 -1
- package/package.json +1 -1
- package/src/{Panel.tsx → Panel.ts} +58 -40
- package/src/{PanelGroup.tsx → PanelGroup.ts} +40 -22
- package/src/{PanelResizeHandle.tsx → PanelResizeHandle.ts} +44 -44
- package/src/hooks/useWindowSplitterBehavior.ts +19 -7
- package/src/types.ts +6 -0
- package/src/utils/coordinates.ts +2 -10
- package/src/utils/group.ts +31 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.23
|
|
4
|
+
* [#40](https://github.com/bvaughn/react-resizable-panels/issues/40): Add optional `maxSize` prop to `Panel`.
|
|
5
|
+
* [#41](https://github.com/bvaughn/react-resizable-panels/issues/41): Add optional `onResize` prop to `Panel`. This prop can be used (along with `defaultSize`) to persistence layouts somewhere externally.
|
|
6
|
+
* [#42](https://github.com/bvaughn/react-resizable-panels/issues/42): Don't cancel resize operations when exiting the window. Only cancel when a `"mouseup"` (or `"touchend"`) event is fired.
|
|
7
|
+
|
|
3
8
|
## 0.0.22
|
|
4
9
|
* Replaced the `"ew-resize"` and `"ns-resize"` cursor style with `"col-resize"` and `"row-resize"`.
|
|
5
10
|
|
package/README.md
CHANGED
|
@@ -33,16 +33,18 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
|
|
|
33
33
|
| `tagName` | `?string = "div"` | Optional HTML element tag name for root element
|
|
34
34
|
|
|
35
35
|
### `Panel`
|
|
36
|
-
| prop | type
|
|
37
|
-
| :------------ |
|
|
38
|
-
| `children` | `ReactNode`
|
|
39
|
-
| `className` | `?string`
|
|
40
|
-
| `defaultSize` | `?number`
|
|
41
|
-
| `id` | `?string`
|
|
42
|
-
| `
|
|
43
|
-
| `
|
|
44
|
-
| `
|
|
45
|
-
| `
|
|
36
|
+
| prop | type | description
|
|
37
|
+
| :------------ | :------------------------ | :---
|
|
38
|
+
| `children` | `ReactNode` | Arbitrary React element(s)
|
|
39
|
+
| `className` | `?string` | Optional class name to attach to root element
|
|
40
|
+
| `defaultSize` | `?number` | Initial size of panel (numeric value between 1-100)
|
|
41
|
+
| `id` | `?string` | Optional panel id (unique within group); falls back to `useId` when not provided
|
|
42
|
+
| `maxSize` | `?number` | Maximum allowable size of panel (numeric value between 1-100)
|
|
43
|
+
| `minSize` | `?number` | Minimum allowable size of panel (numeric value between 1-100)
|
|
44
|
+
| `onResize` | `?(size: number) => void` | Optional function to be called when panel is resized; `size` parameter is a numeric value between 1-100
|
|
45
|
+
| `order` | `?number` | Order of panel within group; required for groups with conditionally rendered panels
|
|
46
|
+
| `style` | `?CSSProperties` | Optional CSS style to attach to root element
|
|
47
|
+
| `tagName` | `?string = "div"` | Optional HTML element tag name for root element
|
|
46
48
|
|
|
47
49
|
### `PanelResizeHandle`
|
|
48
50
|
| prop | type | description
|
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
import { CSSProperties, ElementType, ReactNode } from "react";
|
|
1
|
+
import { RefObject, CSSProperties, ElementType, ReactNode } from "react";
|
|
2
2
|
type Direction = "horizontal" | "vertical";
|
|
3
|
-
|
|
3
|
+
type PanelOnResize = (size: number) => void;
|
|
4
|
+
type PanelData = {
|
|
5
|
+
defaultSize: number;
|
|
6
|
+
id: string;
|
|
7
|
+
maxSize: number;
|
|
8
|
+
minSize: number;
|
|
9
|
+
onResizeRef: RefObject<PanelOnResize | null>;
|
|
10
|
+
order: number | null;
|
|
11
|
+
};
|
|
12
|
+
type ResizeEvent = KeyboardEvent | MouseEvent | TouchEvent;
|
|
13
|
+
type PanelProps = {
|
|
4
14
|
children?: ReactNode;
|
|
5
15
|
className?: string;
|
|
6
16
|
defaultSize?: number | null;
|
|
7
17
|
id?: string | null;
|
|
18
|
+
maxSize?: number;
|
|
8
19
|
minSize?: number;
|
|
20
|
+
onResize?: PanelOnResize | null;
|
|
9
21
|
order?: number | null;
|
|
10
22
|
style?: CSSProperties;
|
|
11
23
|
tagName?: ElementType;
|
|
12
|
-
}
|
|
13
|
-
export function
|
|
24
|
+
};
|
|
25
|
+
export function Panel({ children, className: classNameFromProps, defaultSize, id: idFromProps, maxSize, minSize, onResize, order, style: styleFromProps, tagName: Type, }: PanelProps): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
26
|
+
type PanelGroupProps = {
|
|
14
27
|
autoSaveId?: string;
|
|
15
28
|
children?: ReactNode;
|
|
16
29
|
className?: string;
|
|
@@ -18,14 +31,26 @@ export function PanelGroup({ autoSaveId, children, className: classNameFromProps
|
|
|
18
31
|
id?: string | null;
|
|
19
32
|
style?: CSSProperties;
|
|
20
33
|
tagName?: ElementType;
|
|
21
|
-
}
|
|
22
|
-
export function
|
|
34
|
+
};
|
|
35
|
+
export function PanelGroup({ autoSaveId, children, className: classNameFromProps, direction, id: idFromProps, style: styleFromProps, tagName: Type, }: PanelGroupProps): import("react").FunctionComponentElement<import("react").ProviderProps<{
|
|
36
|
+
activeHandleId: string;
|
|
37
|
+
direction: "horizontal" | "vertical";
|
|
38
|
+
getPanelStyle: (id: string) => CSSProperties;
|
|
39
|
+
groupId: string;
|
|
40
|
+
registerPanel: (id: string, panel: PanelData) => void;
|
|
41
|
+
registerResizeHandle: (id: string) => import("types").ResizeHandler;
|
|
42
|
+
startDragging: (id: string, event: ResizeEvent) => void;
|
|
43
|
+
stopDragging: () => void;
|
|
44
|
+
unregisterPanel: (id: string) => void;
|
|
45
|
+
}>>;
|
|
46
|
+
type PanelResizeHandleProps = {
|
|
23
47
|
children?: ReactNode;
|
|
24
48
|
className?: string;
|
|
25
49
|
disabled?: boolean;
|
|
26
50
|
id?: string | null;
|
|
27
51
|
style?: CSSProperties;
|
|
28
52
|
tagName?: ElementType;
|
|
29
|
-
}
|
|
53
|
+
};
|
|
54
|
+
export function PanelResizeHandle({ children, className: classNameFromProps, disabled, id: idFromProps, style: styleFromProps, tagName: Type, }: PanelResizeHandleProps): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
30
55
|
|
|
31
56
|
//# sourceMappingURL=react-resizable-panels.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";
|
|
1
|
+
{"mappings":";ACEA,iBAAwB,YAAY,GAAG,UAAU,CAAC;AAElD,qBAA4B,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAEnD,iBAAwB;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,UAAU,aAAa,GAAG,IAAI,CAAC,CAAC;IAC7C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,mBAA0B,aAAa,GAAG,UAAU,GAAG,UAAU,CAAC;AEDlE,kBAAyB;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB,CAAC;AAEF,sBAA8B,EAC5B,QAAe,EACf,SAAS,EAAE,kBAAuB,EAClC,WAAkB,EAClB,EAAE,EAAE,WAAkB,EACtB,OAAa,EACb,OAAY,EACZ,QAAe,EACf,KAAY,EACZ,KAAK,EAAE,cAAmB,EAC1B,OAAO,EAAE,IAAY,GACtB,EAAE,UAAU,0FAwEZ;AMvED,uBAA8B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB,CAAC;AAEF,2BAAmC,EACjC,UAAU,EACV,QAAe,EACf,SAAS,EAAE,kBAAuB,EAClC,SAAS,EACT,EAAE,EAAE,WAAkB,EACtB,KAAK,EAAE,cAAmB,EAC1B,OAAO,EAAE,IAAY,GACtB,EAAE,eAAe;;;;;;;;;;IA0QjB;AChTD,8BAAqC;IACnC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB,CAAC;AAEF,kCAA0C,EACxC,QAAe,EACf,SAAS,EAAE,kBAAuB,EAClC,QAAgB,EAChB,EAAE,EAAE,WAAkB,EACtB,KAAK,EAAE,cAAmB,EAC1B,OAAO,EAAE,IAAY,GACtB,EAAE,sBAAsB,0FAoHxB","sources":["packages/react-resizable-panels/src/src/hooks/useUniqueId.ts","packages/react-resizable-panels/src/src/types.ts","packages/react-resizable-panels/src/src/PanelContexts.ts","packages/react-resizable-panels/src/src/Panel.ts","packages/react-resizable-panels/src/src/utils/serialization.ts","packages/react-resizable-panels/src/src/constants.ts","packages/react-resizable-panels/src/src/utils/group.ts","packages/react-resizable-panels/src/src/utils/coordinates.ts","packages/react-resizable-panels/src/src/hooks/useWindowSplitterBehavior.ts","packages/react-resizable-panels/src/src/PanelGroup.ts","packages/react-resizable-panels/src/src/PanelResizeHandle.ts","packages/react-resizable-panels/src/src/index.ts","packages/react-resizable-panels/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,"import Panel from \"./Panel\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelGroup, PanelResizeHandle };\n"],"names":[],"version":3,"file":"react-resizable-panels.d.ts.map"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
var $b2QPe$reactjsxruntime = require("react/jsx-runtime");
|
|
2
1
|
var $b2QPe$react = require("react");
|
|
3
2
|
|
|
4
3
|
function $parcel$export(e, n, v, s) {
|
|
5
4
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
5
|
}
|
|
7
6
|
|
|
8
|
-
$parcel$export(module.exports, "Panel", () => $
|
|
9
|
-
$parcel$export(module.exports, "PanelGroup", () => $
|
|
10
|
-
$parcel$export(module.exports, "PanelResizeHandle", () => $
|
|
11
|
-
|
|
7
|
+
$parcel$export(module.exports, "Panel", () => $4b51bd7b90b9da8b$export$2e2bcd8739ae039);
|
|
8
|
+
$parcel$export(module.exports, "PanelGroup", () => $19bf0050f73d236b$export$2e2bcd8739ae039);
|
|
9
|
+
$parcel$export(module.exports, "PanelResizeHandle", () => $01377e07790cf46f$export$2e2bcd8739ae039);
|
|
12
10
|
|
|
13
11
|
|
|
14
12
|
let $6d548a0d130941e3$var$counter = 0;
|
|
@@ -28,24 +26,29 @@ const $3251d17c1c3bce6c$export$7d8c6d083caec74a = (0, $b2QPe$react.createContext
|
|
|
28
26
|
$3251d17c1c3bce6c$export$7d8c6d083caec74a.displayName = "PanelGroupContext";
|
|
29
27
|
|
|
30
28
|
|
|
31
|
-
function $
|
|
29
|
+
function $4b51bd7b90b9da8b$export$2e2bcd8739ae039({ children: children = null , className: classNameFromProps = "" , defaultSize: defaultSize = null , id: idFromProps = null , maxSize: maxSize = 100 , minSize: minSize = 10 , onResize: onResize = null , order: order = null , style: styleFromProps = {} , tagName: Type = "div" }) {
|
|
32
30
|
const context = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a));
|
|
33
31
|
if (context === null) throw Error(`Panel components must be rendered within a PanelGroup container`);
|
|
34
|
-
const
|
|
32
|
+
const onResizeRef = (0, $b2QPe$react.useRef)(onResize);
|
|
33
|
+
// Basic props validation
|
|
35
34
|
if (minSize < 0 || minSize > 100) throw Error(`Panel minSize must be between 0 and 100, but was ${minSize}`);
|
|
36
|
-
if (
|
|
35
|
+
else if (maxSize < 0 || maxSize > 100) throw Error(`Panel maxSize must be between 0 and 100, but was ${maxSize}`);
|
|
36
|
+
else if (defaultSize !== null) {
|
|
37
37
|
if (defaultSize < 0 || defaultSize > 100) throw Error(`Panel defaultSize must be between 0 and 100, but was ${defaultSize}`);
|
|
38
38
|
else if (minSize > defaultSize) {
|
|
39
39
|
console.error(`Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`);
|
|
40
40
|
defaultSize = minSize;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
const panelId = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)(idFromProps);
|
|
43
44
|
const { getPanelStyle: getPanelStyle , registerPanel: registerPanel , unregisterPanel: unregisterPanel } = context;
|
|
44
45
|
(0, $b2QPe$react.useLayoutEffect)(()=>{
|
|
45
46
|
const panel = {
|
|
46
47
|
defaultSize: defaultSize,
|
|
47
48
|
id: panelId,
|
|
49
|
+
maxSize: maxSize,
|
|
48
50
|
minSize: minSize,
|
|
51
|
+
onResizeRef: onResizeRef,
|
|
49
52
|
order: order
|
|
50
53
|
};
|
|
51
54
|
registerPanel(panelId, panel);
|
|
@@ -55,28 +58,28 @@ function $6d390b7f2e6b107f$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
55
58
|
}, [
|
|
56
59
|
defaultSize,
|
|
57
60
|
panelId,
|
|
61
|
+
maxSize,
|
|
58
62
|
minSize,
|
|
59
63
|
order,
|
|
60
64
|
registerPanel,
|
|
61
65
|
unregisterPanel
|
|
62
66
|
]);
|
|
63
67
|
const style = getPanelStyle(panelId);
|
|
64
|
-
return
|
|
68
|
+
return (0, $b2QPe$react.createElement)(Type, {
|
|
69
|
+
children: children,
|
|
65
70
|
className: classNameFromProps,
|
|
66
71
|
"data-panel-id": panelId,
|
|
67
72
|
id: `data-panel-id-${panelId}`,
|
|
68
73
|
style: {
|
|
69
74
|
...style,
|
|
70
75
|
...styleFromProps
|
|
71
|
-
}
|
|
72
|
-
children: children
|
|
76
|
+
}
|
|
73
77
|
});
|
|
74
78
|
}
|
|
75
79
|
// Workaround for Parcel scope hoisting (which renames objects/functions).
|
|
76
80
|
// Casting to :any is required to avoid corrupting the generated TypeScript types.
|
|
77
81
|
// See github.com/parcel-bundler/parcel/issues/8724
|
|
78
|
-
$
|
|
79
|
-
|
|
82
|
+
$4b51bd7b90b9da8b$export$2e2bcd8739ae039.displayName = "Panel";
|
|
80
83
|
|
|
81
84
|
|
|
82
85
|
|
|
@@ -136,30 +139,40 @@ function $d520236daad9c5d5$export$f50bae335f53943c(panels, idBefore, idAfter, de
|
|
|
136
139
|
//
|
|
137
140
|
// A positive delta means the panel immediately before the resizer should "expand".
|
|
138
141
|
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
// Max-bounds check the panel being expanded first.
|
|
143
|
+
{
|
|
144
|
+
const pivotId = delta < 0 ? idAfter : idBefore;
|
|
145
|
+
const index = panelsArray.findIndex((panel)=>panel.id === pivotId);
|
|
142
146
|
const panel = panelsArray[index];
|
|
143
147
|
const prevSize = prevSizes[index];
|
|
144
|
-
const nextSize =
|
|
145
|
-
if (prevSize
|
|
146
|
-
|
|
147
|
-
|
|
148
|
+
const nextSize = $d520236daad9c5d5$var$safeResizePanel(panel, Math.abs(delta), prevSize);
|
|
149
|
+
if (prevSize === nextSize) return prevSizes;
|
|
150
|
+
else delta = delta < 0 ? prevSize - nextSize : nextSize - prevSize;
|
|
151
|
+
}
|
|
152
|
+
let pivotId1 = delta < 0 ? idBefore : idAfter;
|
|
153
|
+
let index1 = panelsArray.findIndex((panel)=>panel.id === pivotId1);
|
|
154
|
+
while(true){
|
|
155
|
+
const panel1 = panelsArray[index1];
|
|
156
|
+
const prevSize1 = prevSizes[index1];
|
|
157
|
+
const nextSize1 = $d520236daad9c5d5$var$safeResizePanel(panel1, 0 - Math.abs(delta), prevSize1);
|
|
158
|
+
if (prevSize1 !== nextSize1) {
|
|
159
|
+
deltaApplied += prevSize1 - nextSize1;
|
|
160
|
+
nextSizes[index1] = nextSize1;
|
|
148
161
|
if (deltaApplied.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879)) >= delta.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879))) break;
|
|
149
162
|
}
|
|
150
163
|
if (delta < 0) {
|
|
151
|
-
if (--
|
|
164
|
+
if (--index1 < 0) break;
|
|
152
165
|
} else {
|
|
153
|
-
if (++
|
|
166
|
+
if (++index1 >= panelsArray.length) break;
|
|
154
167
|
}
|
|
155
168
|
}
|
|
156
169
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
157
170
|
// This will essentially bailout and ignore the "mousemove" event.
|
|
158
171
|
if (deltaApplied === 0) return prevSizes;
|
|
159
172
|
// Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
nextSizes[
|
|
173
|
+
pivotId1 = delta < 0 ? idAfter : idBefore;
|
|
174
|
+
index1 = panelsArray.findIndex((panel)=>panel.id === pivotId1);
|
|
175
|
+
nextSizes[index1] = prevSizes[index1] + deltaApplied;
|
|
163
176
|
return nextSizes;
|
|
164
177
|
}
|
|
165
178
|
function $d520236daad9c5d5$export$6f43503e166de6fb(panels, id, sizes) {
|
|
@@ -210,6 +223,11 @@ function $d520236daad9c5d5$export$68d3a33c21dfbe27(groupId, handleId, panelsArra
|
|
|
210
223
|
function $d520236daad9c5d5$export$a861c0ad45885494(panels) {
|
|
211
224
|
return Array.from(panels.values()).sort((a, b)=>a.order - b.order);
|
|
212
225
|
}
|
|
226
|
+
function $d520236daad9c5d5$var$safeResizePanel(panel, delta, prevSize) {
|
|
227
|
+
const nextSizeUnsafe = prevSize + delta;
|
|
228
|
+
const nextSize = Math.min(panel.maxSize, Math.max(panel.minSize, nextSizeUnsafe));
|
|
229
|
+
return nextSize;
|
|
230
|
+
}
|
|
213
231
|
|
|
214
232
|
|
|
215
233
|
function $f5af57c8e042a4ad$export$ec391ce65b083ed4(event, handleId, direction, initialOffset = 0) {
|
|
@@ -243,11 +261,9 @@ function $f5af57c8e042a4ad$export$354b17c0684607ed(event, groupId, handleId, dir
|
|
|
243
261
|
case "ArrowUp":
|
|
244
262
|
return isHorizontal ? 0 : -delta;
|
|
245
263
|
case "End":
|
|
246
|
-
|
|
247
|
-
else return size;
|
|
264
|
+
return size;
|
|
248
265
|
case "Home":
|
|
249
|
-
|
|
250
|
-
else return -size;
|
|
266
|
+
return -size;
|
|
251
267
|
}
|
|
252
268
|
} else return $f5af57c8e042a4ad$export$ec391ce65b083ed4(event, handleId, direction, initialOffset);
|
|
253
269
|
}
|
|
@@ -277,11 +293,22 @@ function $63be9a96d8675f03$export$d9fcbe062527d159({ committedValuesRef: committ
|
|
|
277
293
|
const panelsArray = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels);
|
|
278
294
|
const [idBefore, idAfter] = (0, $d520236daad9c5d5$export$68d3a33c21dfbe27)(groupId, handleId, panelsArray);
|
|
279
295
|
if (idBefore == null || idAfter == null) return ()=>{};
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
296
|
+
let minSize = 0;
|
|
297
|
+
let maxSize = 100;
|
|
298
|
+
let totalMinSize = 0;
|
|
299
|
+
let totalMaxSize = 0;
|
|
300
|
+
// A panel's effective min/max sizes also need to account for other panel's sizes.
|
|
301
|
+
panelsArray.forEach((panelData)=>{
|
|
302
|
+
if (panelData.id === idBefore) {
|
|
303
|
+
maxSize = panelData.maxSize;
|
|
304
|
+
minSize = panelData.minSize;
|
|
305
|
+
} else {
|
|
306
|
+
totalMinSize += panelData.minSize;
|
|
307
|
+
totalMaxSize += panelData.maxSize;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
const ariaValueMax = Math.min(maxSize, 100 - totalMinSize);
|
|
311
|
+
const ariaValueMin = Math.max(minSize, (panelsArray.length - 1) * 100 - totalMaxSize);
|
|
285
312
|
const flexGrow = (0, $d520236daad9c5d5$export$6f43503e166de6fb)(panels, idBefore, sizes);
|
|
286
313
|
handle.setAttribute("aria-valuemax", "" + Math.round(ariaValueMax));
|
|
287
314
|
handle.setAttribute("aria-valuemin", "" + Math.round(ariaValueMin));
|
|
@@ -365,7 +392,7 @@ function $63be9a96d8675f03$export$33b0bea6ac3ffb03({ disabled: disabled , handle
|
|
|
365
392
|
|
|
366
393
|
|
|
367
394
|
|
|
368
|
-
function $
|
|
395
|
+
function $19bf0050f73d236b$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: classNameFromProps = "" , direction: direction , id: idFromProps = null , style: styleFromProps = {} , tagName: Type = "div" }) {
|
|
369
396
|
const groupId = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)(idFromProps);
|
|
370
397
|
const [activeHandleId, setActiveHandleId] = (0, $b2QPe$react.useState)(null);
|
|
371
398
|
const [panels, setPanels] = (0, $b2QPe$react.useState)(new Map());
|
|
@@ -395,7 +422,8 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
395
422
|
// This assumes that panels register during initial mount (no conditional rendering)!
|
|
396
423
|
(0, $b2QPe$react.useLayoutEffect)(()=>{
|
|
397
424
|
const sizes = committedValuesRef.current.sizes;
|
|
398
|
-
if (sizes.length === panels.size)
|
|
425
|
+
if (sizes.length === panels.size) // Only compute (or restore) default sizes once per panel configuration.
|
|
426
|
+
return;
|
|
399
427
|
// If this panel has been configured to persist sizing information,
|
|
400
428
|
// default size should be restored from local storage if possible.
|
|
401
429
|
let defaultSizes = undefined;
|
|
@@ -409,6 +437,10 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
409
437
|
let panelsWithNullDefaultSize = 0;
|
|
410
438
|
let totalDefaultSize = 0;
|
|
411
439
|
let totalMinSize = 0;
|
|
440
|
+
// TODO
|
|
441
|
+
// Implicit default size calculations below do not account for inferred min/max size values.
|
|
442
|
+
// e.g. if Panel A has a maxSize of 40 then Panels A and B can't both have an implicit default size of 50.
|
|
443
|
+
// For now, these logic edge cases are left to the user to handle via props.
|
|
412
444
|
panelsArray1.forEach((panel)=>{
|
|
413
445
|
totalMinSize += panel.minSize;
|
|
414
446
|
if (panel.defaultSize === null) panelsWithNullDefaultSize++;
|
|
@@ -474,7 +506,17 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
474
506
|
const size = isHorizontal ? rect.width : rect.height;
|
|
475
507
|
const delta = movement / size * 100;
|
|
476
508
|
const nextSizes = (0, $d520236daad9c5d5$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, prevSizes);
|
|
477
|
-
if (prevSizes !== nextSizes)
|
|
509
|
+
if (prevSizes !== nextSizes) {
|
|
510
|
+
// If resize change handlers have been declared, this is the time to call them.
|
|
511
|
+
nextSizes.forEach((nextSize, index)=>{
|
|
512
|
+
const prevSize = prevSizes[index];
|
|
513
|
+
if (prevSize !== nextSize) {
|
|
514
|
+
const onResize = panelsArray[index].onResizeRef.current;
|
|
515
|
+
if (onResize) onResize(nextSize);
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
setSizes(nextSizes);
|
|
519
|
+
}
|
|
478
520
|
};
|
|
479
521
|
return resizeHandler;
|
|
480
522
|
}, [
|
|
@@ -519,32 +561,31 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
519
561
|
overflow: "hidden",
|
|
520
562
|
width: "100%"
|
|
521
563
|
};
|
|
522
|
-
return
|
|
523
|
-
|
|
524
|
-
|
|
564
|
+
return (0, $b2QPe$react.createElement)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a).Provider, {
|
|
565
|
+
children: (0, $b2QPe$react.createElement)(Type, {
|
|
566
|
+
children: children,
|
|
525
567
|
className: classNameFromProps,
|
|
526
568
|
"data-panel-group-direction": direction,
|
|
527
569
|
"data-panel-group-id": groupId,
|
|
528
570
|
style: {
|
|
529
571
|
...style,
|
|
530
572
|
...styleFromProps
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
|
|
573
|
+
}
|
|
574
|
+
}),
|
|
575
|
+
value: context
|
|
534
576
|
});
|
|
535
577
|
}
|
|
536
578
|
// Workaround for Parcel scope hoisting (which renames objects/functions).
|
|
537
579
|
// Casting to :any is required to avoid corrupting the generated TypeScript types.
|
|
538
580
|
// See github.com/parcel-bundler/parcel/issues/8724
|
|
539
|
-
$
|
|
540
|
-
|
|
581
|
+
$19bf0050f73d236b$export$2e2bcd8739ae039.displayName = "PanelGroup";
|
|
541
582
|
|
|
542
583
|
|
|
543
584
|
|
|
544
585
|
|
|
545
586
|
|
|
546
587
|
|
|
547
|
-
function $
|
|
588
|
+
function $01377e07790cf46f$export$2e2bcd8739ae039({ children: children = null , className: classNameFromProps = "" , disabled: disabled = false , id: idFromProps = null , style: styleFromProps = {} , tagName: Type = "div" }) {
|
|
548
589
|
const divElementRef = (0, $b2QPe$react.useRef)(null);
|
|
549
590
|
const panelGroupContext = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a));
|
|
550
591
|
if (panelGroupContext === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
|
|
@@ -580,17 +621,17 @@ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
580
621
|
resizeHandler(event);
|
|
581
622
|
};
|
|
582
623
|
document.body.addEventListener("contextmenu", stopDraggingAndBlur);
|
|
583
|
-
document.body.addEventListener("mouseleave", stopDraggingAndBlur);
|
|
584
624
|
document.body.addEventListener("mousemove", onMove);
|
|
585
625
|
document.body.addEventListener("touchmove", onMove);
|
|
586
|
-
|
|
626
|
+
window.addEventListener("mouseup", stopDraggingAndBlur);
|
|
627
|
+
window.addEventListener("touchend", stopDraggingAndBlur);
|
|
587
628
|
return ()=>{
|
|
588
629
|
document.body.style.cursor = "";
|
|
589
630
|
document.body.removeEventListener("contextmenu", stopDraggingAndBlur);
|
|
590
|
-
document.body.removeEventListener("mouseleave", stopDraggingAndBlur);
|
|
591
631
|
document.body.removeEventListener("mousemove", onMove);
|
|
592
632
|
document.body.removeEventListener("touchmove", onMove);
|
|
593
|
-
|
|
633
|
+
window.removeEventListener("mouseup", stopDraggingAndBlur);
|
|
634
|
+
window.removeEventListener("touchend", stopDraggingAndBlur);
|
|
594
635
|
};
|
|
595
636
|
}, [
|
|
596
637
|
direction,
|
|
@@ -609,7 +650,8 @@ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
609
650
|
touchAction: "none",
|
|
610
651
|
userSelect: "none"
|
|
611
652
|
};
|
|
612
|
-
return
|
|
653
|
+
return (0, $b2QPe$react.createElement)(Type, {
|
|
654
|
+
children: children,
|
|
613
655
|
className: classNameFromProps,
|
|
614
656
|
"data-resize-handle-active": isDragging ? "pointer" : isFocused ? "keyboard" : undefined,
|
|
615
657
|
"data-panel-group-direction": direction,
|
|
@@ -629,14 +671,13 @@ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
629
671
|
...style,
|
|
630
672
|
...styleFromProps
|
|
631
673
|
},
|
|
632
|
-
tabIndex: 0
|
|
633
|
-
children: children
|
|
674
|
+
tabIndex: 0
|
|
634
675
|
});
|
|
635
676
|
}
|
|
636
677
|
// Workaround for Parcel scope hoisting (which renames objects/functions).
|
|
637
678
|
// Casting to :any is required to avoid corrupting the generated TypeScript types.
|
|
638
679
|
// See github.com/parcel-bundler/parcel/issues/8724
|
|
639
|
-
$
|
|
680
|
+
$01377e07790cf46f$export$2e2bcd8739ae039.displayName = "PanelResizeHandle";
|
|
640
681
|
|
|
641
682
|
|
|
642
683
|
|