fix: declare input_string in Python INPUT_TYPES for Nodes 2.0 compatibility (Issue #12)

This commit is contained in:
BRADSEC
2026-03-09 16:29:12 +10:00
parent 48508cc6b5
commit 45ae089fdc
6 changed files with 83 additions and 61 deletions
+63 -58
View File
@@ -2,90 +2,95 @@ import { app } from "../../../scripts/app.js";
import { ComfyWidgets } from "../../../scripts/widgets.js";
// Consistent sizing for all String Essentials nodes
const DEFAULT_NODE_SIZE = [400, 200];
const DEFAULT_NODE_WIDTH = 400;
app.registerExtension({
name: "string.strip",
async beforeRegisterNodeDef(nodeType) {
if (nodeType.comfyClass === "StringStrip") {
nodeType.prototype.onNodeCreated = function() {
this.addInput("input_string", "STRING");
this.setSize(DEFAULT_NODE_SIZE);
};
}
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData.name !== "StringStrip") return;
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const result = onNodeCreated?.apply(this, arguments);
if (this.size) this.size[0] = DEFAULT_NODE_WIDTH;
return result;
};
}
});
app.registerExtension({
name: "string.multireplace",
async beforeRegisterNodeDef(nodeType) {
if (nodeType.comfyClass === "StringMultiReplace") {
nodeType.prototype.onNodeCreated = function() {
this.addInput("input_string", "STRING");
this.setSize(DEFAULT_NODE_SIZE);
};
}
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData.name !== "StringMultiReplace") return;
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const result = onNodeCreated?.apply(this, arguments);
if (this.size) this.size[0] = DEFAULT_NODE_WIDTH;
return result;
};
}
});
app.registerExtension({
name: "string.preview",
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeType.comfyClass === "StringPreview") {
nodeType.prototype.onNodeCreated = function() {
this.addInput("input_string", "STRING");
this.showValueWidget = ComfyWidgets["STRING"](this, "preview", ["STRING", { multiline: true }], app).widget;
this.showValueWidget.inputEl.readOnly = true;
this.showValueWidget.inputEl.style.opacity = 0.6;
this.setSize(DEFAULT_NODE_SIZE);
};
if (nodeData.name !== "StringPreview") return;
const onExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function(message) {
onExecuted?.apply(this, arguments);
if (message?.text?.[0] !== undefined) {
this.showValueWidget.value = message.text[0];
} else {
// Clear preview if no text received
this.showValueWidget.value = "";
}
};
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const result = onNodeCreated?.apply(this, arguments);
this.showValueWidget = ComfyWidgets["STRING"](this, "preview", ["STRING", { multiline: true }], app).widget;
this.showValueWidget.inputEl.readOnly = true;
this.showValueWidget.inputEl.style.opacity = 0.6;
if (this.size) this.size[0] = DEFAULT_NODE_WIDTH;
return result;
};
// Clear preview when input is disconnected
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
nodeType.prototype.onConnectionsChange = function(type, index, connected, link_info) {
if (onConnectionsChange) {
onConnectionsChange.apply(this, arguments);
}
const onExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function (message) {
onExecuted?.apply(this, arguments);
if (message?.text?.[0] !== undefined) {
this.showValueWidget.value = message.text[0];
} else {
this.showValueWidget.value = "";
}
};
// If input was disconnected, clear the preview
if (type === 1 && !connected) { // type 1 = input
this.showValueWidget.value = "";
}
};
}
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
onConnectionsChange?.apply(this, arguments);
if (type === 1 && !connected) {
this.showValueWidget.value = "";
}
};
}
});
app.registerExtension({
name: "string.conditionalappend",
async beforeRegisterNodeDef(nodeType) {
if (nodeType.comfyClass === "StringConditionalAppend") {
nodeType.prototype.onNodeCreated = function() {
this.addInput("input_string", "STRING");
this.setSize(DEFAULT_NODE_SIZE);
};
}
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData.name !== "StringConditionalAppend") return;
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const result = onNodeCreated?.apply(this, arguments);
if (this.size) this.size[0] = DEFAULT_NODE_WIDTH;
return result;
};
}
});
app.registerExtension({
name: "string.textbox",
async beforeRegisterNodeDef(nodeType) {
if (nodeType.comfyClass === "StringTextbox") {
nodeType.prototype.onNodeCreated = function() {
this.setSize(DEFAULT_NODE_SIZE);
};
}
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData.name !== "StringTextbox") return;
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const result = onNodeCreated?.apply(this, arguments);
if (this.size) this.size[0] = DEFAULT_NODE_WIDTH;
return result;
};
}
});