diff --git a/packages/core/src/BlockNoteEditor.ts b/packages/core/src/BlockNoteEditor.ts index 76af2c6810..d0c104aad2 100644 --- a/packages/core/src/BlockNoteEditor.ts +++ b/packages/core/src/BlockNoteEditor.ts @@ -94,7 +94,7 @@ export type BlockNoteEditorOptions = { /** * Disables block nesting by the user if set to `false`. */ - canNestBlock: boolean; + enableNestedBlocks: boolean; /** * The content that should be in the editor when it's created, represented as an array of partial block objects. */ @@ -287,14 +287,16 @@ export class BlockNoteEditor { newOptions.onTextCursorPositionChange?.(this); }, - canNestBlock: - options.canNestBlock !== undefined ? options.canNestBlock : true, editable: options.editable !== undefined ? options.editable : newOptions._tiptapOptions?.editable !== undefined ? newOptions._tiptapOptions?.editable : true, + enableNestedBlocks: + options.enableNestedBlocks !== undefined + ? options.enableNestedBlocks + : true, extensions: newOptions.enableBlockNoteExtensions === false ? newOptions._tiptapOptions?.extensions || [] @@ -761,6 +763,13 @@ export class BlockNoteEditor { * Checks if the block containing the text cursor can be nested. */ public canNestBlock() { + if ( + typeof this._tiptapEditor.options.enableNestedBlocks === "boolean" && + !this._tiptapEditor.options.enableNestedBlocks + ) { + return false; + } + const { startPos, depth } = getBlockInfoFromPos( this._tiptapEditor.state.doc, this._tiptapEditor.state.selection.from @@ -780,6 +789,13 @@ export class BlockNoteEditor { * Checks if the block containing the text cursor is nested. */ public canUnnestBlock() { + if ( + typeof this._tiptapEditor.options.enableNestedBlocks === "boolean" && + !this._tiptapEditor.options.enableNestedBlocks + ) { + return false; + } + const { depth } = getBlockInfoFromPos( this._tiptapEditor.state.doc, this._tiptapEditor.state.selection.from diff --git a/packages/core/src/extensions/Blocks/nodes/BlockContainer.ts b/packages/core/src/extensions/Blocks/nodes/BlockContainer.ts index 4385b53227..9ab13e5730 100644 --- a/packages/core/src/extensions/Blocks/nodes/BlockContainer.ts +++ b/packages/core/src/extensions/Blocks/nodes/BlockContainer.ts @@ -46,7 +46,16 @@ export const BlockContainer = Node.create<{ name: "blockContainer", group: "blockContainer", // A block always contains content, and optionally a blockGroup which contains nested blocks - content: "blockContent blockGroup?", + content() { + if ( + typeof this.editor?.options.enableNestedBlocks === "boolean" && + !this.editor?.options.enableNestedBlocks + ) { + return "blockContent"; + } + + return "blockContent blockGroup?"; + }, // Ensures content-specific keyboard handlers trigger first. priority: 50, defining: true, @@ -621,15 +630,25 @@ export const BlockContainer = Node.create<{ // Always returning true for tab key presses ensures they're not captured by the browser. Otherwise, they blur the // editor since the browser will try to use tab for keyboard navigation. Tab: () => { - if (this.editor.options.canNestBlock) { - this.editor.commands.sinkListItem("blockContainer"); + if ( + typeof this.editor.options.enableNestedBlocks === "boolean" && + !this.editor.options.enableNestedBlocks + ) { + return false; } + + this.editor.commands.sinkListItem("blockContainer"); return true; }, "Shift-Tab": () => { - if (!this.editor.options.canNestBlock) { - this.editor.commands.liftListItem("blockContainer"); + if ( + typeof this.editor.options.enableNestedBlocks === "boolean" && + !this.editor.options.enableNestedBlocks + ) { + return false; } + + this.editor.commands.liftListItem("blockContainer"); return true; }, "Mod-Alt-0": () =>