interactive

This commit is contained in:
Shaun Johnston
2025-12-16 09:27:48 +10:00
parent ff287b5cb4
commit abaf2a0bf7
3 changed files with 35 additions and 53 deletions
+4 -4
View File
@@ -7,7 +7,7 @@ A ComfyUI custom node package for creating and applying multiple find/replace pa
- **Find/Replace Pairs Node**: Create an arbitrary number of find/replace pairs
- Starts with one pair, click "➕ Add Pair" button to add more
- Right-click menu also provides Add/Remove pair options
- Each pair can be converted to an input connector (right-click widget → Convert to Input)
- All pairs are input connectors for easy connection from other nodes
- Outputs: pairs object, JSON, and CSV formats
- **Text Replacer Node**: Apply find/replace pairs to text
@@ -40,7 +40,7 @@ A ComfyUI custom node package for creating and applying multiple find/replace pa
### Connecting Dynamic Values
Right-click on any find or replace widget and select "Convert to Input" to create a connector that can receive values from other nodes.
All find/replace pairs are input connectors, making it easy to connect values from other nodes (e.g., text prompts, primitives, or other string outputs).
### Chaining Replacers
@@ -65,8 +65,8 @@ The Text Replacer node passes through the pairs object, allowing you to chain mu
| Input | Type | Description |
|-------|------|-------------|
| `find_N` | STRING | Find pattern for pair N |
| `replace_N` | STRING | Replacement for pair N |
| `find_N` | STRING (connector) | Find pattern for pair N |
| `replace_N` | STRING (connector) | Replacement for pair N |
**Buttons:**
- **➕ Add Pair** - Add a new find/replace pair
+28 -43
View File
@@ -43,32 +43,9 @@ app.registerExtension({
this.pairCount++;
const idx = this.pairCount;
// Insert new widgets before the buttons
const buttonIndex = this.widgets.indexOf(this.addPairButton);
// Create find widget
const findWidget = ComfyWidgets.STRING(
this,
`find_${idx}`,
["STRING", { default: "", multiline: false, placeholder: `Find pattern ${idx}` }],
app
).widget;
// Create replace widget
const replaceWidget = ComfyWidgets.STRING(
this,
`replace_${idx}`,
["STRING", { default: "", multiline: false, placeholder: `Replacement ${idx}` }],
app
).widget;
// Move the new widgets before the buttons
// Remove from end and insert at button position
this.widgets.splice(this.widgets.length - 2, 2); // Remove the 2 new widgets from end
this.widgets.splice(buttonIndex, 0, findWidget, replaceWidget);
// Re-add buttons at end
this.widgets.push(this.addPairButton, this.removePairButton);
// Add input connectors for find and replace
this.addInput(`find_${idx}`, "STRING");
this.addInput(`replace_${idx}`, "STRING");
this.updateRemoveButtonState();
this.setSize(this.computeSize());
@@ -83,16 +60,14 @@ app.registerExtension({
const findName = `find_${idx}`;
const replaceName = `replace_${idx}`;
// Find and remove the widgets
this.widgets = this.widgets.filter(w =>
w.name !== findName && w.name !== replaceName
);
// Remove inputs if they exist
if (this.inputs) {
this.inputs = this.inputs.filter(input =>
input.name !== findName && input.name !== replaceName
);
// Remove inputs
const findInputIdx = this.inputs?.findIndex(i => i.name === findName);
if (findInputIdx !== undefined && findInputIdx >= 0) {
this.removeInput(findInputIdx);
}
const replaceInputIdx = this.inputs?.findIndex(i => i.name === replaceName);
if (replaceInputIdx !== undefined && replaceInputIdx >= 0) {
this.removeInput(replaceInputIdx);
}
this.pairCount--;
@@ -179,14 +154,24 @@ app.registerExtension({
async nodeCreated(node) {
if (node.comfyClass === "FindReplacePairs") {
// Enable converting widgets to inputs (right-click -> Convert to Input)
if (node.widgets) {
for (const widget of node.widgets) {
if (widget.name?.startsWith("find_") || widget.name?.startsWith("replace_")) {
widget.convertToInput = true;
}
// First pair should also be input connectors - convert widgets to inputs
setTimeout(() => {
// Remove the default widgets for find_1 and replace_1
if (node.widgets) {
node.widgets = node.widgets.filter(w =>
w.name !== "find_1" && w.name !== "replace_1"
);
}
}
// Add as input connectors instead
if (!node.inputs?.find(i => i.name === "find_1")) {
node.addInput("find_1", "STRING");
}
if (!node.inputs?.find(i => i.name === "replace_1")) {
node.addInput("replace_1", "STRING");
}
node.setSize(node.computeSize());
app.graph.setDirtyCanvas(true, true);
}, 50);
}
}
});
+3 -6
View File
@@ -18,19 +18,16 @@ class FindReplacePairs:
def INPUT_TYPES(cls):
"""
Define base inputs. Additional pairs are added dynamically via JS.
All pairs are input connectors.
"""
return {
"required": {},
"optional": {
"find_1": ("STRING", {
"default": "",
"multiline": False,
"placeholder": "Find pattern 1"
"forceInput": True,
}),
"replace_1": ("STRING", {
"default": "",
"multiline": False,
"placeholder": "Replacement 1"
"forceInput": True,
}),
},
"hidden": {