@blocknote/core 0.4.2 → 0.4.4

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 (30) hide show
  1. package/dist/blocknote.js +12248 -12269
  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/package.json +2 -2
  6. package/src/BlockNoteEditor.ts +276 -15
  7. package/src/BlockNoteExtensions.ts +8 -4
  8. package/src/api/formatConversions/formatConversions.ts +4 -4
  9. package/src/extensions/Blocks/api/cursorPositionTypes.ts +2 -0
  10. package/src/extensions/Blocks/nodes/BlockContainer.ts +84 -111
  11. package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +31 -0
  12. package/src/extensions/SlashMenu/SlashMenuExtension.ts +10 -7
  13. package/src/extensions/SlashMenu/{defaultSlashCommands.tsx → defaultSlashMenuItems.tsx} +59 -106
  14. package/src/extensions/SlashMenu/index.ts +3 -7
  15. package/src/index.ts +2 -3
  16. package/src/shared/plugins/suggestion/SuggestionItem.ts +2 -13
  17. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +31 -18
  18. package/types/src/BlockNoteEditor.d.ts +100 -8
  19. package/types/src/BlockNoteExtensions.d.ts +5 -4
  20. package/types/src/api/formatConversions/formatConversions.d.ts +2 -2
  21. package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +2 -0
  22. package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +20 -0
  23. package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +4 -2
  24. package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +5 -0
  25. package/types/src/extensions/SlashMenu/index.d.ts +3 -3
  26. package/types/src/index.d.ts +2 -3
  27. package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +3 -11
  28. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +4 -4
  29. package/src/api/Editor.ts +0 -226
  30. package/src/extensions/SlashMenu/SlashMenuItem.ts +0 -34
@@ -2,10 +2,12 @@ import { Extension } from "@tiptap/core";
2
2
  import { PluginKey } from "prosemirror-state";
3
3
  import { createSuggestionPlugin } from "../../shared/plugins/suggestion/SuggestionPlugin";
4
4
  import { SuggestionsMenuFactory } from "../../shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
5
- import { SlashMenuItem } from "./SlashMenuItem";
5
+ import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
6
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
6
7
 
7
8
  export type SlashMenuOptions = {
8
- commands: SlashMenuItem[] | undefined;
9
+ editor: BlockNoteEditor | undefined;
10
+ commands: BaseSlashMenuItem[] | undefined;
9
11
  slashMenuFactory: SuggestionsMenuFactory<any> | undefined;
10
12
  };
11
13
 
@@ -16,6 +18,7 @@ export const SlashMenuExtension = Extension.create<SlashMenuOptions>({
16
18
 
17
19
  addOptions() {
18
20
  return {
21
+ editor: undefined,
19
22
  commands: undefined,
20
23
  slashMenuFactory: undefined,
21
24
  };
@@ -29,16 +32,16 @@ export const SlashMenuExtension = Extension.create<SlashMenuOptions>({
29
32
  const commands = this.options.commands;
30
33
 
31
34
  return [
32
- createSuggestionPlugin<SlashMenuItem>({
35
+ createSuggestionPlugin<BaseSlashMenuItem>({
33
36
  pluginKey: SlashMenuPluginKey,
34
- editor: this.editor,
37
+ editor: this.options.editor!,
35
38
  defaultTriggerCharacter: "/",
36
39
  suggestionsMenuFactory: this.options.slashMenuFactory!,
37
40
  items: (query) => {
38
- return commands.filter((cmd: SlashMenuItem) => cmd.match(query));
41
+ return commands.filter((cmd: BaseSlashMenuItem) => cmd.match(query));
39
42
  },
40
- onSelectItem: ({ item, editor, range }) => {
41
- item.execute(editor, range);
43
+ onSelectItem: ({ item, editor }) => {
44
+ item.execute(editor);
42
45
  },
43
46
  }),
44
47
  ];
@@ -1,135 +1,88 @@
1
- import { Editor, Range } from "@tiptap/core";
2
- import { formatKeyboardShortcut } from "../../shared/utils";
3
- import { SlashMenuItem } from "./SlashMenuItem";
1
+ import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
2
+ import { PartialBlock } from "../Blocks/api/blockTypes";
3
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
4
+
5
+ function insertOrUpdateBlock(editor: BlockNoteEditor, block: PartialBlock) {
6
+ const currentBlock = editor.getTextCursorPosition().block;
7
+
8
+ if (
9
+ (currentBlock.content.length === 1 &&
10
+ currentBlock.content[0].type === "text" &&
11
+ currentBlock.content[0].text === "/") ||
12
+ currentBlock.content.length === 0
13
+ ) {
14
+ editor.updateBlock(currentBlock, block);
15
+ } else {
16
+ editor.insertBlocks([block], currentBlock, "after");
17
+ editor.setTextCursorPosition(editor.getTextCursorPosition().nextBlock!);
18
+ }
19
+ }
4
20
 
5
21
  /**
6
22
  * An array containing commands for creating all default blocks.
7
23
  */
8
- export const defaultSlashCommands: SlashMenuItem[] = [
24
+ export const defaultSlashMenuItems: BaseSlashMenuItem[] = [
9
25
  // Command for creating a level 1 heading
10
- new SlashMenuItem(
26
+ new BaseSlashMenuItem(
11
27
  "Heading",
12
- (editor: Editor, range: Range) => {
13
- return editor
14
- .chain()
15
- .focus()
16
- .deleteRange(range)
17
- .BNCreateOrUpdateBlock(range.from, {
18
- type: "heading",
19
- props: {
20
- level: "1",
21
- },
22
- })
23
- .run();
24
- },
25
- ["h", "heading1", "h1"],
26
- "Headings",
27
- "Used for a top-level heading",
28
- formatKeyboardShortcut("Mod-Alt-1")
28
+ (editor) =>
29
+ insertOrUpdateBlock(editor, {
30
+ type: "heading",
31
+ props: { level: "1" },
32
+ }),
33
+ ["h", "heading1", "h1"]
29
34
  ),
30
35
 
31
36
  // Command for creating a level 2 heading
32
- new SlashMenuItem(
37
+ new BaseSlashMenuItem(
33
38
  "Heading 2",
34
- (editor: Editor, range: Range) => {
35
- return editor
36
- .chain()
37
- .focus()
38
- .deleteRange(range)
39
- .BNCreateOrUpdateBlock(range.from, {
40
- type: "heading",
41
- props: {
42
- level: "2",
43
- },
44
- })
45
- .run();
46
- },
47
- ["h2", "heading2", "subheading"],
48
- "Headings",
49
- "Used for key sections",
50
- formatKeyboardShortcut("Mod-Alt-2")
39
+ (editor) =>
40
+ insertOrUpdateBlock(editor, {
41
+ type: "heading",
42
+ props: { level: "2" },
43
+ }),
44
+ ["h2", "heading2", "subheading"]
51
45
  ),
52
46
 
53
47
  // Command for creating a level 3 heading
54
- new SlashMenuItem(
48
+ new BaseSlashMenuItem(
55
49
  "Heading 3",
56
- (editor: Editor, range: Range) => {
57
- return editor
58
- .chain()
59
- .focus()
60
- .deleteRange(range)
61
- .BNCreateOrUpdateBlock(range.from, {
62
- type: "heading",
63
- props: {
64
- level: "3",
65
- },
66
- })
67
- .run();
68
- },
69
- ["h3", "heading3", "subheading"],
70
- "Headings",
71
- "Used for subsections and group headings",
72
- formatKeyboardShortcut("Mod-Alt-3")
50
+ (editor) =>
51
+ insertOrUpdateBlock(editor, {
52
+ type: "heading",
53
+ props: { level: "3" },
54
+ }),
55
+ ["h3", "heading3", "subheading"]
73
56
  ),
74
57
 
75
58
  // Command for creating an ordered list
76
- new SlashMenuItem(
59
+ new BaseSlashMenuItem(
77
60
  "Numbered List",
78
- (editor: Editor, range: Range) => {
79
- return editor
80
- .chain()
81
- .focus()
82
- .deleteRange(range)
83
- .BNCreateOrUpdateBlock(range.from, {
84
- type: "numberedListItem",
85
- props: {},
86
- })
87
- .run();
88
- },
89
- ["li", "list", "numberedlist", "numbered list"],
90
- "Basic blocks",
91
- "Used to display a numbered list",
92
- "Mod-Alt-7"
61
+ (editor) =>
62
+ insertOrUpdateBlock(editor, {
63
+ type: "numberedListItem",
64
+ }),
65
+ ["li", "list", "numberedlist", "numbered list"]
93
66
  ),
94
67
 
95
68
  // Command for creating a bullet list
96
- new SlashMenuItem(
69
+ new BaseSlashMenuItem(
97
70
  "Bullet List",
98
- (editor: Editor, range: Range) => {
99
- return editor
100
- .chain()
101
- .focus()
102
- .deleteRange(range)
103
- .BNCreateOrUpdateBlock(range.from, {
104
- type: "bulletListItem",
105
- props: {},
106
- })
107
- .run();
108
- },
109
- ["ul", "list", "bulletlist", "bullet list"],
110
- "Basic blocks",
111
- "Used to display an unordered list",
112
- "Mod-Alt-9"
71
+ (editor) =>
72
+ insertOrUpdateBlock(editor, {
73
+ type: "bulletListItem",
74
+ }),
75
+ ["ul", "list", "bulletlist", "bullet list"]
113
76
  ),
114
77
 
115
78
  // Command for creating a paragraph (pretty useless)
116
- new SlashMenuItem(
79
+ new BaseSlashMenuItem(
117
80
  "Paragraph",
118
- (editor: Editor, range: Range) => {
119
- return editor
120
- .chain()
121
- .focus()
122
- .deleteRange(range)
123
- .BNCreateOrUpdateBlock(range.from, {
124
- type: "paragraph",
125
- props: {},
126
- })
127
- .run();
128
- },
129
- ["p"],
130
- "Basic blocks",
131
- "Used for the body of your document",
132
- "Mod-Alt-0"
81
+ (editor) =>
82
+ insertOrUpdateBlock(editor, {
83
+ type: "paragraph",
84
+ }),
85
+ ["p"]
133
86
  ),
134
87
 
135
88
  // replaceRangeWithNode(editor, range, node);
@@ -1,9 +1,5 @@
1
- import { defaultSlashCommands } from "./defaultSlashCommands";
1
+ import { defaultSlashMenuItems } from "./defaultSlashMenuItems";
2
2
  import { SlashMenuExtension } from "./SlashMenuExtension";
3
- import { SlashMenuItem } from "./SlashMenuItem";
3
+ import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
4
4
 
5
- export {
6
- defaultSlashCommands,
7
- SlashMenuItem as SlashCommand,
8
- SlashMenuExtension,
9
- };
5
+ export { defaultSlashMenuItems, BaseSlashMenuItem, SlashMenuExtension };
package/src/index.ts CHANGED
@@ -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,17 +1,6 @@
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
- */
8
- name: string;
9
-
10
- /**
11
- * This function matches this item against a query string, the function should return **true** if the item
12
- * matches the query or **false** otherwise.
13
- *
14
- * @param query the query string
15
- */
16
- match(query: string): boolean;
4
+ export class SuggestionItem {
5
+ constructor(public name: string, public match: (query: string) => boolean) {}
17
6
  }
@@ -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
 
@@ -1,22 +1,114 @@
1
- import { Editor } from "@tiptap/core";
2
- import { Editor as EditorAPI } from "./api/Editor";
1
+ import { Block, BlockIdentifier, 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: (editor: BlockNoteEditor) => void;
13
- onCreate: (editor: BlockNoteEditor) => void;
13
+ onEditorCreate: (editor: BlockNoteEditor) => void;
14
+ onEditorContentChange: (editor: BlockNoteEditor) => void;
15
+ onTextCursorPositionChange: (editor: BlockNoteEditor) => void;
14
16
  _tiptapOptions: any;
15
17
  };
16
- export declare class BlockNoteEditor extends EditorAPI {
17
- readonly _tiptapEditor: Editor & {
18
+ export declare class BlockNoteEditor {
19
+ readonly _tiptapEditor: TiptapEditor & {
18
20
  contentComponent: any;
19
21
  };
22
+ private blockCache;
20
23
  get domElement(): HTMLDivElement;
21
24
  constructor(options?: Partial<BlockNoteEditorOptions>);
25
+ /**
26
+ * Gets a snapshot of all top-level (non-nested) blocks in the editor.
27
+ * @returns A snapshot of all top-level (non-nested) blocks in the editor.
28
+ */
29
+ get topLevelBlocks(): Block[];
30
+ /**
31
+ * Gets a snapshot of an existing block from the editor.
32
+ * @param blockIdentifier The identifier of an existing block that should be retrieved.
33
+ * @returns The block that matches the identifier, or `undefined` if no matching block was found.
34
+ */
35
+ getBlock(blockIdentifier: BlockIdentifier): Block | undefined;
36
+ /**
37
+ * Traverses all blocks in the editor depth-first, and executes a callback for each.
38
+ * @param callback The callback to execute for each block. Returning `false` stops the traversal.
39
+ * @param reverse Whether the blocks should be traversed in reverse order.
40
+ */
41
+ forEachBlock(callback: (block: Block) => void, reverse?: boolean): void;
42
+ /**
43
+ * Gets a snapshot of the current text cursor position.
44
+ * @returns A snapshot of the current text cursor position.
45
+ */
46
+ getTextCursorPosition(): TextCursorPosition;
47
+ /**
48
+ * Sets the text cursor position to the start or end of an existing block. Throws an error if the target block could
49
+ * not be found.
50
+ * @param targetBlock The identifier of an existing block that the text cursor should be moved to.
51
+ * @param placement Whether the text cursor should be placed at the start or end of the block.
52
+ */
53
+ setTextCursorPosition(targetBlock: BlockIdentifier, placement?: "start" | "end"): void;
54
+ /**
55
+ * Inserts new blocks into the editor. If a block's `id` is undefined, BlockNote generates one automatically. Throws an
56
+ * error if the reference block could not be found.
57
+ * @param blocksToInsert An array of partial blocks that should be inserted.
58
+ * @param referenceBlock An identifier for an existing block, at which the new blocks should be inserted.
59
+ * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
60
+ * `referenceBlock`. Inserts the blocks at the start of the existing block's children if "nested" is used.
61
+ */
62
+ insertBlocks(blocksToInsert: PartialBlock[], referenceBlock: BlockIdentifier, placement?: "before" | "after" | "nested"): void;
63
+ /**
64
+ * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
65
+ * defined. These undefined fields are kept as-is from the existing block. Throws an error if the block to update could
66
+ * not be found.
67
+ * @param blockToUpdate The block that should be updated.
68
+ * @param update A partial block which defines how the existing block should be changed.
69
+ */
70
+ updateBlock(blockToUpdate: Block, update: PartialBlock): void;
71
+ /**
72
+ * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
73
+ * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
74
+ */
75
+ removeBlocks(blocksToRemove: Block[]): void;
76
+ /**
77
+ * Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
78
+ * are at different nesting levels, `blocksToInsert` will be inserted at the position of the first block in
79
+ * `blocksToRemove`. Throws an error if any of the blocks to remove could not be found.
80
+ * @param blocksToRemove An array of blocks that should be replaced.
81
+ * @param blocksToInsert An array of partial blocks to replace the old ones with.
82
+ */
83
+ replaceBlocks(blocksToRemove: Block[], blocksToInsert: PartialBlock[]): void;
84
+ /**
85
+ * Serializes blocks into an HTML string. To better conform to HTML standards, children of blocks which aren't list
86
+ * items are un-nested in the output HTML.
87
+ * @param blocks An array of blocks that should be serialized into HTML.
88
+ * @returns The blocks, serialized as an HTML string.
89
+ */
90
+ blocksToHTML(blocks: Block[]): Promise<string>;
91
+ /**
92
+ * Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
93
+ * `InlineNode` objects from any HTML inline elements, though not all element types are recognized. If BlockNote
94
+ * doesn't recognize an HTML element's tag, it will parse it as a paragraph or plain text.
95
+ * @param html The HTML string to parse blocks from.
96
+ * @returns The blocks parsed from the HTML string.
97
+ */
98
+ HTMLToBlocks(html: string): Promise<Block[]>;
99
+ /**
100
+ * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
101
+ * BlockNote - children of blocks which aren't list items are un-nested and certain styles are removed.
102
+ * @param blocks An array of blocks that should be serialized into Markdown.
103
+ * @returns The blocks, serialized as a Markdown string.
104
+ */
105
+ blocksToMarkdown(blocks: Block[]): Promise<string>;
106
+ /**
107
+ * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
108
+ * Markdown syntax, though not all symbols are recognized. If BlockNote doesn't recognize a symbol, it will parse it
109
+ * as text.
110
+ * @param markdown The Markdown string to parse blocks from.
111
+ * @returns The blocks parsed from the Markdown string.
112
+ */
113
+ markdownToBlocks(markdown: string): Promise<Block[]>;
22
114
  }
@@ -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,6 +1,6 @@
1
1
  import { Schema } from "prosemirror-model";
2
2
  import { Block } from "../../extensions/Blocks/api/blockTypes";
3
3
  export declare function blocksToHTML(blocks: Block[], schema: Schema): Promise<string>;
4
- export declare function HTMLToBlocks(htmlString: string, schema: Schema): Promise<Block[]>;
4
+ export declare function HTMLToBlocks(html: string, schema: Schema): Promise<Block[]>;
5
5
  export declare function blocksToMarkdown(blocks: Block[], schema: Schema): Promise<string>;
6
- export declare function markdownToBlocks(markdownString: string, schema: Schema): Promise<Block[]>;
6
+ export declare function markdownToBlocks(markdown: string, schema: Schema): Promise<Block[]>;
@@ -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
  };
@@ -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
  }