-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (56 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as monaco from 'monaco-editor'
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
import { configureMonacoYaml } from 'monaco-yaml'
import YamlWorker from './yaml.worker.js?worker'
window.MonacoEnvironment = {
getWorker(moduleId, label) {
switch (label) {
case 'editorWorkerService':
return new EditorWorker()
case 'yaml':
return new YamlWorker()
default:
throw new Error(`Unknown label ${label}`)
}
},
setTheme: function(theme) {
monaco.editor.defineTheme('monaco-yaml-theme', themeData(theme))
}
}
configureMonacoYaml(monaco, {
enableSchemaRequest: true
})
window.yamlEditor = {
create: function(element, uri, content, theme) {
monaco.editor.defineTheme('monaco-yaml-theme', themeData(theme))
monaco.editor.setTheme('monaco-yaml-theme')
monaco.languages.html.registerHTMLLanguageService('xml', {}, { documentFormattingEdits: true })
return monaco.editor.create(element, {
automaticLayout: true,
model: monaco.editor.createModel(content, undefined, monaco.Uri.parse(uri)),
tabSize: 2,
renderWhitespace: 'all'
});
},
uri: function(uriRaw) {
return monaco.Uri.parse(uriRaw);
}
}
function themeData(theme) {
if (theme == 'dark') {
return {
base: 'vs-dark',
colors: {
'editor.background': '#293241'
},
inherit: true,
rules: []
};
}
return {
base: 'vs',
colors: {},
inherit: true,
rules: []
};
}