From bf3afc34eda4860d57fa396a6dc661804d92c759 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Mon, 17 Jul 2023 17:33:23 +0530 Subject: [PATCH] make image attributes optional and better ts check --- src/data/transform.ts | 6 +- src/packages/excalidraw/example/App.tsx | 4 +- .../excalidraw/example/initialData.tsx | 75 ++++++++++--------- 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/data/transform.ts b/src/data/transform.ts index 8770eafcd4..3f8fc2aadb 100644 --- a/src/data/transform.ts +++ b/src/data/transform.ts @@ -134,7 +134,6 @@ export interface ExcalidrawProgrammaticAPI { | Extract< ExcalidrawElement, | ExcalidrawSelectionElement - | ExcalidrawImageElement | ExcalidrawFreeDrawElement | ExcalidrawFrameElement > @@ -152,6 +151,11 @@ export interface ExcalidrawProgrammaticAPI { y: number; id?: ExcalidrawTextElement["id"]; } & Partial) + | ({ + type: Extract; + x: number; + y: number; + } & Partial) )[] | null; } diff --git a/src/packages/excalidraw/example/App.tsx b/src/packages/excalidraw/example/App.tsx index 3399b5caf0..1e17959ad9 100644 --- a/src/packages/excalidraw/example/App.tsx +++ b/src/packages/excalidraw/example/App.tsx @@ -146,9 +146,7 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) { //@ts-ignore initialStatePromiseRef.current.promise.resolve({ ...initialData, - elements: convertToExcalidrawElements( - initialData.elements as ExcalidrawProgrammaticAPI["elements"], - ), + elements: convertToExcalidrawElements(initialData.elements), }); excalidrawAPI.addFiles(imagesArray); }; diff --git a/src/packages/excalidraw/example/initialData.tsx b/src/packages/excalidraw/example/initialData.tsx index 00bf2c53db..afe0f9130c 100644 --- a/src/packages/excalidraw/example/initialData.tsx +++ b/src/packages/excalidraw/example/initialData.tsx @@ -1,41 +1,44 @@ -export default { - elements: [ - { - type: "rectangle", - x: 10, - y: 10, - strokeWidth: "2", - }, - { - type: "diamond", - x: 120, - y: 20, - backgroundColor: "#fff3bf", - strokeWidth: "2", - label: { - text: "HELLO EXCALIDRAW", - strokeColor: "#099268", - fontSize: 30, - }, - }, - { - type: "arrow", - x: 100, - y: 200, - label: { text: "HELLO WORLD!!" }, - start: { type: "rectangle" }, - end: { type: "ellipse" }, - }, +import { ExcalidrawProgrammaticAPI } from "../../../data/transform"; +import { FileId } from "../../../element/types"; - { - fileId: "rocket", - type: "image", - x: 606.1042326312408, - y: 153.57729779411773, - width: 231.30325348751828, - height: 231.64340533088227, +const elements: ExcalidrawProgrammaticAPI["elements"] = [ + { + type: "rectangle", + x: 10, + y: 10, + strokeWidth: 2, + }, + { + type: "diamond", + x: 120, + y: 20, + backgroundColor: "#fff3bf", + strokeWidth: 2, + label: { + text: "HELLO EXCALIDRAW", + strokeColor: "#099268", + fontSize: 30, }, - ], + }, + { + type: "arrow", + x: 100, + y: 200, + label: { text: "HELLO WORLD!!" }, + start: { type: "rectangle" }, + end: { type: "ellipse" }, + }, + { + fileId: "rocket" as FileId, + type: "image", + x: 606.1042326312408, + y: 153.57729779411773, + width: 231.30325348751828, + height: 231.64340533088227, + }, +]; +export default { + elements, appState: { viewBackgroundColor: "#AFEEEE", currentItemFontFamily: 1 }, scrollToContent: true, libraryItems: [