react-resizable-panels 0.0.8 → 0.0.9
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 +4 -1
- package/dist/react-resizable-panels.d.ts.map +1 -1
- package/dist/react-resizable-panels.js +290 -86
- package/dist/react-resizable-panels.js.map +1 -1
- package/dist/react-resizable-panels.module.js +290 -86
- package/dist/react-resizable-panels.module.js.map +1 -1
- package/package.json +1 -1
- package/src/Panel.tsx +6 -1
- package/src/PanelGroup.tsx +39 -141
- package/src/PanelResizeHandle.tsx +11 -1
- package/src/constants.ts +1 -0
- package/src/hooks/useWindowSplitterBehavior.ts +185 -0
- package/src/types.ts +1 -1
- package/src/utils/coordinates.ts +118 -0
- package/src/utils/group.ts +176 -0
- package/src/utils/touch.ts +0 -44
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.9
|
|
4
|
+
* [#13](https://github.com/bvaughn/react-resizable-panels/issues/13): `PanelResizeHandle` should declare "separator" role and implement the recommended ["Window Splitter" pattern](https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/)
|
|
5
|
+
|
|
3
6
|
## 0.0.8
|
|
4
7
|
* [#7](https://github.com/bvaughn/react-resizable-panels/issues/7): Support "touch" events for mobile compatibility.
|
|
5
8
|
|
|
@@ -8,7 +11,7 @@
|
|
|
8
11
|
## 0.0.6
|
|
9
12
|
* [#5](https://github.com/bvaughn/react-resizable-panels/issues/5): Removed `panelBefore` and `panelAfter` props from `PanelResizeHandle`. `PanelGroup` now infers this based on position within the group.
|
|
10
13
|
## 0.0.5
|
|
11
|
-
* TypeScript props type fix
|
|
14
|
+
* TypeScript props type fix for `PanelGroup`'s `children` prop.
|
|
12
15
|
|
|
13
16
|
## 0.0.4
|
|
14
17
|
* [#8](https://github.com/bvaughn/react-resizable-panels/issues/8): Added optional `order` prop to `Panel` to improve conditional rendering.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AAAA,iBAAwB,YAAY,GAAG,UAAU,CAAC;ACIlD,OAAO,MAAM;oBACK,MAAM,GAAG,IAAI;EAChB,CAAC;ACChB,sBAA8B,EAC5B,QAAe,EACf,SAAc,EACd,WAAiB,EACjB,EAAE,EACF,OAAa,EACb,KAAY,GACb,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,
|
|
1
|
+
{"mappings":";AAAA,iBAAwB,YAAY,GAAG,UAAU,CAAC;ACIlD,OAAO,MAAM;oBACK,MAAM,GAAG,IAAI;EAChB,CAAC;ACChB,sBAA8B,EAC5B,QAAe,EACf,SAAc,EACd,WAAiB,EACjB,EAAE,EACF,OAAa,EACb,KAAY,GACb,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,eA6CA;AO/BD,aAAa;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAMF,2BAAmC,EACjC,UAAU,EACV,QAAe,EACf,SAAc,EACd,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE,KAAK,eA8OP;AC9RD,kCAA0C,EACxC,QAAe,EACf,SAAc,EACd,QAAgB,EAChB,EAAE,EAAE,MAAa,GAClB,EAAE;IACD,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;CACpB,eAyFA","sources":["packages/react-resizable-panels/src/src/types.ts","packages/react-resizable-panels/src/src/PanelContexts.ts","packages/react-resizable-panels/src/src/Panel.tsx","packages/react-resizable-panels/src/src/hooks/useUniqueId.ts","packages/react-resizable-panels/src/src/utils/serialization.ts","packages/react-resizable-panels/src/src/utils/coordinates.ts","packages/react-resizable-panels/src/src/constants.ts","packages/react-resizable-panels/src/src/utils/group.ts","packages/react-resizable-panels/src/src/hooks/useWindowSplitterBehavior.ts","packages/react-resizable-panels/src/src/PanelGroup.tsx","packages/react-resizable-panels/src/src/PanelResizeHandle.tsx","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 { PanelContext } from \"./PanelContexts\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelContext, PanelGroup, PanelResizeHandle };\n"],"names":[],"version":3,"file":"react-resizable-panels.d.ts.map","sourceRoot":"../../../"}
|
|
@@ -46,6 +46,8 @@ function $6d390b7f2e6b107f$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
46
46
|
const style = getPanelStyle(id);
|
|
47
47
|
return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
|
|
48
48
|
className: className,
|
|
49
|
+
"data-panel-id": id,
|
|
50
|
+
id: `data-panel-id-${id}`,
|
|
49
51
|
style: style,
|
|
50
52
|
children: children
|
|
51
53
|
}, void 0, false, {
|
|
@@ -95,10 +97,56 @@ function $e045b0dd313f33c7$export$af183b313c61be4f(autoSaveId, panelIds, sizes)
|
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
const $f5af57c8e042a4ad$var$element = document.createElement("div");
|
|
101
|
+
$f5af57c8e042a4ad$var$element.getBoundingClientRect();
|
|
102
|
+
function $f5af57c8e042a4ad$export$70637efcd850e4ef(event, prevCoordinates, dimensions, direction) {
|
|
99
103
|
const { screenX: prevScreenX , screenY: prevScreenY } = prevCoordinates;
|
|
104
|
+
const { height: height , width: width } = dimensions;
|
|
100
105
|
const getMovementBetween = (current, prev)=>prev === 0 ? 0 : current - prev;
|
|
101
|
-
if ($
|
|
106
|
+
if ($f5af57c8e042a4ad$export$e7bf60a870f429b0(event)) {
|
|
107
|
+
let movementX = 0;
|
|
108
|
+
let movementY = 0;
|
|
109
|
+
const size = direction === "horizontal" ? width : height;
|
|
110
|
+
const denominator = event.shiftKey ? 10 : 100;
|
|
111
|
+
const delta = size / denominator;
|
|
112
|
+
switch(event.key){
|
|
113
|
+
case "ArrowDown":
|
|
114
|
+
movementY = delta;
|
|
115
|
+
break;
|
|
116
|
+
case "ArrowLeft":
|
|
117
|
+
movementX = -delta;
|
|
118
|
+
break;
|
|
119
|
+
case "ArrowRight":
|
|
120
|
+
movementX = delta;
|
|
121
|
+
break;
|
|
122
|
+
case "ArrowUp":
|
|
123
|
+
movementY = -delta;
|
|
124
|
+
break;
|
|
125
|
+
case "End":
|
|
126
|
+
if (direction === "horizontal") movementX = size;
|
|
127
|
+
else movementY = size;
|
|
128
|
+
break;
|
|
129
|
+
case "Home":
|
|
130
|
+
if (direction === "horizontal") movementX = -size;
|
|
131
|
+
else movementY = -size;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
// Estimate screen X/Y to be the center of the resize handle.
|
|
135
|
+
// Otherwise the first mouse/touch event after a keyboard event will appear to "jump"
|
|
136
|
+
let screenX = 0;
|
|
137
|
+
let screenY = 0;
|
|
138
|
+
if (document.activeElement) {
|
|
139
|
+
const rect = document.activeElement.getBoundingClientRect();
|
|
140
|
+
screenX = rect.left + rect.width / 2;
|
|
141
|
+
screenY = rect.top + rect.height / 2;
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
movementX: movementX,
|
|
145
|
+
movementY: movementY,
|
|
146
|
+
screenX: screenX,
|
|
147
|
+
screenY: screenY
|
|
148
|
+
};
|
|
149
|
+
} else if ($f5af57c8e042a4ad$export$ce897e7f0aa63661(event)) {
|
|
102
150
|
const firstTouch = event.touches[0];
|
|
103
151
|
return {
|
|
104
152
|
movementX: getMovementBetween(firstTouch.screenX, prevScreenX),
|
|
@@ -106,20 +154,223 @@ function $37410a9246dfda64$export$70637efcd850e4ef(event, prevCoordinates) {
|
|
|
106
154
|
screenX: firstTouch.screenX,
|
|
107
155
|
screenY: firstTouch.screenY
|
|
108
156
|
};
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
157
|
+
} else if ($f5af57c8e042a4ad$export$5107d838cdd17dee(event)) return {
|
|
111
158
|
movementX: getMovementBetween(event.screenX, prevScreenX),
|
|
112
159
|
movementY: getMovementBetween(event.screenY, prevScreenY),
|
|
113
160
|
screenX: event.screenX,
|
|
114
161
|
screenY: event.screenY
|
|
115
162
|
};
|
|
163
|
+
else throw Error(`Unsupported event type: "${event.type}"`);
|
|
116
164
|
}
|
|
117
|
-
function $
|
|
165
|
+
function $f5af57c8e042a4ad$export$e7bf60a870f429b0(event) {
|
|
166
|
+
return event.type === "keydown";
|
|
167
|
+
}
|
|
168
|
+
function $f5af57c8e042a4ad$export$5107d838cdd17dee(event) {
|
|
169
|
+
return event.type === "mousemove";
|
|
170
|
+
}
|
|
171
|
+
function $f5af57c8e042a4ad$export$ce897e7f0aa63661(event) {
|
|
118
172
|
return event.type === "touchmove";
|
|
119
173
|
}
|
|
120
174
|
|
|
121
175
|
|
|
122
|
-
const $
|
|
176
|
+
const $3237bc4a138172cd$export$d6d3992f3becc879 = 5;
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
function $d520236daad9c5d5$export$f50bae335f53943c(panels, idBefore, idAfter, delta, prevSizes) {
|
|
180
|
+
if (delta === 0) return prevSizes;
|
|
181
|
+
const panelsArray = $d520236daad9c5d5$export$a861c0ad45885494(panels);
|
|
182
|
+
const nextSizes = prevSizes.concat();
|
|
183
|
+
let deltaApplied = 0;
|
|
184
|
+
// A resizing panel affects the panels before or after it.
|
|
185
|
+
//
|
|
186
|
+
// A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.
|
|
187
|
+
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
188
|
+
//
|
|
189
|
+
// A positive delta means the panel immediately before the resizer should "expand".
|
|
190
|
+
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
|
|
191
|
+
let pivotId = delta < 0 ? idBefore : idAfter;
|
|
192
|
+
let index = panelsArray.findIndex((panel)=>panel.id === pivotId);
|
|
193
|
+
while(true){
|
|
194
|
+
const panel = panelsArray[index];
|
|
195
|
+
const prevSize = prevSizes[index];
|
|
196
|
+
const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);
|
|
197
|
+
if (prevSize !== nextSize) {
|
|
198
|
+
deltaApplied += prevSize - nextSize;
|
|
199
|
+
nextSizes[index] = nextSize;
|
|
200
|
+
if (deltaApplied.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879)) >= delta.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879))) break;
|
|
201
|
+
}
|
|
202
|
+
if (delta < 0) {
|
|
203
|
+
if (--index < 0) break;
|
|
204
|
+
} else {
|
|
205
|
+
if (++index >= panelsArray.length) break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// If we were unable to resize any of the panels panels, return the previous state.
|
|
209
|
+
// This will essentially bailout and ignore the "mousemove" event.
|
|
210
|
+
if (deltaApplied === 0) return prevSizes;
|
|
211
|
+
// Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
|
|
212
|
+
pivotId = delta < 0 ? idAfter : idBefore;
|
|
213
|
+
index = panelsArray.findIndex((panel)=>panel.id === pivotId);
|
|
214
|
+
nextSizes[index] = prevSizes[index] + deltaApplied;
|
|
215
|
+
return nextSizes;
|
|
216
|
+
}
|
|
217
|
+
function $d520236daad9c5d5$export$622cea445a1c5b7d(panels, id, direction, sizes, height, width) {
|
|
218
|
+
const panelsArray = $d520236daad9c5d5$export$a861c0ad45885494(panels);
|
|
219
|
+
let index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
220
|
+
if (index < 0) return 0;
|
|
221
|
+
let scaledOffset = 0;
|
|
222
|
+
for(index = index - 1; index >= 0; index--){
|
|
223
|
+
const panel = panelsArray[index];
|
|
224
|
+
scaledOffset += $d520236daad9c5d5$export$31b21d0167753bb4(panels, panel.id, direction, sizes, height, width);
|
|
225
|
+
}
|
|
226
|
+
return Math.round(scaledOffset);
|
|
227
|
+
}
|
|
228
|
+
function $d520236daad9c5d5$export$7361ed18ff57179e(id) {
|
|
229
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
230
|
+
if (element) return element;
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
function $d520236daad9c5d5$export$2e27d3a347680388(id) {
|
|
234
|
+
const element = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
235
|
+
if (element) return element;
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
function $d520236daad9c5d5$export$96a40be80fb6c3c8(id) {
|
|
239
|
+
const handles = $d520236daad9c5d5$export$8d0cd3c32ddc045e();
|
|
240
|
+
const index = handles.findIndex((handle)=>handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
241
|
+
return index ?? null;
|
|
242
|
+
}
|
|
243
|
+
function $d520236daad9c5d5$export$8d0cd3c32ddc045e() {
|
|
244
|
+
return Array.from(document.querySelectorAll(`[data-panel-resize-handle-id]`));
|
|
245
|
+
}
|
|
246
|
+
function $d520236daad9c5d5$export$ae14931f0a0256a3(groupId) {
|
|
247
|
+
return Array.from(document.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
248
|
+
}
|
|
249
|
+
function $d520236daad9c5d5$export$68d3a33c21dfbe27(groupId, handleId, panelsArray) {
|
|
250
|
+
const handle = $d520236daad9c5d5$export$2e27d3a347680388(handleId);
|
|
251
|
+
const handles = $d520236daad9c5d5$export$ae14931f0a0256a3(groupId);
|
|
252
|
+
const index = handles.indexOf(handle);
|
|
253
|
+
const idBefore = panelsArray[index]?.id ?? null;
|
|
254
|
+
const idAfter = panelsArray[index + 1]?.id ?? null;
|
|
255
|
+
return [
|
|
256
|
+
idBefore,
|
|
257
|
+
idAfter
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
function $d520236daad9c5d5$export$a861c0ad45885494(panels) {
|
|
261
|
+
return Array.from(panels.values()).sort((a, b)=>a.order - b.order);
|
|
262
|
+
}
|
|
263
|
+
function $d520236daad9c5d5$export$31b21d0167753bb4(panels, id, direction, sizes, height, width) {
|
|
264
|
+
const totalSize = direction === "horizontal" ? width : height;
|
|
265
|
+
if (panels.size === 1) return totalSize;
|
|
266
|
+
const panelsArray = $d520236daad9c5d5$export$a861c0ad45885494(panels);
|
|
267
|
+
const index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
268
|
+
const size = sizes[index];
|
|
269
|
+
if (size == null) return 0;
|
|
270
|
+
return Math.round(size * totalSize);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
function $63be9a96d8675f03$export$d9fcbe062527d159({ committedValuesRef: committedValuesRef , groupId: groupId , panels: panels , setSizes: setSizes , sizes: sizes }) {
|
|
278
|
+
(0, $b2QPe$react.useEffect)(()=>{
|
|
279
|
+
const { direction: direction , height: height , panels: panels , width: width } = committedValuesRef.current;
|
|
280
|
+
const handles = (0, $d520236daad9c5d5$export$ae14931f0a0256a3)(groupId);
|
|
281
|
+
const cleanupFunctions = handles.map((handle)=>{
|
|
282
|
+
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
283
|
+
const panelsArray = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels);
|
|
284
|
+
const [idBefore, idAfter] = (0, $d520236daad9c5d5$export$68d3a33c21dfbe27)(groupId, handleId, panelsArray);
|
|
285
|
+
if (idBefore == null || idAfter == null) return ()=>{};
|
|
286
|
+
const ariaValueMax = panelsArray.reduce((difference, panel)=>{
|
|
287
|
+
if (panel.id !== idBefore) return difference - panel.minSize;
|
|
288
|
+
return difference;
|
|
289
|
+
}, 1);
|
|
290
|
+
const ariaValueMin = panelsArray.find((panel)=>panel.id == idBefore)?.minSize ?? 0;
|
|
291
|
+
const size = (0, $d520236daad9c5d5$export$31b21d0167753bb4)(panels, idBefore, direction, sizes, height, width);
|
|
292
|
+
const ariaValueNow = size / (direction === "horizontal" ? width : height);
|
|
293
|
+
handle.setAttribute("aria-valuemax", "" + Math.round(100 * ariaValueMax));
|
|
294
|
+
handle.setAttribute("aria-valuemin", "" + Math.round(100 * ariaValueMin));
|
|
295
|
+
handle.setAttribute("aria-valuenow", "" + Math.round(100 * ariaValueNow));
|
|
296
|
+
const onKeyDown = (event)=>{
|
|
297
|
+
switch(event.key){
|
|
298
|
+
case "Enter":
|
|
299
|
+
{
|
|
300
|
+
const index = panelsArray.findIndex((panel)=>panel.id === idBefore);
|
|
301
|
+
if (index >= 0) {
|
|
302
|
+
const panelData = panelsArray[index];
|
|
303
|
+
const size = sizes[index];
|
|
304
|
+
if (size != null) {
|
|
305
|
+
let delta = 0;
|
|
306
|
+
if (size.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879)) <= panelData.minSize.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879))) delta = direction === "horizontal" ? width : height;
|
|
307
|
+
else delta = -(direction === "horizontal" ? width : height);
|
|
308
|
+
const nextSizes = (0, $d520236daad9c5d5$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, sizes);
|
|
309
|
+
if (sizes !== nextSizes) setSizes(nextSizes);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
handle.addEventListener("keydown", onKeyDown);
|
|
317
|
+
const panelBefore = (0, $d520236daad9c5d5$export$7361ed18ff57179e)(idBefore);
|
|
318
|
+
if (panelBefore != null) handle.setAttribute("aria-controls", panelBefore.id);
|
|
319
|
+
return ()=>{
|
|
320
|
+
handle.removeAttribute("aria-valuemax");
|
|
321
|
+
handle.removeAttribute("aria-valuemin");
|
|
322
|
+
handle.removeAttribute("aria-valuenow");
|
|
323
|
+
handle.removeEventListener("keydown", onKeyDown);
|
|
324
|
+
if (panelBefore != null) handle.removeAttribute("aria-controls");
|
|
325
|
+
};
|
|
326
|
+
});
|
|
327
|
+
return ()=>{
|
|
328
|
+
cleanupFunctions.forEach((cleanupFunction)=>cleanupFunction());
|
|
329
|
+
};
|
|
330
|
+
}, [
|
|
331
|
+
groupId,
|
|
332
|
+
panels,
|
|
333
|
+
sizes
|
|
334
|
+
]);
|
|
335
|
+
}
|
|
336
|
+
function $63be9a96d8675f03$export$33b0bea6ac3ffb03({ disabled: disabled , handleId: handleId , resizeHandler: resizeHandler }) {
|
|
337
|
+
(0, $b2QPe$react.useEffect)(()=>{
|
|
338
|
+
if (disabled || resizeHandler == null) return;
|
|
339
|
+
const handleElement = (0, $d520236daad9c5d5$export$2e27d3a347680388)(handleId);
|
|
340
|
+
if (handleElement == null) return;
|
|
341
|
+
const onKeyDown = (event)=>{
|
|
342
|
+
switch(event.key){
|
|
343
|
+
case "ArrowDown":
|
|
344
|
+
case "ArrowLeft":
|
|
345
|
+
case "ArrowRight":
|
|
346
|
+
case "ArrowUp":
|
|
347
|
+
case "End":
|
|
348
|
+
case "Home":
|
|
349
|
+
resizeHandler(event);
|
|
350
|
+
break;
|
|
351
|
+
case "F6":
|
|
352
|
+
{
|
|
353
|
+
const handles = (0, $d520236daad9c5d5$export$8d0cd3c32ddc045e)();
|
|
354
|
+
const index = (0, $d520236daad9c5d5$export$96a40be80fb6c3c8)(handleId);
|
|
355
|
+
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
356
|
+
const nextHandle = handles[nextIndex];
|
|
357
|
+
nextHandle.focus();
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
handleElement.addEventListener("keydown", onKeyDown);
|
|
363
|
+
return ()=>{
|
|
364
|
+
handleElement.removeEventListener("keydown", onKeyDown);
|
|
365
|
+
};
|
|
366
|
+
}, [
|
|
367
|
+
disabled,
|
|
368
|
+
handleId,
|
|
369
|
+
resizeHandler
|
|
370
|
+
]);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
|
|
123
374
|
function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , width: width }) {
|
|
124
375
|
const groupId = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)();
|
|
125
376
|
const [activeHandleId, setActiveHandleId] = (0, $b2QPe$react.useState)(null);
|
|
@@ -147,6 +398,13 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
147
398
|
committedValuesRef.current.sizes = sizes;
|
|
148
399
|
committedValuesRef.current.width = width;
|
|
149
400
|
});
|
|
401
|
+
(0, $63be9a96d8675f03$export$d9fcbe062527d159)({
|
|
402
|
+
committedValuesRef: committedValuesRef,
|
|
403
|
+
groupId: groupId,
|
|
404
|
+
panels: panels,
|
|
405
|
+
setSizes: setSizes,
|
|
406
|
+
sizes: sizes
|
|
407
|
+
});
|
|
150
408
|
// Once all panels have registered themselves,
|
|
151
409
|
// Compute the initial sizes based on default weights.
|
|
152
410
|
// This assumes that panels register during initial mount (no conditional rendering)!
|
|
@@ -159,12 +417,12 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
159
417
|
// default size should be restored from local storage if possible.
|
|
160
418
|
let defaultSizes = undefined;
|
|
161
419
|
if (autoSaveId) {
|
|
162
|
-
const panelIds = $
|
|
420
|
+
const panelIds = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels).map((panel)=>panel.id);
|
|
163
421
|
defaultSizes = (0, $e045b0dd313f33c7$export$9c80c6617f0386da)(autoSaveId, panelIds);
|
|
164
422
|
}
|
|
165
423
|
if (defaultSizes != null) setSizes(defaultSizes);
|
|
166
424
|
else {
|
|
167
|
-
const panelsArray = $
|
|
425
|
+
const panelsArray = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels);
|
|
168
426
|
const totalWeight = panelsArray.reduce((weight, panel)=>{
|
|
169
427
|
return weight + panel.defaultSize;
|
|
170
428
|
}, 0);
|
|
@@ -178,7 +436,7 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
178
436
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
179
437
|
if (autoSaveId) {
|
|
180
438
|
if (sizes.length === 0 || sizes.length !== panels.size) return;
|
|
181
|
-
const panelIds = $
|
|
439
|
+
const panelIds = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels).map((panel)=>panel.id);
|
|
182
440
|
(0, $e045b0dd313f33c7$export$af183b313c61be4f)(autoSaveId, panelIds, sizes);
|
|
183
441
|
}
|
|
184
442
|
}, [
|
|
@@ -188,8 +446,8 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
188
446
|
]);
|
|
189
447
|
const getPanelStyle = (0, $b2QPe$react.useCallback)((id)=>{
|
|
190
448
|
const { panels: panels } = committedValuesRef.current;
|
|
191
|
-
const offset = $
|
|
192
|
-
const size = $
|
|
449
|
+
const offset = (0, $d520236daad9c5d5$export$622cea445a1c5b7d)(panels, id, direction, sizes, height, width);
|
|
450
|
+
const size = (0, $d520236daad9c5d5$export$31b21d0167753bb4)(panels, id, direction, sizes, height, width);
|
|
193
451
|
if (direction === "horizontal") return {
|
|
194
452
|
height: "100%",
|
|
195
453
|
position: "absolute",
|
|
@@ -218,18 +476,17 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
218
476
|
return nextPanels;
|
|
219
477
|
});
|
|
220
478
|
}, []);
|
|
221
|
-
const registerResizeHandle = (0, $b2QPe$react.useCallback)((
|
|
479
|
+
const registerResizeHandle = (0, $b2QPe$react.useCallback)((handleId)=>{
|
|
222
480
|
const resizeHandler = (event)=>{
|
|
223
481
|
event.preventDefault();
|
|
224
482
|
const { direction: direction , height: height , panels: panels , sizes: prevSizes , width: width } = committedValuesRef.current;
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
const index = handles.indexOf(handle);
|
|
228
|
-
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
229
|
-
const idBefore = panelsArray[index]?.id ?? null;
|
|
230
|
-
const idAfter = panelsArray[index + 1]?.id ?? null;
|
|
483
|
+
const panelsArray = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels);
|
|
484
|
+
const [idBefore, idAfter] = (0, $d520236daad9c5d5$export$68d3a33c21dfbe27)(groupId, handleId, panelsArray);
|
|
231
485
|
if (idBefore == null || idAfter == null) return;
|
|
232
|
-
const nextCoordinates = (0, $
|
|
486
|
+
const nextCoordinates = (0, $f5af57c8e042a4ad$export$70637efcd850e4ef)(event, prevCoordinatesRef.current, {
|
|
487
|
+
height: height,
|
|
488
|
+
width: width
|
|
489
|
+
}, direction);
|
|
233
490
|
prevCoordinatesRef.current = {
|
|
234
491
|
screenX: nextCoordinates.screenX,
|
|
235
492
|
screenY: nextCoordinates.screenY
|
|
@@ -237,7 +494,7 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
237
494
|
const isHorizontal = direction === "horizontal";
|
|
238
495
|
const movement = isHorizontal ? nextCoordinates.movementX : nextCoordinates.movementY;
|
|
239
496
|
const delta = isHorizontal ? movement / width : movement / height;
|
|
240
|
-
const nextSizes = $
|
|
497
|
+
const nextSizes = (0, $d520236daad9c5d5$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, prevSizes);
|
|
241
498
|
if (prevSizes !== nextSizes) setSizes(nextSizes);
|
|
242
499
|
};
|
|
243
500
|
return resizeHandler;
|
|
@@ -289,81 +546,21 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
289
546
|
children: children
|
|
290
547
|
}, void 0, false, {
|
|
291
548
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
292
|
-
lineNumber:
|
|
549
|
+
lineNumber: 290,
|
|
293
550
|
columnNumber: 9
|
|
294
551
|
}, this)
|
|
295
552
|
}, void 0, false, {
|
|
296
553
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
297
|
-
lineNumber:
|
|
554
|
+
lineNumber: 289,
|
|
298
555
|
columnNumber: 7
|
|
299
556
|
}, this)
|
|
300
557
|
}, void 0, false, {
|
|
301
558
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
302
|
-
lineNumber:
|
|
559
|
+
lineNumber: 288,
|
|
303
560
|
columnNumber: 5
|
|
304
561
|
}, this);
|
|
305
562
|
}
|
|
306
|
-
|
|
307
|
-
if (delta === 0) return prevSizes;
|
|
308
|
-
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
309
|
-
const nextSizes = prevSizes.concat();
|
|
310
|
-
let deltaApplied = 0;
|
|
311
|
-
// A resizing panel affects the panels before or after it.
|
|
312
|
-
//
|
|
313
|
-
// A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.
|
|
314
|
-
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
315
|
-
//
|
|
316
|
-
// A positive delta means the panel immediately before the resizer should "expand".
|
|
317
|
-
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
|
|
318
|
-
let pivotId = delta < 0 ? idBefore : idAfter;
|
|
319
|
-
let index = panelsArray.findIndex((panel)=>panel.id === pivotId);
|
|
320
|
-
while(true){
|
|
321
|
-
const panel = panelsArray[index];
|
|
322
|
-
const prevSize = prevSizes[index];
|
|
323
|
-
const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);
|
|
324
|
-
if (prevSize !== nextSize) {
|
|
325
|
-
deltaApplied += prevSize - nextSize;
|
|
326
|
-
nextSizes[index] = nextSize;
|
|
327
|
-
if (deltaApplied.toPrecision($d428eaeef644efb2$var$PRECISION) >= delta.toPrecision($d428eaeef644efb2$var$PRECISION)) break;
|
|
328
|
-
}
|
|
329
|
-
if (delta < 0) {
|
|
330
|
-
if (--index < 0) break;
|
|
331
|
-
} else {
|
|
332
|
-
if (++index >= panelsArray.length) break;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
// If we were unable to resize any of the panels panels, return the previous state.
|
|
336
|
-
// This will essentially bailout and ignore the "mousemove" event.
|
|
337
|
-
if (deltaApplied === 0) return prevSizes;
|
|
338
|
-
// Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
|
|
339
|
-
pivotId = delta < 0 ? idAfter : idBefore;
|
|
340
|
-
index = panelsArray.findIndex((panel)=>panel.id === pivotId);
|
|
341
|
-
nextSizes[index] = prevSizes[index] + deltaApplied;
|
|
342
|
-
return nextSizes;
|
|
343
|
-
}
|
|
344
|
-
function $d428eaeef644efb2$var$getOffset(panels, id, direction, sizes, height, width) {
|
|
345
|
-
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
346
|
-
let index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
347
|
-
if (index < 0) return 0;
|
|
348
|
-
let scaledOffset = 0;
|
|
349
|
-
for(index = index - 1; index >= 0; index--){
|
|
350
|
-
const panel = panelsArray[index];
|
|
351
|
-
scaledOffset += $d428eaeef644efb2$var$getSize(panels, panel.id, direction, sizes, height, width);
|
|
352
|
-
}
|
|
353
|
-
return Math.round(scaledOffset);
|
|
354
|
-
}
|
|
355
|
-
function $d428eaeef644efb2$var$getSize(panels, id, direction, sizes, height, width) {
|
|
356
|
-
const totalSize = direction === "horizontal" ? width : height;
|
|
357
|
-
if (panels.size === 1) return totalSize;
|
|
358
|
-
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
359
|
-
const index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
360
|
-
const size = sizes[index];
|
|
361
|
-
if (size == null) return 0;
|
|
362
|
-
return Math.round(size * totalSize);
|
|
363
|
-
}
|
|
364
|
-
function $d428eaeef644efb2$var$panelsMapToSortedArray(panels) {
|
|
365
|
-
return Array.from(panels.values()).sort((a, b)=>a.order - b.order);
|
|
366
|
-
}
|
|
563
|
+
|
|
367
564
|
|
|
368
565
|
|
|
369
566
|
|
|
@@ -387,7 +584,6 @@ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
387
584
|
}
|
|
388
585
|
}, [
|
|
389
586
|
disabled,
|
|
390
|
-
groupId,
|
|
391
587
|
id,
|
|
392
588
|
registerResizeHandle
|
|
393
589
|
]);
|
|
@@ -415,23 +611,31 @@ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
415
611
|
resizeHandler,
|
|
416
612
|
stopDragging
|
|
417
613
|
]);
|
|
614
|
+
(0, $63be9a96d8675f03$export$33b0bea6ac3ffb03)({
|
|
615
|
+
disabled: disabled,
|
|
616
|
+
handleId: id,
|
|
617
|
+
resizeHandler: resizeHandler
|
|
618
|
+
});
|
|
418
619
|
return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
|
|
419
620
|
className: className,
|
|
420
621
|
"data-panel-group-id": groupId,
|
|
622
|
+
"data-panel-resize-handle-enabled": !disabled,
|
|
421
623
|
"data-panel-resize-handle-id": id,
|
|
422
624
|
onMouseDown: ()=>startDragging(id),
|
|
423
625
|
onMouseUp: stopDragging,
|
|
424
626
|
onTouchCancel: stopDragging,
|
|
425
627
|
onTouchEnd: stopDragging,
|
|
426
628
|
onTouchStart: ()=>startDragging(id),
|
|
629
|
+
role: "separator",
|
|
427
630
|
style: {
|
|
428
631
|
cursor: direction === "horizontal" ? "ew-resize" : "ns-resize",
|
|
429
632
|
touchAction: "none"
|
|
430
633
|
},
|
|
634
|
+
tabIndex: 0,
|
|
431
635
|
children: children
|
|
432
636
|
}, void 0, false, {
|
|
433
637
|
fileName: "packages/react-resizable-panels/src/PanelResizeHandle.tsx",
|
|
434
|
-
lineNumber:
|
|
638
|
+
lineNumber: 87,
|
|
435
639
|
columnNumber: 5
|
|
436
640
|
}, this);
|
|
437
641
|
}
|