@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.
- package/dist/blocknote.js +1428 -1252
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +2 -2
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +3 -3
- package/src/BlockNoteEditor.ts +100 -53
- package/src/BlockNoteExtensions.ts +24 -14
- package/src/api/blockManipulation/blockManipulation.test.ts +6 -3
- package/src/api/blockManipulation/blockManipulation.ts +7 -6
- package/src/api/formatConversions/formatConversions.test.ts +13 -8
- package/src/api/formatConversions/formatConversions.ts +15 -12
- package/src/api/nodeConversions/nodeConversions.test.ts +29 -10
- package/src/api/nodeConversions/nodeConversions.ts +33 -12
- package/src/api/nodeConversions/testUtil.ts +8 -4
- package/src/editor.module.css +0 -1
- package/src/extensions/Blocks/api/block.ts +229 -0
- package/src/extensions/Blocks/api/blockTypes.ts +158 -71
- package/src/extensions/Blocks/api/cursorPositionTypes.ts +5 -5
- package/src/extensions/Blocks/api/defaultBlocks.ts +44 -0
- package/src/extensions/Blocks/api/selectionTypes.ts +3 -3
- package/src/extensions/Blocks/api/serialization.ts +29 -0
- package/src/extensions/Blocks/index.ts +0 -8
- package/src/extensions/Blocks/nodes/Block.module.css +24 -12
- package/src/extensions/Blocks/nodes/BlockContainer.ts +8 -4
- package/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.ts +4 -4
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +5 -5
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +100 -97
- package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +4 -4
- package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +11 -9
- package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +6 -5
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +12 -11
- package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +21 -16
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +9 -5
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +30 -42
- package/src/extensions/Placeholder/PlaceholderExtension.ts +1 -0
- package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +5 -2
- package/src/extensions/SlashMenu/SlashMenuExtension.ts +37 -33
- package/src/extensions/SlashMenu/defaultSlashMenuItems.tsx +14 -10
- package/src/extensions/SlashMenu/index.ts +2 -2
- package/src/index.ts +4 -0
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +29 -13
- package/types/src/BlockNoteEditor.d.ts +37 -23
- package/types/src/BlockNoteExtensions.d.ts +15 -8
- package/types/src/api/blockManipulation/blockManipulation.d.ts +4 -4
- package/types/src/api/formatConversions/formatConversions.d.ts +5 -5
- package/types/src/api/nodeConversions/nodeConversions.d.ts +3 -3
- package/types/src/api/nodeConversions/testUtil.d.ts +2 -2
- package/types/src/extensions/Blocks/api/block.d.ts +2 -4
- package/types/src/extensions/Blocks/api/blockTypes.d.ts +77 -33
- package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +5 -5
- package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +4 -4
- package/types/src/extensions/Blocks/api/selectionTypes.d.ts +3 -3
- package/types/src/extensions/Blocks/api/serialization.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +3 -3
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +1 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +1 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +1 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +1 -2
- package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +7 -7
- package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +5 -4
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +11 -10
- package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +6 -5
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +4 -3
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +16 -19
- package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +4 -3
- package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +5 -4
- package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +66 -1
- package/types/src/extensions/SlashMenu/index.d.ts +2 -2
- package/types/src/index.d.ts +4 -0
- 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
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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"
|
|
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"
|
|
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"
|
|
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"
|
|
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
|
};
|
|
@@ -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
|
}
|
package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const HeadingBlockContent: Node<any, any>;
|
|
1
|
+
export declare const HeadingBlockContent: import("../../../api/blockTypes").TipTapNode<"heading">;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const BulletListItemBlockContent: Node<any, any>;
|
|
1
|
+
export declare const BulletListItemBlockContent: import("../../../../api/blockTypes").TipTapNode<"bulletListItem">;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const NumberedListItemBlockContent: Node<any, any>;
|
|
1
|
+
export declare const NumberedListItemBlockContent: import("../../../../api/blockTypes").TipTapNode<"numberedListItem">;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
4
|
-
|
|
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
|
|
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:
|
|
33
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
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 {
|
|
2
|
+
import { createSlashMenuExtension } from "./SlashMenuExtension";
|
|
3
3
|
import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
|
|
4
|
-
export { defaultSlashMenuItems, BaseSlashMenuItem,
|
|
4
|
+
export { defaultSlashMenuItems, BaseSlashMenuItem, createSlashMenuExtension };
|
package/types/src/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
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 {};
|