Files
vue-flow/examples/Empty/EmptyExample.vue
Braks 6a68292f7c feat: merge store with props
* if options are passed to useVueFlow, we want to merge them with possibly passed props
* renamed flowStore to stateStore
* fix examples
* add store prop to pass an already existing store to flow

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
2021-11-19 23:45:39 +01:00

55 lines
1.6 KiB
Vue

<script lang="ts" setup>
import { CSSProperties } from 'vue'
import {
VueFlow,
MiniMap,
Controls,
Background,
BackgroundVariant,
Connection,
Edge,
ElementId,
Elements,
FlowElement,
Node,
FlowInstance,
addEdge,
removeElements,
} from '~/index'
const elements = ref<Elements>([])
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const onLoad = (flowInstance: FlowInstance) => console.log('flow loaded:', flowInstance)
const onElementClick = (element: FlowElement) => console.log('click', element)
const onNodeDragStop = (node: Node) => console.log('drag stop', node)
const buttonStyle: CSSProperties = { position: 'absolute', left: '10px', top: '10px', zIndex: 4 }
const addRandomNode = () => {
const nodeId: ElementId = (elements.value.length + 1).toString()
const newNode: Node = {
id: nodeId,
data: { label: `Node: ${nodeId}` },
position: { x: Math.random() * window.innerWidth, y: Math.random() * window.innerHeight },
} as Node
elements.value = [...elements.value, newNode]
}
</script>
<template>
<VueFlow
v-model="elements"
@load="onLoad"
@element-click="onElementClick"
@elements-remove="onElementsRemove"
@connect="(p) => onConnect(p)"
@node-drag-stop="onNodeDragStop"
>
<MiniMap />
<Controls />
<Background :variant="BackgroundVariant.Lines" />
<button type="button" :style="buttonStyle" @click="addRandomNode">add node</button>
</VueFlow>
</template>