Skip to content

Commit e356667

Browse files
Update litegraph from upstream.
1 parent ad8e0cc commit e356667

File tree

1 file changed

+93
-49
lines changed

1 file changed

+93
-49
lines changed

web/lib/litegraph.core.js

Lines changed: 93 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@
142142
pointerevents_method: "pointer", // "mouse"|"pointer" use mouse for retrocompatibility issues? (none found @ now)
143143
// TODO implement pointercancel, gotpointercapture, lostpointercapture, (pointerover, pointerout if necessary)
144144

145+
ctrl_shift_v_paste_connect_unselected_outputs: true, //[true!] allows ctrl + shift + v to paste nodes with the outputs of the unselected nodes connected with the inputs of the newly pasted nodes
146+
145147
/**
146148
* Register a node class so it can be listed when the user wants to create a new one
147149
* @method registerNodeType
@@ -253,52 +255,68 @@
253255
* @param {String|Object} type name of the node or the node constructor itself
254256
*/
255257
unregisterNodeType: function(type) {
256-
var base_class = type.constructor === String ? this.registered_node_types[type] : type;
257-
if(!base_class)
258-
throw("node type not found: " + type );
259-
delete this.registered_node_types[base_class.type];
260-
if(base_class.constructor.name)
261-
delete this.Nodes[base_class.constructor.name];
262-
},
258+
const base_class =
259+
type.constructor === String
260+
? this.registered_node_types[type]
261+
: type;
262+
if (!base_class) {
263+
throw "node type not found: " + type;
264+
}
265+
delete this.registered_node_types[base_class.type];
266+
if (base_class.constructor.name) {
267+
delete this.Nodes[base_class.constructor.name];
268+
}
269+
},
263270

264271
/**
265272
* Save a slot type and his node
266273
* @method registerSlotType
267274
* @param {String|Object} type name of the node or the node constructor itself
268275
* @param {String} slot_type name of the slot type (variable type), eg. string, number, array, boolean, ..
269276
*/
270-
registerNodeAndSlotType: function(type,slot_type,out){
277+
registerNodeAndSlotType: function(type, slot_type, out){
271278
out = out || false;
272-
var base_class = type.constructor === String && this.registered_node_types[type] !== "anonymous" ? this.registered_node_types[type] : type;
273-
274-
var sCN = base_class.constructor.type;
275-
276-
if (typeof slot_type == "string"){
277-
var aTypes = slot_type.split(",");
278-
}else if (slot_type == this.EVENT || slot_type == this.ACTION){
279-
var aTypes = ["_event_"];
280-
}else{
281-
var aTypes = ["*"];
279+
const base_class =
280+
type.constructor === String &&
281+
this.registered_node_types[type] !== "anonymous"
282+
? this.registered_node_types[type]
283+
: type;
284+
285+
const class_type = base_class.constructor.type;
286+
287+
let allTypes = [];
288+
if (typeof slot_type === "string") {
289+
allTypes = slot_type.split(",");
290+
} else if (slot_type == this.EVENT || slot_type == this.ACTION) {
291+
allTypes = ["_event_"];
292+
} else {
293+
allTypes = ["*"];
282294
}
283295

284-
for (var i = 0; i < aTypes.length; ++i) {
285-
var sT = aTypes[i]; //.toLowerCase();
286-
if (sT === ""){
287-
sT = "*";
296+
for (let i = 0; i < allTypes.length; ++i) {
297+
let slotType = allTypes[i];
298+
if (slotType === "") {
299+
slotType = "*";
288300
}
289-
var registerTo = out ? "registered_slot_out_types" : "registered_slot_in_types";
290-
if (typeof this[registerTo][sT] == "undefined") this[registerTo][sT] = {nodes: []};
291-
this[registerTo][sT].nodes.push(sCN);
292-
301+
const registerTo = out
302+
? "registered_slot_out_types"
303+
: "registered_slot_in_types";
304+
if (this[registerTo][slotType] === undefined) {
305+
this[registerTo][slotType] = { nodes: [] };
306+
}
307+
if (!this[registerTo][slotType].nodes.includes(class_type)) {
308+
this[registerTo][slotType].nodes.push(class_type);
309+
}
310+
293311
// check if is a new type
294-
if (!out){
295-
if (!this.slot_types_in.includes(sT.toLowerCase())){
296-
this.slot_types_in.push(sT.toLowerCase());
312+
if (!out) {
313+
if (!this.slot_types_in.includes(slotType.toLowerCase())) {
314+
this.slot_types_in.push(slotType.toLowerCase());
297315
this.slot_types_in.sort();
298316
}
299-
}else{
300-
if (!this.slot_types_out.includes(sT.toLowerCase())){
301-
this.slot_types_out.push(sT.toLowerCase());
317+
} else {
318+
if (!this.slot_types_out.includes(slotType.toLowerCase())) {
319+
this.slot_types_out.push(slotType.toLowerCase());
302320
this.slot_types_out.sort();
303321
}
304322
}
@@ -1616,7 +1634,8 @@
16161634
var nRet = null;
16171635
for (var i = nodes_list.length - 1; i >= 0; i--) {
16181636
var n = nodes_list[i];
1619-
if (n.isPointInside(x, y, margin)) {
1637+
var skip_title = n.constructor.title_mode == LiteGraph.NO_TITLE;
1638+
if (n.isPointInside(x, y, margin, skip_title)) {
16201639
// check for lesser interest nodes (TODO check for overlapping, use the top)
16211640
/*if (typeof n == "LGraphGroup"){
16221641
nRet = n;
@@ -3967,8 +3986,8 @@
39673986
var aSource = (type+"").toLowerCase().split(",");
39683987
var aDest = aSlots[i].type=="0"||aSlots[i].type=="*"?"0":aSlots[i].type;
39693988
aDest = (aDest+"").toLowerCase().split(",");
3970-
for(sI=0;sI<aSource.length;sI++){
3971-
for(dI=0;dI<aDest.length;dI++){
3989+
for(var sI=0;sI<aSource.length;sI++){
3990+
for(var dI=0;dI<aDest.length;dI++){
39723991
if (aSource[sI]=="_event_") aSource[sI] = LiteGraph.EVENT;
39733992
if (aDest[sI]=="_event_") aDest[sI] = LiteGraph.EVENT;
39743993
if (aSource[sI]=="*") aSource[sI] = 0;
@@ -3987,8 +4006,8 @@
39874006
var aSource = (type+"").toLowerCase().split(",");
39884007
var aDest = aSlots[i].type=="0"||aSlots[i].type=="*"?"0":aSlots[i].type;
39894008
aDest = (aDest+"").toLowerCase().split(",");
3990-
for(sI=0;sI<aSource.length;sI++){
3991-
for(dI=0;dI<aDest.length;dI++){
4009+
for(var sI=0;sI<aSource.length;sI++){
4010+
for(var dI=0;dI<aDest.length;dI++){
39924011
if (aSource[sI]=="*") aSource[sI] = 0;
39934012
if (aDest[sI]=="*") aDest[sI] = 0;
39944013
if (aSource[sI] == aDest[dI]) {
@@ -4019,7 +4038,7 @@
40194038
if (target_node && target_node.constructor === Number) {
40204039
target_node = this.graph.getNodeById(target_node);
40214040
}
4022-
target_slot = target_node.findInputSlotByType(target_slotType, false, true);
4041+
var target_slot = target_node.findInputSlotByType(target_slotType, false, true);
40234042
if (target_slot >= 0 && target_slot !== null){
40244043
//console.debug("CONNbyTYPE type "+target_slotType+" for "+target_slot)
40254044
return this.connect(slot, target_node, target_slot);
@@ -4072,7 +4091,7 @@
40724091
if (source_node && source_node.constructor === Number) {
40734092
source_node = this.graph.getNodeById(source_node);
40744093
}
4075-
source_slot = source_node.findOutputSlotByType(source_slotType, false, true);
4094+
var source_slot = source_node.findOutputSlotByType(source_slotType, false, true);
40764095
if (source_slot >= 0 && source_slot !== null){
40774096
//console.debug("CONNbyTYPE OUT! type "+source_slotType+" for "+source_slot)
40784097
return source_node.connect(source_slot, this, slot);
@@ -5184,6 +5203,7 @@ LGraphNode.prototype.executeAction = function(action)
51845203
this.editor_alpha = 1; //used for transition
51855204
this.pause_rendering = false;
51865205
this.clear_background = true;
5206+
this.clear_background_color = "#222";
51875207

51885208
this.read_only = false; //if set to true users cannot modify the graph
51895209
this.render_only_selected = true;
@@ -6986,17 +7006,17 @@ LGraphNode.prototype.executeAction = function(action)
69867006
block_default = true;
69877007
}
69887008

6989-
if (e.code == "KeyC" && (e.metaKey || e.ctrlKey) && !e.shiftKey) {
7009+
if ((e.keyCode === 67) && (e.metaKey || e.ctrlKey) && !e.shiftKey) {
69907010
//copy
69917011
if (this.selected_nodes) {
69927012
this.copyToClipboard();
69937013
block_default = true;
69947014
}
69957015
}
69967016

6997-
if (e.code == "KeyV" && (e.metaKey || e.ctrlKey) && !e.shiftKey) {
7017+
if ((e.keyCode === 86) && (e.metaKey || e.ctrlKey)) {
69987018
//paste
6999-
this.pasteFromClipboard();
7019+
this.pasteFromClipboard(e.shiftKey);
70007020
}
70017021

70027022
//delete or backspace
@@ -7081,15 +7101,15 @@ LGraphNode.prototype.executeAction = function(action)
70817101
var target_node = this.graph.getNodeById(
70827102
link_info.origin_id
70837103
);
7084-
if (!target_node || !this.selected_nodes[target_node.id]) {
7085-
//improve this by allowing connections to non-selected nodes
7104+
if (!target_node) {
70867105
continue;
7087-
} //not selected
7106+
}
70887107
clipboard_info.links.push([
70897108
target_node._relative_id,
70907109
link_info.origin_slot, //j,
70917110
node._relative_id,
7092-
link_info.target_slot
7111+
link_info.target_slot,
7112+
target_node.id
70937113
]);
70947114
}
70957115
}
@@ -7100,7 +7120,11 @@ LGraphNode.prototype.executeAction = function(action)
71007120
);
71017121
};
71027122

7103-
LGraphCanvas.prototype.pasteFromClipboard = function() {
7123+
LGraphCanvas.prototype.pasteFromClipboard = function(isConnectUnselected = false) {
7124+
// if ctrl + shift + v is off, return when isConnectUnselected is true (shift is pressed) to maintain old behavior
7125+
if (!LiteGraph.ctrl_shift_v_paste_connect_unselected_outputs && isConnectUnselected) {
7126+
return;
7127+
}
71047128
var data = localStorage.getItem("litegrapheditor_clipboard");
71057129
if (!data) {
71067130
return;
@@ -7149,7 +7173,16 @@ LGraphNode.prototype.executeAction = function(action)
71497173
//create links
71507174
for (var i = 0; i < clipboard_info.links.length; ++i) {
71517175
var link_info = clipboard_info.links[i];
7152-
var origin_node = nodes[link_info[0]];
7176+
var origin_node;
7177+
var origin_node_relative_id = link_info[0];
7178+
if (origin_node_relative_id != null) {
7179+
origin_node = nodes[origin_node_relative_id];
7180+
} else if (LiteGraph.ctrl_shift_v_paste_connect_unselected_outputs && isConnectUnselected) {
7181+
var origin_node_id = link_info[4];
7182+
if (origin_node_id) {
7183+
origin_node = this.graph.getNodeById(origin_node_id);
7184+
}
7185+
}
71537186
var target_node = nodes[link_info[2]];
71547187
if( origin_node && target_node )
71557188
origin_node.connect(link_info[1], target_node, link_info[3]);
@@ -8212,6 +8245,17 @@ LGraphNode.prototype.executeAction = function(action)
82128245
this.ds.toCanvasContext(ctx);
82138246

82148247
//render BG
8248+
if ( this.ds.scale < 1.5 && !bg_already_painted && this.clear_background_color )
8249+
{
8250+
ctx.fillStyle = this.clear_background_color;
8251+
ctx.fillRect(
8252+
this.visible_area[0],
8253+
this.visible_area[1],
8254+
this.visible_area[2],
8255+
this.visible_area[3]
8256+
);
8257+
}
8258+
82158259
if (
82168260
this.background_image &&
82178261
this.ds.scale > 0.5 &&
@@ -12274,7 +12318,7 @@ LGraphNode.prototype.executeAction = function(action)
1227412318

1227512319
var aProps = LiteGraph.availableCanvasOptions;
1227612320
aProps.sort();
12277-
for(pI in aProps){
12321+
for(var pI in aProps){
1227812322
var pX = aProps[pI];
1227912323
panel.addWidget( "boolean", pX, graphcanvas[pX], {key: pX, on: "True", off: "False"}, fUpdate);
1228012324
}

0 commit comments

Comments
 (0)