diff --git a/pkg/Library/NodeGraph/Editor.js b/pkg/Library/NodeGraph/Editor.js index a5f39e1c..52c8bd14 100644 --- a/pkg/Library/NodeGraph/Editor.js +++ b/pkg/Library/NodeGraph/Editor.js @@ -11,11 +11,7 @@ connectionDelimiter: ':', async update(inputs, state) { const {layout, graph} = inputs; - try { - state.graph = typeof graph === 'string' ? JSON.parse(graph) : graph; - } catch(x) { - state.graph = null; - } + state.graph = this.parseGraph(graph); state.layout = layout; const results = this.handleEvents(inputs, state); return { @@ -24,6 +20,23 @@ async update(inputs, state) { }; }, +parseGraph(graph) { + try { + const graphObj = typeof graph === 'string' ? JSON.parse(graph) : graph; + return this.finalizeGraph(graphObj); + } catch(x) { + return null; + } +}, + +finalizeGraph(graph) { + entries(graph?.nodes).forEach(([id, node]) => { + node.id = id; + node.displayName = node.displayName || node.id; + }); + return graph; +}, + handleEvents(inputs, state) { const {event} = inputs; if (event !== state.event) {