2020-06-01 23:16:55 +02:00
|
|
|
<script>
|
2020-12-07 16:27:46 +01:00
|
|
|
import { get } from "svelte/store"
|
|
|
|
import { store, currentAsset } from "builderStore"
|
2020-06-01 13:15:44 +02:00
|
|
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
2021-01-12 21:00:35 +01:00
|
|
|
import { findComponentParent } from "builderStore/storeUtils"
|
2021-04-26 14:42:45 +02:00
|
|
|
import { ActionMenu, MenuItem, Icon } from "@budibase/bbui"
|
2020-06-01 13:15:44 +02:00
|
|
|
|
|
|
|
export let component
|
|
|
|
|
|
|
|
let confirmDeleteDialog
|
2020-09-07 00:50:11 +02:00
|
|
|
let anchor
|
2020-09-06 23:58:47 +02:00
|
|
|
|
2021-02-09 11:49:22 +01:00
|
|
|
$: definition = store.actions.components.getDefinition(component?._component)
|
|
|
|
$: noChildrenAllowed = !component || !definition?.hasChildren
|
2020-06-02 12:11:53 +02:00
|
|
|
$: noPaste = !$store.componentToPaste
|
2020-06-01 13:15:44 +02:00
|
|
|
|
|
|
|
const moveUpComponent = () => {
|
2021-01-14 10:09:23 +01:00
|
|
|
const asset = get(currentAsset)
|
|
|
|
const parent = findComponentParent(asset.props, component._id)
|
|
|
|
if (!parent) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const currentIndex = parent._children.indexOf(component)
|
|
|
|
if (currentIndex === 0) {
|
|
|
|
return
|
|
|
|
}
|
2021-04-23 12:39:48 +02:00
|
|
|
const newChildren = parent._children.filter((c) => c !== component)
|
2021-01-14 10:09:23 +01:00
|
|
|
newChildren.splice(currentIndex - 1, 0, component)
|
|
|
|
parent._children = newChildren
|
|
|
|
store.actions.preview.saveSelected()
|
2020-06-01 13:15:44 +02:00
|
|
|
}
|
2020-06-01 13:12:25 +02:00
|
|
|
|
2020-06-01 13:15:44 +02:00
|
|
|
const moveDownComponent = () => {
|
2021-01-14 10:09:23 +01:00
|
|
|
const asset = get(currentAsset)
|
|
|
|
const parent = findComponentParent(asset.props, component._id)
|
|
|
|
if (!parent) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const currentIndex = parent._children.indexOf(component)
|
|
|
|
if (currentIndex === parent._children.length - 1) {
|
|
|
|
return
|
|
|
|
}
|
2021-04-23 12:39:48 +02:00
|
|
|
const newChildren = parent._children.filter((c) => c !== component)
|
2021-01-14 10:09:23 +01:00
|
|
|
newChildren.splice(currentIndex + 1, 0, component)
|
|
|
|
parent._children = newChildren
|
|
|
|
store.actions.preview.saveSelected()
|
2020-06-01 13:15:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-05 12:44:18 +01:00
|
|
|
const duplicateComponent = () => {
|
2020-10-07 23:30:00 +02:00
|
|
|
storeComponentForCopy(false)
|
|
|
|
pasteComponent("below")
|
2020-06-01 13:15:44 +02:00
|
|
|
}
|
2020-06-01 13:12:25 +02:00
|
|
|
|
2021-02-23 17:29:50 +01:00
|
|
|
const deleteComponent = async () => {
|
|
|
|
await store.actions.components.delete(component)
|
2020-06-01 13:15:44 +02:00
|
|
|
}
|
2020-06-01 13:12:25 +02:00
|
|
|
|
2020-06-01 13:15:44 +02:00
|
|
|
const storeComponentForCopy = (cut = false) => {
|
2020-08-12 17:28:19 +02:00
|
|
|
// lives in store - also used by drag drop
|
2020-11-04 18:09:45 +01:00
|
|
|
store.actions.components.copy(component, cut)
|
2020-06-01 13:15:44 +02:00
|
|
|
}
|
2020-06-01 13:12:25 +02:00
|
|
|
|
2021-04-23 12:39:48 +02:00
|
|
|
const pasteComponent = (mode) => {
|
2020-08-12 17:28:19 +02:00
|
|
|
// lives in store - also used by drag drop
|
2020-11-04 18:09:45 +01:00
|
|
|
store.actions.components.paste(component, mode)
|
2020-06-01 13:15:44 +02:00
|
|
|
}
|
2020-06-01 11:18:45 +02:00
|
|
|
</script>
|
|
|
|
|
2021-04-27 11:48:47 +02:00
|
|
|
<ActionMenu>
|
2021-04-27 15:34:17 +02:00
|
|
|
<div slot="control" class="icon">
|
2021-04-27 16:30:13 +02:00
|
|
|
<Icon size="S" hoverable name="MoreSmallList" />
|
2021-04-26 12:29:45 +02:00
|
|
|
</div>
|
2021-04-27 15:34:17 +02:00
|
|
|
<MenuItem icon="Delete" on:click={confirmDeleteDialog.show}>Delete</MenuItem>
|
|
|
|
<MenuItem noClose icon="ChevronUp" on:click={moveUpComponent}
|
|
|
|
>Move up</MenuItem
|
2021-04-26 14:42:45 +02:00
|
|
|
>
|
2021-04-27 15:34:17 +02:00
|
|
|
<MenuItem noClose icon="ChevronDown" on:click={moveDownComponent}
|
|
|
|
>Move down</MenuItem
|
|
|
|
>
|
|
|
|
<MenuItem noClose icon="Duplicate" on:click={duplicateComponent}
|
|
|
|
>Duplicate</MenuItem
|
|
|
|
>
|
|
|
|
<MenuItem icon="Cut" on:click={() => storeComponentForCopy(true)}
|
|
|
|
>Cut</MenuItem
|
2021-04-26 14:42:45 +02:00
|
|
|
>
|
|
|
|
<MenuItem icon="Copy" on:click={() => storeComponentForCopy(false)}
|
|
|
|
>Copy</MenuItem
|
|
|
|
>
|
|
|
|
<MenuItem
|
|
|
|
icon="LayersBringToFront"
|
2021-04-27 11:48:47 +02:00
|
|
|
on:click={() => pasteComponent("above")}
|
2021-04-26 14:42:45 +02:00
|
|
|
disabled={noPaste}>Paste above</MenuItem
|
|
|
|
>
|
|
|
|
<MenuItem
|
|
|
|
icon="LayersSendToBack"
|
2021-04-27 11:48:47 +02:00
|
|
|
on:click={() => pasteComponent("below")}
|
2021-04-26 14:42:45 +02:00
|
|
|
disabled={noPaste}>Paste below</MenuItem
|
|
|
|
>
|
|
|
|
<MenuItem
|
|
|
|
icon="ShowOneLayer"
|
2021-04-27 11:48:47 +02:00
|
|
|
on:click={() => pasteComponent("inside")}
|
2021-04-26 14:42:45 +02:00
|
|
|
disabled={noPaste || noChildrenAllowed}>Paste inside</MenuItem
|
|
|
|
>
|
2021-04-26 12:29:45 +02:00
|
|
|
</ActionMenu>
|
2020-06-01 11:18:45 +02:00
|
|
|
<ConfirmDialog
|
|
|
|
bind:this={confirmDeleteDialog}
|
2020-10-28 17:05:19 +01:00
|
|
|
title="Confirm Deletion"
|
2021-02-09 11:49:22 +01:00
|
|
|
body={`Are you sure you wish to delete this '${definition?.name}' component?`}
|
2020-06-01 11:18:45 +02:00
|
|
|
okText="Delete Component"
|
2021-04-23 12:39:48 +02:00
|
|
|
onOk={deleteComponent}
|
|
|
|
/>
|
2020-06-01 11:18:45 +02:00
|
|
|
|
|
|
|
<style>
|
2020-10-26 15:23:08 +01:00
|
|
|
hr {
|
2020-06-01 16:31:55 +02:00
|
|
|
margin: 8px 0;
|
2020-10-26 15:23:08 +01:00
|
|
|
background-color: var(--grey-4);
|
|
|
|
height: 1px;
|
|
|
|
border: none;
|
2020-06-01 16:31:55 +02:00
|
|
|
}
|
2020-06-01 13:15:44 +02:00
|
|
|
</style>
|