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>
This commit is contained in:
Braks
2021-11-19 23:45:39 +01:00
parent 921d93c73e
commit 6a68292f7c
19 changed files with 80 additions and 96 deletions
+2 -16
View File
@@ -28,10 +28,7 @@ const onElementsRemove = (elementsToRemove: Elements) => (elements.value = remov
const onLoad = (instance: FlowInstance) => (flowInstance.value = instance)
const onDrop = (event: DragEvent) => {
event.preventDefault()
if (flowInstance.value) {
console.log(event.dataTransfer?.getData('application/vueflow'))
const type = event.dataTransfer?.getData('application/vueflow')
const position = flowInstance.value.project({ x: event.clientX, y: event.clientY - 40 })
const newNode = {
@@ -40,24 +37,13 @@ const onDrop = (event: DragEvent) => {
position,
data: { label: `${type} node` },
} as Node
elements.value.push(newNode)
}
}
</script>
<template>
<div class="dndflow">
<div class="vueflow-wrapper" @drop="onDrop">
<VueFlow
:elements="elements"
@elements-remove="onElementsRemove"
@load="onLoad"
@connect="onConnect"
@dragover="onDragOver"
>
<Controls />
</VueFlow>
</div>
<div class="dndflow" @drop="onDrop">
<VueFlow v-model="elements" @elements-remove="onElementsRemove" @load="onLoad" @connect="onConnect" @dragover="onDragOver" />
<Sidebar />
</div>
</template>