diff --git a/packages/core/src/editor/Editor.ts b/packages/core/src/editor/Editor.ts index 28b3021..f1e26e0 100644 --- a/packages/core/src/editor/Editor.ts +++ b/packages/core/src/editor/Editor.ts @@ -4,12 +4,14 @@ import { EventEmitter } from "./EventEmitter.ts"; import type { EditorEvents, EditorOptions } from "./types.ts"; export class Editor extends EventEmitter { + options: EditorOptions; state: EditorState; view: EditorView; constructor(options: EditorOptions) { super(); - const { element, content } = options; + this.options = options; + const { element, content } = this.options; this.emit("beforeCreate", { editor: this }); @@ -21,6 +23,9 @@ export class Editor extends EventEmitter { parent: element, }); + // @ts-expect-error we set the editor here so users can access the editor object from the DOM element + this.options.element["editor"] = this; + this.emit("create", { editor: this }); } @@ -28,4 +33,12 @@ export class Editor extends EventEmitter { public destroy(): void { this.view.destroy(); } + + get content(): string { + return this.state.doc.toString(); + } + + get json(): string[] { + return this.state.doc.toJSON(); + } }