diff --git a/src/data/transform.ts b/src/data/transform.ts index 3f8fc2aadb..2f630ca3b1 100644 --- a/src/data/transform.ts +++ b/src/data/transform.ts @@ -13,6 +13,7 @@ import { bindLinearElement } from "../element/binding"; import { mutateElement } from "../element/mutateElement"; import { ElementConstructorOpts, + newImageElement, newTextElement, regenerateId, } from "../element/newElement"; @@ -166,6 +167,7 @@ export const ELEMENTS_SUPPORTING_PROGRAMMATIC_API = [ "text", "arrow", "line", + "image", ]; const DEFAULT_LINEAR_ELEMENT_PROPS = { @@ -531,6 +533,13 @@ export const convertToExcalidrawElements = ( ...elementWithId, }); excalidrawElements.add(lineElement); + } else if (elementWithId.type === "image") { + const imageElement = newImageElement({ + width: elementWithId?.width || DEFAULT_DIMENSION, + height: elementWithId?.height || DEFAULT_DIMENSION, + ...elementWithId, + }); + excalidrawElements.add(imageElement); } else { excalidrawElement = { ...elementWithId, diff --git a/src/packages/excalidraw/example/initialData.tsx b/src/packages/excalidraw/example/initialData.tsx index afe0f9130c..8f1870de4c 100644 --- a/src/packages/excalidraw/example/initialData.tsx +++ b/src/packages/excalidraw/example/initialData.tsx @@ -29,12 +29,12 @@ const elements: ExcalidrawProgrammaticAPI["elements"] = [ end: { type: "ellipse" }, }, { - fileId: "rocket" as FileId, type: "image", x: 606.1042326312408, y: 153.57729779411773, width: 231.30325348751828, height: 231.64340533088227, + fileId: "rocket" as FileId, }, ]; export default {