Cleanup saved json file (#578)

It turns out the only thing we need to save in the appState is the background color. All the rest is transient data.

I added `"type": "excalidraw"` at the beginning to explain where it was.

I removed `"source": "http://localhost:3000/"`. I don't think we want to leak on which webpage it was saved from.

I removed `isSelected` from the json

I added indentation so it's easier to read the content. I'm not 100% sure on this one, but I figure filesize doesn't matter too much those days. And if we want to shrink it, there are more effective ways than json.
This commit is contained in:
Christopher Chedeau 2020-01-26 02:30:34 -08:00 committed by David Luzar
parent 3901ad7dbe
commit 61f301c3e0

View File

@ -27,14 +27,20 @@ interface DataState {
export function serializeAsJSON( export function serializeAsJSON(
elements: readonly ExcalidrawElement[], elements: readonly ExcalidrawElement[],
appState?: AppState, appState: AppState,
): string { ): string {
return JSON.stringify({ return JSON.stringify(
version: 1, {
source: window.location.origin, type: "excalidraw",
elements: elements.map(({ shape, ...el }) => el), version: 1,
appState: appState || getDefaultAppState(), appState: {
}); viewBackgroundColor: appState.viewBackgroundColor,
},
elements: elements.map(({ shape, isSelected, ...el }) => el),
},
null,
2,
);
} }
function calculateScroll( function calculateScroll(