Added support for converting widgets to inputs (and back)

This commit is contained in:
pythongosssss
2023-03-23 21:37:19 +00:00
parent dd095efc2c
commit 7a7e3288ee
4 changed files with 385 additions and 20 deletions

View File

@@ -494,7 +494,7 @@ class ComfyApp {
// Create and mount the LiteGraph in the DOM
const canvasEl = (this.canvasEl = Object.assign(document.createElement("canvas"), { id: "graph-canvas" }));
canvasEl.tabIndex = "1"
canvasEl.tabIndex = "1";
document.body.prepend(canvasEl);
this.graph = new LGraph();
@@ -525,7 +525,10 @@ class ComfyApp {
this.loadGraphData(workflow);
restored = true;
}
} catch (err) {}
} catch (err) {
console.error("Error loading previous workflow", err);
debugger;
}
// We failed to restore a workflow so load the default
if (!restored) {
@@ -572,12 +575,8 @@ class ComfyApp {
const type = inputData[0];
if (Array.isArray(type)) {
// Enums e.g. latent rotation
let defaultValue = type[0];
if (inputData[1] && inputData[1].default) {
defaultValue = inputData[1].default;
}
this.addWidget("combo", inputName, defaultValue, () => {}, { values: type });
// Enums
Object.assign(config, widgets.COMBO(this, inputName, inputData, app) || {});
} else if (`${type}:${inputName}` in widgets) {
// Support custom widgets by Type:Name
Object.assign(config, widgets[`${type}:${inputName}`](this, inputName, inputData, app) || {});
@@ -667,11 +666,15 @@ class ComfyApp {
async graphToPrompt() {
const workflow = this.graph.serialize();
const output = {};
for (const n of workflow.nodes) {
const node = this.graph.getNodeById(n.id);
// Process nodes in order of execution
for (const node of this.graph.computeExecutionOrder(false)) {
const n = workflow.nodes.find((n) => n.id === node.id);
if (node.isVirtualNode) {
// Don't serialize frontend only nodes
// Don't serialize frontend only nodes but let them make changes
if (node.applyToGraph) {
node.applyToGraph(workflow);
}
continue;
}
@@ -695,7 +698,11 @@ class ComfyApp {
let link = node.getInputLink(i);
while (parent && parent.isVirtualNode) {
link = parent.getInputLink(link.origin_slot);
parent = parent.getInputNode(link.origin_slot);
if (link) {
parent = parent.getInputNode(link.origin_slot);
} else {
parent = null;
}
}
if (link) {