diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js b/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js index f46167b24..a22f65f76 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js @@ -840,6 +840,64 @@ RED.view.tools = (function() { } } + function wireMultipleToNode() { + if (RED.workspaces.isActiveLocked()) { + return + } + var selection = RED.view.selection(); + if (selection.nodes) { + if (selection.nodes.length > 1) { + var targetNode = selection.nodes[selection.nodes.length - 1]; + if (targetNode.inputs === 0) { + return; + } + var i = 0; + var newLinks = []; + for (i = 0; i < selection.nodes.length - 1; i++) { + var sourceNode = selection.nodes[i]; + if (sourceNode.outputs > 0) { + + // Wire the first output to the target that has no link to the target yet. + // This allows for connecting all combinations of inputs/outputs. + // The user may then delete links quickly that aren't needed. + var sourceConnectedOutports = RED.nodes.filterLinks({ + source: sourceNode, + target: targetNode + }); + + // Get outport indices that have no link yet + var sourceOutportIndices = Array.from({ length: sourceNode.outputs }, (_, i) => i); + var sourceConnectedOutportIndices = sourceConnectedOutports.map( x => x.sourcePort ); + var sourceFreeOutportIndices = sourceOutportIndices.filter(x => !sourceConnectedOutportIndices.includes(x)); + + // Does an unconnected source port exist? + if (sourceFreeOutportIndices.length == 0) { + continue; + } + + // Connect the first free outport to the target + var newLink = { + source: sourceNode, + target: targetNode, + sourcePort: sourceFreeOutportIndices[0] + } + RED.nodes.addLink(newLink); + newLinks.push(newLink); + } + } + if (newLinks.length > 0) { + RED.history.push({ + t: 'add', + links: newLinks, + dirty: RED.nodes.dirty() + }) + RED.nodes.dirty(true); + RED.view.redraw(true); + } + } + } + } + /** * Splits selected wires and re-joins them with link-out+link-in * @param {Object || Object[]} wires The wire(s) to split and replace with link-out, link-in nodes. @@ -1307,6 +1365,7 @@ RED.view.tools = (function() { RED.actions.add("core:wire-series-of-nodes", function() { wireSeriesOfNodes() }) RED.actions.add("core:wire-node-to-multiple", function() { wireNodeToMultiple() }) + RED.actions.add("core:wire-multiple-to-node", function() { wireMultipleToNode() }) RED.actions.add("core:split-wire-with-link-nodes", function () { splitWiresWithLinkNodes() }); RED.actions.add("core:split-wires-with-junctions", function () { addJunctionsToWires() });