From ad6cd76b08ec98c3f7e6520f4c0baaab00875617 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Thu, 19 Mar 2026 11:36:29 +0100 Subject: [PATCH] feat: add ProjectSource JS extension with label title sync Co-Authored-By: Claude Opus 4.6 --- web/project_source.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 web/project_source.js diff --git a/web/project_source.js b/web/project_source.js new file mode 100644 index 0000000..9bb9a51 --- /dev/null +++ b/web/project_source.js @@ -0,0 +1,41 @@ +import { app } from "../../scripts/app.js"; + +app.registerExtension({ + name: "json.manager.project.source", + + async beforeRegisterNodeDef(nodeType, nodeData, app) { + if (nodeData.name !== "ProjectSource") return; + + const origOnNodeCreated = nodeType.prototype.onNodeCreated; + nodeType.prototype.onNodeCreated = function () { + origOnNodeCreated?.apply(this, arguments); + + // Update title when label changes + const labelWidget = this.widgets?.find(w => w.name === "label"); + if (labelWidget) { + const node = this; + const origCallback = labelWidget.callback; + labelWidget.callback = function (...args) { + origCallback?.apply(this, args); + node.title = labelWidget.value + ? `Source: ${labelWidget.value}` + : "Project Source"; + app.graph?.setDirtyCanvas(true, true); + }; + // Set initial title + if (labelWidget.value) { + this.title = `Source: ${labelWidget.value}`; + } + } + }; + + const origOnConfigure = nodeType.prototype.onConfigure; + nodeType.prototype.onConfigure = function (info) { + origOnConfigure?.apply(this, arguments); + const labelWidget = this.widgets?.find(w => w.name === "label"); + if (labelWidget?.value) { + this.title = `Source: ${labelWidget.value}`; + } + }; + }, +});