Explorar el Código

fix cloning element.points (#744)

David Luzar hace 5 años
padre
commit
6dd3620dd6
Se han modificado 1 ficheros con 6 adiciones y 1 borrados
  1. 6 1
      src/element/newElement.ts

+ 6 - 1
src/element/newElement.ts

@@ -65,8 +65,13 @@ export function newTextElement(
 export function duplicateElement(element: ReturnType<typeof newElement>) {
   const copy = {
     ...element,
-    points: JSON.parse(JSON.stringify(element.points)),
   };
+  if ("points" in copy) {
+    copy.points = Array.isArray(element.points)
+      ? JSON.parse(JSON.stringify(element.points))
+      : element.points;
+  }
+
   delete copy.shape;
   copy.id = nanoid();
   copy.seed = randomSeed();