From b2941ff2e988d3a58640447b168d44248097eeae Mon Sep 17 00:00:00 2001 From: John Cantu Date: Tue, 30 Sep 2025 22:22:05 -0700 Subject: [PATCH] add context option to add notes from a node --- web/autonotes.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/web/autonotes.js b/web/autonotes.js index 8e0b348..03fb18e 100644 --- a/web/autonotes.js +++ b/web/autonotes.js @@ -4513,9 +4513,41 @@ class AutoNotesManager { } // Initialize the AutoNotes manager when the extension loads +let autoNotesManagerInstance = null; + app.registerExtension({ name: "AutoNotes", async setup() { - new AutoNotesManager(); + autoNotesManagerInstance = new AutoNotesManager(); }, + async beforeRegisterNodeDef(nodeType, nodeData, app) { + const getExtraMenuOptions = nodeType.prototype.getExtraMenuOptions; + nodeType.prototype.getExtraMenuOptions = function (_, options) { + const menuOptions = getExtraMenuOptions?.apply(this, arguments); + + options.unshift({ + content: "Create AutoNote for this node", + callback: async () => { + if (autoNotesManagerInstance) { + // Set the selected node type to this node's type + autoNotesManagerInstance.selectedNodeType = this.type; + + // Collect node attributes + const nodeAttributes = {}; + if (this.widgets) { + for (const widget of this.widgets) { + nodeAttributes[widget.name] = widget.value; + } + } + autoNotesManagerInstance.selectedNodeAttributes = nodeAttributes; + + // Call the add note from current node function + await autoNotesManagerInstance.addNoteFromCurrentNode(); + } + } + }); + + return menuOptions; + }; + } }); \ No newline at end of file