Skip to content

fix: _tiptapOptions typing and fields getting overridden #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions packages/core/src/BlockNoteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
};

// tiptap options, undocumented
_tiptapOptions: any;
_tiptapOptions: Partial<EditorOptions>;
};

const blockNoteTipTapOptions = {
Expand Down Expand Up @@ -228,10 +228,11 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
},
]);

const tiptapOptions: EditorOptions = {
const tiptapOptions: Partial<EditorOptions> = {
...blockNoteTipTapOptions,
...newOptions._tiptapOptions,
onBeforeCreate(editor) {
newOptions._tiptapOptions?.onBeforeCreate?.(editor);
if (!initialContent) {
// when using collaboration
return;
Expand All @@ -250,7 +251,8 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
);
editor.editor.options.content = root.toJSON();
},
onCreate: () => {
onCreate: (editor) => {
newOptions._tiptapOptions?.onCreate?.(editor);
// We need to wait for the TipTap editor to init before we can set the
// initial content, as the schema may contain custom blocks which need
// it to render.
Expand All @@ -261,7 +263,8 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
newOptions.onEditorReady?.(this);
this.ready = true;
},
onUpdate: () => {
onUpdate: (editor) => {
newOptions._tiptapOptions?.onUpdate?.(editor);
// This seems to be necessary due to a bug in TipTap:
// https://github.com/ueberdosis/tiptap/issues/2583
if (!this.ready) {
Expand All @@ -270,7 +273,8 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {

newOptions.onEditorContentChange?.(this);
},
onSelectionUpdate: () => {
onSelectionUpdate: (editor) => {
newOptions._tiptapOptions?.onSelectionUpdate?.(editor);
// This seems to be necessary due to a bug in TipTap:
// https://github.com/ueberdosis/tiptap/issues/2583
if (!this.ready) {
Expand All @@ -279,17 +283,25 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {

newOptions.onTextCursorPositionChange?.(this);
},
editable: options.editable === undefined ? true : options.editable,
editable:
options.editable !== undefined
? options.editable
: newOptions._tiptapOptions?.editable !== undefined
? newOptions._tiptapOptions?.editable
: true,
extensions:
newOptions.enableBlockNoteExtensions === false
? newOptions._tiptapOptions?.extensions
? newOptions._tiptapOptions?.extensions || []
: [...(newOptions._tiptapOptions?.extensions || []), ...extensions],
editorProps: {
...newOptions._tiptapOptions?.editorProps,
attributes: {
...newOptions._tiptapOptions?.editorProps?.attributes,
...newOptions.domAttributes?.editor,
class: mergeCSSClasses(
styles.bnEditor,
styles.bnRoot,
newOptions.domAttributes?.editor?.class || "",
newOptions.defaultStyles ? styles.defaultStyles : "",
newOptions.domAttributes?.editor?.class || ""
),
Expand Down