From 63b3a049356e84498f134e4eeecae2e8c6a69b43 Mon Sep 17 00:00:00 2001 From: Bowen Tan Date: Tue, 19 Jul 2022 14:17:42 +0800 Subject: [PATCH] fix(paste): paste component into the first slot instead of 'content' slot --- .../editor/src/components/KeyboardEventWrapper.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/components/KeyboardEventWrapper.tsx b/packages/editor/src/components/KeyboardEventWrapper.tsx index a67adc40..62877ea7 100644 --- a/packages/editor/src/components/KeyboardEventWrapper.tsx +++ b/packages/editor/src/components/KeyboardEventWrapper.tsx @@ -29,6 +29,15 @@ export const KeyboardEventWrapper: React.FC = ({ } `; + function getComponentFirstSlot(componentId: string) { + const component = components.find(c => c.id === componentId); + if (component) { + const spec = registry.getComponentByType(component?.type); + return Object.keys(spec.spec.slots)[0] || ''; + } + return ''; + } + const onKeyDown = (e: React.KeyboardEvent) => { switch (e.key) { case 'Delete': @@ -103,7 +112,7 @@ export const KeyboardEventWrapper: React.FC = ({ 'operation', genOperation(registry, 'pasteComponent', { parentId: selectedComponentId || RootId, - slot: 'content', + slot: getComponentFirstSlot(selectedComponentId), component: clonedComponent!, copyTimes: pasteManager.current.copyTimes, })