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(startBoundElement);
|
||||||
elementStore.add(endBoundElement);
|
elementStore.add(endBoundElement);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (elementWithId.type === "text") {
|
||||||
let excalidrawElement;
|
|
||||||
if (elementWithId.type === "text") {
|
|
||||||
const fontFamily = elementWithId?.fontFamily || DEFAULT_FONT_FAMILY;
|
const fontFamily = elementWithId?.fontFamily || DEFAULT_FONT_FAMILY;
|
||||||
const fontSize = elementWithId?.fontSize || DEFAULT_FONT_SIZE;
|
const fontSize = elementWithId?.fontSize || DEFAULT_FONT_SIZE;
|
||||||
const lineHeight =
|
const lineHeight =
|
||||||
|
@ -503,15 +501,15 @@ export const convertToExcalidrawElements = (
|
||||||
getFontString({ fontFamily, fontSize }),
|
getFontString({ fontFamily, fontSize }),
|
||||||
lineHeight,
|
lineHeight,
|
||||||
);
|
);
|
||||||
excalidrawElement = {
|
|
||||||
|
const textElement = newTextElement({
|
||||||
width: metrics.width,
|
width: metrics.width,
|
||||||
height: metrics.height,
|
height: metrics.height,
|
||||||
fontFamily,
|
fontFamily,
|
||||||
fontSize,
|
fontSize,
|
||||||
...elementWithId,
|
...elementWithId,
|
||||||
};
|
});
|
||||||
|
elementStore.add(textElement);
|
||||||
elementStore.add(excalidrawElement as ExcalidrawTextElement);
|
|
||||||
} else if (elementWithId.type === "arrow") {
|
} else if (elementWithId.type === "arrow") {
|
||||||
const { linearElement, startBoundElement, endBoundElement } =
|
const { linearElement, startBoundElement, endBoundElement } =
|
||||||
bindLinearElementToElement(elementWithId, elementStore);
|
bindLinearElementToElement(elementWithId, elementStore);
|
||||||
|
@ -539,14 +537,17 @@ export const convertToExcalidrawElements = (
|
||||||
...elementWithId,
|
...elementWithId,
|
||||||
});
|
});
|
||||||
elementStore.add(imageElement);
|
elementStore.add(imageElement);
|
||||||
} else {
|
} else if (
|
||||||
excalidrawElement = {
|
elementWithId.type === "rectangle" ||
|
||||||
|
elementWithId.type === "ellipse" ||
|
||||||
|
elementWithId.type === "diamond"
|
||||||
|
) {
|
||||||
|
const element = newElement({
|
||||||
...elementWithId,
|
...elementWithId,
|
||||||
width: elementWithId?.width || DEFAULT_DIMENSION,
|
width: elementWithId?.width || DEFAULT_DIMENSION,
|
||||||
height: elementWithId?.height || DEFAULT_DIMENSION,
|
height: elementWithId?.height || DEFAULT_DIMENSION,
|
||||||
} as ExcalidrawGenericElement;
|
});
|
||||||
elementStore.add(excalidrawElement);
|
elementStore.add(element);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return elementStore.get();
|
return elementStore.get();
|
||||||
|
|
Loading…
Add table
Reference in a new issue