@blocknote/core 0.7.1-alpha.0 → 0.8.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 (71) hide show
  1. package/dist/blocknote.js +1428 -1252
  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 +3 -3
  7. package/src/BlockNoteEditor.ts +100 -53
  8. package/src/BlockNoteExtensions.ts +24 -14
  9. package/src/api/blockManipulation/blockManipulation.test.ts +6 -3
  10. package/src/api/blockManipulation/blockManipulation.ts +7 -6
  11. package/src/api/formatConversions/formatConversions.test.ts +13 -8
  12. package/src/api/formatConversions/formatConversions.ts +15 -12
  13. package/src/api/nodeConversions/nodeConversions.test.ts +29 -10
  14. package/src/api/nodeConversions/nodeConversions.ts +33 -12
  15. package/src/api/nodeConversions/testUtil.ts +8 -4
  16. package/src/editor.module.css +0 -1
  17. package/src/extensions/Blocks/api/block.ts +229 -0
  18. package/src/extensions/Blocks/api/blockTypes.ts +158 -71
  19. package/src/extensions/Blocks/api/cursorPositionTypes.ts +5 -5
  20. package/src/extensions/Blocks/api/defaultBlocks.ts +44 -0
  21. package/src/extensions/Blocks/api/selectionTypes.ts +3 -3
  22. package/src/extensions/Blocks/api/serialization.ts +29 -0
  23. package/src/extensions/Blocks/index.ts +0 -8
  24. package/src/extensions/Blocks/nodes/Block.module.css +24 -12
  25. package/src/extensions/Blocks/nodes/BlockContainer.ts +8 -4
  26. package/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.ts +4 -4
  27. package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +5 -5
  28. package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +100 -97
  29. package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +4 -4
  30. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +11 -9
  31. package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +6 -5
  32. package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +12 -11
  33. package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +21 -16
  34. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +9 -5
  35. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +30 -42
  36. package/src/extensions/Placeholder/PlaceholderExtension.ts +1 -0
  37. package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +5 -2
  38. package/src/extensions/SlashMenu/SlashMenuExtension.ts +37 -33
  39. package/src/extensions/SlashMenu/defaultSlashMenuItems.tsx +14 -10
  40. package/src/extensions/SlashMenu/index.ts +2 -2
  41. package/src/index.ts +4 -0
  42. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +29 -13
  43. package/types/src/BlockNoteEditor.d.ts +37 -23
  44. package/types/src/BlockNoteExtensions.d.ts +15 -8
  45. package/types/src/api/blockManipulation/blockManipulation.d.ts +4 -4
  46. package/types/src/api/formatConversions/formatConversions.d.ts +5 -5
  47. package/types/src/api/nodeConversions/nodeConversions.d.ts +3 -3
  48. package/types/src/api/nodeConversions/testUtil.d.ts +2 -2
  49. package/types/src/extensions/Blocks/api/block.d.ts +2 -4
  50. package/types/src/extensions/Blocks/api/blockTypes.d.ts +77 -33
  51. package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +5 -5
  52. package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +4 -4
  53. package/types/src/extensions/Blocks/api/selectionTypes.d.ts +3 -3
  54. package/types/src/extensions/Blocks/api/serialization.d.ts +2 -0
  55. package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +3 -3
  56. package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +1 -2
  57. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +1 -2
  58. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +1 -2
  59. package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +1 -2
  60. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +7 -7
  61. package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +5 -4
  62. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +11 -10
  63. package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +6 -5
  64. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +4 -3
  65. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +16 -19
  66. package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +4 -3
  67. package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +5 -4
  68. package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +66 -1
  69. package/types/src/extensions/SlashMenu/index.d.ts +2 -2
  70. package/types/src/index.d.ts +4 -0
  71. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +5 -4
@@ -1,37 +1,81 @@
1
1
  /** Define the main block types **/
2
+ import { Node, NodeConfig } from "@tiptap/core";
3
+ import { BlockNoteEditor } from "../../../BlockNoteEditor";
2
4
  import { InlineContent, PartialInlineContent } from "./inlineContentTypes";
3
- export type BlockTemplate<Type extends string, Props extends Record<string, string>> = {
4
- id: string;
5
+ export type TipTapNodeConfig<Name extends string, Options = any, Storage = any> = {
6
+ [K in keyof NodeConfig<Options, Storage>]: K extends "name" ? Name : K extends "group" ? never : NodeConfig<Options, Storage>[K];
7
+ };
8
+ export type TipTapNode<Name extends string, Options = any, Storage = any> = Node<Options, Storage> & {
9
+ name: Name;
10
+ group: "blockContent";
11
+ };
12
+ export type PropSpec = {
13
+ values?: readonly string[];
14
+ default: string;
15
+ };
16
+ export type PropSchema = Record<string, PropSpec>;
17
+ export type Props<PSchema extends PropSchema> = {
18
+ [PType in keyof PSchema]: PSchema[PType]["values"] extends readonly string[] ? PSchema[PType]["values"][number] : string;
19
+ };
20
+ export type BlockConfig<Type extends string, PSchema extends PropSchema, ContainsInlineContent extends boolean, BSchema extends BlockSchema> = {
5
21
  type: Type;
6
- props: Props;
7
- content: InlineContent[];
8
- children: Block[];
9
- };
10
- export type DefaultBlockProps = {
11
- backgroundColor: string;
12
- textColor: string;
13
- textAlignment: "left" | "center" | "right" | "justify";
14
- };
15
- export type NumberedListItemBlock = BlockTemplate<"numberedListItem", DefaultBlockProps>;
16
- export type BulletListItemBlock = BlockTemplate<"bulletListItem", DefaultBlockProps>;
17
- export type HeadingBlock = BlockTemplate<"heading", DefaultBlockProps & {
18
- level: "1" | "2" | "3";
22
+ readonly propSchema: PSchema;
23
+ containsInlineContent: ContainsInlineContent;
24
+ render: (
25
+ /**
26
+ * The custom block to render
27
+ */
28
+ block: SpecificBlock<BSchema & {
29
+ [k in Type]: BlockSpec<Type, PSchema>;
30
+ }, Type>,
31
+ /**
32
+ * The BlockNote editor instance
33
+ * This is typed generically. If you want an editor with your custom schema, you need to
34
+ * cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
35
+ */
36
+ editor: BlockNoteEditor<BSchema & {
37
+ [k in Type]: BlockSpec<Type, PSchema>;
38
+ }>) => ContainsInlineContent extends true ? {
39
+ dom: HTMLElement;
40
+ contentDOM: HTMLElement;
41
+ } : {
42
+ dom: HTMLElement;
43
+ };
44
+ };
45
+ export type BlockSpec<Type extends string, PSchema extends PropSchema> = {
46
+ readonly propSchema: PSchema;
47
+ node: TipTapNode<Type>;
48
+ };
49
+ export type TypesMatch<Blocks extends Record<string, BlockSpec<string, PropSchema>>> = Blocks extends {
50
+ [Type in keyof Blocks]: Type extends string ? Blocks[Type] extends BlockSpec<Type, PropSchema> ? Blocks[Type] : never : never;
51
+ } ? Blocks : never;
52
+ export type BlockSchema = TypesMatch<Record<string, BlockSpec<string, PropSchema>>>;
53
+ type BlocksWithoutChildren<BSchema extends BlockSchema> = {
54
+ [BType in keyof BSchema]: {
55
+ id: string;
56
+ type: BType;
57
+ props: Props<BSchema[BType]["propSchema"]>;
58
+ content: InlineContent[];
59
+ };
60
+ };
61
+ export type Block<BSchema extends BlockSchema> = BlocksWithoutChildren<BSchema>[keyof BlocksWithoutChildren<BSchema>] & {
62
+ children: Block<BSchema>[];
63
+ };
64
+ export type SpecificBlock<BSchema extends BlockSchema, BlockType extends keyof BSchema> = BlocksWithoutChildren<BSchema>[BlockType] & {
65
+ children: Block<BSchema>[];
66
+ };
67
+ type PartialBlocksWithoutChildren<BSchema extends BlockSchema> = {
68
+ [BType in keyof BSchema]: Partial<{
69
+ id: string;
70
+ type: BType;
71
+ props: Partial<Props<BSchema[BType]["propSchema"]>>;
72
+ content: PartialInlineContent[] | string;
73
+ }>;
74
+ };
75
+ export type PartialBlock<BSchema extends BlockSchema> = PartialBlocksWithoutChildren<BSchema>[keyof PartialBlocksWithoutChildren<BSchema>] & Partial<{
76
+ children: PartialBlock<BSchema>[];
19
77
  }>;
20
- export type ParagraphBlock = BlockTemplate<"paragraph", DefaultBlockProps>;
21
- export type Block = ParagraphBlock | HeadingBlock | BulletListItemBlock | NumberedListItemBlock;
22
- export type BlockIdentifier = string | Block;
23
- /** Define "Partial Blocks", these are for updating or creating blocks */
24
- export type PartialBlockTemplate<B extends Block> = B extends Block ? Partial<Omit<B, "props" | "children" | "content" | "type">> & {
25
- type?: B["type"];
26
- props?: Partial<B["props"]>;
27
- content?: string | PartialInlineContent[];
28
- children?: PartialBlock[];
29
- } : never;
30
- export type PartialBlock = PartialBlockTemplate<Block>;
31
- export type BlockPropsTemplate<Props> = Props extends Block["props"] ? keyof Props : never;
32
- /**
33
- * Expose blockProps. This is currently not very nice, but it's expected this
34
- * will change anyway once we allow for custom blocks
35
- */
36
- export declare const globalProps: Array<keyof DefaultBlockProps>;
37
- export declare const blockProps: Record<Block["type"], Set<string>>;
78
+ export type BlockIdentifier = {
79
+ id: string;
80
+ } | string;
81
+ export {};
@@ -1,6 +1,6 @@
1
- import { Block } from "./blockTypes";
2
- export type TextCursorPosition = {
3
- block: Block;
4
- prevBlock: Block | undefined;
5
- nextBlock: Block | undefined;
1
+ import { Block, BlockSchema } from "./blockTypes";
2
+ export type TextCursorPosition<BSchema extends BlockSchema> = {
3
+ block: Block<BSchema>;
4
+ prevBlock: Block<BSchema> | undefined;
5
+ nextBlock: Block<BSchema> | undefined;
6
6
  };
@@ -26,7 +26,7 @@ export declare const defaultBlockSchema: {
26
26
  values: readonly ["left", "center", "right", "justify"];
27
27
  };
28
28
  };
29
- readonly node: import("./blockTypes").TipTapNode<"paragraph", any, any>;
29
+ readonly node: import("./blockTypes").TipTapNode<"paragraph">;
30
30
  };
31
31
  readonly heading: {
32
32
  readonly propSchema: {
@@ -45,7 +45,7 @@ export declare const defaultBlockSchema: {
45
45
  values: readonly ["left", "center", "right", "justify"];
46
46
  };
47
47
  };
48
- readonly node: import("./blockTypes").TipTapNode<"heading", any, any>;
48
+ readonly node: import("./blockTypes").TipTapNode<"heading">;
49
49
  };
50
50
  readonly bulletListItem: {
51
51
  readonly propSchema: {
@@ -60,7 +60,7 @@ export declare const defaultBlockSchema: {
60
60
  values: readonly ["left", "center", "right", "justify"];
61
61
  };
62
62
  };
63
- readonly node: import("./blockTypes").TipTapNode<"bulletListItem", any, any>;
63
+ readonly node: import("./blockTypes").TipTapNode<"bulletListItem">;
64
64
  };
65
65
  readonly numberedListItem: {
66
66
  readonly propSchema: {
@@ -75,7 +75,7 @@ export declare const defaultBlockSchema: {
75
75
  values: readonly ["left", "center", "right", "justify"];
76
76
  };
77
77
  };
78
- readonly node: import("./blockTypes").TipTapNode<"numberedListItem", any, any>;
78
+ readonly node: import("./blockTypes").TipTapNode<"numberedListItem">;
79
79
  };
80
80
  };
81
81
  export type DefaultBlockSchema = TypesMatch<typeof defaultBlockSchema>;
@@ -1,4 +1,4 @@
1
- import { Block } from "./blockTypes";
2
- export type Selection = {
3
- blocks: Block[];
1
+ import { Block, BlockSchema } from "./blockTypes";
2
+ export type Selection<BSchema extends BlockSchema> = {
3
+ blocks: Block<BSchema>[];
4
4
  };
@@ -0,0 +1,2 @@
1
+ import { Extension } from "@tiptap/core";
2
+ export declare const CustomBlockSerializerExtension: Extension<any, any>;
@@ -1,5 +1,5 @@
1
1
  import { Node } from "@tiptap/core";
2
- import { PartialBlock } from "../api/blockTypes";
2
+ import { BlockSchema, PartialBlock } from "../api/blockTypes";
3
3
  export interface IBlock {
4
4
  HTMLAttributes: Record<string, any>;
5
5
  }
@@ -10,8 +10,8 @@ declare module "@tiptap/core" {
10
10
  BNDeleteBlock: (posInBlock: number) => ReturnType;
11
11
  BNMergeBlocks: (posBetweenBlocks: number) => ReturnType;
12
12
  BNSplitBlock: (posInBlock: number, keepType: boolean) => ReturnType;
13
- BNUpdateBlock: (posInBlock: number, block: PartialBlock) => ReturnType;
14
- BNCreateOrUpdateBlock: (posInBlock: number, block: PartialBlock) => ReturnType;
13
+ BNUpdateBlock: <BSchema extends BlockSchema>(posInBlock: number, block: PartialBlock<BSchema>) => ReturnType;
14
+ BNCreateOrUpdateBlock: <BSchema extends BlockSchema>(posInBlock: number, block: PartialBlock<BSchema>) => ReturnType;
15
15
  };
16
16
  }
17
17
  }
@@ -1,2 +1 @@
1
- import { Node } from "@tiptap/core";
2
- export declare const HeadingBlockContent: Node<any, any>;
1
+ export declare const HeadingBlockContent: import("../../../api/blockTypes").TipTapNode<"heading">;
@@ -1,2 +1 @@
1
- import { Node } from "@tiptap/core";
2
- export declare const BulletListItemBlockContent: Node<any, any>;
1
+ export declare const BulletListItemBlockContent: import("../../../../api/blockTypes").TipTapNode<"bulletListItem">;
@@ -1,2 +1 @@
1
- import { Node } from "@tiptap/core";
2
- export declare const NumberedListItemBlockContent: Node<any, any>;
1
+ export declare const NumberedListItemBlockContent: import("../../../../api/blockTypes").TipTapNode<"numberedListItem">;
@@ -1,2 +1 @@
1
- import { Node } from "@tiptap/core";
2
- export declare const ParagraphBlockContent: Node<any, any>;
1
+ export declare const ParagraphBlockContent: import("../../../api/blockTypes").TipTapNode<"paragraph">;
@@ -1,17 +1,17 @@
1
1
  import { EditorElement, ElementFactory } from "../../shared/EditorElement";
2
2
  import { BlockNoteEditor } from "../../BlockNoteEditor";
3
- import { Block } from "../Blocks/api/blockTypes";
4
- export type BlockSideMenuStaticParams = {
5
- editor: BlockNoteEditor;
3
+ import { Block, BlockSchema } from "../Blocks/api/blockTypes";
4
+ export type BlockSideMenuStaticParams<BSchema extends BlockSchema> = {
5
+ editor: BlockNoteEditor<BSchema>;
6
6
  addBlock: () => void;
7
7
  blockDragStart: (event: DragEvent) => void;
8
8
  blockDragEnd: () => void;
9
9
  freezeMenu: () => void;
10
10
  unfreezeMenu: () => void;
11
11
  };
12
- export type BlockSideMenuDynamicParams = {
13
- block: Block;
12
+ export type BlockSideMenuDynamicParams<BSchema extends BlockSchema> = {
13
+ block: Block<BSchema>;
14
14
  referenceRect: DOMRect;
15
15
  };
16
- export type BlockSideMenu = EditorElement<BlockSideMenuDynamicParams>;
17
- export type BlockSideMenuFactory = ElementFactory<BlockSideMenuStaticParams, BlockSideMenuDynamicParams>;
16
+ export type BlockSideMenu<BSchema extends BlockSchema> = EditorElement<BlockSideMenuDynamicParams<BSchema>>;
17
+ export type BlockSideMenuFactory<BSchema extends BlockSchema> = ElementFactory<BlockSideMenuStaticParams<BSchema>, BlockSideMenuDynamicParams<BSchema>>;
@@ -1,10 +1,11 @@
1
1
  import { Editor, Extension } from "@tiptap/core";
2
2
  import { BlockSideMenuFactory } from "./BlockSideMenuFactoryTypes";
3
3
  import { BlockNoteEditor } from "../../BlockNoteEditor";
4
- export type DraggableBlocksOptions = {
4
+ import { BlockSchema } from "../Blocks/api/blockTypes";
5
+ export type DraggableBlocksOptions<BSchema extends BlockSchema> = {
5
6
  tiptapEditor: Editor;
6
- editor: BlockNoteEditor;
7
- blockSideMenuFactory: BlockSideMenuFactory;
7
+ editor: BlockNoteEditor<BSchema>;
8
+ blockSideMenuFactory: BlockSideMenuFactory<BSchema>;
8
9
  };
9
10
  /**
10
11
  * This extension adds a menu to the side of blocks which features various BlockNote functions such as adding and
@@ -12,4 +13,4 @@ export type DraggableBlocksOptions = {
12
13
  *
13
14
  * code based on https://github.com/ueberdosis/tiptap/issues/323#issuecomment-506637799
14
15
  */
15
- export declare const DraggableBlocksExtension: Extension<DraggableBlocksOptions, any>;
16
+ export declare const createDraggableBlocksExtension: <BSchema extends Record<string, import("../Blocks/api/blockTypes").BlockSpec<string, import("../Blocks/api/blockTypes").PropSchema>>>() => Extension<DraggableBlocksOptions<BSchema>, any>;
@@ -3,23 +3,24 @@ import { Plugin } from "prosemirror-state";
3
3
  import { BlockSideMenu, BlockSideMenuDynamicParams, BlockSideMenuFactory, BlockSideMenuStaticParams } from "./BlockSideMenuFactoryTypes";
4
4
  import { DraggableBlocksOptions } from "./DraggableBlocksExtension";
5
5
  import { BlockNoteEditor } from "../../BlockNoteEditor";
6
- export type BlockMenuViewProps = {
6
+ import { BlockSchema } from "../Blocks/api/blockTypes";
7
+ export type BlockMenuViewProps<BSchema extends BlockSchema> = {
7
8
  tiptapEditor: Editor;
8
- editor: BlockNoteEditor;
9
- blockMenuFactory: BlockSideMenuFactory;
9
+ editor: BlockNoteEditor<BSchema>;
10
+ blockMenuFactory: BlockSideMenuFactory<BSchema>;
10
11
  horizontalPosAnchoredAtRoot: boolean;
11
12
  };
12
- export declare class BlockMenuView {
13
- editor: BlockNoteEditor;
13
+ export declare class BlockMenuView<BSchema extends BlockSchema> {
14
+ editor: BlockNoteEditor<BSchema>;
14
15
  private ttEditor;
15
16
  horizontalPosAnchoredAtRoot: boolean;
16
17
  horizontalPosAnchor: number;
17
- blockMenu: BlockSideMenu;
18
+ blockMenu: BlockSideMenu<BSchema>;
18
19
  hoveredBlock: HTMLElement | undefined;
19
20
  isDragging: boolean;
20
21
  menuOpen: boolean;
21
22
  menuFrozen: boolean;
22
- constructor({ tiptapEditor, editor, blockMenuFactory, horizontalPosAnchoredAtRoot, }: BlockMenuViewProps);
23
+ constructor({ tiptapEditor, editor, blockMenuFactory, horizontalPosAnchoredAtRoot, }: BlockMenuViewProps<BSchema>);
23
24
  /**
24
25
  * Sets isDragging when dragging text.
25
26
  */
@@ -42,7 +43,7 @@ export declare class BlockMenuView {
42
43
  onScroll: () => void;
43
44
  destroy(): void;
44
45
  addBlock(): void;
45
- getStaticParams(): BlockSideMenuStaticParams;
46
- getDynamicParams(): BlockSideMenuDynamicParams;
46
+ getStaticParams(): BlockSideMenuStaticParams<BSchema>;
47
+ getDynamicParams(): BlockSideMenuDynamicParams<BSchema>;
47
48
  }
48
- export declare const createDraggableBlocksPlugin: (options: DraggableBlocksOptions) => Plugin<any>;
49
+ export declare const createDraggableBlocksPlugin: <BSchema extends Record<string, import("../Blocks/api/blockTypes").BlockSpec<string, import("../Blocks/api/blockTypes").PropSchema>>>(options: DraggableBlocksOptions<BSchema>) => Plugin<any>;
@@ -1,10 +1,11 @@
1
1
  import { Extension } from "@tiptap/core";
2
- import { BlockNoteEditor } from "../..";
2
+ import { BlockNoteEditor, BlockSchema } from "../..";
3
3
  import { FormattingToolbarFactory } from "./FormattingToolbarFactoryTypes";
4
+ export type FormattingToolbarOptions<BSchema extends BlockSchema> = {
5
+ formattingToolbarFactory: FormattingToolbarFactory<BSchema>;
6
+ editor: BlockNoteEditor<BSchema>;
7
+ };
4
8
  /**
5
9
  * The menu that is displayed when selecting a piece of text.
6
10
  */
7
- export declare const FormattingToolbarExtension: Extension<{
8
- formattingToolbarFactory: FormattingToolbarFactory;
9
- editor: BlockNoteEditor;
10
- }, any>;
11
+ export declare const createFormattingToolbarExtension: <BSchema extends Record<string, import("../..").BlockSpec<string, import("../..").PropSchema>>>() => Extension<FormattingToolbarOptions<BSchema>, any>;
@@ -1,10 +1,11 @@
1
1
  import { EditorElement, ElementFactory } from "../../shared/EditorElement";
2
2
  import { BlockNoteEditor } from "../../BlockNoteEditor";
3
- export type FormattingToolbarStaticParams = {
4
- editor: BlockNoteEditor;
3
+ import { BlockSchema } from "../Blocks/api/blockTypes";
4
+ export type FormattingToolbarStaticParams<BSchema extends BlockSchema> = {
5
+ editor: BlockNoteEditor<BSchema>;
5
6
  };
6
7
  export type FormattingToolbarDynamicParams = {
7
8
  referenceRect: DOMRect;
8
9
  };
9
10
  export type FormattingToolbar = EditorElement<FormattingToolbarDynamicParams>;
10
- export type FormattingToolbarFactory = ElementFactory<FormattingToolbarStaticParams, FormattingToolbarDynamicParams>;
11
+ export type FormattingToolbarFactory<BSchema extends BlockSchema> = ElementFactory<FormattingToolbarStaticParams<BSchema>, FormattingToolbarDynamicParams>;
@@ -1,27 +1,19 @@
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
+ import { BlockNoteEditor, BlockSchema } from "../..";
5
5
  import { FormattingToolbar, FormattingToolbarDynamicParams, FormattingToolbarFactory, FormattingToolbarStaticParams } from "./FormattingToolbarFactoryTypes";
6
- export interface FormattingToolbarPluginProps {
6
+ export interface FormattingToolbarPluginProps<BSchema extends BlockSchema> {
7
7
  pluginKey: PluginKey;
8
8
  tiptapEditor: Editor;
9
- editor: BlockNoteEditor;
10
- formattingToolbarFactory: FormattingToolbarFactory;
11
- shouldShow?: ((props: {
12
- editor: BlockNoteEditor;
13
- view: EditorView;
14
- state: EditorState;
15
- oldState?: EditorState;
16
- from: number;
17
- to: number;
18
- }) => boolean) | null;
9
+ editor: BlockNoteEditor<BSchema>;
10
+ formattingToolbarFactory: FormattingToolbarFactory<BSchema>;
19
11
  }
20
- export type FormattingToolbarViewProps = FormattingToolbarPluginProps & {
12
+ export type FormattingToolbarViewProps<BSchema extends BlockSchema> = FormattingToolbarPluginProps<BSchema> & {
21
13
  view: EditorView;
22
14
  };
23
- export declare class FormattingToolbarView {
24
- editor: BlockNoteEditor;
15
+ export declare class FormattingToolbarView<BSchema extends BlockSchema> {
16
+ editor: BlockNoteEditor<BSchema>;
25
17
  private ttEditor;
26
18
  view: EditorView;
27
19
  formattingToolbar: FormattingToolbar;
@@ -29,8 +21,13 @@ export declare class FormattingToolbarView {
29
21
  preventShow: boolean;
30
22
  toolbarIsOpen: boolean;
31
23
  prevWasEditable: boolean | null;
32
- shouldShow: Exclude<FormattingToolbarPluginProps["shouldShow"], null>;
33
- constructor({ editor, tiptapEditor, formattingToolbarFactory, view, shouldShow, }: FormattingToolbarViewProps);
24
+ shouldShow: (props: {
25
+ view: EditorView;
26
+ state: EditorState;
27
+ from: number;
28
+ to: number;
29
+ }) => boolean;
30
+ constructor({ editor, tiptapEditor, formattingToolbarFactory, view, }: FormattingToolbarViewProps<BSchema>);
34
31
  viewMousedownHandler: () => void;
35
32
  viewMouseupHandler: () => void;
36
33
  dragstartHandler: () => void;
@@ -42,7 +39,7 @@ export declare class FormattingToolbarView {
42
39
  update(view: EditorView, oldState?: EditorState): void;
43
40
  destroy(): void;
44
41
  getSelectionBoundingBox(): DOMRect;
45
- getStaticParams(): FormattingToolbarStaticParams;
42
+ getStaticParams(): FormattingToolbarStaticParams<BSchema>;
46
43
  getDynamicParams(): FormattingToolbarDynamicParams;
47
44
  }
48
- export declare const createFormattingToolbarPlugin: (options: FormattingToolbarPluginProps) => Plugin<any>;
45
+ export declare const createFormattingToolbarPlugin: <BSchema extends Record<string, import("../..").BlockSpec<string, import("../..").PropSchema>>>(options: FormattingToolbarPluginProps<BSchema>) => Plugin<any>;
@@ -1,13 +1,14 @@
1
1
  import { SuggestionItem } from "../../shared/plugins/suggestion/SuggestionItem";
2
2
  import { BlockNoteEditor } from "../../BlockNoteEditor";
3
+ import { BlockSchema } from "../Blocks/api/blockTypes";
3
4
  /**
4
5
  * A class that defines a slash command (/<command>).
5
6
  *
6
7
  * (Not to be confused with ProseMirror commands nor TipTap commands.)
7
8
  */
8
- export declare class BaseSlashMenuItem extends SuggestionItem {
9
+ export declare class BaseSlashMenuItem<BSchema extends BlockSchema> extends SuggestionItem {
9
10
  readonly name: string;
10
- readonly execute: (editor: BlockNoteEditor) => void;
11
+ readonly execute: (editor: BlockNoteEditor<BSchema>) => void;
11
12
  readonly aliases: string[];
12
13
  /**
13
14
  * Constructs a new slash-command.
@@ -16,5 +17,5 @@ export declare class BaseSlashMenuItem extends SuggestionItem {
16
17
  * @param execute The callback for creating a new node
17
18
  * @param aliases Aliases for this command
18
19
  */
19
- constructor(name: string, execute: (editor: BlockNoteEditor) => void, aliases?: string[]);
20
+ constructor(name: string, execute: (editor: BlockNoteEditor<BSchema>) => void, aliases?: string[]);
20
21
  }
@@ -3,10 +3,11 @@ import { PluginKey } from "prosemirror-state";
3
3
  import { SuggestionsMenuFactory } from "../../shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
4
4
  import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
5
5
  import { BlockNoteEditor } from "../../BlockNoteEditor";
6
- export type SlashMenuOptions = {
7
- editor: BlockNoteEditor | undefined;
8
- commands: BaseSlashMenuItem[] | undefined;
6
+ import { BlockSchema } from "../Blocks/api/blockTypes";
7
+ export type SlashMenuOptions<BSchema extends BlockSchema> = {
8
+ editor: BlockNoteEditor<BSchema> | undefined;
9
+ commands: BaseSlashMenuItem<BSchema>[] | undefined;
9
10
  slashMenuFactory: SuggestionsMenuFactory<any> | undefined;
10
11
  };
11
12
  export declare const SlashMenuPluginKey: PluginKey<any>;
12
- export declare const SlashMenuExtension: Extension<SlashMenuOptions, any>;
13
+ export declare const createSlashMenuExtension: <BSchema extends Record<string, import("../Blocks/api/blockTypes").BlockSpec<string, import("../Blocks/api/blockTypes").PropSchema>>>() => Extension<SlashMenuOptions<BSchema>, any>;
@@ -2,4 +2,69 @@ import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
2
2
  /**
3
3
  * An array containing commands for creating all default blocks.
4
4
  */
5
- export declare const defaultSlashMenuItems: BaseSlashMenuItem[];
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
+ }>[];
@@ -1,4 +1,4 @@
1
1
  import { defaultSlashMenuItems } from "./defaultSlashMenuItems";
2
- import { SlashMenuExtension } from "./SlashMenuExtension";
2
+ import { createSlashMenuExtension } from "./SlashMenuExtension";
3
3
  import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
4
- export { defaultSlashMenuItems, BaseSlashMenuItem, SlashMenuExtension };
4
+ export { defaultSlashMenuItems, BaseSlashMenuItem, createSlashMenuExtension };
@@ -1,6 +1,8 @@
1
1
  export * from "./BlockNoteEditor";
2
2
  export * from "./BlockNoteExtensions";
3
+ export * from "./extensions/Blocks/api/block";
3
4
  export * from "./extensions/Blocks/api/blockTypes";
5
+ export * from "./extensions/Blocks/api/defaultBlocks";
4
6
  export * from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
5
7
  export * from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
6
8
  export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
@@ -10,3 +12,5 @@ export * from "./shared/EditorElement";
10
12
  export type { SuggestionItem } from "./shared/plugins/suggestion/SuggestionItem";
11
13
  export * from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
12
14
  export * from "./extensions/Blocks/api/inlineContentTypes";
15
+ export * from "./extensions/Blocks/api/serialization";
16
+ export * as blockStyles from "./extensions/Blocks/nodes/Block.module.css";
@@ -3,7 +3,8 @@ import { Plugin, PluginKey } from "prosemirror-state";
3
3
  import { SuggestionsMenuFactory } from "./SuggestionsMenuFactoryTypes";
4
4
  import { SuggestionItem } from "./SuggestionItem";
5
5
  import { BlockNoteEditor } from "../../../BlockNoteEditor";
6
- export type SuggestionPluginOptions<T extends SuggestionItem> = {
6
+ import { BlockSchema } from "../../../extensions/Blocks/api/blockTypes";
7
+ export type SuggestionPluginOptions<T extends SuggestionItem, BSchema extends BlockSchema> = {
7
8
  /**
8
9
  * The name of the plugin.
9
10
  *
@@ -13,7 +14,7 @@ export type SuggestionPluginOptions<T extends SuggestionItem> = {
13
14
  /**
14
15
  * The BlockNote editor.
15
16
  */
16
- editor: BlockNoteEditor;
17
+ editor: BlockNoteEditor<BSchema>;
17
18
  /**
18
19
  * The character that should trigger the suggestion menu to pop up (e.g. a '/' for commands), when typed by the user.
19
20
  */
@@ -28,7 +29,7 @@ export type SuggestionPluginOptions<T extends SuggestionItem> = {
28
29
  */
29
30
  onSelectItem?: (props: {
30
31
  item: T;
31
- editor: BlockNoteEditor;
32
+ editor: BlockNoteEditor<BSchema>;
32
33
  }) => void;
33
34
  /**
34
35
  * A function that should supply the plugin with items to suggest, based on a certain query string.
@@ -61,5 +62,5 @@ type SuggestionPluginState<T extends SuggestionItem> = {
61
62
  * @param options options for configuring the plugin
62
63
  * @returns the prosemirror plugin
63
64
  */
64
- export declare function createSuggestionPlugin<T extends SuggestionItem>({ pluginKey, editor, defaultTriggerCharacter, suggestionsMenuFactory, onSelectItem: selectItemCallback, items, }: SuggestionPluginOptions<T>): Plugin<SuggestionPluginState<T>>;
65
+ export declare function createSuggestionPlugin<T extends SuggestionItem, BSchema extends BlockSchema>({ pluginKey, editor, defaultTriggerCharacter, suggestionsMenuFactory, onSelectItem: selectItemCallback, items, }: SuggestionPluginOptions<T, BSchema>): Plugin<SuggestionPluginState<T>>;
65
66
  export {};