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
|
@@ -70,6 +70,7 @@ function PanelWithForwardedRef({
|
|
|
70
70
|
collapsedSizePercentage,
|
|
71
71
|
collapsedSizePixels,
|
|
72
72
|
collapsible,
|
|
73
|
+
dataAttributes,
|
|
73
74
|
defaultSizePercentage,
|
|
74
75
|
defaultSizePixels,
|
|
75
76
|
forwardedRef,
|
|
@@ -194,6 +195,7 @@ function PanelWithForwardedRef({
|
|
|
194
195
|
...style,
|
|
195
196
|
...styleFromProps
|
|
196
197
|
},
|
|
198
|
+
...dataAttributes,
|
|
197
199
|
// CSS selectors
|
|
198
200
|
"data-panel": "",
|
|
199
201
|
"data-panel-id": panelId,
|
|
@@ -331,7 +333,13 @@ function resizePanel({
|
|
|
331
333
|
if (minSizePercentage != null) {
|
|
332
334
|
if (fuzzyCompareNumbers(size, minSizePercentage) < 0) {
|
|
333
335
|
if (collapsible) {
|
|
334
|
-
|
|
336
|
+
// Collapsible panels should snap closed or open only once they cross the halfway point between collapsed and min size.
|
|
337
|
+
const halfwayPoint = (collapsedSizePercentage + minSizePercentage) / 2;
|
|
338
|
+
if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
|
|
339
|
+
size = collapsedSizePercentage;
|
|
340
|
+
} else {
|
|
341
|
+
size = minSizePercentage;
|
|
342
|
+
}
|
|
335
343
|
} else {
|
|
336
344
|
size = minSizePercentage;
|
|
337
345
|
}
|
|
@@ -358,60 +366,123 @@ function adjustLayoutByDelta({
|
|
|
358
366
|
const nextLayout = [...prevLayout];
|
|
359
367
|
let deltaApplied = 0;
|
|
360
368
|
|
|
369
|
+
//const DEBUG = [];
|
|
370
|
+
//DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
|
|
371
|
+
//DEBUG.push(` delta: ${delta}`);
|
|
372
|
+
//DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
373
|
+
//DEBUG.push(` trigger: ${trigger}`);
|
|
374
|
+
//DEBUG.push("");
|
|
375
|
+
|
|
361
376
|
// A resizing panel affects the panels before or after it.
|
|
362
377
|
//
|
|
363
|
-
// A negative delta means the panel immediately after the
|
|
378
|
+
// A negative delta means the panel(s) immediately after the resize handle should grow/expand by decreasing its offset.
|
|
364
379
|
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
365
380
|
//
|
|
366
|
-
// A positive delta means the panel immediately before the
|
|
367
|
-
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the
|
|
381
|
+
// A positive delta means the panel(s) immediately before the resize handle should "expand".
|
|
382
|
+
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resize handle.
|
|
368
383
|
|
|
369
|
-
// First, check the panel we're pivoting around;
|
|
370
|
-
// We should only expand or contract by as much as its constraints allow
|
|
371
384
|
{
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
385
|
+
// If this is a resize triggered by a keyboard event, our logic for expanding/collapsing is different.
|
|
386
|
+
// We no longer check the halfway threshold because this may prevent the panel from expanding at all.
|
|
387
|
+
if (trigger === "keyboard") {
|
|
388
|
+
{
|
|
389
|
+
// Check if we should expand a collapsed panel
|
|
390
|
+
const index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
391
|
+
const constraints = panelConstraints[index];
|
|
392
|
+
//DEBUG.push(`edge case check 1: ${index}`);
|
|
393
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
394
|
+
if (constraints.collapsible) {
|
|
395
|
+
const prevSize = prevLayout[index];
|
|
396
|
+
const {
|
|
397
|
+
collapsedSizePercentage,
|
|
398
|
+
minSizePercentage
|
|
399
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
400
|
+
if (fuzzyNumbersEqual(prevSize, collapsedSizePercentage)) {
|
|
401
|
+
const localDelta = minSizePercentage - prevSize;
|
|
402
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
403
|
+
|
|
404
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
405
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
406
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
407
|
+
}
|
|
388
408
|
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
{
|
|
413
|
+
// Check if we should collapse a panel at its minimum size
|
|
414
|
+
const index = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
415
|
+
const constraints = panelConstraints[index];
|
|
416
|
+
//DEBUG.push(`edge case check 2: ${index}`);
|
|
417
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
418
|
+
if (constraints.collapsible) {
|
|
419
|
+
const prevSize = prevLayout[index];
|
|
420
|
+
const {
|
|
421
|
+
collapsedSizePercentage,
|
|
422
|
+
minSizePercentage
|
|
423
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
424
|
+
if (fuzzyNumbersEqual(prevSize, minSizePercentage)) {
|
|
425
|
+
const localDelta = prevSize - collapsedSizePercentage;
|
|
426
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
427
|
+
|
|
428
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
429
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
430
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
389
434
|
}
|
|
390
435
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
436
|
+
//DEBUG.push("");
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
{
|
|
440
|
+
// Pre-calculate max available delta in the opposite direction of our pivot.
|
|
441
|
+
// This will be the maximum amount we're allowed to expand/contract the panels in the primary direction.
|
|
442
|
+
// If this amount is less than the requested delta, adjust the requested delta.
|
|
443
|
+
// If this amount is greater than the requested delta, that's useful information too–
|
|
444
|
+
// as an expanding panel might change from collapsed to min size.
|
|
445
|
+
|
|
446
|
+
const increment = delta < 0 ? 1 : -1;
|
|
447
|
+
let index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
448
|
+
let maxAvailableDelta = 0;
|
|
449
|
+
|
|
450
|
+
//DEBUG.push("pre calc...");
|
|
451
|
+
while (true) {
|
|
452
|
+
const prevSize = prevLayout[index];
|
|
453
|
+
const maxSafeSize = resizePanel({
|
|
454
|
+
groupSizePixels,
|
|
455
|
+
panelConstraints,
|
|
456
|
+
panelIndex: index,
|
|
457
|
+
size: 100
|
|
458
|
+
});
|
|
459
|
+
const delta = maxSafeSize - prevSize;
|
|
460
|
+
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
461
|
+
|
|
462
|
+
maxAvailableDelta += delta;
|
|
463
|
+
index += increment;
|
|
464
|
+
if (index < 0 || index >= panelConstraints.length) {
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
402
467
|
}
|
|
468
|
+
|
|
469
|
+
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
470
|
+
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
471
|
+
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
472
|
+
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
473
|
+
//DEBUG.push("");
|
|
403
474
|
}
|
|
404
475
|
|
|
405
|
-
// Delta added to a panel needs to be subtracted from other panels
|
|
406
|
-
// within the constraints that those panels allow
|
|
407
476
|
{
|
|
477
|
+
// Delta added to a panel needs to be subtracted from other panels (within the constraints that those panels allow).
|
|
478
|
+
|
|
408
479
|
const pivotIndex = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
409
480
|
let index = pivotIndex;
|
|
410
481
|
while (index >= 0 && index < panelConstraints.length) {
|
|
411
482
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
412
483
|
const prevSize = prevLayout[index];
|
|
413
484
|
const unsafeSize = prevSize - deltaRemaining;
|
|
414
|
-
|
|
485
|
+
const safeSize = resizePanel({
|
|
415
486
|
groupSizePixels,
|
|
416
487
|
panelConstraints,
|
|
417
488
|
panelIndex: index,
|
|
@@ -433,13 +504,18 @@ function adjustLayoutByDelta({
|
|
|
433
504
|
}
|
|
434
505
|
}
|
|
435
506
|
}
|
|
507
|
+
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
508
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
509
|
+
//DEBUG.push("");
|
|
436
510
|
|
|
437
511
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
438
512
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
439
513
|
if (fuzzyNumbersEqual(deltaApplied, 0)) {
|
|
514
|
+
//console.log(DEBUG.join("\n"));
|
|
440
515
|
return prevLayout;
|
|
441
516
|
}
|
|
442
517
|
{
|
|
518
|
+
// Now distribute the applied delta to the panels in the other direction
|
|
443
519
|
const pivotIndex = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
444
520
|
const unsafeSize = prevLayout[pivotIndex] + deltaApplied;
|
|
445
521
|
const safeSize = resizePanel({
|
|
@@ -479,29 +555,21 @@ function adjustLayoutByDelta({
|
|
|
479
555
|
index++;
|
|
480
556
|
}
|
|
481
557
|
}
|
|
482
|
-
|
|
483
|
-
// If we can't redistribute, this layout is invalid;
|
|
484
|
-
// There may be an incremental layout that is valid though
|
|
485
|
-
if (!fuzzyNumbersEqual(deltaRemaining, 0)) {
|
|
486
|
-
try {
|
|
487
|
-
return adjustLayoutByDelta({
|
|
488
|
-
delta: delta < 0 ? delta + 1 : delta - 1,
|
|
489
|
-
groupSizePixels,
|
|
490
|
-
layout: prevLayout,
|
|
491
|
-
panelConstraints,
|
|
492
|
-
pivotIndices,
|
|
493
|
-
trigger
|
|
494
|
-
});
|
|
495
|
-
} catch (error) {
|
|
496
|
-
if (error instanceof RangeError) {
|
|
497
|
-
console.error(`Could not apply delta ${delta} to layout`);
|
|
498
|
-
return prevLayout;
|
|
499
|
-
}
|
|
500
|
-
} finally {
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
558
|
}
|
|
504
559
|
}
|
|
560
|
+
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
561
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
562
|
+
//DEBUG.push("");
|
|
563
|
+
|
|
564
|
+
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
565
|
+
deltaApplied = 100 - totalSize;
|
|
566
|
+
//DEBUG.push(`total size: ${totalSize}`);
|
|
567
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
568
|
+
//console.log(DEBUG.join("\n"));
|
|
569
|
+
|
|
570
|
+
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
571
|
+
return prevLayout;
|
|
572
|
+
}
|
|
505
573
|
return nextLayout;
|
|
506
574
|
}
|
|
507
575
|
|
|
@@ -1285,6 +1353,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1285
1353
|
autoSaveId,
|
|
1286
1354
|
children,
|
|
1287
1355
|
className: classNameFromProps = "",
|
|
1356
|
+
dataAttributes,
|
|
1288
1357
|
direction,
|
|
1289
1358
|
forwardedRef,
|
|
1290
1359
|
id: idFromProps,
|
|
@@ -1859,6 +1928,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1859
1928
|
...style,
|
|
1860
1929
|
...styleFromProps
|
|
1861
1930
|
},
|
|
1931
|
+
...dataAttributes,
|
|
1862
1932
|
// CSS selectors
|
|
1863
1933
|
"data-panel-group": "",
|
|
1864
1934
|
"data-panel-group-direction": direction,
|
|
@@ -1946,6 +2016,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1946
2016
|
function PanelResizeHandle({
|
|
1947
2017
|
children = null,
|
|
1948
2018
|
className: classNameFromProps = "",
|
|
2019
|
+
dataAttributes,
|
|
1949
2020
|
disabled = false,
|
|
1950
2021
|
id: idFromProps = null,
|
|
1951
2022
|
onDragging,
|
|
@@ -2068,6 +2139,7 @@ function PanelResizeHandle({
|
|
|
2068
2139
|
...styleFromProps
|
|
2069
2140
|
},
|
|
2070
2141
|
tabIndex: 0,
|
|
2142
|
+
...dataAttributes,
|
|
2071
2143
|
// CSS selectors
|
|
2072
2144
|
"data-panel-group-direction": direction,
|
|
2073
2145
|
"data-panel-group-id": groupId,
|
|
@@ -46,6 +46,7 @@ function PanelWithForwardedRef({
|
|
|
46
46
|
collapsedSizePercentage,
|
|
47
47
|
collapsedSizePixels,
|
|
48
48
|
collapsible,
|
|
49
|
+
dataAttributes,
|
|
49
50
|
defaultSizePercentage,
|
|
50
51
|
defaultSizePixels,
|
|
51
52
|
forwardedRef,
|
|
@@ -170,6 +171,7 @@ function PanelWithForwardedRef({
|
|
|
170
171
|
...style,
|
|
171
172
|
...styleFromProps
|
|
172
173
|
},
|
|
174
|
+
...dataAttributes,
|
|
173
175
|
// CSS selectors
|
|
174
176
|
"data-panel": "",
|
|
175
177
|
"data-panel-id": panelId,
|
|
@@ -307,7 +309,13 @@ function resizePanel({
|
|
|
307
309
|
if (minSizePercentage != null) {
|
|
308
310
|
if (fuzzyCompareNumbers(size, minSizePercentage) < 0) {
|
|
309
311
|
if (collapsible) {
|
|
310
|
-
|
|
312
|
+
// Collapsible panels should snap closed or open only once they cross the halfway point between collapsed and min size.
|
|
313
|
+
const halfwayPoint = (collapsedSizePercentage + minSizePercentage) / 2;
|
|
314
|
+
if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
|
|
315
|
+
size = collapsedSizePercentage;
|
|
316
|
+
} else {
|
|
317
|
+
size = minSizePercentage;
|
|
318
|
+
}
|
|
311
319
|
} else {
|
|
312
320
|
size = minSizePercentage;
|
|
313
321
|
}
|
|
@@ -334,60 +342,123 @@ function adjustLayoutByDelta({
|
|
|
334
342
|
const nextLayout = [...prevLayout];
|
|
335
343
|
let deltaApplied = 0;
|
|
336
344
|
|
|
345
|
+
//const DEBUG = [];
|
|
346
|
+
//DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
|
|
347
|
+
//DEBUG.push(` delta: ${delta}`);
|
|
348
|
+
//DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
349
|
+
//DEBUG.push(` trigger: ${trigger}`);
|
|
350
|
+
//DEBUG.push("");
|
|
351
|
+
|
|
337
352
|
// A resizing panel affects the panels before or after it.
|
|
338
353
|
//
|
|
339
|
-
// A negative delta means the panel immediately after the
|
|
354
|
+
// A negative delta means the panel(s) immediately after the resize handle should grow/expand by decreasing its offset.
|
|
340
355
|
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
341
356
|
//
|
|
342
|
-
// A positive delta means the panel immediately before the
|
|
343
|
-
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the
|
|
357
|
+
// A positive delta means the panel(s) immediately before the resize handle should "expand".
|
|
358
|
+
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resize handle.
|
|
344
359
|
|
|
345
|
-
// First, check the panel we're pivoting around;
|
|
346
|
-
// We should only expand or contract by as much as its constraints allow
|
|
347
360
|
{
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
361
|
+
// If this is a resize triggered by a keyboard event, our logic for expanding/collapsing is different.
|
|
362
|
+
// We no longer check the halfway threshold because this may prevent the panel from expanding at all.
|
|
363
|
+
if (trigger === "keyboard") {
|
|
364
|
+
{
|
|
365
|
+
// Check if we should expand a collapsed panel
|
|
366
|
+
const index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
367
|
+
const constraints = panelConstraints[index];
|
|
368
|
+
//DEBUG.push(`edge case check 1: ${index}`);
|
|
369
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
370
|
+
if (constraints.collapsible) {
|
|
371
|
+
const prevSize = prevLayout[index];
|
|
372
|
+
const {
|
|
373
|
+
collapsedSizePercentage,
|
|
374
|
+
minSizePercentage
|
|
375
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
376
|
+
if (fuzzyNumbersEqual(prevSize, collapsedSizePercentage)) {
|
|
377
|
+
const localDelta = minSizePercentage - prevSize;
|
|
378
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
379
|
+
|
|
380
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
381
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
382
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
383
|
+
}
|
|
364
384
|
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
{
|
|
389
|
+
// Check if we should collapse a panel at its minimum size
|
|
390
|
+
const index = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
391
|
+
const constraints = panelConstraints[index];
|
|
392
|
+
//DEBUG.push(`edge case check 2: ${index}`);
|
|
393
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
394
|
+
if (constraints.collapsible) {
|
|
395
|
+
const prevSize = prevLayout[index];
|
|
396
|
+
const {
|
|
397
|
+
collapsedSizePercentage,
|
|
398
|
+
minSizePercentage
|
|
399
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
400
|
+
if (fuzzyNumbersEqual(prevSize, minSizePercentage)) {
|
|
401
|
+
const localDelta = prevSize - collapsedSizePercentage;
|
|
402
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
403
|
+
|
|
404
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
405
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
406
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
365
410
|
}
|
|
366
411
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
412
|
+
//DEBUG.push("");
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
{
|
|
416
|
+
// Pre-calculate max available delta in the opposite direction of our pivot.
|
|
417
|
+
// This will be the maximum amount we're allowed to expand/contract the panels in the primary direction.
|
|
418
|
+
// If this amount is less than the requested delta, adjust the requested delta.
|
|
419
|
+
// If this amount is greater than the requested delta, that's useful information too–
|
|
420
|
+
// as an expanding panel might change from collapsed to min size.
|
|
421
|
+
|
|
422
|
+
const increment = delta < 0 ? 1 : -1;
|
|
423
|
+
let index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
424
|
+
let maxAvailableDelta = 0;
|
|
425
|
+
|
|
426
|
+
//DEBUG.push("pre calc...");
|
|
427
|
+
while (true) {
|
|
428
|
+
const prevSize = prevLayout[index];
|
|
429
|
+
const maxSafeSize = resizePanel({
|
|
430
|
+
groupSizePixels,
|
|
431
|
+
panelConstraints,
|
|
432
|
+
panelIndex: index,
|
|
433
|
+
size: 100
|
|
434
|
+
});
|
|
435
|
+
const delta = maxSafeSize - prevSize;
|
|
436
|
+
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
437
|
+
|
|
438
|
+
maxAvailableDelta += delta;
|
|
439
|
+
index += increment;
|
|
440
|
+
if (index < 0 || index >= panelConstraints.length) {
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
378
443
|
}
|
|
444
|
+
|
|
445
|
+
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
446
|
+
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
447
|
+
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
448
|
+
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
449
|
+
//DEBUG.push("");
|
|
379
450
|
}
|
|
380
451
|
|
|
381
|
-
// Delta added to a panel needs to be subtracted from other panels
|
|
382
|
-
// within the constraints that those panels allow
|
|
383
452
|
{
|
|
453
|
+
// Delta added to a panel needs to be subtracted from other panels (within the constraints that those panels allow).
|
|
454
|
+
|
|
384
455
|
const pivotIndex = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
385
456
|
let index = pivotIndex;
|
|
386
457
|
while (index >= 0 && index < panelConstraints.length) {
|
|
387
458
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
388
459
|
const prevSize = prevLayout[index];
|
|
389
460
|
const unsafeSize = prevSize - deltaRemaining;
|
|
390
|
-
|
|
461
|
+
const safeSize = resizePanel({
|
|
391
462
|
groupSizePixels,
|
|
392
463
|
panelConstraints,
|
|
393
464
|
panelIndex: index,
|
|
@@ -409,13 +480,18 @@ function adjustLayoutByDelta({
|
|
|
409
480
|
}
|
|
410
481
|
}
|
|
411
482
|
}
|
|
483
|
+
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
484
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
485
|
+
//DEBUG.push("");
|
|
412
486
|
|
|
413
487
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
414
488
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
415
489
|
if (fuzzyNumbersEqual(deltaApplied, 0)) {
|
|
490
|
+
//console.log(DEBUG.join("\n"));
|
|
416
491
|
return prevLayout;
|
|
417
492
|
}
|
|
418
493
|
{
|
|
494
|
+
// Now distribute the applied delta to the panels in the other direction
|
|
419
495
|
const pivotIndex = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
420
496
|
const unsafeSize = prevLayout[pivotIndex] + deltaApplied;
|
|
421
497
|
const safeSize = resizePanel({
|
|
@@ -455,29 +531,21 @@ function adjustLayoutByDelta({
|
|
|
455
531
|
index++;
|
|
456
532
|
}
|
|
457
533
|
}
|
|
458
|
-
|
|
459
|
-
// If we can't redistribute, this layout is invalid;
|
|
460
|
-
// There may be an incremental layout that is valid though
|
|
461
|
-
if (!fuzzyNumbersEqual(deltaRemaining, 0)) {
|
|
462
|
-
try {
|
|
463
|
-
return adjustLayoutByDelta({
|
|
464
|
-
delta: delta < 0 ? delta + 1 : delta - 1,
|
|
465
|
-
groupSizePixels,
|
|
466
|
-
layout: prevLayout,
|
|
467
|
-
panelConstraints,
|
|
468
|
-
pivotIndices,
|
|
469
|
-
trigger
|
|
470
|
-
});
|
|
471
|
-
} catch (error) {
|
|
472
|
-
if (error instanceof RangeError) {
|
|
473
|
-
console.error(`Could not apply delta ${delta} to layout`);
|
|
474
|
-
return prevLayout;
|
|
475
|
-
}
|
|
476
|
-
} finally {
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
534
|
}
|
|
480
535
|
}
|
|
536
|
+
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
537
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
538
|
+
//DEBUG.push("");
|
|
539
|
+
|
|
540
|
+
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
541
|
+
deltaApplied = 100 - totalSize;
|
|
542
|
+
//DEBUG.push(`total size: ${totalSize}`);
|
|
543
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
544
|
+
//console.log(DEBUG.join("\n"));
|
|
545
|
+
|
|
546
|
+
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
547
|
+
return prevLayout;
|
|
548
|
+
}
|
|
481
549
|
return nextLayout;
|
|
482
550
|
}
|
|
483
551
|
|
|
@@ -1261,6 +1329,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1261
1329
|
autoSaveId,
|
|
1262
1330
|
children,
|
|
1263
1331
|
className: classNameFromProps = "",
|
|
1332
|
+
dataAttributes,
|
|
1264
1333
|
direction,
|
|
1265
1334
|
forwardedRef,
|
|
1266
1335
|
id: idFromProps,
|
|
@@ -1835,6 +1904,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1835
1904
|
...style,
|
|
1836
1905
|
...styleFromProps
|
|
1837
1906
|
},
|
|
1907
|
+
...dataAttributes,
|
|
1838
1908
|
// CSS selectors
|
|
1839
1909
|
"data-panel-group": "",
|
|
1840
1910
|
"data-panel-group-direction": direction,
|
|
@@ -1922,6 +1992,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1922
1992
|
function PanelResizeHandle({
|
|
1923
1993
|
children = null,
|
|
1924
1994
|
className: classNameFromProps = "",
|
|
1995
|
+
dataAttributes,
|
|
1925
1996
|
disabled = false,
|
|
1926
1997
|
id: idFromProps = null,
|
|
1927
1998
|
onDragging,
|
|
@@ -2044,6 +2115,7 @@ function PanelResizeHandle({
|
|
|
2044
2115
|
...styleFromProps
|
|
2045
2116
|
},
|
|
2046
2117
|
tabIndex: 0,
|
|
2118
|
+
...dataAttributes,
|
|
2047
2119
|
// CSS selectors
|
|
2048
2120
|
"data-panel-group-direction": direction,
|
|
2049
2121
|
"data-panel-group-id": groupId,
|