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;
};
}
});
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui_stringessentials"
description = "Simple string manipulation nodes for ComfyUI (strip/remove text strings, search and replace text strings, preview modified string outputs). Useful for modifying text prompts or results from LLM outputs. Nodes will be located under standard Add Node > utils menu. Node names: String Textbox, String Strip, String Multi Replace, String Conditional Append, String Contains Any and String Preview."
version = "2.0.8"
version = "2.0.9"
license = {file = "LICENSE"}
[project.urls]
+4
View File
@@ -5,6 +5,10 @@ class StringConditionalAppendNode:
def INPUT_TYPES(cls):
return {
"required": {
"input_string": ("STRING", {
"forceInput": True,
"tooltip": "The string to process"
}),
"strings_to_check": ("STRING", {
"multiline": True,
"default": "",
+4
View File
@@ -5,6 +5,10 @@ class StringMultiReplaceNode:
def INPUT_TYPES(cls):
return {
"required": {
"input_string": ("STRING", {
"forceInput": True,
"tooltip": "The string to process"
}),
"replacement_pairs": ("STRING", {"multiline": True, "default": "", "placeholder": "Enter replacement pairs (one per line)",
"tooltip": "Enter replacement pairs (one per line). Format: 'search<delimiter>replace'. Default delimiter is ':' (colon)"}),
"replacement_delimiter": ("STRING", {"default": "::",
+7 -2
View File
@@ -2,7 +2,12 @@ class StringPreviewNode:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {},
"required": {
"input_string": ("STRING", {
"forceInput": True,
"tooltip": "The string to preview"
}),
},
}
RETURN_TYPES = ("STRING",)
@@ -16,5 +21,5 @@ class StringPreviewNode:
# Force re-evaluation every time to ensure fresh data in PNG metadata
return float("nan")
def preview_string(self, input_string=""):
def preview_string(self, input_string):
return {"ui": {"text": (input_string,)}, "result": (input_string,)}
+4
View File
@@ -5,6 +5,10 @@ class StringStripNode:
def INPUT_TYPES(cls):
return {
"required": {
"input_string": ("STRING", {
"forceInput": True,
"tooltip": "The string to process"
}),
"strings_to_remove": ("STRING", {"multiline": True, "default": "", "placeholder": "Enter strings to remove (one per line)",
"tooltip": "Enter strings to remove (one per line). Can include multiple words or strings on one line like: 'This image is'. This will only match this entire string."}),
"match_case": ("BOOLEAN", {"default": False,