@blocknote/core 0.3.0 → 0.4.2
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 +12698 -1341
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +50 -1
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +16 -5
- package/src/BlockNoteEditor.test.ts +12 -0
- package/src/BlockNoteEditor.ts +39 -15
- package/src/BlockNoteExtensions.ts +36 -32
- package/src/api/Editor.ts +226 -0
- package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +616 -0
- package/src/api/blockManipulation/blockManipulation.test.ts +172 -0
- package/src/api/blockManipulation/blockManipulation.ts +125 -0
- package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +346 -0
- package/src/api/formatConversions/formatConversions.test.ts +766 -0
- package/src/api/formatConversions/formatConversions.ts +86 -0
- package/src/api/formatConversions/removeUnderlinesRehypePlugin.ts +39 -0
- package/src/api/formatConversions/simplifyBlocksRehypePlugin.ts +125 -0
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +268 -0
- package/src/api/nodeConversions/nodeConversions.test.ts +244 -0
- package/src/api/nodeConversions/nodeConversions.ts +279 -0
- package/src/api/nodeConversions/testUtil.ts +61 -0
- package/src/api/util/nodeUtil.ts +38 -0
- package/src/editor.module.css +8 -1
- package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +7 -1
- package/src/extensions/Blocks/api/blockTypes.ts +90 -0
- package/src/extensions/Blocks/api/cursorPositionTypes.ts +5 -0
- package/src/extensions/Blocks/api/inlineContentTypes.ts +35 -0
- package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +4 -4
- package/src/extensions/Blocks/nodes/Block.module.css +39 -36
- package/src/extensions/Blocks/nodes/BlockContainer.ts +74 -23
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +23 -5
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +28 -6
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +149 -87
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +2 -2
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +3 -3
- package/src/extensions/SlashMenu/SlashMenuExtension.ts +7 -12
- package/src/extensions/SlashMenu/SlashMenuItem.ts +4 -1
- package/src/extensions/SlashMenu/{defaultCommands.tsx → defaultSlashCommands.tsx} +34 -17
- package/src/extensions/SlashMenu/index.ts +7 -4
- package/src/extensions/UniqueID/UniqueID.ts +1 -1
- package/src/index.ts +4 -2
- package/src/shared/utils.ts +6 -0
- package/types/src/BlockNoteEditor.d.ts +13 -4
- package/types/src/BlockNoteEditor.test.d.ts +1 -0
- package/types/src/BlockNoteExtensions.d.ts +7 -3
- package/types/src/api/Editor.d.ts +93 -0
- package/types/src/api/blockManipulation/blockManipulation.d.ts +6 -0
- package/types/src/api/blockManipulation/blockManipulation.test.d.ts +1 -0
- package/types/src/api/formatConversions/formatConversions.d.ts +6 -0
- package/types/src/api/formatConversions/formatConversions.test.d.ts +1 -0
- package/types/src/api/formatConversions/removeUnderlinesRehypePlugin.d.ts +6 -0
- package/types/src/api/formatConversions/simplifyBlocksRehypePlugin.d.ts +16 -0
- package/types/src/api/nodeConversions/nodeConversions.d.ts +15 -0
- package/types/src/api/nodeConversions/nodeConversions.test.d.ts +1 -0
- package/types/src/api/nodeConversions/testUtil.d.ts +2 -0
- package/types/src/api/util/nodeUtil.d.ts +8 -0
- package/types/src/extensions/Blocks/api/blockTypes.d.ts +37 -0
- package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +4 -0
- package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +29 -0
- package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +3 -3
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +15 -0
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +2 -2
- package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +1 -3
- package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +4 -1
- package/types/src/extensions/SlashMenu/index.d.ts +3 -3
- package/types/src/index.d.ts +4 -2
- package/types/src/shared/utils.d.ts +3 -0
- package/src/extensions/Blocks/apiTypes.ts +0 -48
- package/types/src/EditorElement.d.ts +0 -7
- package/types/src/api/Document.d.ts +0 -5
- package/types/src/extensions/Blocks/BlockAttributes.d.ts +0 -2
- package/types/src/extensions/Blocks/MultipleNodeSelection.d.ts +0 -24
- package/types/src/extensions/Blocks/apiTypes.d.ts +0 -16
- package/types/src/extensions/Blocks/nodes/Block.d.ts +0 -24
- package/types/src/extensions/Blocks/nodes/BlockContent/BlockContentTypes.d.ts +0 -4
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContentTypes.d.ts +0 -4
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContentTypes.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContentTypes.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContentTypes.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockTypes/HeadingBlock/HeadingContent.d.ts +0 -8
- package/types/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/ListItemContent.d.ts +0 -8
- package/types/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/OrderedListItemIndexPlugin.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockTypes/TextBlock/TextContent.d.ts +0 -6
- package/types/src/extensions/BubbleMenu/BubbleMenuExtension.d.ts +0 -8
- package/types/src/extensions/BubbleMenu/BubbleMenuFactoryTypes.d.ts +0 -27
- package/types/src/extensions/BubbleMenu/BubbleMenuPlugin.d.ts +0 -44
- package/types/src/extensions/DraggableBlocks/BlockMenuFactoryTypes.d.ts +0 -12
- package/types/src/extensions/DraggableBlocks/DragMenuFactoryTypes.d.ts +0 -18
- package/types/src/extensions/Hyperlinks/HyperlinkMark.d.ts +0 -8
- package/types/src/extensions/Hyperlinks/HyperlinkMenuFactoryTypes.d.ts +0 -11
- package/types/src/extensions/Hyperlinks/HyperlinkMenuPlugin.d.ts +0 -11
- package/types/src/extensions/Paragraph/FixedParagraph.d.ts +0 -1
- package/types/src/extensions/SlashMenu/defaultCommands.d.ts +0 -8
- package/types/src/utils.d.ts +0 -2
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Editor } from "@tiptap/core";
|
|
2
|
+
import { BlockIdentifier, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
|
|
3
|
+
export declare function insertBlocks(blocksToInsert: PartialBlock[], referenceBlock: BlockIdentifier, placement: "before" | "after" | "nested" | undefined, editor: Editor): void;
|
|
4
|
+
export declare function updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock, editor: Editor): void;
|
|
5
|
+
export declare function removeBlocks(blocksToRemove: BlockIdentifier[], editor: Editor): void;
|
|
6
|
+
export declare function replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock[], editor: Editor): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Schema } from "prosemirror-model";
|
|
2
|
+
import { Block } from "../../extensions/Blocks/api/blockTypes";
|
|
3
|
+
export declare function blocksToHTML(blocks: Block[], schema: Schema): Promise<string>;
|
|
4
|
+
export declare function HTMLToBlocks(htmlString: string, schema: Schema): Promise<Block[]>;
|
|
5
|
+
export declare function blocksToMarkdown(blocks: Block[], schema: Schema): Promise<string>;
|
|
6
|
+
export declare function markdownToBlocks(markdownString: string, schema: Schema): Promise<Block[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Parent as HASTParent } from "hast";
|
|
2
|
+
/**
|
|
3
|
+
* Rehype plugin which removes <u> tags. Used to remove underlines before converting HTML to markdown, as Markdown
|
|
4
|
+
* doesn't support underlines.
|
|
5
|
+
*/
|
|
6
|
+
export declare function removeUnderlines(): (tree: HASTParent) => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Parent as HASTParent } from "hast";
|
|
2
|
+
type SimplifyBlocksOptions = {
|
|
3
|
+
orderedListItemBlockTypes: Set<string>;
|
|
4
|
+
unorderedListItemBlockTypes: Set<string>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Rehype plugin which converts the HTML output string rendered by BlockNote into a simplified structure which better
|
|
8
|
+
* follows HTML standards. It does several things:
|
|
9
|
+
* - Removes all block related div elements, leaving only the actual content inside the block.
|
|
10
|
+
* - Lifts nested blocks to a higher level for all block types that don't represent list items.
|
|
11
|
+
* - Wraps blocks which represent list items in corresponding ul/ol HTML elements and restructures them to comply
|
|
12
|
+
* with HTML list structure.
|
|
13
|
+
* @param options Options for specifying which block types represent ordered and unordered list items.
|
|
14
|
+
*/
|
|
15
|
+
export declare function simplifyBlocks(options: SimplifyBlocksOptions): (tree: HASTParent) => void;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Node, Schema } from "prosemirror-model";
|
|
2
|
+
import { Block, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
|
|
3
|
+
import { PartialInlineContent } from "../../extensions/Blocks/api/inlineContentTypes";
|
|
4
|
+
/**
|
|
5
|
+
* converts an array of inline content elements to prosemirror nodes
|
|
6
|
+
*/
|
|
7
|
+
export declare function inlineContentToNodes(blockContent: PartialInlineContent[], schema: Schema): Node[];
|
|
8
|
+
/**
|
|
9
|
+
* Converts a BlockNote block to a TipTap node.
|
|
10
|
+
*/
|
|
11
|
+
export declare function blockToNode(block: PartialBlock, schema: Schema): Node;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a TipTap node to a BlockNote block.
|
|
14
|
+
*/
|
|
15
|
+
export declare function nodeToBlock(node: Node, blockCache?: WeakMap<Node, Block>): Block;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Define the main block types **/
|
|
2
|
+
import { InlineContent, PartialInlineContent } from "./inlineContentTypes";
|
|
3
|
+
export type BlockTemplate<Type extends string, Props extends Record<string, string>> = {
|
|
4
|
+
id: string;
|
|
5
|
+
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";
|
|
19
|
+
}>;
|
|
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>>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type Styles = {
|
|
2
|
+
bold?: true;
|
|
3
|
+
italic?: true;
|
|
4
|
+
underline?: true;
|
|
5
|
+
strike?: true;
|
|
6
|
+
textColor?: string;
|
|
7
|
+
backgroundColor?: string;
|
|
8
|
+
};
|
|
9
|
+
export type ToggledStyles = {
|
|
10
|
+
[K in keyof Styles]-?: Required<Styles>[K] extends true ? K : never;
|
|
11
|
+
}[keyof Styles];
|
|
12
|
+
export type ColorStyles = {
|
|
13
|
+
[K in keyof Styles]-?: Required<Styles>[K] extends string ? K : never;
|
|
14
|
+
}[keyof Styles];
|
|
15
|
+
export type StyledText = {
|
|
16
|
+
type: "text";
|
|
17
|
+
text: string;
|
|
18
|
+
styles: Styles;
|
|
19
|
+
};
|
|
20
|
+
export type Link = {
|
|
21
|
+
type: "link";
|
|
22
|
+
href: string;
|
|
23
|
+
content: StyledText[];
|
|
24
|
+
};
|
|
25
|
+
export type PartialLink = Omit<Link, "content"> & {
|
|
26
|
+
content: string | Link["content"];
|
|
27
|
+
};
|
|
28
|
+
export type InlineContent = StyledText | Link;
|
|
29
|
+
export type PartialInlineContent = StyledText | PartialLink;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Node } from "@tiptap/core";
|
|
2
|
-
import {
|
|
2
|
+
import { 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,
|
|
14
|
-
BNCreateOrUpdateBlock: (posInBlock: number,
|
|
13
|
+
BNUpdateBlock: (posInBlock: number, block: PartialBlock) => ReturnType;
|
|
14
|
+
BNCreateOrUpdateBlock: (posInBlock: number, block: PartialBlock) => ReturnType;
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -24,6 +24,21 @@ export declare class BlockMenuView {
|
|
|
24
24
|
menuOpen: boolean;
|
|
25
25
|
menuFrozen: boolean;
|
|
26
26
|
constructor({ editor, blockMenuFactory, horizontalPosAnchoredAtRoot, }: BlockMenuViewProps);
|
|
27
|
+
/**
|
|
28
|
+
* If the event is outside of the editor contents,
|
|
29
|
+
* we dispatch a fake event, so that we can still drop the content
|
|
30
|
+
* when dragging / dropping to the side of the editor
|
|
31
|
+
*/
|
|
32
|
+
onDrop: (event: DragEvent) => void;
|
|
33
|
+
/**
|
|
34
|
+
* If the event is outside of the editor contents,
|
|
35
|
+
* we dispatch a fake event, so that we can still drop the content
|
|
36
|
+
* when dragging / dropping to the side of the editor
|
|
37
|
+
*/
|
|
38
|
+
onDragOver: (event: DragEvent) => void;
|
|
39
|
+
onKeyDown: (_event: KeyboardEvent) => void;
|
|
40
|
+
onMouseDown: (event: MouseEvent) => void;
|
|
41
|
+
onMouseMove: (event: MouseEvent) => void;
|
|
27
42
|
destroy(): void;
|
|
28
43
|
addBlock(): void;
|
|
29
44
|
deleteBlock(): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
import { Block,
|
|
2
|
+
import { Block, PartialBlock } from "../Blocks/api/blockTypes";
|
|
3
3
|
export type FormattingToolbarStaticParams = {
|
|
4
4
|
toggleBold: () => void;
|
|
5
5
|
toggleItalic: () => void;
|
|
@@ -11,7 +11,7 @@ export type FormattingToolbarStaticParams = {
|
|
|
11
11
|
setTextAlignment: (textAlignment: "left" | "center" | "right" | "justify") => void;
|
|
12
12
|
increaseBlockIndent: () => void;
|
|
13
13
|
decreaseBlockIndent: () => void;
|
|
14
|
-
updateBlock: (
|
|
14
|
+
updateBlock: (updatedBlock: PartialBlock) => void;
|
|
15
15
|
};
|
|
16
16
|
export type FormattingToolbarDynamicParams = {
|
|
17
17
|
boldIsActive: boolean;
|
|
@@ -3,9 +3,7 @@ import { PluginKey } from "prosemirror-state";
|
|
|
3
3
|
import { SuggestionsMenuFactory } from "../../shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
4
4
|
import { SlashMenuItem } from "./SlashMenuItem";
|
|
5
5
|
export type SlashMenuOptions = {
|
|
6
|
-
commands:
|
|
7
|
-
[key: string]: SlashMenuItem;
|
|
8
|
-
};
|
|
6
|
+
commands: SlashMenuItem[] | undefined;
|
|
9
7
|
slashMenuFactory: SuggestionsMenuFactory<any> | undefined;
|
|
10
8
|
};
|
|
11
9
|
export declare const SlashMenuPluginKey: PluginKey<any>;
|
|
@@ -9,6 +9,9 @@ export declare class SlashMenuItem implements SuggestionItem {
|
|
|
9
9
|
readonly name: string;
|
|
10
10
|
readonly execute: (editor: Editor, range: Range) => void;
|
|
11
11
|
readonly aliases: string[];
|
|
12
|
+
readonly group: string;
|
|
13
|
+
readonly hint?: string | undefined;
|
|
14
|
+
readonly shortcut?: string | undefined;
|
|
12
15
|
/**
|
|
13
16
|
* Constructs a new slash-command.
|
|
14
17
|
*
|
|
@@ -16,6 +19,6 @@ export declare class SlashMenuItem implements SuggestionItem {
|
|
|
16
19
|
* @param execute The callback for creating a new node
|
|
17
20
|
* @param aliases Aliases for this command
|
|
18
21
|
*/
|
|
19
|
-
constructor(name: string, execute: (editor: Editor, range: Range) => void, aliases
|
|
22
|
+
constructor(name: string, execute: (editor: Editor, range: Range) => void, aliases: string[], group: string, hint?: string | undefined, shortcut?: string | undefined);
|
|
20
23
|
match(query: string): boolean;
|
|
21
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import { defaultSlashCommands } from "./defaultSlashCommands";
|
|
1
2
|
import { SlashMenuExtension } from "./SlashMenuExtension";
|
|
2
|
-
import
|
|
3
|
-
export {
|
|
4
|
-
export default SlashMenuExtension;
|
|
3
|
+
import { SlashMenuItem } from "./SlashMenuItem";
|
|
4
|
+
export { defaultSlashCommands, SlashMenuItem as SlashCommand, SlashMenuExtension, };
|
package/types/src/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export * from "./BlockNoteEditor";
|
|
2
2
|
export * from "./BlockNoteExtensions";
|
|
3
|
-
export
|
|
4
|
-
export * from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
|
|
3
|
+
export * from "./extensions/Blocks/api/blockTypes";
|
|
5
4
|
export * from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
|
|
5
|
+
export * from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
|
|
6
6
|
export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
|
|
7
|
+
export { defaultSlashCommands } from "./extensions/SlashMenu/defaultSlashCommands";
|
|
7
8
|
export * from "./extensions/SlashMenu/SlashMenuItem";
|
|
8
9
|
export * from "./shared/EditorElement";
|
|
9
10
|
export type { SuggestionItem } from "./shared/plugins/suggestion/SuggestionItem";
|
|
10
11
|
export * from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
12
|
+
export * from "../src/api/Editor";
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export type BlockSpec<
|
|
2
|
-
// Type of the block.
|
|
3
|
-
// Examples might include: "paragraph", "heading", or "bulletListItem".
|
|
4
|
-
Type extends string,
|
|
5
|
-
// Changeable props which affect the block's behaviour or appearance.
|
|
6
|
-
// An example might be: { textAlignment: "left" | "right" | "center" | "justify" } for a paragraph block.
|
|
7
|
-
Props extends Record<string, string>
|
|
8
|
-
> = {
|
|
9
|
-
type: Type;
|
|
10
|
-
props: Props;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type BlockSpecUpdate<Spec> = Spec extends BlockSpec<
|
|
14
|
-
infer Type,
|
|
15
|
-
infer Props
|
|
16
|
-
>
|
|
17
|
-
? {
|
|
18
|
-
type: Type;
|
|
19
|
-
props?: Partial<Props>;
|
|
20
|
-
}
|
|
21
|
-
: never;
|
|
22
|
-
|
|
23
|
-
export type NumberedListItemBlock = BlockSpec<"numberedListItem", {}>;
|
|
24
|
-
|
|
25
|
-
export type BulletListItemBlock = BlockSpec<"bulletListItem", {}>;
|
|
26
|
-
|
|
27
|
-
export type HeadingBlock = BlockSpec<
|
|
28
|
-
"heading",
|
|
29
|
-
{
|
|
30
|
-
level: "1" | "2" | "3";
|
|
31
|
-
}
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
export type ParagraphBlock = BlockSpec<"paragraph", {}>;
|
|
35
|
-
|
|
36
|
-
export type Block =
|
|
37
|
-
| ParagraphBlock
|
|
38
|
-
| HeadingBlock
|
|
39
|
-
| BulletListItemBlock
|
|
40
|
-
| NumberedListItemBlock;
|
|
41
|
-
|
|
42
|
-
export type BlockUpdate = BlockSpecUpdate<Block>;
|
|
43
|
-
|
|
44
|
-
/*
|
|
45
|
-
TODO:
|
|
46
|
-
1) guard read / writes (now we just pass on internal node attrs)
|
|
47
|
-
2) where to locate this code / types
|
|
48
|
-
*/
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare type EditorElement<ElementParams extends Record<string, any>> = {
|
|
2
|
-
element: HTMLElement | undefined;
|
|
3
|
-
show: (params: ElementParams) => void;
|
|
4
|
-
hide: () => void;
|
|
5
|
-
update: (params: ElementParams) => void;
|
|
6
|
-
};
|
|
7
|
-
export declare type ElementFactory<ElementParams extends Record<string, any>> = (params: ElementParams) => EditorElement<ElementParams>;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Node } from "prosemirror-model";
|
|
2
|
-
import { EditorState } from "prosemirror-state";
|
|
3
|
-
import { Block, Document } from "../extensions/Blocks/apiTypes";
|
|
4
|
-
export declare function BlockFromPMNode(node: Node): Block;
|
|
5
|
-
export declare function DocumentFromPMState(_state: EditorState): Document;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Selection } from "prosemirror-state";
|
|
2
|
-
import { Node, ResolvedPos, Slice } from "prosemirror-model";
|
|
3
|
-
import { Mappable } from "prosemirror-transform";
|
|
4
|
-
/**
|
|
5
|
-
* This class represents an editor selection which spans multiple nodes/blocks. It's currently only used to allow users
|
|
6
|
-
* to drag multiple blocks at the same time. Expects the selection anchor and head to be between nodes, i.e. just before
|
|
7
|
-
* the first target node and just after the last, and that anchor and head are at the same nesting level.
|
|
8
|
-
*
|
|
9
|
-
* Partially based on ProseMirror's NodeSelection implementation:
|
|
10
|
-
* (https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.ts)
|
|
11
|
-
* MultipleNodeSelection differs from NodeSelection in the following ways:
|
|
12
|
-
* 1. Stores which nodes are included in the selection instead of just a single node.
|
|
13
|
-
* 2. Already expects the selection to start just before the first target node and ends just after the last, while a
|
|
14
|
-
* NodeSelection automatically sets both anchor and head to just before the single target node.
|
|
15
|
-
*/
|
|
16
|
-
export declare class MultipleNodeSelection extends Selection {
|
|
17
|
-
nodes: Array<Node>;
|
|
18
|
-
constructor($anchor: ResolvedPos, $head: ResolvedPos);
|
|
19
|
-
static create(doc: Node, from: number, to?: number): MultipleNodeSelection;
|
|
20
|
-
content(): Slice;
|
|
21
|
-
eq(selection: Selection): boolean;
|
|
22
|
-
map(doc: Node, mapping: Mappable): Selection;
|
|
23
|
-
toJSON(): any;
|
|
24
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type BlockSpec<Type extends string, Props extends Record<string, string>> = {
|
|
2
|
-
type: Type;
|
|
3
|
-
props: Props;
|
|
4
|
-
};
|
|
5
|
-
export type BlockSpecUpdate<Spec> = Spec extends BlockSpec<infer Type, infer Props> ? {
|
|
6
|
-
type: Type;
|
|
7
|
-
props?: Partial<Props>;
|
|
8
|
-
} : never;
|
|
9
|
-
export type NumberedListItemBlock = BlockSpec<"numberedListItem", {}>;
|
|
10
|
-
export type BulletListItemBlock = BlockSpec<"bulletListItem", {}>;
|
|
11
|
-
export type HeadingBlock = BlockSpec<"heading", {
|
|
12
|
-
level: "1" | "2" | "3";
|
|
13
|
-
}>;
|
|
14
|
-
export type ParagraphBlock = BlockSpec<"paragraph", {}>;
|
|
15
|
-
export type Block = ParagraphBlock | HeadingBlock | BulletListItemBlock | NumberedListItemBlock;
|
|
16
|
-
export type BlockUpdate = BlockSpecUpdate<Block>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Node } from "@tiptap/core";
|
|
2
|
-
import { TextContentType } from "./BlockTypes/TextBlock/TextContent";
|
|
3
|
-
import { HeadingContentType } from "./BlockTypes/HeadingBlock/HeadingContent";
|
|
4
|
-
import { ListItemContentType } from "./BlockTypes/ListItemBlock/ListItemContent";
|
|
5
|
-
export interface IBlock {
|
|
6
|
-
HTMLAttributes: Record<string, any>;
|
|
7
|
-
}
|
|
8
|
-
export declare type BlockContentType = TextContentType | HeadingContentType | ListItemContentType;
|
|
9
|
-
declare module "@tiptap/core" {
|
|
10
|
-
interface Commands<ReturnType> {
|
|
11
|
-
block: {
|
|
12
|
-
BNCreateBlock: (pos: number) => ReturnType;
|
|
13
|
-
BNDeleteBlock: (posInBlock: number) => ReturnType;
|
|
14
|
-
BNMergeBlocks: (posBetweenBlocks: number) => ReturnType;
|
|
15
|
-
BNSplitBlock: (posInBlock: number, keepType: boolean) => ReturnType;
|
|
16
|
-
BNSetContentType: (posInBlock: number, type: BlockContentType) => ReturnType;
|
|
17
|
-
BNCreateBlockOrSetContentType: (posInBlock: number, type: BlockContentType) => ReturnType;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* The main "Block node" documents consist of
|
|
23
|
-
*/
|
|
24
|
-
export declare const Block: Node<IBlock, any>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Extension } from "@tiptap/core";
|
|
2
|
-
import { BubbleMenuFactory } from "./BubbleMenuFactoryTypes";
|
|
3
|
-
/**
|
|
4
|
-
* The menu that is displayed when selecting a piece of text.
|
|
5
|
-
*/
|
|
6
|
-
export declare const BubbleMenuExtension: Extension<{
|
|
7
|
-
bubbleMenuFactory: BubbleMenuFactory;
|
|
8
|
-
}, any>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
export declare type BubbleMenuParams = {
|
|
3
|
-
boldIsActive: boolean;
|
|
4
|
-
toggleBold: () => void;
|
|
5
|
-
italicIsActive: boolean;
|
|
6
|
-
toggleItalic: () => void;
|
|
7
|
-
underlineIsActive: boolean;
|
|
8
|
-
toggleUnderline: () => void;
|
|
9
|
-
strikeIsActive: boolean;
|
|
10
|
-
toggleStrike: () => void;
|
|
11
|
-
hyperlinkIsActive: boolean;
|
|
12
|
-
activeHyperlinkUrl: string;
|
|
13
|
-
activeHyperlinkText: string;
|
|
14
|
-
setHyperlink: (url: string, text?: string) => void;
|
|
15
|
-
paragraphIsActive: boolean;
|
|
16
|
-
setParagraph: () => void;
|
|
17
|
-
headingIsActive: boolean;
|
|
18
|
-
activeHeadingLevel: string;
|
|
19
|
-
setHeading: (level: string) => void;
|
|
20
|
-
setListItem: (type: string) => void;
|
|
21
|
-
listItemIsActive: boolean;
|
|
22
|
-
activeListItemType: string;
|
|
23
|
-
selectionBoundingBox: DOMRect;
|
|
24
|
-
editorElement: Element;
|
|
25
|
-
};
|
|
26
|
-
export declare type BubbleMenu = EditorElement<BubbleMenuParams>;
|
|
27
|
-
export declare type BubbleMenuFactory = ElementFactory<BubbleMenuParams>;
|