diff --git a/src/data/restore.ts b/src/data/restore.ts index 675b080d..2a12c639 100644 --- a/src/data/restore.ts +++ b/src/data/restore.ts @@ -141,7 +141,7 @@ export const restoreElements = ( }, [] as ExcalidrawElement[]); }; -const restoreAppState = ( +export const restoreAppState = ( appState: ImportedDataState["appState"], localAppState: Partial | null, ): AppState => { diff --git a/src/packages/excalidraw/CHANGELOG.md b/src/packages/excalidraw/CHANGELOG.md index c8709648..6f000ab3 100644 --- a/src/packages/excalidraw/CHANGELOG.md +++ b/src/packages/excalidraw/CHANGELOG.md @@ -12,6 +12,14 @@ The change should be grouped under one of the below section and must contain PR Please add the latest change on the top under the correct section. --> +## [Unreleased] + +## Excalidraw API + +### Features + +- Export [`restore`](https://github.com/excalidraw/excalidraw/blob/master/src/data/restore.ts#L182), [`restoreAppState`](https://github.com/excalidraw/excalidraw/blob/master/src/data/restore.ts#L144) and [`restoreElements`](https://github.com/excalidraw/excalidraw/blob/master/src/data/restore.ts#L128) to host + ## 0.3.1 ## Excalidraw API diff --git a/src/packages/excalidraw/README.md b/src/packages/excalidraw/README.md index 620455ef..ba2e3ecf 100644 --- a/src/packages/excalidraw/README.md +++ b/src/packages/excalidraw/README.md @@ -252,51 +252,6 @@ export default function IndexPage() { | [`zenModeEnabled`](#zenModeEnabled) | boolean | | This implies if the zen mode is enabled | | [`gridModeEnabled`](#gridModeEnabled) | boolean | | This implies if the grid mode is enabled | -### `Extra API's` - -#### `getSceneVersion` - -**How to use** - -
-import { getSceneVersion } from "@excalidraw/excalidraw";
-getSceneVersion(elements:  ExcalidrawElement[])
-
- -This function returns the current scene version. - -#### `getSyncableElements` - -**_Signature_** - -
-getSyncableElements(elements:  ExcalidrawElement[]):ExcalidrawElement[]
-
- -**How to use** - -```js -import { getSyncableElements } from "@excalidraw/excalidraw"; -``` - -This function returns all the deleted elements of the scene. - -### `getElementMap` - -**_Signature_** - -
-getElementsMap(elements:  ExcalidrawElement[]): {[id: string]: ExcalidrawElement}
-
- -**How to use** - -```js -import { getElementsMap } from "@excalidraw/excalidraw"; -``` - -This function returns an object where each element is mapped to its id. - #### `width` This props defines the `width` of the Excalidraw component. Defaults to `window.innerWidth` if not passed. @@ -451,3 +406,98 @@ This prop indicates whether the app is in `zen mode`. When supplied, the value t #### `gridModeEnabled` This prop indicates whether the shows the grid. When supplied, the value takes precedence over `intialData.appState.gridModeEnabled`, the grid will be fully controlled by the host app, and users won't be able to toggle it from within the app. + +### Extra API's + +#### `getSceneVersion` + +**How to use** + +
+import { getSceneVersion } from "@excalidraw/excalidraw";
+getSceneVersion(elements:  ExcalidrawElement[])
+
+ +This function returns the current scene version. + +#### `getSyncableElements` + +**_Signature_** + +
+getSyncableElements(elements:  ExcalidrawElement[]):ExcalidrawElement[]
+
+ +**How to use** + +```js +import { getSyncableElements } from "@excalidraw/excalidraw"; +``` + +This function returns all the deleted elements of the scene. + +#### `getElementMap` + +**_Signature_** + +
+getElementsMap(elements:  ExcalidrawElement[]): {[id: string]: ExcalidrawElement}
+
+ +**How to use** + +```js +import { getElementsMap } from "@excalidraw/excalidraw"; +``` + +This function returns an object where each element is mapped to its id. + +**_The below api's will be available in [next version](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/CHANGELOG.md#unreleased)_** + +#### `restoreAppState` + +**_Signature_** + +
+restoreAppState(appState:  ImportedDataState["appState"], localAppState: Partial<AppState> | null): AppState
+
+ +**_How to use_** + +```js +import { restoreAppState } from "@excalidraw/excalidraw"; +``` + +This function will make sure all the keys have appropriate values in [appState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L37) and if any key is missing, it will be set to default value. If you pass `localAppState`, `localAppState` value will be preferred over the `appState` passed in params. + +#### `restoreElements` + +**_Signature_** + +
+restoreElements(elements:  ImportedDataState["elements"]): ExcalidrawElement[]
+
+ +**_How to use_** + +```js +import { restoreElements } from "@excalidraw/excalidraw"; +``` + +This function will make sure all properties of element is correctly set and if any attribute is missing, it will be set to default value. + +#### `restore` + +**_Signature_** + +
+restoreElements(data:  ImportedDataState): DataState
+
+ +**_How to use_** + +```js +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) diff --git a/src/packages/excalidraw/index.tsx b/src/packages/excalidraw/index.tsx index 82f9f5dd..222ac966 100644 --- a/src/packages/excalidraw/index.tsx +++ b/src/packages/excalidraw/index.tsx @@ -106,3 +106,4 @@ export { getElementMap, } from "../../element"; export { defaultLang, languages } from "../../i18n"; +export { restore, restoreAppState, restoreElements } from "../../data/restore";