Fix chained RefMod prompt chips

This commit is contained in:
2026-10-20 15:49:02 +00:00
parent e45f69ecb8
commit 5d41800ffb
+32 -25
View File
@@ -46,36 +46,44 @@ function widgetValue(node, name) {
}
function refModDescriptorsForNode(node) {
const source = linkedNode(node, "ref_mods");
if (!source) return [];
const className = String(source.comfyClass || source.type || "");
const result = [];
const add = (name, copies = 1) => {
const count = Math.max(1, Math.min(32, Number(copies) || 1));
for (let index = 0; index < count; index += 1) {
result.push({ name: String(name || `RefMod ${result.length + 1}`), source });
result.push({ name: String(name || `RefMod ${result.length + 1}`) });
}
};
// The loader exposes the selected bundle rows as mod_1..mod_8 and copies.
if (className.includes("RefModsLoader")) {
for (let index = 1; index <= 8; index += 1) {
const name = widgetValue(source, `mod_${index}`);
const strength = Number(widgetValue(source, `strength_${index}`) ?? 1);
if (name && name !== "(none)" && strength > 0) add(name, widgetValue(source, `copies_${index}`));
const visited = new Set();
const visit = (source) => {
if (!source || visited.has(source.id)) return;
visited.add(source.id);
const className = String(source.comfyClass || source.type || "");
// H3RefModLoader appends its selected item after the incoming bundle,
// so recurse first to preserve the backend's @R ordering.
if (className.includes("H3RefModLoader")) {
visit(linkedNode(source, "mods"));
const name = widgetValue(source, "mod");
const weight = Number(widgetValue(source, "video_weight") ?? widgetValue(source, "weight") ?? 1);
if (name && name !== "(none)" && weight > 0) add(name, Math.ceil(weight));
return;
}
// The picker loader appends one selected RefMod to an existing bundle.
} else if (className.includes("H3RefModLoader")) {
const name = widgetValue(source, "mod");
const weight = Number(widgetValue(source, "video_weight") ?? widgetValue(source, "weight") ?? 1);
if (name && name !== "(none)" && weight > 0) add(name, Math.ceil(weight));
} else if (className.includes("RefModExtract") || className.includes("RefModCreate")) {
add(widgetValue(source, "name") || "Created RefMod");
} else {
// A bundle can also come from a custom/bridge node whose contents are
// only known when the graph executes. Keep the UI usable and reserve
// one slot rather than hiding the connection completely.
// The loader exposes selected bundle rows as mod_1..mod_8 and copies.
if (className.includes("RefModsLoader")) {
for (let index = 1; index <= 8; index += 1) {
const name = widgetValue(source, `mod_${index}`);
const strength = Number(widgetValue(source, `strength_${index}`) ?? 1);
if (name && name !== "(none)" && strength > 0) add(name, widgetValue(source, `copies_${index}`));
}
return;
}
if (className.includes("RefModExtract") || className.includes("RefModCreate")) {
add(widgetValue(source, "name") || "Created RefMod");
return;
}
// A custom bundle node's contents are only known after execution.
add("Attached RefMod");
}
};
visit(linkedNode(node, "ref_mods"));
return result;
}
@@ -523,12 +531,11 @@ function configure(node) {
button.onclick = (event) => { event.preventDefault(); event.stopPropagation(); insertReferenceToken(slot); };
referenceRow.append(button);
});
if (refModsConnected) {
if (refModsConnected && !refModDescriptors.length) {
const status = el("div"); status.title = "RefMods are connected to the prompt builder and are assigned after image reference slots.";
status.style.cssText = "display:inline-flex;align-items:center;gap:7px;height:31px;padding:2px 11px 2px 5px;border:2px solid #b78cff;border-radius:18px;background:#2a2138;color:#d9c2ff;font:13px monospace;white-space:nowrap";
const icon = el("span", "R"); icon.style.cssText = "display:grid;place-items:center;width:25px;height:25px;border-radius:50%;background:#7952a8;color:#fff;font-weight:bold;font-size:12px";
const endSlot = firstRefModSlot + Math.max(1, refModDescriptors.length);
status.append(icon, el("span", `RefMods → @R${firstRefModSlot + 1}${endSlot === firstRefModSlot + 1 ? "" : `–@R${endSlot}`}`)); referenceRow.append(status);
status.append(icon, el("span", `RefMods → @R${firstRefModSlot + 1}`)); referenceRow.append(status);
}
if (!connectedReferences.length && !refModsConnected) {
const empty = el("span", "Connect image references or RefMods to populate this row."); empty.style.cssText = "color:#77817a;font:11px Arial;padding:3px 2px"; referenceRow.append(empty);