UNPKG

rivet-plugin-trouver-parents

Version:

A Rivet plugin node that outputs a list of graphs that call the current one as a subgraph.

86 lines (77 loc) 1.86 kB
function findParentGraphNode(rivet) { const nodeImpl = { create() { return { id: rivet.newId(), type: "findParentGraph", title: "Find Parent Graphs", data: {}, visualData: { x: 0, y: 0, width: 250 } }; }, getInputDefinitions() { return []; }, getOutputDefinitions() { return [ { id: "callers", title: "Callers", dataType: "string" } ]; }, getUIData() { return { contextMenuTitle: "Find Parent Graphs", group: "Tools", infoBoxTitle: "Find Parent Graph Usage", infoBoxBody: "Lists all graphs that call this one as a subgraph." }; }, getEditors() { return []; }, getBody(_data, _ctx) { return "This node returns the list of parent graphs."; }, async process(_data, _inputData, context) { const callers = []; for (const g of context.project.graphs) { for (const node of g.nodes) { if (node.type === "subgraph" && node.subgraph === context.graph.id) { callers.push(g.name); break; } } } const result = callers.length ? callers.join(", ") : "Ce graphe n'est appelé par aucun autre."; return { callers: { type: "string", value: result } }; } }; return rivet.pluginNodeDefinition(nodeImpl, "Find Parent Graphs"); } const plugin = (rivet) => { const findNode = findParentGraphNode(rivet); return { id: "rivet-plugin-find-parent-graphs", name: "Find Parent Graphs", configSpec: {}, contextMenuGroups: [{ id: "tools", label: "Tools" }], register(register) { register(findNode); } }; }; export default plugin;