@blocknote/core 0.15.5 → 0.15.6
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 +1842 -1783
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +6 -6
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +2 -2
- package/src/api/exporters/copyExtension.ts +25 -21
- package/src/api/exporters/html/externalHTMLExporter.ts +15 -6
- package/src/api/exporters/html/htmlConversion.test.ts +8 -3
- package/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts +11 -3
- package/src/api/exporters/markdown/markdownExporter.ts +25 -12
- package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +12 -2
- package/src/api/parsers/html/util/nestedLists.test.ts +8 -8
- package/src/api/parsers/markdown/parseMarkdown.ts +11 -12
- package/src/editor/BlockNoteEditor.ts +16 -3
- package/src/extensions/SideMenu/SideMenuPlugin.ts +2 -0
- package/src/index.ts +7 -6
- package/src/util/esmDependencies.ts +51 -0
- package/types/src/api/exporters/markdown/markdownExporter.d.ts +1 -1
- package/types/src/editor/BlockNoteEditor.d.ts +1 -1
- package/types/src/index.d.ts +7 -6
- package/types/src/util/esmDependencies.d.ts +24 -0
package/dist/webpack-stats.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"builtAt":
|
|
1
|
+
{"builtAt":1724890687204,"assets":[{"name":"blocknote.umd.cjs","size":196895},{"name":"blocknote.umd.cjs.map","size":710888}],"chunks":[{"id":"a1ee98a","entry":true,"initial":true,"files":["blocknote.umd.cjs"],"names":["index"]}],"modules":[{"name":"./src/i18n/locales/ar.ts","size":6582,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/de.ts","size":7183,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/en.ts","size":6664,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/es.ts","size":6796,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/fr.ts","size":7294,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/is.ts","size":6876,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/ja.ts","size":6323,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/ko.ts","size":6146,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/nl.ts","size":7079,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/pl.ts","size":6768,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/pt.ts","size":6965,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/ru.ts","size":7638,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/vi.ts","size":6927,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/zh.ts","size":6093,"chunks":["a1ee98a"]},{"name":"./src/i18n/locales/index.ts","size":0,"chunks":["a1ee98a"]},{"name":"./src/util/esmDependencies.ts","size":820,"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":2311,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts","size":3283,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/html/externalHTMLExporter.ts","size":1320,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/html/internalHTMLSerializer.ts","size":758,"chunks":["a1ee98a"]},{"name":"./src/api/getCurrentBlockContentType.ts","size":192,"chunks":["a1ee98a"]},{"name":"./src/util/browser.ts","size":536,"chunks":["a1ee98a"]},{"name":"./src/blocks/defaultBlockHelpers.ts","size":1691,"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":8574,"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/FileBlockContent.ts","size":1939,"chunks":["a1ee98a"]},{"name":"./src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts","size":316,"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/extensions/BackgroundColor/BackgroundColorMark.ts","size":946,"chunks":["a1ee98a"]},{"name":"./src/extensions/TextColor/TextColorMark.ts","size":866,"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":1580,"chunks":["a1ee98a"]},{"name":"./src/api/nodeUtil.ts","size":548,"chunks":["a1ee98a"]},{"name":"./src/api/blockManipulation/blockManipulation.ts","size":5664,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/markdown/removeUnderlinesRehypePlugin.ts","size":752,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts","size":962,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/markdown/markdownExporter.ts","size":837,"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":1104,"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":5062,"chunks":["a1ee98a"]},{"name":"./src/extensions/LinkToolbar/LinkToolbarPlugin.ts","size":7365,"chunks":["a1ee98a"]},{"name":"./src/extensions/SideMenu/MultipleNodeSelection.ts","size":1616,"chunks":["a1ee98a"]},{"name":"./src/extensions/SideMenu/SideMenuPlugin.ts","size":17152,"chunks":["a1ee98a"]},{"name":"./src/extensions/SuggestionMenu/SuggestionPlugin.ts","size":7719,"chunks":["a1ee98a"]},{"name":"./src/extensions/TableHandles/TableHandlesPlugin.ts","size":15235,"chunks":["a1ee98a"]},{"name":"./src/api/exporters/copyExtension.ts","size":3132,"chunks":["a1ee98a"]},{"name":"./src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts","size":6319,"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":791,"chunks":["a1ee98a"]},{"name":"./src/extensions/TextAlignment/TextAlignmentExtension.ts","size":928,"chunks":["a1ee98a"]},{"name":"./src/extensions/TextColor/TextColorExtension.ts","size":725,"chunks":["a1ee98a"]},{"name":"./src/extensions/TrailingNode/TrailingNodeExtension.ts","size":1594,"chunks":["a1ee98a"]},{"name":"./src/extensions/NonEditableBlocks/NonEditableBlockPlugin.ts","size":1086,"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":2823,"chunks":["a1ee98a"]},{"name":"./src/extensions/Placeholder/PlaceholderPlugin.ts","size":2758,"chunks":["a1ee98a"]},{"name":"./src/style.css","size":0,"chunks":["a1ee98a"]},{"name":"./src/editor/BlockNoteEditor.ts","size":26591,"chunks":["a1ee98a"]},{"name":"./src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts","size":700,"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.15.
|
|
6
|
+
"version": "0.15.6",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
9
9
|
"types",
|
|
@@ -119,5 +119,5 @@
|
|
|
119
119
|
"access": "public",
|
|
120
120
|
"registry": "https://registry.npmjs.org/"
|
|
121
121
|
},
|
|
122
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "570cdb49eb6111c74f3698898dd2278b16e90d9c"
|
|
123
123
|
}
|
|
@@ -5,25 +5,26 @@ import { NodeSelection, Plugin } from "prosemirror-state";
|
|
|
5
5
|
import { EditorView } from "prosemirror-view";
|
|
6
6
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
7
7
|
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema";
|
|
8
|
+
import { initializeESMDependencies } from "../../util/esmDependencies";
|
|
8
9
|
import { createExternalHTMLExporter } from "./html/externalHTMLExporter";
|
|
9
10
|
import { createInternalHTMLSerializer } from "./html/internalHTMLSerializer";
|
|
10
11
|
import { cleanHTMLToMarkdown } from "./markdown/markdownExporter";
|
|
11
12
|
|
|
12
|
-
function selectedFragmentToHTML<
|
|
13
|
+
async function selectedFragmentToHTML<
|
|
13
14
|
BSchema extends BlockSchema,
|
|
14
15
|
I extends InlineContentSchema,
|
|
15
16
|
S extends StyleSchema
|
|
16
17
|
>(
|
|
17
18
|
view: EditorView,
|
|
18
19
|
editor: BlockNoteEditor<BSchema, I, S>
|
|
19
|
-
): {
|
|
20
|
+
): Promise<{
|
|
20
21
|
internalHTML: string;
|
|
21
22
|
externalHTML: string;
|
|
22
23
|
plainText: string;
|
|
23
|
-
} {
|
|
24
|
+
}> {
|
|
24
25
|
const selectedFragment = view.state.selection.content().content;
|
|
25
26
|
|
|
26
|
-
const internalHTMLSerializer = createInternalHTMLSerializer(
|
|
27
|
+
const internalHTMLSerializer = await createInternalHTMLSerializer(
|
|
27
28
|
view.state.schema,
|
|
28
29
|
editor
|
|
29
30
|
);
|
|
@@ -32,6 +33,7 @@ function selectedFragmentToHTML<
|
|
|
32
33
|
{}
|
|
33
34
|
);
|
|
34
35
|
|
|
36
|
+
await initializeESMDependencies();
|
|
35
37
|
const externalHTMLExporter = createExternalHTMLExporter(
|
|
36
38
|
view.state.schema,
|
|
37
39
|
editor
|
|
@@ -41,7 +43,7 @@ function selectedFragmentToHTML<
|
|
|
41
43
|
{}
|
|
42
44
|
);
|
|
43
45
|
|
|
44
|
-
const plainText = cleanHTMLToMarkdown(externalHTML);
|
|
46
|
+
const plainText = await cleanHTMLToMarkdown(externalHTML);
|
|
45
47
|
|
|
46
48
|
return { internalHTML, externalHTML, plainText };
|
|
47
49
|
}
|
|
@@ -83,15 +85,16 @@ export const createCopyToClipboardExtension = <
|
|
|
83
85
|
);
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// TODO: Writing to other MIME types not working in Safari for
|
|
90
|
-
// some reason.
|
|
91
|
-
event.clipboardData!.setData("blocknote/html", internalHTML);
|
|
92
|
-
event.clipboardData!.setData("text/html", externalHTML);
|
|
93
|
-
event.clipboardData!.setData("text/plain", plainText);
|
|
88
|
+
(async () => {
|
|
89
|
+
const { internalHTML, externalHTML, plainText } =
|
|
90
|
+
await selectedFragmentToHTML(view, editor);
|
|
94
91
|
|
|
92
|
+
// TODO: Writing to other MIME types not working in Safari for
|
|
93
|
+
// some reason.
|
|
94
|
+
event.clipboardData!.setData("blocknote/html", internalHTML);
|
|
95
|
+
event.clipboardData!.setData("text/html", externalHTML);
|
|
96
|
+
event.clipboardData!.setData("text/plain", plainText);
|
|
97
|
+
})();
|
|
95
98
|
// Prevent default PM handler to be called
|
|
96
99
|
return true;
|
|
97
100
|
},
|
|
@@ -125,15 +128,16 @@ export const createCopyToClipboardExtension = <
|
|
|
125
128
|
event.preventDefault();
|
|
126
129
|
event.dataTransfer!.clearData();
|
|
127
130
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// TODO: Writing to other MIME types not working in Safari for
|
|
132
|
-
// some reason.
|
|
133
|
-
event.dataTransfer!.setData("blocknote/html", internalHTML);
|
|
134
|
-
event.dataTransfer!.setData("text/html", externalHTML);
|
|
135
|
-
event.dataTransfer!.setData("text/plain", plainText);
|
|
131
|
+
(async () => {
|
|
132
|
+
const { internalHTML, externalHTML, plainText } =
|
|
133
|
+
await selectedFragmentToHTML(view, editor);
|
|
136
134
|
|
|
135
|
+
// TODO: Writing to other MIME types not working in Safari for
|
|
136
|
+
// some reason.
|
|
137
|
+
event.dataTransfer!.setData("blocknote/html", internalHTML);
|
|
138
|
+
event.dataTransfer!.setData("text/html", externalHTML);
|
|
139
|
+
event.dataTransfer!.setData("text/plain", plainText);
|
|
140
|
+
})();
|
|
137
141
|
// Prevent default PM handler to be called
|
|
138
142
|
return true;
|
|
139
143
|
},
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { DOMSerializer, Fragment, Node, Schema } from "prosemirror-model";
|
|
2
|
-
import rehypeParse from "rehype-parse";
|
|
3
|
-
import rehypeStringify from "rehype-stringify";
|
|
4
|
-
import { unified } from "unified";
|
|
5
2
|
|
|
6
3
|
import { PartialBlock } from "../../../blocks/defaultBlocks";
|
|
7
4
|
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
|
|
8
5
|
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
|
|
6
|
+
import { esmDependencies } from "../../../util/esmDependencies";
|
|
9
7
|
import { blockToNode } from "../../nodeConversions/nodeConversions";
|
|
10
8
|
import {
|
|
11
9
|
serializeNodeInner,
|
|
@@ -47,6 +45,8 @@ export interface ExternalHTMLExporter<
|
|
|
47
45
|
) => string;
|
|
48
46
|
}
|
|
49
47
|
|
|
48
|
+
// Needs to be sync because it's used in drag handler event (SideMenuPlugin)
|
|
49
|
+
// Ideally, call `await initializeESMDependencies()` before calling this function
|
|
50
50
|
export const createExternalHTMLExporter = <
|
|
51
51
|
BSchema extends BlockSchema,
|
|
52
52
|
I extends InlineContentSchema,
|
|
@@ -55,6 +55,14 @@ export const createExternalHTMLExporter = <
|
|
|
55
55
|
schema: Schema,
|
|
56
56
|
editor: BlockNoteEditor<BSchema, I, S>
|
|
57
57
|
): ExternalHTMLExporter<BSchema, I, S> => {
|
|
58
|
+
const deps = esmDependencies;
|
|
59
|
+
|
|
60
|
+
if (!deps) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"External HTML exporter requires ESM dependencies to be initialized"
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
58
66
|
const serializer = DOMSerializer.fromSchema(schema) as DOMSerializer & {
|
|
59
67
|
serializeNodeInner: (
|
|
60
68
|
node: Node,
|
|
@@ -79,8 +87,9 @@ export const createExternalHTMLExporter = <
|
|
|
79
87
|
// but additionally runs it through the `simplifyBlocks` rehype plugin to
|
|
80
88
|
// convert the internal HTML to external.
|
|
81
89
|
serializer.exportProseMirrorFragment = (fragment, options) => {
|
|
82
|
-
const externalHTML = unified
|
|
83
|
-
.
|
|
90
|
+
const externalHTML = deps.unified
|
|
91
|
+
.unified()
|
|
92
|
+
.use(deps.rehypeParse.default, { fragment: true })
|
|
84
93
|
.use(simplifyBlocks, {
|
|
85
94
|
orderedListItemBlockTypes: new Set<string>(["numberedListItem"]),
|
|
86
95
|
unorderedListItemBlockTypes: new Set<string>([
|
|
@@ -88,7 +97,7 @@ export const createExternalHTMLExporter = <
|
|
|
88
97
|
"checkListItem",
|
|
89
98
|
]),
|
|
90
99
|
})
|
|
91
|
-
.use(rehypeStringify)
|
|
100
|
+
.use(deps.rehypeStringify.default)
|
|
92
101
|
.processSync(serializeProseMirrorFragment(fragment, serializer, options));
|
|
93
102
|
|
|
94
103
|
return externalHTML.value as string;
|
|
@@ -7,6 +7,7 @@ import { PartialBlock } from "../../../blocks/defaultBlocks";
|
|
|
7
7
|
import { BlockSchema } from "../../../schema/blocks/types";
|
|
8
8
|
import { InlineContentSchema } from "../../../schema/inlineContent/types";
|
|
9
9
|
import { StyleSchema } from "../../../schema/styles/types";
|
|
10
|
+
import { initializeESMDependencies } from "../../../util/esmDependencies";
|
|
10
11
|
import { customBlocksTestCases } from "../../testUtil/cases/customBlocks";
|
|
11
12
|
import { customInlineContentTestCases } from "../../testUtil/cases/customInlineContent";
|
|
12
13
|
import { customStylesTestCases } from "../../testUtil/cases/customStyles";
|
|
@@ -44,6 +45,7 @@ async function convertToHTMLAndCompareSnapshots<
|
|
|
44
45
|
|
|
45
46
|
expect(parsed).toStrictEqual(fullBlocks);
|
|
46
47
|
|
|
48
|
+
await initializeESMDependencies();
|
|
47
49
|
// Create the "external" HTML, which is a cleaned up HTML representation, but lossy
|
|
48
50
|
const exporter = createExternalHTMLExporter(editor.pmSchema, editor);
|
|
49
51
|
const externalHTML = exporter.exportBlocks(blocks, {});
|
|
@@ -175,7 +177,7 @@ describe("Test ProseMirror fragment edge case conversion", () => {
|
|
|
175
177
|
editor.replaceBlocks(editor.document, blocks);
|
|
176
178
|
});
|
|
177
179
|
|
|
178
|
-
it("Selection within a block's children", () => {
|
|
180
|
+
it("Selection within a block's children", async () => {
|
|
179
181
|
// Selection starts and ends within the first block's children.
|
|
180
182
|
editor.dispatch(
|
|
181
183
|
editor._tiptapEditor.state.tr.setSelection(
|
|
@@ -186,6 +188,7 @@ describe("Test ProseMirror fragment edge case conversion", () => {
|
|
|
186
188
|
const copiedFragment =
|
|
187
189
|
editor._tiptapEditor.state.selection.content().content;
|
|
188
190
|
|
|
191
|
+
await initializeESMDependencies();
|
|
189
192
|
const exporter = createExternalHTMLExporter(editor.pmSchema, editor);
|
|
190
193
|
const externalHTML = exporter.exportProseMirrorFragment(
|
|
191
194
|
copiedFragment,
|
|
@@ -197,7 +200,7 @@ describe("Test ProseMirror fragment edge case conversion", () => {
|
|
|
197
200
|
);
|
|
198
201
|
});
|
|
199
202
|
|
|
200
|
-
it("Selection leaves a block's children", () => {
|
|
203
|
+
it("Selection leaves a block's children", async () => {
|
|
201
204
|
// Selection starts and ends within the first block's children and ends
|
|
202
205
|
// outside, at a shallower nesting level in the second block.
|
|
203
206
|
editor.dispatch(
|
|
@@ -209,6 +212,7 @@ describe("Test ProseMirror fragment edge case conversion", () => {
|
|
|
209
212
|
const copiedFragment =
|
|
210
213
|
editor._tiptapEditor.state.selection.content().content;
|
|
211
214
|
|
|
215
|
+
await initializeESMDependencies();
|
|
212
216
|
const exporter = createExternalHTMLExporter(editor.pmSchema, editor);
|
|
213
217
|
const externalHTML = exporter.exportProseMirrorFragment(
|
|
214
218
|
copiedFragment,
|
|
@@ -220,7 +224,7 @@ describe("Test ProseMirror fragment edge case conversion", () => {
|
|
|
220
224
|
);
|
|
221
225
|
});
|
|
222
226
|
|
|
223
|
-
it("Selection spans multiple blocks' children", () => {
|
|
227
|
+
it("Selection spans multiple blocks' children", async () => {
|
|
224
228
|
// Selection starts and ends within the first block's children and ends
|
|
225
229
|
// within the second block's children.
|
|
226
230
|
editor.dispatch(
|
|
@@ -231,6 +235,7 @@ describe("Test ProseMirror fragment edge case conversion", () => {
|
|
|
231
235
|
|
|
232
236
|
const copiedFragment =
|
|
233
237
|
editor._tiptapEditor.state.selection.content().content;
|
|
238
|
+
await initializeESMDependencies();
|
|
234
239
|
const exporter = createExternalHTMLExporter(editor.pmSchema, editor);
|
|
235
240
|
const externalHTML = exporter.exportProseMirrorFragment(
|
|
236
241
|
copiedFragment,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Element as HASTElement, Parent as HASTParent } from "hast";
|
|
2
|
-
import {
|
|
2
|
+
import { esmDependencies } from "../../../../util/esmDependencies";
|
|
3
3
|
|
|
4
4
|
type SimplifyBlocksOptions = {
|
|
5
5
|
orderedListItemBlockTypes: Set<string>;
|
|
@@ -16,6 +16,14 @@ type SimplifyBlocksOptions = {
|
|
|
16
16
|
* @param options Options for specifying which block types represent ordered and unordered list items.
|
|
17
17
|
*/
|
|
18
18
|
export function simplifyBlocks(options: SimplifyBlocksOptions) {
|
|
19
|
+
const deps = esmDependencies;
|
|
20
|
+
|
|
21
|
+
if (!deps) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"simplifyBlocks requires ESM dependencies to be initialized"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
const listItemBlockTypes = new Set<string>([
|
|
20
28
|
...options.orderedListItemBlockTypes,
|
|
21
29
|
...options.unorderedListItemBlockTypes,
|
|
@@ -110,13 +118,13 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) {
|
|
|
110
118
|
// type as this was already done earlier.
|
|
111
119
|
if (!activeList) {
|
|
112
120
|
// Creates a new list element to represent an active list.
|
|
113
|
-
activeList = fromDom(
|
|
121
|
+
activeList = deps.hastUtilFromDom.fromDom(
|
|
114
122
|
document.createElement(listItemBlockType!)
|
|
115
123
|
) as HASTElement;
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
// Creates a new list item element to represent the block.
|
|
119
|
-
const listItemElement = fromDom(
|
|
127
|
+
const listItemElement = deps.hastUtilFromDom.fromDom(
|
|
120
128
|
document.createElement("li")
|
|
121
129
|
) as HASTElement;
|
|
122
130
|
|
|
@@ -1,30 +1,42 @@
|
|
|
1
1
|
import { Schema } from "prosemirror-model";
|
|
2
|
-
import rehypeParse from "rehype-parse";
|
|
3
|
-
import rehypeRemark from "rehype-remark";
|
|
4
|
-
import remarkGfm from "remark-gfm";
|
|
5
|
-
import remarkStringify from "remark-stringify";
|
|
6
|
-
import { unified } from "unified";
|
|
7
2
|
import { PartialBlock } from "../../../blocks/defaultBlocks";
|
|
8
3
|
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
|
|
9
4
|
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
|
|
5
|
+
import {
|
|
6
|
+
esmDependencies,
|
|
7
|
+
initializeESMDependencies,
|
|
8
|
+
} from "../../../util/esmDependencies";
|
|
10
9
|
import { createExternalHTMLExporter } from "../html/externalHTMLExporter";
|
|
11
10
|
import { removeUnderlines } from "./removeUnderlinesRehypePlugin";
|
|
12
11
|
import { addSpacesToCheckboxes } from "./util/addSpacesToCheckboxesRehypePlugin";
|
|
13
12
|
|
|
13
|
+
// Needs to be sync because it's used in drag handler event (SideMenuPlugin)
|
|
14
|
+
// Ideally, call `await initializeESMDependencies()` before calling this function
|
|
14
15
|
export function cleanHTMLToMarkdown(cleanHTMLString: string) {
|
|
15
|
-
const
|
|
16
|
-
|
|
16
|
+
const deps = esmDependencies;
|
|
17
|
+
|
|
18
|
+
if (!deps) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"cleanHTMLToMarkdown requires ESM dependencies to be initialized"
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const markdownString = deps.unified
|
|
25
|
+
.unified()
|
|
26
|
+
.use(deps.rehypeParse.default, { fragment: true })
|
|
17
27
|
.use(removeUnderlines)
|
|
18
28
|
.use(addSpacesToCheckboxes)
|
|
19
|
-
.use(rehypeRemark)
|
|
20
|
-
.use(remarkGfm)
|
|
21
|
-
.use(remarkStringify, {
|
|
29
|
+
.use(deps.rehypeRemark.default)
|
|
30
|
+
.use(deps.remarkGfm.default)
|
|
31
|
+
.use(deps.remarkStringify.default, {
|
|
32
|
+
handlers: { text: (node) => node.value },
|
|
33
|
+
})
|
|
22
34
|
.processSync(cleanHTMLString);
|
|
23
35
|
|
|
24
36
|
return markdownString.value as string;
|
|
25
37
|
}
|
|
26
38
|
|
|
27
|
-
export function blocksToMarkdown<
|
|
39
|
+
export async function blocksToMarkdown<
|
|
28
40
|
BSchema extends BlockSchema,
|
|
29
41
|
I extends InlineContentSchema,
|
|
30
42
|
S extends StyleSchema
|
|
@@ -33,7 +45,8 @@ export function blocksToMarkdown<
|
|
|
33
45
|
schema: Schema,
|
|
34
46
|
editor: BlockNoteEditor<BSchema, I, S>,
|
|
35
47
|
options: { document?: Document }
|
|
36
|
-
): string {
|
|
48
|
+
): Promise<string> {
|
|
49
|
+
await initializeESMDependencies();
|
|
37
50
|
const exporter = createExternalHTMLExporter(schema, editor);
|
|
38
51
|
const externalHTML = exporter.exportBlocks(blocks, options);
|
|
39
52
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Element as HASTElement, Parent as HASTParent } from "hast";
|
|
2
|
-
import {
|
|
2
|
+
import { esmDependencies } from "../../../../util/esmDependencies";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Rehype plugin which adds a space after each checkbox input element. This is
|
|
@@ -7,6 +7,14 @@ import { fromDom } from "hast-util-from-dom";
|
|
|
7
7
|
* itself, but these are needed for correct Markdown syntax.
|
|
8
8
|
*/
|
|
9
9
|
export function addSpacesToCheckboxes() {
|
|
10
|
+
const deps = esmDependencies;
|
|
11
|
+
|
|
12
|
+
if (!deps) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
"simplifyBlocks requires ESM dependencies to be initialized"
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
const helper = (tree: HASTParent) => {
|
|
11
19
|
if (tree.children && "length" in tree.children && tree.children.length) {
|
|
12
20
|
for (let i = tree.children.length - 1; i >= 0; i--) {
|
|
@@ -29,7 +37,9 @@ export function addSpacesToCheckboxes() {
|
|
|
29
37
|
nextChild.children.splice(
|
|
30
38
|
0,
|
|
31
39
|
0,
|
|
32
|
-
fromDom(
|
|
40
|
+
deps.hastUtilFromDom.fromDom(
|
|
41
|
+
document.createTextNode(" ")
|
|
42
|
+
) as HASTElement
|
|
33
43
|
);
|
|
34
44
|
} else {
|
|
35
45
|
helper(child as HASTParent);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import rehypeFormat from "rehype-format";
|
|
2
|
-
import rehypeParse from "rehype-parse";
|
|
3
|
-
import rehypeStringify from "rehype-stringify";
|
|
4
|
-
import { unified } from "unified";
|
|
5
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { initializeESMDependencies } from "../../../../util/esmDependencies";
|
|
6
3
|
import { nestedListsToBlockNoteStructure } from "./nestedLists";
|
|
7
4
|
|
|
8
5
|
async function testHTML(html: string) {
|
|
6
|
+
const deps = await initializeESMDependencies();
|
|
7
|
+
|
|
9
8
|
const htmlNode = nestedListsToBlockNoteStructure(html);
|
|
10
9
|
|
|
11
|
-
const pretty = await unified
|
|
12
|
-
.
|
|
13
|
-
.use(
|
|
14
|
-
.use(
|
|
10
|
+
const pretty = await deps.unified
|
|
11
|
+
.unified()
|
|
12
|
+
.use(deps.rehypeParse.default, { fragment: true })
|
|
13
|
+
.use(deps.rehypeFormat.default)
|
|
14
|
+
.use(deps.rehypeStringify.default)
|
|
15
15
|
.process(htmlNode.innerHTML);
|
|
16
16
|
|
|
17
17
|
expect(pretty.value).toMatchSnapshot();
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Schema } from "prosemirror-model";
|
|
2
|
-
|
|
3
|
-
import remarkGfm from "remark-gfm";
|
|
4
|
-
import remarkParse from "remark-parse";
|
|
5
|
-
import remarkRehype, { defaultHandlers } from "remark-rehype";
|
|
6
|
-
import { unified } from "unified";
|
|
2
|
+
|
|
7
3
|
import { Block } from "../../../blocks/defaultBlocks";
|
|
8
4
|
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
|
|
5
|
+
import { initializeESMDependencies } from "../../../util/esmDependencies";
|
|
9
6
|
import { HTMLToBlocks } from "../html/parseHTML";
|
|
10
7
|
|
|
11
8
|
// modified version of https://github.com/syntax-tree/mdast-util-to-hast/blob/main/lib/handlers/code.js
|
|
@@ -47,7 +44,7 @@ function code(state: any, node: any) {
|
|
|
47
44
|
return result;
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
export function markdownToBlocks<
|
|
47
|
+
export async function markdownToBlocks<
|
|
51
48
|
BSchema extends BlockSchema,
|
|
52
49
|
I extends InlineContentSchema,
|
|
53
50
|
S extends StyleSchema
|
|
@@ -58,16 +55,18 @@ export function markdownToBlocks<
|
|
|
58
55
|
styleSchema: S,
|
|
59
56
|
pmSchema: Schema
|
|
60
57
|
): Promise<Block<BSchema, I, S>[]> {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
.
|
|
64
|
-
.use(
|
|
58
|
+
const deps = await initializeESMDependencies();
|
|
59
|
+
const htmlString = deps.unified
|
|
60
|
+
.unified()
|
|
61
|
+
.use(deps.remarkParse.default)
|
|
62
|
+
.use(deps.remarkGfm.default)
|
|
63
|
+
.use(deps.remarkRehype.default, {
|
|
65
64
|
handlers: {
|
|
66
|
-
...(defaultHandlers as any),
|
|
65
|
+
...(deps.remarkRehype.defaultHandlers as any),
|
|
67
66
|
code,
|
|
68
67
|
},
|
|
69
68
|
})
|
|
70
|
-
.use(rehypeStringify)
|
|
69
|
+
.use(deps.rehypeStringify.default)
|
|
71
70
|
.processSync(markdown);
|
|
72
71
|
|
|
73
72
|
return HTMLToBlocks(
|
|
@@ -68,6 +68,7 @@ import { en } from "../i18n/locales";
|
|
|
68
68
|
import { Transaction } from "@tiptap/pm/state";
|
|
69
69
|
import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer";
|
|
70
70
|
import "../style.css";
|
|
71
|
+
import { initializeESMDependencies } from "../util/esmDependencies";
|
|
71
72
|
|
|
72
73
|
export type BlockNoteEditorOptions<
|
|
73
74
|
BSchema extends BlockSchema,
|
|
@@ -271,7 +272,7 @@ export class BlockNoteEditor<
|
|
|
271
272
|
return new BlockNoteEditor<BSchema, ISchema, SSchema>(options);
|
|
272
273
|
}
|
|
273
274
|
|
|
274
|
-
|
|
275
|
+
protected constructor(
|
|
275
276
|
private readonly options: Partial<BlockNoteEditorOptions<any, any, any>>
|
|
276
277
|
) {
|
|
277
278
|
const anyOpts = options as any;
|
|
@@ -402,6 +403,10 @@ export class BlockNoteEditor<
|
|
|
402
403
|
editorProps: {
|
|
403
404
|
...newOptions._tiptapOptions?.editorProps,
|
|
404
405
|
attributes: {
|
|
406
|
+
// As of TipTap v2.5.0 the tabIndex is removed when the editor is not
|
|
407
|
+
// editable, so you can't focus it. We want to revert this as we have
|
|
408
|
+
// UI behaviour that relies on it.
|
|
409
|
+
tabIndex: "0",
|
|
405
410
|
...newOptions._tiptapOptions?.editorProps?.attributes,
|
|
406
411
|
...newOptions.domAttributes?.editor,
|
|
407
412
|
class: mergeCSSClasses(
|
|
@@ -719,9 +724,16 @@ export class BlockNoteEditor<
|
|
|
719
724
|
return true;
|
|
720
725
|
}
|
|
721
726
|
|
|
727
|
+
// Fixed the block pos and size
|
|
728
|
+
// all block is wrapped with a blockContent wrapper
|
|
729
|
+
// and blockContent wrapper pos = inner block pos - 1
|
|
730
|
+
// blockContent wrapper end = inner block pos + nodeSize + 1
|
|
731
|
+
// need to add 1 to start and -1 to end
|
|
732
|
+
const end = pos + node.nodeSize - 1;
|
|
733
|
+
const start = pos + 1;
|
|
722
734
|
if (
|
|
723
|
-
|
|
724
|
-
|
|
735
|
+
end <= this._tiptapEditor.state.selection.from ||
|
|
736
|
+
start >= this._tiptapEditor.state.selection.to
|
|
725
737
|
) {
|
|
726
738
|
return true;
|
|
727
739
|
}
|
|
@@ -1016,6 +1028,7 @@ export class BlockNoteEditor<
|
|
|
1016
1028
|
public async blocksToHTMLLossy(
|
|
1017
1029
|
blocks: PartialBlock<BSchema, ISchema, SSchema>[] = this.document
|
|
1018
1030
|
): Promise<string> {
|
|
1031
|
+
await initializeESMDependencies();
|
|
1019
1032
|
const exporter = createExternalHTMLExporter(this.pmSchema, this);
|
|
1020
1033
|
return exporter.exportBlocks(blocks, {});
|
|
1021
1034
|
}
|
|
@@ -12,6 +12,7 @@ import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
|
12
12
|
import { UiElementPosition } from "../../extensions-shared/UiElementPosition";
|
|
13
13
|
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema";
|
|
14
14
|
import { EventEmitter } from "../../util/EventEmitter";
|
|
15
|
+
import { initializeESMDependencies } from "../../util/esmDependencies";
|
|
15
16
|
import { MultipleNodeSelection } from "./MultipleNodeSelection";
|
|
16
17
|
|
|
17
18
|
let dragImageElement: Element | undefined;
|
|
@@ -302,6 +303,7 @@ export class SideMenuView<
|
|
|
302
303
|
"dragover",
|
|
303
304
|
this.onDragOver as EventListener
|
|
304
305
|
);
|
|
306
|
+
initializeESMDependencies();
|
|
305
307
|
this.pmView.dom.addEventListener("dragstart", this.onDragStart);
|
|
306
308
|
|
|
307
309
|
// Shows or updates menu position whenever the cursor moves, if the menu isn't frozen.
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as locales from "./i18n/locales";
|
|
2
2
|
export * from "./api/exporters/html/externalHTMLExporter";
|
|
3
3
|
export * from "./api/exporters/html/internalHTMLSerializer";
|
|
4
|
-
export * from "./api/testUtil";
|
|
5
4
|
export * from "./api/getCurrentBlockContentType";
|
|
6
|
-
export * from "./
|
|
5
|
+
export * from "./api/testUtil";
|
|
7
6
|
export * from "./blocks/AudioBlockContent/AudioBlockContent";
|
|
8
7
|
export * from "./blocks/FileBlockContent/FileBlockContent";
|
|
9
|
-
export * from "./blocks/ImageBlockContent/ImageBlockContent";
|
|
10
|
-
export * from "./blocks/VideoBlockContent/VideoBlockContent";
|
|
11
8
|
export * from "./blocks/FileBlockContent/fileBlockHelpers";
|
|
12
9
|
export * from "./blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY";
|
|
10
|
+
export * from "./blocks/ImageBlockContent/ImageBlockContent";
|
|
13
11
|
export { parseImageElement } from "./blocks/ImageBlockContent/imageBlockHelpers";
|
|
12
|
+
export * from "./blocks/VideoBlockContent/VideoBlockContent";
|
|
13
|
+
export * from "./blocks/defaultBlockHelpers";
|
|
14
14
|
export * from "./blocks/defaultBlockTypeGuards";
|
|
15
15
|
export * from "./blocks/defaultBlocks";
|
|
16
16
|
export * from "./blocks/defaultProps";
|
|
@@ -23,15 +23,16 @@ export * from "./extensions/FilePanel/FilePanelPlugin";
|
|
|
23
23
|
export * from "./extensions/FormattingToolbar/FormattingToolbarPlugin";
|
|
24
24
|
export * from "./extensions/LinkToolbar/LinkToolbarPlugin";
|
|
25
25
|
export * from "./extensions/SideMenu/SideMenuPlugin";
|
|
26
|
-
export * from "./extensions/SuggestionMenu/DefaultSuggestionItem";
|
|
27
26
|
export * from "./extensions/SuggestionMenu/DefaultGridSuggestionItem";
|
|
27
|
+
export * from "./extensions/SuggestionMenu/DefaultSuggestionItem";
|
|
28
28
|
export * from "./extensions/SuggestionMenu/SuggestionPlugin";
|
|
29
|
-
export * from "./extensions/SuggestionMenu/getDefaultSlashMenuItems";
|
|
30
29
|
export * from "./extensions/SuggestionMenu/getDefaultEmojiPickerItems";
|
|
30
|
+
export * from "./extensions/SuggestionMenu/getDefaultSlashMenuItems";
|
|
31
31
|
export * from "./extensions/TableHandles/TableHandlesPlugin";
|
|
32
32
|
export * from "./i18n/dictionary";
|
|
33
33
|
export * from "./schema";
|
|
34
34
|
export * from "./util/browser";
|
|
35
|
+
export * from "./util/esmDependencies";
|
|
35
36
|
export * from "./util/string";
|
|
36
37
|
export * from "./util/typescript";
|
|
37
38
|
export { UnreachableCaseError, assertEmpty } from "./util/typescript";
|