fix: wire schema scopes at import boundaries
This commit is contained in:
+21
-12
@@ -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({
|
||||
|
||||
@@ -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<AppProps, AppState> {
|
||||
elements,
|
||||
position: "center",
|
||||
files: null,
|
||||
schemaVersion: SCHEMA_VERSIONS.latest,
|
||||
migrationScope: "api",
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2818,7 +2821,13 @@ class App extends React.Component<AppProps, AppState> {
|
||||
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<AppProps, AppState> {
|
||||
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<AppProps, AppState> {
|
||||
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<AppProps, AppState> {
|
||||
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<AppProps, AppState> {
|
||||
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<AppProps, AppState> {
|
||||
elements: distributeLibraryItemsOnSquareGrid(libraryItems),
|
||||
position: event,
|
||||
files: null,
|
||||
schemaVersion: SCHEMA_VERSIONS.latest,
|
||||
migrationScope: "library",
|
||||
});
|
||||
}
|
||||
} catch (error: any) {
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -168,7 +168,10 @@ export const loadSceneOrLibraryFromBlob = async (
|
||||
);
|
||||
const migratedElements = migrateElementsBySchema(
|
||||
data.elements,
|
||||
schemaVersion,
|
||||
{
|
||||
schemaVersion,
|
||||
scope: "scene",
|
||||
},
|
||||
);
|
||||
return {
|
||||
type: MIME_TYPES.excalidraw,
|
||||
|
||||
@@ -964,7 +964,10 @@ const restoreLibraryItem = (
|
||||
const elements = restoreElements(
|
||||
migrateElementsBySchema(
|
||||
getNonDeletedElements(libraryItem.elements),
|
||||
schemaVersion,
|
||||
{
|
||||
schemaVersion,
|
||||
scope: "library",
|
||||
},
|
||||
),
|
||||
null,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user