feat(core): add getIncomers, getOutgoers & getConnectedEdges as store actions

This commit is contained in:
braks
2023-10-06 18:00:01 +02:00
committed by Braks
parent 5e888987eb
commit edc7669b18
4 changed files with 95 additions and 20 deletions
+21 -2
View File
@@ -34,9 +34,11 @@ import {
createGraphNodes,
createNodeRemoveChange,
createSelectionChange,
getConnectedEdges,
getConnectedEdges as getConnectedEdgesBase,
getDimensions,
getHandleBounds,
getIncomers as getIncomersBase,
getOutgoers as getOutgoersBase,
getOverlappingArea,
getSelectionChanges,
isDef,
@@ -54,7 +56,9 @@ export function useActions(
hooksOn: any,
state: State,
getters: ComputedGetters,
// todo: change to a Set
nodeIds: ComputedRef<string[]>,
// todo: change to a Set
edgeIds: ComputedRef<string[]>,
): Actions {
const viewportHelper = useViewport(state, getters)
@@ -65,6 +69,18 @@ export function useActions(
state.hooks.updateNodeInternals.trigger(updateIds)
}
const getIncomers: Actions['getIncomers'] = (nodeOrId) => {
return getIncomersBase(nodeOrId, state.nodes, state.edges)
}
const getOutgoers: Actions['getOutgoers'] = (nodeOrId) => {
return getOutgoersBase(nodeOrId, state.nodes, state.edges)
}
const getConnectedEdges: Actions['getConnectedEdges'] = (nodesOrId) => {
return getConnectedEdgesBase(nodesOrId, state.edges)
}
const findNode: Actions['findNode'] = (id) => {
if (!id) {
return
@@ -519,7 +535,7 @@ export function useActions(
const edgeChanges: EdgeRemoveChange[] = []
function createEdgeRemovalChanges(nodes: Node[]) {
const connections = getConnectedEdges(nodes, state.edges).filter((edge) => (isDef(edge.deletable) ? edge.deletable : true))
const connections = getConnectedEdges(nodes).filter((edge) => (isDef(edge.deletable) ? edge.deletable : true))
edgeChanges.push(
...connections.map((connection) => createEdgeRemoveChange(connection.id, connection.source, connection.target)),
@@ -920,6 +936,9 @@ export function useActions(
setInteractive,
setState,
getIntersectingNodes,
getIncomers,
getOutgoers,
getConnectedEdges,
isNodeIntersecting,
panBy,
fitView: (params) => viewportHelper.value.fitView(params),
+2
View File
@@ -31,7 +31,9 @@ function defaultState(): State {
return {
vueFlowRef: null,
viewportRef: null,
// todo: change this to a Set
nodes: [],
// todo: change this to a Set
edges: [],
nodeTypes: {},
edgeTypes: {},