From 9c003d4353a4bbfe7d9a4d8ac7f8ed3e708c3c29 Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:07:09 +0200 Subject: [PATCH] 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> --- .changeset/twenty-snakes-hear.md | 5 +++++ packages/core/src/store/actions.ts | 5 +++++ packages/core/src/types/store.ts | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/twenty-snakes-hear.md diff --git a/.changeset/twenty-snakes-hear.md b/.changeset/twenty-snakes-hear.md new file mode 100644 index 00000000..3b647d92 --- /dev/null +++ b/.changeset/twenty-snakes-hear.md @@ -0,0 +1,5 @@ +--- +"@vue-flow/core": minor +--- + +Add `getHandleConnections` action to store. diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index 61e0a1f5..fe048d77 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -72,6 +72,10 @@ export function useActions(state: State, nodeLookup: ComputedRef, ed 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) => { if (!id) { return @@ -880,6 +884,7 @@ export function useActions(state: State, nodeLookup: ComputedRef, ed getIncomers, getOutgoers, getConnectedEdges, + getHandleConnections, isNodeIntersecting, panBy, fitView: (params) => viewportHelper.value.fitView(params), diff --git a/packages/core/src/types/store.ts b/packages/core/src/types/store.ts index 481922fb..c1b3844f 100644 --- a/packages/core/src/types/store.ts +++ b/packages/core/src/types/store.ts @@ -24,13 +24,14 @@ import type { ConnectionMode, ConnectionStatus, Connector, + HandleConnection, } from './connection' import type { DefaultEdgeOptions, Edge, EdgeUpdatable, GraphEdge } from './edge' import type { CoordinateExtent, CoordinateExtentRange, GraphNode, Node } from './node' import type { D3Selection, D3Zoom, D3ZoomHandler, PanOnScrollMode, ViewportTransform } from './zoom' import type { CustomEvent, FlowHooks, FlowHooksEmit, FlowHooksOn } from './hooks' import type { EdgeChange, NodeChange, NodeDragItem } from './changes' -import type { ConnectingHandle, ValidConnectionFunc } from './handle' +import type { ConnectingHandle, HandleType, ValidConnectionFunc } from './handle' export type NodeLookup = Map @@ -324,6 +325,8 @@ export interface Actions extends Omit { getOutgoers: (nodeOrId: Node | string) => GraphNode[] /** get a node's connected edges */ 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 */ panBy: (delta: XYPosition) => boolean /** viewport helper instance */