@@ -152,23 +152,23 @@ export function parseEdge(edge: Edge, defaults: Partial<GraphEdge> = {}): GraphE
152
152
}
153
153
154
154
function getConnectedElements < T extends Elements = FlowElements > (
155
- node : Node ,
155
+ nodeOrId : Node | { id : string } | string ,
156
156
elements : T ,
157
157
dir : 'source' | 'target' ,
158
158
) : T extends FlowElements ? GraphNode [ ] : Node [ ] {
159
- if ( ! isNode ( node ) ) {
160
- return [ ]
161
- }
159
+ const id = isString ( nodeOrId ) ? nodeOrId : nodeOrId . id
160
+
162
161
const origin = dir === 'source' ? 'target' : 'source'
163
- const ids = elements . filter ( ( e ) => isEdge ( e ) && e [ origin ] === node . id ) . map ( ( e ) => isEdge ( e ) && e [ dir ] )
162
+ const ids = elements . filter ( ( e ) => isEdge ( e ) && e [ origin ] === id ) . map ( ( e ) => isEdge ( e ) && e [ dir ] )
163
+
164
164
return elements . filter ( ( e ) => ids . includes ( e . id ) ) as T extends FlowElements ? GraphNode [ ] : Node [ ]
165
165
}
166
- export function getOutgoers < T extends Elements = FlowElements > ( node : Node , elements : T ) {
167
- return getConnectedElements ( node , elements , 'target' )
166
+ export function getOutgoers < T extends Elements = FlowElements > ( nodeOrId : Node | { id : string } | string , elements : T ) {
167
+ return getConnectedElements ( nodeOrId , elements , 'target' )
168
168
}
169
169
170
- export function getIncomers < T extends Elements = FlowElements > ( node : Node , elements : T ) {
171
- return getConnectedElements ( node , elements , 'source' )
170
+ export function getIncomers < T extends Elements = FlowElements > ( nodeOrId : Node | { id : string } | string , elements : T ) {
171
+ return getConnectedElements ( nodeOrId , elements , 'source' )
172
172
}
173
173
174
174
export function getEdgeId ( { source, sourceHandle, target, targetHandle } : Connection ) {
0 commit comments