mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #4051 from sonntam/feature-editor-multipleToNode
Added editor feature for connecting multiple nodes to single node
This commit is contained in:
commit
c2772e5038
@ -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() });
|
||||
|
Loading…
Reference in New Issue
Block a user