Skip to content
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

Added editor option to disable nested blocks #408

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

abasse
Copy link

@abasse abasse commented Nov 6, 2023

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> }>;

Copy link

vercel bot commented Nov 6, 2023

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

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Nov 6, 2023

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

@matthewlipski
Copy link
Collaborator

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.

@abasse
Copy link
Author

abasse commented Nov 9, 2023

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
Copy link
Author

abasse commented Nov 14, 2023

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

@NicHaley
Copy link

I'm looking to disable nesting as well

@jueinin
Copy link

jueinin commented Jun 27, 2024

@NicHaley #876 maybe you can view this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants