Sync panel props to editing element (#470)

* ensure panel props are sync to editing elem

* ensure we don't create empty-text elements (fixes #468)

* remove dead code

Co-authored-by: Christopher Chedeau <vjeuxx@gmail.com>
This commit is contained in:
David Luzar 2020-01-21 00:16:22 +01:00 committed by Christopher Chedeau
parent ff7a340d2f
commit 2340dddaad
7 changed files with 159 additions and 100 deletions

View file

@ -2,6 +2,9 @@ import { randomSeed } from "roughjs/bin/math";
import nanoid from "nanoid";
import { Drawable } from "roughjs/bin/core";
import { ExcalidrawElement, ExcalidrawTextElement } from "../element/types";
import { measureText } from "../utils";
export function newElement(
type: string,
x: number,
@ -35,6 +38,28 @@ export function newElement(
return element;
}
export function newTextElement(
element: ExcalidrawElement,
text: string,
font: string
) {
const metrics = measureText(text, font);
const textElement: ExcalidrawTextElement = {
...element,
type: "text",
text: text,
font: font,
// Center the text
x: element.x - metrics.width / 2,
y: element.y - metrics.height / 2,
width: metrics.width,
height: metrics.height,
baseline: metrics.baseline
};
return textElement;
}
export function duplicateElement(element: ReturnType<typeof newElement>) {
const copy = { ...element };
delete copy.shape;