react-resizable-panels 0.0.53 → 0.0.55

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 (41) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/declarations/src/Panel.d.ts +6 -5
  3. package/dist/declarations/src/PanelGroup.d.ts +8 -4
  4. package/dist/declarations/src/PanelResizeHandle.d.ts +5 -2
  5. package/dist/declarations/src/index.d.ts +9 -8
  6. package/dist/declarations/src/types.d.ts +4 -2
  7. package/dist/declarations/src/utils/group.d.ts +29 -0
  8. package/dist/react-resizable-panels.browser.cjs.js +1709 -0
  9. package/dist/react-resizable-panels.browser.cjs.mjs +6 -0
  10. package/dist/react-resizable-panels.browser.development.cjs.js +1764 -0
  11. package/dist/react-resizable-panels.browser.development.cjs.mjs +6 -0
  12. package/dist/react-resizable-panels.browser.development.esm.js +1737 -0
  13. package/dist/react-resizable-panels.browser.esm.js +1682 -0
  14. package/dist/react-resizable-panels.cjs.js +395 -126
  15. package/dist/react-resizable-panels.cjs.js.map +1 -0
  16. package/dist/react-resizable-panels.cjs.mjs +2 -1
  17. package/dist/react-resizable-panels.development.cjs.js +452 -135
  18. package/dist/react-resizable-panels.development.cjs.mjs +6 -0
  19. package/dist/react-resizable-panels.development.esm.js +452 -136
  20. package/dist/react-resizable-panels.development.node.cjs.js +1579 -0
  21. package/dist/react-resizable-panels.development.node.cjs.mjs +6 -0
  22. package/dist/react-resizable-panels.development.node.esm.js +1552 -0
  23. package/dist/react-resizable-panels.esm.js +395 -127
  24. package/dist/react-resizable-panels.esm.js.map +1 -0
  25. package/dist/react-resizable-panels.node.cjs.js +1523 -0
  26. package/dist/react-resizable-panels.node.cjs.mjs +6 -0
  27. package/dist/react-resizable-panels.node.esm.js +1496 -0
  28. package/package.json +26 -1
  29. package/src/Panel.ts +37 -37
  30. package/src/PanelContexts.ts +5 -6
  31. package/src/PanelGroup.ts +269 -121
  32. package/src/PanelResizeHandle.ts +1 -4
  33. package/src/env-conditions/browser.ts +1 -0
  34. package/src/env-conditions/node.ts +1 -0
  35. package/src/env-conditions/unknown.ts +1 -0
  36. package/src/hooks/useIsomorphicEffect.ts +2 -9
  37. package/src/hooks/useWindowSplitterBehavior.ts +14 -11
  38. package/src/index.ts +11 -3
  39. package/src/types.ts +3 -1
  40. package/src/utils/group.ts +327 -28
  41. 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.55",
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
@@ -19,7 +19,9 @@ import {
19
19
  PanelData,
20
20
  PanelOnCollapse,
21
21
  PanelOnResize,
22
+ Units,
22
23
  } from "./types";
24
+ import { getAvailableGroupSizePixels } from "./utils/group";
23
25
 
24
26
  export type PanelProps = {
25
27
  children?: ReactNode;
@@ -28,7 +30,7 @@ export type PanelProps = {
28
30
  collapsible?: boolean;
29
31
  defaultSize?: number | null;
30
32
  id?: string | null;
31
- maxSize?: number;
33
+ maxSize?: number | null;
32
34
  minSize?: number;
33
35
  onCollapse?: PanelOnCollapse | null;
34
36
  onResize?: PanelOnResize | null;
@@ -41,8 +43,9 @@ export type ImperativePanelHandle = {
41
43
  collapse: () => void;
42
44
  expand: () => void;
43
45
  getCollapsed(): boolean;
44
- getSize(): number;
45
- resize: (percentage: number) => void;
46
+ getId(): string;
47
+ getSize(units?: Units): number;
48
+ resize: (percentage: number, units?: Units) => void;
46
49
  };
47
50
 
48
51
  function PanelWithForwardedRef({
@@ -53,8 +56,8 @@ function PanelWithForwardedRef({
53
56
  defaultSize = null,
54
57
  forwardedRef,
55
58
  id: idFromProps = null,
56
- maxSize = 100,
57
- minSize = 10,
59
+ maxSize = null,
60
+ minSize,
58
61
  onCollapse = null,
59
62
  onResize = null,
60
63
  order = null,
@@ -75,12 +78,24 @@ function PanelWithForwardedRef({
75
78
  const {
76
79
  collapsePanel,
77
80
  expandPanel,
81
+ getPanelSize,
78
82
  getPanelStyle,
79
83
  registerPanel,
80
84
  resizePanel,
85
+ units,
81
86
  unregisterPanel,
82
87
  } = context;
83
88
 
89
+ if (minSize == null) {
90
+ if (units === "percentages") {
91
+ // Mimics legacy default value for percentage based panel groups
92
+ minSize = 10;
93
+ } else {
94
+ // There is no meaningful minimum pixel default we can provide
95
+ minSize = 0;
96
+ }
97
+ }
98
+
84
99
  // Use a ref to guard against users passing inline props
85
100
  const callbacksRef = useRef<{
86
101
  onCollapse: PanelOnCollapse | null;
@@ -91,27 +106,6 @@ function PanelWithForwardedRef({
91
106
  callbacksRef.current.onResize = onResize;
92
107
  });
93
108
 
94
- // Basic props validation
95
- if (minSize < 0 || minSize > 100) {
96
- throw Error(`Panel minSize must be between 0 and 100, but was ${minSize}`);
97
- } else if (maxSize < 0 || maxSize > 100) {
98
- throw Error(`Panel maxSize must be between 0 and 100, but was ${maxSize}`);
99
- } else {
100
- if (defaultSize !== null) {
101
- if (defaultSize < 0 || defaultSize > 100) {
102
- throw Error(
103
- `Panel defaultSize must be between 0 and 100, but was ${defaultSize}`
104
- );
105
- } else if (minSize > defaultSize && !collapsible) {
106
- console.error(
107
- `Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`
108
- );
109
-
110
- defaultSize = minSize;
111
- }
112
- }
113
- }
114
-
115
109
  const style = getPanelStyle(panelId, defaultSize);
116
110
 
117
111
  const committedValuesRef = useRef<{
@@ -119,13 +113,15 @@ function PanelWithForwardedRef({
119
113
  }>({
120
114
  size: parseSizeFromStyle(style),
121
115
  });
116
+
122
117
  const panelDataRef = useRef<{
123
118
  callbacksRef: PanelCallbackRef;
124
119
  collapsedSize: number;
125
120
  collapsible: boolean;
126
121
  defaultSize: number | null;
127
122
  id: string;
128
- maxSize: number;
123
+ idWasAutoGenerated: boolean;
124
+ maxSize: number | null;
129
125
  minSize: number;
130
126
  order: number | null;
131
127
  }>({
@@ -134,10 +130,12 @@ function PanelWithForwardedRef({
134
130
  collapsible,
135
131
  defaultSize,
136
132
  id: panelId,
133
+ idWasAutoGenerated: idFromProps == null,
137
134
  maxSize,
138
135
  minSize,
139
136
  order,
140
137
  });
138
+
141
139
  useIsomorphicLayoutEffect(() => {
142
140
  committedValuesRef.current.size = parseSizeFromStyle(style);
143
141
 
@@ -146,8 +144,9 @@ function PanelWithForwardedRef({
146
144
  panelDataRef.current.collapsible = collapsible;
147
145
  panelDataRef.current.defaultSize = defaultSize;
148
146
  panelDataRef.current.id = panelId;
147
+ panelDataRef.current.idWasAutoGenerated = idFromProps == null;
149
148
  panelDataRef.current.maxSize = maxSize;
150
- panelDataRef.current.minSize = minSize;
149
+ panelDataRef.current.minSize = minSize as number;
151
150
  panelDataRef.current.order = order;
152
151
  });
153
152
 
@@ -167,12 +166,16 @@ function PanelWithForwardedRef({
167
166
  getCollapsed() {
168
167
  return committedValuesRef.current.size === 0;
169
168
  },
170
- getSize() {
171
- return committedValuesRef.current.size;
169
+ getId() {
170
+ return panelId;
171
+ },
172
+ getSize(units) {
173
+ return getPanelSize(panelId, units);
172
174
  },
173
- resize: (percentage: number) => resizePanel(panelId, percentage),
175
+ resize: (percentage: number, units) =>
176
+ resizePanel(panelId, percentage, units),
174
177
  }),
175
- [collapsePanel, expandPanel, panelId, resizePanel]
178
+ [collapsePanel, expandPanel, getPanelSize, panelId, resizePanel]
176
179
  );
177
180
 
178
181
  return createElement(Type, {
@@ -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 {
@@ -1,23 +1,22 @@
1
1
  import { CSSProperties, createContext } from "./vendor/react";
2
2
 
3
- import { PanelData, ResizeEvent, ResizeHandler } from "./types";
3
+ import { PanelData, ResizeEvent, ResizeHandler, Units } from "./types";
4
4
 
5
5
  export const PanelGroupContext = createContext<{
6
6
  activeHandleId: string | null;
7
7
  collapsePanel: (id: string) => void;
8
8
  direction: "horizontal" | "vertical";
9
9
  expandPanel: (id: string) => void;
10
+ getPanelSize: (id: string, units?: Units) => number;
10
11
  getPanelStyle: (id: string, defaultSize: number | null) => CSSProperties;
11
12
  groupId: string;
12
13
  registerPanel: (id: string, panel: PanelData) => void;
13
14
  registerResizeHandle: (id: string) => ResizeHandler;
14
- resizePanel: (id: string, percentage: number) => void;
15
+ resizePanel: (id: string, percentage: number, units?: Units) => void;
15
16
  startDragging: (id: string, event: ResizeEvent) => void;
16
17
  stopDragging: () => void;
17
18
  unregisterPanel: (id: string) => void;
19
+ units: Units;
18
20
  } | null>(null);
19
21
 
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";
22
+ PanelGroupContext.displayName = "PanelGroupContext";