-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (35 loc) · 1021 Bytes
/
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
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
(function () {
// create div to avoid needing a HtmlWebpackPlugin template
const div = document.createElement('div');
div.id = 'root';
div.style = 'width:800px; height:600px; border:1px solid #ccc;';
document.body.appendChild(div);
})();
async function init() {
const SCHEMA_URL = './schema/Bookmarks.json';
async function getJsonFromUri(jsonUri) {
const response = await fetch(jsonUri);
const json = await response.json();
return json;
}
const schemaUri = monaco.Uri.parse(SCHEMA_URL);
const schema = await getJsonFromUri(SCHEMA_URL);
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
schemas: [
{
uri: schemaUri,
fileMatch: ['*'],
schema: schema
}
]
});
monaco.editor.create(document.getElementById('root'), {
value: "",
language: 'json',
});
}
document.addEventListener('DOMContentLoaded', () => {
init();
});