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

5
package-lock.json generated
View file

@ -8296,6 +8296,11 @@
"resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz",
"integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w=="
},
"klona": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/klona/-/klona-1.1.1.tgz",
"integrity": "sha512-o/QDZouW8bt6cejtMQhw3qyqi4aTlrB7sbqzQ8+PdI/qJ3WMbmSOA//4ClIevCQp0DPUU9l1pxGRcGMkkxb8TA=="
},
"last-call-webpack-plugin": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/last-call-webpack-plugin/-/last-call-webpack-plugin-3.0.0.tgz",

View file

@ -8,6 +8,7 @@
"dependencies": {
"browser-nativefs": "0.2.0",
"i18next-browser-languagedetector": "4.0.1",
"klona": "1.1.1",
"nanoid": "2.1.11",
"react": "16.12.0",
"react-dom": "16.12.0",

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();