support ids, clean up code and move the api related stuff to transform.ts

This commit is contained in:
Aakansha Doshi
2023-05-24 17:12:26 +05:30
parent da8e97ad14
commit 985318e960
11 changed files with 337 additions and 250 deletions

View File

@@ -980,55 +980,3 @@ export const getDefaultLineHeight = (fontFamily: FontFamilyValues) => {
}
return DEFAULT_LINE_HEIGHT[DEFAULT_FONT_FAMILY];
};
export const bindTextToContainer = (
containerProps:
| {
type:
| Exclude<ExcalidrawGenericElement["type"], "selection">
| ExcalidrawLinearElement["type"];
} & MarkOptional<ElementConstructorOpts, "x" | "y">,
textProps: { text: string } & MarkOptional<ElementConstructorOpts, "x" | "y">,
) => {
let container;
if (containerProps.type === "arrow") {
container = newLinearElement({
width: containerProps.width || 300,
height: containerProps.height || 24,
//@ts-ignore
type: containerProps.type,
//@ts-ignore,
endArrowhead: containerProps.type === "arrow" ? "arrow" : null,
//@ts-ignore
points: [
[0, 0],
[300, 0],
],
...containerProps,
});
} else {
//@ts-ignore
container = newElement({
...containerProps,
});
}
const textElement: ExcalidrawTextElement = newTextElement({
x: 0,
y: 0,
textAlign: TEXT_ALIGN.CENTER,
verticalAlign: VERTICAL_ALIGN.MIDDLE,
...textProps,
containerId: container.id,
});
mutateElement(container, {
boundElements: (container.boundElements || []).concat({
type: "text",
id: textElement.id,
}),
});
redrawTextBoundingBox(textElement, container);
return [container, textElement];
};