diff --git a/excalidraw-app/App.tsx b/excalidraw-app/App.tsx index 8b9f940382..3c7e96ec6b 100644 --- a/excalidraw-app/App.tsx +++ b/excalidraw-app/App.tsx @@ -55,6 +55,7 @@ import { } from "@excalidraw/excalidraw/data/restore"; import { newElementWith } from "@excalidraw/element"; import { isInitializedImageElement } from "@excalidraw/element"; +import { CURRENT_SCHEMA_VERSION, getSchemaVersion } from "@excalidraw/element"; import clsx from "clsx"; import { parseLibraryTokensFromUrl, @@ -243,6 +244,7 @@ const initializeScene = async (opts: { elements: restoreElements(localDataState?.elements, null, { repairBindings: true, deleteInvisibleElements: true, + schemaVersion: localDataState?.schemaVersion, }), appState: restoreAppState(localDataState?.appState, null), }; @@ -269,6 +271,7 @@ const initializeScene = async (opts: { restoreElements(imported.elements, null, { repairBindings: true, deleteInvisibleElements: true, + schemaVersion: getSchemaVersion(imported), }), localDataState?.elements, ), @@ -583,8 +586,12 @@ const ExcalidrawWrapper = () => { loadImages(data); if (data.scene) { excalidrawAPI.updateScene({ + // NOTE: scene elements passed through restore during + // initialization, so they are already at the current + // schema version elements: restoreElements(data.scene.elements, null, { repairBindings: true, + schemaVersion: CURRENT_SCHEMA_VERSION, }), appState: restoreAppState(data.scene.appState, null), captureUpdate: CaptureUpdateAction.IMMEDIATELY, diff --git a/excalidraw-app/app_constants.ts b/excalidraw-app/app_constants.ts index e4370e7986..a856eb74c1 100644 --- a/excalidraw-app/app_constants.ts +++ b/excalidraw-app/app_constants.ts @@ -38,6 +38,7 @@ export const ROOM_ID_BYTES = 10; export const STORAGE_KEYS = { LOCAL_STORAGE_ELEMENTS: "excalidraw", + LOCAL_STORAGE_SCHEMA_VERSION: "excalidraw-schema-version", LOCAL_STORAGE_APP_STATE: "excalidraw-state", LOCAL_STORAGE_COLLAB: "excalidraw-collab", LOCAL_STORAGE_THEME: "excalidraw-theme", diff --git a/excalidraw-app/collab/Collab.tsx b/excalidraw-app/collab/Collab.tsx index 34d225b37e..bb7e12e7c7 100644 --- a/excalidraw-app/collab/Collab.tsx +++ b/excalidraw-app/collab/Collab.tsx @@ -22,6 +22,7 @@ import { decryptData } from "@excalidraw/excalidraw/data/encryption"; import { getVisibleSceneBounds } from "@excalidraw/element"; import { newElementWith } from "@excalidraw/element"; import { isImageElement, isInitializedImageElement } from "@excalidraw/element"; +import { CURRENT_SCHEMA_VERSION, getSchemaVersion } from "@excalidraw/element"; import { AbortError } from "@excalidraw/excalidraw/errors"; import { t } from "@excalidraw/excalidraw/i18n"; import { withBatchedUpdates } from "@excalidraw/excalidraw/reactUtils"; @@ -597,8 +598,10 @@ class Collab extends PureComponent { const remoteElements = toBrandedType< readonly RemoteExcalidrawElement[] >(decryptedData.payload.elements); - const reconciledElements = - this._reconcileElements(remoteElements); + const reconciledElements = this._reconcileElements( + remoteElements, + getSchemaVersion(decryptedData.payload), + ); this.handleRemoteSceneUpdate(reconciledElements); // noop if already resolved via init from firebase scenePromise.resolve({ @@ -614,6 +617,7 @@ class Collab extends PureComponent { toBrandedType( decryptedData.payload.elements, ), + getSchemaVersion(decryptedData.payload), ), ); break; @@ -760,15 +764,27 @@ class Collab extends PureComponent { private _reconcileElements = ( remoteElements: readonly RemoteExcalidrawElement[], + remoteSchemaVersion: number = 0, ): ReconciledExcalidrawElement[] => { const appState = this.excalidrawAPI.getAppState(); const existingElements = this.getSceneElementsIncludingDeleted(); + if (remoteSchemaVersion > CURRENT_SCHEMA_VERSION) { + // NOTE: remote client is newer than us; we can't downgrade its elements, + // so restore as-is and rely on unknown properties being preserved + console.warn( + `Received collab update with schema version ${remoteSchemaVersion} ` + + `(local: ${CURRENT_SCHEMA_VERSION})`, + ); + } + // NOTE ideally we restore _after_ reconciliation but we can't do that // as we'd regenerate even elements such as appState.newElement which would // break the state - remoteElements = restoreElements(remoteElements, existingElements); + remoteElements = restoreElements(remoteElements, existingElements, { + schemaVersion: remoteSchemaVersion, + }); let reconciledElements = reconcileElements( existingElements, diff --git a/excalidraw-app/collab/Portal.tsx b/excalidraw-app/collab/Portal.tsx index 2e076a661e..11b4d32062 100644 --- a/excalidraw-app/collab/Portal.tsx +++ b/excalidraw-app/collab/Portal.tsx @@ -2,6 +2,7 @@ import { CaptureUpdateAction } from "@excalidraw/excalidraw"; import { trackEvent } from "@excalidraw/excalidraw/analytics"; import { encryptData } from "@excalidraw/excalidraw/data/encryption"; import { newElementWith } from "@excalidraw/element"; +import { CURRENT_SCHEMA_VERSION } from "@excalidraw/element"; import throttle from "lodash.throttle"; import type { UserIdleState } from "@excalidraw/common"; @@ -167,6 +168,7 @@ class Portal { type: updateType, payload: { elements: syncableElements, + schemaVersion: CURRENT_SCHEMA_VERSION, }, }; diff --git a/excalidraw-app/data/LocalData.ts b/excalidraw-app/data/LocalData.ts index d09d8aa88e..dc58167217 100644 --- a/excalidraw-app/data/LocalData.ts +++ b/excalidraw-app/data/LocalData.ts @@ -27,6 +27,7 @@ import { } from "idb-keyval"; import { getNonDeletedElements } from "@excalidraw/element"; +import { CURRENT_SCHEMA_VERSION } from "@excalidraw/element"; import type { LibraryPersistedData } from "@excalidraw/excalidraw/data/library"; import type { ImportedDataState } from "@excalidraw/excalidraw/data/types"; @@ -91,6 +92,10 @@ const saveDataStateToLocalStorage = ( STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS, JSON.stringify(getNonDeletedElements(elements)), ); + localStorage.setItem( + STORAGE_KEYS.LOCAL_STORAGE_SCHEMA_VERSION, + JSON.stringify(CURRENT_SCHEMA_VERSION), + ); localStorage.setItem( STORAGE_KEYS.LOCAL_STORAGE_APP_STATE, JSON.stringify(_appState), diff --git a/excalidraw-app/data/firebase.ts b/excalidraw-app/data/firebase.ts index 11177d90aa..722e60c6ec 100644 --- a/excalidraw-app/data/firebase.ts +++ b/excalidraw-app/data/firebase.ts @@ -7,6 +7,7 @@ import { } from "@excalidraw/excalidraw/data/encryption"; import { restoreElements } from "@excalidraw/excalidraw/data/restore"; import { getSceneVersion } from "@excalidraw/element"; +import { CURRENT_SCHEMA_VERSION, getSchemaVersion } from "@excalidraw/element"; import { initializeApp } from "firebase/app"; import { getFirestore, @@ -86,6 +87,7 @@ export const loadFirebaseStorage = async () => { type FirebaseStoredScene = { sceneVersion: number; + schemaVersion?: number; iv: Bytes; ciphertext: Bytes; }; @@ -179,6 +181,7 @@ const createFirebaseSceneDocument = async ( const { ciphertext, iv } = await encryptElements(roomKey, elements); return { sceneVersion, + schemaVersion: CURRENT_SCHEMA_VERSION, ciphertext: Bytes.fromUint8Array(new Uint8Array(ciphertext)), iv: Bytes.fromUint8Array(iv), } as FirebaseStoredScene; @@ -216,7 +219,9 @@ export const saveToFirebase = async ( const prevStoredScene = snapshot.data() as FirebaseStoredScene; const prevStoredElements = getSyncableElements( - restoreElements(await decryptElements(prevStoredScene, roomKey), null), + restoreElements(await decryptElements(prevStoredScene, roomKey), null, { + schemaVersion: getSchemaVersion(prevStoredScene), + }), ); const reconciledElements = getSyncableElements( reconcileElements( @@ -238,7 +243,9 @@ export const saveToFirebase = async ( }); const storedElements = getSyncableElements( - restoreElements(await decryptElements(storedScene, roomKey), null), + restoreElements(await decryptElements(storedScene, roomKey), null, { + schemaVersion: getSchemaVersion(storedScene), + }), ); FirebaseSceneVersionCache.set(socket, storedElements); @@ -261,6 +268,7 @@ export const loadFromFirebase = async ( const elements = getSyncableElements( restoreElements(await decryptElements(storedScene, roomKey), null, { deleteInvisibleElements: true, + schemaVersion: getSchemaVersion(storedScene), }), ); diff --git a/excalidraw-app/data/index.ts b/excalidraw-app/data/index.ts index bf765941a2..2946196743 100644 --- a/excalidraw-app/data/index.ts +++ b/excalidraw-app/data/index.ts @@ -10,6 +10,7 @@ import { import { serializeAsJSON } from "@excalidraw/excalidraw/data/json"; import { isInvisiblySmallElement } from "@excalidraw/element"; import { isInitializedImageElement } from "@excalidraw/element"; +import { getSchemaVersion } from "@excalidraw/element"; import { t } from "@excalidraw/excalidraw/i18n"; import { bytesToHexString } from "@excalidraw/common"; @@ -84,12 +85,14 @@ export type SocketUpdateDataSource = { type: WS_SUBTYPES.INIT; payload: { elements: readonly OrderedExcalidrawElement[]; + schemaVersion?: number; }; }; SCENE_UPDATE: { type: WS_SUBTYPES.UPDATE; payload: { elements: readonly OrderedExcalidrawElement[]; + schemaVersion?: number; }; }; MOUSE_LOCATION: { @@ -196,6 +199,7 @@ const legacy_decodeFromBackend = async ({ return { elements: data.elements || null, appState: data.appState || null, + schemaVersion: getSchemaVersion(data), }; }; @@ -226,6 +230,7 @@ export const importFromBackend = async ( return { elements: data.elements || null, appState: data.appState || null, + schemaVersion: getSchemaVersion(data), }; } catch (error: any) { console.warn( diff --git a/excalidraw-app/data/localStorage.ts b/excalidraw-app/data/localStorage.ts index 28c166cd74..c5294d7223 100644 --- a/excalidraw-app/data/localStorage.ts +++ b/excalidraw-app/data/localStorage.ts @@ -3,6 +3,8 @@ import { getDefaultAppState, } from "@excalidraw/excalidraw/appState"; +import { getSchemaVersion } from "@excalidraw/element"; + import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { AppState } from "@excalidraw/excalidraw/types"; @@ -37,10 +39,14 @@ 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); @@ -56,6 +62,17 @@ export const importFromLocalStorage = () => { } } + let schemaVersion: number | undefined; + if (savedSchemaVersion) { + try { + schemaVersion = getSchemaVersion({ + schemaVersion: JSON.parse(savedSchemaVersion), + }); + } catch (error: any) { + console.error(error); + } + } + let appState = null; if (savedState) { try { @@ -70,7 +87,7 @@ export const importFromLocalStorage = () => { // Do nothing because appState is already null } } - return { elements, appState }; + return { elements, appState, schemaVersion }; }; export const getElementsStorageSize = () => { diff --git a/packages/element/src/__tests__/__snapshots__/transform.test.ts.snap b/packages/element/src/__tests__/__snapshots__/transform.test.ts.snap index 7814a7ffdc..5488f6448b 100644 --- a/packages/element/src/__tests__/__snapshots__/transform.test.ts.snap +++ b/packages/element/src/__tests__/__snapshots__/transform.test.ts.snap @@ -28,7 +28,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#66a80f", "strokeStyle": "solid", @@ -67,7 +66,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#9c36b5", "strokeStyle": "solid", @@ -121,7 +119,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": { @@ -184,7 +181,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": { @@ -232,7 +228,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -279,7 +274,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t "originalText": "HEYYYYY", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#c2255c", "strokeStyle": "solid", @@ -329,7 +323,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t "originalText": "Whats up ?", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -391,7 +384,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": { @@ -442,7 +434,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t "originalText": "HELLO WORLD!!", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -504,7 +495,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": { @@ -555,7 +545,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe "originalText": "HELLO WORLD!!", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -597,7 +586,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -636,7 +624,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -695,7 +682,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": { @@ -746,7 +732,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when "originalText": "HELLO WORLD!!", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -796,7 +781,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when "originalText": "HEYYYYY", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -846,7 +830,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when "originalText": "WHATS UP ?", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -883,7 +866,6 @@ exports[`Test Transform > should not allow duplicate ids 1`] = ` "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -930,7 +912,6 @@ exports[`Test Transform > should transform linear elements 1`] = ` ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": null, @@ -979,7 +960,6 @@ exports[`Test Transform > should transform linear elements 2`] = ` ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": "dot", "startBinding": null, @@ -1028,7 +1008,6 @@ exports[`Test Transform > should transform linear elements 3`] = ` "polygon": false, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": null, @@ -1077,7 +1056,6 @@ exports[`Test Transform > should transform linear elements 4`] = ` "polygon": false, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": null, @@ -1113,7 +1091,6 @@ exports[`Test Transform > should transform regular shapes 1`] = ` "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1147,7 +1124,6 @@ exports[`Test Transform > should transform regular shapes 2`] = ` "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1181,7 +1157,6 @@ exports[`Test Transform > should transform regular shapes 3`] = ` "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1215,7 +1190,6 @@ exports[`Test Transform > should transform regular shapes 4`] = ` "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1249,7 +1223,6 @@ exports[`Test Transform > should transform regular shapes 5`] = ` "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "dotted", @@ -1283,7 +1256,6 @@ exports[`Test Transform > should transform regular shapes 6`] = ` "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1971c2", "strokeStyle": "dashed", @@ -1325,7 +1297,6 @@ exports[`Test Transform > should transform text element 1`] = ` "originalText": "HELLO WORLD!", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1370,7 +1341,6 @@ exports[`Test Transform > should transform text element 2`] = ` "originalText": "STYLED HELLO WORLD!", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#5f3dc4", "strokeStyle": "solid", @@ -1418,7 +1388,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1459,7 +1428,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1504,7 +1472,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1553,7 +1520,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1614,7 +1580,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "roundness": { "type": 2, }, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": { @@ -1680,7 +1645,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "roundness": { "type": 2, }, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": { @@ -1733,7 +1697,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "originalText": "B", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1780,7 +1743,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "originalText": "A", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1827,7 +1789,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "originalText": "Alice", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1874,7 +1835,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "originalText": "Bob", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1919,7 +1879,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "originalText": "How are you?", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1964,7 +1923,6 @@ exports[`Test Transform > should transform the elements correctly when linear el "originalText": "Friendship", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2019,7 +1977,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": null, @@ -2073,7 +2030,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": null, @@ -2127,7 +2083,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": null, @@ -2181,7 +2136,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide ], "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "startArrowhead": null, "startBinding": null, @@ -2225,7 +2179,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide "originalText": "LABELED ARROW", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2270,7 +2223,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide "originalText": "STYLED LABELED ARROW", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#099268", "strokeStyle": "solid", @@ -2315,7 +2267,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide "originalText": "ANOTHER STYLED LABELLED ARROW", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1098ad", "strokeStyle": "solid", @@ -2361,7 +2312,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide "originalText": "ANOTHER STYLED LABELLED ARROW", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#099268", "strokeStyle": "solid", @@ -2404,7 +2354,6 @@ exports[`Test Transform > should transform to text containers when label provide "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2443,7 +2392,6 @@ exports[`Test Transform > should transform to text containers when label provide "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2482,7 +2430,6 @@ exports[`Test Transform > should transform to text containers when label provide "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2521,7 +2468,6 @@ exports[`Test Transform > should transform to text containers when label provide "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2560,7 +2506,6 @@ exports[`Test Transform > should transform to text containers when label provide "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#c2255c", "strokeStyle": "solid", @@ -2599,7 +2544,6 @@ exports[`Test Transform > should transform to text containers when label provide "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#f08c00", "strokeStyle": "solid", @@ -2641,7 +2585,6 @@ exports[`Test Transform > should transform to text containers when label provide "originalText": "RECTANGLE TEXT CONTAINER", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2686,7 +2629,6 @@ exports[`Test Transform > should transform to text containers when label provide "originalText": "ELLIPSE TEXT CONTAINER", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2733,7 +2675,6 @@ exports[`Test Transform > should transform to text containers when label provide TEXT CONTAINER", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2780,7 +2721,6 @@ exports[`Test Transform > should transform to text containers when label provide "originalText": "STYLED DIAMOND TEXT CONTAINER", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#099268", "strokeStyle": "solid", @@ -2826,7 +2766,6 @@ exports[`Test Transform > should transform to text containers when label provide "originalText": "TOP LEFT ALIGNED RECTANGLE TEXT CONTAINER", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#c2255c", "strokeStyle": "solid", @@ -2873,7 +2812,6 @@ exports[`Test Transform > should transform to text containers when label provide "originalText": "STYLED ELLIPSE TEXT CONTAINER", "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": Any, "strokeColor": "#c2255c", "strokeStyle": "solid", diff --git a/packages/element/src/__tests__/versioning.test.ts b/packages/element/src/__tests__/versioning.test.ts index b10f9e4b7e..f310179d4d 100644 --- a/packages/element/src/__tests__/versioning.test.ts +++ b/packages/element/src/__tests__/versioning.test.ts @@ -1,72 +1,88 @@ import { - CURRENT_ELEMENT_SCHEMA_VERSION, - getElementSchemaVersion, - upgradeElementSchema, + CURRENT_SCHEMA_VERSION, + getSchemaVersion, + migrateElement, + migrateElementPartial, + migrateElements, } from "../versioning"; -describe("element schema versioning", () => { - describe("getElementSchemaVersion", () => { - it("treats an element without schemaVersion as legacy (version 0)", () => { - expect(getElementSchemaVersion({})).toBe(0); - expect(getElementSchemaVersion({ schemaVersion: undefined })).toBe(0); +describe("scene schema versioning", () => { + describe("getSchemaVersion", () => { + it("treats a container without schemaVersion as legacy (version 0)", () => { + expect(getSchemaVersion({})).toBe(0); + expect(getSchemaVersion({ schemaVersion: undefined })).toBe(0); + expect(getSchemaVersion(null)).toBe(0); + expect(getSchemaVersion(undefined)).toBe(0); }); - it("returns the element's schemaVersion when present", () => { - expect(getElementSchemaVersion({ schemaVersion: 1 })).toBe(1); - expect(getElementSchemaVersion({ schemaVersion: 3 })).toBe(3); + it("treats an invalid schemaVersion as legacy (version 0)", () => { + expect(getSchemaVersion({ schemaVersion: "2" })).toBe(0); + expect(getSchemaVersion({ schemaVersion: NaN })).toBe(0); + expect(getSchemaVersion({ schemaVersion: Infinity })).toBe(0); + }); + + it("returns the container's schemaVersion when present", () => { + expect(getSchemaVersion({ schemaVersion: 1 })).toBe(1); + expect(getSchemaVersion({ schemaVersion: 3 })).toBe(3); }); }); - describe("upgradeElementSchema", () => { - it("lifts a legacy element to the current schema version", () => { - const legacy = { id: "a", type: "rectangle", backgroundColor: "#fff" }; + describe("migrateElements", () => { + it("lifts legacy elements through the whole migration chain", () => { + const legacy = [{ id: "a", type: "rectangle", backgroundColor: "#fff" }]; - const upgraded = upgradeElementSchema(legacy); + const migrated = migrateElements(legacy, 0); - expect(upgraded.schemaVersion).toBe(CURRENT_ELEMENT_SCHEMA_VERSION); + // v0 -> v1 migration keeps the element shape intact + expect(migrated).toEqual(legacy); }); - it("preserves all other properties when upgrading", () => { - const legacy = { id: "a", type: "rectangle", backgroundColor: "#fff" }; + it("returns the input array unchanged when already current", () => { + const elements = [{ id: "a", type: "rectangle" }]; - const upgraded = upgradeElementSchema(legacy); - - expect(upgraded).toEqual({ - ...legacy, - schemaVersion: CURRENT_ELEMENT_SCHEMA_VERSION, - }); + expect(migrateElements(elements, CURRENT_SCHEMA_VERSION)).toBe(elements); }); - it("is idempotent on an already-current element", () => { - const current = { - id: "a", - type: "rectangle", - schemaVersion: CURRENT_ELEMENT_SCHEMA_VERSION, - }; + it("returns the input array unchanged when coming from a newer client", () => { + const elements = [{ id: "a", type: "rectangle" }]; - const upgraded = upgradeElementSchema(current); - - expect(upgraded).toEqual(current); - }); - - it("does not mutate the input element", () => { - const legacy = { id: "a", type: "rectangle" }; - - upgradeElementSchema(legacy); - - expect(legacy).not.toHaveProperty("schemaVersion"); - }); - - // Template for future N -> N+1 migrations. When a real migration is added - // (e.g. repurposing an attribute at schema version 2), assert here that a - // legacy element is transformed as expected end-to-end. Kept minimal on - // purpose so it documents the pattern without asserting fake behavior. - it("runs migrations in sequence up to the current version", () => { - const upgraded = upgradeElementSchema({ id: "a", schemaVersion: 0 }); - - expect(getElementSchemaVersion(upgraded)).toBe( - CURRENT_ELEMENT_SCHEMA_VERSION, + expect(migrateElements(elements, CURRENT_SCHEMA_VERSION + 1)).toBe( + elements, ); }); }); + + describe("migrateElement", () => { + it("does not mutate the input element", () => { + const legacy = { id: "a", type: "rectangle" }; + + const migrated = migrateElement(legacy, 0); + + expect(migrated).toEqual({ id: "a", type: "rectangle" }); + expect(legacy).toEqual({ id: "a", type: "rectangle" }); + }); + }); + + describe("migrateElementPartial", () => { + it("lifts a legacy delta partial to the current schema version", () => { + const partial = { backgroundColor: "#fff", version: 2 }; + + expect(migrateElementPartial(partial, 0)).toEqual(partial); + }); + + it("returns the partial unchanged when already current", () => { + const partial = { backgroundColor: "#fff" }; + + expect(migrateElementPartial(partial, CURRENT_SCHEMA_VERSION)).toBe( + partial, + ); + }); + }); + + // Template for future migrations + it("runs migrations in sequence up to the current version", () => { + const migrated = migrateElement({ id: "a" }, 0); + + expect(migrated).toEqual({ id: "a" }); + }); }); diff --git a/packages/element/src/delta.ts b/packages/element/src/delta.ts index 8219389fd8..5f9a6a1c18 100644 --- a/packages/element/src/delta.ts +++ b/packages/element/src/delta.ts @@ -36,6 +36,8 @@ import type { import { getObservedAppState } from "./store"; +import { CURRENT_SCHEMA_VERSION, migrateElementPartial } from "./versioning"; + import { BoundElement, BindableElement, @@ -1085,9 +1087,33 @@ export class ElementsDelta implements DeltaContainer { return delta; } - public static restore(elementsDeltaDTO: DTO): ElementsDelta { + public static restore( + elementsDeltaDTO: DTO, + schemaVersion: number = CURRENT_SCHEMA_VERSION, + ): ElementsDelta { const { added, removed, updated } = elementsDeltaDTO; - return ElementsDelta.create(added, removed, updated); + return ElementsDelta.create( + ElementsDelta.migratePartialDeltas(added, schemaVersion), + ElementsDelta.migratePartialDeltas(removed, schemaVersion), + ElementsDelta.migratePartialDeltas(updated, schemaVersion), + ); + } + + private static migratePartialDeltas( + deltas: Record>, + fromVersion: number, + ): Record> { + if (fromVersion >= CURRENT_SCHEMA_VERSION) { + return deltas; + } + + return Object.entries(deltas).reduce((acc, [id, delta]) => { + acc[id] = Delta.create( + migrateElementPartial(delta.deleted, fromVersion), + migrateElementPartial(delta.inserted, fromVersion), + ); + return acc; + }, {} as Record>); } private static satisfiesAddition = ({ diff --git a/packages/element/src/newElement.ts b/packages/element/src/newElement.ts index a966ef6eb9..e342abdc9d 100644 --- a/packages/element/src/newElement.ts +++ b/packages/element/src/newElement.ts @@ -33,7 +33,6 @@ import { normalizeText, measureText } from "./textMeasurements"; import { wrapText } from "./textWrapping"; import { isLineElement } from "./typeChecks"; -import { CURRENT_ELEMENT_SCHEMA_VERSION } from "./versioning"; import type { ExcalidrawElement, @@ -71,7 +70,6 @@ export type ElementConstructorOpts = MarkOptional< | "seed" | "version" | "versionNonce" - | "schemaVersion" | "link" | "strokeStyle" | "fillStyle" @@ -161,7 +159,6 @@ const _newElementBase = ( seed: rest.seed ?? randomInteger(), version: rest.version || 1, versionNonce: rest.versionNonce ?? 0, - schemaVersion: rest.schemaVersion ?? CURRENT_ELEMENT_SCHEMA_VERSION, isDeleted: false as false, boundElements, updated: timestamp, diff --git a/packages/element/src/store.ts b/packages/element/src/store.ts index 38235e752c..b4ac545822 100644 --- a/packages/element/src/store.ts +++ b/packages/element/src/store.ts @@ -19,6 +19,8 @@ import { newElementWith } from "./mutateElement"; import { ElementsDelta, AppStateDelta, Delta } from "./delta"; +import { CURRENT_SCHEMA_VERSION, getSchemaVersion } from "./versioning"; + import { syncInvalidIndicesImmutable, hashElementsVersion, @@ -499,6 +501,7 @@ export class StoreDelta { public readonly id: string, public readonly elements: ElementsDelta, public readonly appState: AppStateDelta, + public readonly schemaVersion: number = CURRENT_SCHEMA_VERSION, ) {} /** @@ -513,7 +516,7 @@ export class StoreDelta { id: randomId(), }, ) { - return new this(opts.id, elements, appState); + return new this(opts.id, elements, appState, CURRENT_SCHEMA_VERSION); } /** @@ -535,26 +538,31 @@ export class StoreDelta { } /** - * Restore a store delta instance from a DTO. + * Restore a store delta instance from a DTO, lifting the contained element + * partials to the current schema version. */ public static restore(storeDeltaDTO: DTO) { const { id, elements, appState } = storeDeltaDTO; return new this( id, - ElementsDelta.restore(elements), + ElementsDelta.restore(elements, getSchemaVersion(storeDeltaDTO)), AppStateDelta.restore(appState), ); } /** - * Parse and load the delta from the remote payload. + * Parse and load the delta from the remote payload, lifting the contained + * element partials to the current schema version. */ - public static load({ - id, - elements: { added, removed, updated }, - appState: { delta: appStateDelta }, - }: DTO) { - const elements = ElementsDelta.create(added, removed, updated); + public static load(storeDeltaDTO: DTO) { + const { + id, + appState: { delta: appStateDelta }, + } = storeDeltaDTO; + const elements = ElementsDelta.restore( + storeDeltaDTO.elements, + getSchemaVersion(storeDeltaDTO), + ); const appState = AppStateDelta.create(appStateDelta); return new this(id, elements, appState); diff --git a/packages/element/src/types.ts b/packages/element/src/types.ts index ca38f77b3c..68891be19f 100644 --- a/packages/element/src/types.ts +++ b/packages/element/src/types.ts @@ -62,11 +62,6 @@ type _ExcalidrawElementBase = Readonly<{ Used for deterministic reconciliation of updates during collaboration, in case the versions (see above) are identical. */ versionNonce: number; - /** Schema version of the element's shape/semantics. Unrelated to `version` - (the collab/reconciliation counter). Legacy elements persisted before - schema versioning lack it and are lifted to the current version on - restore. See `CURRENT_ELEMENT_SCHEMA_VERSION`. */ - schemaVersion: number; /** String in a fractional form defined by https://github.com/rocicorp/fractional-indexing. Used for ordering in multiplayer scenarios, such as during reconciliation or undo / redo. Always kept in sync with the array order by `syncMovedIndices` and `syncInvalidIndices`. diff --git a/packages/element/src/versioning.ts b/packages/element/src/versioning.ts index 4f49a5a1c7..5502cd5990 100644 --- a/packages/element/src/versioning.ts +++ b/packages/element/src/versioning.ts @@ -1,57 +1,87 @@ /** - * The schema version that the current in-memory element shape corresponds to. + * The schema version the current in-memory element shape corresponds to. */ -export const CURRENT_ELEMENT_SCHEMA_VERSION = 1; +export const CURRENT_SCHEMA_VERSION = 1; + +type SchemaMigration = { + // Upgrades a full element from schema version n to n + 1. + element: (element: any) => any; + // Upgrades a partial element (durable undo/redo). + elementPartial: (partial: any) => any; +}; + +const identity = (value: T): T => value; /** - * A migration that upgrades an element from one schema version to the next. - */ -type ElementSchemaMigration = (element: any) => any; - -/** - * `migrations[n]` upgrades an element from schema version `n` to `n + 1`. + * migrations[n] upgrades data from schema version to n + 1. * - * Index `0` migrates legacy (unversioned) elements to version 1. + * NOTE: Index 0 migrates legacy (unversioned) data to version 1. + * + * IMPORTANT: data of unknown provenance (API input, clipboard from older + * builds etc.) is considered 'legacy' v0! */ -const migrations: Record = { - 0: (element) => element, +const migrations: Record = { + 0: { element: identity, elementPartial: identity }, }; /** - * Returns an element's schema version, treating a missing `schemaVersion` (i.e. - * a legacy element persisted before schema versioning) as version 0. + * Returns the schema version indicated by a container. */ -export const getElementSchemaVersion = (element: { - schemaVersion?: number; -}): number => - typeof element.schemaVersion === "number" ? element.schemaVersion : 0; +export const getSchemaVersion = (source: unknown): number => { + const schemaVersion = (source as { schemaVersion?: unknown } | null) + ?.schemaVersion; -/** - * Lifts an element up to {@link CURRENT_ELEMENT_SCHEMA_VERSION} by running each - * migration in sequence, then stamps the current schema version onto it. - * - * Safe to call on an already-current element (the migration chain is empty and - * it is simply re-stamped). If a migration step is missing (which shouldn't - * happen), it stops early rather than throwing, so a partially-known element is - * still returned rather than lost. - */ -export const upgradeElementSchema = ( - element: T, -): T & { schemaVersion: number } => { - let version = getElementSchemaVersion(element as { schemaVersion?: number }); - let upgraded: any = element; + return typeof schemaVersion === "number" && Number.isFinite(schemaVersion) + ? schemaVersion + : 0; +}; - while (version < CURRENT_ELEMENT_SCHEMA_VERSION) { - const migrate = migrations[version]; - if (!migrate) { +const runMigrations = ( + kind: keyof SchemaMigration, + value: T, + fromVersion: number, +): T => { + let version = fromVersion; + let migrated: any = value; + + // NOTE: data from a newer client (fromVersion > current) is returned as-is; + // unknown properties are preserved down the line for forward-compatibility + while (version < CURRENT_SCHEMA_VERSION) { + const migration = migrations[version]; + if (!migration) { break; } - upgraded = migrate(upgraded); + migrated = migration[kind](migrated); version += 1; } - return { - ...upgraded, - schemaVersion: CURRENT_ELEMENT_SCHEMA_VERSION, - }; + return migrated; }; + +/** + * Lifts a full element from `fromVersion` up to + * {@link CURRENT_SCHEMA_VERSION} by running each migration in sequence. + */ +export const migrateElement = (element: T, fromVersion: number): T => + runMigrations("element", element, fromVersion); + +/** + * Lifts all elements of a container from `fromVersion` up to + * {@link CURRENT_SCHEMA_VERSION}. + */ +export const migrateElements = ( + elements: readonly T[], + fromVersion: number, +): readonly T[] => + fromVersion >= CURRENT_SCHEMA_VERSION + ? elements + : elements.map((element) => migrateElement(element, fromVersion)); + +/** + * Lifts a partial element shape (as contained in deltas) from `fromVersion` + * up to {@link CURRENT_SCHEMA_VERSION}. + */ +export const migrateElementPartial = (partial: T, fromVersion: number): T => + fromVersion >= CURRENT_SCHEMA_VERSION + ? partial + : runMigrations("elementPartial", partial, fromVersion); diff --git a/packages/excalidraw/clipboard.ts b/packages/excalidraw/clipboard.ts index 5075343f65..914a905568 100644 --- a/packages/excalidraw/clipboard.ts +++ b/packages/excalidraw/clipboard.ts @@ -10,6 +10,7 @@ import { import { mutateElement } from "@excalidraw/element"; import { deepCopyElement } from "@excalidraw/element"; +import { CURRENT_SCHEMA_VERSION, getSchemaVersion } from "@excalidraw/element"; import { isFrameLikeElement, isInitializedImageElement, @@ -38,6 +39,7 @@ import type { BinaryFiles } from "./types"; type ElementsClipboard = { type: typeof EXPORT_DATA_TYPES.excalidrawClipboard; + schemaVersion: number; elements: readonly NonDeletedExcalidrawElement[]; files: BinaryFiles | undefined; }; @@ -46,6 +48,7 @@ export type PastedMixedContent = { type: "text" | "imageUrl"; value: string }[]; export interface ClipboardData { elements?: readonly ExcalidrawElement[]; + schemaVersion?: number; files?: BinaryFiles; text?: string; mixedContent?: PastedMixedContent; @@ -172,6 +175,7 @@ export const serializeAsClipboardJSON = ({ // select bound text elements when copying const contents: ElementsClipboard = { type: EXPORT_DATA_TYPES.excalidrawClipboard, + schemaVersion: CURRENT_SCHEMA_VERSION, elements: elements.map((element) => { if ( getContainingFrame(element, elementsMap) && @@ -542,6 +546,7 @@ export const parseClipboard = async ( if (clipboardContainsElements(systemClipboardData)) { return { elements: systemClipboardData.elements, + schemaVersion: getSchemaVersion(systemClipboardData), files: systemClipboardData.files, text: isPlainPaste ? JSON.stringify(systemClipboardData.elements, null, 2) diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index a1055d2050..88caf06007 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -263,6 +263,8 @@ import { getBindingStrategyForDraggingBindingElementEndpoints, isNonDeletedElement, DEFAULT_BOUND_TEXT_LABEL_POSITION, + CURRENT_SCHEMA_VERSION, + getSchemaVersion, } from "@excalidraw/element"; import type { GlobalPoint, LocalPoint, Radians } from "@excalidraw/math"; @@ -3635,6 +3637,7 @@ class App extends React.Component { const restoredElements = restoreElements(initialData?.elements, null, { repairBindings: true, deleteInvisibleElements: true, + schemaVersion: getSchemaVersion(initialData), }); let restoredAppState = restoreAppState(initialData?.appState, null); const activeTool = restoredAppState.activeTool; @@ -4678,6 +4681,7 @@ class App extends React.Component { this.editorInterface.formFactor === "desktop" ? "cursor" : "center", retainSeed: isPlainPaste, preserveFrameChildrenOrder: true, + schemaVersion: data.programmaticAPI ? undefined : data.schemaVersion, }); return; } @@ -4826,9 +4830,11 @@ class App extends React.Component { retainSeed?: boolean; fit?: SetViewportOptions["fit"]; preserveFrameChildrenOrder?: boolean; + schemaVersion?: number; }) => { const elements = restoreElements(opts.elements, null, { deleteInvisibleElements: true, + schemaVersion: opts.schemaVersion ?? CURRENT_SCHEMA_VERSION, }); const [minX, minY, maxX, maxY] = getCommonBounds(elements); diff --git a/packages/excalidraw/components/PublishLibrary.tsx b/packages/excalidraw/components/PublishLibrary.tsx index c9376895da..e7a4dd0ee5 100644 --- a/packages/excalidraw/components/PublishLibrary.tsx +++ b/packages/excalidraw/components/PublishLibrary.tsx @@ -10,6 +10,8 @@ import { getExportSource, } from "@excalidraw/common"; +import { CURRENT_SCHEMA_VERSION } from "@excalidraw/element"; + import { EditorLocalStorage } from "../data/EditorLocalStorage"; import { canvasToBlob, resizeImageFile } from "../data/blob"; import { t } from "../i18n"; @@ -280,6 +282,7 @@ const PublishLibrary = ({ const libContent: ExportedLibraryData = { type: EXPORT_DATA_TYPES.excalidrawLibrary, version: VERSIONS.excalidrawLibrary, + schemaVersion: CURRENT_SCHEMA_VERSION, source: getExportSource(), libraryItems: clonedLibItems, }; diff --git a/packages/excalidraw/data/blob.ts b/packages/excalidraw/data/blob.ts index 3234965960..d1075b62b4 100644 --- a/packages/excalidraw/data/blob.ts +++ b/packages/excalidraw/data/blob.ts @@ -7,6 +7,8 @@ import { isPromiseLike, } from "@excalidraw/common"; +import { getSchemaVersion } from "@excalidraw/element"; + import type { ValueOf } from "@excalidraw/common/utility-types"; import type { ExcalidrawElement, FileId } from "@excalidraw/element/types"; @@ -161,6 +163,7 @@ export const loadSceneOrLibraryFromBlob = async ( const elements = restoreElements(data.elements, localElements, { repairBindings: true, deleteInvisibleElements: true, + schemaVersion: getSchemaVersion(data), }); return { type: MIME_TYPES.excalidraw, @@ -224,7 +227,9 @@ export const parseLibraryJSON = ( throw new Error("Invalid library"); } const libraryItems = data.libraryItems || data.library; - return restoreLibraryItems(libraryItems, defaultStatus); + return restoreLibraryItems(libraryItems, defaultStatus, { + schemaVersion: getSchemaVersion(data), + }); }; export const loadLibraryFromBlob = async ( diff --git a/packages/excalidraw/data/json.ts b/packages/excalidraw/data/json.ts index a49d58cd02..feee628498 100644 --- a/packages/excalidraw/data/json.ts +++ b/packages/excalidraw/data/json.ts @@ -5,6 +5,8 @@ import { VERSIONS, } from "@excalidraw/common"; +import { CURRENT_SCHEMA_VERSION } from "@excalidraw/element"; + import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { MaybePromise } from "@excalidraw/common/utility-types"; @@ -58,6 +60,7 @@ export const serializeAsJSON = ( const data: ExportedDataState = { type: EXPORT_DATA_TYPES.excalidraw, version: VERSIONS.excalidraw, + schemaVersion: CURRENT_SCHEMA_VERSION, source: getExportSource(), elements, appState: @@ -138,6 +141,7 @@ export const serializeLibraryAsJSON = (libraryItems: LibraryItems) => { const data: ExportedLibraryData = { type: EXPORT_DATA_TYPES.excalidrawLibrary, version: VERSIONS.excalidrawLibrary, + schemaVersion: CURRENT_SCHEMA_VERSION, source: getExportSource(), libraryItems, }; diff --git a/packages/excalidraw/data/library.ts b/packages/excalidraw/data/library.ts index abe2fec853..1bed9ea02c 100644 --- a/packages/excalidraw/data/library.ts +++ b/packages/excalidraw/data/library.ts @@ -18,6 +18,7 @@ import { } from "@excalidraw/common"; import { hashElementsVersion, hashString } from "@excalidraw/element"; +import { CURRENT_SCHEMA_VERSION, getSchemaVersion } from "@excalidraw/element"; import { getCommonBoundingBox } from "@excalidraw/element"; @@ -65,9 +66,11 @@ type LibraryUpdate = { updatedItems: Map; }; -// an object so that we can later add more properties to it without breaking, -// such as schema version -export type LibraryPersistedData = { libraryItems: LibraryItems }; +// an object so that we can later add more properties to it without breaking +export type LibraryPersistedData = { + libraryItems: LibraryItems; + schemaVersion?: number; +}; const onLibraryUpdateEmitter = new Emitter< [update: LibraryUpdate, libraryItems: LibraryItems] @@ -554,7 +557,11 @@ class AdapterTransaction { new Promise(async (resolve, reject) => { try { const data = await adapter.load({ source }); - resolve(restoreLibraryItems(data?.libraryItems || [], "published")); + resolve( + restoreLibraryItems(data?.libraryItems || [], "published", { + schemaVersion: getSchemaVersion(data), + }), + ); } catch (error: any) { reject(error); } @@ -662,7 +669,10 @@ const persistLibraryUpdate = async ( const version = getLibraryItemsHash(nextLibraryItems); if (version !== lastSavedLibraryItemsHash) { - await adapter.save({ libraryItems: nextLibraryItems }); + await adapter.save({ + libraryItems: nextLibraryItems, + schemaVersion: CURRENT_SCHEMA_VERSION, + }); } lastSavedLibraryItemsHash = version; @@ -862,6 +872,7 @@ export const useHandleLibrary = ( restoredData = restoreLibraryItems( libraryData.libraryItems || [], "published", + { schemaVersion: getSchemaVersion(libraryData) }, ); // we don't queue this operation because it's running inside diff --git a/packages/excalidraw/data/restore.ts b/packages/excalidraw/data/restore.ts index 8e3b222253..4ef71f0044 100644 --- a/packages/excalidraw/data/restore.ts +++ b/packages/excalidraw/data/restore.ts @@ -56,10 +56,7 @@ import { normalizeStickyNoteFontSize, normalizeStickyNoteStrokeColor, } from "@excalidraw/element"; -import { - CURRENT_ELEMENT_SCHEMA_VERSION, - upgradeElementSchema, -} from "@excalidraw/element"; +import { migrateElements } from "@excalidraw/element"; import { getBoundTextElement, getContainerElement } from "@excalidraw/element"; import { isStickyNoteElement } from "@excalidraw/element"; import { detectLineHeight } from "@excalidraw/element"; @@ -458,7 +455,6 @@ const restoreElementWithProperties = < // newly added elements version: element.version || 1, versionNonce: element.versionNonce ?? 0, - schemaVersion: element.schemaVersion || CURRENT_ELEMENT_SCHEMA_VERSION, index: element.index ?? null, isDeleted: element.isDeleted ?? false, id: element.id || randomId(), @@ -532,7 +528,7 @@ export const restoreElement = ( deleteInvisibleElements?: boolean; }, ): typeof element | null => { - element = upgradeElementSchema({ ...element }); + element = { ...element }; switch (element.type) { case "text": @@ -959,18 +955,23 @@ export const restoreElements = ( refreshDimensions?: boolean; repairBindings?: boolean; deleteInvisibleElements?: boolean; + schemaVersion?: number; } | undefined, ): CombineBrandsIfNeeded => { // used to detect duplicate top-level element ids const existingIds = new Set(); - const targetElementsMap = arrayToMap(targetElements || []); + const migratedTargetElements = migrateElements( + targetElements || [], + opts?.schemaVersion ?? 0, + ); + const targetElementsMap = arrayToMap(migratedTargetElements); const existingElementsMap = existingElements ? arrayToMap(existingElements) : null; const restoredElements = syncInvalidIndices( - (targetElements || []).reduce((elements, element) => { + migratedTargetElements.reduce((elements, element) => { // filtering out selection, which is legacy, no longer kept in elements, // and causing issues if retained if (element.type === "selection") { @@ -1355,9 +1356,14 @@ export const restoreAppState = ( }; }; -const restoreLibraryItem = (libraryItem: LibraryItem): LibraryItem | null => { +const restoreLibraryItem = ( + libraryItem: LibraryItem, + schemaVersion: number | undefined, +) => { const elements = getNonDeletedElements( - restoreElements(libraryItem.elements, null), + restoreElements(getNonDeletedElements(libraryItem.elements), null, { + schemaVersion, + }), ); return elements.length ? { ...libraryItem, elements } : null; }; @@ -1365,17 +1371,24 @@ const restoreLibraryItem = (libraryItem: LibraryItem): LibraryItem | null => { export const restoreLibraryItems = ( libraryItems: ImportedDataState["libraryItems"] = [], defaultStatus: LibraryItem["status"], + opts?: { + /** @see restoreElements */ + schemaVersion?: number; + }, ) => { const restoredItems: LibraryItem[] = []; for (const item of libraryItems) { // migrate older libraries if (Array.isArray(item)) { - const restoredItem = restoreLibraryItem({ - status: defaultStatus, - elements: item, - id: randomId(), - created: Date.now(), - }); + const restoredItem = restoreLibraryItem( + { + status: defaultStatus, + elements: item, + id: randomId(), + created: Date.now(), + }, + opts?.schemaVersion, + ); if (restoredItem) { restoredItems.push(restoredItem); } @@ -1384,12 +1397,15 @@ export const restoreLibraryItems = ( LibraryItem, "id" | "status" | "created" >; - const restoredItem = restoreLibraryItem({ - ..._item, - id: _item.id || randomId(), - status: _item.status || defaultStatus, - created: _item.created || Date.now(), - }); + const restoredItem = restoreLibraryItem( + { + ..._item, + id: _item.id || randomId(), + status: _item.status || defaultStatus, + created: _item.created || Date.now(), + }, + opts?.schemaVersion, + ); if (restoredItem) { restoredItems.push(restoredItem); } diff --git a/packages/excalidraw/data/types.ts b/packages/excalidraw/data/types.ts index 94947c2b98..615a59b29d 100644 --- a/packages/excalidraw/data/types.ts +++ b/packages/excalidraw/data/types.ts @@ -14,6 +14,7 @@ import type { export interface ExportedDataState { type: string; version: number; + schemaVersion: number; source: string; elements: readonly ExcalidrawElement[]; appState: ReturnType; @@ -35,6 +36,7 @@ export type LegacyAppState = { export interface ImportedDataState { type?: string; version?: number; + schemaVersion?: number; source?: string; elements?: readonly ExcalidrawElement[] | null; appState?: Readonly< @@ -52,6 +54,7 @@ export interface ImportedDataState { export interface ExportedLibraryData { type: string; version: typeof VERSIONS.excalidrawLibrary; + schemaVersion: number; source: string; libraryItems: LibraryItems; } diff --git a/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap index c35f1a6797..bd3f305ce4 100644 --- a/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap +++ b/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap @@ -1029,7 +1029,6 @@ exports[`contextMenu element > right-clicking on a group should select whole gro "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1065,7 +1064,6 @@ exports[`contextMenu element > right-clicking on a group should select whole gro "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1237,7 +1235,6 @@ exports[`contextMenu element > selecting 'Add to library' in context menu adds e "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1294,7 +1291,6 @@ exports[`contextMenu element > selecting 'Add to library' in context menu adds e "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -1313,6 +1309,7 @@ exports[`contextMenu element > selecting 'Add to library' in context menu adds e "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, ] `; @@ -1464,7 +1461,6 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1014066025, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1498,7 +1494,6 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1555,7 +1550,6 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -1574,6 +1568,7 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -1611,7 +1606,6 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -1630,6 +1624,7 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings "updated": {}, }, "id": "id5", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -1663,6 +1658,7 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings }, }, "id": "id7", + "schemaVersion": 1, }, ] `; @@ -1814,7 +1810,6 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1014066025, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1848,7 +1843,6 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -1905,7 +1899,6 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -1924,6 +1917,7 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -1961,7 +1955,6 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -1980,6 +1973,7 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings "updated": {}, }, "id": "id5", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -2013,6 +2007,7 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings }, }, "id": "id7", + "schemaVersion": 1, }, ] `; @@ -2166,7 +2161,6 @@ exports[`contextMenu element > selecting 'Copy styles' in context menu copies st "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2223,7 +2217,6 @@ exports[`contextMenu element > selecting 'Copy styles' in context menu copies st "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -2242,6 +2235,7 @@ exports[`contextMenu element > selecting 'Copy styles' in context menu copies st "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, ] `; @@ -2391,7 +2385,6 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2448,7 +2441,6 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -2467,6 +2459,7 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -2498,6 +2491,7 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen "updated": {}, }, "id": "id4", + "schemaVersion": 1, }, ] `; @@ -2649,7 +2643,6 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2683,7 +2676,6 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1014066025, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -2740,7 +2732,6 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -2759,6 +2750,7 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -2796,7 +2788,6 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -2815,6 +2806,7 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates "updated": {}, }, "id": "id5", + "schemaVersion": 1, }, ] `; @@ -2973,7 +2965,6 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -3009,7 +3000,6 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1014066025, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -3066,7 +3056,6 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -3085,6 +3074,7 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3122,7 +3112,6 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -3141,6 +3130,7 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group "updated": {}, }, "id": "id5", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3161,6 +3151,7 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group "updated": {}, }, "id": "id8", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3206,6 +3197,7 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group }, }, "id": "id11", + "schemaVersion": 1, }, ] `; @@ -3359,7 +3351,6 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s "opacity": 60, "roughness": 2, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#e03131", "strokeStyle": "dotted", @@ -3393,7 +3384,6 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s "opacity": 60, "roughness": 2, "roundness": null, - "schemaVersion": 1, "seed": 406373543, "strokeColor": "#e03131", "strokeStyle": "dotted", @@ -3450,7 +3440,6 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -3469,6 +3458,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3506,7 +3496,6 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -3525,6 +3514,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s "updated": {}, }, "id": "id5", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3550,6 +3540,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s }, }, "id": "id7", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3575,6 +3566,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s }, }, "id": "id9", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3600,6 +3592,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s }, }, "id": "id11", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3625,6 +3618,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s }, }, "id": "id13", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3650,6 +3644,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s }, }, "id": "id15", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3675,6 +3670,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s }, }, "id": "id17", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3700,6 +3696,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s }, }, "id": "id19", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -3745,6 +3742,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s }, }, "id": "id21", + "schemaVersion": 1, }, ] `; @@ -3896,7 +3894,6 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 238820263, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -3930,7 +3927,6 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -3987,7 +3983,6 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -4006,6 +4001,7 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -4043,7 +4039,6 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -4062,6 +4057,7 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e "updated": {}, }, "id": "id5", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -4087,6 +4083,7 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e }, }, "id": "id7", + "schemaVersion": 1, }, ] `; @@ -4238,7 +4235,6 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1014066025, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -4272,7 +4268,6 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -4329,7 +4324,6 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -4348,6 +4342,7 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -4385,7 +4380,6 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -4404,6 +4398,7 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el "updated": {}, }, "id": "id5", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -4429,6 +4424,7 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el }, }, "id": "id7", + "schemaVersion": 1, }, ] `; @@ -4583,7 +4579,6 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -4617,7 +4612,6 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 400692809, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -4674,7 +4668,6 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -4693,6 +4686,7 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -4730,7 +4724,6 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -4749,6 +4742,7 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung "updated": {}, }, "id": "id5", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -4769,6 +4763,7 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung "updated": {}, }, "id": "id8", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -4814,6 +4809,7 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung }, }, "id": "id11", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -4859,6 +4855,7 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung }, }, "id": "id13", + "schemaVersion": 1, }, ] `; @@ -5887,7 +5884,6 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -5921,7 +5917,6 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 400692809, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -5978,7 +5973,6 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -5997,6 +5991,7 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -6034,7 +6029,6 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -6053,6 +6047,7 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi "updated": {}, }, "id": "id5", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -6075,6 +6070,7 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi "updated": {}, }, "id": "id8", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -6095,6 +6091,7 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi "updated": {}, }, "id": "id11", + "schemaVersion": 1, }, ] `; @@ -7127,7 +7124,6 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -7163,7 +7159,6 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 400692809, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -7220,7 +7215,6 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -7239,6 +7233,7 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -7276,7 +7271,6 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -7295,6 +7289,7 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro "updated": {}, }, "id": "id5", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -7317,6 +7312,7 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro "updated": {}, }, "id": "id8", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -7337,6 +7333,7 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro "updated": {}, }, "id": "id11", + "schemaVersion": 1, }, { "appState": AppStateDelta { @@ -7382,6 +7379,7 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro }, }, "id": "id14", + "schemaVersion": 1, }, ] `; @@ -10112,7 +10110,6 @@ exports[`contextMenu element > shows context menu for element > [end of test] el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -10146,7 +10143,6 @@ exports[`contextMenu element > shows context menu for element > [end of test] el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -10180,7 +10176,6 @@ exports[`contextMenu element > shows context menu for element > [end of test] el "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -10243,7 +10238,6 @@ exports[`contextMenu element > shows context menu for element > [end of test] un "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "strokeColor": "#1e1e1e", "strokeStyle": "solid", "strokeWidth": 2, @@ -10262,6 +10256,7 @@ exports[`contextMenu element > shows context menu for element > [end of test] un "updated": {}, }, "id": "id2", + "schemaVersion": 1, }, ] `; diff --git a/packages/excalidraw/tests/__snapshots__/dragCreate.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/dragCreate.test.tsx.snap index 07cfe18682..a082842101 100644 --- a/packages/excalidraw/tests/__snapshots__/dragCreate.test.tsx.snap +++ b/packages/excalidraw/tests/__snapshots__/dragCreate.test.tsx.snap @@ -36,7 +36,6 @@ exports[`Test dragCreate > add element to the scene when pointer dragging long e "roundness": { "type": 2, }, - "schemaVersion": 1, "seed": 1278240551, "startArrowhead": null, "startBinding": null, @@ -74,7 +73,6 @@ exports[`Test dragCreate > add element to the scene when pointer dragging long e "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -110,7 +108,6 @@ exports[`Test dragCreate > add element to the scene when pointer dragging long e "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", @@ -157,7 +154,6 @@ exports[`Test dragCreate > add element to the scene when pointer dragging long e "polygon": false, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "startArrowhead": null, "startBinding": null, @@ -195,7 +191,6 @@ exports[`Test dragCreate > add element to the scene when pointer dragging long e "opacity": 100, "roughness": 1, "roundness": null, - "schemaVersion": 1, "seed": 1278240551, "strokeColor": "#1e1e1e", "strokeStyle": "solid", diff --git a/packages/excalidraw/tests/__snapshots__/export.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/export.test.tsx.snap index 566e1cf97c..6b39075abb 100644 --- a/packages/excalidraw/tests/__snapshots__/export.test.tsx.snap +++ b/packages/excalidraw/tests/__snapshots__/export.test.tsx.snap @@ -1,7 +1,7 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`export > export svg-embedded scene > svg-embdedded scene export output 1`] = ` -"eyJ2ZXJzaW9uIjoiMSIsImVuY29kaW5nIjoiYnN0cmluZyIsImNvbXByZXNzZWQiOnRydWUsImVuY29kZWQiOiJ4nHVTwW7bMFxmve8rXGb3WqxOiu6QW7u2aFx1MDAwZu2hXHUwMDE5tkOxg2oxNlx1MDAxMUVcdTAwMTIkuklcdTAwMTZcdTAwMDTYZ+zWX+wnlFI8K3bSXHUwMDA0MKBHUnx8fNp8ybKc1lx1MDAxNvJJlsOqXHUwMDE0XG6lXHUwMDEzy/w04K/gPFx1MDAxYc2hcTx707gyZtZEdnJ2plxmXHUwMDE31MbT5Lwoil1cdTAwMTEoWIAmz2nPfM6yTfxyXHUwMDA0ZSi9jGlcdTAwMTH435dgRVx0XTFUdKd177RESTUjo29cdTAwMWRUXHUwMDAzVjX1MaErXHUwMDA1vUJPzszhu1HGhY4nI1xi/9T0RZTzyplGyy6HnNDeXG7Hw6S8XHUwMDE5KjWldbyd9WC18kGPXy3F8Vx1MDAwMP+siptWtVx1MDAwNlx1MDAxZlx1MDAwNFx1MDAxYnWosaJEXG7Dj4o0RWBo72XU9nfi5MRcdTAwMDLug7i6UaqDUUtYXHLBOGLbrVx1MDAxN/BcdTAwMDCyxyAt/1x1MDAwMHs0ulx1MDAxY8hb1rBcdTAwMTA/j5Sgv2ZHULx8JpSHJHmgcpPc0qPTWClowEihnlx1MDAwZvPYgfMjd0dHsdbvb//+7i3PaJrin0B9XFz00FuxQFx1MDAxNdS+6F1xqbBcbuPkXG5meyZgXHUwMDE5XGLZ+V2YjE3Rku9cdTAwMTOowVx1MDAxZK7EOKxQXHUwMDBi9eMoPdGQeVx1MDAwMr8jSK6B/cnhrvP51/FFXGZs+Vx1MDAxYl2QXHUwMDBia6fEenF099rYKShcdTAwMDej7jBcdTAwMDKbxozQg5Fwo8WLXHUwMDFh6pi/XCIsr1x1MDAwZVx1MDAxZsbJLP5a4u1cblx1MDAxZVx1MDAxYUU45VWXxFx1MDAxNlxi+9xcdTAwMDR+28iPX1xytND2XHUwMDAzo9gvdiJ9