From 26f97cadf160e3c9e19cea7a27586d67838ef230 Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Thu, 17 Apr 2025 18:13:24 +0200 Subject: [PATCH 1/2] feat: expose prosemirrorState again? --- packages/core/src/editor/BlockNoteEditor.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/core/src/editor/BlockNoteEditor.ts b/packages/core/src/editor/BlockNoteEditor.ts index 8f37c3428..3382407ec 100644 --- a/packages/core/src/editor/BlockNoteEditor.ts +++ b/packages/core/src/editor/BlockNoteEditor.ts @@ -871,8 +871,18 @@ export class BlockNoteEditor< this._tiptapEditor.mount(this, parentElement, contentComponent); }; + /** + * Get the underlying prosemirror state + * @note Prefer using `editor.transact` to read the current editor state, as that will ensure the state is up to date + * @see https://prosemirror.net/docs/ref/#state.EditorState + */ + public get prosemirrorState() { + return this._tiptapEditor.state; + } + /** * Get the underlying prosemirror view + * @see https://prosemirror.net/docs/ref/#view.EditorView */ public get prosemirrorView() { return this._tiptapEditor.view; From 614ef281b847870dd1e03071e696b98ddf84c162 Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Fri, 18 Apr 2025 09:21:12 +0200 Subject: [PATCH 2/2] refactor: cleanup a bit --- packages/core/src/editor/BlockNoteEditor.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/src/editor/BlockNoteEditor.ts b/packages/core/src/editor/BlockNoteEditor.ts index 3382407ec..b68ca3d63 100644 --- a/packages/core/src/editor/BlockNoteEditor.ts +++ b/packages/core/src/editor/BlockNoteEditor.ts @@ -877,6 +877,11 @@ export class BlockNoteEditor< * @see https://prosemirror.net/docs/ref/#state.EditorState */ public get prosemirrorState() { + if (this.activeTransaction) { + throw new Error( + "`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state" + ); + } return this._tiptapEditor.state; } @@ -1044,7 +1049,7 @@ export class BlockNoteEditor< * Executes a callback whenever the editor's contents change. * @param callback The callback to execute. * - * @deprecated use `onChange` instead + * @deprecated use {@link BlockNoteEditor.onChange} instead */ public onEditorContentChange(callback: () => void) { this._tiptapEditor.on("update", callback);