use a better cloning algorithm

This commit is contained in:
dwelle
2020-02-10 13:31:39 +01:00
parent 1ec3946ed6
commit 7279262129
3 changed files with 8 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ import { Point } from "roughjs/bin/geometry";
import { ExcalidrawElement, ExcalidrawTextElement } from "../element/types";
import { measureText } from "../utils";
import klona from "klona";
export function newElement(
type: string,
@@ -63,15 +64,7 @@ export function newTextElement(
}
export function duplicateElement(element: ReturnType<typeof newElement>) {
const copy = {
...element,
};
if ("points" in copy) {
copy.points = Array.isArray(element.points)
? JSON.parse(JSON.stringify(element.points))
: element.points;
}
const copy = klona(element);
delete copy.shape;
copy.id = nanoid();
copy.seed = randomSeed();