update(examples): Add update node example
This commit is contained in:
@@ -15,8 +15,8 @@ import Flow, {
|
|||||||
|
|
||||||
import './provider.css'
|
import './provider.css'
|
||||||
|
|
||||||
const onElementClick = (_: MouseEvent, element: FlowElement) => console.log('click', element)
|
const onElementClick = (element: FlowElement) => console.log('click', element)
|
||||||
const onLoad = (reactFlowInstance: OnLoadParams) => console.log('flow loaded:', reactFlowInstance)
|
const onLoad = (flowInstance: OnLoadParams) => console.log('flow loaded:', flowInstance)
|
||||||
|
|
||||||
const initialElements: Elements = [
|
const initialElements: Elements = [
|
||||||
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
|
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
|
||||||
@@ -35,7 +35,7 @@ const onElementsRemove = (elementsToRemove: Elements) => (elements.value = remov
|
|||||||
<template>
|
<template>
|
||||||
<div class="providerflow">
|
<div class="providerflow">
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
<div class="reactflow-wrapper">
|
<div class="vue-flow-wrapper">
|
||||||
<Flow
|
<Flow
|
||||||
:elements="elements"
|
:elements="elements"
|
||||||
:connection-mode="ConnectionMode.Loose"
|
:connection-mode="ConnectionMode.Loose"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const selectAll = () => {
|
|||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<aside>
|
<aside>
|
||||||
<div class="description">This is an example of how you can access the internal state outside of the ReactFlow component.</div>
|
<div class="description">This is an example of how you can access the internal state outside of the Vue Flow component.</div>
|
||||||
<div class="title">Zoom & pan transform</div>
|
<div class="title">Zoom & pan transform</div>
|
||||||
<div class="transform">{{ [transform[0].toFixed(2), transform[1].toFixed(2), transform[2].toFixed(2)] }}</div>
|
<div class="transform">{{ [transform[0].toFixed(2), transform[1].toFixed(2), transform[2].toFixed(2)] }}</div>
|
||||||
<div class="title">Nodes</div>
|
<div class="title">Nodes</div>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.providerflow .reactflow-wrapper {
|
.providerflow .vue-flow-wrapper {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ const initialElements: Elements = [
|
|||||||
] as Elements
|
] as Elements
|
||||||
|
|
||||||
const elements = ref(initialElements)
|
const elements = ref(initialElements)
|
||||||
const onLoad = (reactFlowInstance: OnLoadParams) => reactFlowInstance.fitView()
|
const onLoad = (flowInstance: OnLoadParams) => flowInstance.fitView()
|
||||||
const onEdgeUpdateStart = (edge: Edge) => console.log('start update', edge)
|
const onEdgeUpdateStart = (edge: Edge) => console.log('start update', edge)
|
||||||
const onEdgeUpdateEnd = (edge: Edge) => console.log('end update', edge)
|
const onEdgeUpdateEnd = (edge: Edge) => console.log('end update', edge)
|
||||||
const onEdgeUpdate = ({ edge, connection }: FlowEvents['edgeUpdate']) =>
|
const onEdgeUpdate = ({ edge, connection }: FlowEvents['edgeUpdate']) =>
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import Flow, { Elements } from '~/index'
|
||||||
|
|
||||||
|
import './updatenode.css'
|
||||||
|
|
||||||
|
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' },
|
||||||
|
] as Elements
|
||||||
|
|
||||||
|
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">
|
||||||
|
<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>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
.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;
|
||||||
|
}
|
||||||
@@ -89,6 +89,10 @@ export const routes: RouterOptions['routes'] = [
|
|||||||
path: '/updateable-edge',
|
path: '/updateable-edge',
|
||||||
component: () => import('./UpdatableEdge/UpdatableEdgeExample.vue'),
|
component: () => import('./UpdatableEdge/UpdatableEdgeExample.vue'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/update-node',
|
||||||
|
component: () => import('./UpdateNode/UpdateNodeExample.vue'),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
export const router = createRouter({
|
export const router = createRouter({
|
||||||
|
|||||||
Reference in New Issue
Block a user