* no more elements prop - v-model instead! * Instead of passing an object map to components just pass in an array of strings as nodeTypes/edgeTypes object * the string name will either be resolved to a dynamic component with :is="type" or a slot with the type-name * update all examples Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
55 lines
1.2 KiB
Vue
55 lines
1.2 KiB
Vue
<script lang="ts" setup>
|
|
import ButtonEdge from './ButtonEdge.vue'
|
|
import {
|
|
VueFlow,
|
|
addEdge,
|
|
Background,
|
|
Connection,
|
|
Controls,
|
|
Edge,
|
|
Elements,
|
|
MiniMap,
|
|
FlowInstance,
|
|
removeElements,
|
|
} from '~/index'
|
|
|
|
const elements = ref<Elements>([
|
|
{
|
|
id: 'ewb-1',
|
|
type: 'input',
|
|
data: { label: 'Input 1' },
|
|
position: { x: 250, y: 0 },
|
|
},
|
|
{ id: 'ewb-2', data: { label: 'Node 2' }, position: { x: 250, y: 300 } },
|
|
{
|
|
id: 'edge-1-2',
|
|
source: 'ewb-1',
|
|
target: 'ewb-2',
|
|
type: 'button',
|
|
},
|
|
])
|
|
|
|
const onLoad = (flowInstance: FlowInstance) => flowInstance.fitView()
|
|
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
|
|
const onConnect = (params: Connection | Edge) =>
|
|
(elements.value = addEdge({ ...params, type: 'buttonedge' } as Edge, elements.value))
|
|
</script>
|
|
<template>
|
|
<VueFlow
|
|
key="edge-with-button"
|
|
v-model="elements"
|
|
:snap-to-grid="true"
|
|
:edge-types="['button']"
|
|
@load="onLoad"
|
|
@elementsRemove="onElementsRemove"
|
|
@connect="onConnect"
|
|
>
|
|
<template #edge-button="props">
|
|
<ButtonEdge v-bind="props" />
|
|
</template>
|
|
<MiniMap />
|
|
<Controls />
|
|
<Background />
|
|
</VueFlow>
|
|
</template>
|