UNPKG

@selenite/graph-editor

Version:

A graph editor for visual programming, based on rete and svelte.

27 lines (26 loc) 1.13 kB
import { structures } from 'rete-structures'; import { Connection, Node } from './Node.svelte'; export function getLeavesFromOutput(node, key) { const connections = node.getEditor().getConnections(); const loopNode = connections .filter((connection) => connection.source === node.id && connection.sourceOutput === key) .map((connection) => node.getEditor().getNode(connection.target))[0]; if (!loopNode) return []; return getNodesToWaitFor(loopNode, structures(node.getEditor())); } function getNodesToWaitFor(node, struct) { const outExec = node.getNaturalFlow(); // console.log("outExec", outExec); if (outExec === undefined || !(outExec in node.outputs)) return [node]; const editor = node.getEditor(); const nextNodes = editor .getConnections() .filter((connection) => connection.source === node.id && connection.sourceOutput === outExec) .map((connection) => editor.getNode(connection.target)); if (nextNodes.length === 0) return [node]; const nextNode = nextNodes[0]; return getNodesToWaitFor(nextNode, struct); }