make image attributes optional and better ts check

This commit is contained in:
Aakansha Doshi 2023-07-17 17:33:23 +05:30
parent bdb84b01ca
commit bf3afc34ed
3 changed files with 45 additions and 40 deletions

View file

@ -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<ExcalidrawTextElement>)
| ({
type: Extract<ExcalidrawImageElement["type"], "image">;
x: number;
y: number;
} & Partial<ExcalidrawImageElement>)
)[]
| null;
}

View file

@ -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);
};

View file

@ -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: [