From 95a39fa26784c429ccf78f95faa7a369b72bbfc7 Mon Sep 17 00:00:00 2001 From: Evan Date: Wed, 10 Jun 2020 11:46:20 -0600 Subject: [PATCH] Make 'editor' Property Public --- README.md | 1 + src/wc-codemirror.js | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a121cee..817b2ae 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Try it on [WebComponents.dev](https://webcomponents.dev/edit/uQEePfQ92jOWOpupDzp **Properties** +- `editor` - the CodeMirror editor instance - `value` - get/set the editor's contents *Note: The ID attribute is required when multiple editors instances are present* diff --git a/src/wc-codemirror.js b/src/wc-codemirror.js index f5188c7..f6146c9 100644 --- a/src/wc-codemirror.js +++ b/src/wc-codemirror.js @@ -23,7 +23,7 @@ export class WCCodeMirror extends HTMLElement { this.setSrc(); } - get value () { return this.__editor.getValue(); } + get value () { return this.editor.getValue(); } set value (value) { this.setValue(value); } @@ -35,7 +35,7 @@ export class WCCodeMirror extends HTMLElement { this.appendChild(template.content.cloneNode(true)); this.__initialized = false; this.__element = null; - this.__editor = null; + this.editor = null; } async connectedCallback () { @@ -58,7 +58,7 @@ export class WCCodeMirror extends HTMLElement { viewportMargin = viewportMarginAttr === 'infinity' ? Infinity : parseInt(viewportMarginAttr); } - this.__editor = CodeMirror.fromTextArea(this.__element, { + this.editor = CodeMirror.fromTextArea(this.__element, { lineNumbers: true, readOnly: false, mode, @@ -80,13 +80,13 @@ export class WCCodeMirror extends HTMLElement { async setSrc () { const src = this.getAttribute('src'); const contents = await this.fetchSrc(src); - this.__editor.swapDoc(CodeMirror.Doc(contents, this.getAttribute('mode'))); - this.__editor.refresh(); + this.editor.swapDoc(CodeMirror.Doc(contents, this.getAttribute('mode'))); + this.editor.refresh(); } async setValue (value) { - this.__editor.swapDoc(CodeMirror.Doc(value, this.getAttribute('mode'))); - this.__editor.refresh(); + this.editor.swapDoc(CodeMirror.Doc(value, this.getAttribute('mode'))); + this.editor.refresh(); } async fetchSrc (src) {