react-resizable-panels 0.0.53 → 0.0.54

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/declarations/src/Panel.d.ts +2 -2
  3. package/dist/declarations/src/PanelGroup.d.ts +2 -2
  4. package/dist/declarations/src/PanelResizeHandle.d.ts +5 -2
  5. package/dist/declarations/src/index.d.ts +7 -7
  6. package/dist/declarations/src/types.d.ts +2 -1
  7. package/dist/react-resizable-panels.browser.cjs.js +1432 -0
  8. package/dist/react-resizable-panels.browser.cjs.mjs +5 -0
  9. package/dist/react-resizable-panels.browser.development.cjs.js +1455 -0
  10. package/dist/react-resizable-panels.browser.development.cjs.mjs +5 -0
  11. package/dist/react-resizable-panels.browser.development.esm.js +1429 -0
  12. package/dist/react-resizable-panels.browser.esm.js +1406 -0
  13. package/dist/react-resizable-panels.cjs.js +10 -18
  14. package/dist/react-resizable-panels.development.cjs.js +35 -27
  15. package/dist/react-resizable-panels.development.cjs.mjs +5 -0
  16. package/dist/react-resizable-panels.development.esm.js +35 -27
  17. package/dist/react-resizable-panels.development.node.cjs.js +1373 -0
  18. package/dist/react-resizable-panels.development.node.cjs.mjs +5 -0
  19. package/dist/react-resizable-panels.development.node.esm.js +1347 -0
  20. package/dist/react-resizable-panels.esm.js +10 -18
  21. package/dist/react-resizable-panels.node.cjs.js +1345 -0
  22. package/dist/react-resizable-panels.node.cjs.mjs +5 -0
  23. package/dist/react-resizable-panels.node.esm.js +1319 -0
  24. package/package.json +26 -1
  25. package/src/Panel.ts +5 -5
  26. package/src/PanelContexts.ts +1 -4
  27. package/src/PanelGroup.ts +48 -10
  28. package/src/PanelResizeHandle.ts +1 -4
  29. package/src/env-conditions/browser.ts +1 -0
  30. package/src/env-conditions/node.ts +1 -0
  31. package/src/env-conditions/unknown.ts +1 -0
  32. package/src/hooks/useIsomorphicEffect.ts +2 -9
  33. package/src/types.ts +1 -0
  34. package/src/utils/ssr.ts +0 -7
@@ -24,6 +24,8 @@ function _interopNamespace(e) {
24
24
 
25
25
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
26
 
27
+ const isBrowser = typeof window !== "undefined";
28
+
27
29
  // This module exists to work around Webpack issue https://github.com/webpack/webpack/issues/14814
28
30
 
29
31
  // eslint-disable-next-line no-restricted-imports
@@ -45,8 +47,7 @@ const {
45
47
  // `toString()` prevents bundlers from trying to `import { useId } from 'react'`
46
48
  const useId = React__namespace["useId".toString()];
47
49
 
48
- const canUseEffectHooks = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
49
- const useIsomorphicLayoutEffect = canUseEffectHooks ? useLayoutEffect : () => {};
50
+ const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : () => {};
50
51
 
51
52
  const wrappedUseId = typeof useId === "function" ? useId : () => null;
52
53
  let counter = 0;
@@ -60,10 +61,6 @@ function useUniqueId(idFromParams = null) {
60
61
  }
61
62
 
62
63
  const PanelGroupContext = createContext(null);
63
-
64
- // Workaround for Parcel scope hoisting (which renames objects/functions).
65
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
66
- // See github.com/parcel-bundler/parcel/issues/8724
67
64
  PanelGroupContext.displayName = "PanelGroupContext";
68
65
 
69
66
  function PanelWithForwardedRef({
@@ -131,6 +128,7 @@ function PanelWithForwardedRef({
131
128
  collapsible,
132
129
  defaultSize,
133
130
  id: panelId,
131
+ idWasAutoGenerated: idFromProps == null,
134
132
  maxSize,
135
133
  minSize,
136
134
  order
@@ -142,6 +140,7 @@ function PanelWithForwardedRef({
142
140
  panelDataRef.current.collapsible = collapsible;
143
141
  panelDataRef.current.defaultSize = defaultSize;
144
142
  panelDataRef.current.id = panelId;
143
+ panelDataRef.current.idWasAutoGenerated = idFromProps == null;
145
144
  panelDataRef.current.maxSize = maxSize;
146
145
  panelDataRef.current.minSize = minSize;
147
146
  panelDataRef.current.order = order;
@@ -181,10 +180,6 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
181
180
  ...props,
182
181
  forwardedRef: ref
183
182
  }));
184
-
185
- // Workaround for Parcel scope hoisting (which renames objects/functions).
186
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
187
- // See github.com/parcel-bundler/parcel/issues/8724
188
183
  PanelWithForwardedRef.displayName = "Panel";
189
184
  Panel.displayName = "forwardRef(Panel)";
190
185
 
@@ -845,6 +840,11 @@ function PanelGroupWithForwardedRef({
845
840
  // We store the initial Panel sizes in this ref, and apply move deltas to them instead of to the current sizes.
846
841
  // This has the benefit of causing force-collapsed panels to spring back open if drag is reversed.
847
842
  const initialDragStateRef = useRef(null);
843
+ useRef({
844
+ didLogDefaultSizeWarning: false,
845
+ didLogIdAndOrderWarning: false,
846
+ prevPanelIds: []
847
+ });
848
848
 
849
849
  // Use a ref to guard against users passing inline props
850
850
  const callbacksRef = useRef({
@@ -1292,10 +1292,6 @@ const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwar
1292
1292
  ...props,
1293
1293
  forwardedRef: ref
1294
1294
  }));
1295
-
1296
- // Workaround for Parcel scope hoisting (which renames objects/functions).
1297
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
1298
- // See github.com/parcel-bundler/parcel/issues/8724
1299
1295
  PanelGroupWithForwardedRef.displayName = "PanelGroup";
1300
1296
  PanelGroup.displayName = "forwardRef(PanelGroup)";
1301
1297
 
@@ -1431,10 +1427,6 @@ function PanelResizeHandle({
1431
1427
  tabIndex: 0
1432
1428
  });
1433
1429
  }
1434
-
1435
- // Workaround for Parcel scope hoisting (which renames objects/functions).
1436
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
1437
- // See github.com/parcel-bundler/parcel/issues/8724
1438
1430
  PanelResizeHandle.displayName = "PanelResizeHandle";
1439
1431
 
1440
1432
  exports.Panel = Panel;
@@ -24,6 +24,8 @@ function _interopNamespace(e) {
24
24
 
25
25
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
26
 
27
+ const isBrowser = typeof window !== "undefined";
28
+
27
29
  // This module exists to work around Webpack issue https://github.com/webpack/webpack/issues/14814
28
30
 
29
31
  // eslint-disable-next-line no-restricted-imports
@@ -45,8 +47,7 @@ const {
45
47
  // `toString()` prevents bundlers from trying to `import { useId } from 'react'`
46
48
  const useId = React__namespace["useId".toString()];
47
49
 
48
- const canUseEffectHooks = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
49
- const useIsomorphicLayoutEffect = canUseEffectHooks ? useLayoutEffect : () => {};
50
+ const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : () => {};
50
51
 
51
52
  const wrappedUseId = typeof useId === "function" ? useId : () => null;
52
53
  let counter = 0;
@@ -60,10 +61,6 @@ function useUniqueId(idFromParams = null) {
60
61
  }
61
62
 
62
63
  const PanelGroupContext = createContext(null);
63
-
64
- // Workaround for Parcel scope hoisting (which renames objects/functions).
65
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
66
- // See github.com/parcel-bundler/parcel/issues/8724
67
64
  PanelGroupContext.displayName = "PanelGroupContext";
68
65
 
69
66
  function PanelWithForwardedRef({
@@ -131,6 +128,7 @@ function PanelWithForwardedRef({
131
128
  collapsible,
132
129
  defaultSize,
133
130
  id: panelId,
131
+ idWasAutoGenerated: idFromProps == null,
134
132
  maxSize,
135
133
  minSize,
136
134
  order
@@ -142,6 +140,7 @@ function PanelWithForwardedRef({
142
140
  panelDataRef.current.collapsible = collapsible;
143
141
  panelDataRef.current.defaultSize = defaultSize;
144
142
  panelDataRef.current.id = panelId;
143
+ panelDataRef.current.idWasAutoGenerated = idFromProps == null;
145
144
  panelDataRef.current.maxSize = maxSize;
146
145
  panelDataRef.current.minSize = minSize;
147
146
  panelDataRef.current.order = order;
@@ -181,10 +180,6 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
181
180
  ...props,
182
181
  forwardedRef: ref
183
182
  }));
184
-
185
- // Workaround for Parcel scope hoisting (which renames objects/functions).
186
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
187
- // See github.com/parcel-bundler/parcel/issues/8724
188
183
  PanelWithForwardedRef.displayName = "Panel";
189
184
  Panel.displayName = "forwardRef(Panel)";
190
185
 
@@ -778,13 +773,6 @@ function savePanelGroupLayout(autoSaveId, panels, sizes, storage) {
778
773
  }
779
774
  }
780
775
 
781
- function isServerRendering() {
782
- try {
783
- return typeof window === undefined;
784
- } catch (error) {}
785
- return true;
786
- }
787
-
788
776
  const debounceMap = {};
789
777
 
790
778
  // PanelGroup might be rendering in a server-side environment where localStorage is not available
@@ -852,6 +840,11 @@ function PanelGroupWithForwardedRef({
852
840
  // We store the initial Panel sizes in this ref, and apply move deltas to them instead of to the current sizes.
853
841
  // This has the benefit of causing force-collapsed panels to spring back open if drag is reversed.
854
842
  const initialDragStateRef = useRef(null);
843
+ const devWarningsRef = useRef({
844
+ didLogDefaultSizeWarning: false,
845
+ didLogIdAndOrderWarning: false,
846
+ prevPanelIds: []
847
+ });
855
848
 
856
849
  // Use a ref to guard against users passing inline props
857
850
  const callbacksRef = useRef({
@@ -1002,6 +995,26 @@ function PanelGroupWithForwardedRef({
1002
995
  }
1003
996
  debounceMap[autoSaveId](autoSaveId, panelsArray, sizes, storage);
1004
997
  }
998
+ {
999
+ const {
1000
+ didLogIdAndOrderWarning,
1001
+ prevPanelIds
1002
+ } = devWarningsRef.current;
1003
+ if (!didLogIdAndOrderWarning) {
1004
+ const {
1005
+ panels
1006
+ } = committedValuesRef.current;
1007
+ const panelIds = Array.from(panels.keys());
1008
+ devWarningsRef.current.prevPanelIds = panelIds;
1009
+ const panelsHaveChanged = prevPanelIds.length > 0 && !areEqual(prevPanelIds, panelIds);
1010
+ if (panelsHaveChanged) {
1011
+ if (Array.from(panels.values()).find(panel => panel.current.idWasAutoGenerated || panel.current.order == null)) {
1012
+ devWarningsRef.current.didLogIdAndOrderWarning = true;
1013
+ console.warn(`WARNING: Panel id and order props recommended when panels are dynamically rendered`);
1014
+ }
1015
+ }
1016
+ }
1017
+ }
1005
1018
  }, [autoSaveId, panels, sizes, storage]);
1006
1019
  const getPanelStyle = useCallback((id, defaultSize) => {
1007
1020
  const {
@@ -1013,8 +1026,11 @@ function PanelGroupWithForwardedRef({
1013
1026
  // At this point the best we can do is render everything with the same size.
1014
1027
  if (panels.size === 0) {
1015
1028
  {
1016
- if (isServerRendering() && defaultSize == null) {
1017
- console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
1029
+ if (!devWarningsRef.current.didLogDefaultSizeWarning) {
1030
+ if (!isBrowser && defaultSize == null) {
1031
+ devWarningsRef.current.didLogDefaultSizeWarning = true;
1032
+ console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
1033
+ }
1018
1034
  }
1019
1035
  }
1020
1036
  return {
@@ -1304,10 +1320,6 @@ const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwar
1304
1320
  ...props,
1305
1321
  forwardedRef: ref
1306
1322
  }));
1307
-
1308
- // Workaround for Parcel scope hoisting (which renames objects/functions).
1309
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
1310
- // See github.com/parcel-bundler/parcel/issues/8724
1311
1323
  PanelGroupWithForwardedRef.displayName = "PanelGroup";
1312
1324
  PanelGroup.displayName = "forwardRef(PanelGroup)";
1313
1325
 
@@ -1443,10 +1455,6 @@ function PanelResizeHandle({
1443
1455
  tabIndex: 0
1444
1456
  });
1445
1457
  }
1446
-
1447
- // Workaround for Parcel scope hoisting (which renames objects/functions).
1448
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
1449
- // See github.com/parcel-bundler/parcel/issues/8724
1450
1458
  PanelResizeHandle.displayName = "PanelResizeHandle";
1451
1459
 
1452
1460
  exports.Panel = Panel;
@@ -0,0 +1,5 @@
1
+ export {
2
+ Panel,
3
+ PanelGroup,
4
+ PanelResizeHandle
5
+ } from "./react-resizable-panels.development.cjs.js";
@@ -1,5 +1,7 @@
1
1
  import * as React from 'react';
2
2
 
3
+ const isBrowser = typeof window !== "undefined";
4
+
3
5
  // This module exists to work around Webpack issue https://github.com/webpack/webpack/issues/14814
4
6
 
5
7
  // eslint-disable-next-line no-restricted-imports
@@ -21,8 +23,7 @@ const {
21
23
  // `toString()` prevents bundlers from trying to `import { useId } from 'react'`
22
24
  const useId = React["useId".toString()];
23
25
 
24
- const canUseEffectHooks = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
25
- const useIsomorphicLayoutEffect = canUseEffectHooks ? useLayoutEffect : () => {};
26
+ const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : () => {};
26
27
 
27
28
  const wrappedUseId = typeof useId === "function" ? useId : () => null;
28
29
  let counter = 0;
@@ -36,10 +37,6 @@ function useUniqueId(idFromParams = null) {
36
37
  }
37
38
 
38
39
  const PanelGroupContext = createContext(null);
39
-
40
- // Workaround for Parcel scope hoisting (which renames objects/functions).
41
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
42
- // See github.com/parcel-bundler/parcel/issues/8724
43
40
  PanelGroupContext.displayName = "PanelGroupContext";
44
41
 
45
42
  function PanelWithForwardedRef({
@@ -107,6 +104,7 @@ function PanelWithForwardedRef({
107
104
  collapsible,
108
105
  defaultSize,
109
106
  id: panelId,
107
+ idWasAutoGenerated: idFromProps == null,
110
108
  maxSize,
111
109
  minSize,
112
110
  order
@@ -118,6 +116,7 @@ function PanelWithForwardedRef({
118
116
  panelDataRef.current.collapsible = collapsible;
119
117
  panelDataRef.current.defaultSize = defaultSize;
120
118
  panelDataRef.current.id = panelId;
119
+ panelDataRef.current.idWasAutoGenerated = idFromProps == null;
121
120
  panelDataRef.current.maxSize = maxSize;
122
121
  panelDataRef.current.minSize = minSize;
123
122
  panelDataRef.current.order = order;
@@ -157,10 +156,6 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
157
156
  ...props,
158
157
  forwardedRef: ref
159
158
  }));
160
-
161
- // Workaround for Parcel scope hoisting (which renames objects/functions).
162
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
163
- // See github.com/parcel-bundler/parcel/issues/8724
164
159
  PanelWithForwardedRef.displayName = "Panel";
165
160
  Panel.displayName = "forwardRef(Panel)";
166
161
 
@@ -754,13 +749,6 @@ function savePanelGroupLayout(autoSaveId, panels, sizes, storage) {
754
749
  }
755
750
  }
756
751
 
757
- function isServerRendering() {
758
- try {
759
- return typeof window === undefined;
760
- } catch (error) {}
761
- return true;
762
- }
763
-
764
752
  const debounceMap = {};
765
753
 
766
754
  // PanelGroup might be rendering in a server-side environment where localStorage is not available
@@ -828,6 +816,11 @@ function PanelGroupWithForwardedRef({
828
816
  // We store the initial Panel sizes in this ref, and apply move deltas to them instead of to the current sizes.
829
817
  // This has the benefit of causing force-collapsed panels to spring back open if drag is reversed.
830
818
  const initialDragStateRef = useRef(null);
819
+ const devWarningsRef = useRef({
820
+ didLogDefaultSizeWarning: false,
821
+ didLogIdAndOrderWarning: false,
822
+ prevPanelIds: []
823
+ });
831
824
 
832
825
  // Use a ref to guard against users passing inline props
833
826
  const callbacksRef = useRef({
@@ -978,6 +971,26 @@ function PanelGroupWithForwardedRef({
978
971
  }
979
972
  debounceMap[autoSaveId](autoSaveId, panelsArray, sizes, storage);
980
973
  }
974
+ {
975
+ const {
976
+ didLogIdAndOrderWarning,
977
+ prevPanelIds
978
+ } = devWarningsRef.current;
979
+ if (!didLogIdAndOrderWarning) {
980
+ const {
981
+ panels
982
+ } = committedValuesRef.current;
983
+ const panelIds = Array.from(panels.keys());
984
+ devWarningsRef.current.prevPanelIds = panelIds;
985
+ const panelsHaveChanged = prevPanelIds.length > 0 && !areEqual(prevPanelIds, panelIds);
986
+ if (panelsHaveChanged) {
987
+ if (Array.from(panels.values()).find(panel => panel.current.idWasAutoGenerated || panel.current.order == null)) {
988
+ devWarningsRef.current.didLogIdAndOrderWarning = true;
989
+ console.warn(`WARNING: Panel id and order props recommended when panels are dynamically rendered`);
990
+ }
991
+ }
992
+ }
993
+ }
981
994
  }, [autoSaveId, panels, sizes, storage]);
982
995
  const getPanelStyle = useCallback((id, defaultSize) => {
983
996
  const {
@@ -989,8 +1002,11 @@ function PanelGroupWithForwardedRef({
989
1002
  // At this point the best we can do is render everything with the same size.
990
1003
  if (panels.size === 0) {
991
1004
  {
992
- if (isServerRendering() && defaultSize == null) {
993
- console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
1005
+ if (!devWarningsRef.current.didLogDefaultSizeWarning) {
1006
+ if (!isBrowser && defaultSize == null) {
1007
+ devWarningsRef.current.didLogDefaultSizeWarning = true;
1008
+ console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
1009
+ }
994
1010
  }
995
1011
  }
996
1012
  return {
@@ -1280,10 +1296,6 @@ const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwar
1280
1296
  ...props,
1281
1297
  forwardedRef: ref
1282
1298
  }));
1283
-
1284
- // Workaround for Parcel scope hoisting (which renames objects/functions).
1285
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
1286
- // See github.com/parcel-bundler/parcel/issues/8724
1287
1299
  PanelGroupWithForwardedRef.displayName = "PanelGroup";
1288
1300
  PanelGroup.displayName = "forwardRef(PanelGroup)";
1289
1301
 
@@ -1419,10 +1431,6 @@ function PanelResizeHandle({
1419
1431
  tabIndex: 0
1420
1432
  });
1421
1433
  }
1422
-
1423
- // Workaround for Parcel scope hoisting (which renames objects/functions).
1424
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
1425
- // See github.com/parcel-bundler/parcel/issues/8724
1426
1434
  PanelResizeHandle.displayName = "PanelResizeHandle";
1427
1435
 
1428
1436
  export { Panel, PanelGroup, PanelResizeHandle };