use element API to create regular text, diamond, ellipse and rectangle

This commit is contained in:
Aakansha Doshi 2023-08-03 11:53:54 +05:30
parent 685ece4b3a
commit e49c94f22f

View file

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