Add duplicate action to settings bar

This commit is contained in:
Andrew Kingston 2022-03-07 14:05:26 +00:00
parent d2b13cf3fa
commit e84e4f9899
3 changed files with 18 additions and 0 deletions

View File

@ -159,6 +159,11 @@
await store.actions.components.updateProp(data.prop, data.value) await store.actions.components.updateProp(data.prop, data.value)
} else if (type === "delete-component" && data.id) { } else if (type === "delete-component" && data.id) {
confirmDeleteComponent(data.id) confirmDeleteComponent(data.id)
} else if (type === "duplicate-component" && data.id) {
const rootComponent = get(currentAsset).props
const component = findComponent(rootComponent, data.id)
store.actions.components.copy(component)
await store.actions.components.paste(component)
} else if (type === "preview-loaded") { } else if (type === "preview-loaded") {
// Wait for this event to show the client library if intelligent // Wait for this event to show the client library if intelligent
// loading is supported // loading is supported

View File

@ -146,6 +146,15 @@
<div class="divider" /> <div class="divider" />
{/if} {/if}
{/each} {/each}
<SettingsButton
icon="Duplicate"
on:click={() => {
builderStore.actions.duplicateComponent(
$builderStore.selectedComponent._id
)
}}
title="Duplicate component"
/>
<SettingsButton <SettingsButton
icon="Delete" icon="Delete"
on:click={() => { on:click={() => {
@ -153,6 +162,7 @@
$builderStore.selectedComponent._id $builderStore.selectedComponent._id
) )
}} }}
title="Delete component"
/> />
</div> </div>
{/if} {/if}

View File

@ -62,6 +62,9 @@ const createBuilderStore = () => {
deleteComponent: id => { deleteComponent: id => {
dispatchEvent("delete-component", { id }) dispatchEvent("delete-component", { id })
}, },
duplicateComponent: id => {
dispatchEvent("duplicate-component", { id })
},
notifyLoaded: () => { notifyLoaded: () => {
dispatchEvent("preview-loaded") dispatchEvent("preview-loaded")
}, },