mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-21 22:47:00 +08:00
Support multiple image loaders
This commit is contained in:
parent
cef8c13703
commit
71725566ac
@ -1,9 +1,9 @@
|
|||||||
import { $el } from "../ui.js";
|
import { $el } from "../ui.js";
|
||||||
|
|
||||||
export class ComfyDialog extends EventTarget {
|
export class ComfyDialog extends EventTarget {
|
||||||
constructor() {
|
constructor(type = "div") {
|
||||||
super();
|
super();
|
||||||
this.element = $el("div.comfy-modal", { parent: document.body }, [
|
this.element = $el(type + ".comfy-modal", { parent: document.body }, [
|
||||||
$el("div.comfy-modal-content", [$el("p", { $: (p) => (this.textElement = p) }), ...this.createButtons()]),
|
$el("div.comfy-modal-content", [$el("p", { $: (p) => (this.textElement = p) }), ...this.createButtons()]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ export class ComfyDialog extends EventTarget {
|
|||||||
if (typeof html === "string") {
|
if (typeof html === "string") {
|
||||||
this.textElement.innerHTML = html;
|
this.textElement.innerHTML = html;
|
||||||
} else {
|
} else {
|
||||||
this.textElement.replaceChildren(html);
|
this.textElement.replaceChildren(...(html instanceof Array ? html : [html]));
|
||||||
}
|
}
|
||||||
this.element.style.display = "flex";
|
this.element.style.display = "flex";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -598,3 +598,43 @@
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Send to workflow widget selection dialog */
|
||||||
|
.comfy-widget-selection-dialog {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-widget-selection-dialog div {
|
||||||
|
color: var(--fg-color);
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-widget-selection-dialog h2 {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-widget-selection-dialog section {
|
||||||
|
width: fit-content;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-widget-selection-item {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-widget-selection-item span {
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-widget-selection-item span::before {
|
||||||
|
content: '#' attr(data-id);
|
||||||
|
opacity: 0.5;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-modal .comfy-widget-selection-item button {
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@ import { api } from "../../api.js";
|
|||||||
import { ComfyPopup } from "../components/popup.js";
|
import { ComfyPopup } from "../components/popup.js";
|
||||||
import { createSpinner } from "../spinner.js";
|
import { createSpinner } from "../spinner.js";
|
||||||
import { ComfyWorkflow, trimJsonExt } from "../../workflows.js";
|
import { ComfyWorkflow, trimJsonExt } from "../../workflows.js";
|
||||||
|
import { ComfyDialog } from "../dialog.js";
|
||||||
|
|
||||||
export class ComfyWorkflowsMenu {
|
export class ComfyWorkflowsMenu {
|
||||||
#first = true;
|
#first = true;
|
||||||
@ -173,6 +174,7 @@ export class ComfyWorkflowsMenu {
|
|||||||
const imageId = `${subfolder ? subfolder + "/" : ""}${filename} [${type}]`;
|
const imageId = `${subfolder ? subfolder + "/" : ""}${filename} [${type}]`;
|
||||||
widget.value = imageId;
|
widget.value = imageId;
|
||||||
node.imgs = [img];
|
node.imgs = [img];
|
||||||
|
app.graph.setDirtyCanvas(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -181,35 +183,31 @@ export class ComfyWorkflowsMenu {
|
|||||||
*/
|
*/
|
||||||
async function sendToWorkflow(img, workflow) {
|
async function sendToWorkflow(img, workflow) {
|
||||||
await workflow.load();
|
await workflow.load();
|
||||||
let targetNode;
|
let options = [];
|
||||||
let targetWidget;
|
|
||||||
const nodes = app.graph.computeExecutionOrder(false);
|
const nodes = app.graph.computeExecutionOrder(false);
|
||||||
for (const n of nodes) {
|
for (const node of nodes) {
|
||||||
const widget = getImageWidget(n);
|
const widget = getImageWidget(node);
|
||||||
if (widget == null) continue;
|
if (widget == null) continue;
|
||||||
|
|
||||||
if (n.title?.toLowerCase().includes("input")) {
|
if (node.title?.toLowerCase().includes("input")) {
|
||||||
targetWidget = widget;
|
options = [{ widget, node }];
|
||||||
targetNode = n;
|
|
||||||
break;
|
break;
|
||||||
} else if (!targetWidget) {
|
|
||||||
targetWidget = widget;
|
|
||||||
targetNode = n;
|
|
||||||
} else {
|
} else {
|
||||||
alert(
|
options.push({ widget, node });
|
||||||
"Multiple image nodes have been found, the first one has been selected. You can include 'input' in the title of the node to use a specific node."
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!targetWidget) {
|
if (!options.length) {
|
||||||
alert("No image nodes have been found in this workflow!");
|
alert("No image nodes have been found in this workflow!");
|
||||||
return;
|
return;
|
||||||
|
} else if (options.length > 1) {
|
||||||
|
const dialog = new WidgetSelectionDialog(options);
|
||||||
|
const res = await dialog.show(app);
|
||||||
|
if (!res) return;
|
||||||
|
options = [res];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setWidgetImage(options[0].node, options[0].widget, img);
|
||||||
setWidgetImage(targetNode, targetWidget, img);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getExtraMenuOptions = nodeType.prototype["getExtraMenuOptions"];
|
const getExtraMenuOptions = nodeType.prototype["getExtraMenuOptions"];
|
||||||
@ -614,3 +612,69 @@ class WorkflowElement {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class WidgetSelectionDialog extends ComfyDialog {
|
||||||
|
#options;
|
||||||
|
#resolve;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Array<{widget: {name: string}, node: {pos: [number, number], title: string, id: string, type: string}}>} options
|
||||||
|
*/
|
||||||
|
constructor(options) {
|
||||||
|
super("dialog");
|
||||||
|
this.#options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
show(app) {
|
||||||
|
this.element.addEventListener("close", () => {
|
||||||
|
this.close();
|
||||||
|
});
|
||||||
|
this.element.classList.add("comfy-widget-selection-dialog");
|
||||||
|
super.show(
|
||||||
|
$el("div", [
|
||||||
|
$el("h2", "Select image target"),
|
||||||
|
$el(
|
||||||
|
"p",
|
||||||
|
"This workflow has multiple image loader nodes, you can rename a node to include 'input' in the title for it to be automatically selected, or select one below."
|
||||||
|
),
|
||||||
|
$el(
|
||||||
|
"section",
|
||||||
|
this.#options.map((opt) => {
|
||||||
|
return $el("div.comfy-widget-selection-item", [
|
||||||
|
$el("span", { dataset: { id: opt.node.id } }, `${opt.node.title ?? opt.node.type} ${opt.widget.name}`),
|
||||||
|
$el(
|
||||||
|
"button.comfyui-button",
|
||||||
|
{
|
||||||
|
onclick: () => {
|
||||||
|
app.canvas.ds.offset[0] = -opt.node.pos[0] + 50;
|
||||||
|
app.canvas.ds.offset[1] = -opt.node.pos[1] + 50;
|
||||||
|
app.canvas.selectNode(opt.node);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Show"
|
||||||
|
),
|
||||||
|
$el(
|
||||||
|
"button.comfyui-button.primary",
|
||||||
|
{
|
||||||
|
onclick: () => {
|
||||||
|
this.#resolve(opt);
|
||||||
|
this.close();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Select"
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
})
|
||||||
|
),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.#resolve = resolve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.#resolve();
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user