From b9841d810a787256af8a1ba392b7a8501ac41dd8 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Mon, 28 Jul 2025 22:19:07 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20clear=20outputs=20con?= =?UTF-8?q?text=20menu=20for=20debug=20node?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/debug.js | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/web/debug.js b/web/debug.js index 2f6a355..6c384e6 100644 --- a/web/debug.js +++ b/web/debug.js @@ -80,6 +80,24 @@ app.registerExtension({ */ async beforeRegisterNodeDef(nodeType, nodeData, app) { if (nodeData.name === 'Debug (mtb)') { + const clear_widgets = (target) => { + if (target.widgets) { + let tgt_len = target.widgets.length + for (let i = 0; i < target.widgets.length; i++) { + if ( + !['output_to_console', 'as_detailed_types', 'rich_mode'].includes( + target.widgets[i].name, + ) + ) { + target.widgets[i].onRemove?.() + target.widgets[i].onRemoved?.() + tgt_len -= 1 + } + } + target.widgets.length = tgt_len + } + } + const onNodeCreated = nodeType.prototype.onNodeCreated nodeType.prototype.onNodeCreated = function (...args) { this.options = {} @@ -87,6 +105,17 @@ app.registerExtension({ this.addInput('anything_1', '*') return r } + const original_getExtraMenuOptions = + nodeType.prototype.getExtraMenuOptions + nodeType.prototype.getExtraMenuOptions = function (_, options) { + original_getExtraMenuOptions?.apply(this, arguments) + options.push({ + content: '🐛 Clear Outputs', + callback: async () => { + clear_widgets(this) + }, + }) + } const onConnectionsChange = nodeType.prototype.onConnectionsChange /** @@ -128,21 +157,7 @@ app.registerExtension({ onExecuted?.apply(this, args) const [data, ..._rest] = args - if (this.widgets) { - let tgt_len = this.widgets.length - for (let i = 0; i < this.widgets.length; i++) { - if ( - !['output_to_console', 'as_detailed_types', 'rich_mode'].includes( - this.widgets[i].name, - ) - ) { - this.widgets[i].onRemove?.() - this.widgets[i].onRemoved?.() - tgt_len -= 1 - } - } - this.widgets.length = tgt_len - } + clear_widgets(this) const inputData = {} @@ -183,7 +198,9 @@ app.registerExtension({ }) } - this.addDOMWidget(`debug_section_${widgetI}`, 'CUSTOM', section, {}) + this.addDOMWidget(`debug_section_${widgetI}`, 'CUSTOM', section, { + hideOnZoom: false, + }) widgetI++ }