@blocknote/core 0.14.1 → 0.14.2
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 +1955 -1856
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +5 -5
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +2 -2
- package/src/api/exporters/markdown/__snapshots__/lists/basic/markdown.md +2 -2
- package/src/api/exporters/markdown/__snapshots__/lists/nested/markdown.md +2 -2
- package/src/api/exporters/markdown/markdownExporter.ts +1 -1
- package/src/api/parsers/acceptedMIMETypes.ts +6 -0
- package/src/api/parsers/fileDropExtension.ts +51 -0
- package/src/api/parsers/handleFileInsertion.ts +99 -0
- package/src/api/parsers/pasteExtension.ts +16 -16
- package/src/editor/BlockNoteEditor.ts +6 -7
- package/src/editor/BlockNoteExtensions.ts +5 -1
- package/src/extensions/FilePanel/FilePanelPlugin.ts +4 -4
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +2 -2
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +12 -4
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +11 -2
- package/src/extensions/SideMenu/SideMenuPlugin.ts +59 -17
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +7 -5
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +1 -1
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +46 -24
- package/src/i18n/locales/ar.ts +87 -128
- package/types/src/api/parsers/acceptedMIMETypes.d.ts +1 -0
- package/types/src/api/parsers/fileDropExtension.d.ts +6 -0
- package/types/src/api/parsers/handleFileInsertion.d.ts +3 -0
- package/types/src/editor/BlockNoteEditor.d.ts +1 -1
- package/types/src/editor/BlockNoteExtensions.d.ts +2 -2
- package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +1 -1
package/dist/webpack-stats.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"builtAt":
|
|
1
|
+
{"builtAt":1719257221461,"assets":[{"name":"blocknote.umd.cjs","size":174820},{"name":"blocknote.umd.cjs.map","size":652657}],"chunks":[{"id":"a1ee98a","entry":true,"initial":true,"files":["blocknote.umd.cjs"],"names":["index"]}],"modules":[{"name":"./src/i18n/locales/ar.ts","size":6398,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/en.ts","size":6512,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/fr.ts","size":7122,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/is.ts","size":6695,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/ja.ts","size":6185,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/ko.ts","size":5879,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/nl.ts","size":6834,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/pl.ts","size":6595,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/pt.ts","size":6785,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/vi.ts","size":6643,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/zh.ts","size":5872,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/index.ts","size":0,"chunks":["a1ee98a"]},{"name":"./src/extensions/UniqueID/UniqueID.ts","size":8518,"chunks":["a1ee98a"]},{"name":"./src/api/getBlockInfoFromPos.ts","size":1691,"chunks":["a1ee98a"]},{"name":"./src/schema/inlineContent/types.ts","size":302,"chunks":["a1ee98a"]},{"name":"./src/util/typescript.ts","size":331,"chunks":["a1ee98a"]},{"name":"./src/api/nodeConversions/nodeConversions.ts","size":11998,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/html/util/sharedHTMLConversion.ts","size":2293,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts","size":2687,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/html/externalHTMLExporter.ts","size":1107,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/html/internalHTMLSerializer.ts","size":704,"chunks":["a1ee98a"]},{"name":"./src/util/browser.ts","size":536,"chunks":["a1ee98a"]},{"name":"./src/blocks/defaultBlockHelpers.ts","size":1731,"chunks":["a1ee98a"]},{"name":"./src/blocks/defaultProps.ts","size":269,"chunks":["a1ee98a"]},{"name":"./src/util/string.ts","size":299,"chunks":["a1ee98a"]},{"name":"./src/schema/blocks/internal.ts","size":3877,"chunks":["a1ee98a"]},{"name":"./src/schema/blocks/createSpec.ts","size":2814,"chunks":["a1ee98a"]},{"name":"./src/schema/inlineContent/internal.ts","size":1357,"chunks":["a1ee98a"]},{"name":"./src/schema/inlineContent/createSpec.ts","size":1627,"chunks":["a1ee98a"]},{"name":"./src/schema/styles/internal.ts","size":1162,"chunks":["a1ee98a"]},{"name":"./src/schema/styles/createSpec.ts","size":1263,"chunks":["a1ee98a"]},{"name":"./src/blocks/FileBlockContent/fileBlockHelpers.ts","size":8593,"chunks":["a1ee98a"]},{"name":"./src/blocks/FileBlockContent/FileBlockContent.ts","size":1939,"chunks":["a1ee98a"]},{"name":"./src/blocks/ImageBlockContent/imageBlockHelpers.ts","size":175,"chunks":["a1ee98a"]},{"name":"./src/blocks/ImageBlockContent/ImageBlockContent.ts","size":3959,"chunks":["a1ee98a"]},{"name":"./src/blocks/VideoBlockContent/videoBlockHelpers.ts","size":175,"chunks":["a1ee98a"]},{"name":"./src/blocks/VideoBlockContent/VideoBlockContent.ts","size":3763,"chunks":["a1ee98a"]},{"name":"./src/blocks/AudioBlockContent/audioBlockHelpers.ts","size":108,"chunks":["a1ee98a"]},{"name":"./src/blocks/AudioBlockContent/AudioBlockContent.ts","size":3741,"chunks":["a1ee98a"]},{"name":"./src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts","size":316,"chunks":["a1ee98a"]},{"name":"./src/extensions/BackgroundColor/BackgroundColorMark.ts","size":946,"chunks":["a1ee98a"]},{"name":"./src/extensions/TextColor/TextColorMark.ts","size":866,"chunks":["a1ee98a"]},{"name":"./src/api/getCurrentBlockContentType.ts","size":192,"chunks":["a1ee98a"]},{"name":"./src/blocks/HeadingBlockContent/HeadingBlockContent.ts","size":3439,"chunks":["a1ee98a"]},{"name":"./src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts","size":1201,"chunks":["a1ee98a"]},{"name":"./src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts","size":3122,"chunks":["a1ee98a"]},{"name":"./src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts","size":1862,"chunks":["a1ee98a"]},{"name":"./src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts","size":3437,"chunks":["a1ee98a"]},{"name":"./src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts","size":6423,"chunks":["a1ee98a"]},{"name":"./src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts","size":1307,"chunks":["a1ee98a"]},{"name":"./src/blocks/TableBlockContent/TableExtension.ts","size":1462,"chunks":["a1ee98a"]},{"name":"./src/blocks/TableBlockContent/TableBlockContent.ts","size":1624,"chunks":["a1ee98a"]},{"name":"./src/blocks/defaultBlocks.ts","size":1123,"chunks":["a1ee98a"]},{"name":"./src/blocks/defaultBlockTypeGuards.ts","size":1331,"chunks":["a1ee98a"]},{"name":"./src/api/nodeUtil.ts","size":548,"chunks":["a1ee98a"]},{"name":"./src/api/blockManipulation/blockManipulation.ts","size":5738,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/markdown/removeUnderlinesRehypePlugin.ts","size":752,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts","size":775,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/markdown/markdownExporter.ts","size":622,"chunks":["a1ee98a"]},{"name":"./src/api/parsers/html/util/nestedLists.ts","size":2174,"chunks":["a1ee98a"]},{"name":"./src/api/parsers/html/parseHTML.ts","size":503,"chunks":["a1ee98a"]},{"name":"./src/api/parsers/markdown/parseMarkdown.ts","size":1054,"chunks":["a1ee98a"]},{"name":"./src/util/EventEmitter.ts","size":744,"chunks":["a1ee98a"]},{"name":"./src/extensions/FilePanel/FilePanelPlugin.ts","size":3480,"chunks":["a1ee98a"]},{"name":"./src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts","size":4355,"chunks":["a1ee98a"]},{"name":"./src/extensions/LinkToolbar/LinkToolbarPlugin.ts","size":7365,"chunks":["a1ee98a"]},{"name":"./src/extensions/SuggestionMenu/SuggestionPlugin.ts","size":7738,"chunks":["a1ee98a"]},{"name":"./src/extensions/SideMenu/MultipleNodeSelection.ts","size":1616,"chunks":["a1ee98a"]},{"name":"./src/extensions/SideMenu/SideMenuPlugin.ts","size":16932,"chunks":["a1ee98a"]},{"name":"./src/extensions/TableHandles/TableHandlesPlugin.ts","size":15292,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/copyExtension.ts","size":2883,"chunks":["a1ee98a"]},{"name":"./src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts","size":6248,"chunks":["a1ee98a"]},{"name":"./src/api/parsers/acceptedMIMETypes.ts","size":91,"chunks":["a1ee98a"]},{"name":"./src/api/parsers/handleFileInsertion.ts","size":1983,"chunks":["a1ee98a"]},{"name":"./src/api/parsers/pasteExtension.ts","size":1244,"chunks":["a1ee98a"]},{"name":"./src/api/parsers/fileDropExtension.ts","size":884,"chunks":["a1ee98a"]},{"name":"./src/extensions/BackgroundColor/BackgroundColorExtension.ts","size":688,"chunks":["a1ee98a"]},{"name":"./src/extensions/TextAlignment/TextAlignmentExtension.ts","size":825,"chunks":["a1ee98a"]},{"name":"./src/extensions/TextColor/TextColorExtension.ts","size":622,"chunks":["a1ee98a"]},{"name":"./src/extensions/TrailingNode/TrailingNodeExtension.ts","size":1594,"chunks":["a1ee98a"]},{"name":"./src/extensions/NonEditableBlocks/NonEditableBlockPlugin.ts","size":1014,"chunks":["a1ee98a"]},{"name":"./src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts","size":4578,"chunks":["a1ee98a"]},{"name":"./src/pm-nodes/BlockContainer.ts","size":18112,"chunks":["a1ee98a"]},{"name":"./src/pm-nodes/BlockGroup.ts","size":1097,"chunks":["a1ee98a"]},{"name":"./src/pm-nodes/Doc.ts","size":90,"chunks":["a1ee98a"]},{"name":"./src/editor/BlockNoteExtensions.ts","size":4243,"chunks":["a1ee98a"]},{"name":"./src/editor/transformPasted.ts","size":1062,"chunks":["a1ee98a"]},{"name":"./src/editor/BlockNoteSchema.ts","size":1044,"chunks":["a1ee98a"]},{"name":"./src/editor/BlockNoteTipTapEditor.ts","size":2655,"chunks":["a1ee98a"]},{"name":"./src/extensions/Placeholder/PlaceholderPlugin.ts","size":2758,"chunks":["a1ee98a"]},{"name":"./src/editor/Block.css","size":17,"chunks":["a1ee98a"]},{"name":"./src/editor/editor.css","size":18,"chunks":["a1ee98a"]},{"name":"./src/editor/BlockNoteEditor.ts","size":23024,"chunks":["a1ee98a"]},{"name":"./src/api/testUtil/partialBlockTestUtil.ts","size":2166,"chunks":["a1ee98a"]},{"name":"./src/index.ts","size":0,"chunks":["a1ee98a"]}]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"homepage": "https://github.com/TypeCellOS/BlockNote",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
|
-
"version": "0.14.
|
|
6
|
+
"version": "0.14.2",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
9
9
|
"types",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"access": "public",
|
|
117
117
|
"registry": "https://registry.npmjs.org/"
|
|
118
118
|
},
|
|
119
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "edfb6e84dbcefc26feb5045bd9a6351b05aefdd8"
|
|
120
120
|
}
|
|
@@ -18,7 +18,7 @@ export function cleanHTMLToMarkdown(cleanHTMLString: string) {
|
|
|
18
18
|
.use(addSpacesToCheckboxes)
|
|
19
19
|
.use(rehypeRemark)
|
|
20
20
|
.use(remarkGfm)
|
|
21
|
-
.use(remarkStringify)
|
|
21
|
+
.use(remarkStringify, { handlers: { text: (node) => node.value } })
|
|
22
22
|
.processSync(cleanHTMLString);
|
|
23
23
|
|
|
24
24
|
return markdownString.value as string;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
import { Plugin } from "prosemirror-state";
|
|
3
|
+
|
|
4
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
5
|
+
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema";
|
|
6
|
+
import { handleFileInsertion } from "./handleFileInsertion";
|
|
7
|
+
import { acceptedMIMETypes } from "./acceptedMIMETypes";
|
|
8
|
+
|
|
9
|
+
export const createDropFileExtension = <
|
|
10
|
+
BSchema extends BlockSchema,
|
|
11
|
+
I extends InlineContentSchema,
|
|
12
|
+
S extends StyleSchema
|
|
13
|
+
>(
|
|
14
|
+
editor: BlockNoteEditor<BSchema, I, S>
|
|
15
|
+
) =>
|
|
16
|
+
Extension.create<{ editor: BlockNoteEditor<BSchema, I, S> }, undefined>({
|
|
17
|
+
name: "dropFile",
|
|
18
|
+
addProseMirrorPlugins() {
|
|
19
|
+
return [
|
|
20
|
+
new Plugin({
|
|
21
|
+
props: {
|
|
22
|
+
handleDOMEvents: {
|
|
23
|
+
drop(_view, event) {
|
|
24
|
+
if (!editor.isEditable) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let format: (typeof acceptedMIMETypes)[number] | null = null;
|
|
29
|
+
for (const mimeType of acceptedMIMETypes) {
|
|
30
|
+
if (event.dataTransfer!.types.includes(mimeType)) {
|
|
31
|
+
format = mimeType;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (format === null) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (format === "Files") {
|
|
40
|
+
handleFileInsertion(event, editor);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return false;
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
];
|
|
50
|
+
},
|
|
51
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
2
|
+
import { PartialBlock } from "../../blocks/defaultBlocks";
|
|
3
|
+
import { insertOrUpdateBlock } from "../../extensions/SuggestionMenu/getDefaultSlashMenuItems";
|
|
4
|
+
import {
|
|
5
|
+
BlockSchema,
|
|
6
|
+
FileBlockConfig,
|
|
7
|
+
InlineContentSchema,
|
|
8
|
+
StyleSchema,
|
|
9
|
+
} from "../../schema";
|
|
10
|
+
import { acceptedMIMETypes } from "./acceptedMIMETypes";
|
|
11
|
+
|
|
12
|
+
function checkMIMETypesMatch(mimeType1: string, mimeType2: string) {
|
|
13
|
+
const types1 = mimeType1.split("/");
|
|
14
|
+
const types2 = mimeType2.split("/");
|
|
15
|
+
|
|
16
|
+
if (types1.length !== 2) {
|
|
17
|
+
throw new Error(`The string ${mimeType1} is not a valid MIME type.`);
|
|
18
|
+
}
|
|
19
|
+
if (types2.length !== 2) {
|
|
20
|
+
throw new Error(`The string ${mimeType2} is not a valid MIME type.`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (types1[1] === "*" || types2[1] === "*") {
|
|
24
|
+
return types1[0] === types2[0];
|
|
25
|
+
}
|
|
26
|
+
if (types1[0] === "*" || types2[0] === "*") {
|
|
27
|
+
return types1[1] === types2[1];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return types1[0] === types2[0] && types1[1] === types2[1];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function handleFileInsertion<
|
|
34
|
+
BSchema extends BlockSchema,
|
|
35
|
+
I extends InlineContentSchema,
|
|
36
|
+
S extends StyleSchema
|
|
37
|
+
>(event: DragEvent | ClipboardEvent, editor: BlockNoteEditor<BSchema, I, S>) {
|
|
38
|
+
if (!editor.uploadFile) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const dataTransfer =
|
|
43
|
+
"dataTransfer" in event ? event.dataTransfer : event.clipboardData;
|
|
44
|
+
if (dataTransfer === null) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let format: (typeof acceptedMIMETypes)[number] | null = null;
|
|
49
|
+
for (const mimeType of acceptedMIMETypes) {
|
|
50
|
+
if (dataTransfer.types.includes(mimeType)) {
|
|
51
|
+
format = mimeType;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (format !== "Files") {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const items = dataTransfer.items;
|
|
60
|
+
if (!items) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
|
|
66
|
+
const fileBlockConfigs = Object.values(editor.schema.blockSchema).filter(
|
|
67
|
+
(blockConfig) => blockConfig.isFileBlock
|
|
68
|
+
) as FileBlockConfig[];
|
|
69
|
+
|
|
70
|
+
for (let i = 0; i < items.length; i++) {
|
|
71
|
+
// Gets file block corresponding to MIME type.
|
|
72
|
+
let fileBlockType = "file";
|
|
73
|
+
for (const fileBlockConfig of fileBlockConfigs) {
|
|
74
|
+
for (const mimeType of fileBlockConfig.fileBlockAcceptMimeTypes || []) {
|
|
75
|
+
if (checkMIMETypesMatch(items[i].type, mimeType)) {
|
|
76
|
+
fileBlockType = fileBlockConfig.type;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const file = items[i].getAsFile();
|
|
83
|
+
if (file) {
|
|
84
|
+
const updateData = await editor.uploadFile(file);
|
|
85
|
+
|
|
86
|
+
if (typeof updateData === "string") {
|
|
87
|
+
const fileBlock = {
|
|
88
|
+
type: fileBlockType,
|
|
89
|
+
props: {
|
|
90
|
+
name: file.name,
|
|
91
|
+
url: updateData,
|
|
92
|
+
},
|
|
93
|
+
} as PartialBlock<BSchema, I, S>;
|
|
94
|
+
|
|
95
|
+
insertOrUpdateBlock(editor, fileBlock);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -3,13 +3,9 @@ import { Plugin } from "prosemirror-state";
|
|
|
3
3
|
|
|
4
4
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
5
5
|
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema";
|
|
6
|
+
import { handleFileInsertion } from "./handleFileInsertion";
|
|
6
7
|
import { nestedListsToBlockNoteStructure } from "./html/util/nestedLists";
|
|
7
|
-
|
|
8
|
-
const acceptedMIMETypes = [
|
|
9
|
-
"blocknote/html",
|
|
10
|
-
"text/html",
|
|
11
|
-
"text/plain",
|
|
12
|
-
] as const;
|
|
8
|
+
import { acceptedMIMETypes } from "./acceptedMIMETypes";
|
|
13
9
|
|
|
14
10
|
export const createPasteFromClipboardExtension = <
|
|
15
11
|
BSchema extends BlockSchema,
|
|
@@ -33,26 +29,30 @@ export const createPasteFromClipboardExtension = <
|
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
let format: (typeof acceptedMIMETypes)[number] | null = null;
|
|
36
|
-
|
|
37
32
|
for (const mimeType of acceptedMIMETypes) {
|
|
38
33
|
if (event.clipboardData!.types.includes(mimeType)) {
|
|
39
34
|
format = mimeType;
|
|
40
35
|
break;
|
|
41
36
|
}
|
|
42
37
|
}
|
|
38
|
+
if (format === null) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
43
41
|
|
|
44
|
-
if (format
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
data.trim()
|
|
49
|
-
);
|
|
42
|
+
if (format === "Files") {
|
|
43
|
+
handleFileInsertion(event, editor);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
let data = event.clipboardData!.getData(format);
|
|
48
|
+
|
|
49
|
+
if (format === "text/html") {
|
|
50
|
+
const htmlNode = nestedListsToBlockNoteStructure(data.trim());
|
|
51
|
+
data = htmlNode.innerHTML;
|
|
54
52
|
}
|
|
55
53
|
|
|
54
|
+
editor._tiptapEditor.view.pasteHTML(data);
|
|
55
|
+
|
|
56
56
|
return true;
|
|
57
57
|
},
|
|
58
58
|
},
|
|
@@ -73,9 +73,7 @@ export type BlockNoteEditorOptions<
|
|
|
73
73
|
ISchema extends InlineContentSchema,
|
|
74
74
|
SSchema extends StyleSchema
|
|
75
75
|
> = {
|
|
76
|
-
|
|
77
|
-
enableBlockNoteExtensions: boolean;
|
|
78
|
-
|
|
76
|
+
disableExtensions: string[];
|
|
79
77
|
/**
|
|
80
78
|
* A dictionary object containing translations for the editor.
|
|
81
79
|
*/
|
|
@@ -280,6 +278,7 @@ export class BlockNoteEditor<
|
|
|
280
278
|
inlineContentSpecs: this.schema.inlineContentSpecs,
|
|
281
279
|
collaboration: newOptions.collaboration,
|
|
282
280
|
trailingBlock: newOptions.trailingBlock,
|
|
281
|
+
disableExtensions: newOptions.disableExtensions,
|
|
283
282
|
});
|
|
284
283
|
|
|
285
284
|
const blockNoteUIExtension = Extension.create({
|
|
@@ -336,10 +335,10 @@ export class BlockNoteEditor<
|
|
|
336
335
|
...blockNoteTipTapOptions,
|
|
337
336
|
...newOptions._tiptapOptions,
|
|
338
337
|
content: initialContent,
|
|
339
|
-
extensions:
|
|
340
|
-
newOptions.
|
|
341
|
-
|
|
342
|
-
|
|
338
|
+
extensions: [
|
|
339
|
+
...(newOptions._tiptapOptions?.extensions || []),
|
|
340
|
+
...extensions,
|
|
341
|
+
],
|
|
343
342
|
editorProps: {
|
|
344
343
|
...newOptions._tiptapOptions?.editorProps,
|
|
345
344
|
attributes: {
|
|
@@ -13,6 +13,7 @@ import { Text } from "@tiptap/extension-text";
|
|
|
13
13
|
import * as Y from "yjs";
|
|
14
14
|
import { createCopyToClipboardExtension } from "../api/exporters/copyExtension";
|
|
15
15
|
import { createPasteFromClipboardExtension } from "../api/parsers/pasteExtension";
|
|
16
|
+
import { createDropFileExtension } from "../api/parsers/fileDropExtension";
|
|
16
17
|
import { BackgroundColorExtension } from "../extensions/BackgroundColor/BackgroundColorExtension";
|
|
17
18
|
import { TextAlignmentExtension } from "../extensions/TextAlignment/TextAlignmentExtension";
|
|
18
19
|
import { TextColorExtension } from "../extensions/TextColor/TextColorExtension";
|
|
@@ -53,6 +54,7 @@ export const getBlockNoteExtensions = <
|
|
|
53
54
|
provider: any;
|
|
54
55
|
renderCursor?: (user: any) => HTMLElement;
|
|
55
56
|
};
|
|
57
|
+
disableExtensions: string[] | undefined;
|
|
56
58
|
}) => {
|
|
57
59
|
const ret: Extensions = [
|
|
58
60
|
extensions.ClipboardTextSerializer,
|
|
@@ -145,6 +147,7 @@ export const getBlockNoteExtensions = <
|
|
|
145
147
|
}),
|
|
146
148
|
createCopyToClipboardExtension(opts.editor),
|
|
147
149
|
createPasteFromClipboardExtension(opts.editor),
|
|
150
|
+
createDropFileExtension(opts.editor),
|
|
148
151
|
|
|
149
152
|
Dropcursor.configure({ width: 5, color: "#ddeeff" }),
|
|
150
153
|
// This needs to be at the bottom of this list, because Key events (such as enter, when selecting a /command),
|
|
@@ -193,5 +196,6 @@ export const getBlockNoteExtensions = <
|
|
|
193
196
|
ret.push(History);
|
|
194
197
|
}
|
|
195
198
|
|
|
196
|
-
|
|
199
|
+
const disableExtensions: string[] = opts.disableExtensions || [];
|
|
200
|
+
return ret.filter(ex => !disableExtensions.includes(ex.name));
|
|
197
201
|
};
|
|
@@ -49,7 +49,7 @@ export class FilePanelView<I extends InlineContentSchema, S extends StyleSchema>
|
|
|
49
49
|
// Setting capture=true ensures that any parent container of the editor that
|
|
50
50
|
// gets scrolled will trigger the scroll event. Scroll events do not bubble
|
|
51
51
|
// and so won't propagate to the document by default.
|
|
52
|
-
|
|
52
|
+
pmView.root.addEventListener("scroll", this.scrollHandler, true);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
mouseDownHandler = () => {
|
|
@@ -69,7 +69,7 @@ export class FilePanelView<I extends InlineContentSchema, S extends StyleSchema>
|
|
|
69
69
|
|
|
70
70
|
scrollHandler = () => {
|
|
71
71
|
if (this.state?.show) {
|
|
72
|
-
const blockElement =
|
|
72
|
+
const blockElement = this.pmView.root.querySelector(
|
|
73
73
|
`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`
|
|
74
74
|
)!;
|
|
75
75
|
|
|
@@ -84,7 +84,7 @@ export class FilePanelView<I extends InlineContentSchema, S extends StyleSchema>
|
|
|
84
84
|
} = this.pluginKey.getState(view.state);
|
|
85
85
|
|
|
86
86
|
if (!this.state?.show && pluginState.block && this.editor.isEditable) {
|
|
87
|
-
const blockElement =
|
|
87
|
+
const blockElement = this.pmView.root.querySelector(
|
|
88
88
|
`[data-node-type="blockContainer"][data-id="${pluginState.block.id}"]`
|
|
89
89
|
)!;
|
|
90
90
|
|
|
@@ -124,7 +124,7 @@ export class FilePanelView<I extends InlineContentSchema, S extends StyleSchema>
|
|
|
124
124
|
|
|
125
125
|
this.pmView.dom.removeEventListener("dragstart", this.dragstartHandler);
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
this.pmView.root.removeEventListener("scroll", this.scrollHandler, true);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -62,7 +62,7 @@ export class FormattingToolbarView implements PluginView {
|
|
|
62
62
|
// Setting capture=true ensures that any parent container of the editor that
|
|
63
63
|
// gets scrolled will trigger the scroll event. Scroll events do not bubble
|
|
64
64
|
// and so won't propagate to the document by default.
|
|
65
|
-
|
|
65
|
+
pmView.root.addEventListener("scroll", this.scrollHandler, true);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
viewMousedownHandler = () => {
|
|
@@ -147,7 +147,7 @@ export class FormattingToolbarView implements PluginView {
|
|
|
147
147
|
this.pmView.dom.removeEventListener("dragstart", this.dragHandler);
|
|
148
148
|
this.pmView.dom.removeEventListener("dragover", this.dragHandler);
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
this.pmView.root.removeEventListener("scroll", this.scrollHandler, true);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
closeMenu = () => {
|
|
@@ -61,12 +61,16 @@ class LinkToolbarView implements PluginView {
|
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
this.pmView.dom.addEventListener("mouseover", this.mouseOverHandler);
|
|
64
|
-
|
|
64
|
+
this.pmView.root.addEventListener(
|
|
65
|
+
"click",
|
|
66
|
+
this.clickHandler as EventListener,
|
|
67
|
+
true
|
|
68
|
+
);
|
|
65
69
|
|
|
66
70
|
// Setting capture=true ensures that any parent container of the editor that
|
|
67
71
|
// gets scrolled will trigger the scroll event. Scroll events do not bubble
|
|
68
72
|
// and so won't propagate to the document by default.
|
|
69
|
-
|
|
73
|
+
this.pmView.root.addEventListener("scroll", this.scrollHandler, true);
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
mouseOverHandler = (event: MouseEvent) => {
|
|
@@ -271,8 +275,12 @@ class LinkToolbarView implements PluginView {
|
|
|
271
275
|
|
|
272
276
|
destroy() {
|
|
273
277
|
this.pmView.dom.removeEventListener("mouseover", this.mouseOverHandler);
|
|
274
|
-
|
|
275
|
-
|
|
278
|
+
this.pmView.root.removeEventListener("scroll", this.scrollHandler, true);
|
|
279
|
+
this.pmView.root.removeEventListener(
|
|
280
|
+
"click",
|
|
281
|
+
this.clickHandler as EventListener,
|
|
282
|
+
true
|
|
283
|
+
);
|
|
276
284
|
}
|
|
277
285
|
}
|
|
278
286
|
|
|
@@ -16,7 +16,12 @@ export const PlaceholderPlugin = (
|
|
|
16
16
|
if (nonce) {
|
|
17
17
|
styleEl.setAttribute("nonce", nonce);
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
if (editor._tiptapEditor.view.root instanceof ShadowRoot) {
|
|
20
|
+
editor._tiptapEditor.view.root.append(styleEl);
|
|
21
|
+
} else {
|
|
22
|
+
editor._tiptapEditor.view.root.head.appendChild(styleEl);
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
const styleSheet = styleEl.sheet!;
|
|
21
26
|
|
|
22
27
|
const getBaseSelector = (additionalSelectors = "") =>
|
|
@@ -62,7 +67,11 @@ export const PlaceholderPlugin = (
|
|
|
62
67
|
|
|
63
68
|
return {
|
|
64
69
|
destroy: () => {
|
|
65
|
-
|
|
70
|
+
if (editor._tiptapEditor.view.root instanceof ShadowRoot) {
|
|
71
|
+
editor._tiptapEditor.view.root.removeChild(styleEl);
|
|
72
|
+
} else {
|
|
73
|
+
editor._tiptapEditor.view.root.head.removeChild(styleEl);
|
|
74
|
+
}
|
|
66
75
|
},
|
|
67
76
|
};
|
|
68
77
|
},
|
|
@@ -128,7 +128,7 @@ function setDragImage(view: EditorView, from: number, to = from) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// dataTransfer.setDragImage(element) only works if element is attached to the DOM.
|
|
131
|
-
unsetDragImage();
|
|
131
|
+
unsetDragImage(view.root);
|
|
132
132
|
dragImageElement = parentClone;
|
|
133
133
|
|
|
134
134
|
// TODO: This is hacky, need a better way of assigning classes to the editor so that they can also be applied to the
|
|
@@ -146,12 +146,21 @@ function setDragImage(view: EditorView, from: number, to = from) {
|
|
|
146
146
|
dragImageElement.className =
|
|
147
147
|
dragImageElement.className + " bn-drag-preview " + inheritedClasses;
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
if (view.root instanceof ShadowRoot) {
|
|
150
|
+
view.root.appendChild(dragImageElement);
|
|
151
|
+
} else {
|
|
152
|
+
view.root.body.appendChild(dragImageElement);
|
|
153
|
+
}
|
|
150
154
|
}
|
|
151
155
|
|
|
152
|
-
function unsetDragImage() {
|
|
156
|
+
function unsetDragImage(rootEl: Document | ShadowRoot) {
|
|
153
157
|
if (dragImageElement !== undefined) {
|
|
154
|
-
|
|
158
|
+
if (rootEl instanceof ShadowRoot) {
|
|
159
|
+
rootEl.removeChild(dragImageElement);
|
|
160
|
+
} else {
|
|
161
|
+
rootEl.body.appendChild(dragImageElement);
|
|
162
|
+
}
|
|
163
|
+
|
|
155
164
|
dragImageElement = undefined;
|
|
156
165
|
}
|
|
157
166
|
}
|
|
@@ -177,7 +186,7 @@ function dragStart<
|
|
|
177
186
|
top: e.clientY,
|
|
178
187
|
};
|
|
179
188
|
|
|
180
|
-
const elements =
|
|
189
|
+
const elements = view.root.elementsFromPoint(coords.left, coords.top);
|
|
181
190
|
let blockEl = undefined;
|
|
182
191
|
|
|
183
192
|
for (const element of elements) {
|
|
@@ -283,22 +292,37 @@ export class SideMenuView<
|
|
|
283
292
|
this.pmView.dom.firstChild! as HTMLElement
|
|
284
293
|
).getBoundingClientRect().x;
|
|
285
294
|
|
|
286
|
-
|
|
287
|
-
|
|
295
|
+
this.pmView.root.addEventListener(
|
|
296
|
+
"drop",
|
|
297
|
+
this.onDrop as EventListener,
|
|
298
|
+
true
|
|
299
|
+
);
|
|
300
|
+
this.pmView.root.addEventListener(
|
|
301
|
+
"dragover",
|
|
302
|
+
this.onDragOver as EventListener
|
|
303
|
+
);
|
|
288
304
|
this.pmView.dom.addEventListener("dragstart", this.onDragStart);
|
|
289
305
|
|
|
290
306
|
// Shows or updates menu position whenever the cursor moves, if the menu isn't frozen.
|
|
291
|
-
|
|
307
|
+
this.pmView.root.addEventListener(
|
|
308
|
+
"mousemove",
|
|
309
|
+
this.onMouseMove as EventListener,
|
|
310
|
+
true
|
|
311
|
+
);
|
|
292
312
|
|
|
293
313
|
// Unfreezes the menu whenever the user clicks.
|
|
294
314
|
this.pmView.dom.addEventListener("mousedown", this.onMouseDown);
|
|
295
315
|
// Hides and unfreezes the menu whenever the user presses a key.
|
|
296
|
-
|
|
316
|
+
this.pmView.root.addEventListener(
|
|
317
|
+
"keydown",
|
|
318
|
+
this.onKeyDown as EventListener,
|
|
319
|
+
true
|
|
320
|
+
);
|
|
297
321
|
|
|
298
322
|
// Setting capture=true ensures that any parent container of the editor that
|
|
299
323
|
// gets scrolled will trigger the scroll event. Scroll events do not bubble
|
|
300
324
|
// and so won't propagate to the document by default.
|
|
301
|
-
|
|
325
|
+
this.pmView.root.addEventListener("scroll", this.onScroll, true);
|
|
302
326
|
}
|
|
303
327
|
|
|
304
328
|
updateState = () => {
|
|
@@ -322,7 +346,10 @@ export class SideMenuView<
|
|
|
322
346
|
top: this.mousePos.y,
|
|
323
347
|
};
|
|
324
348
|
|
|
325
|
-
const elements =
|
|
349
|
+
const elements = this.pmView.root.elementsFromPoint(
|
|
350
|
+
coords.left,
|
|
351
|
+
coords.top
|
|
352
|
+
);
|
|
326
353
|
let block = undefined;
|
|
327
354
|
|
|
328
355
|
for (const element of elements) {
|
|
@@ -553,13 +580,28 @@ export class SideMenuView<
|
|
|
553
580
|
this.state.show = false;
|
|
554
581
|
this.emitUpdate(this.state);
|
|
555
582
|
}
|
|
556
|
-
|
|
557
|
-
|
|
583
|
+
this.pmView.root.removeEventListener(
|
|
584
|
+
"mousemove",
|
|
585
|
+
this.onMouseMove as EventListener,
|
|
586
|
+
true
|
|
587
|
+
);
|
|
588
|
+
this.pmView.root.removeEventListener(
|
|
589
|
+
"dragover",
|
|
590
|
+
this.onDragOver as EventListener
|
|
591
|
+
);
|
|
558
592
|
this.pmView.dom.removeEventListener("dragstart", this.onDragStart);
|
|
559
|
-
|
|
560
|
-
|
|
593
|
+
this.pmView.root.removeEventListener(
|
|
594
|
+
"drop",
|
|
595
|
+
this.onDrop as EventListener,
|
|
596
|
+
true
|
|
597
|
+
);
|
|
598
|
+
this.pmView.root.removeEventListener("scroll", this.onScroll, true);
|
|
561
599
|
this.pmView.dom.removeEventListener("mousedown", this.onMouseDown);
|
|
562
|
-
|
|
600
|
+
this.pmView.root.removeEventListener(
|
|
601
|
+
"keydown",
|
|
602
|
+
this.onKeyDown as EventListener,
|
|
603
|
+
true
|
|
604
|
+
);
|
|
563
605
|
}
|
|
564
606
|
|
|
565
607
|
addBlock() {
|
|
@@ -665,7 +707,7 @@ export class SideMenuProsemirrorPlugin<
|
|
|
665
707
|
/**
|
|
666
708
|
* Handles drag & drop events for blocks.
|
|
667
709
|
*/
|
|
668
|
-
blockDragEnd = () => unsetDragImage();
|
|
710
|
+
blockDragEnd = () => unsetDragImage(this.editor.prosemirrorView.root);
|
|
669
711
|
/**
|
|
670
712
|
* Freezes the side menu. When frozen, the side menu will stay
|
|
671
713
|
* attached to the same block regardless of which block is hovered by the
|