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
19 changes: 7 additions & 12 deletions packages/core/src/BlockNoteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
public blockCache = new WeakMap<Node, Block<BSchema>>();
public readonly schema: BSchema;
public ready = false;
public enableNestedBlocks = true;

public readonly sideMenu: SideMenuProsemirrorPlugin<BSchema>;
public readonly formattingToolbar: FormattingToolbarProsemirrorPlugin<BSchema>;
Expand Down Expand Up @@ -194,6 +195,10 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
);
this.hyperlinkToolbar = new HyperlinkToolbarProsemirrorPlugin(this);
this.imageToolbar = new ImageToolbarProsemirrorPlugin(this);
this.enableNestedBlocks =
options.enableNestedBlocks !== undefined
? options.enableNestedBlocks
: true;

const extensions = getBlockNoteExtensions<BSchema>({
editor: this,
Expand Down Expand Up @@ -293,10 +298,6 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
: 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 @@ -763,10 +764,7 @@ 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
) {
if (!this.enableNestedBlocks) {
return false;
}

Expand All @@ -789,10 +787,7 @@ 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
) {
if (!this.enableNestedBlocks) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/BlockNoteExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const getBlockNoteExtensions = <BSchema extends BlockSchema>(opts: {
Doc,
BlockContainer.configure({
domAttributes: opts.domAttributes,
enableNestedBlocks: opts.editor.enableNestedBlocks,
}),
BlockGroup.configure({
domAttributes: opts.domAttributes,
Expand Down
16 changes: 4 additions & 12 deletions packages/core/src/extensions/Blocks/nodes/BlockContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ declare module "@tiptap/core" {
*/
export const BlockContainer = Node.create<{
domAttributes?: BlockNoteDOMAttributes;
enableNestedBlocks?: boolean;
}>({
name: "blockContainer",
group: "blockContainer",
// A block always contains content, and optionally a blockGroup which contains nested blocks
content() {
if (
typeof this.editor?.options.enableNestedBlocks === "boolean" &&
!this.editor?.options.enableNestedBlocks
) {
if (!this.options.enableNestedBlocks) {
return "blockContent";
}

Expand Down Expand Up @@ -630,20 +628,14 @@ 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 (
typeof this.editor.options.enableNestedBlocks === "boolean" &&
this.editor.options.enableNestedBlocks
) {
if (this.options.enableNestedBlocks) {
this.editor.commands.sinkListItem("blockContainer");
}

return true;
},
"Shift-Tab": () => {
if (
typeof this.editor.options.enableNestedBlocks === "boolean" &&
this.editor.options.enableNestedBlocks
) {
if (this.options.enableNestedBlocks) {
this.editor.commands.liftListItem("blockContainer");
}

Expand Down