diff --git a/excalidraw-app/App.tsx b/excalidraw-app/App.tsx index da7e73d51e..b41bc4e01c 100644 --- a/excalidraw-app/App.tsx +++ b/excalidraw-app/App.tsx @@ -244,10 +244,13 @@ const initializeScene = async (opts: { elements: restoreElements( migrateElementsBySchema( localDataState?.elements, - resolveSchemaVersion( - localDataState?.schemaVersion, - SCHEMA_VERSIONS.initial, - ), + { + schemaVersion: resolveSchemaVersion( + localDataState?.schemaVersion, + SCHEMA_VERSIONS.initial, + ), + scope: "scene", + }, ), null, { @@ -280,10 +283,13 @@ const initializeScene = async (opts: { restoreElements( migrateElementsBySchema( imported.elements, - resolveSchemaVersion( - imported.schemaVersion, - SCHEMA_VERSIONS.initial, - ), + { + schemaVersion: resolveSchemaVersion( + imported.schemaVersion, + SCHEMA_VERSIONS.initial, + ), + scope: "scene", + }, ), null, { @@ -576,10 +582,13 @@ const ExcalidrawWrapper = () => { const username = importUsernameFromLocalStorage(); const migratedElements = migrateElementsBySchema( localDataState?.elements, - resolveSchemaVersion( - localDataState?.schemaVersion, - SCHEMA_VERSIONS.initial, - ), + { + schemaVersion: resolveSchemaVersion( + localDataState?.schemaVersion, + SCHEMA_VERSIONS.initial, + ), + scope: "scene", + }, ); setLangCode(getPreferredLanguage()); excalidrawAPI.updateScene({ diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index 34d5a108c5..780b6c50c2 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -359,6 +359,7 @@ import { migrateElementsBySchema, resolveSchemaVersion, SCHEMA_VERSIONS, + type SchemaMigrationScope, } from "../data/schema"; import { getCenter, getDistance } from "../gesture"; import { History } from "../history"; @@ -2331,6 +2332,8 @@ class App extends React.Component { elements, position: "center", files: null, + schemaVersion: SCHEMA_VERSIONS.latest, + migrationScope: "api", }); }; @@ -2818,7 +2821,13 @@ class App extends React.Component { const restoredElements = restoreElements( migrateElementsBySchema( initialData?.elements, - resolveSchemaVersion(initialData?.schemaVersion, initialDataSchemaFallback), + { + schemaVersion: resolveSchemaVersion( + initialData?.schemaVersion, + initialDataSchemaFallback, + ), + scope: "scene", + }, ), null, { @@ -3593,6 +3602,7 @@ class App extends React.Component { schemaVersion: data.programmaticAPI ? SCHEMA_VERSIONS.latest : resolveSchemaVersion(data.schemaVersion, SCHEMA_VERSIONS.initial), + migrationScope: data.programmaticAPI ? "api" : "clipboard", position: this.editorInterface.formFactor === "desktop" ? "cursor" : "center", retainSeed: isPlainPaste, @@ -3619,6 +3629,8 @@ class App extends React.Component { this.addElementsFromPasteOrLibrary({ elements, files, + schemaVersion: SCHEMA_VERSIONS.latest, + migrationScope: "api", position: this.editorInterface.formFactor === "desktop" ? "cursor" : "center", }); @@ -3737,6 +3749,7 @@ class App extends React.Component { elements: readonly ExcalidrawElement[]; files: BinaryFiles | null; schemaVersion?: number; + migrationScope: SchemaMigrationScope; position: { clientX: number; clientY: number } | "cursor" | "center"; retainSeed?: boolean; fitToContent?: boolean; @@ -3744,7 +3757,13 @@ class App extends React.Component { const elements = restoreElements( migrateElementsBySchema( opts.elements, - resolveSchemaVersion(opts.schemaVersion, SCHEMA_VERSIONS.latest), + { + schemaVersion: resolveSchemaVersion( + opts.schemaVersion, + SCHEMA_VERSIONS.latest, + ), + scope: opts.migrationScope, + }, ), null, { @@ -11519,6 +11538,8 @@ class App extends React.Component { elements: distributeLibraryItemsOnSquareGrid(libraryItems), position: event, files: null, + schemaVersion: SCHEMA_VERSIONS.latest, + migrationScope: "library", }); } } catch (error: any) { diff --git a/packages/excalidraw/components/TTDDialog/common.ts b/packages/excalidraw/components/TTDDialog/common.ts index f00f409132..63b0c0d5f4 100644 --- a/packages/excalidraw/components/TTDDialog/common.ts +++ b/packages/excalidraw/components/TTDDialog/common.ts @@ -6,6 +6,7 @@ import type { } from "@excalidraw/element/types"; import { EditorLocalStorage } from "../../data/EditorLocalStorage"; +import { SCHEMA_VERSIONS } from "../../data/schema"; import { convertToExcalidrawElements, exportToCanvas, @@ -148,6 +149,8 @@ export const insertToEditor = ({ app.addElementsFromPasteOrLibrary({ elements: newElements, files, + schemaVersion: SCHEMA_VERSIONS.latest, + migrationScope: "api", position: "center", fitToContent: true, }); diff --git a/packages/excalidraw/data/blob.ts b/packages/excalidraw/data/blob.ts index f211329f17..a936c34436 100644 --- a/packages/excalidraw/data/blob.ts +++ b/packages/excalidraw/data/blob.ts @@ -168,7 +168,10 @@ export const loadSceneOrLibraryFromBlob = async ( ); const migratedElements = migrateElementsBySchema( data.elements, - schemaVersion, + { + schemaVersion, + scope: "scene", + }, ); return { type: MIME_TYPES.excalidraw, diff --git a/packages/excalidraw/data/restore.ts b/packages/excalidraw/data/restore.ts index 0c5d4f0b43..783ab8d495 100644 --- a/packages/excalidraw/data/restore.ts +++ b/packages/excalidraw/data/restore.ts @@ -964,7 +964,10 @@ const restoreLibraryItem = ( const elements = restoreElements( migrateElementsBySchema( getNonDeletedElements(libraryItem.elements), - schemaVersion, + { + schemaVersion, + scope: "library", + }, ), null, );