diff --git a/packages/node_modules/@node-red/editor-client/src/js/nodes.js b/packages/node_modules/@node-red/editor-client/src/js/nodes.js index 366120796..4042f3e12 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/nodes.js +++ b/packages/node_modules/@node-red/editor-client/src/js/nodes.js @@ -707,12 +707,15 @@ RED.nodes = (function() { } n["_"] = RED._; } + + // Both node and config node can use a config node + updateConfigNodeUsers(newNode, { action: "add" }); + if (n._def.category == "config") { configNodes[n.id] = newNode; } else { if (n.wires && (n.wires.length > n.outputs)) { n.outputs = n.wires.length; } n.dirty = true; - updateConfigNodeUsers(newNode, { action: "add" }); if (n._def.category == "subflows" && typeof n.i === "undefined") { var nextId = 0; RED.nodes.eachNode(function(node) { @@ -774,9 +777,11 @@ RED.nodes = (function() { var removedLinks = []; var removedNodes = []; var node; + if (id in configNodes) { node = configNodes[id]; delete configNodes[id]; + updateConfigNodeUsers(node, { action: "remove" }); RED.events.emit('nodes:remove',node); RED.workspaces.refresh(); } else if (allNodes.hasNode(id)) { @@ -786,6 +791,8 @@ RED.nodes = (function() { removedLinks = links.filter(function(l) { return (l.source === node) || (l.target === node); }); removedLinks.forEach(removeLink); updateConfigNodeUsers(node, { action: "remove" }); + + // TODO: Legacy code for exclusive config node var updatedConfigNode = false; for (var d in node._def.defaults) { if (node._def.defaults.hasOwnProperty(d)) { @@ -2187,6 +2194,21 @@ RED.nodes = (function() { } } + // Config node can use another config node, must ensure that this other + // config node is added before to exists when updating the user list + const configNodeFilter = function (node) { + let count = 0; + if (node._def?.defaults) { + for (const def of Object.values(node._def.defaults)) { + if (def.type) { + count++; + } + } + } + return count; + }; + new_nodes.sort((a, b) => configNodeFilter(a) - configNodeFilter(b)); + // Find regular flow nodes and subflow instances for (i=0;i