fix(flowchart): expose pure modules as window globals for standalone window; v4.9.7

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
This commit is contained in:
2026-09-14 23:59:50 +05:30
parent 5f846d1e5f
commit 86d4c0d23a
8 changed files with 53 additions and 2 deletions
+6
View File
@@ -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 };
});
+6
View File
@@ -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 };
});
+6
View File
@@ -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,
+6
View File
@@ -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 };
});