feat(core): add getHandleConnections action (#1595)

* feat(core): add `getHandleConnections` action

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>

* chore(changeset): add

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>

---------

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2024-08-30 12:45:11 +02:00
parent 940b08e080
commit 9c003d4353
3 changed files with 14 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@vue-flow/core": minor
---
Add `getHandleConnections` action to store.
+5
View File
@@ -72,6 +72,10 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
return getConnectedEdgesBase(nodesOrId, state.edges) return getConnectedEdgesBase(nodesOrId, state.edges)
} }
const getHandleConnections: Actions['getHandleConnections'] = ({ id, type, nodeId }) => {
return Array.from(state.connectionLookup.get(`${nodeId}-${type}-${id ?? null}`)?.values() ?? [])
}
const findNode: Actions['findNode'] = (id) => { const findNode: Actions['findNode'] = (id) => {
if (!id) { if (!id) {
return return
@@ -880,6 +884,7 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
getIncomers, getIncomers,
getOutgoers, getOutgoers,
getConnectedEdges, getConnectedEdges,
getHandleConnections,
isNodeIntersecting, isNodeIntersecting,
panBy, panBy,
fitView: (params) => viewportHelper.value.fitView(params), fitView: (params) => viewportHelper.value.fitView(params),
+4 -1
View File
@@ -24,13 +24,14 @@ import type {
ConnectionMode, ConnectionMode,
ConnectionStatus, ConnectionStatus,
Connector, Connector,
HandleConnection,
} from './connection' } from './connection'
import type { DefaultEdgeOptions, Edge, EdgeUpdatable, GraphEdge } from './edge' import type { DefaultEdgeOptions, Edge, EdgeUpdatable, GraphEdge } from './edge'
import type { CoordinateExtent, CoordinateExtentRange, GraphNode, Node } from './node' import type { CoordinateExtent, CoordinateExtentRange, GraphNode, Node } from './node'
import type { D3Selection, D3Zoom, D3ZoomHandler, PanOnScrollMode, ViewportTransform } from './zoom' import type { D3Selection, D3Zoom, D3ZoomHandler, PanOnScrollMode, ViewportTransform } from './zoom'
import type { CustomEvent, FlowHooks, FlowHooksEmit, FlowHooksOn } from './hooks' import type { CustomEvent, FlowHooks, FlowHooksEmit, FlowHooksOn } from './hooks'
import type { EdgeChange, NodeChange, NodeDragItem } from './changes' import type { EdgeChange, NodeChange, NodeDragItem } from './changes'
import type { ConnectingHandle, ValidConnectionFunc } from './handle' import type { ConnectingHandle, HandleType, ValidConnectionFunc } from './handle'
export type NodeLookup = Map<string, GraphNode> export type NodeLookup = Map<string, GraphNode>
@@ -324,6 +325,8 @@ export interface Actions extends Omit<ViewportHelper, 'viewportInitialized'> {
getOutgoers: (nodeOrId: Node | string) => GraphNode[] getOutgoers: (nodeOrId: Node | string) => GraphNode[]
/** get a node's connected edges */ /** get a node's connected edges */
getConnectedEdges: (nodesOrId: Node[] | string) => GraphEdge[] getConnectedEdges: (nodesOrId: Node[] | string) => GraphEdge[]
/** get all connections of a handle belonging to a node */
getHandleConnections: ({ id, type, nodeId }: { id?: string | null; type: HandleType; nodeId: string }) => HandleConnection[]
/** pan the viewport; return indicates if a transform has happened or not */ /** pan the viewport; return indicates if a transform has happened or not */
panBy: (delta: XYPosition) => boolean panBy: (delta: XYPosition) => boolean
/** viewport helper instance */ /** viewport helper instance */