Add clear-all references button on o1key image generator

This commit is contained in:
Jony
2026-11-09 10:14:04 +08:00
parent a181cc1768
commit f72d0a5c56
2 changed files with 151 additions and 7 deletions
+91 -4
View File
@@ -337,6 +337,10 @@ const renderReferenceRole = vm.runInContext("renderReferenceRole", context);
const editReference = vm.runInContext("editReference", context);
const replaceReference = vm.runInContext("replaceReference", context);
const updateBatchReferenceHint = vm.runInContext("updateBatchReferenceHint", context);
const clearAllReferences = vm.runInContext("clearAllReferences", context);
const syncClearReferenceButtons = vm.runInContext("syncClearReferenceButtons", context);
const referenceListsAreEmpty = vm.runInContext("referenceListsAreEmpty", context);
const setWidgetValue = vm.runInContext("setWidgetValue", context);
const updateBatchSummary = vm.runInContext("updateBatchSummary", context);
const initializeSaveSlots = vm.runInContext("initializeSaveSlots", context);
const updateSaveSlotsForState = vm.runInContext("updateSaveSlotsForState", context);
@@ -495,14 +499,25 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) {
assert.equal(node._o1igModelAdd, undefined);
const referenceActions = node._o1igReferenceHeader.children.at(-1);
assert.equal(referenceActions.className, "o1ig-asset-actions");
assert.equal(referenceActions.children.length, 1, "画布取图 is the only header action");
assert.equal(referenceActions.children[0], node._o1igCanvasPick);
assert.equal(referenceActions.children.length, 2, "清空参考图 + 画布取图");
assert.equal(referenceActions.children[0], node._o1igClearReferences);
assert.equal(referenceActions.children[1], node._o1igCanvasPick);
assert.equal(node._o1igClearReferences.className, "o1ig-clear-refs");
assert.equal(node._o1igClearReferences.children[0].textContent, "清空参考图");
assert.equal(node._o1igClearReferences.disabled, true, "Empty lists disable clear");
assert.ok(node._o1igReferenceInput, "The hidden picker input lives beside the track");
assert.ok(node._o1igReferenceHeader.contains(node._o1igCanvasPick));
assert.ok(node._o1igReferenceHeader.contains(node._o1igClearReferences));
assert.equal(node._o1igRefs.children[0].className, "o1ig-empty-reference");
node._o1igBatchToggle.dispatch("click");
assert.equal(node._o1igBatchEnabled, true);
assert.equal(node._o1igModelAssets.classList.contains("visible"), true);
const modelActions = [...node._o1igModelAssets.children[0].children].at(-1);
assert.equal(modelActions.className, "o1ig-asset-actions");
assert.equal(modelActions.children[0], node._o1igClearModelReferences);
assert.equal(modelActions.children[1], node._o1igModelCanvasPick);
assert.equal(node._o1igClearModelReferences.children[0].textContent, "清空");
assert.equal(node._o1igClearModelReferences.disabled, true);
node._o1igBatchToggle.dispatch("click");
assert.equal(node._o1igBatchEnabled, false);
const promptWidget = widgets.find(widget => widget.name === "prompt");
@@ -3103,6 +3118,75 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) {
document._querySelector = null;
}
{
const names = [
"prompt", "模型", "模型线路", "思考等级", "分辨率", "宽高比", "生图数量", "seed",
"参考图清单", "质量", "输出格式", "蒙版清单", "缩放图片", "背景", "批量出图",
"批量模式", "模特图清单", "命名规则", "filename_prefix", "格式", "保存位置", "图层拆分", "复杂度", "帧数", "帧时长ms",
];
const values = [
"clear refs", "Nano Banana 2.1", "专线", "高", "2K", "1:1", "1", 1,
"[]", "自动", "jpeg", "{}", "不缩放", "auto", false,
"整组素材→多个目标", "[]", "自定义前缀", "clear-prefix", "原始", "", false, "中", 9, 200,
];
const widgets = names.map((name, index) => ({ name, value: values[index], options: {} }));
const clearNode = {
comfyClass: "O1keyImageGenerator", widgets, size: [560, 1035], outputs: [],
addDOMWidget(name, type, element, options) {
const widget = { name, type, element, options }; this.widgets.push(widget); return widget;
},
computeSize() { return [500, 1025]; },
setSize(size) { this.size = size; },
setDirtyCanvas() {},
};
buildPanel(clearNode);
assert.equal(referenceListsAreEmpty(clearNode), true);
assert.equal(clearAllReferences(clearNode), false, "No-op when already empty");
assert.equal(clearNode._o1igClearReferences.disabled, true);
clearNode._o1igReferences = [
{ name: "a.png", subfolder: "", type: "input" },
{ name: "b.png", subfolder: "", type: "input" },
];
clearNode._o1igMask = { name: "mask.png", subfolder: "", type: "input" };
setWidgetValue(clearNode, "参考图清单", JSON.stringify(clearNode._o1igReferences));
setWidgetValue(clearNode, "蒙版清单", JSON.stringify(clearNode._o1igMask));
syncClearReferenceButtons(clearNode);
assert.equal(clearNode._o1igClearReferences.disabled, false);
assert.equal(clearAllReferences(clearNode), true);
assert.deepEqual(JSON.parse(JSON.stringify(clearNode._o1igReferences)), []);
assert.deepEqual(JSON.parse(JSON.stringify(clearNode._o1igModelReferences)), []);
assert.equal(widgets.find((widget) => widget.name === "参考图清单").value, "[]");
assert.equal(widgets.find((widget) => widget.name === "模特图清单").value, "[]");
assert.deepEqual(
JSON.parse(JSON.stringify(clearNode._o1igMask)),
{ name: "mask.png", subfolder: "", type: "input" },
"Clearing references leaves the independent mask alone",
);
assert.equal(clearNode._o1igClearReferences.disabled, true);
clearNode._o1igBatchEnabled = true;
clearNode._o1igReferences = [{ name: "outfit.png", subfolder: "", type: "input" }];
clearNode._o1igModelReferences = [
{ name: "model-a.png", subfolder: "", type: "input" },
{ name: "model-b.png", subfolder: "", type: "input" },
];
setWidgetValue(clearNode, "参考图清单", JSON.stringify(clearNode._o1igReferences));
setWidgetValue(clearNode, "模特图清单", JSON.stringify(clearNode._o1igModelReferences));
syncClearReferenceButtons(clearNode);
assert.equal(clearNode._o1igClearReferences.disabled, false);
assert.equal(clearNode._o1igClearModelReferences.disabled, false);
clearNode._o1igClearModelReferences.dispatch("click");
assert.deepEqual(JSON.parse(JSON.stringify(clearNode._o1igReferences)), []);
assert.deepEqual(JSON.parse(JSON.stringify(clearNode._o1igModelReferences)), []);
assert.equal(widgets.find((widget) => widget.name === "参考图清单").value, "[]");
assert.equal(widgets.find((widget) => widget.name === "模特图清单").value, "[]");
assert.equal(clearNode._o1igClearReferences.disabled, true);
assert.equal(clearNode._o1igClearModelReferences.disabled, true);
}
{
const sourceNode = {
id: 900,
@@ -3188,8 +3272,11 @@ assert.doesNotMatch(source, /app\.queuePrompt\(0, 1, \[saveNode\.id\]\)/);
assert.match(source, /\.o1ig-refs\{[\s\S]*?flex:0 0 109px[\s\S]*?min-height:109px/);
assert.match(source, /\.o1ig-thumb\{[\s\S]*?flex:0 0 102px;height:102px/);
assert.match(source, /\.o1ig-thumb img\{[\s\S]*?object-fit:contain;background:var\(--o1ig-surface\)/);
assert.match(source, /referenceActions\.append\(canvasPick\)/);
assert.match(source, /modelActions\.append\(modelCanvasPick\)/);
assert.match(source, /referenceActions\.append\(clearReferences, canvasPick\)/);
assert.match(source, /modelActions\.append\(clearModelReferences, modelCanvasPick\)/);
assert.match(source, /function clearAllReferences\(node\)/);
assert.match(source, /textContent = "清空参考图"/);
assert.match(source, /\.o1ig-clear-refs\{/);
assert.doesNotMatch(source, /o1ig-add[\s\S]{0,400}?addLabel\.textContent = "上传"/, "头部不再有上传按钮");
assert.match(source, /upload\.addEventListener\("click", \(\) => requestReferenceUpload\(node, role\)\)/);
assert.match(source, /window\.o1keyCanvasImagePicker = Object\.freeze/);
+60 -3
View File
@@ -303,6 +303,9 @@ const CSS = `
.o1ig-add{position:relative;display:flex;flex:0 0 auto;height:28px;box-sizing:border-box;align-items:center;justify-content:center;gap:5px;padding:0 9px;border-radius:var(--o1ig-radius);cursor:pointer;}
.o1ig-add b{font-size:15px;line-height:1;font-weight:400;}.o1ig-add span{font-size:11px;}
.o1ig-canvas-pick b{font-size:13px;line-height:1;}
.o1ig-clear-refs{position:relative;display:flex;flex:0 0 auto;height:28px;box-sizing:border-box;align-items:center;justify-content:center;gap:5px;padding:0 9px;border-radius:var(--o1ig-radius);cursor:pointer;}
.o1ig-clear-refs span{font-size:11px;}
.o1ig-panel .o1ig-clear-refs:disabled,.o1ig-panel .o1ig-clear-refs:disabled:hover{cursor:default;opacity:.45;}
.o1ig-thumb img{width:100%;height:100%;display:block;object-fit:contain;background:var(--o1ig-surface);}
.o1ig-thumb .o1ig-edit{position:absolute;top:5px;left:5px;z-index:2;width:25px;height:25px;padding:0;display:grid;place-items:center;border-radius:6px;cursor:pointer;font-size:15px;opacity:.84;}
.o1ig-thumb:hover .o1ig-edit,.o1ig-thumb .o1ig-edit:focus-visible{opacity:1;}
@@ -2293,6 +2296,42 @@ function renderReferences(node) {
renderReferenceRole(node, "models");
updateBatchSummary(node);
syncGptOutputOptions(node);
syncClearReferenceButtons(node);
}
function referenceListsAreEmpty(node) {
return !(
(node?._o1igReferences?.length || 0)
|| (node?._o1igPending?.length || 0)
|| (node?._o1igModelReferences?.length || 0)
|| (node?._o1igModelPending?.length || 0)
);
}
function syncClearReferenceButtons(node) {
const empty = referenceListsAreEmpty(node);
if (node?._o1igClearReferences) {
node._o1igClearReferences.disabled = empty;
node._o1igClearReferences.title = empty ? "暂无参考图可清空" : "清空全部参考图与目标图";
}
if (node?._o1igClearModelReferences) {
node._o1igClearModelReferences.disabled = empty;
node._o1igClearModelReferences.title = empty ? "暂无图片可清空" : "清空全部素材图与目标图";
}
}
/** Clear every reference image list the panel uses for generation (batch + non-batch). */
function clearAllReferences(node) {
if (!node || referenceListsAreEmpty(node)) return false;
node._o1igReferences = [];
node._o1igPending = [];
node._o1igModelReferences = [];
node._o1igModelPending = [];
// Follow single-tile remove: mask stays on its own control.
setWidgetValue(node, "参考图清单", "[]");
setWidgetValue(node, "模特图清单", "[]");
renderReferences(node);
return true;
}
async function acceptFiles(node, files, role = "references") {
@@ -4942,7 +4981,7 @@ function buildPanel(node) {
refs.addEventListener("wheel", (event) => event.stopPropagation());
bindImageFileDropTarget(node, refs);
// The trailing "+ 添加…" card is the only upload entry point; the header keeps
// just 画布取图, so the picker input lives beside the track instead of inside a button.
// 清空参考图 + 画布取图, so the picker input lives beside the track instead of inside a button.
const fileInput = createReferenceFileInput(node, "references");
const canvasPick = document.createElement("button");
canvasPick.type = "button";
@@ -4966,8 +5005,16 @@ function buildPanel(node) {
referenceMeta.className = "o1ig-asset-meta";
referenceMeta.append(referenceTitle, referenceHint);
const referenceActions = document.createElement("div");
const clearReferences = document.createElement("button");
clearReferences.type = "button";
clearReferences.className = "o1ig-clear-refs";
clearReferences.title = "清空全部参考图与目标图";
const clearReferencesLabel = document.createElement("span");
clearReferencesLabel.textContent = "清空参考图";
clearReferences.append(clearReferencesLabel);
clearReferences.addEventListener("click", () => clearAllReferences(node));
referenceActions.className = "o1ig-asset-actions";
referenceActions.append(canvasPick);
referenceActions.append(clearReferences, canvasPick);
referenceHeader.append(referenceMeta, referenceActions);
const referenceAssets = document.createElement("div");
referenceAssets.className = "o1ig-assets";
@@ -5010,8 +5057,16 @@ function buildPanel(node) {
modelMeta.className = "o1ig-asset-meta";
modelMeta.append(modelTitle, modelHint);
const modelActions = document.createElement("div");
const clearModelReferences = document.createElement("button");
clearModelReferences.type = "button";
clearModelReferences.className = "o1ig-clear-refs";
clearModelReferences.title = "清空全部素材图与目标图";
const clearModelReferencesLabel = document.createElement("span");
clearModelReferencesLabel.textContent = "清空";
clearModelReferences.append(clearModelReferencesLabel);
clearModelReferences.addEventListener("click", () => clearAllReferences(node));
modelActions.className = "o1ig-asset-actions";
modelActions.append(modelCanvasPick);
modelActions.append(clearModelReferences, modelCanvasPick);
modelHeader.append(modelMeta, modelActions);
const modelAssets = document.createElement("div");
modelAssets.className = "o1ig-assets o1ig-model-assets";
@@ -5272,12 +5327,14 @@ function buildPanel(node) {
_o1igReplaceInput: replaceInput,
_o1igReferenceInput: fileInput,
_o1igCanvasPick: canvasPick,
_o1igClearReferences: clearReferences,
_o1igReferenceHeader: referenceHeader,
_o1igReferenceTitle: referenceTitle,
_o1igReferenceHint: referenceHint,
_o1igModelRefs: modelRefs,
_o1igModelInput: modelFileInput,
_o1igModelCanvasPick: modelCanvasPick,
_o1igClearModelReferences: clearModelReferences,
_o1igModelAssets: modelAssets,
_o1igModelHint: modelHint,
_o1igBatchToggle: batchToggle,