- Add js/shared/{nodes2,canvas_widgets,preset_picker_widget}.mjs: widgets
registered with type "button" get hijacked by ComfyUI's Vue widget
registry (Nodes 2.0), which renders a generic button showing the raw
internal widget name instead of calling our draw(). Dividers/status
boxes now use type "custom" via addCustomWidget, which correctly falls
through to the legacy-canvas bridge in both renderers. The interactive
preset-chip picker is dual-path: canvas+hit-testing in classic mode,
real <button> elements via addDOMWidget in Nodes 2.0 (mirrors how
ComfyUI-Pixaroma solved the same problem for its own widgets)
- Rewire smart_batch_resize.js, smart_resize.js, smart_profile_switch.js,
smart_prompt_controller.js to use the shared factories, removing the
duplicated divider/status/preset-chip code that existed across them
- Fix a save/reload regression found during verification: repositioning
the Nodes 2.0 preset-chip DOM widget into the middle of node.widgets
after configure() has run desyncs Vue's value-to-row binding for every
later widget (values appear shifted by one row, though the saved JSON
itself is correct). The DOM widget is no longer repositioned under
Nodes 2.0; classic mode is unaffected and keeps the original placement
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
import { app } from "../../scripts/app.js";
|
|
import { createStatusWidget } from "./shared/canvas_widgets.mjs";
|
|
|
|
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];
|
|
|
|
// Collapse the default customtext widget ComfyUI adds for ui.text
|
|
for (const w of node.widgets) {
|
|
if (w !== statusWidget && w.type === "customtext") {
|
|
w.computeSize = () => [0, -4];
|
|
}
|
|
}
|
|
}
|
|
|
|
node.setDirtyCanvas(true);
|
|
};
|
|
},
|
|
});
|