2023-04-02 14:57:12 +00:00
|
|
|
import { app } from "/scripts/app.js";
|
2023-04-20 04:19:56 +00:00
|
|
|
import { ComfyWidgets } from "/scripts/widgets.js";
|
2023-04-02 14:57:12 +00:00
|
|
|
// Adds defaults for quickly adding nodes with middle click on the input/output
|
|
|
|
|
|
|
|
app.registerExtension({
|
|
|
|
name: "Comfy.SlotDefaults",
|
2023-04-20 19:13:14 +00:00
|
|
|
suggestionsNumber: null,
|
2023-04-02 14:57:12 +00:00
|
|
|
init() {
|
2023-04-29 16:19:14 +00:00
|
|
|
LiteGraph.search_filter_enabled = true;
|
2023-04-02 14:57:12 +00:00
|
|
|
LiteGraph.middle_click_slot_add_default_node = true;
|
2023-04-20 19:13:14 +00:00
|
|
|
this.suggestionsNumber = app.ui.settings.addSetting({
|
|
|
|
id: "Comfy.NodeSuggestions.number",
|
|
|
|
name: "number of nodes suggestions",
|
|
|
|
type: "slider",
|
|
|
|
attrs: {
|
|
|
|
min: 1,
|
|
|
|
max: 100,
|
|
|
|
step: 1,
|
|
|
|
},
|
|
|
|
defaultValue: 5,
|
|
|
|
onChange: (newVal, oldVal) => {
|
|
|
|
this.setDefaults(newVal);
|
|
|
|
}
|
|
|
|
});
|
2023-04-20 04:19:56 +00:00
|
|
|
},
|
2023-04-20 19:13:14 +00:00
|
|
|
slot_types_default_out: {},
|
|
|
|
slot_types_default_in: {},
|
2023-04-20 04:19:56 +00:00
|
|
|
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
2023-04-20 19:13:14 +00:00
|
|
|
var nodeId = nodeData.name;
|
2023-04-20 04:19:56 +00:00
|
|
|
var inputs = [];
|
2023-04-20 19:13:14 +00:00
|
|
|
inputs = nodeData["input"]["required"]; //only show required inputs to reduce the mess also not logical to create node with optional inputs
|
2023-04-20 04:19:56 +00:00
|
|
|
for (const inputKey in inputs) {
|
|
|
|
var input = (inputs[inputKey]);
|
|
|
|
if (typeof input[0] !== "string") continue;
|
|
|
|
|
|
|
|
var type = input[0]
|
|
|
|
if (type in ComfyWidgets) {
|
|
|
|
var customProperties = input[1]
|
|
|
|
if (!(customProperties?.forceInput)) continue; //ignore widgets that don't force input
|
|
|
|
}
|
|
|
|
|
2023-04-20 19:13:14 +00:00
|
|
|
if (!(type in this.slot_types_default_out)) {
|
|
|
|
this.slot_types_default_out[type] = ["Reroute"];
|
2023-04-20 04:19:56 +00:00
|
|
|
}
|
2023-04-20 19:13:14 +00:00
|
|
|
if (this.slot_types_default_out[type].includes(nodeId)) continue;
|
|
|
|
this.slot_types_default_out[type].push(nodeId);
|
2023-04-29 16:19:14 +00:00
|
|
|
|
|
|
|
// Input types have to be stored as lower case
|
|
|
|
// Store each node that can handle this input type
|
|
|
|
const lowerType = type.toLocaleLowerCase();
|
|
|
|
if (!(lowerType in LiteGraph.registered_slot_in_types)) {
|
|
|
|
LiteGraph.registered_slot_in_types[lowerType] = { nodes: [] };
|
|
|
|
}
|
|
|
|
LiteGraph.registered_slot_in_types[lowerType].nodes.push(nodeType.comfyClass);
|
2023-04-20 19:13:14 +00:00
|
|
|
}
|
2023-04-20 04:19:56 +00:00
|
|
|
|
|
|
|
var outputs = nodeData["output"];
|
|
|
|
for (const key in outputs) {
|
|
|
|
var type = outputs[key];
|
2023-04-20 19:13:14 +00:00
|
|
|
if (!(type in this.slot_types_default_in)) {
|
|
|
|
this.slot_types_default_in[type] = ["Reroute"];// ["Reroute", "Primitive"]; primitive doesn't always work :'()
|
2023-04-20 04:19:56 +00:00
|
|
|
}
|
2023-04-02 14:57:12 +00:00
|
|
|
|
2023-04-20 19:13:14 +00:00
|
|
|
this.slot_types_default_in[type].push(nodeId);
|
2023-04-29 16:19:14 +00:00
|
|
|
|
|
|
|
// Store each node that can handle this output type
|
|
|
|
if (!(type in LiteGraph.registered_slot_out_types)) {
|
|
|
|
LiteGraph.registered_slot_out_types[type] = { nodes: [] };
|
|
|
|
}
|
|
|
|
LiteGraph.registered_slot_out_types[type].nodes.push(nodeType.comfyClass);
|
|
|
|
|
|
|
|
if(!LiteGraph.slot_types_out.includes(type)) {
|
|
|
|
LiteGraph.slot_types_out.push(type);
|
|
|
|
}
|
2023-04-20 19:13:14 +00:00
|
|
|
}
|
2023-04-22 03:43:38 +00:00
|
|
|
var maxNum = this.suggestionsNumber.value;
|
2023-04-20 19:13:14 +00:00
|
|
|
this.setDefaults(maxNum);
|
2023-04-02 14:57:12 +00:00
|
|
|
},
|
2023-04-20 19:13:14 +00:00
|
|
|
setDefaults(maxNum) {
|
|
|
|
|
|
|
|
LiteGraph.slot_types_default_out = {};
|
|
|
|
LiteGraph.slot_types_default_in = {};
|
|
|
|
|
|
|
|
for (const type in this.slot_types_default_out) {
|
|
|
|
LiteGraph.slot_types_default_out[type] = this.slot_types_default_out[type].slice(0, maxNum);
|
|
|
|
}
|
|
|
|
for (const type in this.slot_types_default_in) {
|
|
|
|
LiteGraph.slot_types_default_in[type] = this.slot_types_default_in[type].slice(0, maxNum);
|
|
|
|
}
|
|
|
|
}
|
2023-04-02 14:57:12 +00:00
|
|
|
});
|