Commit ba90ec75 authored by Jérome Perrin's avatar Jérome Perrin

monaco_editor: support editing JSON with an optional json schema

parent ed6243c9
......@@ -108,6 +108,9 @@
options.portal_type === 'Module Component'
) {
model_language = 'python';
} else if (options.content_type === 'application/json') {
model_language = 'json';
state_dict.json_schema_url = options.json_schema_url;
}
state_dict.model_language = model_language;
state_dict.value = options.value || '';
......@@ -195,6 +198,23 @@
.push(addExtraLibrary('./monaco-renderjs.d.ts', 'renderjs'))
.push(addExtraLibrary('./monaco-jio.d.ts', 'jio'));
}
if (this.state.model_language === 'json') {
let schemas = []
if (this.state.json_schema_url) {
schemas.push(
{
uri: this.state.json_schema_url,
fileMatch: "*"
}
)
}
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
allowComments: false,
schemas: schemas,
enableSchemaRequest: true,
});
}
if (modification_dict.hasOwnProperty('editable')) {
this.editor.updateOptions({ readOnly: !this.state.editable });
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment