react-resizable-panels 0.0.54 → 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 (34) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/declarations/src/Panel.d.ts +5 -4
  3. package/dist/declarations/src/PanelGroup.d.ts +7 -3
  4. package/dist/declarations/src/index.d.ts +3 -2
  5. package/dist/declarations/src/types.d.ts +2 -1
  6. package/dist/declarations/src/utils/group.d.ts +29 -0
  7. package/dist/react-resizable-panels.browser.cjs.js +385 -108
  8. package/dist/react-resizable-panels.browser.cjs.mjs +2 -1
  9. package/dist/react-resizable-panels.browser.development.cjs.js +417 -108
  10. package/dist/react-resizable-panels.browser.development.cjs.mjs +2 -1
  11. package/dist/react-resizable-panels.browser.development.esm.js +417 -109
  12. package/dist/react-resizable-panels.browser.esm.js +385 -109
  13. package/dist/react-resizable-panels.cjs.js +385 -108
  14. package/dist/react-resizable-panels.cjs.js.map +1 -0
  15. package/dist/react-resizable-panels.cjs.mjs +2 -1
  16. package/dist/react-resizable-panels.development.cjs.js +417 -108
  17. package/dist/react-resizable-panels.development.cjs.mjs +2 -1
  18. package/dist/react-resizable-panels.development.esm.js +417 -109
  19. package/dist/react-resizable-panels.development.node.cjs.js +282 -76
  20. package/dist/react-resizable-panels.development.node.cjs.mjs +2 -1
  21. package/dist/react-resizable-panels.development.node.esm.js +282 -77
  22. package/dist/react-resizable-panels.esm.js +385 -109
  23. package/dist/react-resizable-panels.esm.js.map +1 -0
  24. package/dist/react-resizable-panels.node.cjs.js +254 -76
  25. package/dist/react-resizable-panels.node.cjs.mjs +2 -1
  26. package/dist/react-resizable-panels.node.esm.js +254 -77
  27. package/package.json +1 -1
  28. package/src/Panel.ts +32 -32
  29. package/src/PanelContexts.ts +4 -2
  30. package/src/PanelGroup.ts +221 -111
  31. package/src/hooks/useWindowSplitterBehavior.ts +14 -11
  32. package/src/index.ts +11 -3
  33. package/src/types.ts +2 -1
  34. package/src/utils/group.ts +327 -28
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,6 +113,7 @@ 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;
@@ -126,7 +121,7 @@ function PanelWithForwardedRef({
126
121
  defaultSize: number | null;
127
122
  id: string;
128
123
  idWasAutoGenerated: boolean;
129
- maxSize: number;
124
+ maxSize: number | null;
130
125
  minSize: number;
131
126
  order: number | null;
132
127
  }>({
@@ -140,6 +135,7 @@ function PanelWithForwardedRef({
140
135
  minSize,
141
136
  order,
142
137
  });
138
+
143
139
  useIsomorphicLayoutEffect(() => {
144
140
  committedValuesRef.current.size = parseSizeFromStyle(style);
145
141
 
@@ -150,7 +146,7 @@ function PanelWithForwardedRef({
150
146
  panelDataRef.current.id = panelId;
151
147
  panelDataRef.current.idWasAutoGenerated = idFromProps == null;
152
148
  panelDataRef.current.maxSize = maxSize;
153
- panelDataRef.current.minSize = minSize;
149
+ panelDataRef.current.minSize = minSize as number;
154
150
  panelDataRef.current.order = order;
155
151
  });
156
152
 
@@ -170,12 +166,16 @@ function PanelWithForwardedRef({
170
166
  getCollapsed() {
171
167
  return committedValuesRef.current.size === 0;
172
168
  },
173
- getSize() {
174
- return committedValuesRef.current.size;
169
+ getId() {
170
+ return panelId;
171
+ },
172
+ getSize(units) {
173
+ return getPanelSize(panelId, units);
175
174
  },
176
- resize: (percentage: number) => resizePanel(panelId, percentage),
175
+ resize: (percentage: number, units) =>
176
+ resizePanel(panelId, percentage, units),
177
177
  }),
178
- [collapsePanel, expandPanel, panelId, resizePanel]
178
+ [collapsePanel, expandPanel, getPanelSize, panelId, resizePanel]
179
179
  );
180
180
 
181
181
  return createElement(Type, {
@@ -1,20 +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
22
  PanelGroupContext.displayName = "PanelGroupContext";