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/);