mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add viewAddPort viewRemovePort viewAddNode viewRemoveNode hooks to view
This commit is contained in:
parent
319af51f84
commit
c47b553a8e
@ -3789,7 +3789,9 @@ RED.view = (function() {
|
||||
}
|
||||
|
||||
var node = nodeLayer.selectAll(".red-ui-flow-node-group").data(activeNodes,function(d){return d.id});
|
||||
node.exit().remove();
|
||||
node.exit().each(function(d,i) {
|
||||
RED.hooks.trigger("viewRemoveNode",{node:d,el:this})
|
||||
}).remove();
|
||||
|
||||
var nodeEnter = node.enter().insert("svg:g")
|
||||
.attr("class", "red-ui-flow-node red-ui-flow-node-group")
|
||||
@ -3963,6 +3965,7 @@ RED.view = (function() {
|
||||
});
|
||||
node.each(function(d,i) {
|
||||
if (d.dirty) {
|
||||
var self = this;
|
||||
var thisNode = d3.select(this);
|
||||
|
||||
var isLink = (d.type === "link in" || d.type === "link out")
|
||||
@ -4073,7 +4076,15 @@ RED.view = (function() {
|
||||
|
||||
var inputPorts = thisNode.selectAll(".red-ui-flow-port-input");
|
||||
if ((!isLink || (showAllLinkPorts === -1 && !activeLinkNodes[d.id])) && d.inputs === 0 && !inputPorts.empty()) {
|
||||
inputPorts.remove();
|
||||
inputPorts.each(function(d,i) {
|
||||
RED.hooks.trigger("viewRemovePort",{
|
||||
node:d,
|
||||
el:self,
|
||||
port:d3.select(this)[0][0],
|
||||
portType: "input",
|
||||
portIndex: 0
|
||||
})
|
||||
}).remove();
|
||||
} else if (((isLink && (showAllLinkPorts===PORT_TYPE_INPUT||activeLinkNodes[d.id]))|| d.inputs === 1) && inputPorts.empty()) {
|
||||
var inputGroup = thisNode.append("g").attr("class","red-ui-flow-port-input");
|
||||
var inputGroupPorts;
|
||||
@ -4086,12 +4097,17 @@ RED.view = (function() {
|
||||
} else {
|
||||
inputGroupPorts = inputGroup.append("rect").attr("class","red-ui-flow-port").attr("rx",3).attr("ry",3).attr("width",10).attr("height",10)
|
||||
}
|
||||
inputGroup[0][0].__port__ = inputGroupPorts[0][0];
|
||||
inputGroupPorts[0][0].__data__ = this.__data__;
|
||||
inputGroupPorts[0][0].__portType__ = PORT_TYPE_INPUT;
|
||||
inputGroupPorts[0][0].__portIndex__ = 0;
|
||||
inputGroupPorts.on("mousedown",function(d){portMouseDown(d,PORT_TYPE_INPUT,0);})
|
||||
.on("touchstart",function(d){portMouseDown(d,PORT_TYPE_INPUT,0);d3.event.preventDefault();})
|
||||
.on("mouseup",function(d){portMouseUp(d,PORT_TYPE_INPUT,0);} )
|
||||
.on("touchend",function(d){portMouseUp(d,PORT_TYPE_INPUT,0);d3.event.preventDefault();} )
|
||||
.on("mouseover",function(d){portMouseOver(d3.select(this),d,PORT_TYPE_INPUT,0);})
|
||||
.on("mouseout",function(d) {portMouseOut(d3.select(this),d,PORT_TYPE_INPUT,0);});
|
||||
RED.hooks.trigger("viewAddPort",{node:d,el: this, port: inputGroup[0][0], portType: "input", portIndex: 0})
|
||||
}
|
||||
var numOutputs = d.outputs;
|
||||
if (isLink && d.type === "link out") {
|
||||
@ -4106,6 +4122,13 @@ RED.view = (function() {
|
||||
// Remove extra ports
|
||||
while (this.__outputs__.length > numOutputs) {
|
||||
var port = this.__outputs__.pop();
|
||||
RED.hooks.trigger("viewRemovePort",{
|
||||
node:d,
|
||||
el:this,
|
||||
port:port,
|
||||
portType: "output",
|
||||
portIndex: this.__outputs__.length
|
||||
})
|
||||
port.remove();
|
||||
}
|
||||
for(var portIndex = 0; portIndex < numOutputs; portIndex++ ) {
|
||||
@ -4129,6 +4152,7 @@ RED.view = (function() {
|
||||
portPort.setAttribute("class","red-ui-flow-port");
|
||||
}
|
||||
portGroup.appendChild(portPort);
|
||||
portGroup.__port__ = portPort;
|
||||
portPort.__data__ = this.__data__;
|
||||
portPort.__portType__ = PORT_TYPE_OUTPUT;
|
||||
portPort.__portIndex__ = portIndex;
|
||||
@ -4141,6 +4165,7 @@ RED.view = (function() {
|
||||
|
||||
this.appendChild(portGroup);
|
||||
this.__outputs__.push(portGroup);
|
||||
RED.hooks.trigger("viewAddPort",{node:d,el: this, port: portGroup, portType: "output", portIndex: portIndex})
|
||||
} else {
|
||||
portGroup = this.__outputs__[portIndex];
|
||||
}
|
||||
@ -4229,6 +4254,8 @@ RED.view = (function() {
|
||||
// });
|
||||
}
|
||||
|
||||
RED.hooks.trigger("viewAddNode",{node:d,el:this})
|
||||
|
||||
if (d.dirtyStatus) {
|
||||
redrawStatus(d,this);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user