@blocknote/core 0.3.0 → 0.4.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 +12508 -1276
- 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 +38 -15
- package/src/BlockNoteExtensions.ts +25 -21
- package/src/api/Editor.ts +142 -0
- package/src/api/blockManipulation/blockManipulation.ts +114 -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/nodeConversions.ts +170 -0
- package/src/editor.module.css +7 -1
- package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +7 -1
- package/src/extensions/Blocks/api/blockTypes.ts +85 -0
- package/src/extensions/Blocks/api/cursorPositionTypes.ts +5 -0
- package/src/extensions/Blocks/api/inlineContentTypes.ts +44 -0
- package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +4 -4
- package/src/extensions/Blocks/nodes/BlockContainer.ts +75 -25
- 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/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/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 +73 -0
- package/types/src/api/blockManipulation/blockManipulation.d.ts +6 -0
- package/types/src/api/formatConversions/formatConversions.d.ts +6 -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 +8 -0
- package/types/src/api/removeUnderlinesRehypePlugin.d.ts +6 -0
- package/types/src/api/simplifyBlocksRehypePlugin.d.ts +16 -0
- package/types/src/extensions/Blocks/api/apiTypes.d.ts +18 -0
- package/types/src/extensions/Blocks/api/blockTypes.d.ts +36 -0
- package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +4 -0
- package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +23 -0
- package/types/src/extensions/Blocks/api/styleTypes.d.ts +22 -0
- package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +3 -3
- 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/src/extensions/Blocks/apiTypes.ts +0 -48
|
@@ -33,6 +33,7 @@ export const BulletListItemBlockContent = Node.create({
|
|
|
33
33
|
|
|
34
34
|
parseHTML() {
|
|
35
35
|
return [
|
|
36
|
+
// Case for regular HTML list structure.
|
|
36
37
|
{
|
|
37
38
|
tag: "li",
|
|
38
39
|
getAttrs: (element) => {
|
|
@@ -46,18 +47,35 @@ export const BulletListItemBlockContent = Node.create({
|
|
|
46
47
|
return false;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
if (parent.getAttribute("data-content-type") === "bulletListItem") {
|
|
50
|
+
if (parent.tagName === "UL") {
|
|
51
51
|
return {};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
return false;
|
|
55
|
+
},
|
|
56
|
+
node: "blockContainer",
|
|
57
|
+
},
|
|
58
|
+
// Case for BlockNote list structure.
|
|
59
|
+
{
|
|
60
|
+
tag: "p",
|
|
61
|
+
getAttrs: (element) => {
|
|
62
|
+
if (typeof element === "string") {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const parent = element.parentElement;
|
|
67
|
+
|
|
68
|
+
if (parent === null) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (parent.getAttribute("data-content-type") === "bulletListItem") {
|
|
56
73
|
return {};
|
|
57
74
|
}
|
|
58
75
|
|
|
59
76
|
return false;
|
|
60
77
|
},
|
|
78
|
+
priority: 300,
|
|
61
79
|
node: "blockContainer",
|
|
62
80
|
},
|
|
63
81
|
];
|
|
@@ -70,7 +88,7 @@ export const BulletListItemBlockContent = Node.create({
|
|
|
70
88
|
class: styles.blockContent,
|
|
71
89
|
"data-content-type": this.name,
|
|
72
90
|
}),
|
|
73
|
-
["
|
|
91
|
+
["p", 0],
|
|
74
92
|
];
|
|
75
93
|
},
|
|
76
94
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InputRule, mergeAttributes, Node } from "@tiptap/core";
|
|
2
|
-
import { NumberedListIndexingPlugin } from "./NumberedListIndexingPlugin";
|
|
3
2
|
import styles from "../../../Block.module.css";
|
|
4
3
|
import { handleEnter } from "../ListItemKeyboardShortcuts";
|
|
4
|
+
import { NumberedListIndexingPlugin } from "./NumberedListIndexingPlugin";
|
|
5
5
|
|
|
6
6
|
export const NumberedListItemBlockContent = Node.create({
|
|
7
7
|
name: "numberedListItem",
|
|
@@ -52,6 +52,8 @@ export const NumberedListItemBlockContent = Node.create({
|
|
|
52
52
|
|
|
53
53
|
parseHTML() {
|
|
54
54
|
return [
|
|
55
|
+
// Case for regular HTML list structure.
|
|
56
|
+
// (e.g.: when pasting from other apps)
|
|
55
57
|
{
|
|
56
58
|
tag: "li",
|
|
57
59
|
getAttrs: (element) => {
|
|
@@ -65,18 +67,36 @@ export const NumberedListItemBlockContent = Node.create({
|
|
|
65
67
|
return false;
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
if (parent.getAttribute("data-content-type") === "numberedListItem") {
|
|
70
|
+
if (parent.tagName === "OL") {
|
|
70
71
|
return {};
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
return false;
|
|
75
|
+
},
|
|
76
|
+
node: "blockContainer",
|
|
77
|
+
},
|
|
78
|
+
// Case for BlockNote list structure.
|
|
79
|
+
// (e.g.: when pasting from blocknote)
|
|
80
|
+
{
|
|
81
|
+
tag: "p",
|
|
82
|
+
getAttrs: (element) => {
|
|
83
|
+
if (typeof element === "string") {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const parent = element.parentElement;
|
|
88
|
+
|
|
89
|
+
if (parent === null) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (parent.getAttribute("data-content-type") === "numberedListItem") {
|
|
75
94
|
return {};
|
|
76
95
|
}
|
|
77
96
|
|
|
78
97
|
return false;
|
|
79
98
|
},
|
|
99
|
+
priority: 300,
|
|
80
100
|
node: "blockContainer",
|
|
81
101
|
},
|
|
82
102
|
];
|
|
@@ -89,7 +109,9 @@ export const NumberedListItemBlockContent = Node.create({
|
|
|
89
109
|
class: styles.blockContent,
|
|
90
110
|
"data-content-type": this.name,
|
|
91
111
|
}),
|
|
92
|
-
|
|
112
|
+
// we use a <p> tag, because for <li> tags we'd need to add a <ul> parent for around siblings to be semantically correct,
|
|
113
|
+
// which would be quite cumbersome
|
|
114
|
+
["p", 0],
|
|
93
115
|
];
|
|
94
116
|
},
|
|
95
117
|
});
|
|
@@ -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
|
|
|
4
4
|
export type FormattingToolbarStaticParams = {
|
|
5
5
|
toggleBold: () => void;
|
|
@@ -17,7 +17,7 @@ export type FormattingToolbarStaticParams = {
|
|
|
17
17
|
increaseBlockIndent: () => void;
|
|
18
18
|
decreaseBlockIndent: () => void;
|
|
19
19
|
|
|
20
|
-
updateBlock: (
|
|
20
|
+
updateBlock: (updatedBlock: PartialBlock) => void;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export type FormattingToolbarDynamicParams = {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "@tiptap/core";
|
|
7
7
|
import { EditorState, Plugin, PluginKey } from "prosemirror-state";
|
|
8
8
|
import { EditorView } from "prosemirror-view";
|
|
9
|
-
import { Block,
|
|
9
|
+
import { Block, PartialBlock } from "../Blocks/api/blockTypes";
|
|
10
10
|
import { getBlockInfoFromPos } from "../Blocks/helpers/getBlockInfoFromPos";
|
|
11
11
|
import {
|
|
12
12
|
FormattingToolbar,
|
|
@@ -288,11 +288,11 @@ export class FormattingToolbarView {
|
|
|
288
288
|
this.editor.view.focus();
|
|
289
289
|
this.editor.commands.liftListItem("blockContainer");
|
|
290
290
|
},
|
|
291
|
-
updateBlock: (
|
|
291
|
+
updateBlock: (updatedBlock: PartialBlock) => {
|
|
292
292
|
this.editor.view.focus();
|
|
293
293
|
this.editor.commands.BNUpdateBlock(
|
|
294
294
|
this.editor.state.selection.from,
|
|
295
|
-
|
|
295
|
+
updatedBlock
|
|
296
296
|
);
|
|
297
297
|
},
|
|
298
298
|
};
|
|
@@ -2,11 +2,10 @@ import { Extension } from "@tiptap/core";
|
|
|
2
2
|
import { PluginKey } from "prosemirror-state";
|
|
3
3
|
import { createSuggestionPlugin } from "../../shared/plugins/suggestion/SuggestionPlugin";
|
|
4
4
|
import { SuggestionsMenuFactory } from "../../shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
5
|
-
import defaultCommands from "./defaultCommands";
|
|
6
5
|
import { SlashMenuItem } from "./SlashMenuItem";
|
|
7
6
|
|
|
8
7
|
export type SlashMenuOptions = {
|
|
9
|
-
commands:
|
|
8
|
+
commands: SlashMenuItem[] | undefined;
|
|
10
9
|
slashMenuFactory: SuggestionsMenuFactory<any> | undefined;
|
|
11
10
|
};
|
|
12
11
|
|
|
@@ -17,16 +16,18 @@ export const SlashMenuExtension = Extension.create<SlashMenuOptions>({
|
|
|
17
16
|
|
|
18
17
|
addOptions() {
|
|
19
18
|
return {
|
|
20
|
-
commands:
|
|
21
|
-
slashMenuFactory: undefined,
|
|
19
|
+
commands: undefined,
|
|
20
|
+
slashMenuFactory: undefined,
|
|
22
21
|
};
|
|
23
22
|
},
|
|
24
23
|
|
|
25
24
|
addProseMirrorPlugins() {
|
|
26
|
-
if (!this.options.slashMenuFactory) {
|
|
27
|
-
throw new Error("
|
|
25
|
+
if (!this.options.slashMenuFactory || !this.options.commands) {
|
|
26
|
+
throw new Error("required args not defined for SlashMenuExtension");
|
|
28
27
|
}
|
|
29
28
|
|
|
29
|
+
const commands = this.options.commands;
|
|
30
|
+
|
|
30
31
|
return [
|
|
31
32
|
createSuggestionPlugin<SlashMenuItem>({
|
|
32
33
|
pluginKey: SlashMenuPluginKey,
|
|
@@ -34,12 +35,6 @@ export const SlashMenuExtension = Extension.create<SlashMenuOptions>({
|
|
|
34
35
|
defaultTriggerCharacter: "/",
|
|
35
36
|
suggestionsMenuFactory: this.options.slashMenuFactory!,
|
|
36
37
|
items: (query) => {
|
|
37
|
-
const commands = [];
|
|
38
|
-
|
|
39
|
-
for (const key in this.options.commands) {
|
|
40
|
-
commands.push(this.options.commands[key]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
38
|
return commands.filter((cmd: SlashMenuItem) => cmd.match(query));
|
|
44
39
|
},
|
|
45
40
|
onSelectItem: ({ item, editor, range }) => {
|
|
@@ -17,7 +17,10 @@ export class SlashMenuItem implements SuggestionItem {
|
|
|
17
17
|
constructor(
|
|
18
18
|
public readonly name: string,
|
|
19
19
|
public readonly execute: (editor: Editor, range: Range) => void,
|
|
20
|
-
public readonly aliases: string[] = []
|
|
20
|
+
public readonly aliases: string[] = [],
|
|
21
|
+
public readonly group: string,
|
|
22
|
+
public readonly hint?: string,
|
|
23
|
+
public readonly shortcut?: string
|
|
21
24
|
) {}
|
|
22
25
|
|
|
23
26
|
match(query: string): boolean {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { SlashMenuItem } from "./SlashMenuItem";
|
|
2
1
|
import { Editor, Range } from "@tiptap/core";
|
|
2
|
+
import { formatKeyboardShortcut } from "../../shared/utils";
|
|
3
|
+
import { SlashMenuItem } from "./SlashMenuItem";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* An array containing commands for creating all default blocks.
|
|
6
7
|
*/
|
|
7
|
-
const
|
|
8
|
+
export const defaultSlashCommands: SlashMenuItem[] = [
|
|
8
9
|
// Command for creating a level 1 heading
|
|
9
|
-
|
|
10
|
+
new SlashMenuItem(
|
|
10
11
|
"Heading",
|
|
11
12
|
(editor: Editor, range: Range) => {
|
|
12
13
|
return editor
|
|
@@ -21,11 +22,14 @@ const defaultCommands: { [key: string]: SlashMenuItem } = {
|
|
|
21
22
|
})
|
|
22
23
|
.run();
|
|
23
24
|
},
|
|
24
|
-
["h", "heading1", "h1"]
|
|
25
|
+
["h", "heading1", "h1"],
|
|
26
|
+
"Headings",
|
|
27
|
+
"Used for a top-level heading",
|
|
28
|
+
formatKeyboardShortcut("Mod-Alt-1")
|
|
25
29
|
),
|
|
26
30
|
|
|
27
31
|
// Command for creating a level 2 heading
|
|
28
|
-
|
|
32
|
+
new SlashMenuItem(
|
|
29
33
|
"Heading 2",
|
|
30
34
|
(editor: Editor, range: Range) => {
|
|
31
35
|
return editor
|
|
@@ -40,11 +44,14 @@ const defaultCommands: { [key: string]: SlashMenuItem } = {
|
|
|
40
44
|
})
|
|
41
45
|
.run();
|
|
42
46
|
},
|
|
43
|
-
["h2", "heading2", "subheading"]
|
|
47
|
+
["h2", "heading2", "subheading"],
|
|
48
|
+
"Headings",
|
|
49
|
+
"Used for key sections",
|
|
50
|
+
formatKeyboardShortcut("Mod-Alt-2")
|
|
44
51
|
),
|
|
45
52
|
|
|
46
53
|
// Command for creating a level 3 heading
|
|
47
|
-
|
|
54
|
+
new SlashMenuItem(
|
|
48
55
|
"Heading 3",
|
|
49
56
|
(editor: Editor, range: Range) => {
|
|
50
57
|
return editor
|
|
@@ -59,11 +66,14 @@ const defaultCommands: { [key: string]: SlashMenuItem } = {
|
|
|
59
66
|
})
|
|
60
67
|
.run();
|
|
61
68
|
},
|
|
62
|
-
["h3", "heading3", "subheading"]
|
|
69
|
+
["h3", "heading3", "subheading"],
|
|
70
|
+
"Headings",
|
|
71
|
+
"Used for subsections and group headings",
|
|
72
|
+
formatKeyboardShortcut("Mod-Alt-3")
|
|
63
73
|
),
|
|
64
74
|
|
|
65
75
|
// Command for creating an ordered list
|
|
66
|
-
|
|
76
|
+
new SlashMenuItem(
|
|
67
77
|
"Numbered List",
|
|
68
78
|
(editor: Editor, range: Range) => {
|
|
69
79
|
return editor
|
|
@@ -76,11 +86,14 @@ const defaultCommands: { [key: string]: SlashMenuItem } = {
|
|
|
76
86
|
})
|
|
77
87
|
.run();
|
|
78
88
|
},
|
|
79
|
-
["li", "list", "numberedlist", "numbered list"]
|
|
89
|
+
["li", "list", "numberedlist", "numbered list"],
|
|
90
|
+
"Basic blocks",
|
|
91
|
+
"Used to display a numbered list",
|
|
92
|
+
"Mod-Alt-7"
|
|
80
93
|
),
|
|
81
94
|
|
|
82
95
|
// Command for creating a bullet list
|
|
83
|
-
|
|
96
|
+
new SlashMenuItem(
|
|
84
97
|
"Bullet List",
|
|
85
98
|
(editor: Editor, range: Range) => {
|
|
86
99
|
return editor
|
|
@@ -93,11 +106,14 @@ const defaultCommands: { [key: string]: SlashMenuItem } = {
|
|
|
93
106
|
})
|
|
94
107
|
.run();
|
|
95
108
|
},
|
|
96
|
-
["ul", "list", "bulletlist", "bullet list"]
|
|
109
|
+
["ul", "list", "bulletlist", "bullet list"],
|
|
110
|
+
"Basic blocks",
|
|
111
|
+
"Used to display an unordered list",
|
|
112
|
+
"Mod-Alt-9"
|
|
97
113
|
),
|
|
98
114
|
|
|
99
115
|
// Command for creating a paragraph (pretty useless)
|
|
100
|
-
|
|
116
|
+
new SlashMenuItem(
|
|
101
117
|
"Paragraph",
|
|
102
118
|
(editor: Editor, range: Range) => {
|
|
103
119
|
return editor
|
|
@@ -110,7 +126,10 @@ const defaultCommands: { [key: string]: SlashMenuItem } = {
|
|
|
110
126
|
})
|
|
111
127
|
.run();
|
|
112
128
|
},
|
|
113
|
-
["p"]
|
|
129
|
+
["p"],
|
|
130
|
+
"Basic blocks",
|
|
131
|
+
"Used for the body of your document",
|
|
132
|
+
"Mod-Alt-0"
|
|
114
133
|
),
|
|
115
134
|
|
|
116
135
|
// replaceRangeWithNode(editor, range, node);
|
|
@@ -216,6 +235,4 @@ const defaultCommands: { [key: string]: SlashMenuItem } = {
|
|
|
216
235
|
// TableIcon,
|
|
217
236
|
// "Used to create a simple table"
|
|
218
237
|
// ),
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
export default defaultCommands;
|
|
238
|
+
];
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { defaultSlashCommands } from "./defaultSlashCommands";
|
|
1
2
|
import { SlashMenuExtension } from "./SlashMenuExtension";
|
|
2
|
-
import
|
|
3
|
+
import { SlashMenuItem } from "./SlashMenuItem";
|
|
3
4
|
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export {
|
|
6
|
+
defaultSlashCommands,
|
|
7
|
+
SlashMenuItem as SlashCommand,
|
|
8
|
+
SlashMenuExtension,
|
|
9
|
+
};
|
|
@@ -123,7 +123,7 @@ const UniqueID = Extension.create({
|
|
|
123
123
|
new Plugin({
|
|
124
124
|
key: new PluginKey("uniqueID"),
|
|
125
125
|
appendTransaction: (transactions, oldState, newState) => {
|
|
126
|
-
console.log("appendTransaction");
|
|
126
|
+
// console.log("appendTransaction");
|
|
127
127
|
const docChanges =
|
|
128
128
|
transactions.some((transaction) => transaction.docChanged) &&
|
|
129
129
|
!oldState.doc.eq(newState.doc);
|
package/src/index.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,13 +1,22 @@
|
|
|
1
|
-
import { Editor
|
|
1
|
+
import { Editor } from "@tiptap/core";
|
|
2
|
+
import { Editor as EditorAPI } from "./api/Editor";
|
|
2
3
|
import { UiFactories } from "./BlockNoteExtensions";
|
|
3
|
-
|
|
4
|
+
import { SlashCommand } from "./extensions/SlashMenu";
|
|
5
|
+
export type BlockNoteEditorOptions = {
|
|
4
6
|
enableBlockNoteExtensions: boolean;
|
|
5
7
|
disableHistoryExtension: boolean;
|
|
6
8
|
uiFactories: UiFactories;
|
|
9
|
+
slashCommands: SlashCommand[];
|
|
10
|
+
parentElement: HTMLElement;
|
|
11
|
+
editorDOMAttributes: Record<string, string>;
|
|
12
|
+
onUpdate: () => void;
|
|
13
|
+
onCreate: () => void;
|
|
14
|
+
_tiptapOptions: any;
|
|
7
15
|
};
|
|
8
|
-
export declare class BlockNoteEditor {
|
|
9
|
-
readonly
|
|
16
|
+
export declare class BlockNoteEditor extends EditorAPI {
|
|
17
|
+
readonly _tiptapEditor: Editor & {
|
|
10
18
|
contentComponent: any;
|
|
11
19
|
};
|
|
20
|
+
get domElement(): HTMLDivElement;
|
|
12
21
|
constructor(options?: Partial<BlockNoteEditorOptions>);
|
|
13
22
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Extensions } from "@tiptap/core";
|
|
2
|
+
import { BlockSideMenuFactory } from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
|
|
2
3
|
import { FormattingToolbarFactory } from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
|
|
3
4
|
import { HyperlinkToolbarFactory } from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
|
|
4
|
-
import {
|
|
5
|
-
import { BlockSideMenuFactory } from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
|
|
5
|
+
import { SlashCommand } from "./extensions/SlashMenu";
|
|
6
6
|
import { SlashMenuItem } from "./extensions/SlashMenu/SlashMenuItem";
|
|
7
|
+
import { SuggestionsMenuFactory } from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
7
8
|
export type UiFactories = Partial<{
|
|
8
9
|
formattingToolbarFactory: FormattingToolbarFactory;
|
|
9
10
|
hyperlinkToolbarFactory: HyperlinkToolbarFactory;
|
|
@@ -13,4 +14,7 @@ export type UiFactories = Partial<{
|
|
|
13
14
|
/**
|
|
14
15
|
* Get all the Tiptap extensions BlockNote is configured with by default
|
|
15
16
|
*/
|
|
16
|
-
export declare const getBlockNoteExtensions: (
|
|
17
|
+
export declare const getBlockNoteExtensions: (opts: {
|
|
18
|
+
uiFactories: UiFactories;
|
|
19
|
+
slashCommands: SlashCommand[];
|
|
20
|
+
}) => Extensions;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Editor as TiptapEditor } from "@tiptap/core";
|
|
2
|
+
import { Node } from "prosemirror-model";
|
|
3
|
+
import { Block, 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 list of all top-level blocks that are in the editor.
|
|
11
|
+
*/
|
|
12
|
+
get allBlocks(): Block[];
|
|
13
|
+
/**
|
|
14
|
+
* Gets information regarding the position of the text cursor in the editor.
|
|
15
|
+
*/
|
|
16
|
+
get textCursorPosition(): TextCursorPosition;
|
|
17
|
+
/**
|
|
18
|
+
* Inserts multiple blocks before, after, or nested inside an existing block in the editor.
|
|
19
|
+
* @param blocksToInsert An array of blocks to insert.
|
|
20
|
+
* @param blockToInsertAt An existing block, marking where the new blocks should be inserted at.
|
|
21
|
+
* @param placement Determines whether the blocks should be inserted just before, just after, or nested inside the
|
|
22
|
+
* existing block.
|
|
23
|
+
*/
|
|
24
|
+
insertBlocks(blocksToInsert: PartialBlock[], blockToInsertAt: Block, placement?: "before" | "after" | "nested"): void;
|
|
25
|
+
/**
|
|
26
|
+
* Updates a block in the editor to the given specification.
|
|
27
|
+
* @param blockToUpdate The block that should be updated.
|
|
28
|
+
* @param updatedBlock The specification that the block should be updated to.
|
|
29
|
+
*/
|
|
30
|
+
updateBlock(blockToUpdate: Block, updatedBlock: PartialBlock): void;
|
|
31
|
+
/**
|
|
32
|
+
* Removes multiple blocks from the editor. Throws an error if any of the blocks could not be found.
|
|
33
|
+
* @param blocksToRemove An array of blocks that should be removed.
|
|
34
|
+
*/
|
|
35
|
+
removeBlocks(blocksToRemove: Block[]): void;
|
|
36
|
+
/**
|
|
37
|
+
* Replaces multiple blocks in the editor with several other blocks. If the provided blocks to remove are not adjacent
|
|
38
|
+
* to each other, the new blocks are inserted at the position of the first block in the array. Throws an error if any
|
|
39
|
+
* of the blocks could not be found.
|
|
40
|
+
* @param blocksToRemove An array of blocks that should be replaced.
|
|
41
|
+
* @param blocksToInsert An array of blocks to replace the old ones with.
|
|
42
|
+
*/
|
|
43
|
+
replaceBlocks(blocksToRemove: Block[], blocksToInsert: PartialBlock[]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Executes a callback function whenever the editor's content changes.
|
|
46
|
+
* @param callback The callback function to execute.
|
|
47
|
+
*/
|
|
48
|
+
onContentChange(callback: () => void): void;
|
|
49
|
+
/**
|
|
50
|
+
* Serializes a list of blocks into an HTML string. The output is not the same as what's rendered by the editor, and
|
|
51
|
+
* is simplified in order to better conform to HTML standards. Block structuring elements are removed, children of
|
|
52
|
+
* blocks which aren't list items are lifted out of them, and list items blocks are wrapped in `ul`/`ol` tags.
|
|
53
|
+
* @param blocks The list of blocks to serialize into HTML.
|
|
54
|
+
*/
|
|
55
|
+
blocksToHTML(blocks: Block[]): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a list of blocks from an HTML string.
|
|
58
|
+
* @param htmlString The HTML string to create a list of blocks from.
|
|
59
|
+
*/
|
|
60
|
+
HTMLToBlocks(htmlString: string): Promise<Block[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Serializes a list of blocks into a Markdown string. The output is simplified as Markdown does not support all
|
|
63
|
+
* features of BlockNote. Block structuring elements are removed, children of blocks which aren't list items are
|
|
64
|
+
* lifted out of them, and certain styles are removed.
|
|
65
|
+
* @param blocks The list of blocks to serialize into Markdown.
|
|
66
|
+
*/
|
|
67
|
+
blocksToMarkdown(blocks: Block[]): Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a list of blocks from a Markdown string.
|
|
70
|
+
* @param markdownString The Markdown string to create a list of blocks from.
|
|
71
|
+
*/
|
|
72
|
+
markdownToBlocks(markdownString: string): Promise<Block[]>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Editor } from "@tiptap/core";
|
|
2
|
+
import { Block, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
|
|
3
|
+
export declare function insertBlocks(blocksToInsert: PartialBlock[], blockToInsertAt: Block, placement: "before" | "after" | "nested" | undefined, editor: Editor): void;
|
|
4
|
+
export declare function updateBlock(blockToUpdate: Block, updatedBlock: PartialBlock, editor: Editor): void;
|
|
5
|
+
export declare function removeBlocks(blocksToRemove: Block[], editor: Editor): void;
|
|
6
|
+
export declare function replaceBlocks(blocksToRemove: Block[], blocksToInsert: PartialBlock[], editor: Editor): void;
|
|
@@ -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,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,8 @@
|
|
|
1
|
+
import { Node, Schema } from "prosemirror-model";
|
|
2
|
+
import { Block, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
|
|
3
|
+
export declare function blockToNode(block: PartialBlock, schema: Schema): Node;
|
|
4
|
+
export declare function getNodeById(id: string, doc: Node): {
|
|
5
|
+
node: Node;
|
|
6
|
+
posBeforeNode: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function nodeToBlock(node: Node, blockCache?: WeakMap<Node, Block>): Block;
|
|
@@ -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,18 @@
|
|
|
1
|
+
export type BlockSpec<Type extends string, Props extends Record<string, string>> = {
|
|
2
|
+
id: string;
|
|
3
|
+
children: Block[];
|
|
4
|
+
type: Type;
|
|
5
|
+
props: Props;
|
|
6
|
+
};
|
|
7
|
+
export type BlockSpecUpdate<Spec> = Spec extends BlockSpec<infer Type, infer Props> ? {
|
|
8
|
+
type: Type;
|
|
9
|
+
props?: Partial<Props>;
|
|
10
|
+
} : never;
|
|
11
|
+
export type NumberedListItemBlock = BlockSpec<"numberedListItem", {}>;
|
|
12
|
+
export type BulletListItemBlock = BlockSpec<"bulletListItem", {}>;
|
|
13
|
+
export type HeadingBlock = BlockSpec<"heading", {
|
|
14
|
+
level: "1" | "2" | "3";
|
|
15
|
+
}>;
|
|
16
|
+
export type ParagraphBlock = BlockSpec<"paragraph", {}>;
|
|
17
|
+
export type Block = ParagraphBlock | HeadingBlock | BulletListItemBlock | NumberedListItemBlock;
|
|
18
|
+
export type BlockUpdate = BlockSpecUpdate<Block>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Define the main block types **/
|
|
2
|
+
import { InlineContent } 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 GlobalProps = {
|
|
11
|
+
backgroundColor: string;
|
|
12
|
+
textColor: string;
|
|
13
|
+
textAlignment: "left" | "center" | "right" | "justify";
|
|
14
|
+
};
|
|
15
|
+
export type NumberedListItemBlock = BlockTemplate<"numberedListItem", GlobalProps>;
|
|
16
|
+
export type BulletListItemBlock = BlockTemplate<"bulletListItem", GlobalProps>;
|
|
17
|
+
export type HeadingBlock = BlockTemplate<"heading", GlobalProps & {
|
|
18
|
+
level: "1" | "2" | "3";
|
|
19
|
+
}>;
|
|
20
|
+
export type ParagraphBlock = BlockTemplate<"paragraph", GlobalProps>;
|
|
21
|
+
export type Block = ParagraphBlock | HeadingBlock | BulletListItemBlock | NumberedListItemBlock;
|
|
22
|
+
/** Define "Partial Blocks", these are for updating or creating blocks */
|
|
23
|
+
export type PartialBlockTemplate<B extends Block> = B extends Block ? Partial<Omit<B, "props" | "children" | "content" | "type">> & {
|
|
24
|
+
type: B["type"];
|
|
25
|
+
props?: Partial<B["props"]>;
|
|
26
|
+
content?: string | B["content"];
|
|
27
|
+
children?: PartialBlock[];
|
|
28
|
+
} : never;
|
|
29
|
+
export type PartialBlock = PartialBlockTemplate<Block>;
|
|
30
|
+
export type BlockPropsTemplate<Props> = Props extends Block["props"] ? keyof Props : never;
|
|
31
|
+
/**
|
|
32
|
+
* Expose blockProps. This is currently not very nice, but it's expected this
|
|
33
|
+
* will change anyway once we allow for custom blocks
|
|
34
|
+
*/
|
|
35
|
+
export declare const globalProps: Array<keyof GlobalProps>;
|
|
36
|
+
export declare const blockProps: Record<Block["type"], Set<string>>;
|