Skip to content

Commit 45ae089

Browse files
author
BRADSEC
committed
fix: declare input_string in Python INPUT_TYPES for Nodes 2.0 compatibility (Issue #12)
1 parent 48508cc commit 45ae089

File tree

6 files changed

+83
-61
lines changed

6 files changed

+83
-61
lines changed

js/string_essentials.js

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,90 +2,95 @@ import { app } from "../../../scripts/app.js";
22
import { ComfyWidgets } from "../../../scripts/widgets.js";
33

44
// Consistent sizing for all String Essentials nodes
5-
const DEFAULT_NODE_SIZE = [400, 200];
5+
const DEFAULT_NODE_WIDTH = 400;
66

77
app.registerExtension({
88
name: "string.strip",
9-
async beforeRegisterNodeDef(nodeType) {
10-
if (nodeType.comfyClass === "StringStrip") {
11-
nodeType.prototype.onNodeCreated = function() {
12-
this.addInput("input_string", "STRING");
13-
this.setSize(DEFAULT_NODE_SIZE);
14-
};
15-
}
9+
async beforeRegisterNodeDef(nodeType, nodeData) {
10+
if (nodeData.name !== "StringStrip") return;
11+
12+
const onNodeCreated = nodeType.prototype.onNodeCreated;
13+
nodeType.prototype.onNodeCreated = function () {
14+
const result = onNodeCreated?.apply(this, arguments);
15+
if (this.size) this.size[0] = DEFAULT_NODE_WIDTH;
16+
return result;
17+
};
1618
}
1719
});
1820

1921
app.registerExtension({
2022
name: "string.multireplace",
21-
async beforeRegisterNodeDef(nodeType) {
22-
if (nodeType.comfyClass === "StringMultiReplace") {
23-
nodeType.prototype.onNodeCreated = function() {
24-
this.addInput("input_string", "STRING");
25-
this.setSize(DEFAULT_NODE_SIZE);
26-
};
27-
}
23+
async beforeRegisterNodeDef(nodeType, nodeData) {
24+
if (nodeData.name !== "StringMultiReplace") return;
25+
26+
const onNodeCreated = nodeType.prototype.onNodeCreated;
27+
nodeType.prototype.onNodeCreated = function () {
28+
const result = onNodeCreated?.apply(this, arguments);
29+
if (this.size) this.size[0] = DEFAULT_NODE_WIDTH;
30+
return result;
31+
};
2832
}
2933
});
3034

3135
app.registerExtension({
3236
name: "string.preview",
3337
async beforeRegisterNodeDef(nodeType, nodeData) {
34-
if (nodeType.comfyClass === "StringPreview") {
35-
nodeType.prototype.onNodeCreated = function() {
36-
this.addInput("input_string", "STRING");
37-
this.showValueWidget = ComfyWidgets["STRING"](this, "preview", ["STRING", { multiline: true }], app).widget;
38-
this.showValueWidget.inputEl.readOnly = true;
39-
this.showValueWidget.inputEl.style.opacity = 0.6;
40-
this.setSize(DEFAULT_NODE_SIZE);
41-
};
38+
if (nodeData.name !== "StringPreview") return;
4239

43-
const onExecuted = nodeType.prototype.onExecuted;
44-
nodeType.prototype.onExecuted = function(message) {
45-
onExecuted?.apply(this, arguments);
46-
if (message?.text?.[0] !== undefined) {
47-
this.showValueWidget.value = message.text[0];
48-
} else {
49-
// Clear preview if no text received
50-
this.showValueWidget.value = "";
51-
}
52-
};
40+
const onNodeCreated = nodeType.prototype.onNodeCreated;
41+
nodeType.prototype.onNodeCreated = function () {
42+
const result = onNodeCreated?.apply(this, arguments);
43+
this.showValueWidget = ComfyWidgets["STRING"](this, "preview", ["STRING", { multiline: true }], app).widget;
44+
this.showValueWidget.inputEl.readOnly = true;
45+
this.showValueWidget.inputEl.style.opacity = 0.6;
46+
if (this.size) this.size[0] = DEFAULT_NODE_WIDTH;
47+
return result;
48+
};
5349

54-
// Clear preview when input is disconnected
55-
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
56-
nodeType.prototype.onConnectionsChange = function(type, index, connected, link_info) {
57-
if (onConnectionsChange) {
58-
onConnectionsChange.apply(this, arguments);
59-
}
50+
const onExecuted = nodeType.prototype.onExecuted;
51+
nodeType.prototype.onExecuted = function (message) {
52+
onExecuted?.apply(this, arguments);
53+
if (message?.text?.[0] !== undefined) {
54+
this.showValueWidget.value = message.text[0];
55+
} else {
56+
this.showValueWidget.value = "";
57+
}
58+
};
6059

61-
// If input was disconnected, clear the preview
62-
if (type === 1 && !connected) { // type 1 = input
63-
this.showValueWidget.value = "";
64-
}
65-
};
66-
}
60+
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
61+
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
62+
onConnectionsChange?.apply(this, arguments);
63+
if (type === 1 && !connected) {
64+
this.showValueWidget.value = "";
65+
}
66+
};
6767
}
6868
});
6969

7070
app.registerExtension({
7171
name: "string.conditionalappend",
72-
async beforeRegisterNodeDef(nodeType) {
73-
if (nodeType.comfyClass === "StringConditionalAppend") {
74-
nodeType.prototype.onNodeCreated = function() {
75-
this.addInput("input_string", "STRING");
76-
this.setSize(DEFAULT_NODE_SIZE);
77-
};
78-
}
72+
async beforeRegisterNodeDef(nodeType, nodeData) {
73+
if (nodeData.name !== "StringConditionalAppend") return;
74+
75+
const onNodeCreated = nodeType.prototype.onNodeCreated;
76+
nodeType.prototype.onNodeCreated = function () {
77+
const result = onNodeCreated?.apply(this, arguments);
78+
if (this.size) this.size[0] = DEFAULT_NODE_WIDTH;
79+
return result;
80+
};
7981
}
8082
});
8183

8284
app.registerExtension({
8385
name: "string.textbox",
84-
async beforeRegisterNodeDef(nodeType) {
85-
if (nodeType.comfyClass === "StringTextbox") {
86-
nodeType.prototype.onNodeCreated = function() {
87-
this.setSize(DEFAULT_NODE_SIZE);
88-
};
89-
}
86+
async beforeRegisterNodeDef(nodeType, nodeData) {
87+
if (nodeData.name !== "StringTextbox") return;
88+
89+
const onNodeCreated = nodeType.prototype.onNodeCreated;
90+
nodeType.prototype.onNodeCreated = function () {
91+
const result = onNodeCreated?.apply(this, arguments);
92+
if (this.size) this.size[0] = DEFAULT_NODE_WIDTH;
93+
return result;
94+
};
9095
}
9196
});

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui_stringessentials"
33
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."
4-
version = "2.0.8"
4+
version = "2.0.9"
55
license = {file = "LICENSE"}
66

77
[project.urls]

string_conditional_append_node.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ class StringConditionalAppendNode:
55
def INPUT_TYPES(cls):
66
return {
77
"required": {
8+
"input_string": ("STRING", {
9+
"forceInput": True,
10+
"tooltip": "The string to process"
11+
}),
812
"strings_to_check": ("STRING", {
913
"multiline": True,
1014
"default": "",

string_multi_replace_node.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ class StringMultiReplaceNode:
55
def INPUT_TYPES(cls):
66
return {
77
"required": {
8+
"input_string": ("STRING", {
9+
"forceInput": True,
10+
"tooltip": "The string to process"
11+
}),
812
"replacement_pairs": ("STRING", {"multiline": True, "default": "", "placeholder": "Enter replacement pairs (one per line)",
913
"tooltip": "Enter replacement pairs (one per line). Format: 'search<delimiter>replace'. Default delimiter is ':' (colon)"}),
1014
"replacement_delimiter": ("STRING", {"default": "::",

string_preview_node.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ class StringPreviewNode:
22
@classmethod
33
def INPUT_TYPES(cls):
44
return {
5-
"required": {},
5+
"required": {
6+
"input_string": ("STRING", {
7+
"forceInput": True,
8+
"tooltip": "The string to preview"
9+
}),
10+
},
611
}
712

813
RETURN_TYPES = ("STRING",)
@@ -16,5 +21,5 @@ def IS_CHANGED(cls, **kwargs):
1621
# Force re-evaluation every time to ensure fresh data in PNG metadata
1722
return float("nan")
1823

19-
def preview_string(self, input_string=""):
24+
def preview_string(self, input_string):
2025
return {"ui": {"text": (input_string,)}, "result": (input_string,)}

string_strip_node.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ class StringStripNode:
55
def INPUT_TYPES(cls):
66
return {
77
"required": {
8+
"input_string": ("STRING", {
9+
"forceInput": True,
10+
"tooltip": "The string to process"
11+
}),
812
"strings_to_remove": ("STRING", {"multiline": True, "default": "", "placeholder": "Enter strings to remove (one per line)",
913
"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."}),
1014
"match_case": ("BOOLEAN", {"default": False,

0 commit comments

Comments
 (0)