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
|
@@ -66,6 +66,7 @@ function PanelWithForwardedRef({
|
|
|
66
66
|
collapsedSizePercentage,
|
|
67
67
|
collapsedSizePixels,
|
|
68
68
|
collapsible,
|
|
69
|
+
dataAttributes,
|
|
69
70
|
defaultSizePercentage,
|
|
70
71
|
defaultSizePixels,
|
|
71
72
|
forwardedRef,
|
|
@@ -162,6 +163,7 @@ function PanelWithForwardedRef({
|
|
|
162
163
|
...style,
|
|
163
164
|
...styleFromProps
|
|
164
165
|
},
|
|
166
|
+
...dataAttributes,
|
|
165
167
|
// CSS selectors
|
|
166
168
|
"data-panel": "",
|
|
167
169
|
"data-panel-id": panelId,
|
|
@@ -299,7 +301,13 @@ function resizePanel({
|
|
|
299
301
|
if (minSizePercentage != null) {
|
|
300
302
|
if (fuzzyCompareNumbers(size, minSizePercentage) < 0) {
|
|
301
303
|
if (collapsible) {
|
|
302
|
-
|
|
304
|
+
// Collapsible panels should snap closed or open only once they cross the halfway point between collapsed and min size.
|
|
305
|
+
const halfwayPoint = (collapsedSizePercentage + minSizePercentage) / 2;
|
|
306
|
+
if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
|
|
307
|
+
size = collapsedSizePercentage;
|
|
308
|
+
} else {
|
|
309
|
+
size = minSizePercentage;
|
|
310
|
+
}
|
|
303
311
|
} else {
|
|
304
312
|
size = minSizePercentage;
|
|
305
313
|
}
|
|
@@ -326,60 +334,123 @@ function adjustLayoutByDelta({
|
|
|
326
334
|
const nextLayout = [...prevLayout];
|
|
327
335
|
let deltaApplied = 0;
|
|
328
336
|
|
|
337
|
+
//const DEBUG = [];
|
|
338
|
+
//DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
|
|
339
|
+
//DEBUG.push(` delta: ${delta}`);
|
|
340
|
+
//DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
341
|
+
//DEBUG.push(` trigger: ${trigger}`);
|
|
342
|
+
//DEBUG.push("");
|
|
343
|
+
|
|
329
344
|
// A resizing panel affects the panels before or after it.
|
|
330
345
|
//
|
|
331
|
-
// A negative delta means the panel immediately after the
|
|
346
|
+
// A negative delta means the panel(s) immediately after the resize handle should grow/expand by decreasing its offset.
|
|
332
347
|
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
333
348
|
//
|
|
334
|
-
// A positive delta means the panel immediately before the
|
|
335
|
-
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the
|
|
349
|
+
// A positive delta means the panel(s) immediately before the resize handle should "expand".
|
|
350
|
+
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resize handle.
|
|
336
351
|
|
|
337
|
-
// First, check the panel we're pivoting around;
|
|
338
|
-
// We should only expand or contract by as much as its constraints allow
|
|
339
352
|
{
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
353
|
+
// If this is a resize triggered by a keyboard event, our logic for expanding/collapsing is different.
|
|
354
|
+
// We no longer check the halfway threshold because this may prevent the panel from expanding at all.
|
|
355
|
+
if (trigger === "keyboard") {
|
|
356
|
+
{
|
|
357
|
+
// Check if we should expand a collapsed panel
|
|
358
|
+
const index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
359
|
+
const constraints = panelConstraints[index];
|
|
360
|
+
//DEBUG.push(`edge case check 1: ${index}`);
|
|
361
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
362
|
+
if (constraints.collapsible) {
|
|
363
|
+
const prevSize = prevLayout[index];
|
|
364
|
+
const {
|
|
365
|
+
collapsedSizePercentage,
|
|
366
|
+
minSizePercentage
|
|
367
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
368
|
+
if (fuzzyNumbersEqual(prevSize, collapsedSizePercentage)) {
|
|
369
|
+
const localDelta = minSizePercentage - prevSize;
|
|
370
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
371
|
+
|
|
372
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
373
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
374
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
{
|
|
381
|
+
// Check if we should collapse a panel at its minimum size
|
|
382
|
+
const index = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
383
|
+
const constraints = panelConstraints[index];
|
|
384
|
+
//DEBUG.push(`edge case check 2: ${index}`);
|
|
385
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
386
|
+
if (constraints.collapsible) {
|
|
387
|
+
const prevSize = prevLayout[index];
|
|
388
|
+
const {
|
|
389
|
+
collapsedSizePercentage,
|
|
390
|
+
minSizePercentage
|
|
391
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
392
|
+
if (fuzzyNumbersEqual(prevSize, minSizePercentage)) {
|
|
393
|
+
const localDelta = prevSize - collapsedSizePercentage;
|
|
394
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
395
|
+
|
|
396
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
397
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
398
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
399
|
+
}
|
|
356
400
|
}
|
|
401
|
+
}
|
|
357
402
|
}
|
|
358
403
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
404
|
+
//DEBUG.push("");
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
{
|
|
408
|
+
// Pre-calculate max available delta in the opposite direction of our pivot.
|
|
409
|
+
// This will be the maximum amount we're allowed to expand/contract the panels in the primary direction.
|
|
410
|
+
// If this amount is less than the requested delta, adjust the requested delta.
|
|
411
|
+
// If this amount is greater than the requested delta, that's useful information too–
|
|
412
|
+
// as an expanding panel might change from collapsed to min size.
|
|
413
|
+
|
|
414
|
+
const increment = delta < 0 ? 1 : -1;
|
|
415
|
+
let index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
416
|
+
let maxAvailableDelta = 0;
|
|
417
|
+
|
|
418
|
+
//DEBUG.push("pre calc...");
|
|
419
|
+
while (true) {
|
|
420
|
+
const prevSize = prevLayout[index];
|
|
421
|
+
const maxSafeSize = resizePanel({
|
|
422
|
+
groupSizePixels,
|
|
423
|
+
panelConstraints,
|
|
424
|
+
panelIndex: index,
|
|
425
|
+
size: 100
|
|
426
|
+
});
|
|
427
|
+
const delta = maxSafeSize - prevSize;
|
|
428
|
+
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
429
|
+
|
|
430
|
+
maxAvailableDelta += delta;
|
|
431
|
+
index += increment;
|
|
432
|
+
if (index < 0 || index >= panelConstraints.length) {
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
370
435
|
}
|
|
436
|
+
|
|
437
|
+
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
438
|
+
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
439
|
+
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
440
|
+
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
441
|
+
//DEBUG.push("");
|
|
371
442
|
}
|
|
372
443
|
|
|
373
|
-
// Delta added to a panel needs to be subtracted from other panels
|
|
374
|
-
// within the constraints that those panels allow
|
|
375
444
|
{
|
|
445
|
+
// Delta added to a panel needs to be subtracted from other panels (within the constraints that those panels allow).
|
|
446
|
+
|
|
376
447
|
const pivotIndex = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
377
448
|
let index = pivotIndex;
|
|
378
449
|
while (index >= 0 && index < panelConstraints.length) {
|
|
379
450
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
380
451
|
const prevSize = prevLayout[index];
|
|
381
452
|
const unsafeSize = prevSize - deltaRemaining;
|
|
382
|
-
|
|
453
|
+
const safeSize = resizePanel({
|
|
383
454
|
groupSizePixels,
|
|
384
455
|
panelConstraints,
|
|
385
456
|
panelIndex: index,
|
|
@@ -401,13 +472,18 @@ function adjustLayoutByDelta({
|
|
|
401
472
|
}
|
|
402
473
|
}
|
|
403
474
|
}
|
|
475
|
+
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
476
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
477
|
+
//DEBUG.push("");
|
|
404
478
|
|
|
405
479
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
406
480
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
407
481
|
if (fuzzyNumbersEqual(deltaApplied, 0)) {
|
|
482
|
+
//console.log(DEBUG.join("\n"));
|
|
408
483
|
return prevLayout;
|
|
409
484
|
}
|
|
410
485
|
{
|
|
486
|
+
// Now distribute the applied delta to the panels in the other direction
|
|
411
487
|
const pivotIndex = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
412
488
|
const unsafeSize = prevLayout[pivotIndex] + deltaApplied;
|
|
413
489
|
const safeSize = resizePanel({
|
|
@@ -447,29 +523,21 @@ function adjustLayoutByDelta({
|
|
|
447
523
|
index++;
|
|
448
524
|
}
|
|
449
525
|
}
|
|
450
|
-
|
|
451
|
-
// If we can't redistribute, this layout is invalid;
|
|
452
|
-
// There may be an incremental layout that is valid though
|
|
453
|
-
if (!fuzzyNumbersEqual(deltaRemaining, 0)) {
|
|
454
|
-
try {
|
|
455
|
-
return adjustLayoutByDelta({
|
|
456
|
-
delta: delta < 0 ? delta + 1 : delta - 1,
|
|
457
|
-
groupSizePixels,
|
|
458
|
-
layout: prevLayout,
|
|
459
|
-
panelConstraints,
|
|
460
|
-
pivotIndices,
|
|
461
|
-
trigger
|
|
462
|
-
});
|
|
463
|
-
} catch (error) {
|
|
464
|
-
if (error instanceof RangeError) {
|
|
465
|
-
console.error(`Could not apply delta ${delta} to layout`);
|
|
466
|
-
return prevLayout;
|
|
467
|
-
}
|
|
468
|
-
} finally {
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
526
|
}
|
|
472
527
|
}
|
|
528
|
+
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
529
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
530
|
+
//DEBUG.push("");
|
|
531
|
+
|
|
532
|
+
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
533
|
+
deltaApplied = 100 - totalSize;
|
|
534
|
+
//DEBUG.push(`total size: ${totalSize}`);
|
|
535
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
536
|
+
//console.log(DEBUG.join("\n"));
|
|
537
|
+
|
|
538
|
+
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
539
|
+
return prevLayout;
|
|
540
|
+
}
|
|
473
541
|
return nextLayout;
|
|
474
542
|
}
|
|
475
543
|
|
|
@@ -1110,6 +1178,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1110
1178
|
autoSaveId,
|
|
1111
1179
|
children,
|
|
1112
1180
|
className: classNameFromProps = "",
|
|
1181
|
+
dataAttributes,
|
|
1113
1182
|
direction,
|
|
1114
1183
|
forwardedRef,
|
|
1115
1184
|
id: idFromProps,
|
|
@@ -1586,6 +1655,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1586
1655
|
...style,
|
|
1587
1656
|
...styleFromProps
|
|
1588
1657
|
},
|
|
1658
|
+
...dataAttributes,
|
|
1589
1659
|
// CSS selectors
|
|
1590
1660
|
"data-panel-group": "",
|
|
1591
1661
|
"data-panel-group-direction": direction,
|
|
@@ -1673,6 +1743,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1673
1743
|
function PanelResizeHandle({
|
|
1674
1744
|
children = null,
|
|
1675
1745
|
className: classNameFromProps = "",
|
|
1746
|
+
dataAttributes,
|
|
1676
1747
|
disabled = false,
|
|
1677
1748
|
id: idFromProps = null,
|
|
1678
1749
|
onDragging,
|
|
@@ -1795,6 +1866,7 @@ function PanelResizeHandle({
|
|
|
1795
1866
|
...styleFromProps
|
|
1796
1867
|
},
|
|
1797
1868
|
tabIndex: 0,
|
|
1869
|
+
...dataAttributes,
|
|
1798
1870
|
// CSS selectors
|
|
1799
1871
|
"data-panel-group-direction": direction,
|
|
1800
1872
|
"data-panel-group-id": groupId,
|
|
@@ -42,6 +42,7 @@ function PanelWithForwardedRef({
|
|
|
42
42
|
collapsedSizePercentage,
|
|
43
43
|
collapsedSizePixels,
|
|
44
44
|
collapsible,
|
|
45
|
+
dataAttributes,
|
|
45
46
|
defaultSizePercentage,
|
|
46
47
|
defaultSizePixels,
|
|
47
48
|
forwardedRef,
|
|
@@ -138,6 +139,7 @@ function PanelWithForwardedRef({
|
|
|
138
139
|
...style,
|
|
139
140
|
...styleFromProps
|
|
140
141
|
},
|
|
142
|
+
...dataAttributes,
|
|
141
143
|
// CSS selectors
|
|
142
144
|
"data-panel": "",
|
|
143
145
|
"data-panel-id": panelId,
|
|
@@ -275,7 +277,13 @@ function resizePanel({
|
|
|
275
277
|
if (minSizePercentage != null) {
|
|
276
278
|
if (fuzzyCompareNumbers(size, minSizePercentage) < 0) {
|
|
277
279
|
if (collapsible) {
|
|
278
|
-
|
|
280
|
+
// Collapsible panels should snap closed or open only once they cross the halfway point between collapsed and min size.
|
|
281
|
+
const halfwayPoint = (collapsedSizePercentage + minSizePercentage) / 2;
|
|
282
|
+
if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
|
|
283
|
+
size = collapsedSizePercentage;
|
|
284
|
+
} else {
|
|
285
|
+
size = minSizePercentage;
|
|
286
|
+
}
|
|
279
287
|
} else {
|
|
280
288
|
size = minSizePercentage;
|
|
281
289
|
}
|
|
@@ -302,60 +310,123 @@ function adjustLayoutByDelta({
|
|
|
302
310
|
const nextLayout = [...prevLayout];
|
|
303
311
|
let deltaApplied = 0;
|
|
304
312
|
|
|
313
|
+
//const DEBUG = [];
|
|
314
|
+
//DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
|
|
315
|
+
//DEBUG.push(` delta: ${delta}`);
|
|
316
|
+
//DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
317
|
+
//DEBUG.push(` trigger: ${trigger}`);
|
|
318
|
+
//DEBUG.push("");
|
|
319
|
+
|
|
305
320
|
// A resizing panel affects the panels before or after it.
|
|
306
321
|
//
|
|
307
|
-
// A negative delta means the panel immediately after the
|
|
322
|
+
// A negative delta means the panel(s) immediately after the resize handle should grow/expand by decreasing its offset.
|
|
308
323
|
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
309
324
|
//
|
|
310
|
-
// A positive delta means the panel immediately before the
|
|
311
|
-
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the
|
|
325
|
+
// A positive delta means the panel(s) immediately before the resize handle should "expand".
|
|
326
|
+
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resize handle.
|
|
312
327
|
|
|
313
|
-
// First, check the panel we're pivoting around;
|
|
314
|
-
// We should only expand or contract by as much as its constraints allow
|
|
315
328
|
{
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
329
|
+
// If this is a resize triggered by a keyboard event, our logic for expanding/collapsing is different.
|
|
330
|
+
// We no longer check the halfway threshold because this may prevent the panel from expanding at all.
|
|
331
|
+
if (trigger === "keyboard") {
|
|
332
|
+
{
|
|
333
|
+
// Check if we should expand a collapsed panel
|
|
334
|
+
const index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
335
|
+
const constraints = panelConstraints[index];
|
|
336
|
+
//DEBUG.push(`edge case check 1: ${index}`);
|
|
337
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
338
|
+
if (constraints.collapsible) {
|
|
339
|
+
const prevSize = prevLayout[index];
|
|
340
|
+
const {
|
|
341
|
+
collapsedSizePercentage,
|
|
342
|
+
minSizePercentage
|
|
343
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
344
|
+
if (fuzzyNumbersEqual(prevSize, collapsedSizePercentage)) {
|
|
345
|
+
const localDelta = minSizePercentage - prevSize;
|
|
346
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
347
|
+
|
|
348
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
349
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
350
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
{
|
|
357
|
+
// Check if we should collapse a panel at its minimum size
|
|
358
|
+
const index = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
359
|
+
const constraints = panelConstraints[index];
|
|
360
|
+
//DEBUG.push(`edge case check 2: ${index}`);
|
|
361
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
362
|
+
if (constraints.collapsible) {
|
|
363
|
+
const prevSize = prevLayout[index];
|
|
364
|
+
const {
|
|
365
|
+
collapsedSizePercentage,
|
|
366
|
+
minSizePercentage
|
|
367
|
+
} = computePercentagePanelConstraints(panelConstraints, index, groupSizePixels);
|
|
368
|
+
if (fuzzyNumbersEqual(prevSize, minSizePercentage)) {
|
|
369
|
+
const localDelta = prevSize - collapsedSizePercentage;
|
|
370
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
371
|
+
|
|
372
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
373
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
374
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
375
|
+
}
|
|
332
376
|
}
|
|
377
|
+
}
|
|
333
378
|
}
|
|
334
379
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
380
|
+
//DEBUG.push("");
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
{
|
|
384
|
+
// Pre-calculate max available delta in the opposite direction of our pivot.
|
|
385
|
+
// This will be the maximum amount we're allowed to expand/contract the panels in the primary direction.
|
|
386
|
+
// If this amount is less than the requested delta, adjust the requested delta.
|
|
387
|
+
// If this amount is greater than the requested delta, that's useful information too–
|
|
388
|
+
// as an expanding panel might change from collapsed to min size.
|
|
389
|
+
|
|
390
|
+
const increment = delta < 0 ? 1 : -1;
|
|
391
|
+
let index = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
392
|
+
let maxAvailableDelta = 0;
|
|
393
|
+
|
|
394
|
+
//DEBUG.push("pre calc...");
|
|
395
|
+
while (true) {
|
|
396
|
+
const prevSize = prevLayout[index];
|
|
397
|
+
const maxSafeSize = resizePanel({
|
|
398
|
+
groupSizePixels,
|
|
399
|
+
panelConstraints,
|
|
400
|
+
panelIndex: index,
|
|
401
|
+
size: 100
|
|
402
|
+
});
|
|
403
|
+
const delta = maxSafeSize - prevSize;
|
|
404
|
+
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
405
|
+
|
|
406
|
+
maxAvailableDelta += delta;
|
|
407
|
+
index += increment;
|
|
408
|
+
if (index < 0 || index >= panelConstraints.length) {
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
346
411
|
}
|
|
412
|
+
|
|
413
|
+
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
414
|
+
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
415
|
+
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
416
|
+
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
417
|
+
//DEBUG.push("");
|
|
347
418
|
}
|
|
348
419
|
|
|
349
|
-
// Delta added to a panel needs to be subtracted from other panels
|
|
350
|
-
// within the constraints that those panels allow
|
|
351
420
|
{
|
|
421
|
+
// Delta added to a panel needs to be subtracted from other panels (within the constraints that those panels allow).
|
|
422
|
+
|
|
352
423
|
const pivotIndex = delta < 0 ? pivotIndices[0] : pivotIndices[1];
|
|
353
424
|
let index = pivotIndex;
|
|
354
425
|
while (index >= 0 && index < panelConstraints.length) {
|
|
355
426
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
356
427
|
const prevSize = prevLayout[index];
|
|
357
428
|
const unsafeSize = prevSize - deltaRemaining;
|
|
358
|
-
|
|
429
|
+
const safeSize = resizePanel({
|
|
359
430
|
groupSizePixels,
|
|
360
431
|
panelConstraints,
|
|
361
432
|
panelIndex: index,
|
|
@@ -377,13 +448,18 @@ function adjustLayoutByDelta({
|
|
|
377
448
|
}
|
|
378
449
|
}
|
|
379
450
|
}
|
|
451
|
+
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
452
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
453
|
+
//DEBUG.push("");
|
|
380
454
|
|
|
381
455
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
382
456
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
383
457
|
if (fuzzyNumbersEqual(deltaApplied, 0)) {
|
|
458
|
+
//console.log(DEBUG.join("\n"));
|
|
384
459
|
return prevLayout;
|
|
385
460
|
}
|
|
386
461
|
{
|
|
462
|
+
// Now distribute the applied delta to the panels in the other direction
|
|
387
463
|
const pivotIndex = delta < 0 ? pivotIndices[1] : pivotIndices[0];
|
|
388
464
|
const unsafeSize = prevLayout[pivotIndex] + deltaApplied;
|
|
389
465
|
const safeSize = resizePanel({
|
|
@@ -423,29 +499,21 @@ function adjustLayoutByDelta({
|
|
|
423
499
|
index++;
|
|
424
500
|
}
|
|
425
501
|
}
|
|
426
|
-
|
|
427
|
-
// If we can't redistribute, this layout is invalid;
|
|
428
|
-
// There may be an incremental layout that is valid though
|
|
429
|
-
if (!fuzzyNumbersEqual(deltaRemaining, 0)) {
|
|
430
|
-
try {
|
|
431
|
-
return adjustLayoutByDelta({
|
|
432
|
-
delta: delta < 0 ? delta + 1 : delta - 1,
|
|
433
|
-
groupSizePixels,
|
|
434
|
-
layout: prevLayout,
|
|
435
|
-
panelConstraints,
|
|
436
|
-
pivotIndices,
|
|
437
|
-
trigger
|
|
438
|
-
});
|
|
439
|
-
} catch (error) {
|
|
440
|
-
if (error instanceof RangeError) {
|
|
441
|
-
console.error(`Could not apply delta ${delta} to layout`);
|
|
442
|
-
return prevLayout;
|
|
443
|
-
}
|
|
444
|
-
} finally {
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
502
|
}
|
|
448
503
|
}
|
|
504
|
+
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
505
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
506
|
+
//DEBUG.push("");
|
|
507
|
+
|
|
508
|
+
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
509
|
+
deltaApplied = 100 - totalSize;
|
|
510
|
+
//DEBUG.push(`total size: ${totalSize}`);
|
|
511
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
512
|
+
//console.log(DEBUG.join("\n"));
|
|
513
|
+
|
|
514
|
+
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
515
|
+
return prevLayout;
|
|
516
|
+
}
|
|
449
517
|
return nextLayout;
|
|
450
518
|
}
|
|
451
519
|
|
|
@@ -1086,6 +1154,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1086
1154
|
autoSaveId,
|
|
1087
1155
|
children,
|
|
1088
1156
|
className: classNameFromProps = "",
|
|
1157
|
+
dataAttributes,
|
|
1089
1158
|
direction,
|
|
1090
1159
|
forwardedRef,
|
|
1091
1160
|
id: idFromProps,
|
|
@@ -1562,6 +1631,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1562
1631
|
...style,
|
|
1563
1632
|
...styleFromProps
|
|
1564
1633
|
},
|
|
1634
|
+
...dataAttributes,
|
|
1565
1635
|
// CSS selectors
|
|
1566
1636
|
"data-panel-group": "",
|
|
1567
1637
|
"data-panel-group-direction": direction,
|
|
@@ -1649,6 +1719,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1649
1719
|
function PanelResizeHandle({
|
|
1650
1720
|
children = null,
|
|
1651
1721
|
className: classNameFromProps = "",
|
|
1722
|
+
dataAttributes,
|
|
1652
1723
|
disabled = false,
|
|
1653
1724
|
id: idFromProps = null,
|
|
1654
1725
|
onDragging,
|
|
@@ -1771,6 +1842,7 @@ function PanelResizeHandle({
|
|
|
1771
1842
|
...styleFromProps
|
|
1772
1843
|
},
|
|
1773
1844
|
tabIndex: 0,
|
|
1845
|
+
...dataAttributes,
|
|
1774
1846
|
// CSS selectors
|
|
1775
1847
|
"data-panel-group-direction": direction,
|
|
1776
1848
|
"data-panel-group-id": groupId,
|