mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-25 02:10:38 +02:00
support ids, clean up code and move the api related stuff to transform.ts
This commit is contained in:
@@ -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];
|
||||
};
|
||||
|
Reference in New Issue
Block a user