react-resizable-panels 0.0.30 → 0.0.31
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 +5 -0
- package/README.md +4 -2
- package/dist/react-resizable-panels.d.ts +2 -0
- package/dist/react-resizable-panels.d.ts.map +1 -1
- package/dist/react-resizable-panels.js +46 -23
- package/dist/react-resizable-panels.js.map +1 -1
- package/dist/react-resizable-panels.module.js +47 -24
- package/dist/react-resizable-panels.module.js.map +1 -1
- package/package.json +1 -1
- package/src/Panel.ts +37 -10
- package/src/PanelGroup.ts +9 -4
- package/src/hooks/useWindowSplitterBehavior.ts +4 -1
- package/src/utils/group.ts +13 -4
- package/src/utils/serialization.ts +1 -1
package/src/PanelGroup.ts
CHANGED
|
@@ -105,6 +105,7 @@ export function PanelGroup({
|
|
|
105
105
|
panels,
|
|
106
106
|
setSizes,
|
|
107
107
|
sizes,
|
|
108
|
+
panelSizeBeforeCollapse,
|
|
108
109
|
});
|
|
109
110
|
|
|
110
111
|
// Notify external code when sizes have changed.
|
|
@@ -288,7 +289,8 @@ export function PanelGroup({
|
|
|
288
289
|
idBefore,
|
|
289
290
|
idAfter,
|
|
290
291
|
delta,
|
|
291
|
-
prevSizes
|
|
292
|
+
prevSizes,
|
|
293
|
+
panelSizeBeforeCollapse.current
|
|
292
294
|
);
|
|
293
295
|
if (prevSizes === nextSizes) {
|
|
294
296
|
// If the pointer has moved too far to resize the panel any further,
|
|
@@ -368,7 +370,8 @@ export function PanelGroup({
|
|
|
368
370
|
idBefore,
|
|
369
371
|
idAfter,
|
|
370
372
|
delta,
|
|
371
|
-
prevSizes
|
|
373
|
+
prevSizes,
|
|
374
|
+
panelSizeBeforeCollapse.current
|
|
372
375
|
);
|
|
373
376
|
if (prevSizes !== nextSizes) {
|
|
374
377
|
// If resize change handlers have been declared, this is the time to call them.
|
|
@@ -418,7 +421,8 @@ export function PanelGroup({
|
|
|
418
421
|
idBefore,
|
|
419
422
|
idAfter,
|
|
420
423
|
delta,
|
|
421
|
-
prevSizes
|
|
424
|
+
prevSizes,
|
|
425
|
+
panelSizeBeforeCollapse.current
|
|
422
426
|
);
|
|
423
427
|
if (prevSizes !== nextSizes) {
|
|
424
428
|
// If resize change handlers have been declared, this is the time to call them.
|
|
@@ -461,7 +465,8 @@ export function PanelGroup({
|
|
|
461
465
|
idBefore,
|
|
462
466
|
idAfter,
|
|
463
467
|
delta,
|
|
464
|
-
prevSizes
|
|
468
|
+
prevSizes,
|
|
469
|
+
panelSizeBeforeCollapse.current
|
|
465
470
|
);
|
|
466
471
|
if (prevSizes !== nextSizes) {
|
|
467
472
|
// If resize change handlers have been declared, this is the time to call them.
|
|
@@ -24,12 +24,14 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
24
24
|
panels,
|
|
25
25
|
setSizes,
|
|
26
26
|
sizes,
|
|
27
|
+
panelSizeBeforeCollapse,
|
|
27
28
|
}: {
|
|
28
29
|
committedValuesRef: RefObject<CommittedValues>;
|
|
29
30
|
groupId: string;
|
|
30
31
|
panels: PanelDataMap;
|
|
31
32
|
setSizes: (sizes: number[]) => void;
|
|
32
33
|
sizes: number[];
|
|
34
|
+
panelSizeBeforeCollapse: RefObject<Map<string, number>>;
|
|
33
35
|
}): void {
|
|
34
36
|
useEffect(() => {
|
|
35
37
|
const { direction, panels } = committedValuesRef.current;
|
|
@@ -104,7 +106,8 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
104
106
|
idBefore,
|
|
105
107
|
idAfter,
|
|
106
108
|
delta,
|
|
107
|
-
sizes
|
|
109
|
+
sizes,
|
|
110
|
+
panelSizeBeforeCollapse.current
|
|
108
111
|
);
|
|
109
112
|
if (sizes !== nextSizes) {
|
|
110
113
|
setSizes(nextSizes);
|
package/src/utils/group.ts
CHANGED
|
@@ -6,7 +6,8 @@ export function adjustByDelta(
|
|
|
6
6
|
idBefore: string,
|
|
7
7
|
idAfter: string,
|
|
8
8
|
delta: number,
|
|
9
|
-
prevSizes: number[]
|
|
9
|
+
prevSizes: number[],
|
|
10
|
+
panelSizeBeforeCollapse: Map<string, number>
|
|
10
11
|
): number[] {
|
|
11
12
|
if (delta === 0) {
|
|
12
13
|
return prevSizes;
|
|
@@ -37,6 +38,10 @@ export function adjustByDelta(
|
|
|
37
38
|
if (prevSize === nextSize) {
|
|
38
39
|
return prevSizes;
|
|
39
40
|
} else {
|
|
41
|
+
if (nextSize === 0 && prevSize > 0) {
|
|
42
|
+
panelSizeBeforeCollapse.set(pivotId, prevSize);
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
delta = delta < 0 ? prevSize - nextSize : nextSize - prevSize;
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -49,6 +54,10 @@ export function adjustByDelta(
|
|
|
49
54
|
|
|
50
55
|
const nextSize = safeResizePanel(panel, 0 - Math.abs(delta), prevSize);
|
|
51
56
|
if (prevSize !== nextSize) {
|
|
57
|
+
if (nextSize === 0 && prevSize > 0) {
|
|
58
|
+
panelSizeBeforeCollapse.set(panel.id, prevSize);
|
|
59
|
+
}
|
|
60
|
+
|
|
52
61
|
deltaApplied += prevSize - nextSize;
|
|
53
62
|
|
|
54
63
|
nextSizes[index] = nextSize;
|
|
@@ -182,7 +191,7 @@ export function getResizeHandleIndex(id: string): number | null {
|
|
|
182
191
|
const index = handles.findIndex(
|
|
183
192
|
(handle) => handle.getAttribute("data-panel-resize-handle-id") === id
|
|
184
193
|
);
|
|
185
|
-
return index
|
|
194
|
+
return index || null;
|
|
186
195
|
}
|
|
187
196
|
|
|
188
197
|
export function getResizeHandles(): HTMLDivElement[] {
|
|
@@ -206,8 +215,8 @@ export function getResizeHandlePanelIds(
|
|
|
206
215
|
const handles = getResizeHandlesForGroup(groupId);
|
|
207
216
|
const index = handles.indexOf(handle);
|
|
208
217
|
|
|
209
|
-
const idBefore: string | null = panelsArray[index]?.id
|
|
210
|
-
const idAfter: string | null = panelsArray[index + 1]?.id
|
|
218
|
+
const idBefore: string | null = panelsArray[index]?.id || null;
|
|
219
|
+
const idAfter: string | null = panelsArray[index + 1]?.id || null;
|
|
211
220
|
|
|
212
221
|
return [idBefore, idAfter];
|
|
213
222
|
}
|