Virtual whiteboard for sketching hand-drawn like diagrams
feat: allow props.initialData to be a function (#8135)
Esteban Romo6ba9bd60e86d
diff --git a/packages/excalidraw/CHANGELOG.md b/packages/excalidraw/CHANGELOG.mdindex c0e497c937..cb58d6ab6f 100644--- a/packages/excalidraw/CHANGELOG.md+++ b/packages/excalidraw/CHANGELOG.md@@ -15,6 +15,8 @@ Please add the latest change on the top under the correct section.### Features+- `props.initialData` can now be a function that returns `ExcalidrawInitialDataState` or `Promise<ExcalidrawInitialDataState>`. [#8107](https://github.com/excalidraw/excalidraw/pull/8135)+- Added support for multiplayer undo/redo, by calculating invertible increments and storing them inside the local-only undo/redo stacks. [#7348](https://github.com/excalidraw/excalidraw/pull/7348)- `MainMenu.DefaultItems.ToggleTheme` now supports `onSelect(theme: string)` callback, and optionally `allowSystemTheme: boolean` alongside `theme: string` to indicate you want to allow users to set to system theme (you need to handle this yourself). [#7853](https://github.com/excalidraw/excalidraw/pull/7853)diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsxindex d1031caf8f..3fcde774a5 100644--- a/packages/excalidraw/components/App.tsx+++ b/packages/excalidraw/components/App.tsx@@ -2291,7 +2291,11 @@ class App extends React.Component<AppProps, AppState> {}let initialData = null;try {- initialData = (await this.props.initialData) || null;+ if (typeof this.props.initialData === "function") {+ initialData = (await this.props.initialData()) || null;+ } else {+ initialData = (await this.props.initialData) || null;+ }if (initialData?.libraryItems) {this.library.updateLibrary({diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.tsindex 87f594c5db..cb428f695d 100644--- a/packages/excalidraw/types.ts+++ b/packages/excalidraw/types.ts@@ -444,7 +444,9 @@ export interface ExcalidrawProps {appState: AppState,files: BinaryFiles,) => void;- initialData?: MaybePromise<ExcalidrawInitialDataState | null>;+ initialData?:+ | (() => MaybePromise<ExcalidrawInitialDataState | null>)+ | MaybePromise<ExcalidrawInitialDataState | null>;excalidrawAPI?: (api: ExcalidrawImperativeAPI) => void;isCollaborating?: boolean;onPointerUpdate?: (payload: {