Files
rubz 6f8ad8320b fix: complete Nodes 2.0 compatibility for custom widgets, bump to 1.1.1
Simplifies the preset-chip picker (Smart Resize / Smart Batch Resize)
to a single canvas implementation - drops the dual DOM-widget path,
so chips stay positioned correctly under "Longest side (px)" in both
classic and Nodes 2.0 rendering instead of jumping to the bottom of
the node.

Adds a shared setWidgetVisible() helper so dynamic show/hide (Counter
start, the hidden customtext output on every node) actually works
under Nodes 2.0's Vue reactivity - it previously only worked in
classic canvas mode.

Fixes two silent Nodes 2.0 rendering bugs: widgets only repaint via
their own triggerDraw(), not setDirtyCanvas(), so the active preset
chip and status-box text were going visually stale after an update
even though the underlying value was correct. And Nodes 2.0's
WidgetLegacy bridge permanently stamps a widget.width that classic
mode's own click hit-test then reads forever after - once a node had
ever rendered under Nodes 2.0, classic mode silently lost clicks on
the right side of a wide node. Both fixed by keeping widget state in
sync on every draw() instead of trusting it to survive across
renderer switches.

Also centers section-divider labels with flanking lines (was
label-left/line-right) and brightens the line color, which had
become nearly invisible under Nodes 2.0's extra canvas scaling.

README: reorders node sections into actual pipeline order (Prompt
Controller -> Profile Switch -> Resize -> Resolution Multiplier ->
Batch Resize, standalone tool last instead of mid-list), adds a
Nodes 2.0 compatibility screenshot, and refreshes the Smart Batch
Resize screenshot to match its current UI.
2026-08-13 20:45:33 +02:00

53 lines
2.1 KiB
JavaScript

import { app } from "../../scripts/app.js";
import { createStatusWidget } from "./shared/canvas_widgets.mjs?v=3";
import { setWidgetVisible } from "./shared/widget_visibility.mjs?v=2";
app.registerExtension({
name: "Craftopia.SmartPromptController",
async nodeCreated(node) {
if (node.comfyClass !== "SmartPromptController") return;
// Canvas-drawn result display — clearly an output, not an input field
const statusWidget = createStatusWidget("— RUN TO SEE RESULT —");
node.addCustomWidget(statusWidget);
// Override serialize so non-serializable JS widgets (the result display)
// are excluded from widgets_values in the saved workflow JSON. Without this,
// LiteGraph saves null slots for these widgets which then shift all Python
// widget values on load (configure runs before nodeCreated).
const origSerialize = node.serialize;
node.serialize = function () {
const data = origSerialize.call(this);
if (data.widgets_values) {
data.widgets_values = this.widgets
.filter(w => w.serialize !== false && w.options?.serialize !== false)
.map(w => w.value);
}
return data;
};
// Intercept onExecuted: update our widget, hide ComfyUI's default textarea
const origOnExecuted = node.onExecuted;
node.onExecuted = function (output) {
origOnExecuted?.call(this, output);
if (output?.text?.[0]) {
statusWidget._text = output.text[0];
// Hide the default customtext widget ComfyUI adds for ui.text
for (const w of node.widgets) {
if (w !== statusWidget && w.type === "customtext") {
setWidgetVisible(node, w, false);
}
}
// setDirtyCanvas alone doesn't repaint Nodes 2.0's canvas bridge —
// see the comment in preset_picker_widget.mjs.
statusWidget.triggerDraw?.();
}
node.setDirtyCanvas(true);
};
},
});