Korjattu Monaco: window.monaco asetetaan eksplisiittisesti AMD-loaderin jälkeen
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) <noreply@anthropic.com>
This commit is contained in:
@@ -546,23 +546,40 @@ import AgentBar from "../components/AgentBar.astro";
|
|||||||
async function initMonaco() {
|
async function initMonaco() {
|
||||||
if (monacoLoaded) return;
|
if (monacoLoaded) return;
|
||||||
monacoLoaded = true;
|
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); });
|
await new Promise(r => {
|
||||||
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} });
|
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 = {};
|
window._editorModels = {};
|
||||||
const langMap = {py:'python',rs:'rust',js:'javascript',ts:'typescript',toml:'toml',json:'json',html:'html',css:'css',md:'markdown',txt:'plaintext'};
|
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');
|
switchTab('editor');
|
||||||
initMonaco().then(() => {
|
await initMonaco();
|
||||||
for (const [name,code] of Object.entries(files)) {
|
const m = window.monaco;
|
||||||
const ext = name.split('.').pop().toLowerCase();
|
if (!m) { console.error('Monaco ei latautunut'); return; }
|
||||||
if (window._editorModels[name]) window._editorModels[name].setValue(code);
|
for (const [name,code] of Object.entries(files)) {
|
||||||
else window._editorModels[name] = monaco.editor.createModel(code, langMap[ext]||'plaintext');
|
const ext = name.split('.').pop().toLowerCase();
|
||||||
}
|
if (window._editorModels[name]) window._editorModels[name].setValue(code);
|
||||||
document.getElementById('editor-file-list').innerHTML = Object.keys(files).map(n => `<div class="dd-item" onclick="openFile('${n}')">${n}</div>`).join('');
|
else window._editorModels[name] = m.editor.createModel(code, langMap[ext]||'plaintext');
|
||||||
document.getElementById('editor-tabs').innerHTML = Object.keys(files).map(n => `<div class="project-tab" onclick="openFile('${n}')">${n}</div>`).join('');
|
}
|
||||||
|
document.getElementById('editor-file-list').innerHTML = Object.keys(files).map(n => `<div class="dd-item" onclick="openFile('${n}')">${n}</div>`).join('');
|
||||||
|
document.getElementById('editor-tabs').innerHTML = Object.keys(files).map(n => `<div class="project-tab" onclick="openFile('${n}')">${n}</div>`).join('');
|
||||||
openFile(Object.keys(files)[0]);
|
openFile(Object.keys(files)[0]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user