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

Co-authored-by: Aakansha Doshi <aakansha1216@gmail.com>
This commit is contained in:
David Luzar 2021-05-12 00:24:41 +02:00 committed by GitHub
parent 92c7d3257f
commit 8068d1f853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 1 deletions

View File

@ -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.

View File

@ -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 |

View File

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

View File

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

View File

@ -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).