Skip to content

Commit 6a9e6b1

Browse files
authored
feat: option to disable trailing block (#679)
* feat-#631 extended block options for traiing block * feat-#631 Code Updated with less and better changes for feature * feat-#631- updated documentation for this new `trailingBlock` option
1 parent d570afd commit 6a9e6b1

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

docs/pages/docs/editor-basics/setup.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type BlockNoteEditorOptions = {
2525
uploadFile?: (file: File) => Promise<string>;
2626
collaboration?: CollaborationOptions;
2727
schema?: BlockNoteSchema;
28+
trailingBlock?: boolean;
2829
};
2930
```
3031

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

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

48+
`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.
49+
4750
**deps:** Dependency array that's internally passed to `useMemo`. A new editor will only be created when this array changes.
4851

4952
<Callout type="info" emoji={"💡"}>

packages/core/src/editor/BlockNoteEditor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ export type BlockNoteEditorOptions<
133133

134134
// tiptap options, undocumented
135135
_tiptapOptions: Partial<EditorOptions>;
136+
137+
trailingBlock?: boolean;
136138
};
137139

138140
const blockNoteTipTapOptions = {
@@ -250,6 +252,7 @@ export class BlockNoteEditor<
250252
styleSpecs: this.schema.styleSpecs,
251253
inlineContentSpecs: this.schema.inlineContentSpecs,
252254
collaboration: newOptions.collaboration,
255+
trailingBlock: newOptions.trailingBlock,
253256
});
254257

255258
const blockNoteUIExtension = Extension.create({

packages/core/src/editor/BlockNoteExtensions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const getBlockNoteExtensions = <
4545
blockSpecs: BlockSpecs;
4646
inlineContentSpecs: InlineContentSpecs;
4747
styleSpecs: StyleSpecs;
48+
trailingBlock: boolean | undefined;
4849
collaboration?: {
4950
fragment: Y.XmlFragment;
5051
user: {
@@ -131,7 +132,9 @@ export const getBlockNoteExtensions = <
131132
Dropcursor.configure({ width: 5, color: "#ddeeff" }),
132133
// This needs to be at the bottom of this list, because Key events (such as enter, when selecting a /command),
133134
// should be handled before Enter handlers in other components like splitListItem
134-
TrailingNode,
135+
...(opts.trailingBlock === undefined || opts.trailingBlock
136+
? [TrailingNode]
137+
: []),
135138
];
136139

137140
if (opts.collaboration) {

0 commit comments

Comments
 (0)