@blocknote/core 0.2.2 → 0.2.4-alpha.7
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 +1061 -936
- 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 +22 -29
- package/src/BlockNoteExtensions.ts +11 -10
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +61 -0
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +62 -0
- package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +112 -106
- 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 +122 -35
- package/src/extensions/Blocks/{BlockAttributes.ts → nodes/BlockAttributes.ts} +0 -0
- package/src/extensions/Blocks/nodes/{Block.ts → BlockContainer.ts} +113 -119
- 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} +7 -12
- package/src/extensions/Blocks/nodes/BlockGroup.ts +4 -4
- package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +9 -1
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +87 -42
- package/src/extensions/{Blocks → DraggableBlocks}/MultipleNodeSelection.ts +0 -0
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +20 -7
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +51 -12
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.ts +1 -1
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +3 -1
- package/src/extensions/Placeholder/PlaceholderExtension.ts +1 -1
- package/src/extensions/SlashMenu/SlashMenuExtension.ts +1 -1
- package/src/extensions/SlashMenu/SlashMenuItem.ts +3 -28
- package/src/extensions/SlashMenu/defaultCommands.tsx +36 -55
- package/src/extensions/SlashMenu/index.ts +1 -6
- package/src/extensions/TextAlignment/TextAlignmentExtension.ts +75 -0
- package/src/extensions/TextColor/TextColorExtension.ts +54 -0
- package/src/extensions/TextColor/TextColorMark.ts +62 -0
- 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/SuggestionItem.ts +0 -9
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +191 -228
- package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +2 -2
- package/types/src/BlockNoteEditor.d.ts +1 -1
- package/types/src/BlockNoteExtensions.d.ts +1 -3
- package/types/src/api/Document.d.ts +5 -0
- package/types/src/extensions/BackgroundColor/BackgroundColorExtension.d.ts +9 -0
- package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +9 -0
- package/types/src/extensions/Blocks/PreviousBlockTypePlugin.d.ts +3 -2
- 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 +9 -5
- package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +1 -1
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +6 -11
- package/types/src/extensions/DraggableBlocks/MultipleNodeSelection.d.ts +24 -0
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +18 -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 +2 -19
- package/types/src/extensions/SlashMenu/defaultSlashCommands.d.ts +5 -0
- package/types/src/extensions/SlashMenu/index.d.ts +1 -2
- package/types/src/extensions/TextAlignment/TextAlignmentExtension.d.ts +9 -0
- package/types/src/extensions/TextColor/TextColorExtension.d.ts +9 -0
- package/types/src/extensions/TextColor/TextColorMark.d.ts +9 -0
- package/types/src/index.d.ts +2 -1
- package/types/src/shared/EditorElement.d.ts +6 -2
- package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +0 -6
- package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +11 -25
- package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +6 -6
- package/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/ListItemContent.ts +0 -177
- package/src/extensions/Paragraph/FixedParagraph.ts +0 -12
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
import { InputRule, mergeAttributes, Node } from "@tiptap/core";
|
|
2
2
|
import styles from "../../Block.module.css";
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
name: "
|
|
6
|
-
attrs?: {
|
|
7
|
-
headingLevel: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const HeadingContent = Node.create({
|
|
12
|
-
name: "headingContent",
|
|
4
|
+
export const HeadingBlockContent = Node.create({
|
|
5
|
+
name: "heading",
|
|
13
6
|
group: "blockContent",
|
|
14
7
|
content: "inline*",
|
|
15
8
|
|
|
16
9
|
addAttributes() {
|
|
17
10
|
return {
|
|
18
|
-
|
|
11
|
+
level: {
|
|
19
12
|
default: "1",
|
|
20
13
|
// instead of "level" attributes, use "data-level"
|
|
21
|
-
parseHTML: (element) => element.getAttribute("data-
|
|
14
|
+
parseHTML: (element) => element.getAttribute("data-level"),
|
|
22
15
|
renderHTML: (attributes) => {
|
|
23
16
|
return {
|
|
24
|
-
"data-
|
|
17
|
+
"data-level": attributes.level,
|
|
25
18
|
};
|
|
26
19
|
},
|
|
27
20
|
},
|
|
@@ -36,10 +29,10 @@ export const HeadingContent = Node.create({
|
|
|
36
29
|
find: new RegExp(`^(#{${parseInt(level)}})\\s$`),
|
|
37
30
|
handler: ({ state, chain, range }) => {
|
|
38
31
|
chain()
|
|
39
|
-
.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
.BNUpdateBlock(state.selection.from, {
|
|
33
|
+
type: "heading",
|
|
34
|
+
props: {
|
|
35
|
+
level: level as "1" | "2" | "3",
|
|
43
36
|
},
|
|
44
37
|
})
|
|
45
38
|
// Removes the "#" character(s) used to set the heading.
|
|
@@ -54,31 +47,30 @@ export const HeadingContent = Node.create({
|
|
|
54
47
|
return [
|
|
55
48
|
{
|
|
56
49
|
tag: "h1",
|
|
57
|
-
attrs: {
|
|
58
|
-
node: "
|
|
50
|
+
attrs: { level: "1" },
|
|
51
|
+
node: "blockContainer",
|
|
59
52
|
},
|
|
60
53
|
{
|
|
61
54
|
tag: "h2",
|
|
62
|
-
attrs: {
|
|
63
|
-
node: "
|
|
55
|
+
attrs: { level: "2" },
|
|
56
|
+
node: "blockContainer",
|
|
64
57
|
},
|
|
65
58
|
{
|
|
66
59
|
tag: "h3",
|
|
67
|
-
attrs: {
|
|
68
|
-
node: "
|
|
60
|
+
attrs: { level: "3" },
|
|
61
|
+
node: "blockContainer",
|
|
69
62
|
},
|
|
70
63
|
];
|
|
71
64
|
},
|
|
72
65
|
|
|
73
66
|
renderHTML({ node, HTMLAttributes }) {
|
|
74
|
-
console.log(node.attrs);
|
|
75
67
|
return [
|
|
76
68
|
"div",
|
|
77
69
|
mergeAttributes(HTMLAttributes, {
|
|
78
70
|
class: styles.blockContent,
|
|
79
71
|
"data-content-type": this.name,
|
|
80
72
|
}),
|
|
81
|
-
["h" + node.attrs
|
|
73
|
+
["h" + node.attrs.level, 0],
|
|
82
74
|
];
|
|
83
75
|
},
|
|
84
76
|
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { InputRule, mergeAttributes, Node } from "@tiptap/core";
|
|
2
|
+
import styles from "../../../Block.module.css";
|
|
3
|
+
import { handleEnter } from "../ListItemKeyboardShortcuts";
|
|
4
|
+
|
|
5
|
+
export const BulletListItemBlockContent = Node.create({
|
|
6
|
+
name: "bulletListItem",
|
|
7
|
+
group: "blockContent",
|
|
8
|
+
content: "inline*",
|
|
9
|
+
|
|
10
|
+
addInputRules() {
|
|
11
|
+
return [
|
|
12
|
+
// Creates an unordered list when starting with "-", "+", or "*".
|
|
13
|
+
new InputRule({
|
|
14
|
+
find: new RegExp(`^[-+*]\\s$`),
|
|
15
|
+
handler: ({ state, chain, range }) => {
|
|
16
|
+
chain()
|
|
17
|
+
.BNUpdateBlock(state.selection.from, {
|
|
18
|
+
type: "bulletListItem",
|
|
19
|
+
props: {},
|
|
20
|
+
})
|
|
21
|
+
// Removes the "-", "+", or "*" character used to set the list.
|
|
22
|
+
.deleteRange({ from: range.from, to: range.to });
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
];
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
addKeyboardShortcuts() {
|
|
29
|
+
return {
|
|
30
|
+
Enter: () => handleEnter(this.editor),
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
parseHTML() {
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
tag: "li",
|
|
38
|
+
getAttrs: (element) => {
|
|
39
|
+
if (typeof element === "string") {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const parent = element.parentElement;
|
|
44
|
+
|
|
45
|
+
if (parent === null) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Case for BlockNote list structure.
|
|
50
|
+
if (parent.getAttribute("data-content-type") === "bulletListItem") {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Case for regular HTML list structure.
|
|
55
|
+
if (parent.tagName === "UL") {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return false;
|
|
60
|
+
},
|
|
61
|
+
node: "blockContainer",
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
renderHTML({ HTMLAttributes }) {
|
|
67
|
+
return [
|
|
68
|
+
"div",
|
|
69
|
+
mergeAttributes(HTMLAttributes, {
|
|
70
|
+
class: styles.blockContent,
|
|
71
|
+
"data-content-type": this.name,
|
|
72
|
+
}),
|
|
73
|
+
["li", 0],
|
|
74
|
+
];
|
|
75
|
+
},
|
|
76
|
+
});
|
package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/ListItemKeyboardShortcuts.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Editor } from "@tiptap/core";
|
|
2
|
+
import { getBlockInfoFromPos } from "../../../helpers/getBlockInfoFromPos";
|
|
3
|
+
|
|
4
|
+
export const handleEnter = (editor: Editor) => {
|
|
5
|
+
const { node, contentType } = getBlockInfoFromPos(
|
|
6
|
+
editor.state.doc,
|
|
7
|
+
editor.state.selection.from
|
|
8
|
+
)!;
|
|
9
|
+
|
|
10
|
+
const selectionEmpty =
|
|
11
|
+
editor.state.selection.anchor === editor.state.selection.head;
|
|
12
|
+
|
|
13
|
+
if (!contentType.name.endsWith("ListItem") || !selectionEmpty) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return editor.commands.first(({ state, chain, commands }) => [
|
|
18
|
+
() =>
|
|
19
|
+
// Changes list item block to a text block if the content is empty.
|
|
20
|
+
commands.command(() => {
|
|
21
|
+
if (node.textContent.length === 0) {
|
|
22
|
+
return commands.BNUpdateBlock(state.selection.from, {
|
|
23
|
+
type: "paragraph",
|
|
24
|
+
props: {},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false;
|
|
29
|
+
}),
|
|
30
|
+
|
|
31
|
+
() =>
|
|
32
|
+
// Splits the current block, moving content inside that's after the cursor to a new block of the same type
|
|
33
|
+
// below.
|
|
34
|
+
commands.command(() => {
|
|
35
|
+
if (node.textContent.length > 0) {
|
|
36
|
+
chain()
|
|
37
|
+
.deleteSelection()
|
|
38
|
+
.BNSplitBlock(state.selection.from, true)
|
|
39
|
+
.run();
|
|
40
|
+
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return false;
|
|
45
|
+
}),
|
|
46
|
+
]);
|
|
47
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Plugin, PluginKey } from "prosemirror-state";
|
|
2
|
-
import { getBlockInfoFromPos } from "
|
|
2
|
+
import { getBlockInfoFromPos } from "../../../../helpers/getBlockInfoFromPos";
|
|
3
3
|
|
|
4
4
|
// ProseMirror Plugin which automatically assigns indices to ordered list items per nesting level.
|
|
5
|
-
const PLUGIN_KEY = new PluginKey(`
|
|
6
|
-
export const
|
|
5
|
+
const PLUGIN_KEY = new PluginKey(`numbered-list-indexing`);
|
|
6
|
+
export const NumberedListIndexingPlugin = () => {
|
|
7
7
|
return new Plugin({
|
|
8
8
|
key: PLUGIN_KEY,
|
|
9
9
|
appendTransaction: (_transactions, _oldState, newState) => {
|
|
10
10
|
const tr = newState.tr;
|
|
11
|
-
tr.setMeta("
|
|
11
|
+
tr.setMeta("numberedListIndexing", true);
|
|
12
12
|
|
|
13
13
|
let modified = false;
|
|
14
14
|
|
|
@@ -17,9 +17,8 @@ export const OrderedListItemIndexPlugin = () => {
|
|
|
17
17
|
// index of the previous list item block.
|
|
18
18
|
newState.doc.descendants((node, pos) => {
|
|
19
19
|
if (
|
|
20
|
-
node.type.name === "
|
|
21
|
-
node.firstChild!.type.name === "
|
|
22
|
-
node.firstChild!.attrs["listItemType"] === "ordered"
|
|
20
|
+
node.type.name === "blockContainer" &&
|
|
21
|
+
node.firstChild!.type.name === "numberedListItem"
|
|
23
22
|
) {
|
|
24
23
|
let newIndex = "1";
|
|
25
24
|
const isFirstBlockInDoc = pos === 1;
|
|
@@ -45,12 +44,10 @@ export const OrderedListItemIndexPlugin = () => {
|
|
|
45
44
|
const prevBlockContentType = prevBlockInfo.contentType;
|
|
46
45
|
|
|
47
46
|
const isPrevBlockOrderedListItem =
|
|
48
|
-
prevBlockContentType.name === "
|
|
49
|
-
prevBlockContentNode.attrs["listItemType"] === "ordered";
|
|
47
|
+
prevBlockContentType.name === "numberedListItem";
|
|
50
48
|
|
|
51
49
|
if (isPrevBlockOrderedListItem) {
|
|
52
|
-
const prevBlockIndex =
|
|
53
|
-
prevBlockContentNode.attrs["listItemIndex"];
|
|
50
|
+
const prevBlockIndex = prevBlockContentNode.attrs["index"];
|
|
54
51
|
|
|
55
52
|
newIndex = (parseInt(prevBlockIndex) + 1).toString();
|
|
56
53
|
}
|
|
@@ -58,14 +55,13 @@ export const OrderedListItemIndexPlugin = () => {
|
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
const contentNode = blockInfo.contentNode;
|
|
61
|
-
const index = contentNode.attrs["
|
|
58
|
+
const index = contentNode.attrs["index"];
|
|
62
59
|
|
|
63
60
|
if (index !== newIndex) {
|
|
64
61
|
modified = true;
|
|
65
62
|
|
|
66
63
|
tr.setNodeMarkup(pos + 1, undefined, {
|
|
67
|
-
|
|
68
|
-
listItemIndex: newIndex,
|
|
64
|
+
index: newIndex,
|
|
69
65
|
});
|
|
70
66
|
}
|
|
71
67
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { InputRule, mergeAttributes, Node } from "@tiptap/core";
|
|
2
|
+
import { NumberedListIndexingPlugin } from "./NumberedListIndexingPlugin";
|
|
3
|
+
import styles from "../../../Block.module.css";
|
|
4
|
+
import { handleEnter } from "../ListItemKeyboardShortcuts";
|
|
5
|
+
|
|
6
|
+
export const NumberedListItemBlockContent = Node.create({
|
|
7
|
+
name: "numberedListItem",
|
|
8
|
+
group: "blockContent",
|
|
9
|
+
content: "inline*",
|
|
10
|
+
|
|
11
|
+
addAttributes() {
|
|
12
|
+
return {
|
|
13
|
+
index: {
|
|
14
|
+
default: null,
|
|
15
|
+
parseHTML: (element) => element.getAttribute("data-index"),
|
|
16
|
+
renderHTML: (attributes) => {
|
|
17
|
+
return {
|
|
18
|
+
"data-index": attributes.index,
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
addInputRules() {
|
|
26
|
+
return [
|
|
27
|
+
// Creates an ordered list when starting with "1.".
|
|
28
|
+
new InputRule({
|
|
29
|
+
find: new RegExp(`^1\\.\\s$`),
|
|
30
|
+
handler: ({ state, chain, range }) => {
|
|
31
|
+
chain()
|
|
32
|
+
.BNUpdateBlock(state.selection.from, {
|
|
33
|
+
type: "numberedListItem",
|
|
34
|
+
props: {},
|
|
35
|
+
})
|
|
36
|
+
// Removes the "1." characters used to set the list.
|
|
37
|
+
.deleteRange({ from: range.from, to: range.to });
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
];
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
addKeyboardShortcuts() {
|
|
44
|
+
return {
|
|
45
|
+
Enter: () => handleEnter(this.editor),
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
addProseMirrorPlugins() {
|
|
50
|
+
return [NumberedListIndexingPlugin()];
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
parseHTML() {
|
|
54
|
+
return [
|
|
55
|
+
{
|
|
56
|
+
tag: "li",
|
|
57
|
+
getAttrs: (element) => {
|
|
58
|
+
if (typeof element === "string") {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const parent = element.parentElement;
|
|
63
|
+
|
|
64
|
+
if (parent === null) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Case for BlockNote list structure.
|
|
69
|
+
if (parent.getAttribute("data-content-type") === "numberedListItem") {
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Case for regular HTML list structure.
|
|
74
|
+
if (parent.tagName === "OL") {
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return false;
|
|
79
|
+
},
|
|
80
|
+
node: "blockContainer",
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
renderHTML({ HTMLAttributes }) {
|
|
86
|
+
return [
|
|
87
|
+
"div",
|
|
88
|
+
mergeAttributes(HTMLAttributes, {
|
|
89
|
+
class: styles.blockContent,
|
|
90
|
+
"data-content-type": this.name,
|
|
91
|
+
}),
|
|
92
|
+
["li", 0],
|
|
93
|
+
];
|
|
94
|
+
},
|
|
95
|
+
});
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { Node } from "@tiptap/core";
|
|
1
|
+
import { mergeAttributes, Node } from "@tiptap/core";
|
|
2
2
|
import styles from "../../Block.module.css";
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
name: "
|
|
6
|
-
attrs?: {};
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const TextContent = Node.create({
|
|
10
|
-
name: "textContent",
|
|
4
|
+
export const ParagraphBlockContent = Node.create({
|
|
5
|
+
name: "paragraph",
|
|
11
6
|
group: "blockContent",
|
|
12
7
|
content: "inline*",
|
|
13
8
|
|
|
@@ -16,18 +11,18 @@ export const TextContent = Node.create({
|
|
|
16
11
|
{
|
|
17
12
|
tag: "p",
|
|
18
13
|
priority: 200,
|
|
19
|
-
node: "
|
|
14
|
+
node: "blockContainer",
|
|
20
15
|
},
|
|
21
16
|
];
|
|
22
17
|
},
|
|
23
18
|
|
|
24
|
-
renderHTML() {
|
|
19
|
+
renderHTML({ HTMLAttributes }) {
|
|
25
20
|
return [
|
|
26
21
|
"div",
|
|
27
|
-
{
|
|
22
|
+
mergeAttributes(HTMLAttributes, {
|
|
28
23
|
class: styles.blockContent,
|
|
29
24
|
"data-content-type": this.name,
|
|
30
|
-
},
|
|
25
|
+
}),
|
|
31
26
|
["p", 0],
|
|
32
27
|
];
|
|
33
28
|
},
|
|
@@ -3,6 +3,8 @@ import styles from "./Block.module.css";
|
|
|
3
3
|
|
|
4
4
|
export const BlockGroup = Node.create({
|
|
5
5
|
name: "blockGroup",
|
|
6
|
+
group: "blockGroup",
|
|
7
|
+
content: "blockContainer+",
|
|
6
8
|
|
|
7
9
|
addOptions() {
|
|
8
10
|
return {
|
|
@@ -10,8 +12,6 @@ export const BlockGroup = Node.create({
|
|
|
10
12
|
};
|
|
11
13
|
},
|
|
12
14
|
|
|
13
|
-
content: "block+",
|
|
14
|
-
|
|
15
15
|
parseHTML() {
|
|
16
16
|
return [
|
|
17
17
|
{
|
|
@@ -21,7 +21,7 @@ export const BlockGroup = Node.create({
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
if (element.getAttribute("data-node-type") === "
|
|
24
|
+
if (element.getAttribute("data-node-type") === "blockGroup") {
|
|
25
25
|
// Null means the element matches, but we don't want to add any attributes to the node.
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
@@ -37,7 +37,7 @@ export const BlockGroup = Node.create({
|
|
|
37
37
|
"div",
|
|
38
38
|
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
|
|
39
39
|
class: styles.blockGroup,
|
|
40
|
-
"data-node-type": "
|
|
40
|
+
"data-node-type": "blockGroup",
|
|
41
41
|
}),
|
|
42
42
|
0,
|
|
43
43
|
];
|
|
@@ -3,14 +3,22 @@ import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
|
3
3
|
export type BlockSideMenuStaticParams = {
|
|
4
4
|
addBlock: () => void;
|
|
5
5
|
deleteBlock: () => void;
|
|
6
|
+
|
|
6
7
|
blockDragStart: (event: DragEvent) => void;
|
|
7
8
|
blockDragEnd: () => void;
|
|
9
|
+
|
|
8
10
|
freezeMenu: () => void;
|
|
9
11
|
unfreezeMenu: () => void;
|
|
12
|
+
|
|
13
|
+
setBlockTextColor: (color: string) => void;
|
|
14
|
+
setBlockBackgroundColor: (color: string) => void;
|
|
10
15
|
};
|
|
11
16
|
|
|
12
17
|
export type BlockSideMenuDynamicParams = {
|
|
13
|
-
|
|
18
|
+
blockTextColor: string;
|
|
19
|
+
blockBackgroundColor: string;
|
|
20
|
+
|
|
21
|
+
referenceRect: DOMRect;
|
|
14
22
|
};
|
|
15
23
|
|
|
16
24
|
export type BlockSideMenu = EditorElement<BlockSideMenuDynamicParams>;
|