TypeCellOS / BlockNote

A React Rich Text Editor that's block-based (Notion style) and extensible. Built on top of Prosemirror and Tiptap.
https://www.blocknotejs.org/
Mozilla Public License 2.0
5.89k stars 381 forks source link

how to disable nest or unnest feature? #876

Open jueinin opened 5 days ago

jueinin commented 5 days ago

Due to some special reasons, I need to disable the nest feature.

I customized the toolbar to remove the nest unNest button. However, I still can't get rid of the Tab and Shift Tab shortcuts. I found that the shortcut code is written in the blockContainer, and I intended to disable it through the extend method, with the code as follows:

import {BlockContainer} from "@blocknote/core/src/pm-nodes";

const newBlockContainer = BlockContainer.extend({
  addKeyboardShortcuts() {
    const obj = this.parent?.() || {};
    delete obj.Tab
    delete obj['Shift-Tab']
    return obj
  }
})
export default function App() {

  const editor = useCreateBlockNote({
    _tiptapOptions: {
      extensions: [
        newBlockContainer.configure({
          editor, // the editor has not been initialized
          domAttributes: {},
        })
      ]
    },
    disableExtensions: ['blockContainer'],

  });
  return <BlockNoteView editor={editor} />;
}

However, the issue lies in the fact that the configure method requires the editor object, which, at this point, has not been fully initialized, leading to an error. In this scenario, perhaps the tiptapOptions could be a function instead?

_tiptapOptions: (editor) => Partial<EditorOptions>
jueinin commented 5 days ago

and I'am wondering why this https://github.com/TypeCellOS/BlockNote/pull/408 PR hasn't been merged?

matthewlipski commented 4 days ago

and I'am wondering why this #408 PR hasn't been merged?

This PR doesn't completely removed block nesting - it's a bandaid fix that disables functions to nest/unnest blocks, but nested blocks are allowed in the schema. This means that you can still create them by e.g. copy pasting a nested list from somewhere else, passing them in initialContent, etc. Implementing this feature is a bigger undertaking than it seems, because most block-related types have to be overhauled to "properly" remove nesting.

matthewlipski commented 4 days ago

Also, nesting is a pretty core feature of BlockNote, so adding this hasn't been a high priority issue

jueinin commented 4 days ago

@matthewlipski because I need to transform the editor exported JSON data to another data structure, for some history reason. and the data structure do not support nesting. so that I want to disable the nesting feature.

i know this method is not perfect, but it's enough for us. and how about if someone want to extend some buildin extensions?

so I hope this PR can be merged