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