From 2ffc339d92b8b9bcd3a975e606ce65320f82a378 Mon Sep 17 00:00:00 2001 From: bdbch Date: Thu, 30 Jul 2026 19:55:13 +0200 Subject: [PATCH] feat(core): enhance Editor class with options property and content accessors --- packages/core/src/editor/Editor.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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(); + } } -- 2.51.2