update(examples): use computedPosition in GroupNode.vue

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-12-20 19:29:52 +01:00
parent d2961dec9f
commit a983858acf
2 changed files with 15 additions and 16 deletions
+12 -10
View File
@@ -8,26 +8,28 @@ store.hooks.nodeDragStop.on(({ node }) => {
const nodes = getNodesInside( const nodes = getNodesInside(
store.getNodes, store.getNodes,
{ {
height: props.height, ...props.dimensions,
width: props.width, x: props.computedPosition.x,
x: props.position.x, y: props.computedPosition.y,
y: props.position.y,
}, },
store.transform, store.transform,
) )
if (nodes.some((n) => n.id === node.id)) { console.log(nodes)
node.data.label = `In ${props.id}` if (nodes.some((n) => n.id === node.id && n.id !== props.id)) {
node.data.group = props.id node.label = `In ${props.id}`
} else if (node.data.group === props.id) { node.data = {
group: props.id,
}
} else if (node.data?.group === props.id) {
node.data.group = undefined node.data.group = undefined
node.data.label = node.id node.label = node.id
} }
}) })
</script> </script>
<template> <template>
<div class="vue-flow__group-node"> <div class="vue-flow__group-node">
<Handle type="target" :position="Position.Top" /> <Handle type="target" :position="Position.Top" />
<strong>Group {{ data.label }}</strong> <strong>Group {{ label }}</strong>
<Handle type="source" :position="Position.Bottom" /> <Handle type="source" :position="Position.Bottom" />
</div> </div>
</template> </template>
+3 -6
View File
@@ -6,7 +6,7 @@ const elements = ref<Elements<{ label: string; group?: string }>>([
{ id: 'node-2', label: 'node-2', position: { x: 50, y: 5 } }, { id: 'node-2', label: 'node-2', position: { x: 50, y: 5 } },
{ {
id: 'group-a', id: 'group-a',
style: { zIndex: 2, width: '300px', height: '300px' }, type: 'group',
label: 'A', label: 'A',
position: { x: 50, y: 100 }, position: { x: 50, y: 100 },
children: [ children: [
@@ -30,12 +30,9 @@ const elements = ref<Elements<{ label: string; group?: string }>>([
const onConnect = (params: Edge | Connection) => addEdge(params, elements.value) const onConnect = (params: Edge | Connection) => addEdge(params, elements.value)
</script> </script>
<template> <template>
<VueFlow v-model="elements" :node-types="['group-a', 'group-b']" @connect="onConnect"> <VueFlow v-model="elements" @connect="onConnect">
<template #node-group-a="aProps"> <template #node-group="aProps">
<GroupNode v-bind="aProps" /> <GroupNode v-bind="aProps" />
</template> </template>
<template #node-group-b="bProps">
<GroupNode v-bind="bProps" />
</template>
</VueFlow> </VueFlow>
</template> </template>