BlockNote icon indicating copy to clipboard operation
BlockNote copied to clipboard

Added editor option to disable nested blocks

Open abasse opened this issue 2 years ago • 7 comments

This PR adds an option to the editor to disable nested blocks. (on tab command or via formatting toolbar)

example configuration "canNestBlock":

export type BlockNoteEditorOptions = Partial<{ editable: boolean; canNestBlock: boolean; initialContent: PartialBlock[]; editorDOMAttributes: Record<string, string>; onEditorReady: (editor: BlockNoteEditor) => void; onEditorContentChange: (editor: BlockNoteEditor) => void; onTextCursorPositionChange: (editor: BlockNoteEditor) => void; slashMenuItems: ReactSlashMenuItem[]; defaultStyles: boolean; uploadFile: (file: File) => Promise<string> }>;

abasse avatar Nov 06 '23 15:11 abasse

Someone is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Nov 06 '23 15:11 vercel[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
blocknote ❌ Failed (Inspect) Nov 6, 2023 3:28pm

vercel[bot] avatar Nov 06 '23 15:11 vercel[bot]

Looks good! Though these changes will still let you nest/unnest blocks programatically, e.g. using the formatting toolbar. I think we need 2 more things before we merge this:

  1. Prevent nesting at the schema level - the blockContainer node currently has content: "blockContent blockGroup?", meaning you can place a blockContent node in it, and optionally a blockGroup node for nested blocks. If the canNestBlock option is true, we should change this to content: "blockContent" and make sure everything still works.
  2. Edit the definitions of editor.canNestBlock and editor.canUnnestBlock to just return false if the canNestBlock option is true.

matthewlipski avatar Nov 07 '23 14:11 matthewlipski

Looks good! Though these changes will still let you nest/unnest blocks programatically, e.g. using the formatting toolbar. I think we need 2 more things before we merge this:

  1. Prevent nesting at the schema level - the blockContainer node currently has content: "blockContent blockGroup?", meaning you can place a blockContent node in it, and optionally a blockGroup node for nested blocks. If the canNestBlock option is true, we should change this to content: "blockContent" and make sure everything still works.
  2. Edit the definitions of editor.canNestBlock and editor.canUnnestBlock to just return false if the canNestBlock option is true.

Thanks for the feedback! I had a look at the code, but I'm not really sure where to start. Is that something you would be able to look at?

abasse avatar Nov 09 '23 15:11 abasse

The editor option is now called "enableNestedBlocks" to avoid conflicts with the existing function with the same name.

abasse avatar Nov 14 '23 15:11 abasse

I'm looking to disable nesting as well

NicHaley avatar Jun 12 '24 19:06 NicHaley

@NicHaley https://github.com/TypeCellOS/BlockNote/issues/876 maybe you can view this

jueinin avatar Jun 27 '24 11:06 jueinin