react-resizable-panels 2.0.14 → 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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.15
4
+
5
+ - Better account for high-precision sizes with `onCollapse` and `onExpand` callbacks (#325)
6
+
3
7
  ## 2.0.14
4
8
 
5
9
  - Better account for high-precision `collapsedSize` values (#325)
@@ -1340,10 +1340,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1340
1340
  onResize(size, lastNotifiedSize);
1341
1341
  }
1342
1342
  if (collapsible && (onCollapse || onExpand)) {
1343
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1343
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1344
1344
  onExpand();
1345
1345
  }
1346
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1346
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1347
1347
  onCollapse();
1348
1348
  }
1349
1349
  }
@@ -1356,10 +1356,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1356
1356
  onResize(size, lastNotifiedSize);
1357
1357
  }
1358
1358
  if (collapsible && (onCollapse || onExpand)) {
1359
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1359
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1360
1360
  onExpand();
1361
1361
  }
1362
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1362
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1363
1363
  onCollapse();
1364
1364
  }
1365
1365
  }
@@ -1332,10 +1332,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1332
1332
  onResize(size, lastNotifiedSize);
1333
1333
  }
1334
1334
  if (collapsible && (onCollapse || onExpand)) {
1335
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1335
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1336
1336
  onExpand();
1337
1337
  }
1338
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1338
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1339
1339
  onCollapse();
1340
1340
  }
1341
1341
  }
@@ -1316,10 +1316,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1316
1316
  onResize(size, lastNotifiedSize);
1317
1317
  }
1318
1318
  if (collapsible && (onCollapse || onExpand)) {
1319
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1319
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1320
1320
  onExpand();
1321
1321
  }
1322
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1322
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1323
1323
  onCollapse();
1324
1324
  }
1325
1325
  }
@@ -1342,10 +1342,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1342
1342
  onResize(size, lastNotifiedSize);
1343
1343
  }
1344
1344
  if (collapsible && (onCollapse || onExpand)) {
1345
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1345
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1346
1346
  onExpand();
1347
1347
  }
1348
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1348
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1349
1349
  onCollapse();
1350
1350
  }
1351
1351
  }
@@ -1363,10 +1363,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1363
1363
  onResize(size, lastNotifiedSize);
1364
1364
  }
1365
1365
  if (collapsible && (onCollapse || onExpand)) {
1366
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1366
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1367
1367
  onExpand();
1368
1368
  }
1369
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1369
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1370
1370
  onCollapse();
1371
1371
  }
1372
1372
  }
@@ -1339,10 +1339,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1339
1339
  onResize(size, lastNotifiedSize);
1340
1340
  }
1341
1341
  if (collapsible && (onCollapse || onExpand)) {
1342
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1342
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1343
1343
  onExpand();
1344
1344
  }
1345
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1345
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1346
1346
  onCollapse();
1347
1347
  }
1348
1348
  }
@@ -1201,10 +1201,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1201
1201
  onResize(size, lastNotifiedSize);
1202
1202
  }
1203
1203
  if (collapsible && (onCollapse || onExpand)) {
1204
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1204
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1205
1205
  onExpand();
1206
1206
  }
1207
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1207
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1208
1208
  onCollapse();
1209
1209
  }
1210
1210
  }
@@ -1177,10 +1177,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1177
1177
  onResize(size, lastNotifiedSize);
1178
1178
  }
1179
1179
  if (collapsible && (onCollapse || onExpand)) {
1180
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1180
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1181
1181
  onExpand();
1182
1182
  }
1183
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1183
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1184
1184
  onCollapse();
1185
1185
  }
1186
1186
  }
@@ -1318,10 +1318,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1318
1318
  onResize(size, lastNotifiedSize);
1319
1319
  }
1320
1320
  if (collapsible && (onCollapse || onExpand)) {
1321
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1321
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1322
1322
  onExpand();
1323
1323
  }
1324
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1324
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1325
1325
  onCollapse();
1326
1326
  }
1327
1327
  }
@@ -1190,10 +1190,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1190
1190
  onResize(size, lastNotifiedSize);
1191
1191
  }
1192
1192
  if (collapsible && (onCollapse || onExpand)) {
1193
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1193
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1194
1194
  onExpand();
1195
1195
  }
1196
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1196
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1197
1197
  onCollapse();
1198
1198
  }
1199
1199
  }
@@ -1166,10 +1166,10 @@ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1166
1166
  onResize(size, lastNotifiedSize);
1167
1167
  }
1168
1168
  if (collapsible && (onCollapse || onExpand)) {
1169
- if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
1169
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1170
1170
  onExpand();
1171
1171
  }
1172
- if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
1172
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1173
1173
  onCollapse();
1174
1174
  }
1175
1175
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "2.0.14",
3
+ "version": "2.0.15",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
@@ -545,6 +545,44 @@ describe("PanelGroup", () => {
545
545
 
546
546
  expect(onCollapse).toHaveBeenCalledTimes(1);
547
547
  });
548
+
549
+ it("should be called with collapsedSizes that have many decimal places", () => {
550
+ let onCollapse = jest.fn();
551
+
552
+ let panelRef = createRef<ImperativePanelHandle>();
553
+
554
+ act(() => {
555
+ root.render(
556
+ <PanelGroup direction="horizontal">
557
+ <Panel
558
+ collapsible
559
+ onCollapse={onCollapse}
560
+ collapsedSize={3.8764385221078133}
561
+ minSize={10}
562
+ ref={panelRef}
563
+ />
564
+ <PanelResizeHandle />
565
+ <Panel />
566
+ </PanelGroup>
567
+ );
568
+ });
569
+ expect(onCollapse).not.toHaveBeenCalled();
570
+
571
+ act(() => {
572
+ panelRef.current?.collapse();
573
+ });
574
+ expect(onCollapse).toHaveBeenCalledTimes(1);
575
+
576
+ act(() => {
577
+ panelRef.current?.expand();
578
+ });
579
+ expect(onCollapse).toHaveBeenCalledTimes(1);
580
+
581
+ act(() => {
582
+ panelRef.current?.collapse();
583
+ });
584
+ expect(onCollapse).toHaveBeenCalledTimes(2);
585
+ });
548
586
  });
549
587
 
550
588
  describe("onExpand", () => {
@@ -594,6 +632,45 @@ describe("PanelGroup", () => {
594
632
 
595
633
  expect(onExpand).toHaveBeenCalledTimes(1);
596
634
  });
635
+
636
+ it("should be called with collapsedSizes that have many decimal places", () => {
637
+ let onExpand = jest.fn();
638
+
639
+ let panelRef = createRef<ImperativePanelHandle>();
640
+
641
+ act(() => {
642
+ root.render(
643
+ <PanelGroup direction="horizontal">
644
+ <Panel
645
+ collapsible
646
+ collapsedSize={3.8764385221078133}
647
+ defaultSize={3.8764385221078133}
648
+ minSize={10}
649
+ onExpand={onExpand}
650
+ ref={panelRef}
651
+ />
652
+ <PanelResizeHandle />
653
+ <Panel />
654
+ </PanelGroup>
655
+ );
656
+ });
657
+ expect(onExpand).not.toHaveBeenCalled();
658
+
659
+ act(() => {
660
+ panelRef.current?.resize(25);
661
+ });
662
+ expect(onExpand).toHaveBeenCalledTimes(1);
663
+
664
+ act(() => {
665
+ panelRef.current?.collapse();
666
+ });
667
+ expect(onExpand).toHaveBeenCalledTimes(1);
668
+
669
+ act(() => {
670
+ panelRef.current?.expand();
671
+ });
672
+ expect(onExpand).toHaveBeenCalledTimes(2);
673
+ });
597
674
  });
598
675
 
599
676
  describe("onResize", () => {
@@ -723,6 +800,33 @@ describe("PanelGroup", () => {
723
800
  expect(onResizeRight).not.toHaveBeenCalled();
724
801
  });
725
802
  });
803
+
804
+ it("should support sizes with many decimal places", () => {
805
+ let panelRef = createRef<ImperativePanelHandle>();
806
+ let onResize = jest.fn();
807
+
808
+ act(() => {
809
+ root.render(
810
+ <PanelGroup direction="horizontal">
811
+ <Panel onResize={onResize} ref={panelRef} />
812
+ <PanelResizeHandle />
813
+ <Panel />
814
+ </PanelGroup>
815
+ );
816
+ });
817
+ expect(onResize).toHaveBeenCalledTimes(1);
818
+
819
+ act(() => {
820
+ panelRef.current?.resize(3.8764385221078133);
821
+ });
822
+ expect(onResize).toHaveBeenCalledTimes(2);
823
+
824
+ // An overly-high precision change should be ignored
825
+ act(() => {
826
+ panelRef.current?.resize(3.8764385221078132);
827
+ });
828
+ expect(onResize).toHaveBeenCalledTimes(2);
829
+ });
726
830
  });
727
831
 
728
832
  describe("data attributes", () => {
@@ -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 || lastNotifiedSize === collapsedSize) &&
31
- size !== collapsedSize
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 || lastNotifiedSize !== collapsedSize) &&
39
- size === collapsedSize
40
+ (lastNotifiedSize == null ||
41
+ !fuzzyNumbersEqual(lastNotifiedSize, collapsedSize)) &&
42
+ fuzzyNumbersEqual(size, collapsedSize)
40
43
  ) {
41
44
  onCollapse();
42
45
  }