react-resizable-panels 0.0.57 → 0.0.58
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 -0
- package/dist/declarations/src/Panel.d.ts +7 -3
- package/dist/declarations/src/PanelGroup.d.ts +3 -1
- package/dist/declarations/src/PanelResizeHandle.d.ts +3 -1
- package/dist/declarations/src/types.d.ts +3 -0
- package/dist/react-resizable-panels.browser.cjs.js +129 -57
- package/dist/react-resizable-panels.browser.development.cjs.js +129 -57
- package/dist/react-resizable-panels.browser.development.esm.js +129 -57
- package/dist/react-resizable-panels.browser.esm.js +129 -57
- package/dist/react-resizable-panels.cjs.js +129 -57
- package/dist/react-resizable-panels.cjs.js.map +1 -1
- package/dist/react-resizable-panels.development.cjs.js +129 -57
- package/dist/react-resizable-panels.development.esm.js +129 -57
- package/dist/react-resizable-panels.development.node.cjs.js +129 -57
- package/dist/react-resizable-panels.development.node.esm.js +129 -57
- package/dist/react-resizable-panels.esm.js +129 -57
- package/dist/react-resizable-panels.esm.js.map +1 -1
- package/dist/react-resizable-panels.node.cjs.js +129 -57
- package/dist/react-resizable-panels.node.esm.js +129 -57
- package/package.json +1 -1
- package/src/Panel.ts +8 -2
- package/src/PanelGroup.ts +5 -1
- package/src/PanelResizeHandle.ts +5 -0
- package/src/types.ts +4 -0
- package/src/utils/adjustLayoutByDelta.test.ts +238 -8
- package/src/utils/adjustLayoutByDelta.ts +122 -72
- package/src/utils/resizePanel.test.ts +61 -1
- package/src/utils/resizePanel.ts +7 -1
- package/src/utils/validatePanelGroupLayout.test.ts +36 -6
|
@@ -44,6 +44,7 @@ function PanelWithForwardedRef({
|
|
|
44
44
|
collapsedSizePercentage,
|
|
45
45
|
collapsedSizePixels,
|
|
46
46
|
collapsible,
|
|
47
|
+
dataAttributes,
|
|
47
48
|
defaultSizePercentage,
|
|
48
49
|
defaultSizePixels,
|
|
49
50
|
forwardedRef,
|
|
@@ -163,6 +164,7 @@ function PanelWithForwardedRef({
|
|
|
163
164
|
...style,
|
|
164
165
|
...styleFromProps
|
|
165
166
|
},
|
|
167
|
+
...dataAttributes,
|
|
166
168
|
// CSS selectors
|
|
167
169
|
"data-panel": "",
|
|
168
170
|
"data-panel-id": panelId,
|
|
@@ -300,7 +302,13 @@ function resizePanel({
|
|
|
300
302
|
if (minSizePercentage != null) {
|
|
301
303
|
if (fuzzyCompareNumbers(size, minSizePercentage) < 0) {
|
|
302
304
|
if (collapsible) {
|
|
303
|
-
|
|
305
|
+
// Collapsible panels should snap closed or open only once they cross the halfway point between collapsed and min size.
|
|
306
|
+
const halfwayPoint = (collapsedSizePercentage + minSizePercentage) / 2;
|
|
307
|
+
if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
|
|
308
|
+
size = collapsedSizePercentage;
|
|
309
|
+
} else {
|
|
310
|
+
size = minSizePercentage;
|
|
311
|
+
}
|
|
304
312
|
} else {
|
|
305
313
|
size = minSizePercentage;
|
|
306
314
|
}
|
|
@@ -327,60 +335,123 @@ function adjustLayoutByDelta({
|
|
|
327
335
|
const nextLayout = [...prevLayout];
|
|
328
336
|
let deltaApplied = 0;
|
|
329
337
|
|
|
338
|
+
//const DEBUG = [];
|
|
339
|
+
//DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
|
|
340
|
+
//DEBUG.push(` delta: ${delta}`);
|
|
341
|
+
//DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
342
|
+
//DEBUG.push(` trigger: ${trigger}`);
|
|
343
|
+
//DEBUG.push("");
|
|
344
|
+
|
|
330
345
|
// A resizing panel affects the panels before or after it.
|
|
331
346
|
//
|
|
332
|
-
// A negative delta means the panel immediately after the
|
|
347
|
+
// A negative delta means the panel(s) immediately after the resize handle should grow/expand by decreasing its offset.
|
|
333
348
|
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
334
349
|
//
|
|
335
|
-
// A positive delta means the panel immediately before the
|
|
336
|
-
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the
|
|
350
|
+
// A positive delta means the panel(s) immediately before the resize handle should "expand".
|
|
351
|
+
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resize handle.
|
|
337
352
|
|
|
338
|
-
// First, check the panel we're pivoting around;
|
|
339
|
-
// We should only expand or contract by as much as its constraints allow
|
|
340
353
|
{
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
354
|
+
// If this is a resize triggered by a keyboard event, our logic for expanding/collapsing is different.
|
|
355
|
+
// We no longer check the halfway threshold because this may prevent the panel from expanding at all.
|
|
356
|
+
if (trigger === "keyboard") {
|
|
357
|
+
{
|
|
358
|
+
// Check if we should expand a collapsed panel
|
|
359
|
+
const index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
360
|
+
const constraints = panelConstraints[index];
|
|
361
|
+
//DEBUG.push(`edge case check 1: ${index}`);
|
|
362
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
363
|
+
if (constraints.collapsible) {
|
|
364
|
+
const prevSize = prevLayout[index];
|
|
365
|
+
const {
|
|
366
|
+
collapsedSizePercentage,
|
|
367
|
+
minSizePercentage
|
|
368
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
369
|
+
if (fuzzyNumbersEqual(prevSize, collapsedSizePercentage)) {
|
|
370
|
+
const localDelta = minSizePercentage - prevSize;
|
|
371
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
372
|
+
|
|
373
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
374
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
375
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
376
|
+
}
|
|
357
377
|
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
{
|
|
382
|
+
// Check if we should collapse a panel at its minimum size
|
|
383
|
+
const index = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
384
|
+
const constraints = panelConstraints[index];
|
|
385
|
+
//DEBUG.push(`edge case check 2: ${index}`);
|
|
386
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
387
|
+
if (constraints.collapsible) {
|
|
388
|
+
const prevSize = prevLayout[index];
|
|
389
|
+
const {
|
|
390
|
+
collapsedSizePercentage,
|
|
391
|
+
minSizePercentage
|
|
392
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
393
|
+
if (fuzzyNumbersEqual(prevSize, minSizePercentage)) {
|
|
394
|
+
const localDelta = prevSize - collapsedSizePercentage;
|
|
395
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
396
|
+
|
|
397
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
398
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
399
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
358
403
|
}
|
|
359
404
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
405
|
+
//DEBUG.push("");
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
{
|
|
409
|
+
// Pre-calculate max available delta in the opposite direction of our pivot.
|
|
410
|
+
// This will be the maximum amount we're allowed to expand/contract the panels in the primary direction.
|
|
411
|
+
// If this amount is less than the requested delta, adjust the requested delta.
|
|
412
|
+
// If this amount is greater than the requested delta, that's useful information too–
|
|
413
|
+
// as an expanding panel might change from collapsed to min size.
|
|
414
|
+
|
|
415
|
+
const increment = delta < 0 ? 1 : -1;
|
|
416
|
+
let index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
417
|
+
let maxAvailableDelta = 0;
|
|
418
|
+
|
|
419
|
+
//DEBUG.push("pre calc...");
|
|
420
|
+
while (true) {
|
|
421
|
+
const prevSize = prevLayout[index];
|
|
422
|
+
const maxSafeSize = resizePanel({
|
|
423
|
+
groupSizePixels,
|
|
424
|
+
panelConstraints,
|
|
425
|
+
panelIndex: index,
|
|
426
|
+
size: 100
|
|
427
|
+
});
|
|
428
|
+
const delta = maxSafeSize - prevSize;
|
|
429
|
+
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
430
|
+
|
|
431
|
+
maxAvailableDelta += delta;
|
|
432
|
+
index += increment;
|
|
433
|
+
if (index < 0 || index >= panelConstraints.length) {
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
371
436
|
}
|
|
437
|
+
|
|
438
|
+
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
439
|
+
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
440
|
+
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
441
|
+
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
442
|
+
//DEBUG.push("");
|
|
372
443
|
}
|
|
373
444
|
|
|
374
|
-
// Delta added to a panel needs to be subtracted from other panels
|
|
375
|
-
// within the constraints that those panels allow
|
|
376
445
|
{
|
|
446
|
+
// Delta added to a panel needs to be subtracted from other panels (within the constraints that those panels allow).
|
|
447
|
+
|
|
377
448
|
const pivotIndex = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
378
449
|
let index = pivotIndex;
|
|
379
450
|
while (index >= 0 && index < panelConstraints.length) {
|
|
380
451
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
381
452
|
const prevSize = prevLayout[index];
|
|
382
453
|
const unsafeSize = prevSize - deltaRemaining;
|
|
383
|
-
|
|
454
|
+
const safeSize = resizePanel({
|
|
384
455
|
groupSizePixels,
|
|
385
456
|
panelConstraints,
|
|
386
457
|
panelIndex: index,
|
|
@@ -402,13 +473,18 @@ function adjustLayoutByDelta({
|
|
|
402
473
|
}
|
|
403
474
|
}
|
|
404
475
|
}
|
|
476
|
+
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
477
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
478
|
+
//DEBUG.push("");
|
|
405
479
|
|
|
406
480
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
407
481
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
408
482
|
if (fuzzyNumbersEqual(deltaApplied, 0)) {
|
|
483
|
+
//console.log(DEBUG.join("\n"));
|
|
409
484
|
return prevLayout;
|
|
410
485
|
}
|
|
411
486
|
{
|
|
487
|
+
// Now distribute the applied delta to the panels in the other direction
|
|
412
488
|
const pivotIndex = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
413
489
|
const unsafeSize = prevLayout[pivotIndex] + deltaApplied;
|
|
414
490
|
const safeSize = resizePanel({
|
|
@@ -448,29 +524,21 @@ function adjustLayoutByDelta({
|
|
|
448
524
|
index++;
|
|
449
525
|
}
|
|
450
526
|
}
|
|
451
|
-
|
|
452
|
-
// If we can't redistribute, this layout is invalid;
|
|
453
|
-
// There may be an incremental layout that is valid though
|
|
454
|
-
if (!fuzzyNumbersEqual(deltaRemaining, 0)) {
|
|
455
|
-
try {
|
|
456
|
-
return adjustLayoutByDelta({
|
|
457
|
-
delta: delta < 0 ? delta + 1 : delta - 1,
|
|
458
|
-
groupSizePixels,
|
|
459
|
-
layout: prevLayout,
|
|
460
|
-
panelConstraints,
|
|
461
|
-
pivotIndices,
|
|
462
|
-
trigger
|
|
463
|
-
});
|
|
464
|
-
} catch (error) {
|
|
465
|
-
if (error instanceof RangeError) {
|
|
466
|
-
console.error(`Could not apply delta ${delta} to layout`);
|
|
467
|
-
return prevLayout;
|
|
468
|
-
}
|
|
469
|
-
} finally {
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
527
|
}
|
|
473
528
|
}
|
|
529
|
+
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
530
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
531
|
+
//DEBUG.push("");
|
|
532
|
+
|
|
533
|
+
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
534
|
+
deltaApplied = 100 - totalSize;
|
|
535
|
+
//DEBUG.push(`total size: ${totalSize}`);
|
|
536
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
537
|
+
//console.log(DEBUG.join("\n"));
|
|
538
|
+
|
|
539
|
+
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
540
|
+
return prevLayout;
|
|
541
|
+
}
|
|
474
542
|
return nextLayout;
|
|
475
543
|
}
|
|
476
544
|
|
|
@@ -1254,6 +1322,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1254
1322
|
autoSaveId,
|
|
1255
1323
|
children,
|
|
1256
1324
|
className: classNameFromProps = "",
|
|
1325
|
+
dataAttributes,
|
|
1257
1326
|
direction,
|
|
1258
1327
|
forwardedRef,
|
|
1259
1328
|
id: idFromProps,
|
|
@@ -1828,6 +1897,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1828
1897
|
...style,
|
|
1829
1898
|
...styleFromProps
|
|
1830
1899
|
},
|
|
1900
|
+
...dataAttributes,
|
|
1831
1901
|
// CSS selectors
|
|
1832
1902
|
"data-panel-group": "",
|
|
1833
1903
|
"data-panel-group-direction": direction,
|
|
@@ -1915,6 +1985,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1915
1985
|
function PanelResizeHandle({
|
|
1916
1986
|
children = null,
|
|
1917
1987
|
className: classNameFromProps = "",
|
|
1988
|
+
dataAttributes,
|
|
1918
1989
|
disabled = false,
|
|
1919
1990
|
id: idFromProps = null,
|
|
1920
1991
|
onDragging,
|
|
@@ -2037,6 +2108,7 @@ function PanelResizeHandle({
|
|
|
2037
2108
|
...styleFromProps
|
|
2038
2109
|
},
|
|
2039
2110
|
tabIndex: 0,
|
|
2111
|
+
...dataAttributes,
|
|
2040
2112
|
// CSS selectors
|
|
2041
2113
|
"data-panel-group-direction": direction,
|
|
2042
2114
|
"data-panel-group-id": groupId,
|
|
@@ -44,6 +44,7 @@ function PanelWithForwardedRef({
|
|
|
44
44
|
collapsedSizePercentage,
|
|
45
45
|
collapsedSizePixels,
|
|
46
46
|
collapsible,
|
|
47
|
+
dataAttributes,
|
|
47
48
|
defaultSizePercentage,
|
|
48
49
|
defaultSizePixels,
|
|
49
50
|
forwardedRef,
|
|
@@ -157,6 +158,7 @@ function PanelWithForwardedRef({
|
|
|
157
158
|
...style,
|
|
158
159
|
...styleFromProps
|
|
159
160
|
},
|
|
161
|
+
...dataAttributes,
|
|
160
162
|
// CSS selectors
|
|
161
163
|
"data-panel": "",
|
|
162
164
|
"data-panel-id": panelId,
|
|
@@ -294,7 +296,13 @@ function resizePanel({
|
|
|
294
296
|
if (minSizePercentage != null) {
|
|
295
297
|
if (fuzzyCompareNumbers(size, minSizePercentage) < 0) {
|
|
296
298
|
if (collapsible) {
|
|
297
|
-
|
|
299
|
+
// Collapsible panels should snap closed or open only once they cross the halfway point between collapsed and min size.
|
|
300
|
+
const halfwayPoint = (collapsedSizePercentage + minSizePercentage) / 2;
|
|
301
|
+
if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
|
|
302
|
+
size = collapsedSizePercentage;
|
|
303
|
+
} else {
|
|
304
|
+
size = minSizePercentage;
|
|
305
|
+
}
|
|
298
306
|
} else {
|
|
299
307
|
size = minSizePercentage;
|
|
300
308
|
}
|
|
@@ -321,60 +329,123 @@ function adjustLayoutByDelta({
|
|
|
321
329
|
const nextLayout = [...prevLayout];
|
|
322
330
|
let deltaApplied = 0;
|
|
323
331
|
|
|
332
|
+
//const DEBUG = [];
|
|
333
|
+
//DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
|
|
334
|
+
//DEBUG.push(` delta: ${delta}`);
|
|
335
|
+
//DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
336
|
+
//DEBUG.push(` trigger: ${trigger}`);
|
|
337
|
+
//DEBUG.push("");
|
|
338
|
+
|
|
324
339
|
// A resizing panel affects the panels before or after it.
|
|
325
340
|
//
|
|
326
|
-
// A negative delta means the panel immediately after the
|
|
341
|
+
// A negative delta means the panel(s) immediately after the resize handle should grow/expand by decreasing its offset.
|
|
327
342
|
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
328
343
|
//
|
|
329
|
-
// A positive delta means the panel immediately before the
|
|
330
|
-
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the
|
|
344
|
+
// A positive delta means the panel(s) immediately before the resize handle should "expand".
|
|
345
|
+
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resize handle.
|
|
331
346
|
|
|
332
|
-
// First, check the panel we're pivoting around;
|
|
333
|
-
// We should only expand or contract by as much as its constraints allow
|
|
334
347
|
{
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
348
|
+
// If this is a resize triggered by a keyboard event, our logic for expanding/collapsing is different.
|
|
349
|
+
// We no longer check the halfway threshold because this may prevent the panel from expanding at all.
|
|
350
|
+
if (trigger === "keyboard") {
|
|
351
|
+
{
|
|
352
|
+
// Check if we should expand a collapsed panel
|
|
353
|
+
const index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
354
|
+
const constraints = panelConstraints[index];
|
|
355
|
+
//DEBUG.push(`edge case check 1: ${index}`);
|
|
356
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
357
|
+
if (constraints.collapsible) {
|
|
358
|
+
const prevSize = prevLayout[index];
|
|
359
|
+
const {
|
|
360
|
+
collapsedSizePercentage,
|
|
361
|
+
minSizePercentage
|
|
362
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
363
|
+
if (fuzzyNumbersEqual(prevSize, collapsedSizePercentage)) {
|
|
364
|
+
const localDelta = minSizePercentage - prevSize;
|
|
365
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
366
|
+
|
|
367
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
368
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
369
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
{
|
|
376
|
+
// Check if we should collapse a panel at its minimum size
|
|
377
|
+
const index = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
378
|
+
const constraints = panelConstraints[index];
|
|
379
|
+
//DEBUG.push(`edge case check 2: ${index}`);
|
|
380
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
381
|
+
if (constraints.collapsible) {
|
|
382
|
+
const prevSize = prevLayout[index];
|
|
383
|
+
const {
|
|
384
|
+
collapsedSizePercentage,
|
|
385
|
+
minSizePercentage
|
|
386
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
387
|
+
if (fuzzyNumbersEqual(prevSize, minSizePercentage)) {
|
|
388
|
+
const localDelta = prevSize - collapsedSizePercentage;
|
|
389
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
390
|
+
|
|
391
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
392
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
393
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
394
|
+
}
|
|
351
395
|
}
|
|
396
|
+
}
|
|
352
397
|
}
|
|
353
398
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
399
|
+
//DEBUG.push("");
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
{
|
|
403
|
+
// Pre-calculate max available delta in the opposite direction of our pivot.
|
|
404
|
+
// This will be the maximum amount we're allowed to expand/contract the panels in the primary direction.
|
|
405
|
+
// If this amount is less than the requested delta, adjust the requested delta.
|
|
406
|
+
// If this amount is greater than the requested delta, that's useful information too–
|
|
407
|
+
// as an expanding panel might change from collapsed to min size.
|
|
408
|
+
|
|
409
|
+
const increment = delta < 0 ? 1 : -1;
|
|
410
|
+
let index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
411
|
+
let maxAvailableDelta = 0;
|
|
412
|
+
|
|
413
|
+
//DEBUG.push("pre calc...");
|
|
414
|
+
while (true) {
|
|
415
|
+
const prevSize = prevLayout[index];
|
|
416
|
+
const maxSafeSize = resizePanel({
|
|
417
|
+
groupSizePixels,
|
|
418
|
+
panelConstraints,
|
|
419
|
+
panelIndex: index,
|
|
420
|
+
size: 100
|
|
421
|
+
});
|
|
422
|
+
const delta = maxSafeSize - prevSize;
|
|
423
|
+
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
424
|
+
|
|
425
|
+
maxAvailableDelta += delta;
|
|
426
|
+
index += increment;
|
|
427
|
+
if (index < 0 || index >= panelConstraints.length) {
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
365
430
|
}
|
|
431
|
+
|
|
432
|
+
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
433
|
+
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
434
|
+
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
435
|
+
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
436
|
+
//DEBUG.push("");
|
|
366
437
|
}
|
|
367
438
|
|
|
368
|
-
// Delta added to a panel needs to be subtracted from other panels
|
|
369
|
-
// within the constraints that those panels allow
|
|
370
439
|
{
|
|
440
|
+
// Delta added to a panel needs to be subtracted from other panels (within the constraints that those panels allow).
|
|
441
|
+
|
|
371
442
|
const pivotIndex = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
372
443
|
let index = pivotIndex;
|
|
373
444
|
while (index >= 0 && index < panelConstraints.length) {
|
|
374
445
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
375
446
|
const prevSize = prevLayout[index];
|
|
376
447
|
const unsafeSize = prevSize - deltaRemaining;
|
|
377
|
-
|
|
448
|
+
const safeSize = resizePanel({
|
|
378
449
|
groupSizePixels,
|
|
379
450
|
panelConstraints,
|
|
380
451
|
panelIndex: index,
|
|
@@ -396,13 +467,18 @@ function adjustLayoutByDelta({
|
|
|
396
467
|
}
|
|
397
468
|
}
|
|
398
469
|
}
|
|
470
|
+
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
471
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
472
|
+
//DEBUG.push("");
|
|
399
473
|
|
|
400
474
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
401
475
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
402
476
|
if (fuzzyNumbersEqual(deltaApplied, 0)) {
|
|
477
|
+
//console.log(DEBUG.join("\n"));
|
|
403
478
|
return prevLayout;
|
|
404
479
|
}
|
|
405
480
|
{
|
|
481
|
+
// Now distribute the applied delta to the panels in the other direction
|
|
406
482
|
const pivotIndex = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
407
483
|
const unsafeSize = prevLayout[pivotIndex] + deltaApplied;
|
|
408
484
|
const safeSize = resizePanel({
|
|
@@ -442,29 +518,21 @@ function adjustLayoutByDelta({
|
|
|
442
518
|
index++;
|
|
443
519
|
}
|
|
444
520
|
}
|
|
445
|
-
|
|
446
|
-
// If we can't redistribute, this layout is invalid;
|
|
447
|
-
// There may be an incremental layout that is valid though
|
|
448
|
-
if (!fuzzyNumbersEqual(deltaRemaining, 0)) {
|
|
449
|
-
try {
|
|
450
|
-
return adjustLayoutByDelta({
|
|
451
|
-
delta: delta < 0 ? delta + 1 : delta - 1,
|
|
452
|
-
groupSizePixels,
|
|
453
|
-
layout: prevLayout,
|
|
454
|
-
panelConstraints,
|
|
455
|
-
pivotIndices,
|
|
456
|
-
trigger
|
|
457
|
-
});
|
|
458
|
-
} catch (error) {
|
|
459
|
-
if (error instanceof RangeError) {
|
|
460
|
-
console.error(`Could not apply delta ${delta} to layout`);
|
|
461
|
-
return prevLayout;
|
|
462
|
-
}
|
|
463
|
-
} finally {
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
521
|
}
|
|
467
522
|
}
|
|
523
|
+
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
524
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
525
|
+
//DEBUG.push("");
|
|
526
|
+
|
|
527
|
+
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
528
|
+
deltaApplied = 100 - totalSize;
|
|
529
|
+
//DEBUG.push(`total size: ${totalSize}`);
|
|
530
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
531
|
+
//console.log(DEBUG.join("\n"));
|
|
532
|
+
|
|
533
|
+
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
534
|
+
return prevLayout;
|
|
535
|
+
}
|
|
468
536
|
return nextLayout;
|
|
469
537
|
}
|
|
470
538
|
|
|
@@ -1161,6 +1229,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1161
1229
|
autoSaveId,
|
|
1162
1230
|
children,
|
|
1163
1231
|
className: classNameFromProps = "",
|
|
1232
|
+
dataAttributes,
|
|
1164
1233
|
direction,
|
|
1165
1234
|
forwardedRef,
|
|
1166
1235
|
id: idFromProps,
|
|
@@ -1693,6 +1762,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1693
1762
|
...style,
|
|
1694
1763
|
...styleFromProps
|
|
1695
1764
|
},
|
|
1765
|
+
...dataAttributes,
|
|
1696
1766
|
// CSS selectors
|
|
1697
1767
|
"data-panel-group": "",
|
|
1698
1768
|
"data-panel-group-direction": direction,
|
|
@@ -1780,6 +1850,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1780
1850
|
function PanelResizeHandle({
|
|
1781
1851
|
children = null,
|
|
1782
1852
|
className: classNameFromProps = "",
|
|
1853
|
+
dataAttributes,
|
|
1783
1854
|
disabled = false,
|
|
1784
1855
|
id: idFromProps = null,
|
|
1785
1856
|
onDragging,
|
|
@@ -1902,6 +1973,7 @@ function PanelResizeHandle({
|
|
|
1902
1973
|
...styleFromProps
|
|
1903
1974
|
},
|
|
1904
1975
|
tabIndex: 0,
|
|
1976
|
+
...dataAttributes,
|
|
1905
1977
|
// CSS selectors
|
|
1906
1978
|
"data-panel-group-direction": direction,
|
|
1907
1979
|
"data-panel-group-id": groupId,
|