currentPath = j.path; editor.setValue(j.content || ''); const ext = path.split('.').pop().toLowerCase(); const langMap = { php:'php', js:'javascript', json:'json', css:'css', html:'html', sql:'sql', md:'markdown', yml:'yaml', yaml:'yaml', txt:'plaintext', log:'plaintext' }; monaco.editor.setModelLanguage(editor.getModel(), langMap[ext] || 'plaintext'); } async function saveFile(){ if(!currentPath){ alert('abre un archivo'); return; } const r = await fetch('/panel/editor/save.php', { method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({ path:currentPath, content:editor.getValue() }) }); const j = await r.json(); if(j.ok){ alert('guardado OK\nbackup: ' + j.backup); } else { alert(j.error || 'save error'); } } async function validateFile(){ if(!currentPath){ alert('abre un archivo'); return; } const r = await fetch('/panel/editor/validate.php?path=' + encodeURIComponent(currentPath)); const j = await r.json(); alert(j.output || 'OK'); }