fix(paste): paste component into the first slot instead of 'content' slot

This commit is contained in:
Bowen Tan 2022-07-19 14:17:42 +08:00
parent 267ab40b37
commit 63b3a04935

View File

@ -29,6 +29,15 @@ export const KeyboardEventWrapper: React.FC<Props> = ({
} }
`; `;
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<HTMLInputElement>) => { const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
switch (e.key) { switch (e.key) {
case 'Delete': case 'Delete':
@ -103,7 +112,7 @@ export const KeyboardEventWrapper: React.FC<Props> = ({
'operation', 'operation',
genOperation(registry, 'pasteComponent', { genOperation(registry, 'pasteComponent', {
parentId: selectedComponentId || RootId, parentId: selectedComponentId || RootId,
slot: 'content', slot: getComponentFirstSlot(selectedComponentId),
component: clonedComponent!, component: clonedComponent!,
copyTimes: pasteManager.current.copyTimes, copyTimes: pasteManager.current.copyTimes,
}) })