react-resizable-panels 0.0.48 → 0.0.50

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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.50
4
+ * Improved panel size validation in `PanelGroup`.
5
+
6
+ ## 0.0.49
7
+ * Improved development warnings and props validation checks in `PanelGroup`.
8
+
3
9
  ## 0.0.48
4
10
  * [148](https://github.com/bvaughn/react-resizable-panels/pull/148): Build release bundle with Preconstruct
5
11
 
@@ -762,13 +762,6 @@ function savePanelGroupLayout(autoSaveId, panels, sizes, storage) {
762
762
  }
763
763
  }
764
764
 
765
- function isServerRendering() {
766
- try {
767
- return typeof window === undefined;
768
- } catch (error) {}
769
- return true;
770
- }
771
-
772
765
  const debounceMap = {};
773
766
 
774
767
  // PanelGroup might be rendering in a server-side environment where localStorage is not available
@@ -959,9 +952,11 @@ function PanelGroupWithForwardedRef({
959
952
  }
960
953
  });
961
954
  if (totalDefaultSize > 100) {
962
- throw new Error(`The sum of the defaultSize of all panels in a group cannot exceed 100.`);
955
+ throw new Error(`Default panel sizes cannot exceed 100%`);
956
+ } else if (panelsArray.length > 1 && panelsWithNullDefaultSize === 0 && totalDefaultSize !== 100) {
957
+ throw new Error(`Invalid default sizes specified for panels`);
963
958
  } else if (totalMinSize > 100) {
964
- throw new Error(`The sum of the minSize of all panels in a group cannot exceed 100.`);
959
+ throw new Error(`Minimum panel sizes cannot exceed 100%`);
965
960
  }
966
961
  setSizes(panelsArray.map(panel => {
967
962
  if (panel.current.defaultSize === null) {
@@ -995,9 +990,6 @@ function PanelGroupWithForwardedRef({
995
990
  // This includes server rendering.
996
991
  // At this point the best we can do is render everything with the same size.
997
992
  if (panels.size === 0) {
998
- if (isServerRendering() && defaultSize == null) {
999
- console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
1000
- }
1001
993
  return {
1002
994
  flexBasis: 0,
1003
995
  flexGrow: defaultSize != null ? defaultSize : undefined,
@@ -959,9 +959,11 @@ function PanelGroupWithForwardedRef({
959
959
  }
960
960
  });
961
961
  if (totalDefaultSize > 100) {
962
- throw new Error(`The sum of the defaultSize of all panels in a group cannot exceed 100.`);
962
+ throw new Error(`Default panel sizes cannot exceed 100%`);
963
+ } else if (panelsArray.length > 1 && panelsWithNullDefaultSize === 0 && totalDefaultSize !== 100) {
964
+ throw new Error(`Invalid default sizes specified for panels`);
963
965
  } else if (totalMinSize > 100) {
964
- throw new Error(`The sum of the minSize of all panels in a group cannot exceed 100.`);
966
+ throw new Error(`Minimum panel sizes cannot exceed 100%`);
965
967
  }
966
968
  setSizes(panelsArray.map(panel => {
967
969
  if (panel.current.defaultSize === null) {
@@ -995,8 +997,10 @@ function PanelGroupWithForwardedRef({
995
997
  // This includes server rendering.
996
998
  // At this point the best we can do is render everything with the same size.
997
999
  if (panels.size === 0) {
998
- if (isServerRendering() && defaultSize == null) {
999
- console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
1000
+ {
1001
+ if (isServerRendering() && defaultSize == null) {
1002
+ console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
1003
+ }
1000
1004
  }
1001
1005
  return {
1002
1006
  flexBasis: 0,
@@ -935,9 +935,11 @@ function PanelGroupWithForwardedRef({
935
935
  }
936
936
  });
937
937
  if (totalDefaultSize > 100) {
938
- throw new Error(`The sum of the defaultSize of all panels in a group cannot exceed 100.`);
938
+ throw new Error(`Default panel sizes cannot exceed 100%`);
939
+ } else if (panelsArray.length > 1 && panelsWithNullDefaultSize === 0 && totalDefaultSize !== 100) {
940
+ throw new Error(`Invalid default sizes specified for panels`);
939
941
  } else if (totalMinSize > 100) {
940
- throw new Error(`The sum of the minSize of all panels in a group cannot exceed 100.`);
942
+ throw new Error(`Minimum panel sizes cannot exceed 100%`);
941
943
  }
942
944
  setSizes(panelsArray.map(panel => {
943
945
  if (panel.current.defaultSize === null) {
@@ -971,8 +973,10 @@ function PanelGroupWithForwardedRef({
971
973
  // This includes server rendering.
972
974
  // At this point the best we can do is render everything with the same size.
973
975
  if (panels.size === 0) {
974
- if (isServerRendering() && defaultSize == null) {
975
- console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
976
+ {
977
+ if (isServerRendering() && defaultSize == null) {
978
+ console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
979
+ }
976
980
  }
977
981
  return {
978
982
  flexBasis: 0,
@@ -738,13 +738,6 @@ function savePanelGroupLayout(autoSaveId, panels, sizes, storage) {
738
738
  }
739
739
  }
740
740
 
741
- function isServerRendering() {
742
- try {
743
- return typeof window === undefined;
744
- } catch (error) {}
745
- return true;
746
- }
747
-
748
741
  const debounceMap = {};
749
742
 
750
743
  // PanelGroup might be rendering in a server-side environment where localStorage is not available
@@ -935,9 +928,11 @@ function PanelGroupWithForwardedRef({
935
928
  }
936
929
  });
937
930
  if (totalDefaultSize > 100) {
938
- throw new Error(`The sum of the defaultSize of all panels in a group cannot exceed 100.`);
931
+ throw new Error(`Default panel sizes cannot exceed 100%`);
932
+ } else if (panelsArray.length > 1 && panelsWithNullDefaultSize === 0 && totalDefaultSize !== 100) {
933
+ throw new Error(`Invalid default sizes specified for panels`);
939
934
  } else if (totalMinSize > 100) {
940
- throw new Error(`The sum of the minSize of all panels in a group cannot exceed 100.`);
935
+ throw new Error(`Minimum panel sizes cannot exceed 100%`);
941
936
  }
942
937
  setSizes(panelsArray.map(panel => {
943
938
  if (panel.current.defaultSize === null) {
@@ -971,9 +966,6 @@ function PanelGroupWithForwardedRef({
971
966
  // This includes server rendering.
972
967
  // At this point the best we can do is render everything with the same size.
973
968
  if (panels.size === 0) {
974
- if (isServerRendering() && defaultSize == null) {
975
- console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
976
- }
977
969
  return {
978
970
  flexBasis: 0,
979
971
  flexGrow: defaultSize != null ? defaultSize : undefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
package/src/PanelGroup.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { isDevelopment } from "#is-development";
1
2
  import {
2
3
  createElement,
3
4
  CSSProperties,
@@ -292,13 +293,15 @@ function PanelGroupWithForwardedRef({
292
293
  });
293
294
 
294
295
  if (totalDefaultSize > 100) {
295
- throw new Error(
296
- `The sum of the defaultSize of all panels in a group cannot exceed 100.`
297
- );
296
+ throw new Error(`Default panel sizes cannot exceed 100%`);
297
+ } else if (
298
+ panelsArray.length > 1 &&
299
+ panelsWithNullDefaultSize === 0 &&
300
+ totalDefaultSize !== 100
301
+ ) {
302
+ throw new Error(`Invalid default sizes specified for panels`);
298
303
  } else if (totalMinSize > 100) {
299
- throw new Error(
300
- `The sum of the minSize of all panels in a group cannot exceed 100.`
301
- );
304
+ throw new Error(`Minimum panel sizes cannot exceed 100%`);
302
305
  }
303
306
 
304
307
  setSizes(
@@ -338,10 +341,12 @@ function PanelGroupWithForwardedRef({
338
341
  // This includes server rendering.
339
342
  // At this point the best we can do is render everything with the same size.
340
343
  if (panels.size === 0) {
341
- if (isServerRendering() && defaultSize == null) {
342
- console.warn(
343
- `WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`
344
- );
344
+ if (isDevelopment) {
345
+ if (isServerRendering() && defaultSize == null) {
346
+ console.warn(
347
+ `WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`
348
+ );
349
+ }
345
350
  }
346
351
 
347
352
  return {