From 9bef4c0280aee6c3b65bbc9ac395ba5274e738a6 Mon Sep 17 00:00:00 2001 From: pubuzhixing8 Date: Fri, 19 Apr 2024 15:53:43 +0800 Subject: [PATCH] fix(duplicate-element): fix console error after duplicate content --- .changeset/tidy-weeks-provide.md | 5 +++++ packages/core/src/utils/fragment.ts | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/tidy-weeks-provide.md diff --git a/.changeset/tidy-weeks-provide.md b/.changeset/tidy-weeks-provide.md new file mode 100644 index 000000000..6d1b269bb --- /dev/null +++ b/.changeset/tidy-weeks-provide.md @@ -0,0 +1,5 @@ +--- +'@plait/core': patch +--- + +clone the duplicated content before inserting to resolve console error diff --git a/packages/core/src/utils/fragment.ts b/packages/core/src/utils/fragment.ts index 0487dd06f..055ef7d99 100644 --- a/packages/core/src/utils/fragment.ts +++ b/packages/core/src/utils/fragment.ts @@ -20,10 +20,12 @@ export const duplicateElements = (board: PlaitBoard, elements?: PlaitElement[]) const selectedElements = elements || getSelectedElements(board); const rectangle = getRectangleByElements(board, selectedElements, false); const clipboardContext = board.buildFragment(null, rectangle, 'copy'); - clipboardContext && + const stringifiedContext = clipboardContext && JSON.stringify(clipboardContext); + const clonedContext = stringifiedContext && JSON.parse(stringifiedContext); + clonedContext && board.insertFragment( { - ...clipboardContext, + ...clonedContext, text: undefined }, [rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height / 2]