Skip to content

feat: option to disable trailing block #679

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/pages/docs/editor-basics/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type BlockNoteEditorOptions = {
uploadFile?: (file: File) => Promise<string>;
collaboration?: CollaborationOptions;
schema?: BlockNoteSchema;
trailingBlock?: boolean;
};
```

Expand All @@ -44,6 +45,8 @@ The hook takes two optional parameters:

`schema` (_advanced_): The editor schema if you want to extend your editor with custom blocks, styles, or inline content [Custom Schemas](/docs/custom-schemas).

`trailingBlock`: An option which user can pass with `false` value to disable the automatic creation of a trailing new block on the next line when the user types or edits any block. Defaults to `true` if undefined.

**deps:** Dependency array that's internally passed to `useMemo`. A new editor will only be created when this array changes.

<Callout type="info" emoji={"💡"}>
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/editor/BlockNoteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export type BlockNoteEditorOptions<

// tiptap options, undocumented
_tiptapOptions: Partial<EditorOptions>;

trailingBlock?: boolean;
};

const blockNoteTipTapOptions = {
Expand Down Expand Up @@ -250,6 +252,7 @@ export class BlockNoteEditor<
styleSpecs: this.schema.styleSpecs,
inlineContentSpecs: this.schema.inlineContentSpecs,
collaboration: newOptions.collaboration,
trailingBlock: newOptions.trailingBlock,
});

const blockNoteUIExtension = Extension.create({
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/editor/BlockNoteExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const getBlockNoteExtensions = <
blockSpecs: BlockSpecs;
inlineContentSpecs: InlineContentSpecs;
styleSpecs: StyleSpecs;
trailingBlock: boolean | undefined;
collaboration?: {
fragment: Y.XmlFragment;
user: {
Expand Down Expand Up @@ -131,7 +132,9 @@ export const getBlockNoteExtensions = <
Dropcursor.configure({ width: 5, color: "#ddeeff" }),
// This needs to be at the bottom of this list, because Key events (such as enter, when selecting a /command),
// should be handled before Enter handlers in other components like splitListItem
TrailingNode,
...(opts.trailingBlock === undefined || opts.trailingBlock
? [TrailingNode]
: []),
];

if (opts.collaboration) {
Expand Down
Loading