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

Missing ts type for `disableExtensions` #881

Closed softmarshmallow closed 2 days ago

softmarshmallow commented 4 days ago

Cannot find a doc athttps://www.blocknotejs.org/docs, I cannot find a way to disable the table extension.

const editor = useCreateBlockNote({
    disableExtensions: ["table"],
});

Above will throw error

TypeError: Cannot read properties of undefined (reading 'name')
matthewlipski commented 4 days ago

You should be able to do this by just removing the table block from the schema, as it bundles all supporting nodes with it:

const { table, ...remainingSpecs } = defaultBlockSpecs;
const schema = BlockNoteSchema.create({
  blockSpecs: remainingSpecs,
});

const editor = useCreateBlockNote({
  schema,
});
softmarshmallow commented 2 days ago

Great ! that works. although, when I set schema, I'm not able to set initialContent - Simply ts-ignore it?

Screenshot 2024-06-30 at 7 02 56 PM
matthewlipski commented 4 hours ago

Ah yeah, probably your initialContent also needs a type argument. Normally, when you have the type Block[] for initialContent, it uses the default block schema. But since you're now using a modified schema, you should give it the appropriate type argument:

const { table, ...remainingSpecs } = defaultBlockSpecs;
const schema = BlockNoteSchema.create({
  blockSpecs: remainingSpecs,
});

const initialContent: Block<typeof schema.blockSchema>[] = [];

const editor = useCreateBlockNote({
  schema,
  initialContent,
});

return <BlockNoteView editor={editor} />;