@blocknote/core 0.2.2 → 0.2.3
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 +696 -691
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +1 -1
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +5 -3
- package/src/BlockNoteExtensions.ts +1 -10
- package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +22 -26
- package/src/extensions/Blocks/apiTypes.ts +48 -0
- package/src/extensions/Blocks/helpers/findBlock.ts +3 -1
- package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +1 -1
- package/src/extensions/Blocks/index.ts +10 -8
- package/src/extensions/Blocks/nodes/Block.module.css +31 -29
- package/src/extensions/Blocks/{BlockAttributes.ts → nodes/BlockAttributes.ts} +0 -0
- package/src/extensions/Blocks/nodes/{Block.ts → BlockContainer.ts} +75 -94
- package/src/extensions/Blocks/nodes/{BlockTypes/HeadingBlock/HeadingContent.ts → BlockContent/HeadingBlockContent/HeadingBlockContent.ts} +16 -24
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +76 -0
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/ListItemKeyboardShortcuts.ts +47 -0
- package/src/extensions/Blocks/nodes/{BlockTypes/ListItemBlock/OrderedListItemIndexPlugin.ts → BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts} +10 -14
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +95 -0
- package/src/extensions/Blocks/nodes/{BlockTypes/TextBlock/TextContent.ts → BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts} +3 -8
- package/src/extensions/Blocks/nodes/BlockGroup.ts +4 -4
- package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +1 -1
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +7 -7
- package/src/extensions/{Blocks → DraggableBlocks}/MultipleNodeSelection.ts +0 -0
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +4 -7
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +17 -9
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.ts +1 -1
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +3 -1
- package/src/extensions/SlashMenu/defaultCommands.tsx +22 -23
- package/src/extensions/TrailingNode/TrailingNodeExtension.ts +4 -4
- package/src/extensions/UniqueID/UniqueID.ts +6 -0
- package/src/index.ts +2 -1
- package/src/shared/EditorElement.ts +12 -6
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +2 -2
- package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +1 -1
- package/types/src/BlockNoteEditor.d.ts +1 -1
- package/types/src/BlockNoteExtensions.d.ts +1 -3
- package/types/src/extensions/Blocks/apiTypes.d.ts +16 -0
- package/types/src/extensions/Blocks/helpers/getBlockInfoFromPos.d.ts +1 -1
- package/types/src/extensions/Blocks/nodes/BlockAttributes.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +21 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/BlockContentTypes.d.ts +4 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContentTypes.d.ts +4 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContentTypes.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContentTypes.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContentTypes.d.ts +2 -0
- package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +5 -5
- package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +1 -1
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +2 -2
- package/types/src/extensions/DraggableBlocks/MultipleNodeSelection.d.ts +24 -0
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +8 -8
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +1 -1
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.d.ts +5 -5
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +2 -2
- package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +1 -1
- package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +1 -1
- package/types/src/index.d.ts +2 -1
- package/types/src/shared/EditorElement.d.ts +6 -2
- package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +3 -3
- package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +5 -5
- package/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/ListItemContent.ts +0 -177
- package/src/extensions/Paragraph/FixedParagraph.ts +0 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
export
|
|
2
|
+
export type BlockSideMenuStaticParams = {
|
|
3
3
|
addBlock: () => void;
|
|
4
4
|
deleteBlock: () => void;
|
|
5
5
|
blockDragStart: (event: DragEvent) => void;
|
|
@@ -7,8 +7,8 @@ export declare type BlockSideMenuStaticParams = {
|
|
|
7
7
|
freezeMenu: () => void;
|
|
8
8
|
unfreezeMenu: () => void;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
11
|
-
|
|
10
|
+
export type BlockSideMenuDynamicParams = {
|
|
11
|
+
referenceRect: DOMRect;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
14
|
-
export
|
|
13
|
+
export type BlockSideMenu = EditorElement<BlockSideMenuDynamicParams>;
|
|
14
|
+
export type BlockSideMenuFactory = ElementFactory<BlockSideMenuStaticParams, BlockSideMenuDynamicParams>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Editor, Extension } from "@tiptap/core";
|
|
2
2
|
import { BlockSideMenuFactory } from "./BlockSideMenuFactoryTypes";
|
|
3
|
-
export
|
|
3
|
+
export type DraggableBlocksOptions = {
|
|
4
4
|
editor: Editor;
|
|
5
5
|
blockSideMenuFactory: BlockSideMenuFactory;
|
|
6
6
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Editor } from "@tiptap/core";
|
|
2
2
|
import { Plugin } from "prosemirror-state";
|
|
3
|
-
import { DraggableBlocksOptions } from "./DraggableBlocksExtension";
|
|
4
3
|
import { BlockSideMenu, BlockSideMenuDynamicParams, BlockSideMenuFactory, BlockSideMenuStaticParams } from "./BlockSideMenuFactoryTypes";
|
|
4
|
+
import { DraggableBlocksOptions } from "./DraggableBlocksExtension";
|
|
5
5
|
export declare function createRect(rect: DOMRect): {
|
|
6
6
|
left: number;
|
|
7
7
|
top: number;
|
|
@@ -18,7 +18,7 @@ export declare function absoluteRect(element: HTMLElement): {
|
|
|
18
18
|
bottom: number;
|
|
19
19
|
right: number;
|
|
20
20
|
};
|
|
21
|
-
export
|
|
21
|
+
export type BlockMenuViewProps = {
|
|
22
22
|
editor: Editor;
|
|
23
23
|
blockMenuFactory: BlockSideMenuFactory;
|
|
24
24
|
horizontalPosAnchoredAtRoot: boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
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,14 +1,14 @@
|
|
|
1
1
|
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
2
|
+
import { Block, BlockUpdate } from "../Blocks/apiTypes";
|
|
3
|
+
export type FormattingToolbarStaticParams = {
|
|
4
4
|
toggleBold: () => void;
|
|
5
5
|
toggleItalic: () => void;
|
|
6
6
|
toggleUnderline: () => void;
|
|
7
7
|
toggleStrike: () => void;
|
|
8
8
|
setHyperlink: (url: string, text?: string) => void;
|
|
9
|
-
|
|
9
|
+
updateBlock: (blockUpdate: BlockUpdate) => void;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type FormattingToolbarDynamicParams = {
|
|
12
12
|
boldIsActive: boolean;
|
|
13
13
|
italicIsActive: boolean;
|
|
14
14
|
underlineIsActive: boolean;
|
|
@@ -16,8 +16,8 @@ export declare type FormattingToolbarDynamicParams = {
|
|
|
16
16
|
hyperlinkIsActive: boolean;
|
|
17
17
|
activeHyperlinkUrl: string;
|
|
18
18
|
activeHyperlinkText: string;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
block: Block;
|
|
20
|
+
referenceRect: DOMRect;
|
|
21
21
|
};
|
|
22
|
-
export
|
|
23
|
-
export
|
|
22
|
+
export type FormattingToolbar = EditorElement<FormattingToolbarDynamicParams>;
|
|
23
|
+
export type FormattingToolbarFactory = ElementFactory<FormattingToolbarStaticParams, FormattingToolbarDynamicParams>;
|
|
@@ -15,7 +15,7 @@ export interface FormattingToolbarPluginProps {
|
|
|
15
15
|
to: number;
|
|
16
16
|
}) => boolean) | null;
|
|
17
17
|
}
|
|
18
|
-
export
|
|
18
|
+
export type FormattingToolbarViewProps = FormattingToolbarPluginProps & {
|
|
19
19
|
view: EditorView;
|
|
20
20
|
};
|
|
21
21
|
export declare class FormattingToolbarView {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
export
|
|
2
|
+
export type HyperlinkToolbarStaticParams = {
|
|
3
3
|
editHyperlink: (url: string, text: string) => void;
|
|
4
4
|
deleteHyperlink: () => void;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type HyperlinkToolbarDynamicParams = {
|
|
7
7
|
url: string;
|
|
8
8
|
text: string;
|
|
9
|
-
|
|
9
|
+
referenceRect: DOMRect;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
12
|
-
export
|
|
11
|
+
export type HyperlinkToolbar = EditorElement<HyperlinkToolbarDynamicParams>;
|
|
12
|
+
export type HyperlinkToolbarFactory = ElementFactory<HyperlinkToolbarStaticParams, HyperlinkToolbarDynamicParams>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Editor } from "@tiptap/core";
|
|
2
2
|
import { Plugin } from "prosemirror-state";
|
|
3
3
|
import { HyperlinkToolbarFactory } from "./HyperlinkToolbarFactoryTypes";
|
|
4
|
-
export
|
|
4
|
+
export type HyperlinkToolbarPluginProps = {
|
|
5
5
|
hyperlinkToolbarFactory: HyperlinkToolbarFactory;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
7
|
+
export type HyperlinkToolbarViewProps = {
|
|
8
8
|
editor: Editor;
|
|
9
9
|
hyperlinkToolbarFactory: HyperlinkToolbarFactory;
|
|
10
10
|
};
|
|
@@ -2,7 +2,7 @@ import { Extension } from "@tiptap/core";
|
|
|
2
2
|
import { PluginKey } from "prosemirror-state";
|
|
3
3
|
import { SuggestionsMenuFactory } from "../../shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
4
4
|
import { SlashMenuItem } from "./SlashMenuItem";
|
|
5
|
-
export
|
|
5
|
+
export type SlashMenuOptions = {
|
|
6
6
|
commands: {
|
|
7
7
|
[key: string]: SlashMenuItem;
|
|
8
8
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Editor, Range } from "@tiptap/core";
|
|
2
2
|
import { SuggestionItem } from "../../shared/plugins/suggestion/SuggestionItem";
|
|
3
|
-
export
|
|
3
|
+
export type SlashMenuCallback = (editor: Editor, range: Range) => boolean;
|
|
4
4
|
export declare enum SlashMenuGroups {
|
|
5
5
|
HEADINGS = "Headings",
|
|
6
6
|
BASIC_BLOCKS = "Basic Blocks",
|
package/types/src/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export * from "./BlockNoteEditor";
|
|
2
2
|
export * from "./BlockNoteExtensions";
|
|
3
|
-
export type {
|
|
3
|
+
export type { Block, BlockUpdate } from "./extensions/Blocks/apiTypes";
|
|
4
4
|
export * from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
|
|
5
5
|
export * from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
|
|
6
6
|
export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
|
|
7
7
|
export * from "./extensions/SlashMenu/SlashMenuItem";
|
|
8
|
+
export * from "./shared/EditorElement";
|
|
8
9
|
export type { SuggestionItem } from "./shared/plugins/suggestion/SuggestionItem";
|
|
9
10
|
export * from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type RequiredStaticParams = Record<string, any>;
|
|
2
|
+
export type RequiredDynamicParams = Record<string, any> & {
|
|
3
|
+
referenceRect: DOMRect;
|
|
4
|
+
};
|
|
5
|
+
export type EditorElement<ElementDynamicParams extends RequiredDynamicParams> = {
|
|
2
6
|
element: HTMLElement | undefined;
|
|
3
7
|
render: (params: ElementDynamicParams, isHidden: boolean) => void;
|
|
4
8
|
hide: () => void;
|
|
5
9
|
};
|
|
6
|
-
export
|
|
10
|
+
export type ElementFactory<ElementStaticParams extends RequiredStaticParams, ElementDynamicParams extends RequiredDynamicParams> = (staticParams: ElementStaticParams) => EditorElement<ElementDynamicParams>;
|
|
@@ -2,7 +2,7 @@ import { Editor, Range } from "@tiptap/core";
|
|
|
2
2
|
import { Plugin, PluginKey, Selection } from "prosemirror-state";
|
|
3
3
|
import { SuggestionsMenuFactory } from "./SuggestionsMenuFactoryTypes";
|
|
4
4
|
import { SuggestionItem } from "./SuggestionItem";
|
|
5
|
-
export
|
|
5
|
+
export type SuggestionPluginOptions<T extends SuggestionItem> = {
|
|
6
6
|
/**
|
|
7
7
|
* The name of the plugin.
|
|
8
8
|
*
|
|
@@ -39,7 +39,7 @@ export declare type SuggestionPluginOptions<T extends SuggestionItem> = {
|
|
|
39
39
|
range: Range;
|
|
40
40
|
}) => boolean;
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
type SuggestionPluginState<T extends SuggestionItem> = {
|
|
43
43
|
active: boolean;
|
|
44
44
|
range: Range | null;
|
|
45
45
|
query: string | null;
|
|
@@ -49,7 +49,7 @@ declare type SuggestionPluginState<T extends SuggestionItem> = {
|
|
|
49
49
|
type: string;
|
|
50
50
|
decorationId: string | null;
|
|
51
51
|
};
|
|
52
|
-
export
|
|
52
|
+
export type MenuType = "slash" | "drag";
|
|
53
53
|
/**
|
|
54
54
|
* Finds a command: a specified character (e.g. '/') followed by a string of characters (all characters except the specified character are allowed).
|
|
55
55
|
* Returns the string following the specified character or undefined if no command was found.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { EditorElement, ElementFactory } from "../../EditorElement";
|
|
2
2
|
import { SuggestionItem } from "./SuggestionItem";
|
|
3
|
-
export
|
|
3
|
+
export type SuggestionsMenuStaticParams<T extends SuggestionItem> = {
|
|
4
4
|
itemCallback: (item: T) => void;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type SuggestionsMenuDynamicParams<T extends SuggestionItem> = {
|
|
7
7
|
items: T[];
|
|
8
8
|
selectedItemIndex: number;
|
|
9
|
-
|
|
9
|
+
referenceRect: DOMRect;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
12
|
-
export
|
|
11
|
+
export type SuggestionsMenu<T extends SuggestionItem> = EditorElement<SuggestionsMenuDynamicParams<T>>;
|
|
12
|
+
export type SuggestionsMenuFactory<T extends SuggestionItem> = ElementFactory<SuggestionsMenuStaticParams<T>, SuggestionsMenuDynamicParams<T>>;
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { InputRule, mergeAttributes, Node } from "@tiptap/core";
|
|
2
|
-
import { OrderedListItemIndexPlugin } from "./OrderedListItemIndexPlugin";
|
|
3
|
-
import { getBlockInfoFromPos } from "../../../helpers/getBlockInfoFromPos";
|
|
4
|
-
import styles from "../../Block.module.css";
|
|
5
|
-
|
|
6
|
-
export type ListItemContentType = {
|
|
7
|
-
name: "listItemContent";
|
|
8
|
-
attrs?: {
|
|
9
|
-
listItemType: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const ListItemContent = Node.create({
|
|
14
|
-
name: "listItemContent",
|
|
15
|
-
group: "blockContent",
|
|
16
|
-
content: "inline*",
|
|
17
|
-
|
|
18
|
-
addAttributes() {
|
|
19
|
-
return {
|
|
20
|
-
listItemType: {
|
|
21
|
-
default: "unordered",
|
|
22
|
-
parseHTML: (element) => element.getAttribute("data-list-item-type"),
|
|
23
|
-
renderHTML: (attributes) => {
|
|
24
|
-
return {
|
|
25
|
-
"data-list-item-type": attributes.listItemType,
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
listItemIndex: {
|
|
30
|
-
default: null,
|
|
31
|
-
parseHTML: (element) => element.getAttribute("data-list-item-index"),
|
|
32
|
-
renderHTML: (attributes) => {
|
|
33
|
-
return {
|
|
34
|
-
"data-list-item-index": attributes.listItemIndex,
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
addInputRules() {
|
|
42
|
-
return [
|
|
43
|
-
// Creates an unordered list when starting with "-", "+", or "*".
|
|
44
|
-
new InputRule({
|
|
45
|
-
find: new RegExp(`^[-+*]\\s$`),
|
|
46
|
-
handler: ({ state, chain, range }) => {
|
|
47
|
-
chain()
|
|
48
|
-
.BNSetContentType(state.selection.from, {
|
|
49
|
-
name: "listItemContent",
|
|
50
|
-
attrs: {
|
|
51
|
-
listItemType: "unordered",
|
|
52
|
-
},
|
|
53
|
-
})
|
|
54
|
-
// Removes the "-", "+", or "*" character used to set the list.
|
|
55
|
-
.deleteRange({ from: range.from, to: range.to });
|
|
56
|
-
},
|
|
57
|
-
}),
|
|
58
|
-
// Creates an ordered list when starting with "1.".
|
|
59
|
-
new InputRule({
|
|
60
|
-
find: new RegExp(`^1\\.\\s$`),
|
|
61
|
-
handler: ({ state, chain, range }) => {
|
|
62
|
-
chain()
|
|
63
|
-
.BNSetContentType(state.selection.from, {
|
|
64
|
-
name: "listItemContent",
|
|
65
|
-
attrs: {
|
|
66
|
-
listItemType: "ordered",
|
|
67
|
-
},
|
|
68
|
-
})
|
|
69
|
-
// Removes the "1." characters used to set the list.
|
|
70
|
-
.deleteRange({ from: range.from, to: range.to });
|
|
71
|
-
},
|
|
72
|
-
}),
|
|
73
|
-
];
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
addKeyboardShortcuts() {
|
|
77
|
-
const handleEnter = () => {
|
|
78
|
-
const { node, contentType } = getBlockInfoFromPos(
|
|
79
|
-
this.editor.state.doc,
|
|
80
|
-
this.editor.state.selection.from
|
|
81
|
-
)!;
|
|
82
|
-
|
|
83
|
-
const selectionEmpty =
|
|
84
|
-
this.editor.state.selection.anchor === this.editor.state.selection.head;
|
|
85
|
-
|
|
86
|
-
if (contentType.name !== "listItemContent" || !selectionEmpty) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return this.editor.commands.first(({ state, chain, commands }) => [
|
|
91
|
-
() =>
|
|
92
|
-
// Changes list item block to a text block if both the content is empty.
|
|
93
|
-
commands.command(() => {
|
|
94
|
-
if (node.textContent.length === 0) {
|
|
95
|
-
return commands.BNSetContentType(state.selection.from, {
|
|
96
|
-
name: "textContent",
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return false;
|
|
101
|
-
}),
|
|
102
|
-
|
|
103
|
-
() =>
|
|
104
|
-
// Splits the current block, moving content inside that's after the cursor to a new block of the same type
|
|
105
|
-
// below.
|
|
106
|
-
commands.command(() => {
|
|
107
|
-
if (node.textContent.length > 0) {
|
|
108
|
-
chain()
|
|
109
|
-
.deleteSelection()
|
|
110
|
-
.BNSplitBlock(state.selection.from, true)
|
|
111
|
-
.run();
|
|
112
|
-
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return false;
|
|
117
|
-
}),
|
|
118
|
-
]);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
Enter: handleEnter,
|
|
123
|
-
};
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
addProseMirrorPlugins() {
|
|
127
|
-
return [OrderedListItemIndexPlugin()];
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
parseHTML() {
|
|
131
|
-
return [
|
|
132
|
-
{
|
|
133
|
-
tag: "li",
|
|
134
|
-
getAttrs: (element) => {
|
|
135
|
-
if (typeof element === "string") {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const parent = element.parentElement;
|
|
140
|
-
|
|
141
|
-
if (parent === null) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Case for BlockNote list structure.
|
|
146
|
-
// Gets type of list item (ordered/unordered) based on the block content's listItemType attribute.
|
|
147
|
-
if (parent.getAttribute("data-content-type") === "listItemContent") {
|
|
148
|
-
return { listItemType: parent.getAttribute("data-list-item-type") };
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Case for regular HTML list structure.
|
|
152
|
-
// Gets type of list item (ordered/unordered) based on parent element's tag ("ol"/"ul").
|
|
153
|
-
if (parent.tagName === "UL") {
|
|
154
|
-
return { listItemType: "unordered" };
|
|
155
|
-
}
|
|
156
|
-
if (parent.tagName === "OL") {
|
|
157
|
-
return { listItemType: "ordered" };
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return false;
|
|
161
|
-
},
|
|
162
|
-
node: "block",
|
|
163
|
-
},
|
|
164
|
-
];
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
renderHTML({ HTMLAttributes }) {
|
|
168
|
-
return [
|
|
169
|
-
"div",
|
|
170
|
-
mergeAttributes(HTMLAttributes, {
|
|
171
|
-
class: styles.blockContent,
|
|
172
|
-
"data-content-type": this.name,
|
|
173
|
-
}),
|
|
174
|
-
["li", 0],
|
|
175
|
-
];
|
|
176
|
-
},
|
|
177
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import Paragraph from "@tiptap/extension-paragraph";
|
|
2
|
-
|
|
3
|
-
// Override paragraph to disable "Mod-Alt-0" shortcut throw invalid content for doc type error
|
|
4
|
-
export const FixedParagraph = Paragraph.extend({
|
|
5
|
-
addKeyboardShortcuts: () => {
|
|
6
|
-
return {
|
|
7
|
-
"Mod-Alt-0": () => {
|
|
8
|
-
return false;
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
},
|
|
12
|
-
});
|