Skip to content

Commit 9c003d4

Browse files
committed
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>
1 parent 940b08e commit 9c003d4

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

.changeset/twenty-snakes-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": minor
3+
---
4+
5+
Add `getHandleConnections` action to store.

packages/core/src/store/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
7272
return getConnectedEdgesBase(nodesOrId, state.edges)
7373
}
7474

75+
const getHandleConnections: Actions['getHandleConnections'] = ({ id, type, nodeId }) => {
76+
return Array.from(state.connectionLookup.get(`${nodeId}-${type}-${id ?? null}`)?.values() ?? [])
77+
}
78+
7579
const findNode: Actions['findNode'] = (id) => {
7680
if (!id) {
7781
return
@@ -880,6 +884,7 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
880884
getIncomers,
881885
getOutgoers,
882886
getConnectedEdges,
887+
getHandleConnections,
883888
isNodeIntersecting,
884889
panBy,
885890
fitView: (params) => viewportHelper.value.fitView(params),

packages/core/src/types/store.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ import type {
2424
ConnectionMode,
2525
ConnectionStatus,
2626
Connector,
27+
HandleConnection,
2728
} from './connection'
2829
import type { DefaultEdgeOptions, Edge, EdgeUpdatable, GraphEdge } from './edge'
2930
import type { CoordinateExtent, CoordinateExtentRange, GraphNode, Node } from './node'
3031
import type { D3Selection, D3Zoom, D3ZoomHandler, PanOnScrollMode, ViewportTransform } from './zoom'
3132
import type { CustomEvent, FlowHooks, FlowHooksEmit, FlowHooksOn } from './hooks'
3233
import type { EdgeChange, NodeChange, NodeDragItem } from './changes'
33-
import type { ConnectingHandle, ValidConnectionFunc } from './handle'
34+
import type { ConnectingHandle, HandleType, ValidConnectionFunc } from './handle'
3435

3536
export type NodeLookup = Map<string, GraphNode>
3637

@@ -324,6 +325,8 @@ export interface Actions extends Omit<ViewportHelper, 'viewportInitialized'> {
324325
getOutgoers: (nodeOrId: Node | string) => GraphNode[]
325326
/** get a node's connected edges */
326327
getConnectedEdges: (nodesOrId: Node[] | string) => GraphEdge[]
328+
/** get all connections of a handle belonging to a node */
329+
getHandleConnections: ({ id, type, nodeId }: { id?: string | null; type: HandleType; nodeId: string }) => HandleConnection[]
327330
/** pan the viewport; return indicates if a transform has happened or not */
328331
panBy: (delta: XYPosition) => boolean
329332
/** viewport helper instance */

0 commit comments

Comments
 (0)