Add new PromptAddOrReplace node

This commit is contained in:
relhamdi
2026-06-15 10:44:17 +02:00
parent 902c1abd35
commit e378be6575
2 changed files with 108 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
from ..config import EMPTY_VALUE, NODE_CATEGORY
from ..utils import clean_prompt
class PromptAddOrReplace:
"""
Adds or replaces the input string with the selected option.
"""
CATEGORY = NODE_CATEGORY
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"join": ("STRING", {"default": ", "}),
"mode_toggle": (
"BOOLEAN",
{"default": True, "label_on": "Add", "label_off": "Replace"},
),
"options": ("STRING", {"multiline": True, "default": ""}),
"selected": ("STRING", {"default": ""}),
},
"optional": {
"input": ("STRING", {"forceInput": True}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "process"
def process(self, join, mode_toggle, options, selected, input=""):
v = selected.strip()
if v == EMPTY_VALUE:
v = ""
inp = input.strip() if input else ""
# If mode_toggle, mode = append, else replace
if mode_toggle:
if not v:
return (inp,)
if not inp:
return (v,)
return (clean_prompt(inp + join + v),)
else:
if not v:
return ("",)
return (v,)
NODE_CLASS_MAPPINGS = {
"PromptAddOrReplace": PromptAddOrReplace,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"PromptAddOrReplace": "Prompt Add or Replace",
}
+50
View File
@@ -0,0 +1,50 @@
import { COLORS } from "./constants.js";
import { attachInlineSelector } from "./inline_selector.js";
import {
drawGroupBorder,
findWidget,
hideWidget,
registerNode,
waitForWidget,
} from "./utils.js";
// --- Constants ---
const NODE_NAME = "PromptAddOrReplace";
// --- Attach ---
const attachAddOrReplace = (node) => {
const optionsWidget = findWidget(node, "options");
const selectedWidget = findWidget(node, "selected");
const modeToggleWidget = findWidget(node, "mode_toggle");
if (!optionsWidget || !selectedWidget || !modeToggleWidget) return;
hideWidget(selectedWidget);
// Inline selector
attachInlineSelector(node, optionsWidget, selectedWidget, {
placeholder: "options",
});
// Border around toggle
const original = node.onDrawForeground;
node.onDrawForeground = function (ctx) {
if (original) original.call(this, ctx);
drawGroupBorder(
ctx,
node,
"mode_toggle",
"mode_toggle",
COLORS.toggle_on,
COLORS.toggle_off,
);
};
};
// --- Registration ---
registerNode(NODE_NAME, (node) =>
waitForWidget(node, "options", attachAddOrReplace),
);