react-resizable-panels 2.0.13 → 2.0.15
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 +8 -0
- package/dist/react-resizable-panels.browser.cjs.js +15 -14
- package/dist/react-resizable-panels.browser.development.cjs.js +15 -14
- package/dist/react-resizable-panels.browser.development.esm.js +15 -14
- package/dist/react-resizable-panels.browser.esm.js +15 -14
- package/dist/react-resizable-panels.cjs.js +15 -14
- package/dist/react-resizable-panels.development.cjs.js +15 -14
- package/dist/react-resizable-panels.development.esm.js +15 -14
- package/dist/react-resizable-panels.development.node.cjs.js +15 -14
- package/dist/react-resizable-panels.development.node.esm.js +15 -14
- package/dist/react-resizable-panels.esm.js +15 -14
- package/dist/react-resizable-panels.node.cjs.js +15 -14
- package/dist/react-resizable-panels.node.esm.js +15 -14
- package/package.json +9 -9
- package/src/Panel.test.tsx +153 -0
- package/src/PanelGroup.ts +16 -7
- package/src/utils/callPanelCallbacks.ts +7 -4
- package/src/utils/numbers/fuzzyCompareNumbers.ts +10 -6
- package/.parcel-cache/0e613961dce44a82 +0 -0
- package/.parcel-cache/13776de4870b0ae4.txt +0 -2
- package/.parcel-cache/35c20fb91e350b46 +0 -0
- package/.parcel-cache/data.mdb +0 -0
- package/.parcel-cache/lock.mdb +0 -0
- package/LICENSE +0 -21
package/src/PanelGroup.ts
CHANGED
|
@@ -31,6 +31,10 @@ import { getResizeHandleElement } from "./utils/dom/getResizeHandleElement";
|
|
|
31
31
|
import { isKeyDown, isMouseEvent, isTouchEvent } from "./utils/events";
|
|
32
32
|
import { getResizeEventCursorPosition } from "./utils/events/getResizeEventCursorPosition";
|
|
33
33
|
import { initializeDefaultStorage } from "./utils/initializeDefaultStorage";
|
|
34
|
+
import {
|
|
35
|
+
fuzzyCompareNumbers,
|
|
36
|
+
fuzzyNumbersEqual,
|
|
37
|
+
} from "./utils/numbers/fuzzyCompareNumbers";
|
|
34
38
|
import {
|
|
35
39
|
loadPanelGroupState,
|
|
36
40
|
savePanelGroupState,
|
|
@@ -341,7 +345,7 @@ function PanelGroupWithForwardedRef({
|
|
|
341
345
|
`Panel size not found for panel "${panelData.id}"`
|
|
342
346
|
);
|
|
343
347
|
|
|
344
|
-
if (panelSize
|
|
348
|
+
if (!fuzzyNumbersEqual(panelSize, collapsedSize)) {
|
|
345
349
|
// Store size before collapse;
|
|
346
350
|
// This is the size that gets restored if the expand() API is used.
|
|
347
351
|
panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
|
|
@@ -393,12 +397,12 @@ function PanelGroupWithForwardedRef({
|
|
|
393
397
|
|
|
394
398
|
const {
|
|
395
399
|
collapsedSize = 0,
|
|
396
|
-
panelSize,
|
|
400
|
+
panelSize = 0,
|
|
397
401
|
minSize = 0,
|
|
398
402
|
pivotIndices,
|
|
399
403
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
400
404
|
|
|
401
|
-
if (panelSize
|
|
405
|
+
if (fuzzyNumbersEqual(panelSize, collapsedSize)) {
|
|
402
406
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
403
407
|
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(
|
|
404
408
|
panelData.id
|
|
@@ -484,7 +488,12 @@ function PanelGroupWithForwardedRef({
|
|
|
484
488
|
panelSize,
|
|
485
489
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
486
490
|
|
|
487
|
-
|
|
491
|
+
assert(
|
|
492
|
+
panelSize != null,
|
|
493
|
+
`Panel size not found for panel "${panelData.id}"`
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
return collapsible === true && fuzzyNumbersEqual(panelSize, collapsedSize);
|
|
488
497
|
}, []);
|
|
489
498
|
|
|
490
499
|
// External APIs are safe to memoize via committed values ref
|
|
@@ -502,7 +511,7 @@ function PanelGroupWithForwardedRef({
|
|
|
502
511
|
`Panel size not found for panel "${panelData.id}"`
|
|
503
512
|
);
|
|
504
513
|
|
|
505
|
-
return !collapsible || panelSize >
|
|
514
|
+
return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
|
|
506
515
|
}, []);
|
|
507
516
|
|
|
508
517
|
const registerPanel = useCallback((panelData: PanelData) => {
|
|
@@ -780,9 +789,9 @@ function PanelGroupWithForwardedRef({
|
|
|
780
789
|
if (
|
|
781
790
|
prevCollapsible &&
|
|
782
791
|
nextCollapsible &&
|
|
783
|
-
prevPanelSize
|
|
792
|
+
fuzzyNumbersEqual(prevPanelSize, prevCollapsedSize)
|
|
784
793
|
) {
|
|
785
|
-
if (prevCollapsedSize
|
|
794
|
+
if (!fuzzyNumbersEqual(prevCollapsedSize, nextCollapsedSize)) {
|
|
786
795
|
resizePanel(panelData, nextCollapsedSize);
|
|
787
796
|
} else {
|
|
788
797
|
// Stay collapsed
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PanelData } from "../Panel";
|
|
2
2
|
import { assert } from "./assert";
|
|
3
|
+
import { fuzzyNumbersEqual } from "./numbers/fuzzyCompareNumbers";
|
|
3
4
|
|
|
4
5
|
// Layout should be pre-converted into percentages
|
|
5
6
|
export function callPanelCallbacks(
|
|
@@ -27,16 +28,18 @@ export function callPanelCallbacks(
|
|
|
27
28
|
if (collapsible && (onCollapse || onExpand)) {
|
|
28
29
|
if (
|
|
29
30
|
onExpand &&
|
|
30
|
-
(lastNotifiedSize == null ||
|
|
31
|
-
|
|
31
|
+
(lastNotifiedSize == null ||
|
|
32
|
+
fuzzyNumbersEqual(lastNotifiedSize, collapsedSize)) &&
|
|
33
|
+
!fuzzyNumbersEqual(size, collapsedSize)
|
|
32
34
|
) {
|
|
33
35
|
onExpand();
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
if (
|
|
37
39
|
onCollapse &&
|
|
38
|
-
(lastNotifiedSize == null ||
|
|
39
|
-
|
|
40
|
+
(lastNotifiedSize == null ||
|
|
41
|
+
!fuzzyNumbersEqual(lastNotifiedSize, collapsedSize)) &&
|
|
42
|
+
fuzzyNumbersEqual(size, collapsedSize)
|
|
40
43
|
) {
|
|
41
44
|
onCollapse();
|
|
42
45
|
}
|
|
@@ -5,13 +5,17 @@ export function fuzzyCompareNumbers(
|
|
|
5
5
|
expected: number,
|
|
6
6
|
fractionDigits: number = PRECISION
|
|
7
7
|
): number {
|
|
8
|
-
|
|
9
|
-
expected = parseFloat(expected.toFixed(fractionDigits));
|
|
10
|
-
|
|
11
|
-
const delta = actual - expected;
|
|
12
|
-
if (delta === 0) {
|
|
8
|
+
if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
|
|
13
9
|
return 0;
|
|
14
10
|
} else {
|
|
15
|
-
return
|
|
11
|
+
return actual > expected ? 1 : -1;
|
|
16
12
|
}
|
|
17
13
|
}
|
|
14
|
+
|
|
15
|
+
export function fuzzyNumbersEqual(
|
|
16
|
+
actual: number,
|
|
17
|
+
expected: number,
|
|
18
|
+
fractionDigits: number = PRECISION
|
|
19
|
+
): boolean {
|
|
20
|
+
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
21
|
+
}
|
|
Binary file
|
|
Binary file
|
package/.parcel-cache/data.mdb
DELETED
|
Binary file
|
package/.parcel-cache/lock.mdb
DELETED
|
Binary file
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Brian Vaughn
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|