react-resizable-panels 1.0.2 → 1.0.3
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 -1
- package/dist/react-resizable-panels.browser.cjs.js +33 -21
- package/dist/react-resizable-panels.browser.development.cjs.js +33 -21
- package/dist/react-resizable-panels.browser.development.esm.js +33 -21
- package/dist/react-resizable-panels.browser.esm.js +33 -21
- package/dist/react-resizable-panels.cjs.js +33 -21
- package/dist/react-resizable-panels.development.cjs.js +33 -21
- package/dist/react-resizable-panels.development.esm.js +33 -21
- package/dist/react-resizable-panels.development.node.cjs.js +23 -12
- package/dist/react-resizable-panels.development.node.esm.js +23 -12
- package/dist/react-resizable-panels.esm.js +33 -21
- package/dist/react-resizable-panels.node.cjs.js +23 -12
- package/dist/react-resizable-panels.node.esm.js +23 -12
- package/package.json +1 -1
- package/src/PanelGroup.ts +26 -8
- package/src/utils/serialization.ts +33 -18
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { PanelData } from "../Panel";
|
|
2
2
|
import { PanelGroupStorage } from "../PanelGroup";
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
export type PanelConfigurationState = {
|
|
5
|
+
expandToSizes: {
|
|
6
|
+
[panelId: string]: number;
|
|
7
|
+
};
|
|
8
|
+
layout: number[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type SerializedPanelGroupState = {
|
|
12
|
+
[panelIds: string]: PanelConfigurationState;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function getPanelGroupKey(autoSaveId: string): string {
|
|
16
|
+
return `react-resizable-panels:${autoSaveId}`;
|
|
17
|
+
}
|
|
5
18
|
|
|
6
19
|
// Note that Panel ids might be user-provided (stable) or useId generated (non-deterministic)
|
|
7
20
|
// so they should not be used as part of the serialization key.
|
|
8
21
|
// Using the min/max size attributes should work well enough as a backup.
|
|
9
22
|
// Pre-sorting by minSize allows remembering layouts even if panels are re-ordered/dragged.
|
|
10
|
-
function
|
|
23
|
+
function getPanelKey(panels: PanelData[]): string {
|
|
11
24
|
return panels
|
|
12
25
|
.map((panel) => {
|
|
13
26
|
const { constraints, id, idIsFromProps, order } = panel;
|
|
@@ -28,11 +41,12 @@ function loadSerializedPanelGroupState(
|
|
|
28
41
|
storage: PanelGroupStorage
|
|
29
42
|
): SerializedPanelGroupState | null {
|
|
30
43
|
try {
|
|
31
|
-
const
|
|
44
|
+
const panelGroupKey = getPanelGroupKey(autoSaveId);
|
|
45
|
+
const serialized = storage.getItem(panelGroupKey);
|
|
32
46
|
if (serialized) {
|
|
33
47
|
const parsed = JSON.parse(serialized);
|
|
34
48
|
if (typeof parsed === "object" && parsed != null) {
|
|
35
|
-
return parsed;
|
|
49
|
+
return parsed as SerializedPanelGroupState;
|
|
36
50
|
}
|
|
37
51
|
}
|
|
38
52
|
} catch (error) {}
|
|
@@ -40,32 +54,33 @@ function loadSerializedPanelGroupState(
|
|
|
40
54
|
return null;
|
|
41
55
|
}
|
|
42
56
|
|
|
43
|
-
export function
|
|
57
|
+
export function loadPanelGroupState(
|
|
44
58
|
autoSaveId: string,
|
|
45
59
|
panels: PanelData[],
|
|
46
60
|
storage: PanelGroupStorage
|
|
47
|
-
):
|
|
48
|
-
const state = loadSerializedPanelGroupState(autoSaveId, storage);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return state[key] ?? null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return null;
|
|
61
|
+
): PanelConfigurationState | null {
|
|
62
|
+
const state = loadSerializedPanelGroupState(autoSaveId, storage) ?? {};
|
|
63
|
+
const panelKey = getPanelKey(panels);
|
|
64
|
+
return state[panelKey] ?? null;
|
|
55
65
|
}
|
|
56
66
|
|
|
57
|
-
export function
|
|
67
|
+
export function savePanelGroupState(
|
|
58
68
|
autoSaveId: string,
|
|
59
69
|
panels: PanelData[],
|
|
70
|
+
panelSizesBeforeCollapse: Map<string, number>,
|
|
60
71
|
sizes: number[],
|
|
61
72
|
storage: PanelGroupStorage
|
|
62
73
|
): void {
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
state
|
|
74
|
+
const panelGroupKey = getPanelGroupKey(autoSaveId);
|
|
75
|
+
const panelKey = getPanelKey(panels);
|
|
76
|
+
const state = loadSerializedPanelGroupState(autoSaveId, storage) ?? {};
|
|
77
|
+
state[panelKey] = {
|
|
78
|
+
expandToSizes: Object.fromEntries(panelSizesBeforeCollapse.entries()),
|
|
79
|
+
layout: sizes,
|
|
80
|
+
};
|
|
66
81
|
|
|
67
82
|
try {
|
|
68
|
-
storage.setItem(
|
|
83
|
+
storage.setItem(panelGroupKey, JSON.stringify(state));
|
|
69
84
|
} catch (error) {
|
|
70
85
|
console.error(error);
|
|
71
86
|
}
|