examples: revert nesting example

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-01-18 20:47:32 +01:00
committed by Braks
parent d79e2a420e
commit 8afb98e354
+95 -72
View File
@@ -1,86 +1,109 @@
<script setup lang="ts"> <script lang="ts" setup>
import { Controls } from '@vue-flow/controls' import { ConnectionMode, VueFlow, useVueFlow } from '@vue-flow/core'
import { Background } from '@vue-flow/background' import { Background } from '@vue-flow/background'
import { PanelPosition, VueFlow, useVueFlow } from '@vue-flow/core' import { Controls } from '@vue-flow/controls'
import DiagramCustomNode from './DiagramCustomNode.vue' import { MiniMap } from '@vue-flow/minimap'
import DiagramCustomParentNode from './DiagramCustomParentNode.vue'
import data from './data.json'
const elements = ref<any[]>([]) const { onConnect, addEdges, addNodes, findNode } = useVueFlow({
fitViewOnInit: true,
setTimeout(() => { connectionMode: ConnectionMode.Loose,
elements.value = data nodes: [
}, 1000) { id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 }, class: 'light' },
{
const { id: '2',
fitView, label: 'Node 2',
setInteractive, position: { x: 100, y: 100 },
nodesConnectable, class: 'light',
nodesDraggable, style: { backgroundColor: 'rgba(255, 0, 0, 0.8)' },
onNodesChange, },
onEdgesChange, {
applyNodeChanges, id: '2a',
applyEdgeChanges, label: 'Node 2a',
getNodesInitialized, position: { x: 10, y: 50 },
onNodesInitialized, parentNode: '2',
} = useVueFlow() },
{ id: '3', label: 'Node 3', position: { x: 320, y: 100 }, class: 'light' },
function onPaneReady() { {
fitView({ id: '4',
minZoom: 1, label: 'Node 4',
maxZoom: 1, position: { x: 320, y: 200 },
}) class: 'light',
setInteractive(false) style: { backgroundColor: 'rgba(255, 0, 0, 0.7)', width: '300px', height: '300px' },
},
nodesConnectable.value = false {
nodesDraggable.value = true id: '4a',
} label: 'Node 4a',
position: { x: 15, y: 65 },
onNodesChange((changes) => { class: 'light',
const validChanges = changes.filter((change) => change.type !== 'remove') extent: 'parent',
applyNodeChanges(validChanges) parentNode: '4',
},
{
id: '4b',
label: 'Node 4b',
position: { x: 15, y: 120 },
class: 'light',
style: { backgroundColor: 'rgba(255, 0, 255, 0.7)', height: '150px', width: '270px' },
parentNode: '4',
},
{
id: '4b1',
label: 'Node 4b1',
position: { x: 20, y: 40 },
class: 'light',
parentNode: '4b',
},
{
id: '4b2',
label: 'Node 4b2',
position: { x: 100, y: 100 },
class: 'light',
parentNode: '4b',
},
],
edges: [
{ id: 'e1-2', source: '1', target: '2', animated: true },
{ id: 'e1-3', source: '1', target: '3' },
{ id: 'e2a-4a', source: '2a', target: '4a' },
{ id: 'e3-4', source: '3', target: '4' },
{ id: 'e3-4b', source: '3', target: '4b' },
{ id: 'e4a-4b1', source: '4a', target: '4b1' },
{ id: 'e4a-4b2', source: '4a', target: '4b2' },
{ id: 'e4b1-4b2', source: '4b1', target: '4b2' },
],
}) })
onEdgesChange((changes) => { onConnect((params) => addEdges([params]))
const validChanges = changes.filter((change) => change.type !== 'remove')
applyEdgeChanges(validChanges)
})
onNodesInitialized((nodesInitialized) => { onMounted(() => {
console.log(nodesInitialized) // add nodes to parent
nodesInitialized.forEach((node) => { addNodes([
if (node.expandParent) { {
node.expandParent = false id: '999',
node.extent = { type: 'input',
range: 'parent', label: 'Added after mount',
padding: [48, 24, 24, 24], position: { x: 20, y: 100 },
} class: 'light',
expandParent: true,
parentNode: '2',
},
])
setTimeout(() => {
const node = findNode('999')!
node.expandParent = false
node.extent = {
range: 'parent',
padding: [10],
} }
}) })
}) })
</script> </script>
<template> <template>
<VueFlow <VueFlow>
v-model="elements" <MiniMap />
class="panel" <Controls />
:nodes-connectable="false"
:apply-default="false"
elevate-edges-on-select
@pane-ready="onPaneReady"
>
<template #node-custom="props">
<DiagramCustomNode :data="props.data" />
</template>
<template #node-custom-parent="props">
<DiagramCustomParentNode :data="props.data" />
</template>
<Controls :show-interactive="false" :position="PanelPosition.BottomRight" />
<Background /> <Background />
</VueFlow> </VueFlow>
</template> </template>
<style src="./CustomDiagram.css"></style>