2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-07-18 23:44:29 -06:00

Switch to JS private fields

This commit is contained in:
Jeroen akkerman 2023-04-28 02:59:38 +02:00
parent e6a9359b1d
commit e12e59a003
2 changed files with 14 additions and 18 deletions

View File

@ -43,7 +43,6 @@ jobs:
- name: Test - name: Test
run: npm test run: npm test
# - uses: actions/upload-artifact@v3 # - uses: actions/upload-artifact@v3
# if: failure() # if: failure()
# with: # with:

View File

@ -1,12 +1,9 @@
/* eslint-disable sort-keys,@typescript-eslint/member-ordering,max-classes-per-file */ /* eslint-disable sort-keys,@typescript-eslint/member-ordering,max-classes-per-file */
import { markdown, markdownLanguage } from '@codemirror/lang-markdown'; import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
// import { languages } from "@codemirror/language-data"; // Costs 800KB, probably should be a manual plugin
import { import {
HighlightStyle, HighlightStyle,
defaultHighlightStyle, defaultHighlightStyle,
syntaxHighlighting, syntaxHighlighting,
// HighlightStyle,
// tags
} from '@codemirror/language'; } from '@codemirror/language';
import { EditorState } from '@codemirror/state'; import { EditorState } from '@codemirror/state';
import { drawSelection, EditorView } from '@codemirror/view'; import { drawSelection, EditorView } from '@codemirror/view';
@ -36,15 +33,15 @@ class AlreadyConstructedError extends Error {
export class EasyMDE { export class EasyMDE {
private readonly element: HTMLTextAreaElement; private readonly element: HTMLTextAreaElement;
private _container?: HTMLDivElement; #container?: HTMLDivElement;
private _codemirror?: EditorView; #codemirror?: EditorView;
// private rendered = false; // private rendered = false;
private readonly _options: Options; readonly #options: Options;
private readonly plugins: IEasyMDEPlugin[] = []; private readonly plugins: IEasyMDEPlugin[] = [];
public constructor(options: InputOptions) { public constructor(options: InputOptions) {
this._options = { this.#options = {
...options, ...options,
blockStyles: { blockStyles: {
bold: '**', bold: '**',
@ -59,21 +56,21 @@ export class EasyMDE {
} }
public get container(): HTMLDivElement { public get container(): HTMLDivElement {
if (!this._container) { if (!this.#container) {
throw new NotConstructedError(); throw new NotConstructedError();
} }
return this._container; return this.#container;
} }
public get codemirror(): EditorView { public get codemirror(): EditorView {
if (!this._codemirror) { if (!this.#codemirror) {
throw new NotConstructedError(); throw new NotConstructedError();
} }
return this._codemirror; return this.#codemirror;
} }
public get options(): Readonly<Options> { public get options(): Readonly<Options> {
return Object.freeze(this._options); return Object.freeze(this.#options);
} }
private static verifyAndReturnElement( private static verifyAndReturnElement(
@ -97,7 +94,7 @@ export class EasyMDE {
} }
public async construct(): Promise<void> { public async construct(): Promise<void> {
if (this._container && this._codemirror) { if (this.#container && this.#codemirror) {
throw new AlreadyConstructedError(); throw new AlreadyConstructedError();
} }
@ -148,7 +145,7 @@ export class EasyMDE {
]); ]);
this.element.hidden = true; this.element.hidden = true;
this._codemirror = new EditorView({ this.#codemirror = new EditorView({
state: EditorState.create({ state: EditorState.create({
doc: this.element.value, doc: this.element.value,
extensions: [ extensions: [
@ -183,7 +180,7 @@ export class EasyMDE {
this.codemirror.focus(); this.codemirror.focus();
this._container = easyMDEContainer; this.#container = easyMDEContainer;
} }
public destruct(): void { public destruct(): void {
@ -196,8 +193,8 @@ export class EasyMDE {
this.codemirror.destroy(); this.codemirror.destroy();
this.container.remove(); this.container.remove();
this._container = undefined; this.#container = undefined;
this._codemirror = undefined; this.#codemirror = undefined;
this.element.hidden = false; this.element.hidden = false;
} }