@blocknote/core 0.8.2 → 0.8.4-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +4 -0
  2. package/dist/blocknote.js +1777 -1849
  3. package/dist/blocknote.js.map +1 -1
  4. package/dist/blocknote.umd.cjs +4 -4
  5. package/dist/blocknote.umd.cjs.map +1 -1
  6. package/dist/style.css +1 -1
  7. package/package.json +4 -4
  8. package/src/BlockNoteEditor.ts +89 -39
  9. package/src/BlockNoteExtensions.ts +1 -58
  10. package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +10 -10
  11. package/src/api/formatConversions/formatConversions.test.ts +587 -605
  12. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +15 -15
  13. package/src/api/nodeConversions/nodeConversions.test.ts +90 -94
  14. package/src/extensions/Blocks/api/blockTypes.ts +3 -2
  15. package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +6 -0
  16. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +101 -114
  17. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +184 -149
  18. package/src/extensions/Placeholder/PlaceholderExtension.ts +2 -2
  19. package/src/extensions/{DraggableBlocks/DraggableBlocksPlugin.ts → SideMenu/SideMenuPlugin.ts} +181 -164
  20. package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +7 -30
  21. package/src/extensions/SlashMenu/SlashMenuPlugin.ts +51 -0
  22. package/src/extensions/SlashMenu/defaultSlashMenuItems.ts +109 -0
  23. package/src/extensions/UniqueID/UniqueID.ts +29 -30
  24. package/src/index.ts +9 -8
  25. package/src/shared/BaseUiElementTypes.ts +8 -0
  26. package/src/shared/EditorElement.ts +0 -16
  27. package/src/shared/EventEmitter.ts +58 -0
  28. package/src/shared/plugins/suggestion/SuggestionItem.ts +3 -6
  29. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +341 -403
  30. package/types/src/BlockNoteEditor.d.ts +18 -11
  31. package/types/src/BlockNoteExtensions.d.ts +0 -19
  32. package/types/src/extensions/Blocks/api/blockTypes.d.ts +3 -2
  33. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +18 -24
  34. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +37 -10
  35. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +79 -0
  36. package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +5 -18
  37. package/types/src/extensions/SlashMenu/SlashMenuPlugin.d.ts +13 -0
  38. package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +1 -69
  39. package/types/src/index.d.ts +9 -8
  40. package/types/src/shared/BaseUiElementTypes.d.ts +7 -0
  41. package/types/src/shared/EditorElement.d.ts +0 -10
  42. package/types/src/shared/EventEmitter.d.ts +11 -0
  43. package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +2 -7
  44. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +12 -43
  45. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +0 -29
  46. package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +0 -37
  47. package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +0 -37
  48. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +0 -18
  49. package/src/extensions/HyperlinkToolbar/HyperlinkMark.ts +0 -28
  50. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.ts +0 -19
  51. package/src/extensions/SlashMenu/SlashMenuExtension.ts +0 -53
  52. package/src/extensions/SlashMenu/defaultSlashMenuItems.tsx +0 -195
  53. package/src/extensions/SlashMenu/index.ts +0 -5
  54. package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +0 -21
  55. package/types/src/CustomBlock.d.ts +0 -15
  56. package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableCol.d.ts +0 -2
  57. package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableContent.d.ts +0 -2
  58. package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableRow.d.ts +0 -2
  59. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +0 -17
  60. package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +0 -16
  61. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +0 -49
  62. package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +0 -11
  63. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +0 -10
  64. package/types/src/extensions/HyperlinkToolbar/HyperlinkMark.d.ts +0 -8
  65. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.d.ts +0 -12
  66. package/types/src/extensions/Placeholder/localisation/index.d.ts +0 -2
  67. package/types/src/extensions/Placeholder/localisation/translation.d.ts +0 -51
  68. package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +0 -13
  69. package/types/src/extensions/SlashMenu/index.d.ts +0 -4
  70. package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +0 -12
  71. /package/src/extensions/{DraggableBlocks → SideMenu}/MultipleNodeSelection.ts +0 -0
  72. /package/types/src/extensions/{DraggableBlocks → SideMenu}/MultipleNodeSelection.d.ts +0 -0
@@ -1,28 +1,25 @@
1
1
  import { Node } from "prosemirror-model";
2
2
  import { Editor as TiptapEditor } from "@tiptap/core/dist/packages/core/src/Editor";
3
3
  import * as Y from "yjs";
4
- import { UiFactories } from "./BlockNoteExtensions";
5
4
  import { Block, BlockIdentifier, BlockSchema, PartialBlock } from "./extensions/Blocks/api/blockTypes";
6
5
  import { TextCursorPosition } from "./extensions/Blocks/api/cursorPositionTypes";
7
6
  import { DefaultBlockSchema } from "./extensions/Blocks/api/defaultBlocks";
8
7
  import { Styles } from "./extensions/Blocks/api/inlineContentTypes";
9
8
  import { Selection } from "./extensions/Blocks/api/selectionTypes";
10
- import { BaseSlashMenuItem } from "./extensions/SlashMenu";
9
+ import { FormattingToolbarProsemirrorPlugin } from "./extensions/FormattingToolbar/FormattingToolbarPlugin";
10
+ import { HyperlinkToolbarProsemirrorPlugin } from "./extensions/HyperlinkToolbar/HyperlinkToolbarPlugin";
11
+ import { SideMenuProsemirrorPlugin } from "./extensions/SideMenu/SideMenuPlugin";
12
+ import { BaseSlashMenuItem } from "./extensions/SlashMenu/BaseSlashMenuItem";
13
+ import { SlashMenuProsemirrorPlugin } from "./extensions/SlashMenu/SlashMenuPlugin";
11
14
  export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
12
15
  enableBlockNoteExtensions: boolean;
13
16
  /**
14
- * UI element factories for creating a custom UI, including custom positioning
15
- * & rendering.
16
- */
17
- uiFactories: UiFactories<BSchema>;
18
- /**
19
- * TODO: why is this called slashCommands and not slashMenuItems?
20
17
  *
21
18
  * (couldn't fix any type, see https://github.com/TypeCellOS/BlockNote/pull/191#discussion_r1210708771)
22
19
  *
23
20
  * @default defaultSlashMenuItems from `./extensions/SlashMenu`
24
21
  */
25
- slashCommands: BaseSlashMenuItem<any>[];
22
+ slashMenuItems: BaseSlashMenuItem<any>[];
26
23
  /**
27
24
  * The HTML element that should be used as the parent element for the editor.
28
25
  *
@@ -104,11 +101,16 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
104
101
  };
105
102
  blockCache: WeakMap<Node, Block<BSchema>>;
106
103
  readonly schema: BSchema;
107
- private ready;
104
+ ready: boolean;
105
+ readonly sideMenu: SideMenuProsemirrorPlugin<BSchema>;
106
+ readonly formattingToolbar: FormattingToolbarProsemirrorPlugin<BSchema>;
107
+ readonly slashMenu: SlashMenuProsemirrorPlugin<BSchema, any>;
108
+ readonly hyperlinkToolbar: HyperlinkToolbarProsemirrorPlugin<BSchema>;
109
+ constructor(options?: Partial<BlockNoteEditorOptions<BSchema>>);
110
+ get prosemirrorView(): import("prosemirror-view").EditorView;
108
111
  get domElement(): HTMLDivElement;
109
112
  isFocused(): boolean;
110
113
  focus(): void;
111
- constructor(options?: Partial<BlockNoteEditorOptions<BSchema>>);
112
114
  /**
113
115
  * Gets a snapshot of all top-level (non-nested) blocks in the editor.
114
116
  * @returns A snapshot of all top-level (non-nested) blocks in the editor.
@@ -131,6 +133,11 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
131
133
  * @param callback The callback to execute.
132
134
  */
133
135
  onEditorContentChange(callback: () => void): void;
136
+ /**
137
+ * Executes a callback whenever the editor's selection changes.
138
+ * @param callback The callback to execute.
139
+ */
140
+ onEditorSelectionChange(callback: () => void): void;
134
141
  /**
135
142
  * Gets a snapshot of the current text cursor position.
136
143
  * @returns A snapshot of the current text cursor position.
@@ -1,30 +1,11 @@
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";
5
- import { BlockSideMenuFactory } from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
6
- import { FormattingToolbarFactory } from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
7
- import { HyperlinkToolbarFactory } from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
8
- import { BaseSlashMenuItem } from "./extensions/SlashMenu";
9
- import { SuggestionsMenuFactory } from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
10
- export type UiFactories<BSchema extends BlockSchema> = Partial<{
11
- formattingToolbarFactory: FormattingToolbarFactory<BSchema>;
12
- hyperlinkToolbarFactory: HyperlinkToolbarFactory;
13
- slashMenuFactory: SuggestionsMenuFactory<BaseSlashMenuItem<BSchema>>;
14
- blockSideMenuFactory: BlockSideMenuFactory<BSchema>;
15
- }>;
16
4
  /**
17
5
  * Get all the Tiptap extensions BlockNote is configured with by default
18
6
  */
19
7
  export declare const getBlockNoteExtensions: <BSchema extends Record<string, import("./extensions/Blocks/api/blockTypes").BlockSpec<string, import("./extensions/Blocks/api/blockTypes").PropSchema>>>(opts: {
20
8
  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
9
  blockSchema: BSchema;
29
10
  collaboration?: {
30
11
  fragment: Y.XmlFragment;
@@ -2,6 +2,7 @@
2
2
  import { Node, NodeConfig } from "@tiptap/core";
3
3
  import { BlockNoteEditor } from "../../../BlockNoteEditor";
4
4
  import { InlineContent, PartialInlineContent } from "./inlineContentTypes";
5
+ import { DefaultBlockSchema } from "./defaultBlocks";
5
6
  export type TipTapNodeConfig<Name extends string, Options = any, Storage = any> = {
6
7
  [K in keyof NodeConfig<Options, Storage>]: K extends "name" ? Name : K extends "group" ? never : NodeConfig<Options, Storage>[K];
7
8
  };
@@ -58,7 +59,7 @@ type BlocksWithoutChildren<BSchema extends BlockSchema> = {
58
59
  content: InlineContent[];
59
60
  };
60
61
  };
61
- export type Block<BSchema extends BlockSchema> = BlocksWithoutChildren<BSchema>[keyof BlocksWithoutChildren<BSchema>] & {
62
+ export type Block<BSchema extends BlockSchema = DefaultBlockSchema> = BlocksWithoutChildren<BSchema>[keyof BlocksWithoutChildren<BSchema>] & {
62
63
  children: Block<BSchema>[];
63
64
  };
64
65
  export type SpecificBlock<BSchema extends BlockSchema, BlockType extends keyof BSchema> = BlocksWithoutChildren<BSchema>[BlockType] & {
@@ -72,7 +73,7 @@ type PartialBlocksWithoutChildren<BSchema extends BlockSchema> = {
72
73
  content: PartialInlineContent[] | string;
73
74
  }>;
74
75
  };
75
- export type PartialBlock<BSchema extends BlockSchema> = PartialBlocksWithoutChildren<BSchema>[keyof PartialBlocksWithoutChildren<BSchema>] & Partial<{
76
+ export type PartialBlock<BSchema extends BlockSchema = DefaultBlockSchema> = PartialBlocksWithoutChildren<BSchema>[keyof PartialBlocksWithoutChildren<BSchema>] & Partial<{
76
77
  children: PartialBlock<BSchema>[];
77
78
  }>;
78
79
  export type BlockIdentifier = {
@@ -1,44 +1,38 @@
1
- import { Editor } from "@tiptap/core";
2
1
  import { EditorState, Plugin, PluginKey } from "prosemirror-state";
3
2
  import { EditorView } from "prosemirror-view";
4
- import { BlockNoteEditor, BlockSchema } from "../..";
5
- import { FormattingToolbar, FormattingToolbarFactory, FormattingToolbarStaticParams } from "./FormattingToolbarFactoryTypes";
6
- export interface FormattingToolbarPluginProps<BSchema extends BlockSchema> {
7
- pluginKey: PluginKey;
8
- tiptapEditor: Editor;
9
- editor: BlockNoteEditor<BSchema>;
10
- formattingToolbarFactory: FormattingToolbarFactory<BSchema>;
11
- }
12
- export type FormattingToolbarViewProps<BSchema extends BlockSchema> = FormattingToolbarPluginProps<BSchema> & {
13
- view: EditorView;
14
- };
3
+ import { BaseUiElementCallbacks, BaseUiElementState, BlockNoteEditor, BlockSchema } from "../..";
4
+ import { EventEmitter } from "../../shared/EventEmitter";
5
+ export type FormattingToolbarCallbacks = BaseUiElementCallbacks;
6
+ export type FormattingToolbarState = BaseUiElementState;
15
7
  export declare class FormattingToolbarView<BSchema extends BlockSchema> {
16
- editor: BlockNoteEditor<BSchema>;
17
- private ttEditor;
18
- view: EditorView;
19
- formattingToolbar: FormattingToolbar;
8
+ private readonly editor;
9
+ private readonly pmView;
10
+ private formattingToolbarState?;
11
+ updateFormattingToolbar: () => void;
20
12
  preventHide: boolean;
21
13
  preventShow: boolean;
22
- toolbarIsOpen: boolean;
23
14
  prevWasEditable: boolean | null;
24
- private lastPosition;
25
15
  shouldShow: (props: {
26
16
  view: EditorView;
27
17
  state: EditorState;
28
18
  from: number;
29
19
  to: number;
30
20
  }) => boolean;
31
- constructor({ editor, tiptapEditor, formattingToolbarFactory, view, }: FormattingToolbarViewProps<BSchema>);
21
+ constructor(editor: BlockNoteEditor<BSchema>, pmView: EditorView, updateFormattingToolbar: (formattingToolbarState: FormattingToolbarState) => void);
32
22
  viewMousedownHandler: () => void;
33
23
  viewMouseupHandler: () => void;
34
24
  dragstartHandler: () => void;
35
25
  focusHandler: () => void;
36
- blurHandler: ({ event }: {
37
- event: FocusEvent;
38
- }) => void;
26
+ blurHandler: (event: FocusEvent) => void;
27
+ scrollHandler: () => void;
39
28
  update(view: EditorView, oldState?: EditorState): void;
40
29
  destroy(): void;
41
30
  getSelectionBoundingBox(): DOMRect;
42
- getStaticParams(): FormattingToolbarStaticParams<BSchema>;
43
31
  }
44
- export declare const createFormattingToolbarPlugin: <BSchema extends Record<string, import("../..").BlockSpec<string, import("../..").PropSchema>>>(options: FormattingToolbarPluginProps<BSchema>) => Plugin<any>;
32
+ export declare const formattingToolbarPluginKey: PluginKey<any>;
33
+ export declare class FormattingToolbarProsemirrorPlugin<BSchema extends BlockSchema> extends EventEmitter<any> {
34
+ private view;
35
+ readonly plugin: Plugin;
36
+ constructor(editor: BlockNoteEditor<BSchema>);
37
+ onUpdate(callback: (state: FormattingToolbarState) => void): () => void;
38
+ }
@@ -1,11 +1,38 @@
1
- import { Editor } from "@tiptap/core";
2
- import { Plugin } from "prosemirror-state";
3
- import { HyperlinkToolbarFactory } from "./HyperlinkToolbarFactoryTypes";
4
- export type HyperlinkToolbarPluginProps = {
5
- hyperlinkToolbarFactory: HyperlinkToolbarFactory;
1
+ import { Plugin, PluginKey } from "prosemirror-state";
2
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
3
+ import { BaseUiElementState } from "../../shared/BaseUiElementTypes";
4
+ import { EventEmitter } from "../../shared/EventEmitter";
5
+ import { BlockSchema } from "../Blocks/api/blockTypes";
6
+ export type HyperlinkToolbarState = BaseUiElementState & {
7
+ url: string;
8
+ text: string;
6
9
  };
7
- export type HyperlinkToolbarViewProps = {
8
- editor: Editor;
9
- hyperlinkToolbarFactory: HyperlinkToolbarFactory;
10
- };
11
- export declare const createHyperlinkToolbarPlugin: (editor: Editor, options: HyperlinkToolbarPluginProps) => Plugin<any>;
10
+ export declare const hyperlinkToolbarPluginKey: PluginKey<any>;
11
+ export declare class HyperlinkToolbarProsemirrorPlugin<BSchema extends BlockSchema> extends EventEmitter<any> {
12
+ private view;
13
+ readonly plugin: Plugin;
14
+ constructor(editor: BlockNoteEditor<BSchema>);
15
+ onUpdate(callback: (state: HyperlinkToolbarState) => void): () => void;
16
+ /**
17
+ * Edit the currently hovered hyperlink.
18
+ */
19
+ editHyperlink: (url: string, text: string) => void;
20
+ /**
21
+ * Delete the currently hovered hyperlink.
22
+ */
23
+ deleteHyperlink: () => void;
24
+ /**
25
+ * When hovering on/off hyperlinks using the mouse cursor, the hyperlink
26
+ * toolbar will open & close with a delay.
27
+ *
28
+ * This function starts the delay timer, and should be used for when the mouse cursor enters the hyperlink toolbar.
29
+ */
30
+ startHideTimer: () => void;
31
+ /**
32
+ * When hovering on/off hyperlinks using the mouse cursor, the hyperlink
33
+ * toolbar will open & close with a delay.
34
+ *
35
+ * This function stops the delay timer, and should be used for when the mouse cursor exits the hyperlink toolbar.
36
+ */
37
+ stopHideTimer: () => void;
38
+ }
@@ -0,0 +1,79 @@
1
+ import { PluginView } from "@tiptap/pm/state";
2
+ import { Plugin, PluginKey } from "prosemirror-state";
3
+ import { EditorView } from "prosemirror-view";
4
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
5
+ import { BaseUiElementState } from "../../shared/BaseUiElementTypes";
6
+ import { EventEmitter } from "../../shared/EventEmitter";
7
+ import { Block, BlockSchema } from "../Blocks/api/blockTypes";
8
+ export type SideMenuState<BSchema extends BlockSchema> = BaseUiElementState & {
9
+ block: Block<BSchema>;
10
+ };
11
+ export declare class SideMenuView<BSchema extends BlockSchema> implements PluginView {
12
+ private readonly editor;
13
+ private readonly pmView;
14
+ private readonly updateSideMenu;
15
+ private sideMenuState?;
16
+ private horizontalPosAnchoredAtRoot;
17
+ private horizontalPosAnchor;
18
+ private hoveredBlock;
19
+ isDragging: boolean;
20
+ menuFrozen: boolean;
21
+ constructor(editor: BlockNoteEditor<BSchema>, pmView: EditorView, updateSideMenu: (sideMenuState: SideMenuState<BSchema>) => void);
22
+ /**
23
+ * Sets isDragging when dragging text.
24
+ */
25
+ onDragStart: () => void;
26
+ /**
27
+ * If the event is outside the editor contents,
28
+ * we dispatch a fake event, so that we can still drop the content
29
+ * when dragging / dropping to the side of the editor
30
+ */
31
+ onDrop: (event: DragEvent) => void;
32
+ /**
33
+ * If the event is outside the editor contents,
34
+ * we dispatch a fake event, so that we can still drop the content
35
+ * when dragging / dropping to the side of the editor
36
+ */
37
+ onDragOver: (event: DragEvent) => void;
38
+ onKeyDown: (_event: KeyboardEvent) => void;
39
+ onMouseMove: (event: MouseEvent) => void;
40
+ onScroll: () => void;
41
+ destroy(): void;
42
+ addBlock(): void;
43
+ }
44
+ export declare const sideMenuPluginKey: PluginKey<any>;
45
+ export declare class SideMenuProsemirrorPlugin<BSchema extends BlockSchema> extends EventEmitter<any> {
46
+ private readonly editor;
47
+ private sideMenuView;
48
+ readonly plugin: Plugin;
49
+ constructor(editor: BlockNoteEditor<BSchema>);
50
+ onUpdate(callback: (state: SideMenuState<BSchema>) => void): () => void;
51
+ /**
52
+ * If the block is empty, opens the slash menu. If the block has content,
53
+ * creates a new block below and opens the slash menu in it.
54
+ */
55
+ addBlock: () => void;
56
+ /**
57
+ * Handles drag & drop events for blocks.
58
+ */
59
+ blockDragStart: (event: {
60
+ dataTransfer: DataTransfer | null;
61
+ clientY: number;
62
+ }) => void;
63
+ /**
64
+ * Handles drag & drop events for blocks.
65
+ */
66
+ blockDragEnd: () => void;
67
+ /**
68
+ * Freezes the side menu. When frozen, the side menu will stay
69
+ * attached to the same block regardless of which block is hovered by the
70
+ * mouse cursor.
71
+ */
72
+ freezeMenu: () => boolean;
73
+ /**
74
+ * Unfreezes the side menu. When frozen, the side menu will stay
75
+ * attached to the same block regardless of which block is hovered by the
76
+ * mouse cursor.
77
+ */
78
+ unfreezeMenu: () => boolean;
79
+ }
@@ -1,21 +1,8 @@
1
1
  import { SuggestionItem } from "../../shared/plugins/suggestion/SuggestionItem";
2
2
  import { BlockNoteEditor } from "../../BlockNoteEditor";
3
3
  import { BlockSchema } from "../Blocks/api/blockTypes";
4
- /**
5
- * A class that defines a slash command (/<command>).
6
- *
7
- * (Not to be confused with ProseMirror commands nor TipTap commands.)
8
- */
9
- export declare class BaseSlashMenuItem<BSchema extends BlockSchema> extends SuggestionItem {
10
- readonly name: string;
11
- readonly execute: (editor: BlockNoteEditor<BSchema>) => void;
12
- readonly aliases: string[];
13
- /**
14
- * Constructs a new slash-command.
15
- *
16
- * @param name The name of the command
17
- * @param execute The callback for creating a new node
18
- * @param aliases Aliases for this command
19
- */
20
- constructor(name: string, execute: (editor: BlockNoteEditor<BSchema>) => void, aliases?: string[]);
21
- }
4
+ import { DefaultBlockSchema } from "../Blocks/api/defaultBlocks";
5
+ export type BaseSlashMenuItem<BSchema extends BlockSchema = DefaultBlockSchema> = SuggestionItem & {
6
+ execute: (editor: BlockNoteEditor<BSchema>) => void;
7
+ aliases?: string[];
8
+ };
@@ -0,0 +1,13 @@
1
+ import { Plugin, PluginKey } from "prosemirror-state";
2
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
3
+ import { EventEmitter } from "../../shared/EventEmitter";
4
+ import { SuggestionsMenuState } from "../../shared/plugins/suggestion/SuggestionPlugin";
5
+ import { BlockSchema } from "../Blocks/api/blockTypes";
6
+ import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
7
+ export declare const slashMenuPluginKey: PluginKey<any>;
8
+ export declare class SlashMenuProsemirrorPlugin<BSchema extends BlockSchema, SlashMenuItem extends BaseSlashMenuItem<BSchema>> extends EventEmitter<any> {
9
+ readonly plugin: Plugin;
10
+ readonly itemCallback: (item: SlashMenuItem) => void;
11
+ constructor(editor: BlockNoteEditor<BSchema>, items: SlashMenuItem[]);
12
+ onUpdate(callback: (state: SuggestionsMenuState<SlashMenuItem>) => void): () => void;
13
+ }
@@ -1,70 +1,2 @@
1
1
  import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
2
- /**
3
- * An array containing commands for creating all default blocks.
4
- */
5
- export declare const defaultSlashMenuItems: BaseSlashMenuItem<{
6
- readonly paragraph: {
7
- readonly propSchema: {
8
- backgroundColor: {
9
- default: "transparent";
10
- };
11
- textColor: {
12
- default: "black";
13
- };
14
- textAlignment: {
15
- default: "left";
16
- values: readonly ["left", "center", "right", "justify"];
17
- };
18
- };
19
- readonly node: import("../Blocks/api/blockTypes").TipTapNode<"paragraph">;
20
- };
21
- readonly heading: {
22
- readonly propSchema: {
23
- readonly level: {
24
- readonly default: "1";
25
- readonly values: readonly ["1", "2", "3"];
26
- };
27
- readonly backgroundColor: {
28
- default: "transparent";
29
- };
30
- readonly textColor: {
31
- default: "black";
32
- };
33
- readonly textAlignment: {
34
- default: "left";
35
- values: readonly ["left", "center", "right", "justify"];
36
- };
37
- };
38
- readonly node: import("../Blocks/api/blockTypes").TipTapNode<"heading">;
39
- };
40
- readonly bulletListItem: {
41
- readonly propSchema: {
42
- backgroundColor: {
43
- default: "transparent";
44
- };
45
- textColor: {
46
- default: "black";
47
- };
48
- textAlignment: {
49
- default: "left";
50
- values: readonly ["left", "center", "right", "justify"];
51
- };
52
- };
53
- readonly node: import("../Blocks/api/blockTypes").TipTapNode<"bulletListItem">;
54
- };
55
- readonly numberedListItem: {
56
- readonly propSchema: {
57
- backgroundColor: {
58
- default: "transparent";
59
- };
60
- textColor: {
61
- default: "black";
62
- };
63
- textAlignment: {
64
- default: "left";
65
- values: readonly ["left", "center", "right", "justify"];
66
- };
67
- };
68
- readonly node: import("../Blocks/api/blockTypes").TipTapNode<"numberedListItem">;
69
- };
70
- }>[];
2
+ export declare const getDefaultSlashMenuItems: <BSchema extends Record<string, import("../Blocks/api/blockTypes").BlockSpec<string, import("../Blocks/api/blockTypes").PropSchema>>>(schema?: BSchema) => BaseSlashMenuItem<BSchema>[];
@@ -3,14 +3,15 @@ export * from "./BlockNoteExtensions";
3
3
  export * from "./extensions/Blocks/api/block";
4
4
  export * from "./extensions/Blocks/api/blockTypes";
5
5
  export * from "./extensions/Blocks/api/defaultBlocks";
6
- export * from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
7
- export * from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
8
- export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
9
- export { defaultSlashMenuItems } from "./extensions/SlashMenu/defaultSlashMenuItems";
10
- export * from "./extensions/SlashMenu/BaseSlashMenuItem";
11
- export * from "./shared/EditorElement";
12
- export type { SuggestionItem } from "./shared/plugins/suggestion/SuggestionItem";
13
- export * from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
14
6
  export * from "./extensions/Blocks/api/inlineContentTypes";
15
7
  export * from "./extensions/Blocks/api/serialization";
16
8
  export * as blockStyles from "./extensions/Blocks/nodes/Block.module.css";
9
+ export * from "./extensions/FormattingToolbar/FormattingToolbarPlugin";
10
+ export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarPlugin";
11
+ export * from "./extensions/SideMenu/SideMenuPlugin";
12
+ export * from "./extensions/SlashMenu/BaseSlashMenuItem";
13
+ export * from "./extensions/SlashMenu/SlashMenuPlugin";
14
+ export { getDefaultSlashMenuItems } from "./extensions/SlashMenu/defaultSlashMenuItems";
15
+ export * from "./shared/BaseUiElementTypes";
16
+ export type { SuggestionItem } from "./shared/plugins/suggestion/SuggestionItem";
17
+ export * from "./shared/plugins/suggestion/SuggestionPlugin";
@@ -0,0 +1,7 @@
1
+ export type BaseUiElementCallbacks = {
2
+ destroy: () => void;
3
+ };
4
+ export type BaseUiElementState = {
5
+ show: boolean;
6
+ referencePos: DOMRect;
7
+ };
@@ -1,10 +0,0 @@
1
- export type RequiredStaticParams = Record<string, any> & {
2
- getReferenceRect: () => DOMRect;
3
- };
4
- export type RequiredDynamicParams = Record<string, any> & {};
5
- export type EditorElement<ElementDynamicParams extends RequiredDynamicParams> = {
6
- element: HTMLElement | undefined;
7
- render: (params: ElementDynamicParams, isHidden: boolean) => void;
8
- hide: () => void;
9
- };
10
- export type ElementFactory<ElementStaticParams extends RequiredStaticParams, ElementDynamicParams extends RequiredDynamicParams> = (staticParams: ElementStaticParams) => EditorElement<ElementDynamicParams>;
@@ -0,0 +1,11 @@
1
+ type StringKeyOf<T> = Extract<keyof T, string>;
2
+ type CallbackType<T extends Record<string, any>, EventName extends StringKeyOf<T>> = T[EventName] extends any[] ? T[EventName] : [T[EventName]];
3
+ type CallbackFunction<T extends Record<string, any>, EventName extends StringKeyOf<T>> = (...props: CallbackType<T, EventName>) => any;
4
+ export declare class EventEmitter<T extends Record<string, any>> {
5
+ private callbacks;
6
+ on<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): () => void;
7
+ protected emit<EventName extends StringKeyOf<T>>(event: EventName, ...args: CallbackType<T, EventName>): void;
8
+ off<EventName extends StringKeyOf<T>>(event: EventName, fn?: CallbackFunction<T, EventName>): void;
9
+ protected removeAllListeners(): void;
10
+ }
11
+ export {};
@@ -1,8 +1,3 @@
1
- /**
2
- * A generic interface used in all suggestion menus (slash menu, mentions, etc)
3
- */
4
- export declare class SuggestionItem {
1
+ export type SuggestionItem = {
5
2
  name: string;
6
- match: (query: string) => boolean;
7
- constructor(name: string, match: (query: string) => boolean);
8
- }
3
+ };
@@ -1,44 +1,10 @@
1
- import { Editor, Range } from "@tiptap/core";
2
1
  import { Plugin, PluginKey } from "prosemirror-state";
3
- import { SuggestionsMenuFactory } from "./SuggestionsMenuFactoryTypes";
4
- import { SuggestionItem } from "./SuggestionItem";
5
2
  import { BlockNoteEditor } from "../../../BlockNoteEditor";
6
- import { BlockSchema } from "../../../extensions/Blocks/api/blockTypes";
7
- export type SuggestionPluginOptions<T extends SuggestionItem, BSchema extends BlockSchema> = {
8
- /**
9
- * The name of the plugin.
10
- *
11
- * Used for ensuring that the plugin key is unique when more than one instance of the SuggestionPlugin is used.
12
- */
13
- pluginKey: PluginKey;
14
- /**
15
- * The BlockNote editor.
16
- */
17
- editor: BlockNoteEditor<BSchema>;
18
- /**
19
- * The character that should trigger the suggestion menu to pop up (e.g. a '/' for commands), when typed by the user.
20
- */
21
- defaultTriggerCharacter: string;
22
- suggestionsMenuFactory: SuggestionsMenuFactory<T>;
23
- /**
24
- * The callback that gets executed when an item is selected by the user.
25
- *
26
- * **NOTE:** The command text is not removed automatically from the editor by this plugin,
27
- * this should be done manually. The `editor` and `range` properties passed
28
- * to the callback function might come in handy when doing this.
29
- */
30
- onSelectItem?: (props: {
31
- item: T;
32
- editor: BlockNoteEditor<BSchema>;
33
- }) => void;
34
- /**
35
- * A function that should supply the plugin with items to suggest, based on a certain query string.
36
- */
37
- items?: (query: string) => T[];
38
- allow?: (props: {
39
- editor: Editor;
40
- range: Range;
41
- }) => boolean;
3
+ import { BaseUiElementState } from "../../BaseUiElementTypes";
4
+ import { SuggestionItem } from "./SuggestionItem";
5
+ export type SuggestionsMenuState<T extends SuggestionItem> = BaseUiElementState & {
6
+ filteredItems: T[];
7
+ keyboardHoveredItemIndex: number;
42
8
  };
43
9
  type SuggestionPluginState<T extends SuggestionItem> = {
44
10
  active: boolean;
@@ -58,9 +24,12 @@ type SuggestionPluginState<T extends SuggestionItem> = {
58
24
  * - This version supports generic items instead of only strings (to allow for more advanced filtering for example)
59
25
  * - This version hides some unnecessary complexity from the user of the plugin.
60
26
  * - This version handles key events differently
61
- *
62
- * @param options options for configuring the plugin
63
- * @returns the prosemirror plugin
64
27
  */
65
- export declare function createSuggestionPlugin<T extends SuggestionItem, BSchema extends BlockSchema>({ pluginKey, editor, defaultTriggerCharacter, suggestionsMenuFactory, onSelectItem: selectItemCallback, items, }: SuggestionPluginOptions<T, BSchema>): Plugin<SuggestionPluginState<T>>;
28
+ export declare const setupSuggestionsMenu: <T extends SuggestionItem, BSchema extends Record<string, import("../../../extensions/Blocks/api/blockTypes").BlockSpec<string, import("../../../extensions/Blocks/api/blockTypes").PropSchema>>>(editor: BlockNoteEditor<BSchema>, updateSuggestionsMenu: (suggestionsMenuState: SuggestionsMenuState<T>) => void, pluginKey: PluginKey, defaultTriggerCharacter: string, items?: (query: string) => T[], onSelectItem?: (props: {
29
+ item: T;
30
+ editor: BlockNoteEditor<BSchema>;
31
+ }) => void) => {
32
+ plugin: Plugin<SuggestionPluginState<T>>;
33
+ itemCallback: (item: T) => void;
34
+ };
66
35
  export {};
@@ -1,29 +0,0 @@
1
- import { EditorElement, ElementFactory } from "../../shared/EditorElement";
2
- import { BlockNoteEditor } from "../../BlockNoteEditor";
3
- import { Block, BlockSchema } from "../Blocks/api/blockTypes";
4
-
5
- export type BlockSideMenuStaticParams<BSchema extends BlockSchema> = {
6
- editor: BlockNoteEditor<BSchema>;
7
-
8
- addBlock: () => void;
9
-
10
- blockDragStart: (event: DragEvent) => void;
11
- blockDragEnd: () => void;
12
-
13
- freezeMenu: () => void;
14
- unfreezeMenu: () => void;
15
-
16
- getReferenceRect: () => DOMRect;
17
- };
18
-
19
- export type BlockSideMenuDynamicParams<BSchema extends BlockSchema> = {
20
- block: Block<BSchema>;
21
- };
22
-
23
- export type BlockSideMenu<BSchema extends BlockSchema> = EditorElement<
24
- BlockSideMenuDynamicParams<BSchema>
25
- >;
26
- export type BlockSideMenuFactory<BSchema extends BlockSchema> = ElementFactory<
27
- BlockSideMenuStaticParams<BSchema>,
28
- BlockSideMenuDynamicParams<BSchema>
29
- >;
@@ -1,37 +0,0 @@
1
- import { Editor, Extension } from "@tiptap/core";
2
- import { BlockSideMenuFactory } from "./BlockSideMenuFactoryTypes";
3
- import { createDraggableBlocksPlugin } from "./DraggableBlocksPlugin";
4
- import { BlockNoteEditor } from "../../BlockNoteEditor";
5
- import { BlockSchema } from "../Blocks/api/blockTypes";
6
-
7
- export type DraggableBlocksOptions<BSchema extends BlockSchema> = {
8
- tiptapEditor: Editor;
9
- editor: BlockNoteEditor<BSchema>;
10
- blockSideMenuFactory: BlockSideMenuFactory<BSchema>;
11
- };
12
-
13
- /**
14
- * This extension adds a menu to the side of blocks which features various BlockNote functions such as adding and
15
- * removing blocks. More importantly, it adds a drag handle which allows the user to drag and drop blocks.
16
- *
17
- * code based on https://github.com/ueberdosis/tiptap/issues/323#issuecomment-506637799
18
- */
19
- export const createDraggableBlocksExtension = <BSchema extends BlockSchema>() =>
20
- Extension.create<DraggableBlocksOptions<BSchema>>({
21
- name: "DraggableBlocksExtension",
22
- priority: 1000, // Need to be high, in order to hide menu when typing slash
23
- addProseMirrorPlugins() {
24
- if (!this.options.blockSideMenuFactory) {
25
- throw new Error(
26
- "UI Element factory not defined for DraggableBlocksExtension"
27
- );
28
- }
29
- return [
30
- createDraggableBlocksPlugin({
31
- tiptapEditor: this.editor,
32
- editor: this.options.editor,
33
- blockSideMenuFactory: this.options.blockSideMenuFactory,
34
- }),
35
- ];
36
- },
37
- });