39 lines
926 B
JavaScript
39 lines
926 B
JavaScript
// Monaco Editor setup
|
|
const DEFAULT_CODE = `graph TD
|
|
A[Start] --> B[Process]
|
|
B --> C{Decision}
|
|
C -->|Yes| D[Result]
|
|
C -->|No| E[Other]`;
|
|
|
|
let editor;
|
|
|
|
require.config({ paths: { vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs' } });
|
|
|
|
require(['vs/editor/editor.main'], function () {
|
|
editor = monaco.editor.create(document.getElementById('editor-container'), {
|
|
value: DEFAULT_CODE,
|
|
language: 'markdown',
|
|
theme: 'vs-dark',
|
|
minimap: { enabled: false },
|
|
fontSize: 14,
|
|
lineNumbers: 'on',
|
|
wordWrap: 'on',
|
|
automaticLayout: true,
|
|
scrollBeyondLastLine: false,
|
|
});
|
|
|
|
// Load initial code from server if provided
|
|
fetch('/api/initial-code')
|
|
.then((r) => r.json())
|
|
.then((data) => {
|
|
if (data.code) {
|
|
editor.setValue(data.code);
|
|
}
|
|
})
|
|
.catch(() => {});
|
|
});
|
|
|
|
function getEditorValue() {
|
|
return editor ? editor.getValue() : DEFAULT_CODE;
|
|
}
|