From e12e59a00316e863d0906978cd76e2464d9ded45 Mon Sep 17 00:00:00 2001 From: Jeroen akkerman Date: Fri, 28 Apr 2023 02:59:38 +0200 Subject: [PATCH] Switch to JS private fields --- .github/workflows/cd.yaml | 1 - src/easymde.ts | 31 ++++++++++++++----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 1c19d1e..962dfd8 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -43,7 +43,6 @@ jobs: - name: Test run: npm test - # - uses: actions/upload-artifact@v3 # if: failure() # with: diff --git a/src/easymde.ts b/src/easymde.ts index 5e1f38a..4c3e0e2 100644 --- a/src/easymde.ts +++ b/src/easymde.ts @@ -1,12 +1,9 @@ /* eslint-disable sort-keys,@typescript-eslint/member-ordering,max-classes-per-file */ import { markdown, markdownLanguage } from '@codemirror/lang-markdown'; -// import { languages } from "@codemirror/language-data"; // Costs 800KB, probably should be a manual plugin import { HighlightStyle, defaultHighlightStyle, syntaxHighlighting, - // HighlightStyle, - // tags } from '@codemirror/language'; import { EditorState } from '@codemirror/state'; import { drawSelection, EditorView } from '@codemirror/view'; @@ -36,15 +33,15 @@ class AlreadyConstructedError extends Error { export class EasyMDE { private readonly element: HTMLTextAreaElement; - private _container?: HTMLDivElement; - private _codemirror?: EditorView; + #container?: HTMLDivElement; + #codemirror?: EditorView; // private rendered = false; - private readonly _options: Options; + readonly #options: Options; private readonly plugins: IEasyMDEPlugin[] = []; public constructor(options: InputOptions) { - this._options = { + this.#options = { ...options, blockStyles: { bold: '**', @@ -59,21 +56,21 @@ export class EasyMDE { } public get container(): HTMLDivElement { - if (!this._container) { + if (!this.#container) { throw new NotConstructedError(); } - return this._container; + return this.#container; } public get codemirror(): EditorView { - if (!this._codemirror) { + if (!this.#codemirror) { throw new NotConstructedError(); } - return this._codemirror; + return this.#codemirror; } public get options(): Readonly { - return Object.freeze(this._options); + return Object.freeze(this.#options); } private static verifyAndReturnElement( @@ -97,7 +94,7 @@ export class EasyMDE { } public async construct(): Promise { - if (this._container && this._codemirror) { + if (this.#container && this.#codemirror) { throw new AlreadyConstructedError(); } @@ -148,7 +145,7 @@ export class EasyMDE { ]); this.element.hidden = true; - this._codemirror = new EditorView({ + this.#codemirror = new EditorView({ state: EditorState.create({ doc: this.element.value, extensions: [ @@ -183,7 +180,7 @@ export class EasyMDE { this.codemirror.focus(); - this._container = easyMDEContainer; + this.#container = easyMDEContainer; } public destruct(): void { @@ -196,8 +193,8 @@ export class EasyMDE { this.codemirror.destroy(); this.container.remove(); - this._container = undefined; - this._codemirror = undefined; + this.#container = undefined; + this.#codemirror = undefined; this.element.hidden = false; }