Replies: 9 comments
-
Hi and thank you for using Vue Flow :) I am not sure I am fully understanding what you're trying to accomplish.
But: |
Beta Was this translation helpful? Give feedback.
-
@vladsvd I've created an Example and I'm guessing you're looking for something like that. <script lang="ts" setup>
import GroupNode from './GroupNode.vue'
import { VueFlow, Elements, Node, Edge, Connection, addEdge } from '@braks/vue-flow'
const elements = ref<Elements<{ label: string; group?: string }>>([
{ id: 'node-1', data: { label: 'node-1', group: undefined }, position: { x: 250, y: 5 } },
{ id: 'node-2', data: { label: 'node-2', group: undefined }, position: { x: 50, y: 5 } },
{
id: 'group-a',
type: 'group-a',
style: { zIndex: 2 },
selectable: false,
data: { label: 'A' },
position: { x: 50, y: 100 },
},
{
id: 'group-b',
type: 'group-b',
style: { zIndex: 2 },
selectable: false,
data: { label: 'B' },
position: { x: 500, y: 100 },
},
])
const onConnect = (params: Edge | Connection) => addEdge(params, elements.value)
</script>
<template>
<VueFlow v-model="elements" :node-types="['group-a', 'group-b']" @connect="onConnect">
<template #node-group-a="aProps">
<GroupNode v-bind="aProps" />
</template>
<template #node-group-b="bProps">
<GroupNode v-bind="bProps" />
</template>
</VueFlow>
</template> // GroupNode.vue
<script lang="ts" setup>
import { Handle, Position, getNodesInside, useVueFlow } from '@braks/vue-flow'
import type { NodeProps } from '@braks/vue-flow'
const props = defineProps<NodeProps>()
const store = useVueFlow()
store.hooks.nodeDragStop.on(({ node }) => {
const nodes = getNodesInside(
store.getNodes,
{
height: props.__vf.height,
width: props.__vf.width,
x: props.position.x,
y: props.position.y,
},
store.transform,
)
if (nodes.some((n) => n.id === node.id)) {
node.data.label = `In ${props.id}`
node.data.group = props.id
} else if (node.data.group === props.id) {
node.data.group = undefined
node.data.label = node.id
}
})
</script>
<template>
<div class="vue-flow__group-node">
<Handle type="target" :position="Position.Top" />
<strong>Group {{ data.label }}</strong>
<Handle type="source" :position="Position.Bottom" />
</div>
</template>
<style>
.vue-flow__group-node {
padding: 15px;
width: 300px;
height: 300px;
border: solid 1px black;
}
</style> A group node basically checks whether a dragged node is inside of it's boundaries and if it is, it's set props.data.group to it's id, i.e. you assign a group to a node. So my conclusion is that it's up to you to play around with existing features to create the nesting feature you're after as I do believe the scope of this library is to simple render the elements to the view, not actually provide logic to group / sort etc. I hope this somewhat answers your question, if not, please feel free to ask! :) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response. const initialNodes = [
{ id: '1', data: { label: 'Node 1' }, position: { x: 50, y: 0 } },
{ id: '2', data: { label: 'Group node 2' }, position: { x: 50, y: 100 }, style: { width: 400, height: 200 } },
// this position is relative to the position of the parent node '2'
{ id: '2a', data: { label: 'Child node 2a' }, position: { x: 0, y: 0 }, parentNode: '2' }
]; |
Beta Was this translation helpful? Give feedback.
-
Well I didn't see that PR tbh as I didn't check back on react-flow for a while 😅 I might be able to get it done this weekend, depending on the amount of work of course. |
Beta Was this translation helpful? Give feedback.
-
Just a heads up! But if you're using Vue Flow currently and want to use the nesting feature be prepared for possible breaking changes between versions |
Beta Was this translation helpful? Give feedback.
-
Nothing wrong. I myself am in search of a solution to my ideas. |
Beta Was this translation helpful? Give feedback.
-
Another update: |
Beta Was this translation helpful? Give feedback.
-
@vladsvd If you do check it out, let me know if you have any issues/problems that need attention :) |
Beta Was this translation helpful? Give feedback.
-
@vladsvd You can check it out here |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Thanks for a great project.
Do you plan to support nesting nodes?
There are two types of nesting:
Beta Was this translation helpful? Give feedback.
All reactions