From 8a2f5f6beb2219b8dec8be15b2ff8dd762d591e3 Mon Sep 17 00:00:00 2001 From: Berci Kormendy Date: Mon, 5 Feb 2024 12:20:18 +0100 Subject: [PATCH 1/2] `getFragmentUidFromInsertionPath` --- .../components/editor/store/insertion-path.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/editor/src/components/editor/store/insertion-path.ts b/editor/src/components/editor/store/insertion-path.ts index 5c85616e6e17..58c8a19ba5b8 100644 --- a/editor/src/components/editor/store/insertion-path.ts +++ b/editor/src/components/editor/store/insertion-path.ts @@ -113,6 +113,30 @@ export function insertionPathToString(insertionPath: InsertionPath): string { assertNever(insertionPath) } } +export function getFragmentUidFromInsertionBehaviour( + insertionBehaviour: ConditionalClauseInsertBehavior, +): string | null { + switch (insertionBehaviour.type) { + case 'replace-with-elements-wrapped-in-fragment': + case 'wrap-in-fragment-and-append-elements': + return insertionBehaviour.fragmentUID + case 'replace-with-single-element': + return null + default: + assertNever(insertionBehaviour) + } +} + +export function getFragmentUidFromInsertionPath(insertionPath: InsertionPath): string | null { + switch (insertionPath.type) { + case 'CHILD_INSERTION': + return null + case 'CONDITIONAL_CLAUSE_INSERTION': + return getFragmentUidFromInsertionBehaviour(insertionPath.insertBehavior) + default: + assertNever(insertionPath) + } +} export function commonInsertionPath( metadata: ElementInstanceMetadataMap, From e1601bd7dfc7caa7713688e4ad7bbd4455ee12ae Mon Sep 17 00:00:00 2001 From: Berci Kormendy Date: Mon, 5 Feb 2024 12:20:34 +0100 Subject: [PATCH 2/2] cehck wrapper uid --- .../post-action-options/post-action-paste.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/editor/src/components/canvas/canvas-strategies/post-action-options/post-action-paste.ts b/editor/src/components/canvas/canvas-strategies/post-action-options/post-action-paste.ts index c8ddf989e458..7ef2a55c721f 100644 --- a/editor/src/components/canvas/canvas-strategies/post-action-options/post-action-paste.ts +++ b/editor/src/components/canvas/canvas-strategies/post-action-options/post-action-paste.ts @@ -20,6 +20,7 @@ import { offsetPoint, } from '../../../../core/shared/math-utils' import type { CanvasPoint } from '../../../../core/shared/math-utils' +import { optionalMap } from '../../../../core/shared/optional-utils' import type { ElementPath, ElementPathPart, @@ -42,6 +43,7 @@ import type { import { trueUpGroupElementChanged } from '../../../editor/store/editor-state' import { childInsertionPath, + getFragmentUidFromInsertionPath, replaceWithElementsWrappedInFragmentBehaviour, } from '../../../editor/store/insertion-path' import type { CanvasCommand } from '../../commands/commands' @@ -166,7 +168,10 @@ function pasteChoiceCommon( ) : front() - let fixedUIDMappingNewUIDS: Array = [] + let fixedUIDMappingNewUIDS: Array = + optionalMap((wrapperUid) => [wrapperUid], getFragmentUidFromInsertionPath(target.parentPath)) ?? + [] + let oldPathToNewPathMapping: OldPathToNewPathMapping = {} const elementsToInsert: Array = pasteContext.elementPasteWithMetadata.elements.map((elementPaste) => {