From 86d4c0d23a42e83fc43a1878875417478c5e38d8 Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Mon, 14 Sep 2026 23:59:50 +0530 Subject: [PATCH] fix(flowchart): expose pure modules as window globals for standalone window; v4.9.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each pure module's UMD wrapper assigned window.FlowchartXxx only in the else branch — when 'module' was undefined. But the renderer runs with nodeIntegration:true, so 'module' is always truthy and the else branch never ran. The standalone Flowchart Generator window then aborted with 'Flowchart pure modules not loaded'. Fix: append 'if (typeof window !== undefined) window.FlowchartXxx = exported;' after the CommonJS branch in all 4 pure modules (store, shapes, mermaid, canvas). Both branches can run now; the legacy sidebar panel still loads them via require() and the renderer unconditionally exposes the global. Regression guard: 4 new source-grep tests in tests/flowchart-controller.test.js assert each module's source contains the 'window.FlowchartXxx = exported' assignment. Attribution: Amit Haridas --- README.md | 2 +- UPDATES.md | 7 +++++++ package.json | 2 +- src/flowchart/flowchart-canvas.js | 6 ++++++ src/flowchart/flowchart-mermaid.js | 6 ++++++ src/flowchart/flowchart-shapes.js | 6 ++++++ src/flowchart/flowchart-store.js | 6 ++++++ tests/flowchart-controller.test.js | 20 ++++++++++++++++++++ 8 files changed, 53 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66ce67e..2edabc1 100644 --- a/README.md +++ b/README.md @@ -257,4 +257,4 @@ Amit Haridas (amit.wh@gmail.com) ## Version -v4.9.6 +v4.9.7 diff --git a/UPDATES.md b/UPDATES.md index e0840a2..c7d5b46 100644 --- a/UPDATES.md +++ b/UPDATES.md @@ -1,5 +1,12 @@ # PanConverter - Updates & Changelog +## Version 4.9.7 (2026-09-14) + +### Fix +- **Standalone Flowchart Generator window now loads (was: 'modules not loaded' fatal error).** Each of the four pure modules (`flowchart-shapes.js`, `flowchart-mermaid.js`, `flowchart-store.js`, `flowchart-canvas.js`) ships with a UMD wrapper. The original wrapper assigned `window.FlowchartXxx` only in the `else` branch — i.e. when `module` was undefined. But the renderer runs with `nodeIntegration: true`, so `module` is always truthy in that environment and the `else` branch never ran, leaving `window.FlowchartShapes` / `window.FlowchartMermaid` / `window.FlowchartStore` / `window.FlowchartCanvas` undefined. The standalone window's controller (`src/renderer/flowchart-controller.js`) then aborted with `fatal('Flowchart pure modules not loaded — verify script tags in src/flowchart-generator.html')`. + - Fix: every pure module's UMD wrapper now has a second `if (typeof window !== 'undefined') { window.FlowchartXxx = exported; }` block appended AFTER the CommonJS branch. Both branches can run (the CommonJS branch keeps the legacy sidebar panel working under `require()`; the new branch unconditionally exposes the global in the renderer). The factory IIFE is unchanged, so the public surface of every module is identical to v4.9.6 — no behavioural change. + - New regression guard: 4 source-grep tests in `tests/flowchart-controller.test.js` assert each module's source file contains the `window.FlowchartXxx = exported` assignment so a future refactor can't silently drop the global again. + ## Version 4.9.6 (2026-09-14) ### Refactor diff --git a/package.json b/package.json index 3c42d1f..8808cf3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "markdown-converter", - "version": "4.9.6", + "version": "4.9.7", "description": "Professional Markdown editor and universal file converter with PDF editing, batch processing, and syntax highlighting", "main": "src/main.js", "scripts": { diff --git a/src/flowchart/flowchart-canvas.js b/src/flowchart/flowchart-canvas.js index 7944a0f..cd9bc83 100644 --- a/src/flowchart/flowchart-canvas.js +++ b/src/flowchart/flowchart-canvas.js @@ -337,6 +337,12 @@ function createCanvas(container, store, opts = {}) { } else { root.FlowchartCanvas = exported; } + // v4.9.7 — also expose as window global when running in Electron renderer + // (nodeIntegration:true makes `module` truthy so the else branch above never + // runs; the controller still expects window.FlowchartCanvas). + if (typeof window !== 'undefined') { + window.FlowchartCanvas = exported; + } })(typeof window !== 'undefined' ? window : globalThis, function () { return { createCanvas, SHAPE_KINDS }; }); diff --git a/src/flowchart/flowchart-mermaid.js b/src/flowchart/flowchart-mermaid.js index 928c856..aaeb4a6 100644 --- a/src/flowchart/flowchart-mermaid.js +++ b/src/flowchart/flowchart-mermaid.js @@ -100,6 +100,12 @@ function toMermaid(graph) { } else { root.FlowchartMermaid = exported; } + // v4.9.7 — also expose as window global when running in Electron renderer + // (nodeIntegration:true makes `module` truthy so the else branch above never + // runs; the controller still expects window.FlowchartMermaid). + if (typeof window !== 'undefined') { + window.FlowchartMermaid = exported; + } })(typeof window !== 'undefined' ? window : globalThis, function () { return { toMermaid, escapeLabel, nodeDeclaration, edgeDeclaration }; }); diff --git a/src/flowchart/flowchart-shapes.js b/src/flowchart/flowchart-shapes.js index ee48d37..bb40b91 100644 --- a/src/flowchart/flowchart-shapes.js +++ b/src/flowchart/flowchart-shapes.js @@ -69,6 +69,12 @@ function shapeSvg(kind, x, y, width, height) { } else { root.FlowchartShapes = exported; } + // v4.9.7 — also expose as window global when running in Electron renderer + // (nodeIntegration:true makes `module` truthy so the else branch above never + // runs; the controller still expects window.FlowchartShapes). + if (typeof window !== 'undefined') { + window.FlowchartShapes = exported; + } })(typeof window !== 'undefined' ? window : globalThis, function () { return { shapeSvg, diff --git a/src/flowchart/flowchart-store.js b/src/flowchart/flowchart-store.js index a74bbd5..665d8b1 100644 --- a/src/flowchart/flowchart-store.js +++ b/src/flowchart/flowchart-store.js @@ -268,6 +268,12 @@ function create(io) { } else { root.FlowchartStore = exported; } + // v4.9.7 — also expose as window global when running in Electron renderer + // (nodeIntegration:true makes `module` truthy so the else branch above never + // runs; the controller still expects window.FlowchartStore). + if (typeof window !== 'undefined') { + window.FlowchartStore = exported; + } })(typeof window !== 'undefined' ? window : globalThis, function () { return { create, NODE_KINDS, EDGE_KINDS }; }); diff --git a/tests/flowchart-controller.test.js b/tests/flowchart-controller.test.js index 3bf63cf..8e73296 100644 --- a/tests/flowchart-controller.test.js +++ b/tests/flowchart-controller.test.js @@ -214,3 +214,23 @@ describe('flowchart-controller: renderer.js sidebar registration is disabled', ( expect(liveMatch).toBeNull(); }); }); + +// v4.9.7 regression — pure modules MUST expose themselves as window globals +// so the standalone Flowchart Generator window can load them via