// Loads the Monaco editor (shipped inside the BlazorMonaco package) on first use, so only the // JSON editor page pays for it. BlazorMonaco normally expects three script tags in App.razor; // this loads the same three in the same order. let loading; function loadScript(src) { return new Promise((resolve, reject) => { const script = document.createElement('script'); script.src = src; script.onload = resolve; script.onerror = () => reject(new Error(`${src} could not be loaded`)); document.head.appendChild(script); }); } export function ensureLoaded() { loading ??= (async () => { // Sets the AMD path config (var require = ...) and window.blazorMonaco. await loadScript('_content/BlazorMonaco/jsInterop.js'); await loadScript('_content/BlazorMonaco/lib/monaco-editor/min/vs/loader.js'); await loadScript('_content/BlazorMonaco/lib/monaco-editor/min/vs/editor/editor.main.js'); // editor.main registers itself as an AMD module; wait until it (and window.monaco) is ready. await new Promise(resolve => window.require(['vs/editor/editor.main'], resolve)); })(); return loading; }