react-resizable-panels 0.0.7 → 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 +7 -1
- package/dist/react-resizable-panels.d.ts.map +1 -1
- package/dist/react-resizable-panels.js +336 -89
- package/dist/react-resizable-panels.js.map +1 -1
- package/dist/react-resizable-panels.module.js +336 -89
- 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 +67 -143
- package/src/PanelResizeHandle.tsx +20 -8
- package/src/constants.ts +1 -0
- package/src/hooks/useWindowSplitterBehavior.ts +185 -0
- package/src/types.ts +2 -1
- package/src/utils/coordinates.ts +118 -0
- package/src/utils/group.ts +176 -0
|
@@ -38,6 +38,8 @@ function $ad28bce87b00c2be$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
38
38
|
const style = getPanelStyle(id);
|
|
39
39
|
return /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
|
|
40
40
|
className: className,
|
|
41
|
+
"data-panel-id": id,
|
|
42
|
+
id: `data-panel-id-${id}`,
|
|
41
43
|
style: style,
|
|
42
44
|
children: children
|
|
43
45
|
}, void 0, false, {
|
|
@@ -87,7 +89,280 @@ function $6ff1a22b27cc039d$export$af183b313c61be4f(autoSaveId, panelIds, sizes)
|
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
|
|
90
|
-
const $
|
|
92
|
+
const $96f6397ae645d178$var$element = document.createElement("div");
|
|
93
|
+
$96f6397ae645d178$var$element.getBoundingClientRect();
|
|
94
|
+
function $96f6397ae645d178$export$70637efcd850e4ef(event, prevCoordinates, dimensions, direction) {
|
|
95
|
+
const { screenX: prevScreenX , screenY: prevScreenY } = prevCoordinates;
|
|
96
|
+
const { height: height , width: width } = dimensions;
|
|
97
|
+
const getMovementBetween = (current, prev)=>prev === 0 ? 0 : current - prev;
|
|
98
|
+
if ($96f6397ae645d178$export$e7bf60a870f429b0(event)) {
|
|
99
|
+
let movementX = 0;
|
|
100
|
+
let movementY = 0;
|
|
101
|
+
const size = direction === "horizontal" ? width : height;
|
|
102
|
+
const denominator = event.shiftKey ? 10 : 100;
|
|
103
|
+
const delta = size / denominator;
|
|
104
|
+
switch(event.key){
|
|
105
|
+
case "ArrowDown":
|
|
106
|
+
movementY = delta;
|
|
107
|
+
break;
|
|
108
|
+
case "ArrowLeft":
|
|
109
|
+
movementX = -delta;
|
|
110
|
+
break;
|
|
111
|
+
case "ArrowRight":
|
|
112
|
+
movementX = delta;
|
|
113
|
+
break;
|
|
114
|
+
case "ArrowUp":
|
|
115
|
+
movementY = -delta;
|
|
116
|
+
break;
|
|
117
|
+
case "End":
|
|
118
|
+
if (direction === "horizontal") movementX = size;
|
|
119
|
+
else movementY = size;
|
|
120
|
+
break;
|
|
121
|
+
case "Home":
|
|
122
|
+
if (direction === "horizontal") movementX = -size;
|
|
123
|
+
else movementY = -size;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
// Estimate screen X/Y to be the center of the resize handle.
|
|
127
|
+
// Otherwise the first mouse/touch event after a keyboard event will appear to "jump"
|
|
128
|
+
let screenX = 0;
|
|
129
|
+
let screenY = 0;
|
|
130
|
+
if (document.activeElement) {
|
|
131
|
+
const rect = document.activeElement.getBoundingClientRect();
|
|
132
|
+
screenX = rect.left + rect.width / 2;
|
|
133
|
+
screenY = rect.top + rect.height / 2;
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
movementX: movementX,
|
|
137
|
+
movementY: movementY,
|
|
138
|
+
screenX: screenX,
|
|
139
|
+
screenY: screenY
|
|
140
|
+
};
|
|
141
|
+
} else if ($96f6397ae645d178$export$ce897e7f0aa63661(event)) {
|
|
142
|
+
const firstTouch = event.touches[0];
|
|
143
|
+
return {
|
|
144
|
+
movementX: getMovementBetween(firstTouch.screenX, prevScreenX),
|
|
145
|
+
movementY: getMovementBetween(firstTouch.screenY, prevScreenY),
|
|
146
|
+
screenX: firstTouch.screenX,
|
|
147
|
+
screenY: firstTouch.screenY
|
|
148
|
+
};
|
|
149
|
+
} else if ($96f6397ae645d178$export$5107d838cdd17dee(event)) return {
|
|
150
|
+
movementX: getMovementBetween(event.screenX, prevScreenX),
|
|
151
|
+
movementY: getMovementBetween(event.screenY, prevScreenY),
|
|
152
|
+
screenX: event.screenX,
|
|
153
|
+
screenY: event.screenY
|
|
154
|
+
};
|
|
155
|
+
else throw Error(`Unsupported event type: "${event.type}"`);
|
|
156
|
+
}
|
|
157
|
+
function $96f6397ae645d178$export$e7bf60a870f429b0(event) {
|
|
158
|
+
return event.type === "keydown";
|
|
159
|
+
}
|
|
160
|
+
function $96f6397ae645d178$export$5107d838cdd17dee(event) {
|
|
161
|
+
return event.type === "mousemove";
|
|
162
|
+
}
|
|
163
|
+
function $96f6397ae645d178$export$ce897e7f0aa63661(event) {
|
|
164
|
+
return event.type === "touchmove";
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
const $fc25b75732bfda27$export$d6d3992f3becc879 = 5;
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
function $f30c804b5fe6cc1a$export$f50bae335f53943c(panels, idBefore, idAfter, delta, prevSizes) {
|
|
172
|
+
if (delta === 0) return prevSizes;
|
|
173
|
+
const panelsArray = $f30c804b5fe6cc1a$export$a861c0ad45885494(panels);
|
|
174
|
+
const nextSizes = prevSizes.concat();
|
|
175
|
+
let deltaApplied = 0;
|
|
176
|
+
// A resizing panel affects the panels before or after it.
|
|
177
|
+
//
|
|
178
|
+
// A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.
|
|
179
|
+
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
180
|
+
//
|
|
181
|
+
// A positive delta means the panel immediately before the resizer should "expand".
|
|
182
|
+
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
|
|
183
|
+
let pivotId = delta < 0 ? idBefore : idAfter;
|
|
184
|
+
let index = panelsArray.findIndex((panel)=>panel.id === pivotId);
|
|
185
|
+
while(true){
|
|
186
|
+
const panel = panelsArray[index];
|
|
187
|
+
const prevSize = prevSizes[index];
|
|
188
|
+
const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);
|
|
189
|
+
if (prevSize !== nextSize) {
|
|
190
|
+
deltaApplied += prevSize - nextSize;
|
|
191
|
+
nextSizes[index] = nextSize;
|
|
192
|
+
if (deltaApplied.toPrecision((0, $fc25b75732bfda27$export$d6d3992f3becc879)) >= delta.toPrecision((0, $fc25b75732bfda27$export$d6d3992f3becc879))) break;
|
|
193
|
+
}
|
|
194
|
+
if (delta < 0) {
|
|
195
|
+
if (--index < 0) break;
|
|
196
|
+
} else {
|
|
197
|
+
if (++index >= panelsArray.length) break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// If we were unable to resize any of the panels panels, return the previous state.
|
|
201
|
+
// This will essentially bailout and ignore the "mousemove" event.
|
|
202
|
+
if (deltaApplied === 0) return prevSizes;
|
|
203
|
+
// Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
|
|
204
|
+
pivotId = delta < 0 ? idAfter : idBefore;
|
|
205
|
+
index = panelsArray.findIndex((panel)=>panel.id === pivotId);
|
|
206
|
+
nextSizes[index] = prevSizes[index] + deltaApplied;
|
|
207
|
+
return nextSizes;
|
|
208
|
+
}
|
|
209
|
+
function $f30c804b5fe6cc1a$export$622cea445a1c5b7d(panels, id, direction, sizes, height, width) {
|
|
210
|
+
const panelsArray = $f30c804b5fe6cc1a$export$a861c0ad45885494(panels);
|
|
211
|
+
let index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
212
|
+
if (index < 0) return 0;
|
|
213
|
+
let scaledOffset = 0;
|
|
214
|
+
for(index = index - 1; index >= 0; index--){
|
|
215
|
+
const panel = panelsArray[index];
|
|
216
|
+
scaledOffset += $f30c804b5fe6cc1a$export$31b21d0167753bb4(panels, panel.id, direction, sizes, height, width);
|
|
217
|
+
}
|
|
218
|
+
return Math.round(scaledOffset);
|
|
219
|
+
}
|
|
220
|
+
function $f30c804b5fe6cc1a$export$7361ed18ff57179e(id) {
|
|
221
|
+
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
222
|
+
if (element) return element;
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
function $f30c804b5fe6cc1a$export$2e27d3a347680388(id) {
|
|
226
|
+
const element = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
227
|
+
if (element) return element;
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
function $f30c804b5fe6cc1a$export$96a40be80fb6c3c8(id) {
|
|
231
|
+
const handles = $f30c804b5fe6cc1a$export$8d0cd3c32ddc045e();
|
|
232
|
+
const index = handles.findIndex((handle)=>handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
233
|
+
return index ?? null;
|
|
234
|
+
}
|
|
235
|
+
function $f30c804b5fe6cc1a$export$8d0cd3c32ddc045e() {
|
|
236
|
+
return Array.from(document.querySelectorAll(`[data-panel-resize-handle-id]`));
|
|
237
|
+
}
|
|
238
|
+
function $f30c804b5fe6cc1a$export$ae14931f0a0256a3(groupId) {
|
|
239
|
+
return Array.from(document.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
240
|
+
}
|
|
241
|
+
function $f30c804b5fe6cc1a$export$68d3a33c21dfbe27(groupId, handleId, panelsArray) {
|
|
242
|
+
const handle = $f30c804b5fe6cc1a$export$2e27d3a347680388(handleId);
|
|
243
|
+
const handles = $f30c804b5fe6cc1a$export$ae14931f0a0256a3(groupId);
|
|
244
|
+
const index = handles.indexOf(handle);
|
|
245
|
+
const idBefore = panelsArray[index]?.id ?? null;
|
|
246
|
+
const idAfter = panelsArray[index + 1]?.id ?? null;
|
|
247
|
+
return [
|
|
248
|
+
idBefore,
|
|
249
|
+
idAfter
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
function $f30c804b5fe6cc1a$export$a861c0ad45885494(panels) {
|
|
253
|
+
return Array.from(panels.values()).sort((a, b)=>a.order - b.order);
|
|
254
|
+
}
|
|
255
|
+
function $f30c804b5fe6cc1a$export$31b21d0167753bb4(panels, id, direction, sizes, height, width) {
|
|
256
|
+
const totalSize = direction === "horizontal" ? width : height;
|
|
257
|
+
if (panels.size === 1) return totalSize;
|
|
258
|
+
const panelsArray = $f30c804b5fe6cc1a$export$a861c0ad45885494(panels);
|
|
259
|
+
const index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
260
|
+
const size = sizes[index];
|
|
261
|
+
if (size == null) return 0;
|
|
262
|
+
return Math.round(size * totalSize);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
function $99ad02c951ec80d0$export$d9fcbe062527d159({ committedValuesRef: committedValuesRef , groupId: groupId , panels: panels , setSizes: setSizes , sizes: sizes }) {
|
|
270
|
+
(0, $fpI56$useEffect)(()=>{
|
|
271
|
+
const { direction: direction , height: height , panels: panels , width: width } = committedValuesRef.current;
|
|
272
|
+
const handles = (0, $f30c804b5fe6cc1a$export$ae14931f0a0256a3)(groupId);
|
|
273
|
+
const cleanupFunctions = handles.map((handle)=>{
|
|
274
|
+
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
275
|
+
const panelsArray = (0, $f30c804b5fe6cc1a$export$a861c0ad45885494)(panels);
|
|
276
|
+
const [idBefore, idAfter] = (0, $f30c804b5fe6cc1a$export$68d3a33c21dfbe27)(groupId, handleId, panelsArray);
|
|
277
|
+
if (idBefore == null || idAfter == null) return ()=>{};
|
|
278
|
+
const ariaValueMax = panelsArray.reduce((difference, panel)=>{
|
|
279
|
+
if (panel.id !== idBefore) return difference - panel.minSize;
|
|
280
|
+
return difference;
|
|
281
|
+
}, 1);
|
|
282
|
+
const ariaValueMin = panelsArray.find((panel)=>panel.id == idBefore)?.minSize ?? 0;
|
|
283
|
+
const size = (0, $f30c804b5fe6cc1a$export$31b21d0167753bb4)(panels, idBefore, direction, sizes, height, width);
|
|
284
|
+
const ariaValueNow = size / (direction === "horizontal" ? width : height);
|
|
285
|
+
handle.setAttribute("aria-valuemax", "" + Math.round(100 * ariaValueMax));
|
|
286
|
+
handle.setAttribute("aria-valuemin", "" + Math.round(100 * ariaValueMin));
|
|
287
|
+
handle.setAttribute("aria-valuenow", "" + Math.round(100 * ariaValueNow));
|
|
288
|
+
const onKeyDown = (event)=>{
|
|
289
|
+
switch(event.key){
|
|
290
|
+
case "Enter":
|
|
291
|
+
{
|
|
292
|
+
const index = panelsArray.findIndex((panel)=>panel.id === idBefore);
|
|
293
|
+
if (index >= 0) {
|
|
294
|
+
const panelData = panelsArray[index];
|
|
295
|
+
const size = sizes[index];
|
|
296
|
+
if (size != null) {
|
|
297
|
+
let delta = 0;
|
|
298
|
+
if (size.toPrecision((0, $fc25b75732bfda27$export$d6d3992f3becc879)) <= panelData.minSize.toPrecision((0, $fc25b75732bfda27$export$d6d3992f3becc879))) delta = direction === "horizontal" ? width : height;
|
|
299
|
+
else delta = -(direction === "horizontal" ? width : height);
|
|
300
|
+
const nextSizes = (0, $f30c804b5fe6cc1a$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, sizes);
|
|
301
|
+
if (sizes !== nextSizes) setSizes(nextSizes);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
handle.addEventListener("keydown", onKeyDown);
|
|
309
|
+
const panelBefore = (0, $f30c804b5fe6cc1a$export$7361ed18ff57179e)(idBefore);
|
|
310
|
+
if (panelBefore != null) handle.setAttribute("aria-controls", panelBefore.id);
|
|
311
|
+
return ()=>{
|
|
312
|
+
handle.removeAttribute("aria-valuemax");
|
|
313
|
+
handle.removeAttribute("aria-valuemin");
|
|
314
|
+
handle.removeAttribute("aria-valuenow");
|
|
315
|
+
handle.removeEventListener("keydown", onKeyDown);
|
|
316
|
+
if (panelBefore != null) handle.removeAttribute("aria-controls");
|
|
317
|
+
};
|
|
318
|
+
});
|
|
319
|
+
return ()=>{
|
|
320
|
+
cleanupFunctions.forEach((cleanupFunction)=>cleanupFunction());
|
|
321
|
+
};
|
|
322
|
+
}, [
|
|
323
|
+
groupId,
|
|
324
|
+
panels,
|
|
325
|
+
sizes
|
|
326
|
+
]);
|
|
327
|
+
}
|
|
328
|
+
function $99ad02c951ec80d0$export$33b0bea6ac3ffb03({ disabled: disabled , handleId: handleId , resizeHandler: resizeHandler }) {
|
|
329
|
+
(0, $fpI56$useEffect)(()=>{
|
|
330
|
+
if (disabled || resizeHandler == null) return;
|
|
331
|
+
const handleElement = (0, $f30c804b5fe6cc1a$export$2e27d3a347680388)(handleId);
|
|
332
|
+
if (handleElement == null) return;
|
|
333
|
+
const onKeyDown = (event)=>{
|
|
334
|
+
switch(event.key){
|
|
335
|
+
case "ArrowDown":
|
|
336
|
+
case "ArrowLeft":
|
|
337
|
+
case "ArrowRight":
|
|
338
|
+
case "ArrowUp":
|
|
339
|
+
case "End":
|
|
340
|
+
case "Home":
|
|
341
|
+
resizeHandler(event);
|
|
342
|
+
break;
|
|
343
|
+
case "F6":
|
|
344
|
+
{
|
|
345
|
+
const handles = (0, $f30c804b5fe6cc1a$export$8d0cd3c32ddc045e)();
|
|
346
|
+
const index = (0, $f30c804b5fe6cc1a$export$96a40be80fb6c3c8)(handleId);
|
|
347
|
+
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
348
|
+
const nextHandle = handles[nextIndex];
|
|
349
|
+
nextHandle.focus();
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
handleElement.addEventListener("keydown", onKeyDown);
|
|
355
|
+
return ()=>{
|
|
356
|
+
handleElement.removeEventListener("keydown", onKeyDown);
|
|
357
|
+
};
|
|
358
|
+
}, [
|
|
359
|
+
disabled,
|
|
360
|
+
handleId,
|
|
361
|
+
resizeHandler
|
|
362
|
+
]);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
|
|
91
366
|
function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , width: width }) {
|
|
92
367
|
const groupId = (0, $968185313205dcfa$export$2e2bcd8739ae039)();
|
|
93
368
|
const [activeHandleId, setActiveHandleId] = (0, $fpI56$useState)(null);
|
|
@@ -102,6 +377,12 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
102
377
|
sizes: sizes,
|
|
103
378
|
width: width
|
|
104
379
|
});
|
|
380
|
+
// Tracks the most recent coordinates of a touch/mouse event.
|
|
381
|
+
// This is needed to calculate movement (because TouchEvent doesn't support movementX and movementY).
|
|
382
|
+
const prevCoordinatesRef = (0, $fpI56$useRef)({
|
|
383
|
+
screenX: 0,
|
|
384
|
+
screenY: 0
|
|
385
|
+
});
|
|
105
386
|
(0, $fpI56$useLayoutEffect)(()=>{
|
|
106
387
|
committedValuesRef.current.direction = direction;
|
|
107
388
|
committedValuesRef.current.height = height;
|
|
@@ -109,6 +390,13 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
109
390
|
committedValuesRef.current.sizes = sizes;
|
|
110
391
|
committedValuesRef.current.width = width;
|
|
111
392
|
});
|
|
393
|
+
(0, $99ad02c951ec80d0$export$d9fcbe062527d159)({
|
|
394
|
+
committedValuesRef: committedValuesRef,
|
|
395
|
+
groupId: groupId,
|
|
396
|
+
panels: panels,
|
|
397
|
+
setSizes: setSizes,
|
|
398
|
+
sizes: sizes
|
|
399
|
+
});
|
|
112
400
|
// Once all panels have registered themselves,
|
|
113
401
|
// Compute the initial sizes based on default weights.
|
|
114
402
|
// This assumes that panels register during initial mount (no conditional rendering)!
|
|
@@ -121,12 +409,12 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
121
409
|
// default size should be restored from local storage if possible.
|
|
122
410
|
let defaultSizes = undefined;
|
|
123
411
|
if (autoSaveId) {
|
|
124
|
-
const panelIds = $
|
|
412
|
+
const panelIds = (0, $f30c804b5fe6cc1a$export$a861c0ad45885494)(panels).map((panel)=>panel.id);
|
|
125
413
|
defaultSizes = (0, $6ff1a22b27cc039d$export$9c80c6617f0386da)(autoSaveId, panelIds);
|
|
126
414
|
}
|
|
127
415
|
if (defaultSizes != null) setSizes(defaultSizes);
|
|
128
416
|
else {
|
|
129
|
-
const panelsArray = $
|
|
417
|
+
const panelsArray = (0, $f30c804b5fe6cc1a$export$a861c0ad45885494)(panels);
|
|
130
418
|
const totalWeight = panelsArray.reduce((weight, panel)=>{
|
|
131
419
|
return weight + panel.defaultSize;
|
|
132
420
|
}, 0);
|
|
@@ -140,7 +428,7 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
140
428
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
141
429
|
if (autoSaveId) {
|
|
142
430
|
if (sizes.length === 0 || sizes.length !== panels.size) return;
|
|
143
|
-
const panelIds = $
|
|
431
|
+
const panelIds = (0, $f30c804b5fe6cc1a$export$a861c0ad45885494)(panels).map((panel)=>panel.id);
|
|
144
432
|
(0, $6ff1a22b27cc039d$export$af183b313c61be4f)(autoSaveId, panelIds, sizes);
|
|
145
433
|
}
|
|
146
434
|
}, [
|
|
@@ -150,8 +438,8 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
150
438
|
]);
|
|
151
439
|
const getPanelStyle = (0, $fpI56$useCallback)((id)=>{
|
|
152
440
|
const { panels: panels } = committedValuesRef.current;
|
|
153
|
-
const offset = $
|
|
154
|
-
const size = $
|
|
441
|
+
const offset = (0, $f30c804b5fe6cc1a$export$622cea445a1c5b7d)(panels, id, direction, sizes, height, width);
|
|
442
|
+
const size = (0, $f30c804b5fe6cc1a$export$31b21d0167753bb4)(panels, id, direction, sizes, height, width);
|
|
155
443
|
if (direction === "horizontal") return {
|
|
156
444
|
height: "100%",
|
|
157
445
|
position: "absolute",
|
|
@@ -180,21 +468,25 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
180
468
|
return nextPanels;
|
|
181
469
|
});
|
|
182
470
|
}, []);
|
|
183
|
-
const registerResizeHandle = (0, $fpI56$useCallback)((
|
|
471
|
+
const registerResizeHandle = (0, $fpI56$useCallback)((handleId)=>{
|
|
184
472
|
const resizeHandler = (event)=>{
|
|
185
473
|
event.preventDefault();
|
|
186
474
|
const { direction: direction , height: height , panels: panels , sizes: prevSizes , width: width } = committedValuesRef.current;
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
const index = handles.indexOf(handle);
|
|
190
|
-
const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
|
|
191
|
-
const idBefore = panelsArray[index]?.id ?? null;
|
|
192
|
-
const idAfter = panelsArray[index + 1]?.id ?? null;
|
|
475
|
+
const panelsArray = (0, $f30c804b5fe6cc1a$export$a861c0ad45885494)(panels);
|
|
476
|
+
const [idBefore, idAfter] = (0, $f30c804b5fe6cc1a$export$68d3a33c21dfbe27)(groupId, handleId, panelsArray);
|
|
193
477
|
if (idBefore == null || idAfter == null) return;
|
|
478
|
+
const nextCoordinates = (0, $96f6397ae645d178$export$70637efcd850e4ef)(event, prevCoordinatesRef.current, {
|
|
479
|
+
height: height,
|
|
480
|
+
width: width
|
|
481
|
+
}, direction);
|
|
482
|
+
prevCoordinatesRef.current = {
|
|
483
|
+
screenX: nextCoordinates.screenX,
|
|
484
|
+
screenY: nextCoordinates.screenY
|
|
485
|
+
};
|
|
194
486
|
const isHorizontal = direction === "horizontal";
|
|
195
|
-
const movement = isHorizontal ?
|
|
487
|
+
const movement = isHorizontal ? nextCoordinates.movementX : nextCoordinates.movementY;
|
|
196
488
|
const delta = isHorizontal ? movement / width : movement / height;
|
|
197
|
-
const nextSizes = $
|
|
489
|
+
const nextSizes = (0, $f30c804b5fe6cc1a$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, prevSizes);
|
|
198
490
|
if (prevSizes !== nextSizes) setSizes(nextSizes);
|
|
199
491
|
};
|
|
200
492
|
return resizeHandler;
|
|
@@ -216,7 +508,13 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
216
508
|
registerPanel: registerPanel,
|
|
217
509
|
registerResizeHandle: registerResizeHandle,
|
|
218
510
|
startDragging: (id)=>setActiveHandleId(id),
|
|
219
|
-
stopDragging: ()=>
|
|
511
|
+
stopDragging: ()=>{
|
|
512
|
+
setActiveHandleId(null);
|
|
513
|
+
prevCoordinatesRef.current = {
|
|
514
|
+
screenX: 0,
|
|
515
|
+
screenY: 0
|
|
516
|
+
};
|
|
517
|
+
},
|
|
220
518
|
unregisterPanel: unregisterPanel
|
|
221
519
|
}), [
|
|
222
520
|
direction,
|
|
@@ -240,81 +538,21 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
240
538
|
children: children
|
|
241
539
|
}, void 0, false, {
|
|
242
540
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
243
|
-
lineNumber:
|
|
541
|
+
lineNumber: 290,
|
|
244
542
|
columnNumber: 9
|
|
245
543
|
}, this)
|
|
246
544
|
}, void 0, false, {
|
|
247
545
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
248
|
-
lineNumber:
|
|
546
|
+
lineNumber: 289,
|
|
249
547
|
columnNumber: 7
|
|
250
548
|
}, this)
|
|
251
549
|
}, void 0, false, {
|
|
252
550
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
253
|
-
lineNumber:
|
|
551
|
+
lineNumber: 288,
|
|
254
552
|
columnNumber: 5
|
|
255
553
|
}, this);
|
|
256
554
|
}
|
|
257
|
-
|
|
258
|
-
if (delta === 0) return prevSizes;
|
|
259
|
-
const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
|
|
260
|
-
const nextSizes = prevSizes.concat();
|
|
261
|
-
let deltaApplied = 0;
|
|
262
|
-
// A resizing panel affects the panels before or after it.
|
|
263
|
-
//
|
|
264
|
-
// A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.
|
|
265
|
-
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
266
|
-
//
|
|
267
|
-
// A positive delta means the panel immediately before the resizer should "expand".
|
|
268
|
-
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
|
|
269
|
-
let pivotId = delta < 0 ? idBefore : idAfter;
|
|
270
|
-
let index = panelsArray.findIndex((panel)=>panel.id === pivotId);
|
|
271
|
-
while(true){
|
|
272
|
-
const panel = panelsArray[index];
|
|
273
|
-
const prevSize = prevSizes[index];
|
|
274
|
-
const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);
|
|
275
|
-
if (prevSize !== nextSize) {
|
|
276
|
-
deltaApplied += prevSize - nextSize;
|
|
277
|
-
nextSizes[index] = nextSize;
|
|
278
|
-
if (deltaApplied.toPrecision($c44ee3356398c8a1$var$PRECISION) >= delta.toPrecision($c44ee3356398c8a1$var$PRECISION)) break;
|
|
279
|
-
}
|
|
280
|
-
if (delta < 0) {
|
|
281
|
-
if (--index < 0) break;
|
|
282
|
-
} else {
|
|
283
|
-
if (++index >= panelsArray.length) break;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
// If we were unable to resize any of the panels panels, return the previous state.
|
|
287
|
-
// This will essentially bailout and ignore the "mousemove" event.
|
|
288
|
-
if (deltaApplied === 0) return prevSizes;
|
|
289
|
-
// Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
|
|
290
|
-
pivotId = delta < 0 ? idAfter : idBefore;
|
|
291
|
-
index = panelsArray.findIndex((panel)=>panel.id === pivotId);
|
|
292
|
-
nextSizes[index] = prevSizes[index] + deltaApplied;
|
|
293
|
-
return nextSizes;
|
|
294
|
-
}
|
|
295
|
-
function $c44ee3356398c8a1$var$getOffset(panels, id, direction, sizes, height, width) {
|
|
296
|
-
const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
|
|
297
|
-
let index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
298
|
-
if (index < 0) return 0;
|
|
299
|
-
let scaledOffset = 0;
|
|
300
|
-
for(index = index - 1; index >= 0; index--){
|
|
301
|
-
const panel = panelsArray[index];
|
|
302
|
-
scaledOffset += $c44ee3356398c8a1$var$getSize(panels, panel.id, direction, sizes, height, width);
|
|
303
|
-
}
|
|
304
|
-
return Math.round(scaledOffset);
|
|
305
|
-
}
|
|
306
|
-
function $c44ee3356398c8a1$var$getSize(panels, id, direction, sizes, height, width) {
|
|
307
|
-
const totalSize = direction === "horizontal" ? width : height;
|
|
308
|
-
if (panels.size === 1) return totalSize;
|
|
309
|
-
const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
|
|
310
|
-
const index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
311
|
-
const size = sizes[index];
|
|
312
|
-
if (size == null) return 0;
|
|
313
|
-
return Math.round(size * totalSize);
|
|
314
|
-
}
|
|
315
|
-
function $c44ee3356398c8a1$var$panelsMapToSortedArray(panels) {
|
|
316
|
-
return Array.from(panels.values()).sort((a, b)=>a.order - b.order);
|
|
317
|
-
}
|
|
555
|
+
|
|
318
556
|
|
|
319
557
|
|
|
320
558
|
|
|
@@ -338,25 +576,24 @@ function $b067b37706bb37b8$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
338
576
|
}
|
|
339
577
|
}, [
|
|
340
578
|
disabled,
|
|
341
|
-
groupId,
|
|
342
579
|
id,
|
|
343
580
|
registerResizeHandle
|
|
344
581
|
]);
|
|
345
582
|
(0, $fpI56$useEffect)(()=>{
|
|
346
583
|
if (disabled || resizeHandler == null || !isDragging) return;
|
|
347
584
|
document.body.style.cursor = direction === "horizontal" ? "ew-resize" : "ns-resize";
|
|
348
|
-
const
|
|
585
|
+
const onMove = (event)=>{
|
|
349
586
|
resizeHandler(event);
|
|
350
587
|
};
|
|
351
588
|
document.body.addEventListener("mouseleave", stopDragging);
|
|
352
|
-
document.body.addEventListener("mousemove",
|
|
353
|
-
document.body.addEventListener("touchmove",
|
|
589
|
+
document.body.addEventListener("mousemove", onMove);
|
|
590
|
+
document.body.addEventListener("touchmove", onMove);
|
|
354
591
|
document.body.addEventListener("mouseup", stopDragging);
|
|
355
592
|
return ()=>{
|
|
356
593
|
document.body.style.cursor = "";
|
|
357
594
|
document.body.removeEventListener("mouseleave", stopDragging);
|
|
358
|
-
document.body.removeEventListener("mousemove",
|
|
359
|
-
document.body.removeEventListener("touchmove",
|
|
595
|
+
document.body.removeEventListener("mousemove", onMove);
|
|
596
|
+
document.body.removeEventListener("touchmove", onMove);
|
|
360
597
|
document.body.removeEventListener("mouseup", stopDragging);
|
|
361
598
|
};
|
|
362
599
|
}, [
|
|
@@ -366,21 +603,31 @@ function $b067b37706bb37b8$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
366
603
|
resizeHandler,
|
|
367
604
|
stopDragging
|
|
368
605
|
]);
|
|
606
|
+
(0, $99ad02c951ec80d0$export$33b0bea6ac3ffb03)({
|
|
607
|
+
disabled: disabled,
|
|
608
|
+
handleId: id,
|
|
609
|
+
resizeHandler: resizeHandler
|
|
610
|
+
});
|
|
369
611
|
return /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
|
|
370
612
|
className: className,
|
|
371
613
|
"data-panel-group-id": groupId,
|
|
614
|
+
"data-panel-resize-handle-enabled": !disabled,
|
|
372
615
|
"data-panel-resize-handle-id": id,
|
|
373
616
|
onMouseDown: ()=>startDragging(id),
|
|
374
617
|
onMouseUp: stopDragging,
|
|
375
|
-
|
|
618
|
+
onTouchCancel: stopDragging,
|
|
376
619
|
onTouchEnd: stopDragging,
|
|
620
|
+
onTouchStart: ()=>startDragging(id),
|
|
621
|
+
role: "separator",
|
|
377
622
|
style: {
|
|
378
|
-
cursor: direction === "horizontal" ? "ew-resize" : "ns-resize"
|
|
623
|
+
cursor: direction === "horizontal" ? "ew-resize" : "ns-resize",
|
|
624
|
+
touchAction: "none"
|
|
379
625
|
},
|
|
626
|
+
tabIndex: 0,
|
|
380
627
|
children: children
|
|
381
628
|
}, void 0, false, {
|
|
382
629
|
fileName: "packages/react-resizable-panels/src/PanelResizeHandle.tsx",
|
|
383
|
-
lineNumber:
|
|
630
|
+
lineNumber: 87,
|
|
384
631
|
columnNumber: 5
|
|
385
632
|
}, this);
|
|
386
633
|
}
|