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

add disableExtensions option to allow disabling built in extensions by name. #858

Closed fridaystreet closed 1 week ago

fridaystreet commented 1 week ago

Without completely needing to refactor the way tiptap extensions and core blocknote extensions are added, this should be fairly simple approach to just allow a list of extension names to be passed in that will then be removed from the inbuiult extensions before being passed to tiptap.

This will allow you to the override these extensions if you wish without completely disbaling blocknote via

const editor = useCreateBlockNote({
    disableExtensions:['link'],
    _tiptapOptions: {
      extensions: [
        Link,
      ]
    }
  })
vercel[bot] commented 1 week ago

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

Name Status Preview Updated (UTC)
blocknote ✅ Ready (Inspect) Visit Preview Jun 24, 2024 6:28pm
blocknote-website ✅ Ready (Inspect) Visit Preview Jun 24, 2024 6:28pm
vercel[bot] commented 1 week ago

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

A member of the Team first needs to authorize it.

fridaystreet commented 1 week ago

@matthewlipski ok great thanks. Yeah at first I actually just used enableBlockExtensions and made it

string[] | boolean

but after looking at it a few times it didn't feel like it made sense at it would imply you need to pass an array of all of the enabled ones just omitting the disabled ones.

I wasn't sure if there was some bigger picture reason for being to just disable/enable the whole thing with enableBlockNoteExtensions so opted for the extra parameter. I agree possibly it adds confusion with 2, but then again, if someone does want to disable all of them, they'd have to maintain an array full of all the extension names so maybe it is better to leave both.

I guess another option could be to just have explicit arrays for both, that way if you're looking to only enable some or only disable some it's easy, but probably overkill and confusing

enableExtensions string[] | boolean | undefined disableExtensions string[] | boolean | undefined

Thanks for reveiwing it though. let me know if you want me to submit another PR

matthewlipski commented 5 days ago

All good, I think the use case of disabling all TipTap extensions is extremely rare since at that point you're probably better off just using a different editor, so I went ahead with removing enableBlockExtensions.