Commit 117e8487 authored by Jérome Perrin's avatar Jérome Perrin

monaco_editor: re-format with new prettier

parent 8c53dfaf
/*jslint nomen: true, indent: 2 */ /*jslint nomen: true, indent: 2 */
/*global window, rJS, monaco, JSLINT */ /*global window, rJS, monaco, JSLINT */
(function(window, rJS, monaco) { (function (window, rJS, monaco) {
'use strict'; 'use strict';
// globals // globals
...@@ -10,16 +10,16 @@ ...@@ -10,16 +10,16 @@
rJS(window) rJS(window)
.declareAcquiredMethod('notifySubmit', 'notifySubmit') .declareAcquiredMethod('notifySubmit', 'notifySubmit')
.declareJob('deferNotifySubmit', function() { .declareJob('deferNotifySubmit', function () {
// Ensure error will be correctly handled // Ensure error will be correctly handled
return this.notifySubmit(); return this.notifySubmit();
}) })
.declareAcquiredMethod('notifyChange', 'notifyChange') .declareAcquiredMethod('notifyChange', 'notifyChange')
.declareJob('deferNotifyChange', function() { .declareJob('deferNotifyChange', function () {
// Ensure error will be correctly handled // Ensure error will be correctly handled
return this.notifyChange(); return this.notifyChange();
}) })
.ready(function(context) { .ready(function (context) {
let editor; let editor;
function deferNotifyChange() { function deferNotifyChange() {
if (!context.state.ignoredChangeDuringInitialization) { if (!context.state.ignoredChangeDuringInitialization) {
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
/* because Alt+Click is LeftClick on ChromeOS */ /* because Alt+Click is LeftClick on ChromeOS */
multiCursorModifier: 'ctrlCmd', multiCursorModifier: 'ctrlCmd',
automaticLayout: true, automaticLayout: true,
autoIndent: true autoIndent: true,
} }
); );
editor.addAction({ editor.addAction({
...@@ -43,12 +43,12 @@ ...@@ -43,12 +43,12 @@
keybindingContext: null, keybindingContext: null,
contextMenuGroupId: 'navigation', contextMenuGroupId: 'navigation',
contextMenuOrder: 1.5, contextMenuOrder: 1.5,
run: context.deferNotifySubmit.bind(context) run: context.deferNotifySubmit.bind(context),
}); });
editor.getModel().updateOptions({ editor.getModel().updateOptions({
tabSize: 2, tabSize: 2,
insertSpaces: true insertSpaces: true,
}); });
editor.getModel().onDidChangeContent(deferNotifyChange); editor.getModel().onDidChangeContent(deferNotifyChange);
}) })
...@@ -56,7 +56,9 @@ ...@@ -56,7 +56,9 @@
.declareJob('runJsLint', function () { .declareJob('runJsLint', function () {
var context = this; var context = this;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { return RSVP.delay(500); }) .push(function () {
return RSVP.delay(500);
})
.push(function () { .push(function () {
if (context.state.model_language === 'javascript') { if (context.state.model_language === 'javascript') {
JSLINT(context.editor.getValue(), {}); JSLINT(context.editor.getValue(), {});
...@@ -65,24 +67,27 @@ ...@@ -65,24 +67,27 @@
'jslint', 'jslint',
JSLINT.data() JSLINT.data()
.errors.filter(Boolean) .errors.filter(Boolean)
.map(err => ({ .map((err) => ({
startLineNumber: err.line, startLineNumber: err.line,
startColumn: err.character, startColumn: err.character,
message: err.reason, message: err.reason,
severity: monaco.MarkerSeverity.Error, severity: monaco.MarkerSeverity.Error,
source: 'jslint' source: 'jslint',
})) }))
); );
} }
}); });
}) })
.declareMethod('render', function(options) { .declareMethod('render', function (options) {
var model_language, var model_language,
state_dict = { state_dict = {
key: options.key, key: options.key,
editable: options.editable === undefined ? true : options.editable editable: options.editable === undefined ? true : options.editable,
}; };
if (options.portal_type === 'Web Page' || options.content_type == 'text/html') { if (
options.portal_type === 'Web Page' ||
options.content_type == 'text/html'
) {
model_language = 'html'; model_language = 'html';
} else if (options.portal_type === 'Web Script') { } else if (options.portal_type === 'Web Script') {
model_language = 'javascript'; model_language = 'javascript';
...@@ -105,7 +110,7 @@ ...@@ -105,7 +110,7 @@
return this.changeState(state_dict); return this.changeState(state_dict);
}) })
.onStateChange(function(modification_dict) { .onStateChange(function (modification_dict) {
var queue = new RSVP.Queue(); var queue = new RSVP.Queue();
if (modification_dict.hasOwnProperty('value')) { if (modification_dict.hasOwnProperty('value')) {
// Do not notify the UI when initializing the value // Do not notify the UI when initializing the value
...@@ -135,16 +140,16 @@ ...@@ -135,16 +140,16 @@
plugins: [prettierPlugins.babel], plugins: [prettierPlugins.babel],
// see http://json.schemastore.org/prettierrc for supported options. // see http://json.schemastore.org/prettierrc for supported options.
singleQuote: true, singleQuote: true,
tabWidth: 2 tabWidth: 2,
}); });
return [ return [
{ {
range: model.getFullModelRange(), range: model.getFullModelRange(),
text text,
} },
]; ];
} },
} }
); );
...@@ -155,7 +160,7 @@ ...@@ -155,7 +160,7 @@
// lint with typescript compiler // lint with typescript compiler
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({ monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
noSemanticValidation: false, noSemanticValidation: false,
noSyntaxValidation: false noSyntaxValidation: false,
}); });
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({ monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
...@@ -163,17 +168,17 @@ ...@@ -163,17 +168,17 @@
allowNonTsExtensions: true, allowNonTsExtensions: true,
checkJs: true, checkJs: true,
allowJs: true, allowJs: true,
module: monaco.languages.typescript.ModuleKind.UMD module: monaco.languages.typescript.ModuleKind.UMD,
}); });
// Type mapping for Nexedi libraries // Type mapping for Nexedi libraries
const addExtraLibrary = function(script_name, lib_name) { const addExtraLibrary = function (script_name, lib_name) {
return () => { return () => {
return fetch(script_name) return fetch(script_name)
.then(function(resp) { .then(function (resp) {
return resp.text(); return resp.text();
}) })
.then(function(script_code) { .then(function (script_code) {
monaco.languages.typescript.javascriptDefaults.addExtraLib( monaco.languages.typescript.javascriptDefaults.addExtraLib(
script_code, script_code,
lib_name lib_name
...@@ -186,14 +191,14 @@ ...@@ -186,14 +191,14 @@
.push(addExtraLibrary('./monaco-renderjs.d.ts', 'renderjs')) .push(addExtraLibrary('./monaco-renderjs.d.ts', 'renderjs'))
.push(addExtraLibrary('./monaco-jio.d.ts', 'jio')); .push(addExtraLibrary('./monaco-jio.d.ts', 'jio'));
} }
if (modification_dict.hasOwnProperty('editable')){ if (modification_dict.hasOwnProperty('editable')) {
this.editor.updateOptions({readOnly: !this.state.editable}); this.editor.updateOptions({ readOnly: !this.state.editable });
} }
} }
return queue; return queue;
}) })
.declareMethod('getContent', function() { .declareMethod('getContent', function () {
var form_data = {}; var form_data = {};
if (this.state.editable) { if (this.state.editable) {
form_data[this.state.key] = this.editor.getValue(); form_data[this.state.key] = this.editor.getValue();
......
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