ソースを参照

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.
Christopher Chedeau 5 年 前
コミット
61f301c3e0
1 ファイル変更13 行追加7 行削除
  1. 13 7
      src/scene/data.ts

+ 13 - 7
src/scene/data.ts

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