@blocknote/core 0.2.3 → 0.3.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 +753 -633
- 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 +19 -28
- package/src/BlockNoteExtensions.ts +10 -0
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +61 -0
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +62 -0
- package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +107 -97
- package/src/extensions/Blocks/nodes/Block.module.css +91 -6
- package/src/extensions/Blocks/nodes/BlockContainer.ts +39 -26
- package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +4 -4
- package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +8 -0
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +80 -35
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +16 -0
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +34 -3
- 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 +14 -32
- 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/shared/plugins/suggestion/SuggestionItem.ts +0 -9
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +191 -228
- package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +1 -1
- 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/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +4 -0
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +4 -9
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +10 -0
- 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/shared/plugins/suggestion/SuggestionItem.d.ts +0 -6
- package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +9 -23
- package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
import { getBlockInfoFromPos } from "../Blocks/helpers/getBlockInfoFromPos";
|
|
3
|
+
|
|
4
|
+
declare module "@tiptap/core" {
|
|
5
|
+
interface Commands<ReturnType> {
|
|
6
|
+
textAlignment: {
|
|
7
|
+
setTextAlignment: (
|
|
8
|
+
textAlignment: "left" | "center" | "right" | "justify"
|
|
9
|
+
) => ReturnType;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const TextAlignmentExtension = Extension.create({
|
|
15
|
+
name: "textAlignment",
|
|
16
|
+
|
|
17
|
+
addGlobalAttributes() {
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
// Attribute is applied to block content instead of container so that child blocks don't inherit the text
|
|
21
|
+
// alignment styling.
|
|
22
|
+
types: ["paragraph", "heading", "bulletListItem", "numberedListItem"],
|
|
23
|
+
attributes: {
|
|
24
|
+
textAlignment: {
|
|
25
|
+
default: "left",
|
|
26
|
+
parseHTML: (element) => element.getAttribute("data-text-alignment"),
|
|
27
|
+
renderHTML: (attributes) =>
|
|
28
|
+
attributes.textAlignment !== "left" && {
|
|
29
|
+
"data-text-alignment": attributes.textAlignment,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
addCommands() {
|
|
38
|
+
return {
|
|
39
|
+
setTextAlignment:
|
|
40
|
+
(textAlignment) =>
|
|
41
|
+
({ state }) => {
|
|
42
|
+
const positionsBeforeSelectedContent = [];
|
|
43
|
+
|
|
44
|
+
const blockInfo = getBlockInfoFromPos(
|
|
45
|
+
state.doc,
|
|
46
|
+
state.selection.from
|
|
47
|
+
);
|
|
48
|
+
if (blockInfo === undefined) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Finds all blockContent nodes that the current selection is in.
|
|
53
|
+
let pos = blockInfo.startPos;
|
|
54
|
+
while (pos < state.selection.to) {
|
|
55
|
+
if (
|
|
56
|
+
state.doc.resolve(pos).node().type.spec.group === "blockContent"
|
|
57
|
+
) {
|
|
58
|
+
positionsBeforeSelectedContent.push(pos - 1);
|
|
59
|
+
|
|
60
|
+
pos += state.doc.resolve(pos).node().nodeSize - 1;
|
|
61
|
+
} else {
|
|
62
|
+
pos += 1;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Sets text alignment for all blockContent nodes that the current selection is in.
|
|
67
|
+
for (const pos of positionsBeforeSelectedContent) {
|
|
68
|
+
state.tr.setNodeAttribute(pos, "textAlignment", textAlignment);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return true;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
import { getBlockInfoFromPos } from "../Blocks/helpers/getBlockInfoFromPos";
|
|
3
|
+
|
|
4
|
+
declare module "@tiptap/core" {
|
|
5
|
+
interface Commands<ReturnType> {
|
|
6
|
+
blockTextColor: {
|
|
7
|
+
setBlockTextColor: (posInBlock: number, color: string) => ReturnType;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const TextColorExtension = Extension.create({
|
|
13
|
+
name: "blockTextColor",
|
|
14
|
+
|
|
15
|
+
addGlobalAttributes() {
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
types: ["blockContainer"],
|
|
19
|
+
attributes: {
|
|
20
|
+
textColor: {
|
|
21
|
+
default: "default",
|
|
22
|
+
parseHTML: (element) =>
|
|
23
|
+
element.hasAttribute("data-text-color")
|
|
24
|
+
? element.getAttribute("data-text-color")
|
|
25
|
+
: "default",
|
|
26
|
+
renderHTML: (attributes) =>
|
|
27
|
+
attributes.textColor !== "default" && {
|
|
28
|
+
"data-text-color": attributes.textColor,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
addCommands() {
|
|
37
|
+
return {
|
|
38
|
+
setBlockTextColor:
|
|
39
|
+
(posInBlock, color) =>
|
|
40
|
+
({ state, view }) => {
|
|
41
|
+
const blockInfo = getBlockInfoFromPos(state.doc, posInBlock);
|
|
42
|
+
if (blockInfo === undefined) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
state.tr.setNodeAttribute(blockInfo.startPos - 1, "textColor", color);
|
|
47
|
+
|
|
48
|
+
view.focus();
|
|
49
|
+
|
|
50
|
+
return true;
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Mark } from "@tiptap/core";
|
|
2
|
+
|
|
3
|
+
declare module "@tiptap/core" {
|
|
4
|
+
interface Commands<ReturnType> {
|
|
5
|
+
textColor: {
|
|
6
|
+
setTextColor: (color: string) => ReturnType;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const TextColorMark = Mark.create({
|
|
12
|
+
name: "textColor",
|
|
13
|
+
|
|
14
|
+
addAttributes() {
|
|
15
|
+
return {
|
|
16
|
+
color: {
|
|
17
|
+
default: undefined,
|
|
18
|
+
parseHTML: (element) => element.getAttribute("data-text-color"),
|
|
19
|
+
renderHTML: (attributes) => ({
|
|
20
|
+
"data-text-color": attributes.color,
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
parseHTML() {
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
tag: "span",
|
|
30
|
+
getAttrs: (element) => {
|
|
31
|
+
if (typeof element === "string") {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (element.hasAttribute("data-text-color")) {
|
|
36
|
+
return { color: element.getAttribute("data-text-color") };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return false;
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
renderHTML({ HTMLAttributes }) {
|
|
46
|
+
return ["span", HTMLAttributes, 0];
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
addCommands() {
|
|
50
|
+
return {
|
|
51
|
+
setTextColor:
|
|
52
|
+
(color) =>
|
|
53
|
+
({ commands }) => {
|
|
54
|
+
if (color !== "default") {
|
|
55
|
+
return commands.setMark(this.name, { color: color });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return commands.unsetMark(this.name);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
});
|
|
@@ -7,15 +7,6 @@ export interface SuggestionItem {
|
|
|
7
7
|
*/
|
|
8
8
|
name: string;
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* The name of the group to which this item belongs
|
|
12
|
-
*/
|
|
13
|
-
groupName: string;
|
|
14
|
-
|
|
15
|
-
hint?: string;
|
|
16
|
-
|
|
17
|
-
shortcut?: string;
|
|
18
|
-
|
|
19
10
|
/**
|
|
20
11
|
* This function matches this item against a query string, the function should return **true** if the item
|
|
21
12
|
* matches the query or **false** otherwise.
|