update(examples): fix examples
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import ConnectionLine from './ConnectionLine.vue'
|
import ConnectionLine from './ConnectionLine.vue'
|
||||||
import { VueFlow, addEdge, Background, BackgroundVariant, Elements, useVueFlow } from '~/index'
|
import { VueFlow, Background, BackgroundVariant, Elements } from '~/index'
|
||||||
|
|
||||||
const elements = ref<Elements>([
|
const elements = ref<Elements>([
|
||||||
{
|
{
|
||||||
@@ -10,9 +10,6 @@ const elements = ref<Elements>([
|
|||||||
position: { x: 250, y: 5 },
|
position: { x: 250, y: 5 },
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
const { applyNodeChanges, OnNodesChange, OnConnect } = useVueFlow()
|
|
||||||
OnNodesChange(applyNodeChanges)
|
|
||||||
OnConnect((params) => (elements.value = addEdge(params, elements.value)))
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<VueFlow v-model="elements">
|
<VueFlow v-model="elements">
|
||||||
|
|||||||
@@ -7,14 +7,6 @@ interface ColorSelectorNodeProps extends NodeProps {
|
|||||||
color: string
|
color: string
|
||||||
onChange: (event: any) => void
|
onChange: (event: any) => void
|
||||||
}
|
}
|
||||||
type: string
|
|
||||||
selected?: boolean
|
|
||||||
connectable?: boolean
|
|
||||||
xPos?: number
|
|
||||||
yPos?: number
|
|
||||||
targetPosition?: Position
|
|
||||||
sourcePosition?: Position
|
|
||||||
dragging?: boolean
|
|
||||||
}
|
}
|
||||||
const props = defineProps<ColorSelectorNodeProps>()
|
const props = defineProps<ColorSelectorNodeProps>()
|
||||||
|
|
||||||
|
|||||||
@@ -3,19 +3,16 @@ import ColorSelectorNode from './ColorSelectorNode.vue'
|
|||||||
import {
|
import {
|
||||||
VueFlow,
|
VueFlow,
|
||||||
isEdge,
|
isEdge,
|
||||||
addEdge,
|
|
||||||
MiniMap,
|
MiniMap,
|
||||||
Controls,
|
Controls,
|
||||||
Node,
|
Node,
|
||||||
FlowElement,
|
FlowElement,
|
||||||
FlowInstance,
|
|
||||||
Elements,
|
Elements,
|
||||||
Position,
|
Position,
|
||||||
SnapGrid,
|
SnapGrid,
|
||||||
Connection,
|
|
||||||
ConnectionMode,
|
ConnectionMode,
|
||||||
Edge,
|
|
||||||
useVueFlow,
|
useVueFlow,
|
||||||
|
useNodesState,
|
||||||
} from '~/index'
|
} from '~/index'
|
||||||
|
|
||||||
const elements = ref<Elements>([])
|
const elements = ref<Elements>([])
|
||||||
@@ -89,23 +86,12 @@ onMounted(() => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const { useNodesState, OnPaneReady, OnNodeDragStop, OnConnect } = useVueFlow()
|
const { OnPaneReady } = useVueFlow()
|
||||||
useNodesState(undefined, true)
|
useNodesState()
|
||||||
OnPaneReady((flowInstance) => {
|
OnPaneReady((flowInstance) => {
|
||||||
flowInstance.fitView()
|
flowInstance.fitView()
|
||||||
console.log('flow loaded:', flowInstance)
|
console.log('flow loaded:', flowInstance)
|
||||||
})
|
})
|
||||||
OnNodeDragStop(({ node }) => console.log('drag stop', node))
|
|
||||||
OnConnect((params) =>
|
|
||||||
addEdge(
|
|
||||||
{
|
|
||||||
...params,
|
|
||||||
animated: true,
|
|
||||||
style: { stroke: '#fff' },
|
|
||||||
} as Edge,
|
|
||||||
elements.value,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<VueFlow
|
<VueFlow
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import Sidebar from './Sidebar.vue'
|
import Sidebar from './Sidebar.vue'
|
||||||
import { VueFlow, Controls, FlowInstance, Node, useVueFlow } from '~/index'
|
import { VueFlow, Controls, FlowInstance, Node, useVueFlow, useElementsState } from '~/index'
|
||||||
|
|
||||||
let id = 0
|
let id = 0
|
||||||
const getId = () => `dndnode_${id++}`
|
const getId = () => `dndnode_${id++}`
|
||||||
|
|
||||||
const flowInstance = ref<FlowInstance>()
|
const flowInstance = ref<FlowInstance>()
|
||||||
|
|
||||||
const { useNodesState, useEdgesState, OnPaneReady, OnConnect } = useVueFlow()
|
const { OnPaneReady, OnConnect } = useVueFlow()
|
||||||
const { edges, addEdges } = useEdgesState()
|
const { nodes, edges, addEdges, addNodes } = useElementsState({
|
||||||
const { nodes, addNodes } = useNodesState(
|
nodes: [
|
||||||
[
|
|
||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
type: 'input',
|
type: 'input',
|
||||||
@@ -18,9 +17,7 @@ const { nodes, addNodes } = useNodesState(
|
|||||||
position: { x: 250, y: 5 },
|
position: { x: 250, y: 5 },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
true,
|
})
|
||||||
)
|
|
||||||
|
|
||||||
OnPaneReady((instance) => (flowInstance.value = instance))
|
OnPaneReady((instance) => (flowInstance.value = instance))
|
||||||
const onDragOver = (event: DragEvent) => {
|
const onDragOver = (event: DragEvent) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import CustomEdge from './CustomEdge.vue'
|
import CustomEdge from './CustomEdge.vue'
|
||||||
import CustomEdge2 from './CustomEdge2.vue'
|
import CustomEdge2 from './CustomEdge2.vue'
|
||||||
import CustomLabel from './CustomLabel.vue'
|
import CustomLabel from './CustomLabel.vue'
|
||||||
import { VueFlow, MiniMap, Controls, Background, MarkerType, useVueFlow } from '~/index'
|
import { VueFlow, MiniMap, Controls, Background, MarkerType, useVueFlow, useElementsState } from '~/index'
|
||||||
|
|
||||||
const initialNodes = [
|
const initialNodes = [
|
||||||
{ id: '1', type: 'input', label: 'Input 1', position: { x: 250, y: 0 } },
|
{ id: '1', type: 'input', label: 'Input 1', position: { x: 250, y: 0 } },
|
||||||
@@ -65,13 +65,13 @@ const initialEdges = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const { useNodesState, useEdgesState, OnPaneReady, OnNodeDragStop, OnConnect } = useVueFlow()
|
const { OnPaneReady } = useVueFlow()
|
||||||
const { nodes } = useNodesState(initialNodes)
|
const { nodes, edges, addEdges } = useElementsState({
|
||||||
const { edges, addEdges } = useEdgesState(initialEdges)
|
nodes: initialNodes,
|
||||||
|
edges: initialEdges,
|
||||||
|
})
|
||||||
|
|
||||||
OnPaneReady((flowInstance) => flowInstance.fitView())
|
OnPaneReady((flowInstance) => flowInstance.fitView())
|
||||||
OnNodeDragStop((node) => console.log('drag stop', node))
|
|
||||||
OnConnect((params) => addEdges([params]))
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<VueFlow :snap-to-grid="true">
|
<VueFlow :snap-to-grid="true">
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { VueFlow, MiniMap, Controls, Background, BackgroundVariant, Node, useVueFlow } from '~/index'
|
import { VueFlow, MiniMap, Controls, Background, BackgroundVariant, Node, useVueFlow, useElementsState } from '~/index'
|
||||||
|
|
||||||
const { useNodesState, useEdgesState, OnConnect, OnPaneReady, OnNodeDragStop } = useVueFlow()
|
const { OnConnect, OnPaneReady, OnNodeDragStop, dimensions } = useVueFlow()
|
||||||
const { nodes, addNodes } = useNodesState()
|
const { nodes, addNodes, edges, addEdges } = useElementsState()
|
||||||
const { edges, addEdges } = useEdgesState()
|
|
||||||
|
|
||||||
OnConnect((params) => addEdges[params])
|
OnConnect((params) => addEdges[params])
|
||||||
OnPaneReady((flowInstance) => console.log('flow loaded:', flowInstance))
|
OnPaneReady((flowInstance) => console.log('flow loaded:', flowInstance))
|
||||||
@@ -14,8 +13,8 @@ const addRandomNode = () => {
|
|||||||
const newNode: Node = {
|
const newNode: Node = {
|
||||||
id: nodeId,
|
id: nodeId,
|
||||||
label: `Node: ${nodeId}`,
|
label: `Node: ${nodeId}`,
|
||||||
position: { x: Math.random() * window.innerWidth, y: Math.random() * window.innerHeight },
|
position: { x: Math.random() * dimensions.value.width, y: Math.random() * dimensions.value.height },
|
||||||
} as Node
|
}
|
||||||
addNodes([newNode])
|
addNodes([newNode])
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { VueFlow, MiniMap, Controls, Connection, Edge, Elements } from '~/index'
|
import { VueFlow, MiniMap, Controls, Elements } from '~/index'
|
||||||
|
|
||||||
const initialElements: Elements = [
|
const initialElements: Elements = [
|
||||||
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
|
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { VueFlow, MiniMap, Controls, useVueFlow } from '~/index'
|
import { VueFlow, MiniMap, Controls, useVueFlow, useElementsState } from '~/index'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
nodesDraggable,
|
nodesDraggable,
|
||||||
@@ -11,8 +11,6 @@ const {
|
|||||||
panOnScroll,
|
panOnScroll,
|
||||||
panOnScrollMode,
|
panOnScrollMode,
|
||||||
paneMoveable,
|
paneMoveable,
|
||||||
useNodesState,
|
|
||||||
useEdgesState,
|
|
||||||
OnConnect,
|
OnConnect,
|
||||||
OnNodeDragStart,
|
OnNodeDragStart,
|
||||||
OnNodeDragStop,
|
OnNodeDragStop,
|
||||||
@@ -31,8 +29,7 @@ const {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
const { nodes } = useNodesState()
|
const { nodes, edges, addEdges } = useElementsState()
|
||||||
const { edges, addEdges } = useEdgesState()
|
|
||||||
const captureZoomClick = ref(false)
|
const captureZoomClick = ref(false)
|
||||||
const captureZoomScroll = ref(false)
|
const captureZoomScroll = ref(false)
|
||||||
|
|
||||||
@@ -45,7 +42,7 @@ OnPaneContextMenu((event) => captureZoomClick && console.log('pane ctx menu', ev
|
|||||||
OnMoveEnd((flowTransform) => console.log('move end', flowTransform))
|
OnMoveEnd((flowTransform) => console.log('move end', flowTransform))
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<VueFlow :nodes-draggable="captureZoomScroll">
|
<VueFlow>
|
||||||
<MiniMap />
|
<MiniMap />
|
||||||
<Controls />
|
<Controls />
|
||||||
|
|
||||||
@@ -53,7 +50,7 @@ OnMoveEnd((flowTransform) => console.log('move end', flowTransform))
|
|||||||
<div>
|
<div>
|
||||||
<label for="draggable">
|
<label for="draggable">
|
||||||
nodesDraggable
|
nodesDraggable
|
||||||
<input id="draggable" type="checkbox" class="vue-flow__draggable" />
|
<input id="draggable" v-model="nodesDraggable" type="checkbox" class="vue-flow__draggable" />
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user