mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-19 12:17:00 +08:00
Load image batch improvements
- Uses filter list behavior for LiteGraph context menu - "Replace" button - Can select from combo widget on node directly
This commit is contained in:
parent
d4e73878e2
commit
ec8678c45a
@ -453,14 +453,20 @@ async function loadImageAsync(imageURL) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const MULTIIMAGEUPLOAD = (node, inputName, inputData, app) => {
|
const MULTIIMAGEUPLOAD = (node, inputName, inputData, app) => {
|
||||||
const imagesWidget = node.addWidget("text", inputName, inputData, () => {})
|
let filepaths = { input: [], output: [] }
|
||||||
imagesWidget.disabled = true;
|
|
||||||
|
|
||||||
imagesWidget._filepaths = {}
|
|
||||||
if (inputData[1] && inputData[1].filepaths) {
|
if (inputData[1] && inputData[1].filepaths) {
|
||||||
imagesWidget._filepaths = inputData[1].filepaths
|
filepaths = inputData[1].filepaths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const update = function(v) {
|
||||||
|
this.value = v
|
||||||
|
}
|
||||||
|
|
||||||
|
const imagesWidget = node.addWidget("combo", inputName, inputData, update, { values: filepaths["input"] })
|
||||||
|
imagesWidget._filepaths = filepaths
|
||||||
|
imagesWidget._entries = filepaths["input"]
|
||||||
|
|
||||||
async function showImages(names) {
|
async function showImages(names) {
|
||||||
node.imgs = []
|
node.imgs = []
|
||||||
|
|
||||||
@ -616,10 +622,11 @@ const MULTIIMAGEUPLOAD = (node, inputName, inputData, app) => {
|
|||||||
<option value="output">Output</option>
|
<option value="output">Output</option>
|
||||||
<option value="input">Input</option>
|
<option value="input">Input</option>
|
||||||
</select>
|
</select>
|
||||||
<select class='image-path'></select>
|
<button class='image-path'><span class="image-path-text"></span></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="bar">
|
<div class="bar actions">
|
||||||
<button class="add-image">Add</button>
|
<button class="add-image">Add</button>
|
||||||
|
<button class="replace-image">Replace</button>
|
||||||
</div>`;
|
</div>`;
|
||||||
const previewElem = document.createElement("div");
|
const previewElem = document.createElement("div");
|
||||||
previewElem.innerHTML = previewHtml;
|
previewElem.innerHTML = previewHtml;
|
||||||
@ -628,46 +635,64 @@ const MULTIIMAGEUPLOAD = (node, inputName, inputData, app) => {
|
|||||||
|
|
||||||
const folderTypeSel = previewElem.querySelector('.folder-type');
|
const folderTypeSel = previewElem.querySelector('.folder-type');
|
||||||
const imagePathSel = previewElem.querySelector('.image-path');
|
const imagePathSel = previewElem.querySelector('.image-path');
|
||||||
|
const imagePathText = previewElem.querySelector('.image-path-text');
|
||||||
const imagePreview = previewElem.querySelector('.image-preview');
|
const imagePreview = previewElem.querySelector('.image-preview');
|
||||||
|
|
||||||
imagePathSel.addEventListener("change", (event) => {
|
folderTypeSel.addEventListener("change", (event) => {
|
||||||
const filename = event.target.value;
|
const filepaths = imagesWidget._filepaths[event.target.value];
|
||||||
const type = folderTypeSel.value;
|
imagesWidget._entries = filepaths
|
||||||
imagePreview.src = `/view?filename=${filename}&type=${type}`
|
imagePathText.innerHTML = filepaths[0];
|
||||||
|
imagePreview.src = `/view?filename=${filepaths[0]}&type=${event.target.value}`
|
||||||
});
|
});
|
||||||
|
|
||||||
folderTypeSel.addEventListener("change", (event) => {
|
imagePathSel.addEventListener("click", (event) => {
|
||||||
imagePathSel.innerHTML = "";
|
const type = folderTypeSel.value;
|
||||||
const filepaths = imagesWidget._filepaths[event.target.value];
|
const filepaths = imagesWidget._filepaths[folderTypeSel.value];
|
||||||
if (filepaths == null)
|
const entries = imagesWidget._entries
|
||||||
return;
|
|
||||||
|
|
||||||
for (const filepath of filepaths) {
|
const innerClicked = (v, _options, e, prev) => {
|
||||||
const filename = filepath.split('\\').pop().split('/').pop();
|
const filename = v;
|
||||||
const opt = document.createElement('option');
|
imagePathText.innerHTML = filename;
|
||||||
opt.value = filepath
|
imagePreview.src = `/view?filename=${filename}&type=${type}`
|
||||||
opt.innerHTML = filename
|
|
||||||
imagePathSel.appendChild(opt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imagePathSel.value = filepaths[0]
|
new LiteGraph.ContextMenu(entries, {
|
||||||
imagePathSel.dispatchEvent(new Event('change'));
|
event,
|
||||||
|
callback: innerClicked,
|
||||||
|
node,
|
||||||
|
className: "dark" // required for contextMenuFilter.js to kick in
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
folderTypeSel.value = "output";
|
folderTypeSel.value = "input";
|
||||||
folderTypeSel.dispatchEvent(new Event('change'));
|
folderTypeSel.dispatchEvent(new Event('change'));
|
||||||
|
|
||||||
const addButton = previewElem.querySelector('.add-image');
|
const addButton = previewElem.querySelector('.add-image');
|
||||||
addButton.addEventListener("click", async (event) => {
|
addButton.addEventListener("click", async (event) => {
|
||||||
const filename = imagePathSel.value;
|
const filename = imagePathText.innerHTML;
|
||||||
const type = folderTypeSel.value;
|
const type = folderTypeSel.value;
|
||||||
const value = `${filename} [${type}]`;
|
let value = filename;
|
||||||
|
if (type !== "input")
|
||||||
|
value += ` [${type}]`
|
||||||
imagesWidget._real_value.push(value)
|
imagesWidget._real_value.push(value)
|
||||||
imagesWidget.value = imagesWidget._real_value
|
imagesWidget.value = imagesWidget._real_value
|
||||||
await showImages(imagesWidget.value);
|
await showImages(imagesWidget.value);
|
||||||
inner_refresh();
|
inner_refresh();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const replaceButton = previewElem.querySelector('.replace-image');
|
||||||
|
replaceButton.addEventListener("click", async (event) => {
|
||||||
|
const filename = imagePathText.innerHTML;
|
||||||
|
const type = folderTypeSel.value;
|
||||||
|
let value = filename;
|
||||||
|
if (type !== "input")
|
||||||
|
value += ` [${type}]`
|
||||||
|
imagesWidget._real_value = [value]
|
||||||
|
imagesWidget.value = imagesWidget._real_value
|
||||||
|
await showImages(imagesWidget.value);
|
||||||
|
inner_refresh();
|
||||||
|
})
|
||||||
|
|
||||||
imagesWidget.panel.footer.style.display = "flex";
|
imagesWidget.panel.footer.style.display = "flex";
|
||||||
|
|
||||||
const clearButton = imagesWidget.panel.addButton("Clear", () => {
|
const clearButton = imagesWidget.panel.addButton("Clear", () => {
|
||||||
|
|||||||
@ -381,6 +381,15 @@ button.comfy-queue-btn {
|
|||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.litegraph .dialog.multiimageupload_dialog .image-path-text {
|
||||||
|
max-width: 250px;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
display: block;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
.litegraph .dialog select {
|
.litegraph .dialog select {
|
||||||
margin-right: 20px;
|
margin-right: 20px;
|
||||||
padding-left: 4px;
|
padding-left: 4px;
|
||||||
@ -471,6 +480,7 @@ button.comfy-queue-btn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.multiimageupload_dialog button {
|
.multiimageupload_dialog button {
|
||||||
|
height: 28px;
|
||||||
background-color: #1c1c1c;
|
background-color: #1c1c1c;
|
||||||
color: #aaa;
|
color: #aaa;
|
||||||
border: 0;
|
border: 0;
|
||||||
@ -479,6 +489,10 @@ button.comfy-queue-btn {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.multiimageupload_dialog .actions button {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.multiimageupload_dialog.extra {
|
.multiimageupload_dialog.extra {
|
||||||
color: #ccc;
|
color: #ccc;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user