From e19852a5090fb2e3cba65c939c5333c51fed7389 Mon Sep 17 00:00:00 2001 From: Jaakko Vanhala Date: Thu, 9 Apr 2026 21:16:20 +0300 Subject: [PATCH] =?UTF-8?q?Korjattu=20Monaco:=20window.monaco=20asetetaan?= =?UTF-8?q?=20eksplisiittisesti=20AMD-loaderin=20j=C3=A4lkeen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit openInEditor käyttää nyt async/await initMonacoa ja window.monaco-globaalia eikä oleta AMD-moduulin scopea. Korjaa "monaco is not defined" -virheen. Co-Authored-By: Claude Opus 4.6 (1M context) --- network-poc/frontend/src/pages/index.astro | 39 ++++++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/network-poc/frontend/src/pages/index.astro b/network-poc/frontend/src/pages/index.astro index cc3fd47..d483985 100644 --- a/network-poc/frontend/src/pages/index.astro +++ b/network-poc/frontend/src/pages/index.astro @@ -546,23 +546,40 @@ import AgentBar from "../components/AgentBar.astro"; async function initMonaco() { if (monacoLoaded) return; monacoLoaded = true; - await new Promise(r => { const s = document.createElement('script'); s.src = 'https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs/loader.js'; s.onload = () => { require.config({paths:{vs:'https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs'}}); require(['vs/editor/editor.main'],()=>r()); }; document.head.appendChild(s); }); - window._monaco = monaco.editor.create(document.getElementById('monaco-container'), { value: '// Valitse tiedosto tai generoi projekti\n', language: 'plaintext', theme: 'vs-dark', fontSize: 14, minimap:{enabled:false}, automaticLayout: true, padding:{top:10} }); + await new Promise(r => { + const s = document.createElement('script'); + s.src = 'https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs/loader.js'; + s.onload = () => { + require.config({ paths: { vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs' }}); + require(['vs/editor/editor.main'], () => { + window.monaco = monaco; // Varmistetaan globaali + r(); + }); + }; + document.head.appendChild(s); + }); + window._monaco = window.monaco.editor.create(document.getElementById('monaco-container'), { + value: '// Valitse tiedosto tai generoi projekti\n', + language: 'plaintext', theme: 'vs-dark', fontSize: 14, + minimap: { enabled: false }, automaticLayout: true, padding: { top: 10 } + }); } window._editorModels = {}; const langMap = {py:'python',rs:'rust',js:'javascript',ts:'typescript',toml:'toml',json:'json',html:'html',css:'css',md:'markdown',txt:'plaintext'}; - window.openInEditor = function(files) { + window.openInEditor = async function(files) { switchTab('editor'); - initMonaco().then(() => { - for (const [name,code] of Object.entries(files)) { - const ext = name.split('.').pop().toLowerCase(); - if (window._editorModels[name]) window._editorModels[name].setValue(code); - else window._editorModels[name] = monaco.editor.createModel(code, langMap[ext]||'plaintext'); - } - document.getElementById('editor-file-list').innerHTML = Object.keys(files).map(n => `
${n}
`).join(''); - document.getElementById('editor-tabs').innerHTML = Object.keys(files).map(n => `
${n}
`).join(''); + await initMonaco(); + const m = window.monaco; + if (!m) { console.error('Monaco ei latautunut'); return; } + for (const [name,code] of Object.entries(files)) { + const ext = name.split('.').pop().toLowerCase(); + if (window._editorModels[name]) window._editorModels[name].setValue(code); + else window._editorModels[name] = m.editor.createModel(code, langMap[ext]||'plaintext'); + } + document.getElementById('editor-file-list').innerHTML = Object.keys(files).map(n => `
${n}
`).join(''); + document.getElementById('editor-tabs').innerHTML = Object.keys(files).map(n => `
${n}
`).join(''); openFile(Object.keys(files)[0]); }); };