Преглед изворни кода

feat: export `serializeAsJSON` from package (#3538)

Co-authored-by: Aakansha Doshi <aakansha1216@gmail.com>
David Luzar пре 4 година
родитељ
комит
8068d1f853

+ 3 - 0
src/packages/excalidraw/CHANGELOG.md

@@ -15,6 +15,9 @@ Please add the latest change on the top under the correct section.
 
 ## Excalidraw API
 
+### Features
+
+- Expose [`serializeAsJSON`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#serializeAsJSON) helper that we use when saving Excalidraw scene to a file [#3538](https://github.com/excalidraw/excalidraw/pull/3538).
 - Add support to render custom UI in the top right corner via [`renderTopRight`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#renderTopRight) prop [#3539](https://github.com/excalidraw/excalidraw/pull/3539).
 
   This also removes the GitHub icon, keeping it local to the https://excalidraw.com app.

+ 14 - 1
src/packages/excalidraw/README_NEXT.md

@@ -716,6 +716,19 @@ import { restore } from "@excalidraw/excalidraw";
 
 This function makes sure elements and state is set to appropriate values and set to default value if not present. It is combination of [restoreElements](#restoreElements) and [restoreAppState](#restoreAppState)
 
+#### `serializeAsJSON`
+
+**_Signature_**
+
+<pre>
+serializeAsJSON({
+  elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>,
+  appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42">AppState</a>,
+}): string
+</pre>
+
+Takes the scene elements and state and returns a JSON string. Deleted `elements`as well as most properties from `AppState` are removed from the resulting JSON. (see [`serializeAsJSON()`](https://github.com/excalidraw/excalidraw/blob/master/src/data/json.ts#L16) source for details).
+
 ### Export utilities
 
 #### `exportToCanvas`
@@ -780,7 +793,7 @@ exportToSvg({
   appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42">AppState</a>,
   exportPadding?: number,
   metadata?: string,
-}
+})
 </pre>
 
 | Name | Type | Default | Description |

+ 1 - 0
src/packages/excalidraw/index.tsx

@@ -127,3 +127,4 @@ export {
   exportToBlob,
   exportToSvg,
 } from "../../packages/utils";
+export { serializeAsJSON } from "../../data/json";

+ 2 - 0
src/packages/utils.ts

@@ -97,3 +97,5 @@ export const exportToSvg = ({
     metadata,
   });
 };
+
+export { serializeAsJSON } from "../data/json";

+ 4 - 0
src/packages/utils/README.md

@@ -14,6 +14,10 @@ yarn add @excalidraw/utils
 
 ## API
 
+### `serializeAsJSON`
+
+See [`serializeAsJSON`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#serializeAsJSON) for API and description.
+
 ### `exportToBlob` (async)
 
 Export an Excalidraw diagram to a [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob).