@blocknote/core 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/blocknote.js +1126 -1031
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +2 -2
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/style.css +1 -1
  6. package/package.json +2 -2
  7. package/src/BlockNoteEditor.ts +244 -3
  8. package/src/BlockNoteExtensions.ts +3 -2
  9. package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +35 -35
  10. package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +10 -10
  11. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +10 -10
  12. package/src/api/nodeConversions/nodeConversions.ts +11 -10
  13. package/src/editor.module.css +12 -3
  14. package/src/extensions/Blocks/api/inlineContentTypes.ts +3 -2
  15. package/src/extensions/Blocks/api/selectionTypes.ts +5 -0
  16. package/src/extensions/Blocks/nodes/Block.module.css +20 -2
  17. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +5 -6
  18. package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +5 -2
  19. package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +76 -113
  20. package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +6 -3
  21. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +2 -34
  22. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +39 -113
  23. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +56 -39
  24. package/src/extensions/UniqueID/UniqueID.ts +1 -1
  25. package/src/index.ts +1 -0
  26. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +14 -2
  27. package/types/src/BlockNoteEditor.d.ts +79 -0
  28. package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +3 -2
  29. package/types/src/extensions/Blocks/api/selectionTypes.d.ts +4 -0
  30. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +4 -5
  31. package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +3 -1
  32. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +14 -16
  33. package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +2 -0
  34. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +2 -25
  35. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +9 -4
  36. package/types/src/index.d.ts +1 -0
  37. package/types/src/api/Editor.d.ts +0 -93
  38. package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +0 -24
  39. package/types/src/extensions/SlashMenu/defaultSlashCommands.d.ts +0 -5
@@ -2,30 +2,30 @@ import { Editor } from "@tiptap/core";
2
2
  import { Plugin } from "prosemirror-state";
3
3
  import { BlockSideMenu, BlockSideMenuDynamicParams, BlockSideMenuFactory, BlockSideMenuStaticParams } from "./BlockSideMenuFactoryTypes";
4
4
  import { DraggableBlocksOptions } from "./DraggableBlocksExtension";
5
- export declare function createRect(rect: DOMRect): {
6
- left: number;
7
- top: number;
8
- width: number;
9
- height: number;
10
- bottom: number;
11
- right: number;
12
- };
5
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
13
6
  export type BlockMenuViewProps = {
14
- editor: Editor;
7
+ tiptapEditor: Editor;
8
+ editor: BlockNoteEditor;
15
9
  blockMenuFactory: BlockSideMenuFactory;
16
10
  horizontalPosAnchoredAtRoot: boolean;
17
11
  };
18
12
  export declare class BlockMenuView {
19
- editor: Editor;
13
+ editor: BlockNoteEditor;
14
+ private ttEditor;
20
15
  horizontalPosAnchoredAtRoot: boolean;
21
16
  horizontalPosAnchor: number;
22
17
  blockMenu: BlockSideMenu;
23
- hoveredBlockContent: HTMLElement | undefined;
18
+ hoveredBlock: HTMLElement | undefined;
19
+ isDragging: boolean;
24
20
  menuOpen: boolean;
25
21
  menuFrozen: boolean;
26
- constructor({ editor, blockMenuFactory, horizontalPosAnchoredAtRoot, }: BlockMenuViewProps);
22
+ constructor({ tiptapEditor, editor, blockMenuFactory, horizontalPosAnchoredAtRoot, }: BlockMenuViewProps);
27
23
  /**
28
- * If the event is outside of the editor contents,
24
+ * Sets isDragging when dragging text.
25
+ */
26
+ onDragStart: () => void;
27
+ /**
28
+ * If the event is outside the editor contents,
29
29
  * we dispatch a fake event, so that we can still drop the content
30
30
  * when dragging / dropping to the side of the editor
31
31
  */
@@ -39,11 +39,9 @@ export declare class BlockMenuView {
39
39
  onKeyDown: (_event: KeyboardEvent) => void;
40
40
  onMouseDown: (event: MouseEvent) => void;
41
41
  onMouseMove: (event: MouseEvent) => void;
42
+ onScroll: () => void;
42
43
  destroy(): void;
43
44
  addBlock(): void;
44
- deleteBlock(): void;
45
- setBlockBackgroundColor(color: string): void;
46
- setBlockTextColor(color: string): void;
47
45
  getStaticParams(): BlockSideMenuStaticParams;
48
46
  getDynamicParams(): BlockSideMenuDynamicParams;
49
47
  }
@@ -1,8 +1,10 @@
1
1
  import { Extension } from "@tiptap/core";
2
+ import { BlockNoteEditor } from "../..";
2
3
  import { FormattingToolbarFactory } from "./FormattingToolbarFactoryTypes";
3
4
  /**
4
5
  * The menu that is displayed when selecting a piece of text.
5
6
  */
6
7
  export declare const FormattingToolbarExtension: Extension<{
7
8
  formattingToolbarFactory: FormattingToolbarFactory;
9
+ editor: BlockNoteEditor;
8
10
  }, any>;
@@ -1,32 +1,9 @@
1
1
  import { EditorElement, ElementFactory } from "../../shared/EditorElement";
2
- import { Block, PartialBlock } from "../Blocks/api/blockTypes";
2
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
3
3
  export type FormattingToolbarStaticParams = {
4
- toggleBold: () => void;
5
- toggleItalic: () => void;
6
- toggleUnderline: () => void;
7
- toggleStrike: () => void;
8
- setHyperlink: (url: string, text?: string) => void;
9
- setTextColor: (color: string) => void;
10
- setBackgroundColor: (color: string) => void;
11
- setTextAlignment: (textAlignment: "left" | "center" | "right" | "justify") => void;
12
- increaseBlockIndent: () => void;
13
- decreaseBlockIndent: () => void;
14
- updateBlock: (updatedBlock: PartialBlock) => void;
4
+ editor: BlockNoteEditor;
15
5
  };
16
6
  export type FormattingToolbarDynamicParams = {
17
- boldIsActive: boolean;
18
- italicIsActive: boolean;
19
- underlineIsActive: boolean;
20
- strikeIsActive: boolean;
21
- hyperlinkIsActive: boolean;
22
- activeHyperlinkUrl: string;
23
- activeHyperlinkText: string;
24
- textColor: string;
25
- backgroundColor: string;
26
- textAlignment: "left" | "center" | "right" | "justify";
27
- canIncreaseBlockIndent: boolean;
28
- canDecreaseBlockIndent: boolean;
29
- block: Block;
30
7
  referenceRect: DOMRect;
31
8
  };
32
9
  export type FormattingToolbar = EditorElement<FormattingToolbarDynamicParams>;
@@ -1,13 +1,15 @@
1
1
  import { Editor } from "@tiptap/core";
2
2
  import { EditorState, Plugin, PluginKey } from "prosemirror-state";
3
3
  import { EditorView } from "prosemirror-view";
4
+ import { BlockNoteEditor } from "../..";
4
5
  import { FormattingToolbar, FormattingToolbarDynamicParams, FormattingToolbarFactory, FormattingToolbarStaticParams } from "./FormattingToolbarFactoryTypes";
5
6
  export interface FormattingToolbarPluginProps {
6
7
  pluginKey: PluginKey;
7
- editor: Editor;
8
+ tiptapEditor: Editor;
9
+ editor: BlockNoteEditor;
8
10
  formattingToolbarFactory: FormattingToolbarFactory;
9
11
  shouldShow?: ((props: {
10
- editor: Editor;
12
+ editor: BlockNoteEditor;
11
13
  view: EditorView;
12
14
  state: EditorState;
13
15
  oldState?: EditorState;
@@ -19,14 +21,16 @@ export type FormattingToolbarViewProps = FormattingToolbarPluginProps & {
19
21
  view: EditorView;
20
22
  };
21
23
  export declare class FormattingToolbarView {
22
- editor: Editor;
24
+ editor: BlockNoteEditor;
25
+ private ttEditor;
23
26
  view: EditorView;
24
27
  formattingToolbar: FormattingToolbar;
25
28
  preventHide: boolean;
26
29
  preventShow: boolean;
27
30
  toolbarIsOpen: boolean;
31
+ prevWasEditable: boolean | null;
28
32
  shouldShow: Exclude<FormattingToolbarPluginProps["shouldShow"], null>;
29
- constructor({ editor, formattingToolbarFactory, view, shouldShow, }: FormattingToolbarViewProps);
33
+ constructor({ editor, tiptapEditor, formattingToolbarFactory, view, shouldShow, }: FormattingToolbarViewProps);
30
34
  viewMousedownHandler: () => void;
31
35
  viewMouseupHandler: () => void;
32
36
  dragstartHandler: () => void;
@@ -34,6 +38,7 @@ export declare class FormattingToolbarView {
34
38
  blurHandler: ({ event }: {
35
39
  event: FocusEvent;
36
40
  }) => void;
41
+ scrollHandler: () => void;
37
42
  update(view: EditorView, oldState?: EditorState): void;
38
43
  destroy(): void;
39
44
  getSelectionBoundingBox(): DOMRect;
@@ -9,3 +9,4 @@ 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 "./extensions/Blocks/api/inlineContentTypes";
@@ -1,93 +0,0 @@
1
- import { Editor as TiptapEditor } from "@tiptap/core";
2
- import { Node } from "prosemirror-model";
3
- import { Block, BlockIdentifier, PartialBlock } from "../extensions/Blocks/api/blockTypes";
4
- import { TextCursorPosition } from "../extensions/Blocks/api/cursorPositionTypes";
5
- export declare class Editor {
6
- private tiptapEditor;
7
- private blockCache;
8
- constructor(tiptapEditor: TiptapEditor, blockCache?: WeakMap<Node, Block>);
9
- /**
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.
12
- */
13
- get topLevelBlocks(): Block[];
14
- /**
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.
31
- */
32
- get textCursorPosition(): TextCursorPosition;
33
- /**
34
- * Inserts multiple blocks before, after, or nested inside an existing block in the editor.
35
- * @param blocksToInsert An array of blocks to insert.
36
- * @param blockToInsertAt An existing block, marking where the new blocks should be inserted at.
37
- * @param placement Determines whether the blocks should be inserted just before, just after, or nested inside the
38
- * existing block.
39
- */
40
- insertBlocks(blocksToInsert: PartialBlock[], blockToInsertAt: Block, placement?: "before" | "after" | "nested"): void;
41
- /**
42
- * Updates a block in the editor to the given specification.
43
- * @param blockToUpdate The block that should be updated.
44
- * @param updatedBlock The specification that the block should be updated to.
45
- */
46
- updateBlock(blockToUpdate: Block, updatedBlock: PartialBlock): void;
47
- /**
48
- * Removes multiple blocks from the editor. Throws an error if any of the blocks could not be found.
49
- * @param blocksToRemove An array of blocks that should be removed.
50
- */
51
- removeBlocks(blocksToRemove: Block[]): void;
52
- /**
53
- * Replaces multiple blocks in the editor with several other blocks. If the provided blocks to remove are not adjacent
54
- * to each other, the new blocks are inserted at the position of the first block in the array. Throws an error if any
55
- * of the blocks could not be found.
56
- * @param blocksToRemove An array of blocks that should be replaced.
57
- * @param blocksToInsert An array of blocks to replace the old ones with.
58
- */
59
- replaceBlocks(blocksToRemove: Block[], blocksToInsert: PartialBlock[]): void;
60
- /**
61
- * Executes a callback function whenever the editor's contents change.
62
- * @param callback The callback function to execute.
63
- */
64
- onContentChange(callback: () => void): void;
65
- /**
66
- * Serializes a list of blocks into an HTML string. The output is not the same as what's rendered by the editor, and
67
- * is simplified in order to better conform to HTML standards. Block structuring elements are removed, children of
68
- * blocks which aren't list items are lifted out of them, and list items blocks are wrapped in `ul`/`ol` tags.
69
- * @param blocks The list of blocks to serialize into HTML.
70
- * @returns An HTML representation of the blocks.
71
- */
72
- blocksToHTML(blocks: Block[]): Promise<string>;
73
- /**
74
- * Creates a list of blocks from an HTML string.
75
- * @param htmlString The HTML string to create a list of blocks from.
76
- * @returns A list of blocks parsed from the HTML string.
77
- */
78
- HTMLToBlocks(htmlString: string): Promise<Block[]>;
79
- /**
80
- * Serializes a list of blocks into a Markdown string. The output is simplified as Markdown does not support all
81
- * features of BlockNote. Block structuring elements are removed, children of blocks which aren't list items are
82
- * un-nested, and certain styles are removed.
83
- * @param blocks The list of blocks to serialize into Markdown.
84
- * @returns A Markdown representation of the blocks.
85
- */
86
- blocksToMarkdown(blocks: Block[]): Promise<string>;
87
- /**
88
- * Creates a list of blocks from a Markdown string.
89
- * @param markdownString The Markdown string to create a list of blocks from.
90
- * @returns A list of blocks parsed from the Markdown string.
91
- */
92
- markdownToBlocks(markdownString: string): Promise<Block[]>;
93
- }
@@ -1,24 +0,0 @@
1
- import { Editor, Range } from "@tiptap/core";
2
- import { SuggestionItem } from "../../shared/plugins/suggestion/SuggestionItem";
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 SlashMenuItem implements SuggestionItem {
9
- readonly name: string;
10
- readonly execute: (editor: Editor, range: Range) => void;
11
- readonly aliases: string[];
12
- readonly group: string;
13
- readonly hint?: string | undefined;
14
- readonly shortcut?: string | undefined;
15
- /**
16
- * Constructs a new slash-command.
17
- *
18
- * @param name The name of the command
19
- * @param execute The callback for creating a new node
20
- * @param aliases Aliases for this command
21
- */
22
- constructor(name: string, execute: (editor: Editor, range: Range) => void, aliases: string[], group: string, hint?: string | undefined, shortcut?: string | undefined);
23
- match(query: string): boolean;
24
- }
@@ -1,5 +0,0 @@
1
- import { SlashMenuItem } from "./SlashMenuItem";
2
- /**
3
- * An array containing commands for creating all default blocks.
4
- */
5
- export declare const defaultSlashCommands: SlashMenuItem[];