Files
vue-flow/examples/NodeTypesIdChange/NodeTypesIdChangeExample.vue
Braks 39b21faa5b refactor(types)!: Remove elements prop, change EdgeTypes/NodeTypes prop to string[]
* 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>
2021-11-20 22:10:25 +01:00

54 lines
1.5 KiB
Vue

<script lang="ts" setup>
import { CSSProperties } from 'vue'
import NodeA from './NodeA.vue'
import NodeB from './NodeB.vue'
import { VueFlow, Elements, Position, Connection, Edge, addEdge, NodeTypes } from '~/index'
const initialElements: Elements = [
{
id: '1',
sourcePosition: Position.Right,
type: 'input',
data: { label: 'Input' },
position: { x: 0, y: 80 },
},
{
id: '2',
type: 'a',
sourcePosition: Position.Right,
targetPosition: Position.Left,
data: { label: 'A Node' },
position: { x: 250, y: 0 },
},
]
const buttonStyle: CSSProperties = { position: 'absolute', right: 10, top: 30, zIndex: 4 }
const nodeStyles: CSSProperties = { padding: '10px 15px', border: '1px solid #ddd' }
const nodeTypesObjects: Record<string, NodeTypes> = {
a: ['a'],
b: ['b'],
}
const elements = ref(initialElements)
const nodeTypesId = ref('a')
const changeType = () => {
const id = nodeTypesId.value === 'a' ? 'b' : 'a'
elements.value[1].type = id
nodeTypesId.value = id
}
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
</script>
<template>
<VueFlow v-model="elements" :node-types="nodeTypesObjects[nodeTypesId]" @connect="onConnect">
<template #node-a>
<NodeA :node-styles="nodeStyles" />
</template>
<template #node-b>
<NodeB :node-styles="nodeStyles" />
</template>
<button :style="buttonStyle" @click="changeType">change type</button>
</VueFlow>
</template>