refactor(mdedit): drop window.* TOC globals, call functions directly
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) <noreply@anthropic.com>
This commit is contained in:
parent
b7df50f458
commit
0ad5b7dc0d
4 changed files with 10 additions and 12 deletions
|
|
@ -217,9 +217,9 @@ function initializeEditor(content, isMarkdown = true, filePath = '', fileName =
|
||||||
|
|
||||||
tocDepthSelector.addEventListener('change', function () {
|
tocDepthSelector.addEventListener('change', function () {
|
||||||
const depth = parseInt(this.value);
|
const depth = parseInt(this.value);
|
||||||
if (window.updateToc && editorInstance) {
|
if (editorInstance) {
|
||||||
const currentContent = editorInstance.getMarkdown();
|
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
|
// Generate initial TOC
|
||||||
if (isMarkdown && window.updateToc && tocContainer) {
|
if (isMarkdown && tocContainer) {
|
||||||
try {
|
try {
|
||||||
window.updateToc(markdownBody, tocContainer, editorInstance, tocMaxDepth);
|
updateToc(markdownBody, tocContainer, editorInstance, tocMaxDepth);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error generating TOC:', error);
|
console.error('Error generating TOC:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const debouncedUpdateToc = debounce(() => {
|
const debouncedUpdateToc = debounce(() => {
|
||||||
const currentContent = editorInstance.getMarkdown();
|
const currentContent = editorInstance.getMarkdown();
|
||||||
window.updateToc(currentContent, tocContainer, editorInstance, tocMaxDepth);
|
updateToc(currentContent, tocContainer, editorInstance, tocMaxDepth);
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
editorInstance.on('change', () => {
|
editorInstance.on('change', () => {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ function setupTocDepthSelector() {
|
||||||
const content = instance.editor.getMarkdown();
|
const content = instance.editor.getMarkdown();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
window.updateToc(content, instance.tocContainer, instance.editor, tocMaxDepth);
|
updateToc(content, instance.tocContainer, instance.editor, tocMaxDepth);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating TOC depth:', error);
|
console.error('Error updating TOC depth:', error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -471,9 +471,9 @@ async function reloadFileFromDisk(filePath) {
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
if (editorInstance.tocContainer && window.updateToc) {
|
if (editorInstance.tocContainer) {
|
||||||
try {
|
try {
|
||||||
window.updateToc(parsed.content, editorInstance.tocContainer, editorInstance.editor, tocMaxDepth);
|
updateToc(parsed.content, editorInstance.tocContainer, editorInstance.editor, tocMaxDepth);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating TOC during reload:', error);
|
console.error('Error updating TOC during reload:', error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,5 @@ function setActiveTocItem(tocContainer, headerText) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export globally
|
// Reachable at top-level scope to other concatenated mdedit JS files via the
|
||||||
window.updateToc = updateToc;
|
// build's flat-IIFE-less module pattern; no window.* exports needed.
|
||||||
window.clearActiveTocItem = clearActiveTocItem;
|
|
||||||
window.setActiveTocItem = setActiveTocItem;
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue