mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
retain local appState props on restore (#2224)
Co-authored-by: Lipis <lipiridis@gmail.com>
This commit is contained in:
parent
b91f929503
commit
7618ca48d7
9 changed files with 153 additions and 69 deletions
|
@ -23,11 +23,11 @@ const loadFileContents = async (blob: any) => {
|
|||
return contents;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param blob
|
||||
* @param appState if provided, used for centering scroll to restored scene
|
||||
*/
|
||||
export const loadFromBlob = async (blob: any, appState?: AppState) => {
|
||||
export const loadFromBlob = async (
|
||||
blob: any,
|
||||
/** @see restore.localAppState */
|
||||
localAppState: AppState | null,
|
||||
) => {
|
||||
if (blob.handle) {
|
||||
// TODO: Make this part of `AppState`.
|
||||
(window as any).handle = blob.handle;
|
||||
|
@ -39,16 +39,19 @@ export const loadFromBlob = async (blob: any, appState?: AppState) => {
|
|||
if (data.type !== "excalidraw") {
|
||||
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
||||
}
|
||||
return restore({
|
||||
elements: data.elements,
|
||||
appState: {
|
||||
appearance: appState?.appearance,
|
||||
...cleanAppStateForExport(data.appState || {}),
|
||||
...(appState
|
||||
? calculateScrollCenter(data.elements || [], appState, null)
|
||||
: {}),
|
||||
return restore(
|
||||
{
|
||||
elements: data.elements,
|
||||
appState: {
|
||||
appearance: localAppState?.appearance,
|
||||
...cleanAppStateForExport(data.appState || {}),
|
||||
...(localAppState
|
||||
? calculateScrollCenter(data.elements || [], localAppState, null)
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
});
|
||||
localAppState,
|
||||
);
|
||||
} catch {
|
||||
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue