@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,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
|
-
});
|