mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-04-14 16:40:58 -04:00
use element API to create regular text, diamond, ellipse and rectangle
This commit is contained in:
parent
685ece4b3a
commit
e49c94f22f
1 changed files with 58 additions and 57 deletions
|
@ -489,9 +489,7 @@ export const convertToExcalidrawElements = (
|
|||
elementStore.add(startBoundElement);
|
||||
elementStore.add(endBoundElement);
|
||||
}
|
||||
} else {
|
||||
let excalidrawElement;
|
||||
if (elementWithId.type === "text") {
|
||||
} else if (elementWithId.type === "text") {
|
||||
const fontFamily = elementWithId?.fontFamily || DEFAULT_FONT_FAMILY;
|
||||
const fontSize = elementWithId?.fontSize || DEFAULT_FONT_SIZE;
|
||||
const lineHeight =
|
||||
|
@ -503,15 +501,15 @@ export const convertToExcalidrawElements = (
|
|||
getFontString({ fontFamily, fontSize }),
|
||||
lineHeight,
|
||||
);
|
||||
excalidrawElement = {
|
||||
|
||||
const textElement = newTextElement({
|
||||
width: metrics.width,
|
||||
height: metrics.height,
|
||||
fontFamily,
|
||||
fontSize,
|
||||
...elementWithId,
|
||||
};
|
||||
|
||||
elementStore.add(excalidrawElement as ExcalidrawTextElement);
|
||||
});
|
||||
elementStore.add(textElement);
|
||||
} else if (elementWithId.type === "arrow") {
|
||||
const { linearElement, startBoundElement, endBoundElement } =
|
||||
bindLinearElementToElement(elementWithId, elementStore);
|
||||
|
@ -539,14 +537,17 @@ export const convertToExcalidrawElements = (
|
|||
...elementWithId,
|
||||
});
|
||||
elementStore.add(imageElement);
|
||||
} else {
|
||||
excalidrawElement = {
|
||||
} else if (
|
||||
elementWithId.type === "rectangle" ||
|
||||
elementWithId.type === "ellipse" ||
|
||||
elementWithId.type === "diamond"
|
||||
) {
|
||||
const element = newElement({
|
||||
...elementWithId,
|
||||
width: elementWithId?.width || DEFAULT_DIMENSION,
|
||||
height: elementWithId?.height || DEFAULT_DIMENSION,
|
||||
} as ExcalidrawGenericElement;
|
||||
elementStore.add(excalidrawElement);
|
||||
}
|
||||
});
|
||||
elementStore.add(element);
|
||||
}
|
||||
});
|
||||
return elementStore.get();
|
||||
|
|
Loading…
Add table
Reference in a new issue