adds drag-and-drop to the action drawer
This commit is contained in:
parent
188f2b74d7
commit
5d26724e54
|
@ -2,6 +2,7 @@
|
||||||
import FlowItem from "./FlowItem.svelte"
|
import FlowItem from "./FlowItem.svelte"
|
||||||
import Arrow from "./Arrow.svelte"
|
import Arrow from "./Arrow.svelte"
|
||||||
import { flip } from "svelte/animate"
|
import { flip } from "svelte/animate"
|
||||||
|
import {dndzone} from "svelte-dnd-action";
|
||||||
import { fade, fly } from "svelte/transition"
|
import { fade, fly } from "svelte/transition"
|
||||||
|
|
||||||
export let automation
|
export let automation
|
||||||
|
@ -17,14 +18,22 @@
|
||||||
blocks = blocks.concat(automation.definition.steps || [])
|
blocks = blocks.concat(automation.definition.steps || [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const flipDurationMs = 300;
|
||||||
|
function handleDndConsider(e) {
|
||||||
|
blocks = e.detail.items;
|
||||||
|
}
|
||||||
|
function handleDndFinalize(e) {
|
||||||
|
blocks = e.detail.items;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if !blocks.length}<i>Add a trigger to your automation to get started</i>{/if}
|
{#if !blocks.length}<i>Add a trigger to your automation to get started</i>{/if}
|
||||||
<section class="canvas">
|
<section class="canvas" use:dndzone={{items: blocks, flipDurationMs}} on:consider={handleDndConsider} on:finalize={handleDndFinalize}>
|
||||||
{#each blocks as block, idx (block.id)}
|
{#each blocks as block, idx (block.id)}
|
||||||
<div
|
<div
|
||||||
class="block"
|
class="block"
|
||||||
animate:flip={{ duration: 600 }}
|
animate:flip={{ duration: flipDurationMs}}
|
||||||
in:fade|local
|
in:fade|local
|
||||||
out:fly|local={{ x: 100 }}>
|
out:fly|local={{ x: 100 }}>
|
||||||
<FlowItem {onSelect} {block} />
|
<FlowItem {onSelect} {block} />
|
||||||
|
|
|
@ -9,9 +9,13 @@
|
||||||
const EVENT_TYPE_KEY = "##eventHandlerType"
|
const EVENT_TYPE_KEY = "##eventHandlerType"
|
||||||
|
|
||||||
export let actions
|
export let actions
|
||||||
|
|
||||||
|
// dndzone needs an id on the array items, so this adds some temporary ones.
|
||||||
|
if (actions) {
|
||||||
actions = actions.map((action, i) => {
|
actions = actions.map((action, i) => {
|
||||||
return {...action, id: i}
|
return {...action, id: i}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
let addActionButton
|
let addActionButton
|
||||||
let addActionDropdown
|
let addActionDropdown
|
||||||
|
@ -37,7 +41,7 @@
|
||||||
const newAction = {
|
const newAction = {
|
||||||
parameters: {},
|
parameters: {},
|
||||||
[EVENT_TYPE_KEY]: actionType.name,
|
[EVENT_TYPE_KEY]: actionType.name,
|
||||||
id: actions.length + 1
|
id: actions ? actions.length + 1 : 0
|
||||||
}
|
}
|
||||||
if (!actions) {
|
if (!actions) {
|
||||||
actions = []
|
actions = []
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue