feat: use v-html for node labels

* add span tag as wrapper for node labels

feat(examples):

* Add overview example
This commit is contained in:
Braks
2021-10-21 15:29:17 +02:00
parent a9f187697a
commit 636eeff9fe
8 changed files with 231 additions and 11 deletions

View File

@@ -0,0 +1,45 @@
<script lang="ts" setup>
import { CSSProperties } from 'vue'
import Flow, { addEdge, Connection, Elements, OnLoadParams, Position, Edge, isEdge } from '~/index'
const onLoad = (reactFlowInstance: OnLoadParams) => reactFlowInstance.fitView()
const initialElements: Elements = [
{
id: '1',
sourcePosition: Position.Right,
type: 'input',
data: { label: 'Input' },
position: { x: 0, y: 80 },
},
{
id: '2',
type: 'output',
sourcePosition: Position.Right,
targetPosition: Position.Left,
data: { label: 'A Node' },
position: { x: 250, y: 0 },
},
{ id: 'e1-2', source: '1', type: 'smoothstep', target: '2', animated: true },
] as Elements
const buttonStyle: CSSProperties = { position: 'absolute', right: 10, top: 30, zIndex: 4 }
const elements = ref<Elements>(initialElements)
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const changeType = () => {
elements.value = elements.value.map((el) => {
if (isEdge(el) || el.type === 'input') return el
return {
...el,
type: el.type === 'default' ? 'output' : 'default',
}
})
}
</script>
<template>
<Flow :elements="elements" @connect="onConnect" @load="onLoad">
<button :style="buttonStyle" @click="changeType">change type</button>
</Flow>
</template>