mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-11-17 11:14:23 +01:00
use a better cloning algorithm
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user