Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
evanplaice committed Jun 22, 2020
1 parent 7c44ea5 commit a2a0d25
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
24 changes: 12 additions & 12 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 39 additions & 39 deletions src/wc-monaco-editor.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
/* eslint no-undef: 0 */
import '../monaco/editor.main.js';
import '../monaco/editor.main.js'

const monacoDir = new URL('monaco/', import.meta.url);
const monacoDir = new URL('monaco/', import.meta.url)

// eslint-disable-next-line
self.MonacoEnvironment = {
getWorkerUrl: function (moduleId, label) {
if (label === 'json') {
return `${monacoDir}json.worker.js`;
return `${monacoDir}json.worker.js`
}
if (label === 'css') {
return `${monacoDir}css.worker.js`;
return `${monacoDir}css.worker.js`
}
if (label === 'html') {
return `${monacoDir}html.worker.js`;
return `${monacoDir}html.worker.js`
}
if (label === 'typescript' || label === 'javascript') {
return `${monacoDir}ts.worker.js`;
return `${monacoDir}ts.worker.js`
}
return `${monacoDir}editor.worker.js`;
return `${monacoDir}editor.worker.js`
}
};
}

export class WCMonacoEditor extends HTMLElement {
static get observedAttributes () {
return ['src', 'value'];
return ['src', 'value']
}

attributeChangedCallback (name, oldValue, newValue) {
if (!this.__initialized) { return; }
if (!this.__initialized) { return }
if (oldValue !== newValue) {
this[name] = newValue;
this[name] = newValue
}
}

get src () { return this.getAttribute('src'); }
get src () { return this.getAttribute('src') }
set src (value) {
this.setAttribute('src', value);
this.setSrc();
this.setAttribute('src', value)
this.setSrc()
}

get value () { return this.editor.getValue(); }
get value () { return this.editor.getValue() }
set value (value) {
this.editor.setValue(value);
this.editor.setValue(value)
}

get tabSize () { return this.editor.getModel()._options.tabSize; }
get tabSize () { return this.editor.getModel()._options.tabSize }
set tabSize (value) {
this.editor.getModel().updateOptions({ tabSize: value });
this.editor.getModel().updateOptions({ tabSize: value })
}

constructor () {
super();
this.__initialized = false;
this.editor = null;
super()
this.__initialized = false
this.editor = null
}

async connectedCallback () {
this.style.display = 'block';
if (!this.id) { this.id = 'editor'; }
if (!this.style.width) { this.style.width = '100%'; }
if (!this.style.height) { this.style.height = '100%'; }
this.style.display = 'block'
if (!this.id) { this.id = 'editor' }
if (!this.style.width) { this.style.width = '100%' }
if (!this.style.height) { this.style.height = '100%' }

if (this.hasAttribute('config')) {
const config = await this.fetchConfig(this.getAttribute('config'));
this.editor = monaco.editor.create(document.getElementById(this.id), config);
const config = await this.fetchConfig(this.getAttribute('config'))
this.editor = monaco.editor.create(document.getElementById(this.id), config)
} else {
this.editor = monaco.editor.create(document.getElementById(this.id), {
language: this.getAttribute('language'),
Expand All @@ -76,34 +76,34 @@ export class WCMonacoEditor extends HTMLElement {
minimap: { enabled: !this.hasAttribute('no-minimap') },
wordWrap: this.hasAttribute('word-wrap'),
wrappingIndent: this.getAttribute('wrap-indent')
});
})
}

if (this.hasAttribute('tab-size')) {
this.tabSize = this.getAttribute('tab-size');
this.tabSize = this.getAttribute('tab-size')
}

if (this.hasAttribute('src')) {
this.setSrc();
this.setSrc()
}
this.__initialized = true;
this.__initialized = true
}

async setSrc () {
const src = this.getAttribute('src');
const contents = await this.fetchSrc(src);
this.editor.setValue(contents);
const src = this.getAttribute('src')
const contents = await this.fetchSrc(src)
this.editor.setValue(contents)
}

async fetchSrc (src) {
const response = await fetch(src);
return response.text();
const response = await fetch(src)
return response.text()
}

async fetchConfig (config) {
const response = await fetch(config);
return response.json();
const response = await fetch(config)
return response.json()
}
}

customElements.define('wc-monaco-editor', WCMonacoEditor);
customElements.define('wc-monaco-editor', WCMonacoEditor)

0 comments on commit a2a0d25

Please sign in to comment.