Add PreviewToLoad node for bridging preview images to LoadImage nodes

Previews an image (like PreviewImage) and saves a copy to input/ so a
LoadImage node can reference it.  JS extension adds a target-node-ID
widget and "Send to Load Image" button that updates the target's combo.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 11:49:13 +01:00
parent 1e3e30d8f1
commit b5b4a26f6d
3 changed files with 185 additions and 2 deletions

68
web/image_preview.js Normal file
View File

@@ -0,0 +1,68 @@
import { app } from "../../scripts/app.js";
app.registerExtension({
name: "jdl.preview.to.load",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name !== "JDL_PreviewToLoad") return;
const origOnNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
origOnNodeCreated?.apply(this, arguments);
this.addWidget("number", "load_image_node_id", 0, (v) => {}, {
min: 0,
max: 99999,
step: 10,
precision: 0,
});
this.addWidget("button", "Send to Load Image", null, () => {
const nodeIdWidget = this.widgets?.find(w => w.name === "load_image_node_id");
if (!nodeIdWidget) return;
const targetId = Math.round(nodeIdWidget.value);
const targetNode = app.graph.getNodeById(targetId);
if (!targetNode) {
console.warn("[PreviewToLoad] No node found with ID:", targetId);
return;
}
const filename = this.last_input_filename;
if (!filename) {
console.warn("[PreviewToLoad] No filename available. Run the workflow first.");
return;
}
const imageWidget = targetNode.widgets?.find(w => w.name === "image");
if (!imageWidget) {
console.warn("[PreviewToLoad] Target node has no 'image' widget.");
return;
}
// Add filename to combo options if not already present
if (imageWidget.options?.values && !imageWidget.options.values.includes(filename)) {
imageWidget.options.values.push(filename);
}
imageWidget.value = filename;
if (imageWidget.callback) {
imageWidget.callback(filename);
}
app.graph.setDirtyCanvas(true, true);
});
this.setSize(this.computeSize());
};
const origOnExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function (output) {
origOnExecuted?.apply(this, arguments);
if (output?.input_filename?.length) {
this.last_input_filename = output.input_filename[0];
}
};
},
});