@blocknote/core 0.4.0 → 0.4.3

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 (87) hide show
  1. package/dist/blocknote.js +12371 -12268
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +20 -20
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/style.css +1 -1
  6. package/package.json +2 -2
  7. package/src/BlockNoteEditor.ts +237 -14
  8. package/src/BlockNoteExtensions.ts +19 -15
  9. package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +616 -0
  10. package/src/api/blockManipulation/blockManipulation.test.ts +172 -0
  11. package/src/api/blockManipulation/blockManipulation.ts +25 -14
  12. package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +346 -0
  13. package/src/api/formatConversions/formatConversions.test.ts +766 -0
  14. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +268 -0
  15. package/src/api/nodeConversions/nodeConversions.test.ts +244 -0
  16. package/src/api/nodeConversions/nodeConversions.ts +167 -58
  17. package/src/api/nodeConversions/testUtil.ts +61 -0
  18. package/src/api/util/nodeUtil.ts +38 -0
  19. package/src/editor.module.css +1 -0
  20. package/src/extensions/Blocks/api/blockTypes.ts +14 -9
  21. package/src/extensions/Blocks/api/cursorPositionTypes.ts +2 -0
  22. package/src/extensions/Blocks/api/inlineContentTypes.ts +27 -36
  23. package/src/extensions/Blocks/nodes/Block.module.css +39 -36
  24. package/src/extensions/Blocks/nodes/BlockContainer.ts +15 -14
  25. package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +149 -87
  26. package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +31 -0
  27. package/src/extensions/SlashMenu/SlashMenuExtension.ts +10 -7
  28. package/src/extensions/SlashMenu/{defaultSlashCommands.tsx → defaultSlashMenuItems.tsx} +59 -106
  29. package/src/extensions/SlashMenu/index.ts +3 -7
  30. package/src/index.ts +2 -3
  31. package/src/shared/plugins/suggestion/SuggestionItem.ts +2 -13
  32. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +31 -18
  33. package/src/shared/utils.ts +6 -0
  34. package/types/src/BlockNoteEditor.d.ts +82 -8
  35. package/types/src/BlockNoteExtensions.d.ts +5 -4
  36. package/types/src/api/Editor.d.ts +26 -6
  37. package/types/src/api/blockManipulation/blockManipulation.d.ts +5 -5
  38. package/types/src/api/blockManipulation/blockManipulation.test.d.ts +1 -0
  39. package/types/src/api/formatConversions/formatConversions.test.d.ts +1 -0
  40. package/types/src/api/nodeConversions/nodeConversions.d.ts +11 -4
  41. package/types/src/api/nodeConversions/nodeConversions.test.d.ts +1 -0
  42. package/types/src/api/nodeConversions/testUtil.d.ts +2 -0
  43. package/types/src/api/util/nodeUtil.d.ts +8 -0
  44. package/types/src/extensions/Blocks/api/blockTypes.d.ts +10 -9
  45. package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +2 -0
  46. package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +25 -19
  47. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +15 -0
  48. package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +20 -0
  49. package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +4 -2
  50. package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +5 -0
  51. package/types/src/extensions/SlashMenu/index.d.ts +3 -3
  52. package/types/src/index.d.ts +2 -3
  53. package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +3 -11
  54. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +4 -4
  55. package/types/src/shared/utils.d.ts +3 -0
  56. package/src/api/Editor.ts +0 -142
  57. package/src/extensions/SlashMenu/SlashMenuItem.ts +0 -34
  58. package/types/src/EditorElement.d.ts +0 -7
  59. package/types/src/api/Document.d.ts +0 -5
  60. package/types/src/api/removeUnderlinesRehypePlugin.d.ts +0 -6
  61. package/types/src/api/simplifyBlocksRehypePlugin.d.ts +0 -16
  62. package/types/src/extensions/Blocks/BlockAttributes.d.ts +0 -2
  63. package/types/src/extensions/Blocks/MultipleNodeSelection.d.ts +0 -24
  64. package/types/src/extensions/Blocks/api/apiTypes.d.ts +0 -18
  65. package/types/src/extensions/Blocks/api/styleTypes.d.ts +0 -22
  66. package/types/src/extensions/Blocks/apiTypes.d.ts +0 -16
  67. package/types/src/extensions/Blocks/nodes/Block.d.ts +0 -24
  68. package/types/src/extensions/Blocks/nodes/BlockContent/BlockContentTypes.d.ts +0 -4
  69. package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContentTypes.d.ts +0 -4
  70. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContentTypes.d.ts +0 -2
  71. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContentTypes.d.ts +0 -2
  72. package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContentTypes.d.ts +0 -2
  73. package/types/src/extensions/Blocks/nodes/BlockTypes/HeadingBlock/HeadingContent.d.ts +0 -8
  74. package/types/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/ListItemContent.d.ts +0 -8
  75. package/types/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/OrderedListItemIndexPlugin.d.ts +0 -2
  76. package/types/src/extensions/Blocks/nodes/BlockTypes/TextBlock/TextContent.d.ts +0 -6
  77. package/types/src/extensions/BubbleMenu/BubbleMenuExtension.d.ts +0 -8
  78. package/types/src/extensions/BubbleMenu/BubbleMenuFactoryTypes.d.ts +0 -27
  79. package/types/src/extensions/BubbleMenu/BubbleMenuPlugin.d.ts +0 -44
  80. package/types/src/extensions/DraggableBlocks/BlockMenuFactoryTypes.d.ts +0 -12
  81. package/types/src/extensions/DraggableBlocks/DragMenuFactoryTypes.d.ts +0 -18
  82. package/types/src/extensions/Hyperlinks/HyperlinkMark.d.ts +0 -8
  83. package/types/src/extensions/Hyperlinks/HyperlinkMenuFactoryTypes.d.ts +0 -11
  84. package/types/src/extensions/Hyperlinks/HyperlinkMenuPlugin.d.ts +0 -11
  85. package/types/src/extensions/Paragraph/FixedParagraph.d.ts +0 -1
  86. package/types/src/extensions/SlashMenu/defaultCommands.d.ts +0 -8
  87. package/types/src/utils.d.ts +0 -2
@@ -9,6 +9,7 @@ import {
9
9
  SuggestionsMenuStaticParams,
10
10
  } from "./SuggestionsMenuFactoryTypes";
11
11
  import { SuggestionItem } from "./SuggestionItem";
12
+ import { BlockNoteEditor } from "../../../BlockNoteEditor";
12
13
 
13
14
  export type SuggestionPluginOptions<T extends SuggestionItem> = {
14
15
  /**
@@ -19,9 +20,9 @@ export type SuggestionPluginOptions<T extends SuggestionItem> = {
19
20
  pluginKey: PluginKey;
20
21
 
21
22
  /**
22
- * The TipTap editor.
23
+ * The BlockNote editor.
23
24
  */
24
- editor: Editor;
25
+ editor: BlockNoteEditor;
25
26
 
26
27
  /**
27
28
  * The character that should trigger the suggestion menu to pop up (e.g. a '/' for commands), when typed by the user.
@@ -37,7 +38,7 @@ export type SuggestionPluginOptions<T extends SuggestionItem> = {
37
38
  * this should be done manually. The `editor` and `range` properties passed
38
39
  * to the callback function might come in handy when doing this.
39
40
  */
40
- onSelectItem?: (props: { item: T; editor: Editor; range: Range }) => void;
41
+ onSelectItem?: (props: { item: T; editor: BlockNoteEditor }) => void;
41
42
 
42
43
  /**
43
44
  * A function that should supply the plugin with items to suggest, based on a certain query string.
@@ -81,14 +82,14 @@ function getDefaultPluginState<
81
82
  }
82
83
 
83
84
  type SuggestionPluginViewOptions<T extends SuggestionItem> = {
84
- editor: Editor;
85
+ editor: BlockNoteEditor;
85
86
  pluginKey: PluginKey;
86
- onSelectItem: (props: { item: T; editor: Editor; range: Range }) => void;
87
+ onSelectItem: (props: { item: T; editor: BlockNoteEditor }) => void;
87
88
  suggestionsMenuFactory: SuggestionsMenuFactory<T>;
88
89
  };
89
90
 
90
91
  class SuggestionPluginView<T extends SuggestionItem> {
91
- editor: Editor;
92
+ editor: BlockNoteEditor;
92
93
  pluginKey: PluginKey;
93
94
 
94
95
  suggestionsMenu: SuggestionsMenu<T>;
@@ -107,17 +108,23 @@ class SuggestionPluginView<T extends SuggestionItem> {
107
108
 
108
109
  this.pluginState = getDefaultPluginState<T>();
109
110
 
110
- this.itemCallback = (item: T) =>
111
- selectItemCallback({
112
- item: item,
113
- editor: editor,
114
- range: {
111
+ this.itemCallback = (item: T) => {
112
+ editor._tiptapEditor
113
+ .chain()
114
+ .focus()
115
+ .deleteRange({
115
116
  from:
116
117
  this.pluginState.queryStartPos! -
117
118
  this.pluginState.triggerCharacter!.length,
118
- to: editor.state.selection.from,
119
- },
119
+ to: editor._tiptapEditor.state.selection.from,
120
+ })
121
+ .run();
122
+
123
+ selectItemCallback({
124
+ item: item,
125
+ editor: editor,
120
126
  });
127
+ };
121
128
 
122
129
  this.suggestionsMenu = suggestionsMenuFactory(this.getStaticParams());
123
130
  }
@@ -220,7 +227,7 @@ export function createSuggestionPlugin<T extends SuggestionItem>({
220
227
  new SuggestionPluginView({
221
228
  editor: editor,
222
229
  pluginKey: pluginKey,
223
- onSelectItem: (props: { item: T; editor: Editor; range: Range }) => {
230
+ onSelectItem: (props: { item: T; editor: BlockNoteEditor }) => {
224
231
  deactivate(view);
225
232
  selectItemCallback(props);
226
233
  },
@@ -378,14 +385,20 @@ export function createSuggestionPlugin<T extends SuggestionItem>({
378
385
  // Selects an item and closes the menu.
379
386
  if (event.key === "Enter") {
380
387
  deactivate(view);
388
+ editor._tiptapEditor
389
+ .chain()
390
+ .focus()
391
+ .deleteRange({
392
+ from: queryStartPos! - triggerCharacter!.length,
393
+ to: editor._tiptapEditor.state.selection.from,
394
+ })
395
+ .run();
396
+
381
397
  selectItemCallback({
382
398
  item: items[keyboardHoveredItemIndex],
383
399
  editor: editor,
384
- range: {
385
- from: queryStartPos - triggerCharacter.length,
386
- to: view.state.selection.from,
387
- },
388
400
  });
401
+
389
402
  return true;
390
403
  }
391
404
 
@@ -10,3 +10,9 @@ export function formatKeyboardShortcut(shortcut: string) {
10
10
  return shortcut.replace("Mod", "Ctrl");
11
11
  }
12
12
  }
13
+
14
+ export class UnreachableCaseError extends Error {
15
+ constructor(val: never) {
16
+ super(`Unreachable case: ${val}`);
17
+ }
18
+ }
@@ -1,22 +1,96 @@
1
- import { Editor } from "@tiptap/core";
2
- import { Editor as EditorAPI } from "./api/Editor";
1
+ import { Block, PartialBlock } from "./extensions/Blocks/api/blockTypes";
3
2
  import { UiFactories } from "./BlockNoteExtensions";
4
- import { SlashCommand } from "./extensions/SlashMenu";
3
+ import { BaseSlashMenuItem } from "./extensions/SlashMenu";
4
+ import { Editor as TiptapEditor } from "@tiptap/core/dist/packages/core/src/Editor";
5
+ import { TextCursorPosition } from "./extensions/Blocks/api/cursorPositionTypes";
5
6
  export type BlockNoteEditorOptions = {
6
7
  enableBlockNoteExtensions: boolean;
7
8
  disableHistoryExtension: boolean;
8
9
  uiFactories: UiFactories;
9
- slashCommands: SlashCommand[];
10
+ slashCommands: BaseSlashMenuItem[];
10
11
  parentElement: HTMLElement;
11
12
  editorDOMAttributes: Record<string, string>;
12
- onUpdate: () => void;
13
- onCreate: () => void;
13
+ onUpdate: (editor: BlockNoteEditor) => void;
14
+ onCreate: (editor: BlockNoteEditor) => void;
14
15
  _tiptapOptions: any;
15
16
  };
16
- export declare class BlockNoteEditor extends EditorAPI {
17
- readonly _tiptapEditor: Editor & {
17
+ export declare class BlockNoteEditor {
18
+ readonly _tiptapEditor: TiptapEditor & {
18
19
  contentComponent: any;
19
20
  };
21
+ private blockCache;
20
22
  get domElement(): HTMLDivElement;
21
23
  constructor(options?: Partial<BlockNoteEditorOptions>);
24
+ /**
25
+ * Gets a list of all top-level blocks that are in the editor.
26
+ */
27
+ get topLevelBlocks(): Block[];
28
+ /**
29
+ * Traverses all blocks in the editor, including all nested blocks, and executes a callback for each. The traversal is
30
+ * depth-first, which is the same order as blocks appear in the editor by y-coordinate.
31
+ * @param callback The callback to execute for each block.
32
+ * @param reverse Whether the blocks should be traversed in reverse order.
33
+ */
34
+ allBlocks(callback: (block: Block) => void, reverse?: boolean): void;
35
+ /**
36
+ * Gets information regarding the position of the text cursor in the editor.
37
+ */
38
+ getTextCursorPosition(): TextCursorPosition;
39
+ setTextCursorPosition(block: Block, placement?: "start" | "end"): void;
40
+ /**
41
+ * Inserts multiple blocks before, after, or nested inside an existing block in the editor.
42
+ * @param blocksToInsert An array of blocks to insert.
43
+ * @param blockToInsertAt An existing block, marking where the new blocks should be inserted at.
44
+ * @param placement Determines whether the blocks should be inserted just before, just after, or nested inside the
45
+ * existing block.
46
+ */
47
+ insertBlocks(blocksToInsert: PartialBlock[], blockToInsertAt: Block, placement?: "before" | "after" | "nested"): void;
48
+ /**
49
+ * Updates a block in the editor to the given specification.
50
+ * @param blockToUpdate The block that should be updated.
51
+ * @param updatedBlock The specification that the block should be updated to.
52
+ */
53
+ updateBlock(blockToUpdate: Block, updatedBlock: PartialBlock): void;
54
+ /**
55
+ * Removes multiple blocks from the editor. Throws an error if any of the blocks could not be found.
56
+ * @param blocksToRemove An array of blocks that should be removed.
57
+ */
58
+ removeBlocks(blocksToRemove: Block[]): void;
59
+ /**
60
+ * Replaces multiple blocks in the editor with several other blocks. If the provided blocks to remove are not adjacent
61
+ * to each other, the new blocks are inserted at the position of the first block in the array. Throws an error if any
62
+ * of the blocks could not be found.
63
+ * @param blocksToRemove An array of blocks that should be replaced.
64
+ * @param blocksToInsert An array of blocks to replace the old ones with.
65
+ */
66
+ replaceBlocks(blocksToRemove: Block[], blocksToInsert: PartialBlock[]): void;
67
+ /**
68
+ * Executes a callback function whenever the editor's content changes.
69
+ * @param callback The callback function to execute.
70
+ */
71
+ onContentChange(callback: () => void): void;
72
+ /**
73
+ * Serializes a list of blocks into an HTML string. The output is not the same as what's rendered by the editor, and
74
+ * is simplified in order to better conform to HTML standards. Block structuring elements are removed, children of
75
+ * blocks which aren't list items are lifted out of them, and list items blocks are wrapped in `ul`/`ol` tags.
76
+ * @param blocks The list of blocks to serialize into HTML.
77
+ */
78
+ blocksToHTML(blocks: Block[]): Promise<string>;
79
+ /**
80
+ * Creates a list of blocks from an HTML string.
81
+ * @param htmlString The HTML string to create a list of blocks from.
82
+ */
83
+ HTMLToBlocks(htmlString: string): Promise<Block[]>;
84
+ /**
85
+ * Serializes a list of blocks into a Markdown string. The output is simplified as Markdown does not support all
86
+ * features of BlockNote. Block structuring elements are removed, children of blocks which aren't list items are
87
+ * lifted out of them, and certain styles are removed.
88
+ * @param blocks The list of blocks to serialize into Markdown.
89
+ */
90
+ blocksToMarkdown(blocks: Block[]): Promise<string>;
91
+ /**
92
+ * Creates a list of blocks from a Markdown string.
93
+ * @param markdownString The Markdown string to create a list of blocks from.
94
+ */
95
+ markdownToBlocks(markdownString: string): Promise<Block[]>;
22
96
  }
@@ -1,20 +1,21 @@
1
1
  import { Extensions } from "@tiptap/core";
2
+ import { BlockNoteEditor } from "./BlockNoteEditor";
2
3
  import { BlockSideMenuFactory } from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
3
4
  import { FormattingToolbarFactory } from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
4
5
  import { HyperlinkToolbarFactory } from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
5
- import { SlashCommand } from "./extensions/SlashMenu";
6
- import { SlashMenuItem } from "./extensions/SlashMenu/SlashMenuItem";
6
+ import { BaseSlashMenuItem } from "./extensions/SlashMenu";
7
7
  import { SuggestionsMenuFactory } from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
8
8
  export type UiFactories = Partial<{
9
9
  formattingToolbarFactory: FormattingToolbarFactory;
10
10
  hyperlinkToolbarFactory: HyperlinkToolbarFactory;
11
- slashMenuFactory: SuggestionsMenuFactory<SlashMenuItem>;
11
+ slashMenuFactory: SuggestionsMenuFactory<BaseSlashMenuItem>;
12
12
  blockSideMenuFactory: BlockSideMenuFactory;
13
13
  }>;
14
14
  /**
15
15
  * Get all the Tiptap extensions BlockNote is configured with by default
16
16
  */
17
17
  export declare const getBlockNoteExtensions: (opts: {
18
+ editor: BlockNoteEditor;
18
19
  uiFactories: UiFactories;
19
- slashCommands: SlashCommand[];
20
+ slashCommands: BaseSlashMenuItem[];
20
21
  }) => Extensions;
@@ -1,17 +1,33 @@
1
1
  import { Editor as TiptapEditor } from "@tiptap/core";
2
2
  import { Node } from "prosemirror-model";
3
- import { Block, PartialBlock } from "../extensions/Blocks/api/blockTypes";
3
+ import { Block, BlockIdentifier, PartialBlock } from "../extensions/Blocks/api/blockTypes";
4
4
  import { TextCursorPosition } from "../extensions/Blocks/api/cursorPositionTypes";
5
5
  export declare class Editor {
6
6
  private tiptapEditor;
7
7
  private blockCache;
8
8
  constructor(tiptapEditor: TiptapEditor, blockCache?: WeakMap<Node, Block>);
9
9
  /**
10
- * Gets a list of all top-level blocks that are in the editor.
10
+ * Gets a snapshot of all top-level blocks that are in the editor.
11
+ * @returns An array containing a snapshot of all top-level (non-nested) blocks in the editor.
11
12
  */
12
- get allBlocks(): Block[];
13
+ get topLevelBlocks(): Block[];
13
14
  /**
14
- * Gets information regarding the position of the text cursor in the editor.
15
+ * Retrieves a snapshot of an existing block from the editor.
16
+ * @param block The identifier of an existing block that should be retrieved.
17
+ * @returns The block that matches the identifier, or undefined if no matching block was found.
18
+ */
19
+ getBlock(block: BlockIdentifier): Block | undefined;
20
+ /**
21
+ * Traverses all blocks in the editor, including all nested blocks, and executes a callback for each. The traversal is
22
+ * depth-first, which is the same order as blocks appear in the editor by y-coordinate. Stops traversal if the callback
23
+ * returns false;
24
+ * @param callback The callback to execute for each block.
25
+ * @param reverse Whether the blocks should be traversed in reverse order.
26
+ */
27
+ forEachBlock(callback: (block: Block) => boolean, reverse?: boolean): void;
28
+ /**
29
+ * Gets a snapshot of the text cursor position within the editor.
30
+ * @returns A snapshot of the text cursor position.
15
31
  */
16
32
  get textCursorPosition(): TextCursorPosition;
17
33
  /**
@@ -42,7 +58,7 @@ export declare class Editor {
42
58
  */
43
59
  replaceBlocks(blocksToRemove: Block[], blocksToInsert: PartialBlock[]): void;
44
60
  /**
45
- * Executes a callback function whenever the editor's content changes.
61
+ * Executes a callback function whenever the editor's contents change.
46
62
  * @param callback The callback function to execute.
47
63
  */
48
64
  onContentChange(callback: () => void): void;
@@ -51,23 +67,27 @@ export declare class Editor {
51
67
  * is simplified in order to better conform to HTML standards. Block structuring elements are removed, children of
52
68
  * blocks which aren't list items are lifted out of them, and list items blocks are wrapped in `ul`/`ol` tags.
53
69
  * @param blocks The list of blocks to serialize into HTML.
70
+ * @returns An HTML representation of the blocks.
54
71
  */
55
72
  blocksToHTML(blocks: Block[]): Promise<string>;
56
73
  /**
57
74
  * Creates a list of blocks from an HTML string.
58
75
  * @param htmlString The HTML string to create a list of blocks from.
76
+ * @returns A list of blocks parsed from the HTML string.
59
77
  */
60
78
  HTMLToBlocks(htmlString: string): Promise<Block[]>;
61
79
  /**
62
80
  * Serializes a list of blocks into a Markdown string. The output is simplified as Markdown does not support all
63
81
  * features of BlockNote. Block structuring elements are removed, children of blocks which aren't list items are
64
- * lifted out of them, and certain styles are removed.
82
+ * un-nested, and certain styles are removed.
65
83
  * @param blocks The list of blocks to serialize into Markdown.
84
+ * @returns A Markdown representation of the blocks.
66
85
  */
67
86
  blocksToMarkdown(blocks: Block[]): Promise<string>;
68
87
  /**
69
88
  * Creates a list of blocks from a Markdown string.
70
89
  * @param markdownString The Markdown string to create a list of blocks from.
90
+ * @returns A list of blocks parsed from the Markdown string.
71
91
  */
72
92
  markdownToBlocks(markdownString: string): Promise<Block[]>;
73
93
  }
@@ -1,6 +1,6 @@
1
1
  import { Editor } from "@tiptap/core";
2
- import { Block, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
3
- export declare function insertBlocks(blocksToInsert: PartialBlock[], blockToInsertAt: Block, placement: "before" | "after" | "nested" | undefined, editor: Editor): void;
4
- export declare function updateBlock(blockToUpdate: Block, updatedBlock: PartialBlock, editor: Editor): void;
5
- export declare function removeBlocks(blocksToRemove: Block[], editor: Editor): void;
6
- export declare function replaceBlocks(blocksToRemove: Block[], blocksToInsert: PartialBlock[], editor: Editor): void;
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;
5
+ export declare function removeBlocks(blocksToRemove: BlockIdentifier[], editor: Editor): void;
6
+ export declare function replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock[], editor: Editor): void;
@@ -1,8 +1,15 @@
1
1
  import { Node, Schema } from "prosemirror-model";
2
2
  import { Block, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
3
+ import { PartialInlineContent } from "../../extensions/Blocks/api/inlineContentTypes";
4
+ /**
5
+ * converts an array of inline content elements to prosemirror nodes
6
+ */
7
+ export declare function inlineContentToNodes(blockContent: PartialInlineContent[], schema: Schema): Node[];
8
+ /**
9
+ * Converts a BlockNote block to a TipTap node.
10
+ */
3
11
  export declare function blockToNode(block: PartialBlock, schema: Schema): Node;
4
- export declare function getNodeById(id: string, doc: Node): {
5
- node: Node;
6
- posBeforeNode: number;
7
- };
12
+ /**
13
+ * Convert a TipTap node to a BlockNote block.
14
+ */
8
15
  export declare function nodeToBlock(node: Node, blockCache?: WeakMap<Node, Block>): Block;
@@ -0,0 +1,2 @@
1
+ import { Block, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
2
+ export declare function partialBlockToBlockForTesting(partialBlock: PartialBlock): Block;
@@ -0,0 +1,8 @@
1
+ import { Node } from "prosemirror-model";
2
+ /**
3
+ * Get a TipTap node by id
4
+ */
5
+ export declare function getNodeById(id: string, doc: Node): {
6
+ node: Node;
7
+ posBeforeNode: number;
8
+ };
@@ -1,5 +1,5 @@
1
1
  /** Define the main block types **/
2
- import { InlineContent } from "./inlineContentTypes";
2
+ import { InlineContent, PartialInlineContent } from "./inlineContentTypes";
3
3
  export type BlockTemplate<Type extends string, Props extends Record<string, string>> = {
4
4
  id: string;
5
5
  type: Type;
@@ -7,23 +7,24 @@ export type BlockTemplate<Type extends string, Props extends Record<string, stri
7
7
  content: InlineContent[];
8
8
  children: Block[];
9
9
  };
10
- export type GlobalProps = {
10
+ export type DefaultBlockProps = {
11
11
  backgroundColor: string;
12
12
  textColor: string;
13
13
  textAlignment: "left" | "center" | "right" | "justify";
14
14
  };
15
- export type NumberedListItemBlock = BlockTemplate<"numberedListItem", GlobalProps>;
16
- export type BulletListItemBlock = BlockTemplate<"bulletListItem", GlobalProps>;
17
- export type HeadingBlock = BlockTemplate<"heading", GlobalProps & {
15
+ export type NumberedListItemBlock = BlockTemplate<"numberedListItem", DefaultBlockProps>;
16
+ export type BulletListItemBlock = BlockTemplate<"bulletListItem", DefaultBlockProps>;
17
+ export type HeadingBlock = BlockTemplate<"heading", DefaultBlockProps & {
18
18
  level: "1" | "2" | "3";
19
19
  }>;
20
- export type ParagraphBlock = BlockTemplate<"paragraph", GlobalProps>;
20
+ export type ParagraphBlock = BlockTemplate<"paragraph", DefaultBlockProps>;
21
21
  export type Block = ParagraphBlock | HeadingBlock | BulletListItemBlock | NumberedListItemBlock;
22
+ export type BlockIdentifier = string | Block;
22
23
  /** Define "Partial Blocks", these are for updating or creating blocks */
23
24
  export type PartialBlockTemplate<B extends Block> = B extends Block ? Partial<Omit<B, "props" | "children" | "content" | "type">> & {
24
- type: B["type"];
25
+ type?: B["type"];
25
26
  props?: Partial<B["props"]>;
26
- content?: string | B["content"];
27
+ content?: string | PartialInlineContent[];
27
28
  children?: PartialBlock[];
28
29
  } : never;
29
30
  export type PartialBlock = PartialBlockTemplate<Block>;
@@ -32,5 +33,5 @@ export type BlockPropsTemplate<Props> = Props extends Block["props"] ? keyof Pro
32
33
  * Expose blockProps. This is currently not very nice, but it's expected this
33
34
  * will change anyway once we allow for custom blocks
34
35
  */
35
- export declare const globalProps: Array<keyof GlobalProps>;
36
+ export declare const globalProps: Array<keyof DefaultBlockProps>;
36
37
  export declare const blockProps: Record<Block["type"], Set<string>>;
@@ -1,4 +1,6 @@
1
1
  import { Block } from "./blockTypes";
2
2
  export type TextCursorPosition = {
3
3
  block: Block;
4
+ prevBlock: Block | undefined;
5
+ nextBlock: Block | undefined;
4
6
  };
@@ -1,23 +1,29 @@
1
- export type StyleTemplate<Type extends string, Props extends Record<string, string>> = {
2
- type: Type;
3
- props: Props;
1
+ export type Styles = {
2
+ bold?: true;
3
+ italic?: true;
4
+ underline?: true;
5
+ strike?: true;
6
+ textColor?: string;
7
+ backgroundColor?: string;
4
8
  };
5
- export type Bold = StyleTemplate<"bold", {}>;
6
- export type Italic = StyleTemplate<"italic", {}>;
7
- export type Underline = StyleTemplate<"underline", {}>;
8
- export type Strikethrough = StyleTemplate<"strike", {}>;
9
- export type TextColor = StyleTemplate<"textColor", {
10
- color: string;
11
- }>;
12
- export type BackgroundColor = StyleTemplate<"backgroundColor", {
13
- color: string;
14
- }>;
15
- export type Link = StyleTemplate<"link", {
16
- href: string;
17
- }>;
18
- export type Style = Bold | Italic | Underline | Strikethrough | TextColor | BackgroundColor | Link;
9
+ export type ToggledStyles = {
10
+ [K in keyof Styles]-?: Required<Styles>[K] extends true ? K : never;
11
+ }[keyof Styles];
12
+ export type ColorStyles = {
13
+ [K in keyof Styles]-?: Required<Styles>[K] extends string ? K : never;
14
+ }[keyof Styles];
19
15
  export type StyledText = {
16
+ type: "text";
20
17
  text: string;
21
- styles: Style[];
18
+ styles: Styles;
19
+ };
20
+ export type Link = {
21
+ type: "link";
22
+ href: string;
23
+ content: StyledText[];
24
+ };
25
+ export type PartialLink = Omit<Link, "content"> & {
26
+ content: string | Link["content"];
22
27
  };
23
- export type InlineContent = StyledText;
28
+ export type InlineContent = StyledText | Link;
29
+ export type PartialInlineContent = StyledText | PartialLink;
@@ -24,6 +24,21 @@ export declare class BlockMenuView {
24
24
  menuOpen: boolean;
25
25
  menuFrozen: boolean;
26
26
  constructor({ editor, blockMenuFactory, horizontalPosAnchoredAtRoot, }: BlockMenuViewProps);
27
+ /**
28
+ * If the event is outside of the editor contents,
29
+ * we dispatch a fake event, so that we can still drop the content
30
+ * when dragging / dropping to the side of the editor
31
+ */
32
+ onDrop: (event: DragEvent) => void;
33
+ /**
34
+ * If the event is outside of the editor contents,
35
+ * we dispatch a fake event, so that we can still drop the content
36
+ * when dragging / dropping to the side of the editor
37
+ */
38
+ onDragOver: (event: DragEvent) => void;
39
+ onKeyDown: (_event: KeyboardEvent) => void;
40
+ onMouseDown: (event: MouseEvent) => void;
41
+ onMouseMove: (event: MouseEvent) => void;
27
42
  destroy(): void;
28
43
  addBlock(): void;
29
44
  deleteBlock(): void;
@@ -0,0 +1,20 @@
1
+ import { SuggestionItem } from "../../shared/plugins/suggestion/SuggestionItem";
2
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
3
+ /**
4
+ * A class that defines a slash command (/<command>).
5
+ *
6
+ * (Not to be confused with ProseMirror commands nor TipTap commands.)
7
+ */
8
+ export declare class BaseSlashMenuItem extends SuggestionItem {
9
+ readonly name: string;
10
+ readonly execute: (editor: BlockNoteEditor) => void;
11
+ readonly aliases: string[];
12
+ /**
13
+ * Constructs a new slash-command.
14
+ *
15
+ * @param name The name of the command
16
+ * @param execute The callback for creating a new node
17
+ * @param aliases Aliases for this command
18
+ */
19
+ constructor(name: string, execute: (editor: BlockNoteEditor) => void, aliases?: string[]);
20
+ }
@@ -1,9 +1,11 @@
1
1
  import { Extension } from "@tiptap/core";
2
2
  import { PluginKey } from "prosemirror-state";
3
3
  import { SuggestionsMenuFactory } from "../../shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
4
- import { SlashMenuItem } from "./SlashMenuItem";
4
+ import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
5
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
5
6
  export type SlashMenuOptions = {
6
- commands: SlashMenuItem[] | undefined;
7
+ editor: BlockNoteEditor | undefined;
8
+ commands: BaseSlashMenuItem[] | undefined;
7
9
  slashMenuFactory: SuggestionsMenuFactory<any> | undefined;
8
10
  };
9
11
  export declare const SlashMenuPluginKey: PluginKey<any>;
@@ -0,0 +1,5 @@
1
+ import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
2
+ /**
3
+ * An array containing commands for creating all default blocks.
4
+ */
5
+ export declare const defaultSlashMenuItems: BaseSlashMenuItem[];
@@ -1,4 +1,4 @@
1
- import { defaultSlashCommands } from "./defaultSlashCommands";
1
+ import { defaultSlashMenuItems } from "./defaultSlashMenuItems";
2
2
  import { SlashMenuExtension } from "./SlashMenuExtension";
3
- import { SlashMenuItem } from "./SlashMenuItem";
4
- export { defaultSlashCommands, SlashMenuItem as SlashCommand, SlashMenuExtension, };
3
+ import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
4
+ export { defaultSlashMenuItems, BaseSlashMenuItem, SlashMenuExtension };
@@ -4,9 +4,8 @@ export * from "./extensions/Blocks/api/blockTypes";
4
4
  export * from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
5
5
  export * from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
6
6
  export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
7
- export { defaultSlashCommands } from "./extensions/SlashMenu/defaultSlashCommands";
8
- export * from "./extensions/SlashMenu/SlashMenuItem";
7
+ export { defaultSlashMenuItems } from "./extensions/SlashMenu/defaultSlashMenuItems";
8
+ export * from "./extensions/SlashMenu/BaseSlashMenuItem";
9
9
  export * from "./shared/EditorElement";
10
10
  export type { SuggestionItem } from "./shared/plugins/suggestion/SuggestionItem";
11
11
  export * from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
12
- export * from "../src/api/Editor";
@@ -1,16 +1,8 @@
1
1
  /**
2
2
  * A generic interface used in all suggestion menus (slash menu, mentions, etc)
3
3
  */
4
- export interface SuggestionItem {
5
- /**
6
- * The name of the item
7
- */
4
+ export declare class SuggestionItem {
8
5
  name: string;
9
- /**
10
- * This function matches this item against a query string, the function should return **true** if the item
11
- * matches the query or **false** otherwise.
12
- *
13
- * @param query the query string
14
- */
15
- match(query: string): boolean;
6
+ match: (query: string) => boolean;
7
+ constructor(name: string, match: (query: string) => boolean);
16
8
  }
@@ -2,6 +2,7 @@ import { Editor, Range } from "@tiptap/core";
2
2
  import { Plugin, PluginKey } from "prosemirror-state";
3
3
  import { SuggestionsMenuFactory } from "./SuggestionsMenuFactoryTypes";
4
4
  import { SuggestionItem } from "./SuggestionItem";
5
+ import { BlockNoteEditor } from "../../../BlockNoteEditor";
5
6
  export type SuggestionPluginOptions<T extends SuggestionItem> = {
6
7
  /**
7
8
  * The name of the plugin.
@@ -10,9 +11,9 @@ export type SuggestionPluginOptions<T extends SuggestionItem> = {
10
11
  */
11
12
  pluginKey: PluginKey;
12
13
  /**
13
- * The TipTap editor.
14
+ * The BlockNote editor.
14
15
  */
15
- editor: Editor;
16
+ editor: BlockNoteEditor;
16
17
  /**
17
18
  * The character that should trigger the suggestion menu to pop up (e.g. a '/' for commands), when typed by the user.
18
19
  */
@@ -27,8 +28,7 @@ export type SuggestionPluginOptions<T extends SuggestionItem> = {
27
28
  */
28
29
  onSelectItem?: (props: {
29
30
  item: T;
30
- editor: Editor;
31
- range: Range;
31
+ editor: BlockNoteEditor;
32
32
  }) => void;
33
33
  /**
34
34
  * A function that should supply the plugin with items to suggest, based on a certain query string.
@@ -1,2 +1,5 @@
1
1
  export declare const isAppleOS: () => boolean;
2
2
  export declare function formatKeyboardShortcut(shortcut: string): string;
3
+ export declare class UnreachableCaseError extends Error {
4
+ constructor(val: never);
5
+ }