From 0ad5b7dc0dd1b348d6900c54ee91878ea9648fc6 Mon Sep 17 00:00:00 2001 From: ZDDC Date: Sat, 9 May 2026 18:39:10 -0500 Subject: [PATCH] refactor(mdedit): drop window.* TOC globals, call functions directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mdedit's toc.js exported updateToc / clearActiveTocItem / setActiveTocItem as window.* globals, which was the only remaining violation of the two-globals discipline (only window.app and window.zddc are intended). Other tools either use IIFE + window.app.modules.X, or — like mdedit — declare top-level functions that are reachable across concatenated files without going through window. Removed the three window.* exports and unqualified the four call sites in events.js, editor.js (×3), and file-system.js. setActiveTocItem was already called bare elsewhere; the change is just dropping a window.foo && check chain that's now unnecessary. No behavior change — TOC generation and click-to-scroll work as before. mdedit's three Playwright tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- mdedit/js/editor.js | 10 +++++----- mdedit/js/events.js | 2 +- mdedit/js/file-system.js | 4 ++-- mdedit/js/toc.js | 6 ++---- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/mdedit/js/editor.js b/mdedit/js/editor.js index d2b229a..a030ec6 100644 --- a/mdedit/js/editor.js +++ b/mdedit/js/editor.js @@ -217,9 +217,9 @@ function initializeEditor(content, isMarkdown = true, filePath = '', fileName = tocDepthSelector.addEventListener('change', function () { const depth = parseInt(this.value); - if (window.updateToc && editorInstance) { + if (editorInstance) { const currentContent = editorInstance.getMarkdown(); - window.updateToc(currentContent, tocContainer, editorInstance, depth); + updateToc(currentContent, tocContainer, editorInstance, depth); } }); } @@ -266,16 +266,16 @@ function initializeEditor(content, isMarkdown = true, filePath = '', fileName = } // Generate initial TOC - if (isMarkdown && window.updateToc && tocContainer) { + if (isMarkdown && tocContainer) { try { - window.updateToc(markdownBody, tocContainer, editorInstance, tocMaxDepth); + updateToc(markdownBody, tocContainer, editorInstance, tocMaxDepth); } catch (error) { console.error('Error generating TOC:', error); } const debouncedUpdateToc = debounce(() => { const currentContent = editorInstance.getMarkdown(); - window.updateToc(currentContent, tocContainer, editorInstance, tocMaxDepth); + updateToc(currentContent, tocContainer, editorInstance, tocMaxDepth); }, 300); editorInstance.on('change', () => { diff --git a/mdedit/js/events.js b/mdedit/js/events.js index 0112a19..92264dd 100644 --- a/mdedit/js/events.js +++ b/mdedit/js/events.js @@ -71,7 +71,7 @@ function setupTocDepthSelector() { const content = instance.editor.getMarkdown(); try { - window.updateToc(content, instance.tocContainer, instance.editor, tocMaxDepth); + updateToc(content, instance.tocContainer, instance.editor, tocMaxDepth); } catch (error) { console.error('Error updating TOC depth:', error); } diff --git a/mdedit/js/file-system.js b/mdedit/js/file-system.js index 8fcd575..810cb2c 100644 --- a/mdedit/js/file-system.js +++ b/mdedit/js/file-system.js @@ -471,9 +471,9 @@ async function reloadFileFromDisk(filePath) { } }, 100); - if (editorInstance.tocContainer && window.updateToc) { + if (editorInstance.tocContainer) { try { - window.updateToc(parsed.content, editorInstance.tocContainer, editorInstance.editor, tocMaxDepth); + updateToc(parsed.content, editorInstance.tocContainer, editorInstance.editor, tocMaxDepth); } catch (error) { console.error('Error updating TOC during reload:', error); } diff --git a/mdedit/js/toc.js b/mdedit/js/toc.js index 442ab6f..c2b77b3 100644 --- a/mdedit/js/toc.js +++ b/mdedit/js/toc.js @@ -250,7 +250,5 @@ function setActiveTocItem(tocContainer, headerText) { } } -// Export globally -window.updateToc = updateToc; -window.clearActiveTocItem = clearActiveTocItem; -window.setActiveTocItem = setActiveTocItem; +// Reachable at top-level scope to other concatenated mdedit JS files via the +// build's flat-IIFE-less module pattern; no window.* exports needed.