fix: wire schema scopes at import boundaries
This commit is contained in:
+21
-12
@@ -244,10 +244,13 @@ const initializeScene = async (opts: {
|
|||||||
elements: restoreElements(
|
elements: restoreElements(
|
||||||
migrateElementsBySchema(
|
migrateElementsBySchema(
|
||||||
localDataState?.elements,
|
localDataState?.elements,
|
||||||
resolveSchemaVersion(
|
{
|
||||||
localDataState?.schemaVersion,
|
schemaVersion: resolveSchemaVersion(
|
||||||
SCHEMA_VERSIONS.initial,
|
localDataState?.schemaVersion,
|
||||||
),
|
SCHEMA_VERSIONS.initial,
|
||||||
|
),
|
||||||
|
scope: "scene",
|
||||||
|
},
|
||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
{
|
{
|
||||||
@@ -280,10 +283,13 @@ const initializeScene = async (opts: {
|
|||||||
restoreElements(
|
restoreElements(
|
||||||
migrateElementsBySchema(
|
migrateElementsBySchema(
|
||||||
imported.elements,
|
imported.elements,
|
||||||
resolveSchemaVersion(
|
{
|
||||||
imported.schemaVersion,
|
schemaVersion: resolveSchemaVersion(
|
||||||
SCHEMA_VERSIONS.initial,
|
imported.schemaVersion,
|
||||||
),
|
SCHEMA_VERSIONS.initial,
|
||||||
|
),
|
||||||
|
scope: "scene",
|
||||||
|
},
|
||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
{
|
{
|
||||||
@@ -576,10 +582,13 @@ const ExcalidrawWrapper = () => {
|
|||||||
const username = importUsernameFromLocalStorage();
|
const username = importUsernameFromLocalStorage();
|
||||||
const migratedElements = migrateElementsBySchema(
|
const migratedElements = migrateElementsBySchema(
|
||||||
localDataState?.elements,
|
localDataState?.elements,
|
||||||
resolveSchemaVersion(
|
{
|
||||||
localDataState?.schemaVersion,
|
schemaVersion: resolveSchemaVersion(
|
||||||
SCHEMA_VERSIONS.initial,
|
localDataState?.schemaVersion,
|
||||||
),
|
SCHEMA_VERSIONS.initial,
|
||||||
|
),
|
||||||
|
scope: "scene",
|
||||||
|
},
|
||||||
);
|
);
|
||||||
setLangCode(getPreferredLanguage());
|
setLangCode(getPreferredLanguage());
|
||||||
excalidrawAPI.updateScene({
|
excalidrawAPI.updateScene({
|
||||||
|
|||||||
@@ -359,6 +359,7 @@ import {
|
|||||||
migrateElementsBySchema,
|
migrateElementsBySchema,
|
||||||
resolveSchemaVersion,
|
resolveSchemaVersion,
|
||||||
SCHEMA_VERSIONS,
|
SCHEMA_VERSIONS,
|
||||||
|
type SchemaMigrationScope,
|
||||||
} from "../data/schema";
|
} from "../data/schema";
|
||||||
import { getCenter, getDistance } from "../gesture";
|
import { getCenter, getDistance } from "../gesture";
|
||||||
import { History } from "../history";
|
import { History } from "../history";
|
||||||
@@ -2331,6 +2332,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
elements,
|
elements,
|
||||||
position: "center",
|
position: "center",
|
||||||
files: null,
|
files: null,
|
||||||
|
schemaVersion: SCHEMA_VERSIONS.latest,
|
||||||
|
migrationScope: "api",
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2818,7 +2821,13 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const restoredElements = restoreElements(
|
const restoredElements = restoreElements(
|
||||||
migrateElementsBySchema(
|
migrateElementsBySchema(
|
||||||
initialData?.elements,
|
initialData?.elements,
|
||||||
resolveSchemaVersion(initialData?.schemaVersion, initialDataSchemaFallback),
|
{
|
||||||
|
schemaVersion: resolveSchemaVersion(
|
||||||
|
initialData?.schemaVersion,
|
||||||
|
initialDataSchemaFallback,
|
||||||
|
),
|
||||||
|
scope: "scene",
|
||||||
|
},
|
||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
{
|
{
|
||||||
@@ -3593,6 +3602,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
schemaVersion: data.programmaticAPI
|
schemaVersion: data.programmaticAPI
|
||||||
? SCHEMA_VERSIONS.latest
|
? SCHEMA_VERSIONS.latest
|
||||||
: resolveSchemaVersion(data.schemaVersion, SCHEMA_VERSIONS.initial),
|
: resolveSchemaVersion(data.schemaVersion, SCHEMA_VERSIONS.initial),
|
||||||
|
migrationScope: data.programmaticAPI ? "api" : "clipboard",
|
||||||
position:
|
position:
|
||||||
this.editorInterface.formFactor === "desktop" ? "cursor" : "center",
|
this.editorInterface.formFactor === "desktop" ? "cursor" : "center",
|
||||||
retainSeed: isPlainPaste,
|
retainSeed: isPlainPaste,
|
||||||
@@ -3619,6 +3629,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.addElementsFromPasteOrLibrary({
|
this.addElementsFromPasteOrLibrary({
|
||||||
elements,
|
elements,
|
||||||
files,
|
files,
|
||||||
|
schemaVersion: SCHEMA_VERSIONS.latest,
|
||||||
|
migrationScope: "api",
|
||||||
position:
|
position:
|
||||||
this.editorInterface.formFactor === "desktop" ? "cursor" : "center",
|
this.editorInterface.formFactor === "desktop" ? "cursor" : "center",
|
||||||
});
|
});
|
||||||
@@ -3737,6 +3749,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
elements: readonly ExcalidrawElement[];
|
elements: readonly ExcalidrawElement[];
|
||||||
files: BinaryFiles | null;
|
files: BinaryFiles | null;
|
||||||
schemaVersion?: number;
|
schemaVersion?: number;
|
||||||
|
migrationScope: SchemaMigrationScope;
|
||||||
position: { clientX: number; clientY: number } | "cursor" | "center";
|
position: { clientX: number; clientY: number } | "cursor" | "center";
|
||||||
retainSeed?: boolean;
|
retainSeed?: boolean;
|
||||||
fitToContent?: boolean;
|
fitToContent?: boolean;
|
||||||
@@ -3744,7 +3757,13 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const elements = restoreElements(
|
const elements = restoreElements(
|
||||||
migrateElementsBySchema(
|
migrateElementsBySchema(
|
||||||
opts.elements,
|
opts.elements,
|
||||||
resolveSchemaVersion(opts.schemaVersion, SCHEMA_VERSIONS.latest),
|
{
|
||||||
|
schemaVersion: resolveSchemaVersion(
|
||||||
|
opts.schemaVersion,
|
||||||
|
SCHEMA_VERSIONS.latest,
|
||||||
|
),
|
||||||
|
scope: opts.migrationScope,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
{
|
{
|
||||||
@@ -11519,6 +11538,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
elements: distributeLibraryItemsOnSquareGrid(libraryItems),
|
elements: distributeLibraryItemsOnSquareGrid(libraryItems),
|
||||||
position: event,
|
position: event,
|
||||||
files: null,
|
files: null,
|
||||||
|
schemaVersion: SCHEMA_VERSIONS.latest,
|
||||||
|
migrationScope: "library",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import type {
|
|||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
|
|
||||||
import { EditorLocalStorage } from "../../data/EditorLocalStorage";
|
import { EditorLocalStorage } from "../../data/EditorLocalStorage";
|
||||||
|
import { SCHEMA_VERSIONS } from "../../data/schema";
|
||||||
import {
|
import {
|
||||||
convertToExcalidrawElements,
|
convertToExcalidrawElements,
|
||||||
exportToCanvas,
|
exportToCanvas,
|
||||||
@@ -148,6 +149,8 @@ export const insertToEditor = ({
|
|||||||
app.addElementsFromPasteOrLibrary({
|
app.addElementsFromPasteOrLibrary({
|
||||||
elements: newElements,
|
elements: newElements,
|
||||||
files,
|
files,
|
||||||
|
schemaVersion: SCHEMA_VERSIONS.latest,
|
||||||
|
migrationScope: "api",
|
||||||
position: "center",
|
position: "center",
|
||||||
fitToContent: true,
|
fitToContent: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -168,7 +168,10 @@ export const loadSceneOrLibraryFromBlob = async (
|
|||||||
);
|
);
|
||||||
const migratedElements = migrateElementsBySchema(
|
const migratedElements = migrateElementsBySchema(
|
||||||
data.elements,
|
data.elements,
|
||||||
schemaVersion,
|
{
|
||||||
|
schemaVersion,
|
||||||
|
scope: "scene",
|
||||||
|
},
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
type: MIME_TYPES.excalidraw,
|
type: MIME_TYPES.excalidraw,
|
||||||
|
|||||||
@@ -964,7 +964,10 @@ const restoreLibraryItem = (
|
|||||||
const elements = restoreElements(
|
const elements = restoreElements(
|
||||||
migrateElementsBySchema(
|
migrateElementsBySchema(
|
||||||
getNonDeletedElements(libraryItem.elements),
|
getNonDeletedElements(libraryItem.elements),
|
||||||
schemaVersion,
|
{
|
||||||
|
schemaVersion,
|
||||||
|
scope: "library",
|
||||||
|
},
|
||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user