Skip to content

Commit 16a00e9

Browse files
docs: Ordered editor options alphabetically and updated docs (#1471)
1 parent 129f51b commit 16a00e9

File tree

2 files changed

+124
-91
lines changed

2 files changed

+124
-91
lines changed

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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,62 @@ function useCreateBlockNote(
1919
): BlockNoteEditor;
2020

2121
type BlockNoteEditorOptions = {
22-
initialContent?: PartialBlock[];
23-
domAttributes?: Record<string, string>;
24-
defaultStyles?: boolean;
25-
uploadFile?: (file: File) => Promise<string>;
22+
animations?: boolean;
2623
collaboration?: CollaborationOptions;
24+
defaultStyles?: boolean;
2725
dictionary?: Dictionary;
26+
disableExtensions?: string[];
27+
domAttributes?: Record<string, string>;
28+
dropCursor?: (opts: {
29+
editor: BlockNoteEditor;
30+
color?: string | false;
31+
width?: number;
32+
class?: string;
33+
}) => Plugin;
34+
initialContent?: PartialBlock[];
35+
resolveFileUrl: (url: string) => Promise<string>
2836
schema?: BlockNoteSchema;
37+
setIdAttribute?: boolean;
38+
sideMenuDetection?: "viewport" | "editor";
39+
tabBehavior?: "prefer-navigate-ui" | "prefer-indent"
2940
trailingBlock?: boolean;
30-
animations?: boolean;
41+
uploadFile?: (file: File) => Promise<string>;
3142
};
3243
```
3344

3445
The hook takes two optional parameters:
3546

3647
**options:** An object containing options for the editor:
3748

38-
`initialContent:` The content that should be in the editor when it's created, represented as an array of [partial block objects](/docs/manipulating-blocks#partial-blocks).
49+
`animations`: Whether changes to blocks (like indentation, creating lists, changing headings) should be animated or not. Defaults to `true`.
3950

40-
`domAttributes:` An object containing HTML attributes that should be added to various DOM elements in the editor. See [Adding DOM Attributes](/docs/theming#adding-dom-attributes) for more.
51+
`collaboration`: Options for enabling real-time collaboration. See [Real-time Collaboration](/docs/advanced/real-time-collaboration) for more info.
4152

4253
`defaultStyles`: Whether to use the default font and reset the styles of `<p>`, `<li>`, `<h1>`, etc. elements that are used in BlockNote. Defaults to true if undefined.
4354

44-
`uploadFile`: A function which handles file uploads and eventually returns the URL to the uploaded file. Used for [Image blocks](/docs/editor-basics/default-schema#image).
55+
`dictionary`: Provide strings for localization. See the [Localization / i18n example](/examples/basic/localization) and [Custom Placeholders](/examples/basic/custom-placeholder).
4556

46-
`collaboration`: Options for enabling real-time collaboration. See [Real-time Collaboration](/docs/advanced/real-time-collaboration) for more info.
57+
`disableExtensions` (_advanced_): Disables TipTap extensions used in BlockNote by default, based on their names.
4758

48-
`dictionary`: Provide strings for localization. See the [Localization / i18n example](/examples/basic/localization) and [Custom Placeholders](/examples/basic/custom-placeholder).
59+
`domAttributes:` An object containing HTML attributes that should be added to various DOM elements in the editor. See [Adding DOM Attributes](/docs/theming#adding-dom-attributes) for more.
60+
61+
`dropCursor`: A replacement indicator to use when dragging and dropping blocks. Uses the [ProseMirror drop cursor](https://github.com/ProseMirror/prosemirror-dropcursor), or a modified version when [Column Blocks](/docs/editor-basics/document-structure#column-blocks) are enabled.
62+
63+
`initialContent:` The content that should be in the editor when it's created, represented as an array of [Partial Blocks](/docs/manipulating-blocks#partial-blocks).
4964

50-
`schema` (_advanced_): The editor schema if you want to extend your editor with custom blocks, styles, or inline content [Custom Schemas](/docs/custom-schemas).
65+
`resolveFileUrl:` An async function that fetches the download URL of a file from an initial URL.
66+
67+
`schema`: The editor schema if you want to extend your editor with custom blocks, styles, or inline content [Custom Schemas](/docs/custom-schemas).
68+
69+
`setIdAttribute`: Whether to render an `id` HTML attribute on blocks as well as a `data-id` attribute. Defaults to `false`.
70+
71+
`sideMenuDetection`: Determines whether the mouse cursor position is locked to the editor bounding box for showing the [Block Side Menu](/docs/ui-components/side-menu) and block drag & drop. When set to `viewport`, the Side Menu will be shown next to the nearest block to the cursor, regardless of where it is in the viewport. Dropping blocks will also be locked to the editor bounding box. Otherwise, the Side Menu will only be shown when the cursor is within the editor bounds, and blocks can only be dropped when hovering the editor. In order to use multiple editors, must be set to `editor`. Defaults to `viewport`.
72+
73+
`tabBehavior`: Determines whether pressing the tab key should navigate the UI for keyboard accessibility or indent the current block. Defaults to `prefer-navigate-ui`.
5174

5275
`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.
5376

54-
`animations`: Whether changes to blocks (like indentation, creating lists, changing headings) should be animated or not. Defaults to `true`.
77+
`uploadFile`: A function which handles file uploads and eventually returns the URL to the uploaded file. Used for [Image blocks](/docs/editor-basics/default-schema#image).
5578

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

packages/core/src/editor/BlockNoteEditor.ts

Lines changed: 89 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -117,69 +117,6 @@ export type BlockNoteEditorOptions<
117117
*/
118118
animations?: boolean;
119119

120-
/**
121-
* Disable internal extensions (based on keys / extension name)
122-
*/
123-
disableExtensions: string[];
124-
125-
/**
126-
* A dictionary object containing translations for the editor.
127-
*/
128-
dictionary?: Dictionary & Record<string, any>;
129-
130-
/**
131-
* @deprecated, provide placeholders via dictionary instead
132-
*/
133-
placeholders: Record<
134-
string | "default" | "emptyDocument",
135-
string | undefined
136-
>;
137-
138-
/**
139-
* An object containing attributes that should be added to HTML elements of the editor.
140-
*
141-
* @example { editor: { class: "my-editor-class" } }
142-
*/
143-
domAttributes: Partial<BlockNoteDOMAttributes>;
144-
145-
/**
146-
* The content that should be in the editor when it's created, represented as an array of partial block objects.
147-
*/
148-
initialContent: PartialBlock<
149-
NoInfer<BSchema>,
150-
NoInfer<ISchema>,
151-
NoInfer<SSchema>
152-
>[];
153-
/**
154-
* Use default BlockNote font and reset the styles of <p> <li> <h1> elements etc., that are used in BlockNote.
155-
*
156-
* @default true
157-
*/
158-
defaultStyles: boolean;
159-
160-
schema: BlockNoteSchema<BSchema, ISchema, SSchema>;
161-
162-
/**
163-
* The `uploadFile` method is what the editor uses when files need to be uploaded (for example when selecting an image to upload).
164-
* This method should set when creating the editor as this is application-specific.
165-
*
166-
* `undefined` means the application doesn't support file uploads.
167-
*
168-
* @param file The file that should be uploaded.
169-
* @returns The URL of the uploaded file OR an object containing props that should be set on the file block (such as an id)
170-
*/
171-
uploadFile: (
172-
file: File,
173-
blockId?: string
174-
) => Promise<string | Record<string, any>>;
175-
176-
/**
177-
* Resolve a URL of a file block to one that can be displayed or downloaded. This can be used for creating authenticated URL or
178-
* implementing custom protocols / schemes
179-
* @returns The URL that's
180-
*/
181-
resolveFileUrl: (url: string) => Promise<string>;
182-
183120
/**
184121
* When enabled, allows for collaboration between multiple users.
185122
*/
@@ -213,25 +150,65 @@ export type BlockNoteEditorOptions<
213150
};
214151

215152
/**
216-
* additional tiptap options, undocumented
153+
* Use default BlockNote font and reset the styles of <p> <li> <h1> elements etc., that are used in BlockNote.
154+
*
155+
* @default true
217156
*/
218-
_tiptapOptions: Partial<EditorOptions>;
157+
defaultStyles: boolean;
219158

220159
/**
221-
* (experimental) add extra prosemirror plugins or tiptap extensions to the editor
160+
* A dictionary object containing translations for the editor.
222161
*/
223-
_extensions: Record<string, BlockNoteExtension | BlockNoteExtensionFactory>;
162+
dictionary?: Dictionary & Record<string, any>;
224163

225-
trailingBlock?: boolean;
164+
/**
165+
* Disable internal extensions (based on keys / extension name)
166+
*/
167+
disableExtensions: string[];
226168

227169
/**
228-
* Boolean indicating whether the editor is in headless mode.
229-
* Headless mode means we can use features like importing / exporting blocks,
230-
* but there's no underlying editor (UI) instantiated.
170+
* An object containing attributes that should be added to HTML elements of the editor.
231171
*
232-
* You probably don't need to set this manually, but use the `server-util` package instead that uses this option internally
172+
* @example { editor: { class: "my-editor-class" } }
233173
*/
234-
_headless: boolean;
174+
domAttributes: Partial<BlockNoteDOMAttributes>;
175+
176+
dropCursor?: (opts: {
177+
editor: BlockNoteEditor<
178+
NoInfer<BSchema>,
179+
NoInfer<ISchema>,
180+
NoInfer<SSchema>
181+
>;
182+
color?: string | false;
183+
width?: number;
184+
class?: string;
185+
}) => Plugin;
186+
187+
/**
188+
* The content that should be in the editor when it's created, represented as an array of partial block objects.
189+
*/
190+
initialContent: PartialBlock<
191+
NoInfer<BSchema>,
192+
NoInfer<ISchema>,
193+
NoInfer<SSchema>
194+
>[];
195+
196+
/**
197+
* @deprecated, provide placeholders via dictionary instead
198+
*/
199+
placeholders: Record<
200+
string | "default" | "emptyDocument",
201+
string | undefined
202+
>;
203+
204+
/**
205+
* Resolve a URL of a file block to one that can be displayed or downloaded. This can be used for creating authenticated URL or
206+
* implementing custom protocols / schemes
207+
* @returns The URL that's
208+
*/
209+
resolveFileUrl: (url: string) => Promise<string>;
210+
211+
schema: BlockNoteSchema<BSchema, ISchema, SSchema>;
235212

236213
/**
237214
* A flag indicating whether to set an HTML ID for every block
@@ -243,7 +220,14 @@ export type BlockNoteEditorOptions<
243220
*/
244221
setIdAttribute?: boolean;
245222

246-
dropCursor?: (opts: any) => Plugin;
223+
/**
224+
* The detection mode for showing the side menu - "viewport" always shows the
225+
* side menu for the block next to the mouse cursor, while "editor" only shows
226+
* it when hovering the editor or the side menu itself.
227+
*
228+
* @default "viewport"
229+
*/
230+
sideMenuDetection: "viewport" | "editor";
247231

248232
/**
249233
Select desired behavior when pressing `Tab` (or `Shift-Tab`). Specifically,
@@ -260,14 +244,40 @@ export type BlockNoteEditorOptions<
260244
*/
261245
tabBehavior: "prefer-navigate-ui" | "prefer-indent";
262246

247+
trailingBlock?: boolean;
248+
263249
/**
264-
* The detection mode for showing the side menu - "viewport" always shows the
265-
* side menu for the block next to the mouse cursor, while "editor" only shows
266-
* it when hovering the editor or the side menu itself.
250+
* The `uploadFile` method is what the editor uses when files need to be uploaded (for example when selecting an image to upload).
251+
* This method should set when creating the editor as this is application-specific.
267252
*
268-
* @default "viewport"
253+
* `undefined` means the application doesn't support file uploads.
254+
*
255+
* @param file The file that should be uploaded.
256+
* @returns The URL of the uploaded file OR an object containing props that should be set on the file block (such as an id)
269257
*/
270-
sideMenuDetection: "viewport" | "editor";
258+
uploadFile: (
259+
file: File,
260+
blockId?: string
261+
) => Promise<string | Record<string, any>>;
262+
263+
/**
264+
* additional tiptap options, undocumented
265+
*/
266+
_tiptapOptions: Partial<EditorOptions>;
267+
268+
/**
269+
* (experimental) add extra prosemirror plugins or tiptap extensions to the editor
270+
*/
271+
_extensions: Record<string, BlockNoteExtension | BlockNoteExtensionFactory>;
272+
273+
/**
274+
* Boolean indicating whether the editor is in headless mode.
275+
* Headless mode means we can use features like importing / exporting blocks,
276+
* but there's no underlying editor (UI) instantiated.
277+
*
278+
* You probably don't need to set this manually, but use the `server-util` package instead that uses this option internally
279+
*/
280+
_headless: boolean;
271281
};
272282

273283
const blockNoteTipTapOptions = {

0 commit comments

Comments
 (0)