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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "0.0.53",
3
+ "version": "0.0.54",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
@@ -18,10 +18,30 @@
18
18
  "default": "./dist/react-resizable-panels.cjs.js"
19
19
  },
20
20
  "development": {
21
+ "browser": {
22
+ "module": "./dist/react-resizable-panels.browser.development.esm.js",
23
+ "import": "./dist/react-resizable-panels.browser.development.cjs.mjs",
24
+ "default": "./dist/react-resizable-panels.browser.development.cjs.js"
25
+ },
26
+ "node": {
27
+ "module": "./dist/react-resizable-panels.development.node.esm.js",
28
+ "import": "./dist/react-resizable-panels.development.node.cjs.mjs",
29
+ "default": "./dist/react-resizable-panels.development.node.cjs.js"
30
+ },
21
31
  "module": "./dist/react-resizable-panels.development.esm.js",
22
32
  "import": "./dist/react-resizable-panels.development.cjs.mjs",
23
33
  "default": "./dist/react-resizable-panels.development.cjs.js"
24
34
  },
35
+ "browser": {
36
+ "module": "./dist/react-resizable-panels.browser.esm.js",
37
+ "import": "./dist/react-resizable-panels.browser.cjs.mjs",
38
+ "default": "./dist/react-resizable-panels.browser.cjs.js"
39
+ },
40
+ "node": {
41
+ "module": "./dist/react-resizable-panels.node.esm.js",
42
+ "import": "./dist/react-resizable-panels.node.cjs.mjs",
43
+ "default": "./dist/react-resizable-panels.node.cjs.js"
44
+ },
25
45
  "module": "./dist/react-resizable-panels.esm.js",
26
46
  "import": "./dist/react-resizable-panels.cjs.mjs",
27
47
  "default": "./dist/react-resizable-panels.cjs.js"
@@ -32,6 +52,11 @@
32
52
  "#is-development": {
33
53
  "development": "./src/env-conditions/development.ts",
34
54
  "default": "./src/env-conditions/production.ts"
55
+ },
56
+ "#is-browser": {
57
+ "browser": "./src/env-conditions/browser.ts",
58
+ "node": "./src/env-conditions/node.ts",
59
+ "default": "./src/env-conditions/unknown.ts"
35
60
  }
36
61
  },
37
62
  "types": "dist/react-resizable-panels.cjs.d.ts",
package/src/Panel.ts CHANGED
@@ -125,6 +125,7 @@ function PanelWithForwardedRef({
125
125
  collapsible: boolean;
126
126
  defaultSize: number | null;
127
127
  id: string;
128
+ idWasAutoGenerated: boolean;
128
129
  maxSize: number;
129
130
  minSize: number;
130
131
  order: number | null;
@@ -134,6 +135,7 @@ function PanelWithForwardedRef({
134
135
  collapsible,
135
136
  defaultSize,
136
137
  id: panelId,
138
+ idWasAutoGenerated: idFromProps == null,
137
139
  maxSize,
138
140
  minSize,
139
141
  order,
@@ -146,6 +148,7 @@ function PanelWithForwardedRef({
146
148
  panelDataRef.current.collapsible = collapsible;
147
149
  panelDataRef.current.defaultSize = defaultSize;
148
150
  panelDataRef.current.id = panelId;
151
+ panelDataRef.current.idWasAutoGenerated = idFromProps == null;
149
152
  panelDataRef.current.maxSize = maxSize;
150
153
  panelDataRef.current.minSize = minSize;
151
154
  panelDataRef.current.order = order;
@@ -195,11 +198,8 @@ export const Panel = forwardRef<ImperativePanelHandle, PanelProps>(
195
198
  createElement(PanelWithForwardedRef, { ...props, forwardedRef: ref })
196
199
  );
197
200
 
198
- // Workaround for Parcel scope hoisting (which renames objects/functions).
199
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
200
- // See github.com/parcel-bundler/parcel/issues/8724
201
- (PanelWithForwardedRef as any).displayName = "Panel";
202
- (Panel as any).displayName = "forwardRef(Panel)";
201
+ PanelWithForwardedRef.displayName = "Panel";
202
+ Panel.displayName = "forwardRef(Panel)";
203
203
 
204
204
  // HACK
205
205
  function parseSizeFromStyle(style: CSSProperties): number {
@@ -17,7 +17,4 @@ export const PanelGroupContext = createContext<{
17
17
  unregisterPanel: (id: string) => void;
18
18
  } | null>(null);
19
19
 
20
- // Workaround for Parcel scope hoisting (which renames objects/functions).
21
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
22
- // See github.com/parcel-bundler/parcel/issues/8724
23
- (PanelGroupContext as any).displayName = "PanelGroupContext";
20
+ PanelGroupContext.displayName = "PanelGroupContext";
package/src/PanelGroup.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { isBrowser } from "#is-browser";
1
2
  import { isDevelopment } from "#is-development";
2
3
  import {
3
4
  createElement,
@@ -46,7 +47,6 @@ import {
46
47
  panelsMapToSortedArray,
47
48
  } from "./utils/group";
48
49
  import { loadPanelLayout, savePanelGroupLayout } from "./utils/serialization";
49
- import { isServerRendering } from "./utils/ssr";
50
50
 
51
51
  const debounceMap: {
52
52
  [key: string]: (
@@ -161,6 +161,16 @@ function PanelGroupWithForwardedRef({
161
161
  // This has the benefit of causing force-collapsed panels to spring back open if drag is reversed.
162
162
  const initialDragStateRef = useRef<InitialDragState | null>(null);
163
163
 
164
+ const devWarningsRef = useRef<{
165
+ didLogDefaultSizeWarning: boolean;
166
+ didLogIdAndOrderWarning: boolean;
167
+ prevPanelIds: string[];
168
+ }>({
169
+ didLogDefaultSizeWarning: false,
170
+ didLogIdAndOrderWarning: false,
171
+ prevPanelIds: [],
172
+ });
173
+
164
174
  // Use a ref to guard against users passing inline props
165
175
  const callbacksRef = useRef<{
166
176
  onLayout: PanelGroupOnLayout | undefined;
@@ -334,6 +344,34 @@ function PanelGroupWithForwardedRef({
334
344
  }
335
345
  debounceMap[autoSaveId](autoSaveId, panelsArray, sizes, storage);
336
346
  }
347
+
348
+ if (isDevelopment) {
349
+ const { didLogIdAndOrderWarning, prevPanelIds } = devWarningsRef.current;
350
+ if (!didLogIdAndOrderWarning) {
351
+ const { panels } = committedValuesRef.current;
352
+
353
+ const panelIds = Array.from(panels.keys());
354
+
355
+ devWarningsRef.current.prevPanelIds = panelIds;
356
+
357
+ const panelsHaveChanged =
358
+ prevPanelIds.length > 0 && !areEqual(prevPanelIds, panelIds);
359
+ if (panelsHaveChanged) {
360
+ if (
361
+ Array.from(panels.values()).find(
362
+ (panel) =>
363
+ panel.current.idWasAutoGenerated || panel.current.order == null
364
+ )
365
+ ) {
366
+ devWarningsRef.current.didLogIdAndOrderWarning = true;
367
+
368
+ console.warn(
369
+ `WARNING: Panel id and order props recommended when panels are dynamically rendered`
370
+ );
371
+ }
372
+ }
373
+ }
374
+ }
337
375
  }, [autoSaveId, panels, sizes, storage]);
338
376
 
339
377
  const getPanelStyle = useCallback(
@@ -345,10 +383,13 @@ function PanelGroupWithForwardedRef({
345
383
  // At this point the best we can do is render everything with the same size.
346
384
  if (panels.size === 0) {
347
385
  if (isDevelopment) {
348
- if (isServerRendering() && defaultSize == null) {
349
- console.warn(
350
- `WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`
351
- );
386
+ if (!devWarningsRef.current.didLogDefaultSizeWarning) {
387
+ if (!isBrowser && defaultSize == null) {
388
+ devWarningsRef.current.didLogDefaultSizeWarning = true;
389
+ console.warn(
390
+ `WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`
391
+ );
392
+ }
352
393
  }
353
394
  }
354
395
 
@@ -770,8 +811,5 @@ export const PanelGroup = forwardRef<
770
811
  createElement(PanelGroupWithForwardedRef, { ...props, forwardedRef: ref })
771
812
  );
772
813
 
773
- // Workaround for Parcel scope hoisting (which renames objects/functions).
774
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
775
- // See github.com/parcel-bundler/parcel/issues/8724
776
- (PanelGroupWithForwardedRef as any).displayName = "PanelGroup";
777
- (PanelGroup as any).displayName = "forwardRef(PanelGroup)";
814
+ PanelGroupWithForwardedRef.displayName = "PanelGroup";
815
+ PanelGroup.displayName = "forwardRef(PanelGroup)";
@@ -190,7 +190,4 @@ export function PanelResizeHandle({
190
190
  });
191
191
  }
192
192
 
193
- // Workaround for Parcel scope hoisting (which renames objects/functions).
194
- // Casting to :any is required to avoid corrupting the generated TypeScript types.
195
- // See github.com/parcel-bundler/parcel/issues/8724
196
- (PanelResizeHandle as any).displayName = "PanelResizeHandle";
193
+ PanelResizeHandle.displayName = "PanelResizeHandle";
@@ -0,0 +1 @@
1
+ export const isBrowser = true;
@@ -0,0 +1 @@
1
+ export const isBrowser = false;
@@ -0,0 +1 @@
1
+ export const isBrowser = typeof window !== "undefined";
@@ -1,13 +1,6 @@
1
+ import { isBrowser } from "#is-browser";
1
2
  import { useLayoutEffect } from "../vendor/react";
2
3
 
3
- const canUseEffectHooks = !!(
4
- typeof window !== "undefined" &&
5
- typeof window.document !== "undefined" &&
6
- typeof window.document.createElement !== "undefined"
7
- );
8
-
9
- const useIsomorphicLayoutEffect = canUseEffectHooks
10
- ? useLayoutEffect
11
- : () => {};
4
+ const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : () => {};
12
5
 
13
6
  export default useIsomorphicLayoutEffect;
package/src/types.ts CHANGED
@@ -24,6 +24,7 @@ export type PanelData = {
24
24
  collapsible: boolean;
25
25
  defaultSize: number | null;
26
26
  id: string;
27
+ idWasAutoGenerated: boolean;
27
28
  maxSize: number;
28
29
  minSize: number;
29
30
  order: number | null;
package/src/utils/ssr.ts DELETED
@@ -1,7 +0,0 @@
1
- export function isServerRendering(): boolean {
2
- try {
3
- return typeof window === undefined;
4
- } catch (error) {}
5
-
6
- return true;
7
- }