diff --git a/src/packages/excalidraw/CHANGELOG.md b/src/packages/excalidraw/CHANGELOG.md index 5b223aaa..3de5552b 100644 --- a/src/packages/excalidraw/CHANGELOG.md +++ b/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. diff --git a/src/packages/excalidraw/README_NEXT.md b/src/packages/excalidraw/README_NEXT.md index 2e71b5bc..a5118681 100644 --- a/src/packages/excalidraw/README_NEXT.md +++ b/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_** + +
+serializeAsJSON({
+  elements: ExcalidrawElement[],
+  appState: AppState,
+}): string
+
+ +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: AppState, exportPadding?: number, metadata?: string, -} +}) | Name | Type | Default | Description | diff --git a/src/packages/excalidraw/index.tsx b/src/packages/excalidraw/index.tsx index 2922a7f1..017e7b7d 100644 --- a/src/packages/excalidraw/index.tsx +++ b/src/packages/excalidraw/index.tsx @@ -127,3 +127,4 @@ export { exportToBlob, exportToSvg, } from "../../packages/utils"; +export { serializeAsJSON } from "../../data/json"; diff --git a/src/packages/utils.ts b/src/packages/utils.ts index 9749ee79..b26499dd 100644 --- a/src/packages/utils.ts +++ b/src/packages/utils.ts @@ -97,3 +97,5 @@ export const exportToSvg = ({ metadata, }); }; + +export { serializeAsJSON } from "../data/json"; diff --git a/src/packages/utils/README.md b/src/packages/utils/README.md index 15ef2e42..420f49f1 100644 --- a/src/packages/utils/README.md +++ b/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).