feat(core): add useNodeConnections composable (#1728)

* feat(core): add `useNodeConnections` composable

* chore(core): export `useNodeConnections`

* chore(docs): update math example

* docs: add guide for `useNodeConnections`

* chore(changeset): add
This commit is contained in:
Braks
2025-01-06 12:30:47 +01:00
parent 1c5caffaad
commit 268ed0e84e
6 changed files with 174 additions and 16 deletions

View File

@@ -1,13 +1,11 @@
<script setup lang="ts">
import type { GraphNode } from '@vue-flow/core'
import { Handle, Position, useHandleConnections, useNodesData, useVueFlow } from '@vue-flow/core'
import { Handle, Position, useHandleConnections, useNodeConnections, useNodesData } from '@vue-flow/core'
import type { OperatorNodeData, ValueNodeData } from './types'
import { mathFunctions } from './utils'
defineProps<{ id: string }>()
const { getConnectedEdges } = useVueFlow()
// Get the source connections of the result node. In this example it's only one operator node.
const sourceConnections = useHandleConnections({
// type target means all connections where *this* node is the target
@@ -16,9 +14,10 @@ const sourceConnections = useHandleConnections({
})
// Get the source connections of the operator node
const operatorSourceConnections = computed(() =>
getConnectedEdges(sourceConnections.value[0].source).filter((e) => e.source !== sourceConnections.value[0].source),
)
const operatorSourceConnections = useNodeConnections({
type: 'target',
nodeId: () => sourceConnections.value[0]?.source,
})
const operatorData = useNodesData<GraphNode<OperatorNodeData>>(() =>
sourceConnections.value.map((connection) => connection.source),