Skip to content

Commit 5aed7e9

Browse files
authored
feat: expose editor.prosemirrorState again (#1615)
1 parent 8a37698 commit 5aed7e9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/core/src/editor/BlockNoteEditor.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,23 @@ export class BlockNoteEditor<
871871
this._tiptapEditor.mount(this, parentElement, contentComponent);
872872
};
873873

874+
/**
875+
* Get the underlying prosemirror state
876+
* @note Prefer using `editor.transact` to read the current editor state, as that will ensure the state is up to date
877+
* @see https://prosemirror.net/docs/ref/#state.EditorState
878+
*/
879+
public get prosemirrorState() {
880+
if (this.activeTransaction) {
881+
throw new Error(
882+
"`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"
883+
);
884+
}
885+
return this._tiptapEditor.state;
886+
}
887+
874888
/**
875889
* Get the underlying prosemirror view
890+
* @see https://prosemirror.net/docs/ref/#view.EditorView
876891
*/
877892
public get prosemirrorView() {
878893
return this._tiptapEditor.view;
@@ -1034,7 +1049,7 @@ export class BlockNoteEditor<
10341049
* Executes a callback whenever the editor's contents change.
10351050
* @param callback The callback to execute.
10361051
*
1037-
* @deprecated use `onChange` instead
1052+
* @deprecated use {@link BlockNoteEditor.onChange} instead
10381053
*/
10391054
public onEditorContentChange(callback: () => void) {
10401055
this._tiptapEditor.on("update", callback);

0 commit comments

Comments
 (0)