Style reference chips with thumbnails
tests / test (push) Canceled after 0s
tests / windows-storage (push) Canceled after 0s

This commit is contained in:
2026-10-15 10:27:06 +00:00
parent 4661648cf5
commit d7fad73ec1
4 changed files with 32 additions and 12 deletions
+24 -6
View File
@@ -241,21 +241,39 @@ function configure(node) {
shotChips.append(chip);
});
panel.append(shotChips);
const referenceRow = el("div"); referenceRow.style.cssText = "display:flex;gap:4px;overflow:hidden;margin:4px 0 7px;align-items:center";
const referenceRow = el("div"); referenceRow.style.cssText = "display:flex;gap:8px;overflow:hidden;margin:7px 0 8px;align-items:center;flex-wrap:wrap";
const connectedReferences = Array.from({ length: 9 }, (_, offset) => offset + 1)
.filter((index) => node.inputs?.some((input) => input.name === `reference_image_${index}` && input.link != null));
if (connectedReferences.length) {
const referenceLabel = el("span", "Refs:"); referenceLabel.style.cssText = "color:#8fa898;font:10px monospace;margin-right:2px"; referenceRow.append(referenceLabel);
connectedReferences.forEach((index) => {
const button = el("button", `@R${index}`); button.type = "button";
button.title = `Insert reference image ${index} as @R${index}`;
button.style.cssText = "padding:3px 8px;border:1px solid #4f9bb0;border-radius:4px;background:#172d33;color:#8bd5e7;font:11px monospace;cursor:pointer";
const button = el("button"); button.type = "button";
button.title = `Insert reference image ${index} as @image${index}`;
button.style.cssText = "display:inline-flex;align-items:center;gap:7px;height:31px;padding:2px 11px 2px 3px;border:2px solid #49c9f5;border-radius:18px;background:#202b31;color:#70d8ff;font:16px monospace;cursor:pointer;white-space:nowrap";
const thumbnail = document.createElement("img");
thumbnail.alt = ""; thumbnail.draggable = false;
thumbnail.style.cssText = "width:25px;height:25px;object-fit:cover;border-radius:50%;background:#68727a;display:block";
const linkId = node.inputs?.find((input) => input.name === `reference_image_${index}`)?.link;
const link = linkId == null ? null : (app.graph?.links?.get?.(linkId) ?? app.graph?.links?.[linkId]);
const source = link?.origin_id == null ? null : app.graph?.getNodeById?.(link.origin_id);
const imageWidget = source?.widgets?.find((widget) => ["image", "filename", "file"].includes(widget.name));
const imageValue = imageWidget?.value;
if (imageValue && typeof imageValue === "object" && imageValue.filename) {
const params = new URLSearchParams({ filename: imageValue.filename, type: imageValue.type || "input", subfolder: imageValue.subfolder || "" });
thumbnail.src = `/view?${params.toString()}`;
} else if (typeof imageValue === "string" && imageValue) {
const params = new URLSearchParams({ filename: imageValue, type: "input", subfolder: "" });
thumbnail.src = `/view?${params.toString()}`;
} else {
thumbnail.src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='25' height='25' viewBox='0 0 25 25'%3E%3Crect width='25' height='25' fill='%2368727a'/%3E%3Cpath d='M4 19l5-6 3 3 3-4 6 7' fill='none' stroke='%23dce8ed' stroke-width='2'/%3E%3Ccircle cx='17' cy='8' r='2' fill='%23dce8ed'/%3E%3C/svg%3E";
}
thumbnail.onerror = () => { thumbnail.style.opacity = "0.35"; };
button.append(thumbnail, el("span", `@image${index}`));
button.onclick = (event) => {
event.preventDefault(); event.stopPropagation();
if (!prompt) return;
const start = prompt.selectionStart ?? prompt.value.length;
const end = prompt.selectionEnd ?? start;
const token = `@R${index} `;
const token = `@image${index} `;
prompt.value = prompt.value.slice(0, start) + token + prompt.value.slice(end);
const caret = start + token.length;
prompt.focus(); prompt.setSelectionRange(caret, caret);