Skip to content

Commit 196f970

Browse files
committed
feat: persist and export gridStep/gridModeEnabled app state
- Add gridStep and gridModeEnabled to getPersistedAppState so these settings survive page reload and collaborative sync - Include gridStep and gridModeEnabled in exportDrawingToFile and exportFromEditor so exported .excalidraw files carry grid config - Both fields are optional and only included when non-null, preserving backward compatibility with drawings that lack these fields Change-Id: Icd8a403a56470122ca2ea197e20b9597a468cecc
1 parent 278bc45 commit 196f970

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

frontend/src/pages/editor/shared.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ describe("editor/shared scene guards", () => {
157157
getPersistedAppState({
158158
viewBackgroundColor: "#123456",
159159
gridSize: 24,
160+
gridStep: 5,
161+
gridModeEnabled: true,
160162
cursorButton: "down",
161163
activeTool: { type: "hand", locked: false, lastActiveTool: null },
162164
selectedElementIds: { a: true },
@@ -169,6 +171,8 @@ describe("editor/shared scene guards", () => {
169171
).toEqual({
170172
viewBackgroundColor: "#123456",
171173
gridSize: 24,
174+
gridStep: 5,
175+
gridModeEnabled: true,
172176
});
173177
});
174178

frontend/src/pages/editor/shared.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ type BuildRemoteSceneUpdateInput = {
3131
incomingFiles?: Record<string, any>;
3232
};
3333

34-
export const getPersistedAppState = (appState: Record<string, any> | null | undefined) => ({
35-
viewBackgroundColor: appState?.viewBackgroundColor ?? "#ffffff",
36-
gridSize: appState?.gridSize ?? null,
37-
});
34+
export const getPersistedAppState = (appState: Record<string, any> | null | undefined) => {
35+
const base: Record<string, any> = {
36+
viewBackgroundColor: appState?.viewBackgroundColor ?? "#ffffff",
37+
gridSize: appState?.gridSize ?? null,
38+
};
39+
if (appState?.gridStep != null) base.gridStep = appState.gridStep;
40+
if (appState?.gridModeEnabled != null) base.gridModeEnabled = appState.gridModeEnabled;
41+
return base;
42+
};
3843

3944
export const buildRemoteSceneUpdate = ({
4045
collaborators,

frontend/src/utils/exportUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export const exportDrawingToFile = (
2323
elements: drawing.elements || [],
2424
appState: {
2525
gridSize: drawing.appState?.gridSize ?? null,
26+
...(drawing.appState?.gridStep != null && { gridStep: drawing.appState.gridStep }),
27+
...(drawing.appState?.gridModeEnabled != null && { gridModeEnabled: drawing.appState.gridModeEnabled }),
2628
viewBackgroundColor: drawing.appState?.viewBackgroundColor ?? "#ffffff",
2729
},
2830
files: drawing.files || {},
@@ -58,6 +60,8 @@ export const exportFromEditor = (
5860
elements: Array.from(elements),
5961
appState: {
6062
gridSize: appState?.gridSize ?? null,
63+
...(appState?.gridStep != null && { gridStep: appState.gridStep }),
64+
...(appState?.gridModeEnabled != null && { gridModeEnabled: appState.gridModeEnabled }),
6165
viewBackgroundColor: appState?.viewBackgroundColor ?? "#ffffff",
6266
},
6367
files: files || {},

0 commit comments

Comments
 (0)