|
@@ -4,7 +4,7 @@ import {
|
|
ExcalidrawSelectionElement,
|
|
ExcalidrawSelectionElement,
|
|
} from "../element/types";
|
|
} from "../element/types";
|
|
import { AppState, NormalizedZoomValue } from "../types";
|
|
import { AppState, NormalizedZoomValue } from "../types";
|
|
-import { DataState, ImportedDataState } from "./types";
|
|
|
|
|
|
+import { ImportedDataState } from "./types";
|
|
import { isInvisiblySmallElement, getNormalizedDimensions } from "../element";
|
|
import { isInvisiblySmallElement, getNormalizedDimensions } from "../element";
|
|
import { isLinearElementType } from "../element/typeChecks";
|
|
import { isLinearElementType } from "../element/typeChecks";
|
|
import { randomId } from "../random";
|
|
import { randomId } from "../random";
|
|
@@ -16,6 +16,16 @@ import {
|
|
} from "../constants";
|
|
} from "../constants";
|
|
import { getDefaultAppState } from "../appState";
|
|
import { getDefaultAppState } from "../appState";
|
|
|
|
|
|
|
|
+type RestoredAppState = Omit<
|
|
|
|
+ AppState,
|
|
|
|
+ "offsetTop" | "offsetLeft" | "width" | "height"
|
|
|
|
+>;
|
|
|
|
+
|
|
|
|
+export type RestoredDataState = {
|
|
|
|
+ elements: ExcalidrawElement[];
|
|
|
|
+ appState: RestoredAppState;
|
|
|
|
+};
|
|
|
|
+
|
|
const getFontFamilyByName = (fontFamilyName: string): FontFamily => {
|
|
const getFontFamilyByName = (fontFamilyName: string): FontFamily => {
|
|
for (const [id, fontFamilyString] of Object.entries(FONT_FAMILY)) {
|
|
for (const [id, fontFamilyString] of Object.entries(FONT_FAMILY)) {
|
|
if (fontFamilyString.includes(fontFamilyName)) {
|
|
if (fontFamilyString.includes(fontFamilyName)) {
|
|
@@ -144,7 +154,7 @@ export const restoreElements = (
|
|
export const restoreAppState = (
|
|
export const restoreAppState = (
|
|
appState: ImportedDataState["appState"],
|
|
appState: ImportedDataState["appState"],
|
|
localAppState: Partial<AppState> | null,
|
|
localAppState: Partial<AppState> | null,
|
|
-): DataState["appState"] => {
|
|
|
|
|
|
+): RestoredAppState => {
|
|
appState = appState || {};
|
|
appState = appState || {};
|
|
|
|
|
|
const defaultAppState = getDefaultAppState();
|
|
const defaultAppState = getDefaultAppState();
|
|
@@ -186,7 +196,7 @@ export const restore = (
|
|
* Supply `null` if you can't get access to it.
|
|
* Supply `null` if you can't get access to it.
|
|
*/
|
|
*/
|
|
localAppState: Partial<AppState> | null | undefined,
|
|
localAppState: Partial<AppState> | null | undefined,
|
|
-): DataState => {
|
|
|
|
|
|
+): RestoredDataState => {
|
|
return {
|
|
return {
|
|
elements: restoreElements(data?.elements),
|
|
elements: restoreElements(data?.elements),
|
|
appState: restoreAppState(data?.appState, localAppState || null),
|
|
appState: restoreAppState(data?.appState, localAppState || null),
|