Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 19 additions & 3 deletions packages/core/src/BlockNoteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
/**
* 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.
*/
Expand Down Expand Up @@ -287,14 +287,16 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {

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 || []
Expand Down Expand Up @@ -761,6 +763,13 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
* 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
Expand All @@ -780,6 +789,13 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
* 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
Expand Down
29 changes: 24 additions & 5 deletions packages/core/src/extensions/Blocks/nodes/BlockContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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": () =>
Expand Down