diff --git a/js/stringFunction.js b/js/stringFunction.js new file mode 100644 index 0000000..2b15caf --- /dev/null +++ b/js/stringFunction.js @@ -0,0 +1,33 @@ +import { app } from "/scripts/app.js"; +import { ComfyWidgets } from "/scripts/widgets.js"; + +// Displays input text on a node + +app.registerExtension({ + name: "pysssss.StringFunction", + async beforeRegisterNodeDef(nodeType, nodeData, app) { + if (nodeData.name === "StringFunction|pysssss") { + const onExecuted = nodeType.prototype.onExecuted; + nodeType.prototype.onExecuted = function (message) { + onExecuted?.apply(this, arguments); + + if (this.widgets) { + const pos = this.widgets.findIndex((w) => w.name === "result"); + if (pos !== -1) { + for (let i = pos; i < this.widgets.length; i++) { + this.widgets[i].onRemove?.(); + } + this.widgets.length = pos; + } + } + + const w = ComfyWidgets["STRING"](this, "result", ["STRING", { multiline: true }], app).widget; + w.inputEl.readOnly = true; + w.inputEl.style.opacity = 0.6; + w.value = message.text; + + this.onResize?.(this.size); + }; + } + }, +}); diff --git a/py/string_function.py b/py/string_function.py index cc05f66..a98929b 100644 --- a/py/string_function.py +++ b/py/string_function.py @@ -34,7 +34,7 @@ class StringFunction: out = text_a.replace(text_b, text_c) if tidy_tags: out = out.replace(" ", " ").replace(" ,", ",").replace(",,", ",").replace(",,", ",") - return (out, ) + return {"ui": {"text": (out,)}, "result": (out,)} NODE_CLASS_MAPPINGS = { "StringFunction|pysssss": StringFunction,