Something went wrong. Try again.
YAML-based live configuration of MicroFreak datyoma.tngl.io/mfctl
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js';import 'monaco-editor/esm/vs/editor/editor.all.js';import 'monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution.js';import { configureMonacoYaml } from 'monaco-yaml';import { initVimMode } from 'monaco-vim';import schema from './assets/patch.schema.json';
export function createYamlEditor(element, onApply, vimCheckbox, vimStatus) { globalThis.MonacoEnvironment = { getWorker(_moduleId, label) { const path = label === 'yaml' ? './yaml.worker.js' : './editor.worker.js'; return new Worker(new URL(path, import.meta.url), { type: 'module' }); }, }; const { title, ...editorSchema } = schema; configureMonacoYaml(monaco, { hoverSchemaSource: false, indentation: ' ', schemas: [{ uri: new URL('./patch.schema.json', import.meta.url).href, fileMatch: ['**/patch.yaml'], schema: editorSchema, }], }); const model = monaco.editor.createModel('spec: {}\n', 'yaml', monaco.Uri.parse('file:///patch.yaml')); const editor = monaco.editor.create(element, { model, automaticLayout: true, lineNumbers: 'off', tabSize: 2, insertSpaces: true, detectIndentation: false, minimap: { enabled: false }, fontSize: 14, scrollBeyondLastLine: false, }); editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, onApply); let vimMode; const updateVimMode = () => { if (vimCheckbox.checked) vimMode = initVimMode(editor, vimStatus); else { vimMode?.dispose(); vimMode = undefined; } vimStatus.hidden = !vimCheckbox.checked; }; try { vimCheckbox.checked = localStorage.getItem('mfctl.vimMode') === 'true'; } catch {} updateVimMode(); vimCheckbox.addEventListener('change', () => { updateVimMode(); try { localStorage.setItem('mfctl.vimMode', String(vimCheckbox.checked)); } catch {} }); return editor;}