@blocknote/core 0.7.1-alpha.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/blocknote.js +1428 -1252
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +2 -2
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/style.css +1 -1
  6. package/package.json +3 -3
  7. package/src/BlockNoteEditor.ts +100 -53
  8. package/src/BlockNoteExtensions.ts +24 -14
  9. package/src/api/blockManipulation/blockManipulation.test.ts +6 -3
  10. package/src/api/blockManipulation/blockManipulation.ts +7 -6
  11. package/src/api/formatConversions/formatConversions.test.ts +13 -8
  12. package/src/api/formatConversions/formatConversions.ts +15 -12
  13. package/src/api/nodeConversions/nodeConversions.test.ts +29 -10
  14. package/src/api/nodeConversions/nodeConversions.ts +33 -12
  15. package/src/api/nodeConversions/testUtil.ts +8 -4
  16. package/src/editor.module.css +0 -1
  17. package/src/extensions/Blocks/api/block.ts +229 -0
  18. package/src/extensions/Blocks/api/blockTypes.ts +158 -71
  19. package/src/extensions/Blocks/api/cursorPositionTypes.ts +5 -5
  20. package/src/extensions/Blocks/api/defaultBlocks.ts +44 -0
  21. package/src/extensions/Blocks/api/selectionTypes.ts +3 -3
  22. package/src/extensions/Blocks/api/serialization.ts +29 -0
  23. package/src/extensions/Blocks/index.ts +0 -8
  24. package/src/extensions/Blocks/nodes/Block.module.css +24 -12
  25. package/src/extensions/Blocks/nodes/BlockContainer.ts +8 -4
  26. package/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.ts +4 -4
  27. package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +5 -5
  28. package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +100 -97
  29. package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +4 -4
  30. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +11 -9
  31. package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +6 -5
  32. package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +12 -11
  33. package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +21 -16
  34. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +9 -5
  35. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +30 -42
  36. package/src/extensions/Placeholder/PlaceholderExtension.ts +1 -0
  37. package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +5 -2
  38. package/src/extensions/SlashMenu/SlashMenuExtension.ts +37 -33
  39. package/src/extensions/SlashMenu/defaultSlashMenuItems.tsx +14 -10
  40. package/src/extensions/SlashMenu/index.ts +2 -2
  41. package/src/index.ts +4 -0
  42. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +29 -13
  43. package/types/src/BlockNoteEditor.d.ts +37 -23
  44. package/types/src/BlockNoteExtensions.d.ts +15 -8
  45. package/types/src/api/blockManipulation/blockManipulation.d.ts +4 -4
  46. package/types/src/api/formatConversions/formatConversions.d.ts +5 -5
  47. package/types/src/api/nodeConversions/nodeConversions.d.ts +3 -3
  48. package/types/src/api/nodeConversions/testUtil.d.ts +2 -2
  49. package/types/src/extensions/Blocks/api/block.d.ts +2 -4
  50. package/types/src/extensions/Blocks/api/blockTypes.d.ts +77 -33
  51. package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +5 -5
  52. package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +4 -4
  53. package/types/src/extensions/Blocks/api/selectionTypes.d.ts +3 -3
  54. package/types/src/extensions/Blocks/api/serialization.d.ts +2 -0
  55. package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +3 -3
  56. package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +1 -2
  57. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +1 -2
  58. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +1 -2
  59. package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +1 -2
  60. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +7 -7
  61. package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +5 -4
  62. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +11 -10
  63. package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +6 -5
  64. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +4 -3
  65. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +16 -19
  66. package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +4 -3
  67. package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +5 -4
  68. package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +66 -1
  69. package/types/src/extensions/SlashMenu/index.d.ts +2 -2
  70. package/types/src/index.d.ts +4 -0
  71. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +5 -4
@@ -4,46 +4,50 @@ import { createSuggestionPlugin } from "../../shared/plugins/suggestion/Suggesti
4
4
  import { SuggestionsMenuFactory } from "../../shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
5
5
  import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
6
6
  import { BlockNoteEditor } from "../../BlockNoteEditor";
7
+ import { BlockSchema } from "../Blocks/api/blockTypes";
7
8
 
8
- export type SlashMenuOptions = {
9
- editor: BlockNoteEditor | undefined;
10
- commands: BaseSlashMenuItem[] | undefined;
9
+ export type SlashMenuOptions<BSchema extends BlockSchema> = {
10
+ editor: BlockNoteEditor<BSchema> | undefined;
11
+ commands: BaseSlashMenuItem<BSchema>[] | undefined;
11
12
  slashMenuFactory: SuggestionsMenuFactory<any> | undefined;
12
13
  };
13
14
 
14
15
  export const SlashMenuPluginKey = new PluginKey("suggestions-slash-commands");
15
16
 
16
- export const SlashMenuExtension = Extension.create<SlashMenuOptions>({
17
- name: "slash-command",
17
+ export const createSlashMenuExtension = <BSchema extends BlockSchema>() =>
18
+ Extension.create<SlashMenuOptions<BSchema>>({
19
+ name: "slash-command",
18
20
 
19
- addOptions() {
20
- return {
21
- editor: undefined,
22
- commands: undefined,
23
- slashMenuFactory: undefined,
24
- };
25
- },
21
+ addOptions() {
22
+ return {
23
+ editor: undefined,
24
+ commands: undefined,
25
+ slashMenuFactory: undefined,
26
+ };
27
+ },
26
28
 
27
- addProseMirrorPlugins() {
28
- if (!this.options.slashMenuFactory || !this.options.commands) {
29
- throw new Error("required args not defined for SlashMenuExtension");
30
- }
29
+ addProseMirrorPlugins() {
30
+ if (!this.options.slashMenuFactory || !this.options.commands) {
31
+ throw new Error("required args not defined for SlashMenuExtension");
32
+ }
31
33
 
32
- const commands = this.options.commands;
34
+ const commands = this.options.commands;
33
35
 
34
- return [
35
- createSuggestionPlugin<BaseSlashMenuItem>({
36
- pluginKey: SlashMenuPluginKey,
37
- editor: this.options.editor!,
38
- defaultTriggerCharacter: "/",
39
- suggestionsMenuFactory: this.options.slashMenuFactory!,
40
- items: (query) => {
41
- return commands.filter((cmd: BaseSlashMenuItem) => cmd.match(query));
42
- },
43
- onSelectItem: ({ item, editor }) => {
44
- item.execute(editor);
45
- },
46
- }),
47
- ];
48
- },
49
- });
36
+ return [
37
+ createSuggestionPlugin<BaseSlashMenuItem<BSchema>, BSchema>({
38
+ pluginKey: SlashMenuPluginKey,
39
+ editor: this.options.editor!,
40
+ defaultTriggerCharacter: "/",
41
+ suggestionsMenuFactory: this.options.slashMenuFactory!,
42
+ items: (query) => {
43
+ return commands.filter((cmd: BaseSlashMenuItem<BSchema>) =>
44
+ cmd.match(query)
45
+ );
46
+ },
47
+ onSelectItem: ({ item, editor }) => {
48
+ item.execute(editor);
49
+ },
50
+ }),
51
+ ];
52
+ },
53
+ });
@@ -1,8 +1,12 @@
1
- import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
2
- import { PartialBlock } from "../Blocks/api/blockTypes";
3
1
  import { BlockNoteEditor } from "../../BlockNoteEditor";
2
+ import { PartialBlock } from "../Blocks/api/blockTypes";
3
+ import { DefaultBlockSchema } from "../Blocks/api/defaultBlocks";
4
+ import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
4
5
 
5
- function insertOrUpdateBlock(editor: BlockNoteEditor, block: PartialBlock) {
6
+ function insertOrUpdateBlock<BSchema extends DefaultBlockSchema>(
7
+ editor: BlockNoteEditor<BSchema>,
8
+ block: PartialBlock<BSchema>
9
+ ) {
6
10
  const currentBlock = editor.getTextCursorPosition().block;
7
11
 
8
12
  if (
@@ -21,9 +25,9 @@ function insertOrUpdateBlock(editor: BlockNoteEditor, block: PartialBlock) {
21
25
  /**
22
26
  * An array containing commands for creating all default blocks.
23
27
  */
24
- export const defaultSlashMenuItems: BaseSlashMenuItem[] = [
28
+ export const defaultSlashMenuItems = [
25
29
  // Command for creating a level 1 heading
26
- new BaseSlashMenuItem(
30
+ new BaseSlashMenuItem<DefaultBlockSchema>(
27
31
  "Heading",
28
32
  (editor) =>
29
33
  insertOrUpdateBlock(editor, {
@@ -34,7 +38,7 @@ export const defaultSlashMenuItems: BaseSlashMenuItem[] = [
34
38
  ),
35
39
 
36
40
  // Command for creating a level 2 heading
37
- new BaseSlashMenuItem(
41
+ new BaseSlashMenuItem<DefaultBlockSchema>(
38
42
  "Heading 2",
39
43
  (editor) =>
40
44
  insertOrUpdateBlock(editor, {
@@ -45,7 +49,7 @@ export const defaultSlashMenuItems: BaseSlashMenuItem[] = [
45
49
  ),
46
50
 
47
51
  // Command for creating a level 3 heading
48
- new BaseSlashMenuItem(
52
+ new BaseSlashMenuItem<DefaultBlockSchema>(
49
53
  "Heading 3",
50
54
  (editor) =>
51
55
  insertOrUpdateBlock(editor, {
@@ -56,7 +60,7 @@ export const defaultSlashMenuItems: BaseSlashMenuItem[] = [
56
60
  ),
57
61
 
58
62
  // Command for creating an ordered list
59
- new BaseSlashMenuItem(
63
+ new BaseSlashMenuItem<DefaultBlockSchema>(
60
64
  "Numbered List",
61
65
  (editor) =>
62
66
  insertOrUpdateBlock(editor, {
@@ -66,7 +70,7 @@ export const defaultSlashMenuItems: BaseSlashMenuItem[] = [
66
70
  ),
67
71
 
68
72
  // Command for creating a bullet list
69
- new BaseSlashMenuItem(
73
+ new BaseSlashMenuItem<DefaultBlockSchema>(
70
74
  "Bullet List",
71
75
  (editor) =>
72
76
  insertOrUpdateBlock(editor, {
@@ -76,7 +80,7 @@ export const defaultSlashMenuItems: BaseSlashMenuItem[] = [
76
80
  ),
77
81
 
78
82
  // Command for creating a paragraph (pretty useless)
79
- new BaseSlashMenuItem(
83
+ new BaseSlashMenuItem<DefaultBlockSchema>(
80
84
  "Paragraph",
81
85
  (editor) =>
82
86
  insertOrUpdateBlock(editor, {
@@ -1,5 +1,5 @@
1
1
  import { defaultSlashMenuItems } from "./defaultSlashMenuItems";
2
- import { SlashMenuExtension } from "./SlashMenuExtension";
2
+ import { createSlashMenuExtension } from "./SlashMenuExtension";
3
3
  import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
4
4
 
5
- export { defaultSlashMenuItems, BaseSlashMenuItem, SlashMenuExtension };
5
+ export { defaultSlashMenuItems, BaseSlashMenuItem, createSlashMenuExtension };
package/src/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from "./BlockNoteEditor";
2
2
  export * from "./BlockNoteExtensions";
3
+ export * from "./extensions/Blocks/api/block";
3
4
  export * from "./extensions/Blocks/api/blockTypes";
5
+ export * from "./extensions/Blocks/api/defaultBlocks";
4
6
  export * from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
5
7
  export * from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
6
8
  export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
@@ -10,3 +12,5 @@ export * from "./shared/EditorElement";
10
12
  export type { SuggestionItem } from "./shared/plugins/suggestion/SuggestionItem";
11
13
  export * from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
12
14
  export * from "./extensions/Blocks/api/inlineContentTypes";
15
+ export * from "./extensions/Blocks/api/serialization";
16
+ export * as blockStyles from "./extensions/Blocks/nodes/Block.module.css";
@@ -10,8 +10,12 @@ import {
10
10
  } from "./SuggestionsMenuFactoryTypes";
11
11
  import { SuggestionItem } from "./SuggestionItem";
12
12
  import { BlockNoteEditor } from "../../../BlockNoteEditor";
13
+ import { BlockSchema } from "../../../extensions/Blocks/api/blockTypes";
13
14
 
14
- export type SuggestionPluginOptions<T extends SuggestionItem> = {
15
+ export type SuggestionPluginOptions<
16
+ T extends SuggestionItem,
17
+ BSchema extends BlockSchema
18
+ > = {
15
19
  /**
16
20
  * The name of the plugin.
17
21
  *
@@ -22,7 +26,7 @@ export type SuggestionPluginOptions<T extends SuggestionItem> = {
22
26
  /**
23
27
  * The BlockNote editor.
24
28
  */
25
- editor: BlockNoteEditor;
29
+ editor: BlockNoteEditor<BSchema>;
26
30
 
27
31
  /**
28
32
  * The character that should trigger the suggestion menu to pop up (e.g. a '/' for commands), when typed by the user.
@@ -38,7 +42,7 @@ export type SuggestionPluginOptions<T extends SuggestionItem> = {
38
42
  * this should be done manually. The `editor` and `range` properties passed
39
43
  * to the callback function might come in handy when doing this.
40
44
  */
41
- onSelectItem?: (props: { item: T; editor: BlockNoteEditor }) => void;
45
+ onSelectItem?: (props: { item: T; editor: BlockNoteEditor<BSchema> }) => void;
42
46
 
43
47
  /**
44
48
  * A function that should supply the plugin with items to suggest, based on a certain query string.
@@ -81,15 +85,21 @@ function getDefaultPluginState<
81
85
  };
82
86
  }
83
87
 
84
- type SuggestionPluginViewOptions<T extends SuggestionItem> = {
85
- editor: BlockNoteEditor;
88
+ type SuggestionPluginViewOptions<
89
+ T extends SuggestionItem,
90
+ BSchema extends BlockSchema
91
+ > = {
92
+ editor: BlockNoteEditor<BSchema>;
86
93
  pluginKey: PluginKey;
87
- onSelectItem: (props: { item: T; editor: BlockNoteEditor }) => void;
94
+ onSelectItem: (props: { item: T; editor: BlockNoteEditor<BSchema> }) => void;
88
95
  suggestionsMenuFactory: SuggestionsMenuFactory<T>;
89
96
  };
90
97
 
91
- class SuggestionPluginView<T extends SuggestionItem> {
92
- editor: BlockNoteEditor;
98
+ class SuggestionPluginView<
99
+ T extends SuggestionItem,
100
+ BSchema extends BlockSchema
101
+ > {
102
+ editor: BlockNoteEditor<BSchema>;
93
103
  pluginKey: PluginKey;
94
104
 
95
105
  suggestionsMenu: SuggestionsMenu<T>;
@@ -102,7 +112,7 @@ class SuggestionPluginView<T extends SuggestionItem> {
102
112
  pluginKey,
103
113
  onSelectItem: selectItemCallback = () => {},
104
114
  suggestionsMenuFactory,
105
- }: SuggestionPluginViewOptions<T>) {
115
+ }: SuggestionPluginViewOptions<T, BSchema>) {
106
116
  this.editor = editor;
107
117
  this.pluginKey = pluginKey;
108
118
 
@@ -214,14 +224,17 @@ class SuggestionPluginView<T extends SuggestionItem> {
214
224
  * @param options options for configuring the plugin
215
225
  * @returns the prosemirror plugin
216
226
  */
217
- export function createSuggestionPlugin<T extends SuggestionItem>({
227
+ export function createSuggestionPlugin<
228
+ T extends SuggestionItem,
229
+ BSchema extends BlockSchema
230
+ >({
218
231
  pluginKey,
219
232
  editor,
220
233
  defaultTriggerCharacter,
221
234
  suggestionsMenuFactory,
222
235
  onSelectItem: selectItemCallback = () => {},
223
236
  items = () => [],
224
- }: SuggestionPluginOptions<T>) {
237
+ }: SuggestionPluginOptions<T, BSchema>) {
225
238
  // Assertions
226
239
  if (defaultTriggerCharacter.length !== 1) {
227
240
  throw new Error("'char' should be a single character");
@@ -236,10 +249,13 @@ export function createSuggestionPlugin<T extends SuggestionItem>({
236
249
  key: pluginKey,
237
250
 
238
251
  view: (view: EditorView) =>
239
- new SuggestionPluginView({
252
+ new SuggestionPluginView<T, BSchema>({
240
253
  editor: editor,
241
254
  pluginKey: pluginKey,
242
- onSelectItem: (props: { item: T; editor: BlockNoteEditor }) => {
255
+ onSelectItem: (props: {
256
+ item: T;
257
+ editor: BlockNoteEditor<BSchema>;
258
+ }) => {
243
259
  deactivate(view);
244
260
  selectItemCallback(props);
245
261
  },
@@ -1,24 +1,28 @@
1
+ import { Node } from "prosemirror-model";
1
2
  import { Editor as TiptapEditor } from "@tiptap/core/dist/packages/core/src/Editor";
2
3
  import * as Y from "yjs";
3
4
  import { UiFactories } from "./BlockNoteExtensions";
4
- import { Block, BlockIdentifier, PartialBlock } from "./extensions/Blocks/api/blockTypes";
5
+ import { Block, BlockIdentifier, BlockSchema, PartialBlock } from "./extensions/Blocks/api/blockTypes";
5
6
  import { TextCursorPosition } from "./extensions/Blocks/api/cursorPositionTypes";
7
+ import { DefaultBlockSchema } from "./extensions/Blocks/api/defaultBlocks";
6
8
  import { Styles } from "./extensions/Blocks/api/inlineContentTypes";
7
9
  import { Selection } from "./extensions/Blocks/api/selectionTypes";
8
10
  import { BaseSlashMenuItem } from "./extensions/SlashMenu";
9
- export type BlockNoteEditorOptions = {
11
+ export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
10
12
  enableBlockNoteExtensions: boolean;
11
13
  /**
12
14
  * UI element factories for creating a custom UI, including custom positioning
13
15
  * & rendering.
14
16
  */
15
- uiFactories: UiFactories;
17
+ uiFactories: UiFactories<BSchema>;
16
18
  /**
17
19
  * TODO: why is this called slashCommands and not slashMenuItems?
18
20
  *
21
+ * (couldn't fix any type, see https://github.com/TypeCellOS/BlockNote/pull/191#discussion_r1210708771)
22
+ *
19
23
  * @default defaultSlashMenuItems from `./extensions/SlashMenu`
20
24
  */
21
- slashCommands: BaseSlashMenuItem[];
25
+ slashCommands: BaseSlashMenuItem<any>[];
22
26
  /**
23
27
  * The HTML element that should be used as the parent element for the editor.
24
28
  *
@@ -34,15 +38,15 @@ export type BlockNoteEditorOptions = {
34
38
  /**
35
39
  * A callback function that runs when the editor is ready to be used.
36
40
  */
37
- onEditorReady: (editor: BlockNoteEditor) => void;
41
+ onEditorReady: (editor: BlockNoteEditor<BSchema>) => void;
38
42
  /**
39
43
  * A callback function that runs whenever the editor's contents change.
40
44
  */
41
- onEditorContentChange: (editor: BlockNoteEditor) => void;
45
+ onEditorContentChange: (editor: BlockNoteEditor<BSchema>) => void;
42
46
  /**
43
47
  * A callback function that runs whenever the text cursor position changes.
44
48
  */
45
- onTextCursorPositionChange: (editor: BlockNoteEditor) => void;
49
+ onTextCursorPositionChange: (editor: BlockNoteEditor<BSchema>) => void;
46
50
  /**
47
51
  * Locks the editor from being editable by the user if set to `false`.
48
52
  */
@@ -50,7 +54,7 @@ export type BlockNoteEditorOptions = {
50
54
  /**
51
55
  * The content that should be in the editor when it's created, represented as an array of partial block objects.
52
56
  */
53
- initialContent: PartialBlock[];
57
+ initialContent: PartialBlock<BSchema>[];
54
58
  /**
55
59
  * Use default BlockNote font and reset the styles of <p> <li> <h1> elements etc., that are used in BlockNote.
56
60
  *
@@ -63,6 +67,10 @@ export type BlockNoteEditorOptions = {
63
67
  * @default "light"
64
68
  */
65
69
  theme: "light" | "dark";
70
+ /**
71
+ * A list of block types that should be available in the editor.
72
+ */
73
+ blockSchema: BSchema;
66
74
  /**
67
75
  * When enabled, allows for collaboration between multiple users.
68
76
  */
@@ -89,37 +97,43 @@ export type BlockNoteEditorOptions = {
89
97
  };
90
98
  _tiptapOptions: any;
91
99
  };
92
- export declare class BlockNoteEditor {
100
+ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
93
101
  private readonly options;
94
102
  readonly _tiptapEditor: TiptapEditor & {
95
103
  contentComponent: any;
96
104
  };
97
- private blockCache;
105
+ blockCache: WeakMap<Node, Block<BSchema>>;
106
+ readonly schema: BSchema;
98
107
  get domElement(): HTMLDivElement;
99
108
  focus(): void;
100
- constructor(options?: Partial<BlockNoteEditorOptions>);
109
+ constructor(options?: Partial<BlockNoteEditorOptions<BSchema>>);
101
110
  /**
102
111
  * Gets a snapshot of all top-level (non-nested) blocks in the editor.
103
112
  * @returns A snapshot of all top-level (non-nested) blocks in the editor.
104
113
  */
105
- get topLevelBlocks(): Block[];
114
+ get topLevelBlocks(): Block<BSchema>[];
106
115
  /**
107
116
  * Gets a snapshot of an existing block from the editor.
108
117
  * @param blockIdentifier The identifier of an existing block that should be retrieved.
109
118
  * @returns The block that matches the identifier, or `undefined` if no matching block was found.
110
119
  */
111
- getBlock(blockIdentifier: BlockIdentifier): Block | undefined;
120
+ getBlock(blockIdentifier: BlockIdentifier): Block<BSchema> | undefined;
112
121
  /**
113
122
  * Traverses all blocks in the editor depth-first, and executes a callback for each.
114
123
  * @param callback The callback to execute for each block. Returning `false` stops the traversal.
115
124
  * @param reverse Whether the blocks should be traversed in reverse order.
116
125
  */
117
- forEachBlock(callback: (block: Block) => boolean, reverse?: boolean): void;
126
+ forEachBlock(callback: (block: Block<BSchema>) => boolean, reverse?: boolean): void;
127
+ /**
128
+ * Executes a callback whenever the editor's contents change.
129
+ * @param callback The callback to execute.
130
+ */
131
+ onEditorContentChange(callback: () => void): void;
118
132
  /**
119
133
  * Gets a snapshot of the current text cursor position.
120
134
  * @returns A snapshot of the current text cursor position.
121
135
  */
122
- getTextCursorPosition(): TextCursorPosition;
136
+ getTextCursorPosition(): TextCursorPosition<BSchema>;
123
137
  /**
124
138
  * Sets the text cursor position to the start or end of an existing block. Throws an error if the target block could
125
139
  * not be found.
@@ -130,7 +144,7 @@ export declare class BlockNoteEditor {
130
144
  /**
131
145
  * Gets a snapshot of the current selection.
132
146
  */
133
- getSelection(): Selection | undefined;
147
+ getSelection(): Selection<BSchema> | undefined;
134
148
  /**
135
149
  * Checks if the editor is currently editable, or if it's locked.
136
150
  * @returns True if the editor is editable, false otherwise.
@@ -149,7 +163,7 @@ export declare class BlockNoteEditor {
149
163
  * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
150
164
  * `referenceBlock`. Inserts the blocks at the start of the existing block's children if "nested" is used.
151
165
  */
152
- insertBlocks(blocksToInsert: PartialBlock[], referenceBlock: BlockIdentifier, placement?: "before" | "after" | "nested"): void;
166
+ insertBlocks(blocksToInsert: PartialBlock<BSchema>[], referenceBlock: BlockIdentifier, placement?: "before" | "after" | "nested"): void;
153
167
  /**
154
168
  * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
155
169
  * defined. These undefined fields are kept as-is from the existing block. Throws an error if the block to update could
@@ -157,7 +171,7 @@ export declare class BlockNoteEditor {
157
171
  * @param blockToUpdate The block that should be updated.
158
172
  * @param update A partial block which defines how the existing block should be changed.
159
173
  */
160
- updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock): void;
174
+ updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema>): void;
161
175
  /**
162
176
  * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
163
177
  * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
@@ -170,7 +184,7 @@ export declare class BlockNoteEditor {
170
184
  * @param blocksToRemove An array of blocks that should be replaced.
171
185
  * @param blocksToInsert An array of partial blocks to replace the old ones with.
172
186
  */
173
- replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock[]): void;
187
+ replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock<BSchema>[]): void;
174
188
  /**
175
189
  * Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
176
190
  */
@@ -226,7 +240,7 @@ export declare class BlockNoteEditor {
226
240
  * @param blocks An array of blocks that should be serialized into HTML.
227
241
  * @returns The blocks, serialized as an HTML string.
228
242
  */
229
- blocksToHTML(blocks: Block[]): Promise<string>;
243
+ blocksToHTML(blocks: Block<BSchema>[]): Promise<string>;
230
244
  /**
231
245
  * Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
232
246
  * `InlineNode` objects from any HTML inline elements, though not all element types are recognized. If BlockNote
@@ -234,14 +248,14 @@ export declare class BlockNoteEditor {
234
248
  * @param html The HTML string to parse blocks from.
235
249
  * @returns The blocks parsed from the HTML string.
236
250
  */
237
- HTMLToBlocks(html: string): Promise<Block[]>;
251
+ HTMLToBlocks(html: string): Promise<Block<BSchema>[]>;
238
252
  /**
239
253
  * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
240
254
  * BlockNote - children of blocks which aren't list items are un-nested and certain styles are removed.
241
255
  * @param blocks An array of blocks that should be serialized into Markdown.
242
256
  * @returns The blocks, serialized as a Markdown string.
243
257
  */
244
- blocksToMarkdown(blocks: Block[]): Promise<string>;
258
+ blocksToMarkdown(blocks: Block<BSchema>[]): Promise<string>;
245
259
  /**
246
260
  * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
247
261
  * Markdown syntax, though not all symbols are recognized. If BlockNote doesn't recognize a symbol, it will parse it
@@ -249,7 +263,7 @@ export declare class BlockNoteEditor {
249
263
  * @param markdown The Markdown string to parse blocks from.
250
264
  * @returns The blocks parsed from the Markdown string.
251
265
  */
252
- markdownToBlocks(markdown: string): Promise<Block[]>;
266
+ markdownToBlocks(markdown: string): Promise<Block<BSchema>[]>;
253
267
  /**
254
268
  * Updates the user info for the current user that's shown to other collaborators.
255
269
  */
@@ -1,24 +1,31 @@
1
1
  import { Extensions } from "@tiptap/core";
2
2
  import { BlockNoteEditor } from "./BlockNoteEditor";
3
3
  import * as Y from "yjs";
4
+ import { BlockSchema } from "./extensions/Blocks/api/blockTypes";
4
5
  import { BlockSideMenuFactory } from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
5
6
  import { FormattingToolbarFactory } from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
6
7
  import { HyperlinkToolbarFactory } from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
7
8
  import { BaseSlashMenuItem } from "./extensions/SlashMenu";
8
9
  import { SuggestionsMenuFactory } from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
9
- export type UiFactories = Partial<{
10
- formattingToolbarFactory: FormattingToolbarFactory;
10
+ export type UiFactories<BSchema extends BlockSchema> = Partial<{
11
+ formattingToolbarFactory: FormattingToolbarFactory<BSchema>;
11
12
  hyperlinkToolbarFactory: HyperlinkToolbarFactory;
12
- slashMenuFactory: SuggestionsMenuFactory<BaseSlashMenuItem>;
13
- blockSideMenuFactory: BlockSideMenuFactory;
13
+ slashMenuFactory: SuggestionsMenuFactory<BaseSlashMenuItem<BSchema>>;
14
+ blockSideMenuFactory: BlockSideMenuFactory<BSchema>;
14
15
  }>;
15
16
  /**
16
17
  * Get all the Tiptap extensions BlockNote is configured with by default
17
18
  */
18
- export declare const getBlockNoteExtensions: (opts: {
19
- editor: BlockNoteEditor;
20
- uiFactories: UiFactories;
21
- slashCommands: BaseSlashMenuItem[];
19
+ export declare const getBlockNoteExtensions: <BSchema extends Record<string, import("./extensions/Blocks/api/blockTypes").BlockSpec<string, import("./extensions/Blocks/api/blockTypes").PropSchema>>>(opts: {
20
+ editor: BlockNoteEditor<BSchema>;
21
+ uiFactories: Partial<{
22
+ formattingToolbarFactory: FormattingToolbarFactory<BSchema>;
23
+ hyperlinkToolbarFactory: HyperlinkToolbarFactory;
24
+ slashMenuFactory: SuggestionsMenuFactory<BaseSlashMenuItem<BSchema>>;
25
+ blockSideMenuFactory: BlockSideMenuFactory<BSchema>;
26
+ }>;
27
+ slashCommands: BaseSlashMenuItem<any>[];
28
+ blockSchema: BSchema;
22
29
  collaboration?: {
23
30
  fragment: Y.XmlFragment;
24
31
  user: {
@@ -1,6 +1,6 @@
1
1
  import { Editor } from "@tiptap/core";
2
- import { BlockIdentifier, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
3
- export declare function insertBlocks(blocksToInsert: PartialBlock[], referenceBlock: BlockIdentifier, placement: "before" | "after" | "nested" | undefined, editor: Editor): void;
4
- export declare function updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock, editor: Editor): void;
2
+ import { BlockIdentifier, BlockSchema, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
3
+ export declare function insertBlocks<BSchema extends BlockSchema>(blocksToInsert: PartialBlock<BSchema>[], referenceBlock: BlockIdentifier, placement: "before" | "after" | "nested" | undefined, editor: Editor): void;
4
+ export declare function updateBlock<BSchema extends BlockSchema>(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema>, editor: Editor): void;
5
5
  export declare function removeBlocks(blocksToRemove: BlockIdentifier[], editor: Editor): void;
6
- export declare function replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock[], editor: Editor): void;
6
+ export declare function replaceBlocks<BSchema extends BlockSchema>(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock<BSchema>[], editor: Editor): void;
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "prosemirror-model";
2
- import { Block } from "../../extensions/Blocks/api/blockTypes";
3
- export declare function blocksToHTML(blocks: Block[], schema: Schema): Promise<string>;
4
- export declare function HTMLToBlocks(html: string, schema: Schema): Promise<Block[]>;
5
- export declare function blocksToMarkdown(blocks: Block[], schema: Schema): Promise<string>;
6
- export declare function markdownToBlocks(markdown: string, schema: Schema): Promise<Block[]>;
2
+ import { Block, BlockSchema } from "../../extensions/Blocks/api/blockTypes";
3
+ export declare function blocksToHTML<BSchema extends BlockSchema>(blocks: Block<BSchema>[], schema: Schema): Promise<string>;
4
+ export declare function HTMLToBlocks<BSchema extends BlockSchema>(html: string, blockSchema: BSchema, schema: Schema): Promise<Block<BSchema>[]>;
5
+ export declare function blocksToMarkdown<BSchema extends BlockSchema>(blocks: Block<BSchema>[], schema: Schema): Promise<string>;
6
+ export declare function markdownToBlocks<BSchema extends BlockSchema>(markdown: string, blockSchema: BSchema, schema: Schema): Promise<Block<BSchema>[]>;
@@ -1,5 +1,5 @@
1
1
  import { Node, Schema } from "prosemirror-model";
2
- import { Block, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
2
+ import { Block, BlockSchema, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
3
3
  import { PartialInlineContent } from "../../extensions/Blocks/api/inlineContentTypes";
4
4
  /**
5
5
  * converts an array of inline content elements to prosemirror nodes
@@ -8,8 +8,8 @@ export declare function inlineContentToNodes(blockContent: PartialInlineContent[
8
8
  /**
9
9
  * Converts a BlockNote block to a TipTap node.
10
10
  */
11
- export declare function blockToNode(block: PartialBlock, schema: Schema): Node;
11
+ export declare function blockToNode<BSchema extends BlockSchema>(block: PartialBlock<BSchema>, schema: Schema): Node;
12
12
  /**
13
13
  * Convert a TipTap node to a BlockNote block.
14
14
  */
15
- export declare function nodeToBlock(node: Node, blockCache?: WeakMap<Node, Block>): Block;
15
+ export declare function nodeToBlock<BSchema extends BlockSchema>(node: Node, blockSchema: BSchema, blockCache?: WeakMap<Node, Block<BSchema>>): Block<BSchema>;
@@ -1,2 +1,2 @@
1
- import { Block, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
2
- export declare function partialBlockToBlockForTesting(partialBlock: PartialBlock): Block;
1
+ import { Block, BlockSchema, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
2
+ export declare function partialBlockToBlockForTesting<BSchema extends BlockSchema>(partialBlock: PartialBlock<BSchema>): Block<BSchema>;
@@ -1,9 +1,8 @@
1
- import { Attribute, Extension } from "@tiptap/core";
1
+ import { Attribute } from "@tiptap/core";
2
2
  import { BlockConfig, BlockSchema, BlockSpec, PropSchema, TipTapNode, TipTapNodeConfig } from "./blockTypes";
3
+ export declare function camelToDataKebab(str: string): string;
3
4
  export declare function propsToAttributes<BType extends string, PSchema extends PropSchema, ContainsInlineContent extends boolean, BSchema extends BlockSchema>(blockConfig: Omit<BlockConfig<BType, PSchema, ContainsInlineContent, BSchema>, "render">): Record<string, Attribute>;
4
5
  export declare function parse<BType extends string, PSchema extends PropSchema, ContainsInlineContent extends boolean, BSchema extends BlockSchema>(blockConfig: Omit<BlockConfig<BType, PSchema, ContainsInlineContent, BSchema>, "render">): {
5
- getAttrs: (node: HTMLElement | string) => false | import("./blockTypes").Props<PSchema>;
6
- }[] | {
7
6
  tag: string;
8
7
  }[];
9
8
  export declare function render<BType extends string, PSchema extends PropSchema, ContainsInlineContent extends boolean, BSchema extends BlockSchema>(blockConfig: Omit<BlockConfig<BType, PSchema, ContainsInlineContent, BSchema>, "render">, HTMLAttributes: Record<string, any>): {
@@ -15,4 +14,3 @@ export declare function render<BType extends string, PSchema extends PropSchema,
15
14
  };
16
15
  export declare function createBlockSpec<BType extends string, PSchema extends PropSchema, ContainsInlineContent extends boolean, BSchema extends BlockSchema>(blockConfig: BlockConfig<BType, PSchema, ContainsInlineContent, BSchema>): BlockSpec<BType, PSchema>;
17
16
  export declare function createTipTapBlock<Type extends string>(config: TipTapNodeConfig<Type>): TipTapNode<Type>;
18
- export declare const CustomBlockSerializerExtension: Extension<any, any>;