update(docs): Add all examples

This commit is contained in:
Braks
2021-11-06 08:54:35 +01:00
parent 61779638ac
commit e99dfc3dd2
54 changed files with 2582 additions and 285 deletions
+19 -7
View File
@@ -26,7 +26,10 @@ const elements = ref<Elements>([
])
const rfInstance = ref<FlowInstance | null>(null)
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
const onConnect = (params: Edge | Connection) => (elements.value = addEdge(params, elements.value))
const onConnect = (params: Edge | Connection) => {
elements.value = addEdge(params, elements.value)
console.log(params)
}
const onLoad = (flowInstance: FlowInstance) => {
flowInstance.fitView({ padding: 0.1 })
rfInstance.value = flowInstance
@@ -49,7 +52,7 @@ const resetTransform = () => rfInstance.value?.setTransform({ x: 0, y: 0, zoom:
const toggleClassnames = () => {
elements.value = elements.value.map((el: FlowElement) => {
if (isNode(el)) el.class = el.class === 'light' ? 'dark' : 'light'
if (isNode(el)) el.class = el.class === 'dark' ? 'light' : 'dark'
return el
})
}
@@ -71,11 +74,20 @@ const toggleClassnames = () => {
<MiniMap />
<Controls />
<Background color="#aaa" :gap="8" />
<div style="position: absolute; right: 10px; top: 10px; z-index: 4">
<button style="margin-right: 5px" @click="resetTransform">reset transform</button>
<button style="margin-right: 5px" @click="updatePos">change pos</button>
<button style="margin-right: 5px" @click="toggleClassnames">toggle classnames</button>
<button @click="logToObject">toObject</button>
<div class="absolute right-[10px] top-[10px] z-4">
<button class="button" @click="resetTransform">reset transform</button>
<button class="button" @click="updatePos">change pos</button>
<button class="button" @click="toggleClassnames">toggle classnames</button>
<button class="button" @click="logToObject">toObject</button>
</div>
</Flow>
</template>
<style>
.vue-flow--node .light {
@apply bg-white;
}
.vue-flow--node .dark {
@apply bg-black;
}
</style>
+54
View File
@@ -0,0 +1,54 @@
<script lang="ts" setup>
import Flow, {
addEdge,
Background,
Connection,
Controls,
Edge,
EdgeType,
Elements,
MiniMap,
FlowInstance,
removeElements,
} from '@braks/vue-flow'
import ButtonEdge from '../../components/ButtonEdge.vue'
const edgeTypes = {
buttonedge: ButtonEdge as EdgeType,
}
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: 'buttonedge',
},
])
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>
<Flow
key="edge-with-button"
:elements="elements"
:snap-to-grid="true"
:edge-types="edgeTypes"
@load="onLoad"
@elementsRemove="onElementsRemove"
@connect="onConnect"
>
<MiniMap />
<Controls />
<Background />
</Flow>
</template>
@@ -0,0 +1,23 @@
<script lang="ts" setup>
import Flow, { removeElements, addEdge, Background, BackgroundVariant, Elements, Connection, Edge } from '@braks/vue-flow'
import CustomConnectionLine from '../../components/CustomConnectionLine.vue'
const elements = ref<Elements>([
{
id: '1',
type: 'input',
data: { label: 'Node 1' },
position: { x: 250, y: 5 },
},
])
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
</script>
<template>
<Flow :elements="elements" @elements-remove="onElementsRemove" @connect="onConnect">
<template #custom-connection-line="props">
<CustomConnectionLine v-bind="props" />
</template>
<Background :variant="BackgroundVariant.Lines" />
</Flow>
</template>
+131
View File
@@ -0,0 +1,131 @@
<script lang="ts" setup>
import Flow, {
isEdge,
removeElements,
addEdge,
MiniMap,
Controls,
Node,
FlowElement,
FlowInstance,
Elements,
Position,
SnapGrid,
Connection,
ConnectionMode,
Edge,
} from '@braks/vue-flow'
import ColorPickerNode from '../../components/ColorPickerNode.vue'
const elements = ref<Elements>([])
const bgColor = ref('#1A192B')
const connectionLineStyle = { stroke: '#fff' }
const snapGrid: SnapGrid = [16, 16]
const nodeTypes = {
selectorNode: ColorPickerNode,
}
const onLoad = (flowInstance: FlowInstance) => {
flowInstance.fitView()
console.log('flow loaded:', flowInstance)
}
const onNodeDragStop = (_: MouseEvent, node: Node) => console.log('drag stop', node)
const onElementClick = (_: MouseEvent, element: FlowElement) => console.log('click', element)
const nodeStroke = (n: Node): string => {
if (n.type === 'input') return '#0041d0'
if (n.type === 'selectorNode') return bgColor.value
if (n.type === 'output') return '#ff0072'
return '#eee'
}
const nodeColor = (n: Node): string => {
if (n.type === 'selectorNode') return bgColor.value
return '#fff'
}
onMounted(() => {
const onChange = (event: Event) => {
elements.value = elements.value.map((e: FlowElement) => {
if (isEdge(e) || e.id !== '2') {
return e
}
const color = (event.target as HTMLInputElement).value
bgColor.value = color
return {
...e,
data: {
...e.data,
color,
},
}
})
}
elements.value = [
{
id: '1',
type: 'input',
data: { label: 'An input node' },
position: { x: 0, y: 50 },
sourcePosition: Position.Right,
},
{
id: '2',
type: 'selectorNode',
data: { onChange, color: bgColor.value },
style: { border: '1px solid #777', padding: '10px' },
position: { x: 250, y: 50 },
},
{
id: '3',
type: 'output',
data: { label: 'Output A' },
position: { x: 650, y: 25 },
targetPosition: Position.Left,
},
{
id: '4',
type: 'output',
data: { label: 'Output B' },
position: { x: 650, y: 100 },
targetPosition: Position.Left,
},
{ id: 'e1-2', source: '1', target: '2', animated: true, style: { stroke: '#fff' } },
{ id: 'e2a-3', source: '2', sourceHandle: 'a', target: '3', animated: true, style: { stroke: '#fff' } },
{ id: 'e2b-4', source: '2', sourceHandle: 'b', target: '4', animated: true, style: { stroke: '#fff' } },
]
})
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
const onConnect = (params: Connection | Edge) =>
(elements.value = addEdge(
{
...params,
animated: true,
style: { stroke: '#fff' },
} as Edge,
elements.value,
))
</script>
<template>
<Flow
:elements="elements"
:style="`background: ${bgColor}`"
:node-types="nodeTypes"
:connection-mode="ConnectionMode.Loose"
:connection-line-style="connectionLineStyle"
:snap-to-grid="true"
:snap-grid="snapGrid"
:default-zoom="1.5"
@element-click="onElementClick"
@elements-remove="onElementsRemove"
@connect="onConnect"
@node-drag-stop="onNodeDragStop"
@load="onLoad"
>
<MiniMap :node-stroke-color="nodeStroke" :node-color="nodeColor" />
<Controls />
</Flow>
</template>
+69
View File
@@ -0,0 +1,69 @@
<script lang="ts" setup>
import Flow, {
addEdge,
removeElements,
Controls,
MiniMap,
Background,
FlowInstance,
Elements,
Connection,
Edge,
ElementId,
} from '@braks/vue-flow'
import Sidebar from '../../components/DnDSidebar.vue'
const flowInstance = ref<FlowInstance>()
const elements = ref<Elements>([
{
id: '1',
type: 'input',
data: { label: 'input node' },
position: { x: 250, y: 5 },
},
])
let id = 0
const getId = (): ElementId => `dndnode_${id++}`
const onDragOver = (event: DragEvent) => {
event.preventDefault()
if (event.dataTransfer) {
event.dataTransfer.dropEffect = 'move'
}
}
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
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 - 400, y: event.clientY - 40 })
const newNode = {
id: getId(),
type,
position,
data: { label: `${type} node` },
}
elements.value.push(newNode)
}
}
</script>
<template>
<div class="flex flex-col md:flex-row h-full">
<div class="flex-1 h-full" @drop="onDrop">
<Flow :elements="elements" @elements-remove="onElementsRemove" @load="onLoad" @connect="onConnect" @dragover="onDragOver">
<Controls />
<MiniMap />
<Background color="#aaa" :gap="8" />
</Flow>
</div>
<Sidebar />
</div>
</template>
+32
View File
@@ -0,0 +1,32 @@
<script lang="ts" setup>
/**
* Example for checking the different edge types and source and target positions
*/
import Flow, {
removeElements,
addEdge,
MiniMap,
Controls,
Background,
FlowInstance,
Connection,
Edge,
Elements,
} from '@braks/vue-flow'
import { getElements } from './edgeTypesUtils'
const onLoad = (flowInstance: FlowInstance) => {
flowInstance.fitView()
console.log(flowInstance.getElements())
}
const elements = ref<Elements>(getElements())
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
</script>
<template>
<Flow :elements="elements" :min-zoom="0.2" @load="onLoad" @elements-remove="onElementsRemove" @connect="onConnect">
<MiniMap />
<Controls />
</Flow>
</template>
+106
View File
@@ -0,0 +1,106 @@
import { ElementId, Elements, Position } from '@braks/vue-flow'
const nodeWidth = 80
const nodeGapWidth = nodeWidth * 2
const nodeStyle = { width: `${nodeWidth}px`, fontSize: '11px', color: 'white' }
const sourceTargetPositions = [
{ source: Position.Bottom, target: Position.Top },
{ source: Position.Right, target: Position.Left },
]
const nodeColors = [
['#1e9e99', '#4cb3ac', '#6ec9c0', '#8ddfd4'],
['#0f4c75', '#1b5d8b', '#276fa1', '#3282b8'],
]
const edgeTypes = ['default', 'step', 'smoothstep', 'straight']
const offsets = [
{
x: 0,
y: -nodeGapWidth,
},
{
x: nodeGapWidth,
y: -nodeGapWidth,
},
{
x: nodeGapWidth,
y: 0,
},
{
x: nodeGapWidth,
y: nodeGapWidth,
},
{
x: 0,
y: nodeGapWidth,
},
{
x: -nodeGapWidth,
y: nodeGapWidth,
},
{
x: -nodeGapWidth,
y: 0,
},
{
x: -nodeGapWidth,
y: -nodeGapWidth,
},
]
let id = 0
const getNodeId = (): ElementId => (id++).toString()
export function getElements(): Elements {
const initialElements = []
for (let sourceTargetIndex = 0; sourceTargetIndex < sourceTargetPositions.length; sourceTargetIndex++) {
const currSourceTargetPos = sourceTargetPositions[sourceTargetIndex]
for (let edgeTypeIndex = 0; edgeTypeIndex < edgeTypes.length; edgeTypeIndex++) {
const currEdgeType = edgeTypes[edgeTypeIndex]
for (let offsetIndex = 0; offsetIndex < offsets.length; offsetIndex++) {
const currOffset = offsets[offsetIndex]
const style = { ...nodeStyle, background: nodeColors[sourceTargetIndex][edgeTypeIndex] }
const sourcePosition = {
x: offsetIndex * nodeWidth * 4,
y: edgeTypeIndex * 300 + sourceTargetIndex * edgeTypes.length * 300,
}
const sourceId = getNodeId()
const sourceData = { label: `Source ${sourceId}` }
const sourceNode = {
id: sourceId,
style,
data: sourceData,
position: sourcePosition,
sourcePosition: currSourceTargetPos.source,
targetPosition: currSourceTargetPos.target,
}
const targetId = getNodeId()
const targetData = { label: `Target ${targetId}` }
const targetPosition = {
x: sourcePosition.x + currOffset.x,
y: sourcePosition.y + currOffset.y,
}
const targetNode = {
id: targetId,
style,
data: targetData,
position: targetPosition,
sourcePosition: currSourceTargetPos.source,
targetPosition: currSourceTargetPos.target,
}
initialElements.push(sourceNode)
initialElements.push(targetNode)
initialElements.push({ id: `${sourceId}-${targetId}`, source: sourceId, target: targetId, type: currEdgeType })
}
}
}
return initialElements
}
+105
View File
@@ -0,0 +1,105 @@
<script lang="ts" setup>
import Flow, {
MiniMap,
Controls,
Background,
Elements,
FlowInstance,
FlowElement,
removeElements,
Connection,
Edge,
addEdge,
ArrowHeadType,
} from '@braks/vue-flow'
import CustomEdge from '../../components/CustomEdge.vue'
import CustomEdge2 from '../../components/CustomEdge2.vue'
import CustomLabel from '../../components/CustomLabel.vue'
const initialElements: Elements = [
{ id: '1', type: 'input', data: { label: 'Input 1' }, position: { x: 250, y: 0 } },
{ id: '2', data: { label: 'Node 2' }, position: { x: 150, y: 100 } },
{ id: '2a', data: { label: 'Node 2a' }, position: { x: 0, y: 180 } },
{ id: '3', data: { label: 'Node 3' }, position: { x: 250, y: 200 } },
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 300 } },
{ id: '3a', data: { label: 'Node 3a' }, position: { x: 150, y: 300 } },
{ id: '5', data: { label: 'Node 5' }, position: { x: 250, y: 400 } },
{ id: '6', type: 'output', data: { label: 'Output 6' }, position: { x: 50, y: 550 } },
{ id: '7', type: 'output', data: { label: 'Output 7' }, position: { x: 250, y: 550 } },
{ id: '8', type: 'output', data: { label: 'Output 8' }, position: { x: 525, y: 600 } },
{ id: '9', type: 'output', data: { label: 'Output 9' }, position: { x: 675, y: 500 } },
{ id: 'e1-2', source: '1', target: '2', label: 'bezier edge (default)', class: 'normal-edge' },
{ id: 'e2-2a', source: '2', target: '2a', type: 'smoothstep', label: 'smoothstep edge' },
{ id: 'e2-3', source: '2', target: '3', type: 'step', label: 'step edge' },
{ id: 'e3-4', source: '3', target: '4', type: 'straight', label: 'straight edge' },
{ id: 'e3-3a', source: '3', target: '3a', type: 'straight', label: 'label only edge', style: { stroke: 'none' } },
{ id: 'e3-5', source: '4', target: '5', animated: true, label: 'animated styled edge', style: { stroke: 'red' } },
{
id: 'e5-6',
source: '5',
target: '6',
label: {
component: CustomLabel,
props: {
text: 'custom label text',
},
},
labelStyle: { fill: 'red', fontWeight: 700 },
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e5-7',
source: '5',
target: '7',
label: 'label with styled bg',
labelBgPadding: [8, 4],
labelBgBorderRadius: 4,
labelBgStyle: { fill: '#FFCC00', color: '#fff', fillOpacity: 0.7 },
arrowHeadType: ArrowHeadType.ArrowClosed,
},
{
id: 'e5-8',
source: '5',
target: '8',
type: 'custom',
data: { text: 'custom edge' },
arrowHeadType: ArrowHeadType.ArrowClosed,
},
{
id: 'e5-9',
source: '5',
target: '9',
type: 'custom2',
data: { text: 'custom edge 2' },
},
]
const edgeTypes: Record<string, any> = {
custom: CustomEdge,
custom2: CustomEdge2,
}
const elements = ref<Elements>(initialElements)
const onLoad = (flowInstance: FlowInstance) => flowInstance.fitView()
const onNodeDragStop = (node: Node) => console.log('drag stop', node)
const onElementClick = (element: FlowElement) => console.log('click', element)
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
</script>
<template>
<Flow
:elements="elements"
:snap-to-grid="true"
:edge-types="edgeTypes"
@element-click="onElementClick"
@elements-remove="onElementsRemove"
@connect="onConnect"
@node-drag-stop="onNodeDragStop"
@load="onLoad"
>
<MiniMap />
<Controls />
<Background />
</Flow>
</template>
+53
View File
@@ -0,0 +1,53 @@
<script lang="ts" setup>
import { CSSProperties } from 'vue'
import Flow, {
MiniMap,
Controls,
Background,
BackgroundVariant,
Connection,
Edge,
ElementId,
Elements,
FlowElement,
Node,
FlowInstance,
addEdge,
removeElements,
} from '@braks/vue-flow'
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>
<Flow
:elements="elements"
@load="onLoad"
@element-click="onElementClick"
@elements-remove="onElementsRemove"
@connect="(p) => onConnect(p)"
@node-drag-stop="onNodeDragStop"
>
<MiniMap />
<Controls />
<Background :variant="BackgroundVariant.Lines" />
<button class="button" type="button" :style="buttonStyle" @click="addRandomNode">add node</button>
</Flow>
</template>
+39
View File
@@ -0,0 +1,39 @@
<script lang="ts" setup>
import Flow, { MiniMap, Controls, Connection, Edge, Elements, addEdge } from '@braks/vue-flow'
const initialElements: Elements = [
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } },
{ id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 } },
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 } },
{ id: 'e1-2', source: '1', target: '2' },
{ id: 'e1-3', source: '1', target: '3' },
{ id: 'e3-4', source: '3', target: '4' },
]
const elements = ref<Elements>(initialElements)
const isHidden = ref<boolean>(false)
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
watchEffect(() => {
elements.value = elements.value.map((e) => {
e.isHidden = isHidden.value
return e
})
})
</script>
<template>
<Flow :elements="elements" @connect="onConnect">
<MiniMap />
<Controls />
<div :style="{ position: 'absolute', left: '10px', top: '10px', zIndex: 4 }">
<div>
<label for="ishidden">
isHidden
<input id="ishidden" v-model="isHidden" type="checkbox" class="vue-flow__ishidden" />
</label>
</div>
</div>
</Flow>
</template>
@@ -0,0 +1,71 @@
import { Elements, XYPosition } from '@braks/vue-flow'
const position: XYPosition = { x: 0, y: 0 }
const elements: Elements = [
{
id: '1',
type: 'input',
data: { label: 'input' },
position,
},
{
id: '2',
data: { label: 'node 2' },
position,
},
{
id: '2a',
data: { label: 'node 2a' },
position,
},
{
id: '2b',
data: { label: 'node 2b' },
position,
},
{
id: '2c',
data: { label: 'node 2c' },
position,
},
{
id: '2d',
data: { label: 'node 2d' },
position,
},
{
id: '3',
data: { label: 'node 3' },
position,
},
{
id: '4',
data: { label: 'node 4' },
position,
},
{
id: '5',
data: { label: 'node 5' },
position,
},
{
id: '6',
type: 'output',
data: { label: 'output' },
position,
},
{ id: '7', type: 'output', data: { label: 'output' }, position: { x: 400, y: 450 } },
{ id: 'e12', source: '1', target: '2', type: 'smoothstep', animated: true },
{ id: 'e13', source: '1', target: '3', type: 'smoothstep', animated: true },
{ id: 'e22a', source: '2', target: '2a', type: 'smoothstep', animated: true },
{ id: 'e22b', source: '2', target: '2b', type: 'smoothstep', animated: true },
{ id: 'e22c', source: '2', target: '2c', type: 'smoothstep', animated: true },
{ id: 'e2c2d', source: '2c', target: '2d', type: 'smoothstep', animated: true },
{ id: 'e45', source: '4', target: '5', type: 'smoothstep', animated: true },
{ id: 'e56', source: '5', target: '6', type: 'smoothstep', animated: true },
{ id: 'e57', source: '5', target: '7', type: 'smoothstep', animated: true },
]
export default elements
+151
View File
@@ -0,0 +1,151 @@
<script lang="ts" setup>
import Flow, {
addEdge,
MiniMap,
Controls,
Elements,
Node,
FlowElement,
Connection,
Edge,
PanOnScrollMode,
FlowTransform,
} from '@braks/vue-flow'
const initialElements: Elements = [
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } },
{ id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 } },
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 } },
{ id: 'e1-2', source: '1', target: '2', animated: true },
{ id: 'e1-3', source: '1', target: '3' },
]
const onNodeDragStart = (_: MouseEvent, node: Node) => console.log('drag start', node)
const onNodeDragStop = (_: MouseEvent, node: Node) => console.log('drag stop', node)
const onElementClick = (_: MouseEvent, element: FlowElement) => console.log('click', element)
const onPaneClick = (event: MouseEvent) => console.log('onPaneClick', event)
const onPaneScroll = (event?: WheelEvent) => console.log('onPaneScroll', event)
const onPaneContextMenu = (event: MouseEvent) => console.log('onPaneContextMenu', event)
const onMoveEnd = (flowTranasform?: FlowTransform) => console.log('onMoveEnd', flowTranasform)
const elements = ref<Elements>(initialElements)
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const isSelectable = ref(false)
const isDraggable = ref(false)
const isConnectable = ref(false)
const zoomOnScroll = ref(false)
const zoomOnPinch = ref(false)
const panOnScroll = ref(false)
const panOnScrollMode = ref<PanOnScrollMode>(PanOnScrollMode.Free)
const zoomOnDoubleClick = ref(false)
const paneMoveable = ref(true)
const captureZoomClick = ref(false)
const captureZoomScroll = ref(false)
const captureElementClick = ref(false)
</script>
<template>
<Flow
:elements="elements"
:elements-selectable="isSelectable"
:nodes-connectable="isConnectable"
:nodes-draggable="isDraggable"
:zoom-on-scroll="zoomOnScroll"
:zoom-on-pinch="zoomOnPinch"
:pan-on-scroll="panOnScroll"
:pan-on-scroll-mode="panOnScrollMode"
:zoom-on-double-click="zoomOnDoubleClick"
:pane-moveable="paneMoveable"
@connect="onConnect"
@element-click="captureElementClick ? onElementClick : undefined"
@node-drag-start="onNodeDragStart"
@node-drag-stop="onNodeDragStop"
@pane-click="captureZoomClick ? onPaneClick : undefined"
@pane-scroll="captureZoomScroll ? onPaneScroll : undefined"
@pane-context-menu="captureZoomClick ? onPaneContextMenu : undefined"
@move-end="onMoveEnd"
>
<MiniMap />
<Controls />
<div :style="{ position: 'absolute', left: 10, top: 10, zIndex: 4 }">
<div>
<label for="draggable">
nodesDraggable
<input id="draggable" v-model="isDraggable" type="checkbox" class="vue-flow__draggable" />
</label>
</div>
<div>
<label for="connectable">
nodesConnectable
<input id="connectable" v-model="isConnectable" type="checkbox" class="vue-flow__connectable" />
</label>
</div>
<div>
<label for="selectable">
elementsSelectable
<input id="selectable" v-model="isSelectable" type="checkbox" class="vue-flow__selectable" />
</label>
</div>
<div>
<label for="zoomonscroll">
zoomOnScroll
<input id="zoomonscroll" v-model="zoomOnScroll" type="checkbox" class="vue-flow__zoomonscroll" />
</label>
</div>
<div>
<label for="zoomonpinch">
zoomOnPinch
<input id="zoomonpinch" v-model="zoomOnPinch" type="checkbox" class="vue-flow__zoomonpinch" />
</label>
</div>
<div>
<label for="panonscroll">
panOnScroll
<input id="panonscroll" v-model="panOnScroll" type="checkbox" class="vue-flow__panonscroll" />
</label>
</div>
<div>
<label>
panOnScrollMode
<select id="panonscrollmode" v-model="panOnScrollMode" class="vue-flow__panonscrollmode">
<option value="free">free</option>
<option value="horizontal">horizontal</option>
<option value="vertical">vertical</option>
</select>
</label>
</div>
<div>
<label for="zoomondbl">
zoomOnDoubleClick
<input id="zoomondbl" v-model="zoomOnDoubleClick" type="checkbox" class="vue-flow__zoomondbl" />
</label>
</div>
<div>
<label for="panemoveable">
paneMoveable
<input id="panemoveable" v-model="paneMoveable" type="checkbox" class="vue-flow__panemoveable" />
</label>
</div>
<div>
<label for="capturezoompaneclick">
capture onPaneClick
<input id="capturezoompaneclick" v-model="captureZoomClick" type="checkbox" class="vue-flow__capturezoompaneclick" />
</label>
</div>
<div>
<label for="capturezoompanescroll">
capture onPaneScroll
<input id="capturezoompanescroll" v-model="captureZoomScroll" type="checkbox" class="vue-flow__capturezoompanescroll" />
</label>
</div>
<div>
<label for="captureelementclick">
capture onElementClick
<input id="captureelementclick" v-model="captureElementClick" type="checkbox" class="vue-flow__captureelementclick" />
</label>
</div>
</div>
</Flow>
</template>
+91
View File
@@ -0,0 +1,91 @@
<script lang="ts" setup>
import dagre from 'dagre'
import Flow, {
Controls,
addEdge,
ConnectionMode,
Connection,
Edge,
Elements,
isNode,
NodeExtent,
Position,
removeElements,
} from '@braks/vue-flow'
import initialElements from './initialLayoutingElements'
const dagreGraph = new dagre.graphlib.Graph()
dagreGraph.setDefaultEdgeLabel(() => ({}))
const nodeExtent: NodeExtent = [
[0, 0],
[1000, 1000],
]
const elements = ref<Elements>(initialElements)
const onConnect = (params: Connection | Edge) => (elements.value = addEdge({ ...params, animated: true }, elements.value))
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
// todo changing elements not properly updating flowchart...
const onLayout = (direction: string) => {
const isHorizontal = direction === 'LR'
dagreGraph.setGraph({ rankdir: direction })
elements.value.forEach((el) => {
if (isNode(el)) {
dagreGraph.setNode(el.id, { width: 150, height: 50 })
} else {
dagreGraph.setEdge(el.source, el.target)
}
})
dagre.layout(dagreGraph)
elements.value = elements.value.map((el) => {
if (isNode(el)) {
const nodeWithPosition = dagreGraph.node(el.id)
el.targetPosition = isHorizontal ? Position.Left : Position.Top
el.sourcePosition = isHorizontal ? Position.Right : Position.Bottom
el.position = { x: nodeWithPosition.x, y: nodeWithPosition.y }
}
return el
})
console.log(elements.value)
}
</script>
<template>
<div class="layoutflow">
<Flow
:elements="elements"
:node-extent="nodeExtent"
:connection-mode="ConnectionMode.Loose"
@connect="onConnect"
@clements-remove="onElementsRemove"
@load="() => onLayout('TB')"
>
<Controls />
</Flow>
<div class="controls">
<button class="button" :style="{ marginRight: 10 }" @click="() => onLayout('TB')">vertical layout</button>
<button class="button" @click="() => onLayout('LR')">horizontal layout</button>
</div>
</div>
</template>
<style>
.layoutflow {
flex-grow: 1;
position: relative;
}
.layoutflow .controls {
position: absolute;
right: 10px;
top: 10px;
z-index: 10;
}
.controls button {
margin-left: 10px;
}
</style>
+24
View File
@@ -0,0 +1,24 @@
<script lang="ts" setup>
import Flow from '../../components/Flow.vue'
</script>
<template>
<div class="vue-flow__example-multiflows flex-1">
<Flow />
<Flow />
</div>
</template>
<style>
.vue-flow__example-multiflows {
display: flex;
height: 100%;
}
.vue-flow__example-multiflows .vue-flow {
width: 100%;
height: 100%;
}
.vue-flow__example-multiflows .vue-flow:first-child {
border-right: 2px solid #333;
}
</style>
+47
View File
@@ -0,0 +1,47 @@
<script lang="ts" setup>
import { CSSProperties } from 'vue'
import Flow, { addEdge, Connection, Edge, Elements, isEdge, FlowInstance, Position } from '@braks/vue-flow'
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 },
]
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 onLoad = (flowInstance: FlowInstance) => flowInstance.fitView()
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 class="button mt-2" :style="buttonStyle" @click="changeType">change type</button>
</Flow>
</template>
@@ -0,0 +1,60 @@
<script lang="ts" setup>
import { CSSProperties } from 'vue'
import Flow, { Elements, Position, NodeType, Connection, Edge, addEdge } from '@braks/vue-flow'
import NodeA from '../../components/NodeA.vue'
import NodeB from '../../components/NodeB.vue'
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' }
type NodeTypesObject = {
[key: string]: Record<string, NodeType>
}
const nodeTypesObjects: NodeTypesObject = {
a: {
a: NodeA as NodeType,
},
b: {
b: NodeB as NodeType,
},
}
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>
<Flow :elements="elements" :node-types="nodeTypesObjects[nodeTypesId]" :node-types-id="nodeTypesId" @connect="onConnect">
<template #node-a>
<NodeA :node-styles="nodeStyles" />
</template>
<template #node-b>
<NodeB :node-styles="nodeStyles" />
</template>
<button class="button mt-2" :style="buttonStyle" @click="changeType">change type</button>
</Flow>
</template>
+96
View File
@@ -0,0 +1,96 @@
<script lang="ts" setup>
import Flow, {
addEdge,
removeElements,
Controls,
FlowInstance,
FlowElement,
Connection,
Edge,
Elements,
ConnectionMode,
useStore,
} from '@braks/vue-flow'
import Sidebar from '../../components/ProviderSidebar.vue'
const onElementClick = (element: FlowElement) => console.log('click', element)
const onLoad = (flowInstance: FlowInstance) => console.log('flow loaded:', flowInstance)
const initialElements: Elements = [
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } },
{ id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 } },
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 } },
{ id: 'e1-2', source: '1', target: '2', animated: true },
{ id: 'e1-3', source: '1', target: '3' },
]
useStore()
const elements = ref<Elements>(initialElements)
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
</script>
<template>
<div class="providerflow">
<Sidebar />
<div class="vue-flow-wrapper">
<Flow
:elements="elements"
:connection-mode="ConnectionMode.Loose"
@element-click="onElementClick"
@connect="onConnect"
@elements-remove="onElementsRemove"
@load="onLoad"
>
<Controls />
</Flow>
</div>
</div>
</template>
<style>
.providerflow {
flex-direction: column;
display: flex;
height: 100%;
width: 100%;
}
.providerflow aside {
border-right: 1px solid #eee;
padding: 15px 10px;
font-size: 12px;
background: #fcfcfc;
}
.providerflow aside .description {
margin-bottom: 10px;
}
.providerflow aside .title {
font-weight: 700;
margin-bottom: 5px;
}
.providerflow aside .transform {
margin-bottom: 20px;
}
.providerflow .vue-flow-wrapper {
flex-grow: 1;
height: 100%;
}
.providerflow .selectall {
margin-top: 10px;
}
@media screen and (min-width: 768px) {
.providerflow {
flex-direction: row;
}
.providerflow aside {
max-width: 250px;
}
}
</style>
+37
View File
@@ -0,0 +1,37 @@
<script lang="ts" setup>
import Flow, { addEdge, Connection, Node, Edge, Elements, FlowInstance, removeElements } from '@braks/vue-flow'
import Controls from '../../components/SaveControls.vue'
const initialElements: Elements = [
{ id: '1', data: { label: 'Node 1' }, position: { x: 100, y: 100 } },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 200 } },
{ id: 'e1-2', source: '1', target: '2' },
]
const elements = ref(initialElements)
const flowInstance = ref()
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
const onLoad = (instance: FlowInstance) => (flowInstance.value = instance)
const onRestore = (els: Elements) => (elements.value = els)
const onAdd = (el: Node) => (elements.value = elements.value.concat(el))
</script>
<template>
<Flow :elements="elements" @elements-remove="onElementsRemove" @connect="onConnect" @load="onLoad">
<Controls :flow-instance="flowInstance" @restore="onRestore" @add="onAdd" />
</Flow>
</template>
<style>
.save__controls {
position: absolute;
right: 10px;
top: 10px;
z-index: 4;
font-size: 12px;
}
.save__controls button {
margin-left: 5px;
}
</style>
+89
View File
@@ -0,0 +1,89 @@
<script lang="ts" setup>
import { CSSProperties } from 'vue'
import Flow, {
removeElements,
addEdge,
MiniMap,
isNode,
Controls,
Background,
FlowInstance,
Elements,
Connection,
Edge,
} from '@braks/vue-flow'
function getElements(xElements = 10, yElements = 10): Elements {
const initialElements = []
let nodeId = 1
let recentNodeId = null
for (let y = 0; y < yElements; y++) {
for (let x = 0; x < xElements; x++) {
const position = { x: x * 100, y: y * 50 }
const data = { label: `Node ${nodeId}` }
const node = {
id: nodeId.toString(),
style: { width: 50, fontSize: 11 },
data,
position,
}
initialElements.push(node)
if (recentNodeId && nodeId <= xElements * yElements) {
initialElements.push({ id: `${x}-${y}`, source: recentNodeId.toString(), target: nodeId.toString() })
}
recentNodeId = nodeId
nodeId++
}
}
return initialElements
}
const buttonWrapperStyles: CSSProperties = { position: 'absolute', right: 10, top: 10, zIndex: 4 }
const onLoad = (flowInstance: FlowInstance) => {
flowInstance.fitView()
console.log(flowInstance.getElements())
}
const initialElements: Elements = getElements(10, 10)
const elements = ref(initialElements)
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
const updatePos = () => {
elements.value = elements.value.map((el) => {
if (isNode(el)) {
return {
...el,
position: {
x: Math.random() * window.innerWidth,
y: Math.random() * window.innerHeight,
},
}
}
return el
})
}
const updateElements = () => {
const grid = Math.ceil(Math.random() * 10)
elements.value = getElements(grid, grid)
}
</script>
<template>
<Flow :elements="elements" @load="onLoad" @elementsRemove="onElementsRemove" @connect="onConnect">
<MiniMap />
<Controls />
<Background />
<div :style="buttonWrapperStyles">
<button style="margin-right: 5px" @click="updatePos">change pos</button>
<button @click="updateElements">update elements</button>
</div>
</Flow>
</template>
+47
View File
@@ -0,0 +1,47 @@
<script lang="ts" setup>
import Flow, { removeElements, addEdge, Node, FlowElement, Elements, Connection, Edge } from '@braks/vue-flow'
const onNodeDragStop = (_: MouseEvent, node: Node) => console.log('drag stop', node)
const onElementClick = (_: MouseEvent, element: FlowElement) => console.log('click', element)
const elementsA: Elements = [
{ id: '1a', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 }, class: 'light' },
{ id: '2a', data: { label: 'Node 2' }, position: { x: 100, y: 100 }, class: 'light' },
{ id: '3a', data: { label: 'Node 3' }, position: { x: 400, y: 100 }, class: 'light' },
{ id: '4a', data: { label: 'Node 4' }, position: { x: 400, y: 200 }, class: 'light' },
{ id: 'e1-2', source: '1a', target: '2a' },
{ id: 'e1-3', source: '1a', target: '3a' },
]
const elementsB: Elements = [
{ id: 'inputb', type: 'input', data: { label: 'Input' }, position: { x: 300, y: 5 }, class: 'light' },
{ id: '1b', data: { label: 'Node 1' }, position: { x: 0, y: 100 }, class: 'light' },
{ id: '2b', data: { label: 'Node 2' }, position: { x: 200, y: 100 }, class: 'light' },
{ id: '3b', data: { label: 'Node 3' }, position: { x: 400, y: 100 }, class: 'light' },
{ id: '4b', data: { label: 'Node 4' }, position: { x: 600, y: 100 }, class: 'light' },
{ id: 'e1b', source: 'inputb', target: '1b' },
{ id: 'e2b', source: 'inputb', target: '2b' },
{ id: 'e3b', source: 'inputb', target: '3b' },
{ id: 'e4b', source: 'inputb', target: '4b' },
]
const elements = ref(elementsA)
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
</script>
<template>
<Flow
:elements="elements"
@element-click="onElementClick"
@elements-remove="onElementsRemove"
@connect="onConnect"
@node-drag-stop="onNodeDragStop"
>
<div :style="{ position: 'absolute', right: '10px', top: '10px', zIndex: 4 }">
<button class="button" style="margin-right: 5px" @click="() => (elements = elementsA)">flow a</button>
<button class="button" @click="() => (elements = elementsB)">flow b</button>
</div>
</Flow>
</template>
+204
View File
@@ -0,0 +1,204 @@
<script lang="ts" setup>
import Flow, {
NodeType,
addEdge,
useZoomPanHelper,
Elements,
Connection,
Edge,
ElementId,
Node,
ConnectionLineType,
ConnectionMode,
updateEdge,
ArrowHeadType,
} from '@braks/vue-flow'
import CustomNode from '../../components/UnidirectionalCustomNode.vue'
const initialElements: Elements = [
{
id: '00',
type: 'custom',
position: { x: 300, y: 250 },
},
{
id: '01',
type: 'custom',
position: { x: 100, y: 50 },
},
{
id: '02',
type: 'custom',
position: { x: 500, y: 50 },
},
{
id: '03',
type: 'custom',
position: { x: 500, y: 500 },
},
{
id: '04',
type: 'custom',
position: { x: 100, y: 500 },
},
{
id: '10',
type: 'custom',
position: { x: 300, y: 5 },
},
{
id: '20',
type: 'custom',
position: { x: 600, y: 250 },
},
{
id: '30',
type: 'custom',
position: { x: 300, y: 600 },
},
{
id: '40',
type: 'custom',
position: { x: 5, y: 250 },
},
{
id: 'e0-1a',
source: '00',
target: '01',
sourceHandle: 'left',
targetHandle: 'bottom',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-1b',
source: '00',
target: '01',
sourceHandle: 'top',
targetHandle: 'right',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-2a',
source: '00',
target: '02',
sourceHandle: 'top',
targetHandle: 'left',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-2b',
source: '00',
target: '02',
sourceHandle: 'right',
targetHandle: 'bottom',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-3a',
source: '00',
target: '03',
sourceHandle: 'right',
targetHandle: 'top',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-3b',
source: '00',
target: '03',
sourceHandle: 'bottom',
targetHandle: 'left',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-4a',
source: '00',
target: '04',
sourceHandle: 'bottom',
targetHandle: 'right',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-4b',
source: '00',
target: '04',
sourceHandle: 'left',
targetHandle: 'top',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-10',
source: '00',
target: '10',
sourceHandle: 'top',
targetHandle: 'bottom',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-20',
source: '00',
target: '20',
sourceHandle: 'right',
targetHandle: 'left',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-30',
source: '00',
target: '30',
sourceHandle: 'bottom',
targetHandle: 'top',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
{
id: 'e0-40',
source: '00',
target: '40',
sourceHandle: 'left',
targetHandle: 'right',
type: 'smoothstep',
arrowHeadType: ArrowHeadType.Arrow,
},
]
const nodeTypes: Record<string, NodeType> = {
custom: CustomNode as NodeType,
}
let id = 4
const getId = (): ElementId => `${id++}`
const elements = ref(initialElements)
const onConnect = (params: Connection | Edge) => (elements.value = addEdge({ ...params, type: 'smoothstep' }, elements.value))
const { project } = useZoomPanHelper()
const onEdgeUpdate = (oldEdge: Edge, newConnection: Connection) =>
(elements.value = updateEdge(oldEdge, newConnection, elements.value))
const onPaneClick = (evt: MouseEvent) =>
(elements.value = elements.value.concat({
id: getId(),
position: project({ x: evt.clientX, y: evt.clientY - 40 }),
type: 'custom',
} as Node))
</script>
<template>
<Flow
:elements="elements"
:node-types="nodeTypes"
:connection-line-type="ConnectionLineType.SmoothStep"
:connection-mode="ConnectionMode.Loose"
@connect="onConnect"
@pane-click="onPaneClick"
@edge-pdate="onEdgeUpdate"
/>
</template>
+88
View File
@@ -0,0 +1,88 @@
<script lang="ts" setup>
import Flow, {
Controls,
updateEdge,
addEdge,
Elements,
FlowInstance,
Connection,
Edge,
removeElements,
FlowEvents,
ConnectionMode,
} from '@braks/vue-flow'
const initialElements: Elements = [
{
id: '1',
type: 'input',
data: {
label: 'Node <strong>A</strong>',
},
position: { x: 250, y: 0 },
},
{
id: '2',
data: {
label: 'Node <strong>B</strong>',
},
position: { x: 100, y: 100 },
},
{
id: '3',
data: {
label: 'Node <strong>C</strong>',
},
position: { x: 400, y: 100 },
style: { background: '#D6D5E6', color: '#333', border: '1px solid #222138', width: 180 },
},
{ id: 'e1-2', source: '1', target: '2', label: 'Updateable edge' },
]
const elements = ref(initialElements)
const onLoad = (flowInstance: FlowInstance) => flowInstance.fitView()
const onEdgeUpdateStart = (edge: Edge) => console.log('start update', edge)
const onEdgeUpdateEnd = (edge: Edge) => console.log('end update', edge)
const onEdgeUpdate = ({ edge, connection }: FlowEvents['edgeUpdate']) =>
(elements.value = updateEdge(edge, connection, elements.value))
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
</script>
<template>
<Flow
:elements="elements"
:snap-to-grid="true"
:connection-mode="ConnectionMode.Loose"
@load="onLoad"
@edge-update="onEdgeUpdate"
@connect="onConnect"
@edge-update-start="onEdgeUpdateStart"
@elements-remove="onElementsRemove"
@edge-update-end="onEdgeUpdateEnd"
>
<Controls />
</Flow>
</template>
<style>
.updatenode__controls {
position: absolute;
right: 10px;
top: 10px;
z-index: 4;
font-size: 12px;
}
.updatenode__controls label {
display: block;
}
.updatenode__bglabel {
margin-top: 10px;
}
.updatenode__checkboxwrapper {
margin-top: 10px;
display: flex;
align-items: center;
}
</style>
@@ -0,0 +1,82 @@
<script lang="ts" setup>
import { CSSProperties } from 'vue'
import Flow, {
NodeType,
addEdge,
useZoomPanHelper,
Node,
Elements,
Connection,
Edge,
ElementId,
Position,
isEdge,
FlowInstance,
} from '@braks/vue-flow'
import CustomNode from '../../components/UpdateNodeInternalsCustomNode.vue'
const initialHandleCount = 1
const initialElements: Elements = [
{
id: '1',
type: 'custom',
data: { label: 'Node 1', handleCount: initialHandleCount, handlePosition: 0 },
position: { x: 250, y: 5 },
},
]
const buttonWrapperStyles: CSSProperties = { position: 'absolute', right: '10px', top: '10px', zIndex: 10 }
const nodeTypes: Record<string, NodeType> = {
custom: CustomNode as NodeType,
}
let id = 5
const getId = (): ElementId => `${id++}`
const elements = ref<Elements>(initialElements)
const flowInstance = ref<FlowInstance>()
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const { project } = useZoomPanHelper()
const onPaneClick = (evt: MouseEvent) =>
(elements.value = elements.value.concat({
id: getId(),
position: project({ x: evt.clientX, y: evt.clientY - 40 }),
data: { label: 'new node' },
targetPosition: Position.Left,
sourcePosition: Position.Right,
} as Node))
const toggleHandleCount = () =>
(elements.value = elements.value.map((el) => {
if (isEdge(el)) {
return el
}
return { ...el, data: { ...el.data, handleCount: el.data?.handleCount === 1 ? 2 : 1 } }
}))
const toggleHandlePosition = () =>
(elements.value = elements.value.map((el) => {
if (isEdge(el)) return el
return { ...el, data: { ...el.data, handlePosition: el.data?.handlePosition === 0 ? 1 : 0 } }
}))
const onLoad = (instance: FlowInstance) => {
instance.fitView()
flowInstance.value = instance
}
const updateNodeInternals = () => flowInstance.value?.updateNodeInternals('1')
</script>
<template>
<Flow :elements="elements" :node-types="nodeTypes" @connect="onConnect" @pane-click="onPaneClick" @load="onLoad">
<div :style="buttonWrapperStyles">
<button class="button" @click="toggleHandleCount">toggle handle count</button>
<button class="button" @click="toggleHandlePosition">toggle handle position</button>
<button class="button" @click="updateNodeInternals">update node internals</button>
</div>
</Flow>
</template>
+73
View File
@@ -0,0 +1,73 @@
<script lang="ts" setup>
import Flow, { Elements } from '@braks/vue-flow'
const initialElements: Elements = [
{ id: '1', data: { label: '-' }, position: { x: 100, y: 100 } },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 200 } },
{ id: 'e1-2', source: '1', target: '2' },
]
const elements = ref<Elements>(initialElements)
const nodeName = ref<string>('Node 1')
const nodeBg = ref<string>('#eee')
const nodeHidden = ref<boolean>(false)
const updateNode = () => {
elements.value = elements.value.map((el) => {
if (el.id === '1') {
// it's important that you create a new object here in order to notify react flow about the change
el.data = {
...el.data,
label: nodeName.value,
}
el.style = { backgroundColor: nodeBg.value }
el.isHidden = nodeHidden.value
}
return el
})
}
watchEffect(() => {
updateNode()
})
</script>
<template>
<Flow :elements="elements" :default-zoom="1.5" :min-zoom="0.2" :max-zoom="4">
<div class="updatenode__controls p-4 bg-gray-300 rounded-xl">
<label>label:</label>
<input v-model="nodeName" />
<label class="updatenode__bglabel">background:</label>
<input v-model="nodeBg" type="color" />
<div class="updatenode__checkboxwrapper">
<label>hidden:</label>
<input v-model="nodeHidden" type="checkbox" />
</div>
</div>
</Flow>
</template>
<style>
.updatenode__controls {
position: absolute;
right: 10px;
top: 10px;
z-index: 4;
font-size: 12px;
}
.updatenode__controls label {
display: block;
}
.updatenode__bglabel {
margin-top: 10px;
}
.updatenode__checkboxwrapper {
margin-top: 10px;
display: flex;
align-items: center;
}
</style>
+83
View File
@@ -0,0 +1,83 @@
<script lang="ts" setup>
import Flow, {
addEdge,
Handle,
Connection,
Position,
Elements,
Edge,
OnConnectStartParams,
NodeProps,
FlowInstance,
NodeType,
} from '@braks/vue-flow'
import CustomInput from '../../components/ValidationCustomInput.vue'
import CustomNode from '../../components/ValidationCustomNode.vue'
const initialElements: Elements = [
{ id: '0', type: 'custominput', position: { x: 0, y: 150 } },
{ id: 'A', type: 'customnode', position: { x: 250, y: 0 } },
{ id: 'B', type: 'customnode', position: { x: 250, y: 150 } },
{ id: 'C', type: 'customnode', position: { x: 250, y: 300 } },
]
const onLoad = (reactFlowInstance: FlowInstance) => reactFlowInstance.fitView()
const onConnectStart = ({ nodeId, handleType }: OnConnectStartParams) => console.log('on connect start', { nodeId, handleType })
const onConnectStop = (event: MouseEvent) => console.log('on connect stop', event)
const onConnectEnd = (event: MouseEvent) => console.log('on connect end', event)
const elements = ref<Elements>(initialElements)
const onConnect = (params: Connection | Edge) => {
console.log('on connect', params)
elements.value = addEdge(params, elements.value)
}
const nodeTypes: Record<string, NodeType> = {
custominput: CustomInput as NodeType,
customnode: CustomNode as NodeType,
}
</script>
<template>
<Flow
:elements="elements"
:select-nodes-on-drag="false"
class="validationflow"
:node-types="nodeTypes"
@connect="onConnect"
@oad="onLoad"
@connect-start="onConnectStart"
@connect-stop="onConnectStop"
@connect-end="onConnectEnd"
/>
</template>
<style>
.validationflow .vue-flow__node {
width: 150px;
border-radius: 5px;
padding: 10px;
color: #555;
border: 1px solid #ddd;
text-align: center;
font-size: 12px;
}
.validationflow .vue-flow__node-customnode {
background: #e6e6e9;
border: 1px solid #ddd;
}
.vue-flow__node-custominput .vue-flow__handle {
background: #e6e6e9;
}
.validationflow .vue-flow__node-custominput {
background: #fff;
}
.validationflow .vue-flow__handle-connecting {
background: #ff6060;
}
.validationflow .vue-flow__handle-valid {
background: #55dd99;
}
</style>
+50
View File
@@ -0,0 +1,50 @@
<script lang="ts" setup>
import Flow, {
removeElements,
addEdge,
Background,
MiniMap,
useZoomPanHelper,
Elements,
ElementId,
Connection,
Edge,
Node,
} from '@braks/vue-flow'
const initialElements: Elements = [
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 }, class: 'light' },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 }, class: 'light' },
{ id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 }, class: 'light' },
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 }, class: 'light' },
{ id: 'e1-2', source: '1', target: '2', animated: true },
{ id: 'e1-3', source: '1', target: '3' },
]
let id = 5
const getId = (): ElementId => `${id++}`
const { project } = useZoomPanHelper()
const elements = ref(initialElements)
const onPaneClick = (evt: MouseEvent) => {
const projectedPosition = project({ x: evt.clientX, y: evt.clientY - 40 })
elements.value = elements.value.concat({
id: getId(),
position: projectedPosition,
data: {
label: `${projectedPosition.x}-${projectedPosition.y}`,
},
} as Node)
}
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
</script>
<template>
<Flow :elements="elements" @elements-remove="onElementsRemove" @connect="onConnect" @pane-click="onPaneClick">
<Background />
<MiniMap />
</Flow>
</template>