mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-04-14 16:40:58 -04:00
support image via programmatic API
This commit is contained in:
parent
bf3afc34ed
commit
21ca391e8c
2 changed files with 10 additions and 1 deletions
|
@ -13,6 +13,7 @@ import { bindLinearElement } from "../element/binding";
|
||||||
import { mutateElement } from "../element/mutateElement";
|
import { mutateElement } from "../element/mutateElement";
|
||||||
import {
|
import {
|
||||||
ElementConstructorOpts,
|
ElementConstructorOpts,
|
||||||
|
newImageElement,
|
||||||
newTextElement,
|
newTextElement,
|
||||||
regenerateId,
|
regenerateId,
|
||||||
} from "../element/newElement";
|
} from "../element/newElement";
|
||||||
|
@ -166,6 +167,7 @@ export const ELEMENTS_SUPPORTING_PROGRAMMATIC_API = [
|
||||||
"text",
|
"text",
|
||||||
"arrow",
|
"arrow",
|
||||||
"line",
|
"line",
|
||||||
|
"image",
|
||||||
];
|
];
|
||||||
|
|
||||||
const DEFAULT_LINEAR_ELEMENT_PROPS = {
|
const DEFAULT_LINEAR_ELEMENT_PROPS = {
|
||||||
|
@ -531,6 +533,13 @@ export const convertToExcalidrawElements = (
|
||||||
...elementWithId,
|
...elementWithId,
|
||||||
});
|
});
|
||||||
excalidrawElements.add(lineElement);
|
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 {
|
} else {
|
||||||
excalidrawElement = {
|
excalidrawElement = {
|
||||||
...elementWithId,
|
...elementWithId,
|
||||||
|
|
|
@ -29,12 +29,12 @@ const elements: ExcalidrawProgrammaticAPI["elements"] = [
|
||||||
end: { type: "ellipse" },
|
end: { type: "ellipse" },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fileId: "rocket" as FileId,
|
|
||||||
type: "image",
|
type: "image",
|
||||||
x: 606.1042326312408,
|
x: 606.1042326312408,
|
||||||
y: 153.57729779411773,
|
y: 153.57729779411773,
|
||||||
width: 231.30325348751828,
|
width: 231.30325348751828,
|
||||||
height: 231.64340533088227,
|
height: 231.64340533088227,
|
||||||
|
fileId: "rocket" as FileId,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
export default {
|
export default {
|
||||||
|
|
Loading…
Add table
Reference in a new issue