refactor: remove payload-level schema version
This commit is contained in:
+9
-54
@@ -53,11 +53,6 @@ import {
|
||||
restoreAppState,
|
||||
restoreElements,
|
||||
} from "@excalidraw/excalidraw/data/restore";
|
||||
import {
|
||||
hasElementSchemaVersion,
|
||||
migrateSceneElements,
|
||||
SCHEMA_VERSIONS,
|
||||
} from "@excalidraw/excalidraw/data/schema";
|
||||
import { newElementWith } from "@excalidraw/element";
|
||||
import { isInitializedImageElement } from "@excalidraw/element";
|
||||
import clsx from "clsx";
|
||||
@@ -232,17 +227,6 @@ const initializeScene = async (opts: {
|
||||
const externalUrlMatch = window.location.hash.match(/^#url=(.*)$/);
|
||||
|
||||
const localDataState = importFromLocalStorage();
|
||||
const localStorageSchemaVersionSource = hasElementSchemaVersion(
|
||||
localDataState?.elements,
|
||||
)
|
||||
? {
|
||||
payloadSchemaVersion: undefined,
|
||||
fallbackVersion: SCHEMA_VERSIONS.initial,
|
||||
}
|
||||
: {
|
||||
payloadSchemaVersion: localDataState?.schemaVersion,
|
||||
fallbackVersion: SCHEMA_VERSIONS.initial,
|
||||
};
|
||||
|
||||
let scene: Omit<
|
||||
RestoredDataState,
|
||||
@@ -252,17 +236,10 @@ const initializeScene = async (opts: {
|
||||
> & {
|
||||
scrollToContent?: boolean;
|
||||
} = {
|
||||
elements: restoreElements(
|
||||
migrateSceneElements(
|
||||
localDataState?.elements,
|
||||
localStorageSchemaVersionSource,
|
||||
),
|
||||
null,
|
||||
{
|
||||
repairBindings: true,
|
||||
deleteInvisibleElements: true,
|
||||
},
|
||||
),
|
||||
elements: restoreElements(localDataState?.elements, null, {
|
||||
repairBindings: true,
|
||||
deleteInvisibleElements: true,
|
||||
}),
|
||||
appState: restoreAppState(localDataState?.appState, null),
|
||||
};
|
||||
|
||||
@@ -285,17 +262,10 @@ const initializeScene = async (opts: {
|
||||
|
||||
scene = {
|
||||
elements: bumpElementVersions(
|
||||
restoreElements(
|
||||
migrateSceneElements(imported.elements, {
|
||||
payloadSchemaVersion: imported.schemaVersion,
|
||||
fallbackVersion: SCHEMA_VERSIONS.initial,
|
||||
}),
|
||||
null,
|
||||
{
|
||||
repairBindings: true,
|
||||
deleteInvisibleElements: true,
|
||||
},
|
||||
),
|
||||
restoreElements(imported.elements, null, {
|
||||
repairBindings: true,
|
||||
deleteInvisibleElements: true,
|
||||
}),
|
||||
scene.elements,
|
||||
),
|
||||
appState: restoreAppState(
|
||||
@@ -579,24 +549,9 @@ const ExcalidrawWrapper = () => {
|
||||
if (isBrowserStorageStateNewer(STORAGE_KEYS.VERSION_DATA_STATE)) {
|
||||
const localDataState = importFromLocalStorage();
|
||||
const username = importUsernameFromLocalStorage();
|
||||
const localStorageSchemaVersionSource = hasElementSchemaVersion(
|
||||
localDataState?.elements,
|
||||
)
|
||||
? {
|
||||
payloadSchemaVersion: undefined,
|
||||
fallbackVersion: SCHEMA_VERSIONS.initial,
|
||||
}
|
||||
: {
|
||||
payloadSchemaVersion: localDataState?.schemaVersion,
|
||||
fallbackVersion: SCHEMA_VERSIONS.initial,
|
||||
};
|
||||
const migratedElements = migrateSceneElements(
|
||||
localDataState?.elements,
|
||||
localStorageSchemaVersionSource,
|
||||
);
|
||||
setLangCode(getPreferredLanguage());
|
||||
excalidrawAPI.updateScene({
|
||||
elements: restoreElements(migratedElements, null, {
|
||||
elements: restoreElements(localDataState?.elements, null, {
|
||||
repairBindings: true,
|
||||
deleteInvisibleElements: true,
|
||||
}),
|
||||
|
||||
@@ -39,7 +39,6 @@ export const ROOM_ID_BYTES = 10;
|
||||
export const STORAGE_KEYS = {
|
||||
LOCAL_STORAGE_ELEMENTS: "excalidraw",
|
||||
LOCAL_STORAGE_APP_STATE: "excalidraw-state",
|
||||
LOCAL_STORAGE_SCHEMA_VERSION: "excalidraw-schema-version",
|
||||
LOCAL_STORAGE_COLLAB: "excalidraw-collab",
|
||||
LOCAL_STORAGE_THEME: "excalidraw-theme",
|
||||
LOCAL_STORAGE_DEBUG: "excalidraw-debug",
|
||||
|
||||
@@ -28,7 +28,6 @@ import {
|
||||
|
||||
import { appJotaiStore, atom } from "excalidraw-app/app-jotai";
|
||||
import { getNonDeletedElements } from "@excalidraw/element";
|
||||
import { SCHEMA_VERSIONS } from "@excalidraw/excalidraw/data/schema";
|
||||
|
||||
import type { LibraryPersistedData } from "@excalidraw/excalidraw/data/library";
|
||||
import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
|
||||
@@ -87,12 +86,7 @@ const saveDataStateToLocalStorage = (
|
||||
_appState.openSidebar = null;
|
||||
}
|
||||
|
||||
const persistedElements = getNonDeletedElements(elements).map(
|
||||
(element) => ({
|
||||
...element,
|
||||
schemaVersion: SCHEMA_VERSIONS.latest,
|
||||
}),
|
||||
);
|
||||
const persistedElements = getNonDeletedElements(elements);
|
||||
|
||||
localStorage.setItem(
|
||||
STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS,
|
||||
@@ -102,10 +96,6 @@ const saveDataStateToLocalStorage = (
|
||||
STORAGE_KEYS.LOCAL_STORAGE_APP_STATE,
|
||||
JSON.stringify(_appState),
|
||||
);
|
||||
localStorage.setItem(
|
||||
STORAGE_KEYS.LOCAL_STORAGE_SCHEMA_VERSION,
|
||||
`${SCHEMA_VERSIONS.latest}`,
|
||||
);
|
||||
updateBrowserStateVersion(STORAGE_KEYS.VERSION_DATA_STATE);
|
||||
if (localStorageQuotaExceeded) {
|
||||
appJotaiStore.set(localStorageQuotaExceededAtom, false);
|
||||
|
||||
@@ -196,7 +196,6 @@ const legacy_decodeFromBackend = async ({
|
||||
return {
|
||||
elements: data.elements || null,
|
||||
appState: data.appState || null,
|
||||
schemaVersion: data.schemaVersion,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -227,7 +226,6 @@ export const importFromBackend = async (
|
||||
return {
|
||||
elements: data.elements || null,
|
||||
appState: data.appState || null,
|
||||
schemaVersion: data.schemaVersion,
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.warn(
|
||||
|
||||
@@ -2,10 +2,6 @@ import {
|
||||
clearAppStateForLocalStorage,
|
||||
getDefaultAppState,
|
||||
} from "@excalidraw/excalidraw/appState";
|
||||
import {
|
||||
resolveSchemaVersion,
|
||||
SCHEMA_VERSIONS,
|
||||
} from "@excalidraw/excalidraw/data/schema";
|
||||
|
||||
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
||||
import type { AppState } from "@excalidraw/excalidraw/types";
|
||||
@@ -41,14 +37,10 @@ export const importUsernameFromLocalStorage = (): string | null => {
|
||||
export const importFromLocalStorage = () => {
|
||||
let savedElements = null;
|
||||
let savedState = null;
|
||||
let savedSchemaVersion = null;
|
||||
|
||||
try {
|
||||
savedElements = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS);
|
||||
savedState = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_APP_STATE);
|
||||
savedSchemaVersion = localStorage.getItem(
|
||||
STORAGE_KEYS.LOCAL_STORAGE_SCHEMA_VERSION,
|
||||
);
|
||||
} catch (error: any) {
|
||||
// Unable to access localStorage
|
||||
console.error(error);
|
||||
@@ -78,12 +70,7 @@ export const importFromLocalStorage = () => {
|
||||
// Do nothing because appState is already null
|
||||
}
|
||||
}
|
||||
const schemaVersion = resolveSchemaVersion(
|
||||
Number(savedSchemaVersion),
|
||||
SCHEMA_VERSIONS.initial,
|
||||
);
|
||||
|
||||
return { elements, appState, schemaVersion };
|
||||
return { elements, appState };
|
||||
};
|
||||
|
||||
export const getElementsStorageSize = () => {
|
||||
|
||||
Reference in New Issue
Block a user