|
@@ -10,11 +10,7 @@ import {
|
|
NormalizedZoomValue,
|
|
NormalizedZoomValue,
|
|
} from "../types";
|
|
} from "../types";
|
|
import { ImportedDataState } from "./types";
|
|
import { ImportedDataState } from "./types";
|
|
-import {
|
|
|
|
- getElementMap,
|
|
|
|
- getNormalizedDimensions,
|
|
|
|
- isInvisiblySmallElement,
|
|
|
|
-} from "../element";
|
|
|
|
|
|
+import { getNormalizedDimensions, isInvisiblySmallElement } from "../element";
|
|
import { isLinearElementType } from "../element/typeChecks";
|
|
import { isLinearElementType } from "../element/typeChecks";
|
|
import { randomId } from "../random";
|
|
import { randomId } from "../random";
|
|
import {
|
|
import {
|
|
@@ -27,6 +23,7 @@ import { getDefaultAppState } from "../appState";
|
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
|
import { bumpVersion } from "../element/mutateElement";
|
|
import { bumpVersion } from "../element/mutateElement";
|
|
import { getUpdatedTimestamp } from "../utils";
|
|
import { getUpdatedTimestamp } from "../utils";
|
|
|
|
+import { arrayToMap } from "../utils";
|
|
|
|
|
|
type RestoredAppState = Omit<
|
|
type RestoredAppState = Omit<
|
|
AppState,
|
|
AppState,
|
|
@@ -206,14 +203,14 @@ export const restoreElements = (
|
|
/** NOTE doesn't serve for reconciliation */
|
|
/** NOTE doesn't serve for reconciliation */
|
|
localElements: readonly ExcalidrawElement[] | null | undefined,
|
|
localElements: readonly ExcalidrawElement[] | null | undefined,
|
|
): ExcalidrawElement[] => {
|
|
): ExcalidrawElement[] => {
|
|
- const localElementsMap = localElements ? getElementMap(localElements) : null;
|
|
|
|
|
|
+ const localElementsMap = localElements ? arrayToMap(localElements) : null;
|
|
return (elements || []).reduce((elements, element) => {
|
|
return (elements || []).reduce((elements, element) => {
|
|
// filtering out selection, which is legacy, no longer kept in elements,
|
|
// filtering out selection, which is legacy, no longer kept in elements,
|
|
// and causing issues if retained
|
|
// and causing issues if retained
|
|
if (element.type !== "selection" && !isInvisiblySmallElement(element)) {
|
|
if (element.type !== "selection" && !isInvisiblySmallElement(element)) {
|
|
let migratedElement: ExcalidrawElement | null = restoreElement(element);
|
|
let migratedElement: ExcalidrawElement | null = restoreElement(element);
|
|
if (migratedElement) {
|
|
if (migratedElement) {
|
|
- const localElement = localElementsMap?.[element.id];
|
|
|
|
|
|
+ const localElement = localElementsMap?.get(element.id);
|
|
if (localElement && localElement.version > migratedElement.version) {
|
|
if (localElement && localElement.version > migratedElement.version) {
|
|
migratedElement = bumpVersion(migratedElement, localElement.version);
|
|
migratedElement = bumpVersion(migratedElement, localElement.version);
|
|
}
|
|
}
|