@blocknote/core 0.7.1-alpha.0 → 0.8.1

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 (77) hide show
  1. package/dist/blocknote.js +1711 -1469
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +6 -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 +104 -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/__snapshots__/nodeConversions.test.ts.snap +292 -0
  14. package/src/api/nodeConversions/nodeConversions.test.ts +265 -10
  15. package/src/api/nodeConversions/nodeConversions.ts +199 -47
  16. package/src/api/nodeConversions/testUtil.ts +8 -4
  17. package/src/editor.module.css +5 -6
  18. package/src/extensions/Blocks/api/block.ts +229 -0
  19. package/src/extensions/Blocks/api/blockTypes.ts +158 -71
  20. package/src/extensions/Blocks/api/cursorPositionTypes.ts +5 -5
  21. package/src/extensions/Blocks/api/defaultBlocks.ts +44 -0
  22. package/src/extensions/Blocks/api/selectionTypes.ts +3 -3
  23. package/src/extensions/Blocks/api/serialization.ts +29 -0
  24. package/src/extensions/Blocks/index.ts +0 -8
  25. package/src/extensions/Blocks/nodes/Block.module.css +28 -16
  26. package/src/extensions/Blocks/nodes/BlockContainer.ts +8 -4
  27. package/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.ts +4 -4
  28. package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +5 -5
  29. package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +100 -97
  30. package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +4 -4
  31. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +11 -9
  32. package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +6 -5
  33. package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +57 -14
  34. package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +21 -16
  35. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +9 -5
  36. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +38 -58
  37. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +19 -0
  38. package/src/extensions/Placeholder/PlaceholderExtension.ts +1 -0
  39. package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +5 -2
  40. package/src/extensions/SlashMenu/SlashMenuExtension.ts +37 -33
  41. package/src/extensions/SlashMenu/defaultSlashMenuItems.tsx +14 -10
  42. package/src/extensions/SlashMenu/index.ts +2 -2
  43. package/src/index.ts +4 -0
  44. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +29 -13
  45. package/types/src/BlockNoteEditor.d.ts +38 -23
  46. package/types/src/BlockNoteExtensions.d.ts +15 -8
  47. package/types/src/api/blockManipulation/blockManipulation.d.ts +4 -4
  48. package/types/src/api/formatConversions/formatConversions.d.ts +5 -5
  49. package/types/src/api/nodeConversions/nodeConversions.d.ts +3 -3
  50. package/types/src/api/nodeConversions/testUtil.d.ts +2 -2
  51. package/types/src/extensions/Blocks/api/block.d.ts +2 -4
  52. package/types/src/extensions/Blocks/api/blockTypes.d.ts +77 -33
  53. package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +5 -5
  54. package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +4 -4
  55. package/types/src/extensions/Blocks/api/selectionTypes.d.ts +3 -3
  56. package/types/src/extensions/Blocks/api/serialization.d.ts +2 -0
  57. package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +3 -3
  58. package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +1 -2
  59. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +1 -2
  60. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +1 -2
  61. package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +1 -2
  62. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +7 -7
  63. package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +5 -4
  64. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +12 -11
  65. package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +6 -5
  66. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +4 -3
  67. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +16 -19
  68. package/types/src/extensions/Placeholder/localisation/index.d.ts +2 -0
  69. package/types/src/extensions/Placeholder/localisation/translation.d.ts +51 -0
  70. package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +4 -3
  71. package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +5 -4
  72. package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +66 -1
  73. package/types/src/extensions/SlashMenu/index.d.ts +2 -2
  74. package/types/src/index.d.ts +4 -0
  75. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +5 -4
  76. package/types/src/extensions/Blocks/api/alertBlock.d.ts +0 -13
  77. package/types/src/extensions/Blocks/api/alertBlock2.d.ts +0 -13
@@ -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,44 @@ 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;
108
+ isFocused(): boolean;
99
109
  focus(): void;
100
- constructor(options?: Partial<BlockNoteEditorOptions>);
110
+ constructor(options?: Partial<BlockNoteEditorOptions<BSchema>>);
101
111
  /**
102
112
  * Gets a snapshot of all top-level (non-nested) blocks in the editor.
103
113
  * @returns A snapshot of all top-level (non-nested) blocks in the editor.
104
114
  */
105
- get topLevelBlocks(): Block[];
115
+ get topLevelBlocks(): Block<BSchema>[];
106
116
  /**
107
117
  * Gets a snapshot of an existing block from the editor.
108
118
  * @param blockIdentifier The identifier of an existing block that should be retrieved.
109
119
  * @returns The block that matches the identifier, or `undefined` if no matching block was found.
110
120
  */
111
- getBlock(blockIdentifier: BlockIdentifier): Block | undefined;
121
+ getBlock(blockIdentifier: BlockIdentifier): Block<BSchema> | undefined;
112
122
  /**
113
123
  * Traverses all blocks in the editor depth-first, and executes a callback for each.
114
124
  * @param callback The callback to execute for each block. Returning `false` stops the traversal.
115
125
  * @param reverse Whether the blocks should be traversed in reverse order.
116
126
  */
117
- forEachBlock(callback: (block: Block) => boolean, reverse?: boolean): void;
127
+ forEachBlock(callback: (block: Block<BSchema>) => boolean, reverse?: boolean): void;
128
+ /**
129
+ * Executes a callback whenever the editor's contents change.
130
+ * @param callback The callback to execute.
131
+ */
132
+ onEditorContentChange(callback: () => void): void;
118
133
  /**
119
134
  * Gets a snapshot of the current text cursor position.
120
135
  * @returns A snapshot of the current text cursor position.
121
136
  */
122
- getTextCursorPosition(): TextCursorPosition;
137
+ getTextCursorPosition(): TextCursorPosition<BSchema>;
123
138
  /**
124
139
  * Sets the text cursor position to the start or end of an existing block. Throws an error if the target block could
125
140
  * not be found.
@@ -130,7 +145,7 @@ export declare class BlockNoteEditor {
130
145
  /**
131
146
  * Gets a snapshot of the current selection.
132
147
  */
133
- getSelection(): Selection | undefined;
148
+ getSelection(): Selection<BSchema> | undefined;
134
149
  /**
135
150
  * Checks if the editor is currently editable, or if it's locked.
136
151
  * @returns True if the editor is editable, false otherwise.
@@ -149,7 +164,7 @@ export declare class BlockNoteEditor {
149
164
  * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
150
165
  * `referenceBlock`. Inserts the blocks at the start of the existing block's children if "nested" is used.
151
166
  */
152
- insertBlocks(blocksToInsert: PartialBlock[], referenceBlock: BlockIdentifier, placement?: "before" | "after" | "nested"): void;
167
+ insertBlocks(blocksToInsert: PartialBlock<BSchema>[], referenceBlock: BlockIdentifier, placement?: "before" | "after" | "nested"): void;
153
168
  /**
154
169
  * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
155
170
  * defined. These undefined fields are kept as-is from the existing block. Throws an error if the block to update could
@@ -157,7 +172,7 @@ export declare class BlockNoteEditor {
157
172
  * @param blockToUpdate The block that should be updated.
158
173
  * @param update A partial block which defines how the existing block should be changed.
159
174
  */
160
- updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock): void;
175
+ updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema>): void;
161
176
  /**
162
177
  * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
163
178
  * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
@@ -170,7 +185,7 @@ export declare class BlockNoteEditor {
170
185
  * @param blocksToRemove An array of blocks that should be replaced.
171
186
  * @param blocksToInsert An array of partial blocks to replace the old ones with.
172
187
  */
173
- replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock[]): void;
188
+ replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock<BSchema>[]): void;
174
189
  /**
175
190
  * Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
176
191
  */
@@ -226,7 +241,7 @@ export declare class BlockNoteEditor {
226
241
  * @param blocks An array of blocks that should be serialized into HTML.
227
242
  * @returns The blocks, serialized as an HTML string.
228
243
  */
229
- blocksToHTML(blocks: Block[]): Promise<string>;
244
+ blocksToHTML(blocks: Block<BSchema>[]): Promise<string>;
230
245
  /**
231
246
  * Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
232
247
  * `InlineNode` objects from any HTML inline elements, though not all element types are recognized. If BlockNote
@@ -234,14 +249,14 @@ export declare class BlockNoteEditor {
234
249
  * @param html The HTML string to parse blocks from.
235
250
  * @returns The blocks parsed from the HTML string.
236
251
  */
237
- HTMLToBlocks(html: string): Promise<Block[]>;
252
+ HTMLToBlocks(html: string): Promise<Block<BSchema>[]>;
238
253
  /**
239
254
  * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
240
255
  * BlockNote - children of blocks which aren't list items are un-nested and certain styles are removed.
241
256
  * @param blocks An array of blocks that should be serialized into Markdown.
242
257
  * @returns The blocks, serialized as a Markdown string.
243
258
  */
244
- blocksToMarkdown(blocks: Block[]): Promise<string>;
259
+ blocksToMarkdown(blocks: Block<BSchema>[]): Promise<string>;
245
260
  /**
246
261
  * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
247
262
  * Markdown syntax, though not all symbols are recognized. If BlockNote doesn't recognize a symbol, it will parse it
@@ -249,7 +264,7 @@ export declare class BlockNoteEditor {
249
264
  * @param markdown The Markdown string to parse blocks from.
250
265
  * @returns The blocks parsed from the Markdown string.
251
266
  */
252
- markdownToBlocks(markdown: string): Promise<Block[]>;
267
+ markdownToBlocks(markdown: string): Promise<Block<BSchema>[]>;
253
268
  /**
254
269
  * Updates the user info for the current user that's shown to other collaborators.
255
270
  */
@@ -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>;
@@ -1,37 +1,81 @@
1
1
  /** Define the main block types **/
2
+ import { Node, NodeConfig } from "@tiptap/core";
3
+ import { BlockNoteEditor } from "../../../BlockNoteEditor";
2
4
  import { InlineContent, PartialInlineContent } from "./inlineContentTypes";
3
- export type BlockTemplate<Type extends string, Props extends Record<string, string>> = {
4
- id: string;
5
+ export type TipTapNodeConfig<Name extends string, Options = any, Storage = any> = {
6
+ [K in keyof NodeConfig<Options, Storage>]: K extends "name" ? Name : K extends "group" ? never : NodeConfig<Options, Storage>[K];
7
+ };
8
+ export type TipTapNode<Name extends string, Options = any, Storage = any> = Node<Options, Storage> & {
9
+ name: Name;
10
+ group: "blockContent";
11
+ };
12
+ export type PropSpec = {
13
+ values?: readonly string[];
14
+ default: string;
15
+ };
16
+ export type PropSchema = Record<string, PropSpec>;
17
+ export type Props<PSchema extends PropSchema> = {
18
+ [PType in keyof PSchema]: PSchema[PType]["values"] extends readonly string[] ? PSchema[PType]["values"][number] : string;
19
+ };
20
+ export type BlockConfig<Type extends string, PSchema extends PropSchema, ContainsInlineContent extends boolean, BSchema extends BlockSchema> = {
5
21
  type: Type;
6
- props: Props;
7
- content: InlineContent[];
8
- children: Block[];
9
- };
10
- export type DefaultBlockProps = {
11
- backgroundColor: string;
12
- textColor: string;
13
- textAlignment: "left" | "center" | "right" | "justify";
14
- };
15
- export type NumberedListItemBlock = BlockTemplate<"numberedListItem", DefaultBlockProps>;
16
- export type BulletListItemBlock = BlockTemplate<"bulletListItem", DefaultBlockProps>;
17
- export type HeadingBlock = BlockTemplate<"heading", DefaultBlockProps & {
18
- level: "1" | "2" | "3";
22
+ readonly propSchema: PSchema;
23
+ containsInlineContent: ContainsInlineContent;
24
+ render: (
25
+ /**
26
+ * The custom block to render
27
+ */
28
+ block: SpecificBlock<BSchema & {
29
+ [k in Type]: BlockSpec<Type, PSchema>;
30
+ }, Type>,
31
+ /**
32
+ * The BlockNote editor instance
33
+ * This is typed generically. If you want an editor with your custom schema, you need to
34
+ * cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
35
+ */
36
+ editor: BlockNoteEditor<BSchema & {
37
+ [k in Type]: BlockSpec<Type, PSchema>;
38
+ }>) => ContainsInlineContent extends true ? {
39
+ dom: HTMLElement;
40
+ contentDOM: HTMLElement;
41
+ } : {
42
+ dom: HTMLElement;
43
+ };
44
+ };
45
+ export type BlockSpec<Type extends string, PSchema extends PropSchema> = {
46
+ readonly propSchema: PSchema;
47
+ node: TipTapNode<Type>;
48
+ };
49
+ export type TypesMatch<Blocks extends Record<string, BlockSpec<string, PropSchema>>> = Blocks extends {
50
+ [Type in keyof Blocks]: Type extends string ? Blocks[Type] extends BlockSpec<Type, PropSchema> ? Blocks[Type] : never : never;
51
+ } ? Blocks : never;
52
+ export type BlockSchema = TypesMatch<Record<string, BlockSpec<string, PropSchema>>>;
53
+ type BlocksWithoutChildren<BSchema extends BlockSchema> = {
54
+ [BType in keyof BSchema]: {
55
+ id: string;
56
+ type: BType;
57
+ props: Props<BSchema[BType]["propSchema"]>;
58
+ content: InlineContent[];
59
+ };
60
+ };
61
+ export type Block<BSchema extends BlockSchema> = BlocksWithoutChildren<BSchema>[keyof BlocksWithoutChildren<BSchema>] & {
62
+ children: Block<BSchema>[];
63
+ };
64
+ export type SpecificBlock<BSchema extends BlockSchema, BlockType extends keyof BSchema> = BlocksWithoutChildren<BSchema>[BlockType] & {
65
+ children: Block<BSchema>[];
66
+ };
67
+ type PartialBlocksWithoutChildren<BSchema extends BlockSchema> = {
68
+ [BType in keyof BSchema]: Partial<{
69
+ id: string;
70
+ type: BType;
71
+ props: Partial<Props<BSchema[BType]["propSchema"]>>;
72
+ content: PartialInlineContent[] | string;
73
+ }>;
74
+ };
75
+ export type PartialBlock<BSchema extends BlockSchema> = PartialBlocksWithoutChildren<BSchema>[keyof PartialBlocksWithoutChildren<BSchema>] & Partial<{
76
+ children: PartialBlock<BSchema>[];
19
77
  }>;
20
- export type ParagraphBlock = BlockTemplate<"paragraph", DefaultBlockProps>;
21
- export type Block = ParagraphBlock | HeadingBlock | BulletListItemBlock | NumberedListItemBlock;
22
- export type BlockIdentifier = string | Block;
23
- /** Define "Partial Blocks", these are for updating or creating blocks */
24
- export type PartialBlockTemplate<B extends Block> = B extends Block ? Partial<Omit<B, "props" | "children" | "content" | "type">> & {
25
- type?: B["type"];
26
- props?: Partial<B["props"]>;
27
- content?: string | PartialInlineContent[];
28
- children?: PartialBlock[];
29
- } : never;
30
- export type PartialBlock = PartialBlockTemplate<Block>;
31
- export type BlockPropsTemplate<Props> = Props extends Block["props"] ? keyof Props : never;
32
- /**
33
- * Expose blockProps. This is currently not very nice, but it's expected this
34
- * will change anyway once we allow for custom blocks
35
- */
36
- export declare const globalProps: Array<keyof DefaultBlockProps>;
37
- export declare const blockProps: Record<Block["type"], Set<string>>;
78
+ export type BlockIdentifier = {
79
+ id: string;
80
+ } | string;
81
+ export {};
@@ -1,6 +1,6 @@
1
- import { Block } from "./blockTypes";
2
- export type TextCursorPosition = {
3
- block: Block;
4
- prevBlock: Block | undefined;
5
- nextBlock: Block | undefined;
1
+ import { Block, BlockSchema } from "./blockTypes";
2
+ export type TextCursorPosition<BSchema extends BlockSchema> = {
3
+ block: Block<BSchema>;
4
+ prevBlock: Block<BSchema> | undefined;
5
+ nextBlock: Block<BSchema> | undefined;
6
6
  };
@@ -26,7 +26,7 @@ export declare const defaultBlockSchema: {
26
26
  values: readonly ["left", "center", "right", "justify"];
27
27
  };
28
28
  };
29
- readonly node: import("./blockTypes").TipTapNode<"paragraph", any, any>;
29
+ readonly node: import("./blockTypes").TipTapNode<"paragraph">;
30
30
  };
31
31
  readonly heading: {
32
32
  readonly propSchema: {
@@ -45,7 +45,7 @@ export declare const defaultBlockSchema: {
45
45
  values: readonly ["left", "center", "right", "justify"];
46
46
  };
47
47
  };
48
- readonly node: import("./blockTypes").TipTapNode<"heading", any, any>;
48
+ readonly node: import("./blockTypes").TipTapNode<"heading">;
49
49
  };
50
50
  readonly bulletListItem: {
51
51
  readonly propSchema: {
@@ -60,7 +60,7 @@ export declare const defaultBlockSchema: {
60
60
  values: readonly ["left", "center", "right", "justify"];
61
61
  };
62
62
  };
63
- readonly node: import("./blockTypes").TipTapNode<"bulletListItem", any, any>;
63
+ readonly node: import("./blockTypes").TipTapNode<"bulletListItem">;
64
64
  };
65
65
  readonly numberedListItem: {
66
66
  readonly propSchema: {
@@ -75,7 +75,7 @@ export declare const defaultBlockSchema: {
75
75
  values: readonly ["left", "center", "right", "justify"];
76
76
  };
77
77
  };
78
- readonly node: import("./blockTypes").TipTapNode<"numberedListItem", any, any>;
78
+ readonly node: import("./blockTypes").TipTapNode<"numberedListItem">;
79
79
  };
80
80
  };
81
81
  export type DefaultBlockSchema = TypesMatch<typeof defaultBlockSchema>;
@@ -1,4 +1,4 @@
1
- import { Block } from "./blockTypes";
2
- export type Selection = {
3
- blocks: Block[];
1
+ import { Block, BlockSchema } from "./blockTypes";
2
+ export type Selection<BSchema extends BlockSchema> = {
3
+ blocks: Block<BSchema>[];
4
4
  };
@@ -0,0 +1,2 @@
1
+ import { Extension } from "@tiptap/core";
2
+ export declare const CustomBlockSerializerExtension: Extension<any, any>;
@@ -1,5 +1,5 @@
1
1
  import { Node } from "@tiptap/core";
2
- import { PartialBlock } from "../api/blockTypes";
2
+ import { BlockSchema, PartialBlock } from "../api/blockTypes";
3
3
  export interface IBlock {
4
4
  HTMLAttributes: Record<string, any>;
5
5
  }
@@ -10,8 +10,8 @@ declare module "@tiptap/core" {
10
10
  BNDeleteBlock: (posInBlock: number) => ReturnType;
11
11
  BNMergeBlocks: (posBetweenBlocks: number) => ReturnType;
12
12
  BNSplitBlock: (posInBlock: number, keepType: boolean) => ReturnType;
13
- BNUpdateBlock: (posInBlock: number, block: PartialBlock) => ReturnType;
14
- BNCreateOrUpdateBlock: (posInBlock: number, block: PartialBlock) => ReturnType;
13
+ BNUpdateBlock: <BSchema extends BlockSchema>(posInBlock: number, block: PartialBlock<BSchema>) => ReturnType;
14
+ BNCreateOrUpdateBlock: <BSchema extends BlockSchema>(posInBlock: number, block: PartialBlock<BSchema>) => ReturnType;
15
15
  };
16
16
  }
17
17
  }
@@ -1,2 +1 @@
1
- import { Node } from "@tiptap/core";
2
- export declare const HeadingBlockContent: Node<any, any>;
1
+ export declare const HeadingBlockContent: import("../../../api/blockTypes").TipTapNode<"heading">;
@@ -1,2 +1 @@
1
- import { Node } from "@tiptap/core";
2
- export declare const BulletListItemBlockContent: Node<any, any>;
1
+ export declare const BulletListItemBlockContent: import("../../../../api/blockTypes").TipTapNode<"bulletListItem">;
@@ -1,2 +1 @@
1
- import { Node } from "@tiptap/core";
2
- export declare const NumberedListItemBlockContent: Node<any, any>;
1
+ export declare const NumberedListItemBlockContent: import("../../../../api/blockTypes").TipTapNode<"numberedListItem">;
@@ -1,2 +1 @@
1
- import { Node } from "@tiptap/core";
2
- export declare const ParagraphBlockContent: Node<any, any>;
1
+ export declare const ParagraphBlockContent: import("../../../api/blockTypes").TipTapNode<"paragraph">;
@@ -1,17 +1,17 @@
1
1
  import { EditorElement, ElementFactory } from "../../shared/EditorElement";
2
2
  import { BlockNoteEditor } from "../../BlockNoteEditor";
3
- import { Block } from "../Blocks/api/blockTypes";
4
- export type BlockSideMenuStaticParams = {
5
- editor: BlockNoteEditor;
3
+ import { Block, BlockSchema } from "../Blocks/api/blockTypes";
4
+ export type BlockSideMenuStaticParams<BSchema extends BlockSchema> = {
5
+ editor: BlockNoteEditor<BSchema>;
6
6
  addBlock: () => void;
7
7
  blockDragStart: (event: DragEvent) => void;
8
8
  blockDragEnd: () => void;
9
9
  freezeMenu: () => void;
10
10
  unfreezeMenu: () => void;
11
11
  };
12
- export type BlockSideMenuDynamicParams = {
13
- block: Block;
12
+ export type BlockSideMenuDynamicParams<BSchema extends BlockSchema> = {
13
+ block: Block<BSchema>;
14
14
  referenceRect: DOMRect;
15
15
  };
16
- export type BlockSideMenu = EditorElement<BlockSideMenuDynamicParams>;
17
- export type BlockSideMenuFactory = ElementFactory<BlockSideMenuStaticParams, BlockSideMenuDynamicParams>;
16
+ export type BlockSideMenu<BSchema extends BlockSchema> = EditorElement<BlockSideMenuDynamicParams<BSchema>>;
17
+ export type BlockSideMenuFactory<BSchema extends BlockSchema> = ElementFactory<BlockSideMenuStaticParams<BSchema>, BlockSideMenuDynamicParams<BSchema>>;
@@ -1,10 +1,11 @@
1
1
  import { Editor, Extension } from "@tiptap/core";
2
2
  import { BlockSideMenuFactory } from "./BlockSideMenuFactoryTypes";
3
3
  import { BlockNoteEditor } from "../../BlockNoteEditor";
4
- export type DraggableBlocksOptions = {
4
+ import { BlockSchema } from "../Blocks/api/blockTypes";
5
+ export type DraggableBlocksOptions<BSchema extends BlockSchema> = {
5
6
  tiptapEditor: Editor;
6
- editor: BlockNoteEditor;
7
- blockSideMenuFactory: BlockSideMenuFactory;
7
+ editor: BlockNoteEditor<BSchema>;
8
+ blockSideMenuFactory: BlockSideMenuFactory<BSchema>;
8
9
  };
9
10
  /**
10
11
  * This extension adds a menu to the side of blocks which features various BlockNote functions such as adding and
@@ -12,4 +13,4 @@ export type DraggableBlocksOptions = {
12
13
  *
13
14
  * code based on https://github.com/ueberdosis/tiptap/issues/323#issuecomment-506637799
14
15
  */
15
- export declare const DraggableBlocksExtension: Extension<DraggableBlocksOptions, any>;
16
+ export declare const createDraggableBlocksExtension: <BSchema extends Record<string, import("../Blocks/api/blockTypes").BlockSpec<string, import("../Blocks/api/blockTypes").PropSchema>>>() => Extension<DraggableBlocksOptions<BSchema>, any>;
@@ -3,23 +3,24 @@ import { Plugin } from "prosemirror-state";
3
3
  import { BlockSideMenu, BlockSideMenuDynamicParams, BlockSideMenuFactory, BlockSideMenuStaticParams } from "./BlockSideMenuFactoryTypes";
4
4
  import { DraggableBlocksOptions } from "./DraggableBlocksExtension";
5
5
  import { BlockNoteEditor } from "../../BlockNoteEditor";
6
- export type BlockMenuViewProps = {
6
+ import { BlockSchema } from "../Blocks/api/blockTypes";
7
+ export type BlockMenuViewProps<BSchema extends BlockSchema> = {
7
8
  tiptapEditor: Editor;
8
- editor: BlockNoteEditor;
9
- blockMenuFactory: BlockSideMenuFactory;
9
+ editor: BlockNoteEditor<BSchema>;
10
+ blockMenuFactory: BlockSideMenuFactory<BSchema>;
10
11
  horizontalPosAnchoredAtRoot: boolean;
11
12
  };
12
- export declare class BlockMenuView {
13
- editor: BlockNoteEditor;
13
+ export declare class BlockMenuView<BSchema extends BlockSchema> {
14
+ editor: BlockNoteEditor<BSchema>;
14
15
  private ttEditor;
15
16
  horizontalPosAnchoredAtRoot: boolean;
16
17
  horizontalPosAnchor: number;
17
- blockMenu: BlockSideMenu;
18
+ blockMenu: BlockSideMenu<BSchema>;
18
19
  hoveredBlock: HTMLElement | undefined;
19
20
  isDragging: boolean;
20
21
  menuOpen: boolean;
21
22
  menuFrozen: boolean;
22
- constructor({ tiptapEditor, editor, blockMenuFactory, horizontalPosAnchoredAtRoot, }: BlockMenuViewProps);
23
+ constructor({ tiptapEditor, editor, blockMenuFactory, horizontalPosAnchoredAtRoot, }: BlockMenuViewProps<BSchema>);
23
24
  /**
24
25
  * Sets isDragging when dragging text.
25
26
  */
@@ -31,7 +32,7 @@ export declare class BlockMenuView {
31
32
  */
32
33
  onDrop: (event: DragEvent) => void;
33
34
  /**
34
- * If the event is outside of the editor contents,
35
+ * If the event is outside the editor contents,
35
36
  * we dispatch a fake event, so that we can still drop the content
36
37
  * when dragging / dropping to the side of the editor
37
38
  */
@@ -42,7 +43,7 @@ export declare class BlockMenuView {
42
43
  onScroll: () => void;
43
44
  destroy(): void;
44
45
  addBlock(): void;
45
- getStaticParams(): BlockSideMenuStaticParams;
46
- getDynamicParams(): BlockSideMenuDynamicParams;
46
+ getStaticParams(): BlockSideMenuStaticParams<BSchema>;
47
+ getDynamicParams(): BlockSideMenuDynamicParams<BSchema>;
47
48
  }
48
- export declare const createDraggableBlocksPlugin: (options: DraggableBlocksOptions) => Plugin<any>;
49
+ export declare const createDraggableBlocksPlugin: <BSchema extends Record<string, import("../Blocks/api/blockTypes").BlockSpec<string, import("../Blocks/api/blockTypes").PropSchema>>>(options: DraggableBlocksOptions<BSchema>) => Plugin<any>;