@blocknote/core 0.16.0 → 0.17.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 +3287 -2755
- 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 +5 -2
- package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +3087 -0
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +132 -0
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +71 -0
- package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +2276 -0
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +131 -0
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +103 -0
- package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +3767 -0
- package/src/api/blockManipulation/commands/moveBlock/moveBlock.test.ts +192 -0
- package/src/api/blockManipulation/commands/moveBlock/moveBlock.ts +178 -0
- package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +1136 -0
- package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.ts +34 -0
- package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts +100 -0
- package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +4931 -0
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +222 -0
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +70 -0
- package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +2924 -0
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +136 -0
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +48 -0
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +8376 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +300 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +199 -0
- package/src/api/blockManipulation/insertContentAt.ts +96 -0
- package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +316 -0
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +53 -0
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +130 -0
- package/src/api/blockManipulation/setupTestEnv.ts +179 -0
- package/src/api/clipboard/__snapshots__/tableAllCells.html +1 -1
- package/src/api/clipboard/clipboard.test.ts +5 -6
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +8 -4
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +11 -6
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +8 -4
- package/src/api/clipboard/toClipboard/copyExtension.ts +113 -61
- package/src/api/exporters/html/__snapshots__/complex/misc/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/lists/basic/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/lists/nested/external.html +1 -1
- package/src/api/exporters/html/externalHTMLExporter.ts +42 -94
- package/src/api/exporters/html/htmlConversion.test.ts +19 -13
- package/src/api/exporters/html/internalHTMLSerializer.ts +21 -72
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +263 -0
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +158 -0
- package/src/api/exporters/markdown/markdownExporter.test.ts +10 -10
- package/src/api/exporters/markdown/markdownExporter.ts +11 -7
- package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +2 -2
- package/src/api/getBlockInfoFromPos.ts +172 -90
- package/src/api/nodeConversions/blockToNode.ts +257 -0
- package/src/api/nodeConversions/fragmentToBlocks.ts +60 -0
- package/src/api/nodeConversions/nodeConversions.test.ts +9 -8
- package/src/api/nodeConversions/{nodeConversions.ts → nodeToBlock.ts} +20 -262
- package/src/api/parsers/html/parseHTML.test.ts +2 -2
- package/src/api/parsers/html/parseHTML.ts +8 -4
- package/src/api/parsers/html/util/nestedLists.test.ts +2 -2
- package/src/api/parsers/markdown/parseMarkdown.test.ts +2 -2
- package/src/api/parsers/markdown/parseMarkdown.ts +8 -4
- package/src/api/testUtil/cases/customBlocks.ts +11 -11
- package/src/api/testUtil/cases/customInlineContent.ts +6 -6
- package/src/api/testUtil/cases/customStyles.ts +6 -6
- package/src/api/testUtil/cases/defaultSchema.ts +4 -4
- package/src/api/testUtil/index.ts +6 -6
- package/src/api/testUtil/partialBlockTestUtil.ts +5 -5
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +5 -5
- package/src/blocks/FileBlockContent/FileBlockContent.ts +4 -4
- package/src/blocks/FileBlockContent/fileBlockHelpers.ts +2 -2
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +61 -39
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +5 -5
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +30 -18
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +67 -33
- package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +23 -19
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +22 -24
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +31 -19
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +16 -11
- package/src/blocks/TableBlockContent/TableBlockContent.ts +4 -4
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +5 -5
- package/src/blocks/defaultBlockHelpers.ts +4 -4
- package/src/blocks/defaultBlockTypeGuards.ts +5 -5
- package/src/blocks/defaultBlocks.ts +13 -13
- package/src/blocks/defaultProps.ts +1 -1
- package/src/editor/BlockNoteEditor.test.ts +14 -7
- package/src/editor/BlockNoteEditor.ts +82 -149
- package/src/editor/BlockNoteExtensions.ts +15 -11
- package/src/editor/BlockNoteSchema.ts +7 -7
- package/src/editor/BlockNoteTipTapEditor.ts +5 -3
- package/src/editor/cursorPositionTypes.ts +7 -2
- package/src/editor/selectionTypes.ts +6 -2
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -1
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
- package/src/extensions/FilePanel/FilePanelPlugin.ts +4 -4
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +8 -4
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +333 -0
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +9 -4
- package/src/extensions/{NonEditableBlocks/NonEditableBlockPlugin.ts → NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts} +2 -2
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +1 -1
- package/src/extensions/SideMenu/SideMenuPlugin.ts +72 -401
- package/src/extensions/SideMenu/dragging.ts +251 -0
- package/src/extensions/SuggestionMenu/DefaultSuggestionItem.ts +1 -1
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +8 -4
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +8 -4
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +19 -15
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +11 -7
- package/src/extensions/TextColor/TextColorExtension.ts +1 -1
- package/src/extensions/TextColor/TextColorMark.ts +1 -1
- package/src/i18n/dictionary.ts +1 -1
- package/src/i18n/locales/ar.ts +1 -1
- package/src/i18n/locales/fr.ts +1 -1
- package/src/i18n/locales/hr.ts +308 -0
- package/src/i18n/locales/index.ts +15 -14
- package/src/i18n/locales/is.ts +1 -1
- package/src/i18n/locales/ja.ts +1 -1
- package/src/i18n/locales/ko.ts +1 -1
- package/src/i18n/locales/nl.ts +1 -1
- package/src/i18n/locales/pl.ts +1 -1
- package/src/i18n/locales/pt.ts +1 -1
- package/src/i18n/locales/ru.ts +1 -1
- package/src/i18n/locales/vi.ts +1 -1
- package/src/i18n/locales/zh.ts +1 -1
- package/src/index.ts +45 -44
- package/src/pm-nodes/BlockContainer.ts +3 -647
- package/src/pm-nodes/BlockGroup.ts +2 -2
- package/src/pm-nodes/index.ts +3 -3
- package/src/schema/blocks/createSpec.ts +8 -7
- package/src/schema/blocks/internal.ts +9 -9
- package/src/schema/blocks/types.ts +4 -4
- package/src/schema/index.ts +10 -10
- package/src/schema/inlineContent/createSpec.ts +9 -10
- package/src/schema/inlineContent/internal.ts +3 -3
- package/src/schema/inlineContent/types.ts +2 -2
- package/src/schema/styles/createSpec.ts +4 -3
- package/src/schema/styles/internal.ts +1 -1
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +4 -0
- package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +7 -0
- package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.d.ts +5 -0
- package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +7 -0
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +7 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +5 -0
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +11 -0
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.test.d.ts +1 -0
- package/types/src/api/blockManipulation/insertContentAt.d.ts +6 -0
- package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.d.ts +5 -0
- package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.d.ts +1 -0
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +492 -0
- package/types/src/api/clipboard/fromClipboard/fileDropExtension.d.ts +3 -3
- package/types/src/api/clipboard/fromClipboard/handleFileInsertion.d.ts +1 -1
- package/types/src/api/clipboard/fromClipboard/pasteExtension.d.ts +2 -2
- package/types/src/api/clipboard/toClipboard/copyExtension.d.ts +5 -5
- package/types/src/api/exporters/html/externalHTMLExporter.d.ts +7 -9
- package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +6 -10
- package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +10 -0
- package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +11 -0
- package/types/src/api/exporters/markdown/markdownExporter.d.ts +3 -3
- package/types/src/api/getBlockInfoFromPos.d.ts +63 -20
- package/types/src/api/nodeConversions/blockToNode.d.ts +15 -0
- package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +7 -0
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +16 -0
- package/types/src/api/parsers/html/parseHTML.d.ts +2 -2
- package/types/src/api/parsers/markdown/parseMarkdown.d.ts +2 -2
- package/types/src/api/testUtil/cases/customBlocks.d.ts +39 -39
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +35 -35
- package/types/src/api/testUtil/cases/customStyles.d.ts +35 -35
- package/types/src/api/testUtil/cases/defaultSchema.d.ts +2 -2
- package/types/src/api/testUtil/index.d.ts +6 -6
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +4 -4
- package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +4 -4
- package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +4 -4
- package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +2 -2
- package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +2 -2
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +4 -4
- package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +2 -2
- package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +2 -2
- package/types/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +2 -2
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +2 -2
- package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +2 -2
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +2 -2
- package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +4 -4
- package/types/src/blocks/defaultBlockHelpers.d.ts +3 -3
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +4 -4
- package/types/src/blocks/defaultBlocks.d.ts +38 -38
- package/types/src/blocks/defaultProps.d.ts +1 -1
- package/types/src/editor/BlockNoteEditor.d.ts +28 -16
- package/types/src/editor/BlockNoteExtensions.d.ts +3 -3
- package/types/src/editor/BlockNoteSchema.d.ts +4 -4
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
- package/types/src/editor/cursorPositionTypes.d.ts +3 -2
- package/types/src/editor/selectionTypes.d.ts +2 -2
- package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +1 -1
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +4 -4
- package/types/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +5 -0
- package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +4 -4
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -0
- package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +1 -1
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +12 -28
- package/types/src/extensions/SideMenu/dragging.d.ts +17 -0
- package/types/src/extensions/SuggestionMenu/DefaultSuggestionItem.d.ts +1 -1
- package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +4 -4
- package/types/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.d.ts +3 -3
- package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +4 -4
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +4 -4
- package/types/src/extensions/TextColor/TextColorMark.d.ts +1 -1
- package/types/src/i18n/dictionary.d.ts +1 -1
- package/types/src/i18n/locales/ar.d.ts +1 -1
- package/types/src/i18n/locales/fr.d.ts +1 -1
- package/types/src/i18n/locales/hr.d.ts +239 -0
- package/types/src/i18n/locales/index.d.ts +15 -14
- package/types/src/i18n/locales/is.d.ts +1 -1
- package/types/src/i18n/locales/ja.d.ts +1 -1
- package/types/src/i18n/locales/ko.d.ts +1 -1
- package/types/src/i18n/locales/nl.d.ts +1 -1
- package/types/src/i18n/locales/pl.d.ts +1 -1
- package/types/src/i18n/locales/pt.d.ts +1 -1
- package/types/src/i18n/locales/ru.d.ts +1 -1
- package/types/src/i18n/locales/vi.d.ts +1 -1
- package/types/src/i18n/locales/zh.d.ts +1 -1
- package/types/src/index.d.ts +45 -44
- package/types/src/pm-nodes/BlockContainer.d.ts +2 -16
- package/types/src/pm-nodes/BlockGroup.d.ts +1 -1
- package/types/src/pm-nodes/index.d.ts +3 -3
- package/types/src/schema/blocks/createSpec.d.ts +5 -5
- package/types/src/schema/blocks/internal.d.ts +5 -5
- package/types/src/schema/blocks/types.d.ts +4 -4
- package/types/src/schema/index.d.ts +10 -10
- package/types/src/schema/inlineContent/createSpec.d.ts +3 -3
- package/types/src/schema/inlineContent/internal.d.ts +2 -2
- package/types/src/schema/inlineContent/types.d.ts +2 -2
- package/types/src/schema/styles/createSpec.d.ts +1 -1
- package/types/src/schema/styles/internal.d.ts +1 -1
- package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +0 -714
- package/src/api/blockManipulation/blockManipulation.test.ts +0 -292
- package/src/api/blockManipulation/blockManipulation.ts +0 -350
- package/src/api/exporters/html/util/sharedHTMLConversion.ts +0 -130
- package/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts +0 -218
- package/src/api/getCurrentBlockContentType.ts +0 -14
- package/types/src/api/blockManipulation/blockManipulation.d.ts +0 -14
- package/types/src/api/exporters/html/util/sharedHTMLConversion.d.ts +0 -9
- package/types/src/api/exporters/html/util/simplifyBlocksRehypePlugin.d.ts +0 -16
- package/types/src/api/getCurrentBlockContentType.d.ts +0 -2
- package/types/src/api/nodeConversions/nodeConversions.d.ts +0 -24
- package/types/src/extensions/NonEditableBlocks/NonEditableBlockPlugin.d.ts +0 -2
- /package/types/src/api/blockManipulation/{blockManipulation.test.d.ts → commands/insertBlocks/insertBlocks.test.d.ts} +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js";
|
|
2
|
+
import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js";
|
|
1
3
|
import {
|
|
2
4
|
createBlockSpecFromStronglyTypedTiptapNode,
|
|
3
5
|
createStronglyTypedTiptapNode,
|
|
4
|
-
} from "../../schema";
|
|
5
|
-
import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers";
|
|
6
|
-
import { defaultProps } from "../defaultProps";
|
|
7
|
-
import { getCurrentBlockContentType } from "../../api/getCurrentBlockContentType";
|
|
6
|
+
} from "../../schema/index.js";
|
|
7
|
+
import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
|
|
8
|
+
import { defaultProps } from "../defaultProps.js";
|
|
8
9
|
|
|
9
10
|
export const paragraphPropSchema = {
|
|
10
11
|
...defaultProps,
|
|
@@ -18,16 +19,20 @@ export const ParagraphBlockContent = createStronglyTypedTiptapNode({
|
|
|
18
19
|
addKeyboardShortcuts() {
|
|
19
20
|
return {
|
|
20
21
|
"Mod-Alt-0": () => {
|
|
21
|
-
|
|
22
|
+
const blockInfo = getBlockInfoFromSelection(this.editor.state);
|
|
23
|
+
if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
|
|
22
24
|
return true;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
return this.editor.commands.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
return this.editor.commands.command(
|
|
28
|
+
updateBlockCommand(
|
|
29
|
+
this.options.editor,
|
|
30
|
+
blockInfo.blockContainer.beforePos,
|
|
31
|
+
{
|
|
32
|
+
type: "paragraph",
|
|
33
|
+
props: {},
|
|
34
|
+
}
|
|
35
|
+
)
|
|
31
36
|
);
|
|
32
37
|
},
|
|
33
38
|
};
|
|
@@ -5,10 +5,10 @@ import { TableRow } from "@tiptap/extension-table-row";
|
|
|
5
5
|
import {
|
|
6
6
|
createBlockSpecFromStronglyTypedTiptapNode,
|
|
7
7
|
createStronglyTypedTiptapNode,
|
|
8
|
-
} from "../../schema";
|
|
9
|
-
import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers";
|
|
10
|
-
import { defaultProps } from "../defaultProps";
|
|
11
|
-
import { TableExtension } from "./TableExtension";
|
|
8
|
+
} from "../../schema/index.js";
|
|
9
|
+
import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
|
|
10
|
+
import { defaultProps } from "../defaultProps.js";
|
|
11
|
+
import { TableExtension } from "./TableExtension.js";
|
|
12
12
|
|
|
13
13
|
export const tablePropSchema = {
|
|
14
14
|
...defaultProps,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
1
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
2
2
|
import {
|
|
3
3
|
BlockFromConfig,
|
|
4
4
|
createBlockSpec,
|
|
5
5
|
FileBlockConfig,
|
|
6
6
|
Props,
|
|
7
7
|
PropSchema,
|
|
8
|
-
} from "../../schema";
|
|
9
|
-
import { defaultProps } from "../defaultProps";
|
|
8
|
+
} from "../../schema/index.js";
|
|
9
|
+
import { defaultProps } from "../defaultProps.js";
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
12
|
createFigureWithCaption,
|
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
createLinkWithCaption,
|
|
16
16
|
createResizeHandlesWrapper,
|
|
17
17
|
parseFigureElement,
|
|
18
|
-
} from "../FileBlockContent/fileBlockHelpers";
|
|
19
|
-
import { parseVideoElement } from "./videoBlockHelpers";
|
|
18
|
+
} from "../FileBlockContent/fileBlockHelpers.js";
|
|
19
|
+
import { parseVideoElement } from "./videoBlockHelpers.js";
|
|
20
20
|
|
|
21
21
|
export const videoPropSchema = {
|
|
22
22
|
textAlignment: defaultProps.textAlignment,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { blockToNode } from "../api/nodeConversions/
|
|
2
|
-
import type { BlockNoteEditor } from "../editor/BlockNoteEditor";
|
|
1
|
+
import { blockToNode } from "../api/nodeConversions/blockToNode.js";
|
|
2
|
+
import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
3
3
|
import type {
|
|
4
4
|
BlockNoDefaults,
|
|
5
5
|
BlockSchema,
|
|
6
6
|
InlineContentSchema,
|
|
7
7
|
StyleSchema,
|
|
8
|
-
} from "../schema";
|
|
9
|
-
import { mergeCSSClasses } from "../util/browser";
|
|
8
|
+
} from "../schema/index.js";
|
|
9
|
+
import { mergeCSSClasses } from "../util/browser.js";
|
|
10
10
|
|
|
11
11
|
// Function that creates a ProseMirror `DOMOutputSpec` for a default block.
|
|
12
12
|
// Since all default blocks have the same structure (`blockContent` div with a
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { BlockNoteEditor } from "../editor/BlockNoteEditor";
|
|
1
|
+
import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
2
2
|
import {
|
|
3
3
|
BlockFromConfig,
|
|
4
4
|
BlockSchema,
|
|
5
5
|
FileBlockConfig,
|
|
6
6
|
InlineContentSchema,
|
|
7
7
|
StyleSchema,
|
|
8
|
-
} from "../schema";
|
|
8
|
+
} from "../schema/index.js";
|
|
9
9
|
import {
|
|
10
10
|
Block,
|
|
11
11
|
DefaultBlockSchema,
|
|
12
|
+
DefaultInlineContentSchema,
|
|
12
13
|
defaultBlockSchema,
|
|
13
14
|
defaultInlineContentSchema,
|
|
14
|
-
|
|
15
|
-
} from "./
|
|
16
|
-
import { defaultProps } from "./defaultProps";
|
|
15
|
+
} from "./defaultBlocks.js";
|
|
16
|
+
import { defaultProps } from "./defaultProps.js";
|
|
17
17
|
|
|
18
18
|
export function checkDefaultBlockTypeInSchema<
|
|
19
19
|
BlockType extends keyof DefaultBlockSchema,
|
|
@@ -3,8 +3,8 @@ import Code from "@tiptap/extension-code";
|
|
|
3
3
|
import Italic from "@tiptap/extension-italic";
|
|
4
4
|
import Strike from "@tiptap/extension-strike";
|
|
5
5
|
import Underline from "@tiptap/extension-underline";
|
|
6
|
-
import { BackgroundColor } from "../extensions/BackgroundColor/BackgroundColorMark";
|
|
7
|
-
import { TextColor } from "../extensions/TextColor/TextColorMark";
|
|
6
|
+
import { BackgroundColor } from "../extensions/BackgroundColor/BackgroundColorMark.js";
|
|
7
|
+
import { TextColor } from "../extensions/TextColor/TextColorMark.js";
|
|
8
8
|
import {
|
|
9
9
|
BlockNoDefaults,
|
|
10
10
|
BlockSchema,
|
|
@@ -18,18 +18,18 @@ import {
|
|
|
18
18
|
getBlockSchemaFromSpecs,
|
|
19
19
|
getInlineContentSchemaFromSpecs,
|
|
20
20
|
getStyleSchemaFromSpecs,
|
|
21
|
-
} from "../schema";
|
|
21
|
+
} from "../schema/index.js";
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
23
|
+
import { AudioBlock } from "./AudioBlockContent/AudioBlockContent.js";
|
|
24
|
+
import { FileBlock } from "./FileBlockContent/FileBlockContent.js";
|
|
25
|
+
import { Heading } from "./HeadingBlockContent/HeadingBlockContent.js";
|
|
26
|
+
import { ImageBlock } from "./ImageBlockContent/ImageBlockContent.js";
|
|
27
|
+
import { BulletListItem } from "./ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.js";
|
|
28
|
+
import { CheckListItem } from "./ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.js";
|
|
29
|
+
import { NumberedListItem } from "./ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.js";
|
|
30
|
+
import { Paragraph } from "./ParagraphBlockContent/ParagraphBlockContent.js";
|
|
31
|
+
import { Table } from "./TableBlockContent/TableBlockContent.js";
|
|
32
|
+
import { VideoBlock } from "./VideoBlockContent/VideoBlockContent.js";
|
|
33
33
|
|
|
34
34
|
export const defaultBlockSpecs = {
|
|
35
35
|
paragraph: Paragraph,
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
getBlockInfo,
|
|
4
|
+
getNearestBlockContainerPos,
|
|
5
|
+
} from "../api/getBlockInfoFromPos.js";
|
|
6
|
+
import { BlockNoteEditor } from "./BlockNoteEditor.js";
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* @vitest-environment jsdom
|
|
7
10
|
*/
|
|
8
11
|
it("creates an editor", () => {
|
|
9
12
|
const editor = BlockNoteEditor.create();
|
|
10
|
-
const
|
|
11
|
-
|
|
13
|
+
const posInfo = getNearestBlockContainerPos(
|
|
14
|
+
editor._tiptapEditor.state.doc,
|
|
15
|
+
2
|
|
16
|
+
);
|
|
17
|
+
const { blockContent } = getBlockInfo(posInfo);
|
|
18
|
+
expect(blockContent.node.type.name).toEqual("paragraph");
|
|
12
19
|
});
|
|
13
20
|
|
|
14
21
|
it("immediately replaces doc", async () => {
|
|
@@ -66,7 +73,7 @@ it("adds id attribute when requested", async () => {
|
|
|
66
73
|
"This is a normal text\n\n# And this is a large heading"
|
|
67
74
|
);
|
|
68
75
|
editor.replaceBlocks(editor.document, blocks);
|
|
69
|
-
expect(
|
|
70
|
-
|
|
71
|
-
)
|
|
76
|
+
expect(await editor.blocksToFullHTML(editor.document)).toMatchInlineSnapshot(
|
|
77
|
+
`"<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1" id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1" id="1"><div class="bn-block-content" data-content-type="paragraph"><p class="bn-inline-content">This is a normal text</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="2" id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2" id="2"><div class="bn-block-content" data-content-type="heading" data-level="1"><h1 class="bn-inline-content">And this is a large heading</h1></div></div></div></div>"`
|
|
78
|
+
);
|
|
72
79
|
});
|
|
@@ -2,37 +2,38 @@ import { EditorOptions, Extension, getSchema } from "@tiptap/core";
|
|
|
2
2
|
import { Node, Schema } from "prosemirror-model";
|
|
3
3
|
// import "./blocknote.css";
|
|
4
4
|
import * as Y from "yjs";
|
|
5
|
+
import { insertBlocks } from "../api/blockManipulation/commands/insertBlocks/insertBlocks.js";
|
|
5
6
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "../api/blockManipulation/
|
|
12
|
-
import {
|
|
13
|
-
import { blocksToMarkdown } from "../api/exporters/markdown/markdownExporter";
|
|
14
|
-
import { getBlockInfoFromPos } from "../api/getBlockInfoFromPos";
|
|
7
|
+
moveBlockDown,
|
|
8
|
+
moveBlockUp,
|
|
9
|
+
} from "../api/blockManipulation/commands/moveBlock/moveBlock.js";
|
|
10
|
+
import { removeBlocks } from "../api/blockManipulation/commands/removeBlocks/removeBlocks.js";
|
|
11
|
+
import { replaceBlocks } from "../api/blockManipulation/commands/replaceBlocks/replaceBlocks.js";
|
|
12
|
+
import { updateBlock } from "../api/blockManipulation/commands/updateBlock/updateBlock.js";
|
|
13
|
+
import { insertContentAt } from "../api/blockManipulation/insertContentAt.js";
|
|
15
14
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from "../api/
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
15
|
+
getTextCursorPosition,
|
|
16
|
+
setTextCursorPosition,
|
|
17
|
+
} from "../api/blockManipulation/selections/textCursorPosition/textCursorPosition.js";
|
|
18
|
+
import { createExternalHTMLExporter } from "../api/exporters/html/externalHTMLExporter.js";
|
|
19
|
+
import { blocksToMarkdown } from "../api/exporters/markdown/markdownExporter.js";
|
|
20
|
+
import { getBlockInfoFromSelection } from "../api/getBlockInfoFromPos.js";
|
|
21
|
+
import { HTMLToBlocks } from "../api/parsers/html/parseHTML.js";
|
|
22
|
+
import { markdownToBlocks } from "../api/parsers/markdown/parseMarkdown.js";
|
|
22
23
|
import {
|
|
23
24
|
Block,
|
|
24
25
|
DefaultBlockSchema,
|
|
25
26
|
DefaultInlineContentSchema,
|
|
26
27
|
DefaultStyleSchema,
|
|
27
28
|
PartialBlock,
|
|
28
|
-
} from "../blocks/defaultBlocks";
|
|
29
|
-
import { FilePanelProsemirrorPlugin } from "../extensions/FilePanel/FilePanelPlugin";
|
|
30
|
-
import { FormattingToolbarProsemirrorPlugin } from "../extensions/FormattingToolbar/FormattingToolbarPlugin";
|
|
31
|
-
import { LinkToolbarProsemirrorPlugin } from "../extensions/LinkToolbar/LinkToolbarPlugin";
|
|
32
|
-
import { SideMenuProsemirrorPlugin } from "../extensions/SideMenu/SideMenuPlugin";
|
|
33
|
-
import { SuggestionMenuProseMirrorPlugin } from "../extensions/SuggestionMenu/SuggestionPlugin";
|
|
34
|
-
import { TableHandlesProsemirrorPlugin } from "../extensions/TableHandles/TableHandlesPlugin";
|
|
35
|
-
import { UniqueID } from "../extensions/UniqueID/UniqueID";
|
|
29
|
+
} from "../blocks/defaultBlocks.js";
|
|
30
|
+
import { FilePanelProsemirrorPlugin } from "../extensions/FilePanel/FilePanelPlugin.js";
|
|
31
|
+
import { FormattingToolbarProsemirrorPlugin } from "../extensions/FormattingToolbar/FormattingToolbarPlugin.js";
|
|
32
|
+
import { LinkToolbarProsemirrorPlugin } from "../extensions/LinkToolbar/LinkToolbarPlugin.js";
|
|
33
|
+
import { SideMenuProsemirrorPlugin } from "../extensions/SideMenu/SideMenuPlugin.js";
|
|
34
|
+
import { SuggestionMenuProseMirrorPlugin } from "../extensions/SuggestionMenu/SuggestionPlugin.js";
|
|
35
|
+
import { TableHandlesProsemirrorPlugin } from "../extensions/TableHandles/TableHandlesPlugin.js";
|
|
36
|
+
import { UniqueID } from "../extensions/UniqueID/UniqueID.js";
|
|
36
37
|
import {
|
|
37
38
|
BlockIdentifier,
|
|
38
39
|
BlockNoteDOMAttributes,
|
|
@@ -44,32 +45,34 @@ import {
|
|
|
44
45
|
StyleSchema,
|
|
45
46
|
StyleSpecs,
|
|
46
47
|
Styles,
|
|
47
|
-
} from "../schema";
|
|
48
|
-
import { mergeCSSClasses } from "../util/browser";
|
|
49
|
-
import { NoInfer, UnreachableCaseError } from "../util/typescript";
|
|
48
|
+
} from "../schema/index.js";
|
|
49
|
+
import { mergeCSSClasses } from "../util/browser.js";
|
|
50
|
+
import { NoInfer, UnreachableCaseError } from "../util/typescript.js";
|
|
50
51
|
|
|
51
|
-
import { getBlockNoteExtensions } from "./BlockNoteExtensions";
|
|
52
|
-
import { TextCursorPosition } from "./cursorPositionTypes";
|
|
52
|
+
import { getBlockNoteExtensions } from "./BlockNoteExtensions.js";
|
|
53
|
+
import { TextCursorPosition } from "./cursorPositionTypes.js";
|
|
53
54
|
|
|
54
|
-
import { Selection } from "./selectionTypes";
|
|
55
|
-
import { transformPasted } from "./transformPasted";
|
|
55
|
+
import { Selection } from "./selectionTypes.js";
|
|
56
|
+
import { transformPasted } from "./transformPasted.js";
|
|
56
57
|
|
|
57
|
-
import { checkDefaultBlockTypeInSchema } from "../blocks/defaultBlockTypeGuards";
|
|
58
|
-
import { BlockNoteSchema } from "./BlockNoteSchema";
|
|
58
|
+
import { checkDefaultBlockTypeInSchema } from "../blocks/defaultBlockTypeGuards.js";
|
|
59
|
+
import { BlockNoteSchema } from "./BlockNoteSchema.js";
|
|
59
60
|
import {
|
|
60
61
|
BlockNoteTipTapEditor,
|
|
61
62
|
BlockNoteTipTapEditorOptions,
|
|
62
|
-
} from "./BlockNoteTipTapEditor";
|
|
63
|
+
} from "./BlockNoteTipTapEditor.js";
|
|
63
64
|
|
|
64
|
-
import { PlaceholderPlugin } from "../extensions/Placeholder/PlaceholderPlugin";
|
|
65
|
-
import { Dictionary } from "../i18n/dictionary";
|
|
66
|
-
import { en } from "../i18n/locales";
|
|
65
|
+
import { PlaceholderPlugin } from "../extensions/Placeholder/PlaceholderPlugin.js";
|
|
66
|
+
import { Dictionary } from "../i18n/dictionary.js";
|
|
67
|
+
import { en } from "../i18n/locales/index.js";
|
|
67
68
|
|
|
68
69
|
import { Transaction } from "@tiptap/pm/state";
|
|
69
|
-
import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer";
|
|
70
|
-
import {
|
|
70
|
+
import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer.js";
|
|
71
|
+
import { inlineContentToNodes } from "../api/nodeConversions/blockToNode.js";
|
|
72
|
+
import { nodeToBlock } from "../api/nodeConversions/nodeToBlock.js";
|
|
73
|
+
import { NodeSelectionKeyboardPlugin } from "../extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js";
|
|
74
|
+
import { PreviousBlockTypePlugin } from "../extensions/PreviousBlockType/PreviousBlockTypePlugin.js";
|
|
71
75
|
import "../style.css";
|
|
72
|
-
import { initializeESMDependencies } from "../util/esmDependencies";
|
|
73
76
|
|
|
74
77
|
export type BlockNoteEditorOptions<
|
|
75
78
|
BSchema extends BlockSchema,
|
|
@@ -378,6 +381,7 @@ export class BlockNoteEditor<
|
|
|
378
381
|
...(this.filePanel ? [this.filePanel.plugin] : []),
|
|
379
382
|
...(this.tableHandles ? [this.tableHandles.plugin] : []),
|
|
380
383
|
PlaceholderPlugin(this, newOptions.placeholders),
|
|
384
|
+
NodeSelectionKeyboardPlugin(),
|
|
381
385
|
...(this.options.animations ?? true
|
|
382
386
|
? [PreviousBlockTypePlugin()]
|
|
383
387
|
: []),
|
|
@@ -659,61 +663,7 @@ export class BlockNoteEditor<
|
|
|
659
663
|
ISchema,
|
|
660
664
|
SSchema
|
|
661
665
|
> {
|
|
662
|
-
|
|
663
|
-
this._tiptapEditor.state.doc,
|
|
664
|
-
this._tiptapEditor.state.selection.from
|
|
665
|
-
)!;
|
|
666
|
-
|
|
667
|
-
// Index of the current blockContainer node relative to its parent blockGroup.
|
|
668
|
-
const nodeIndex = this._tiptapEditor.state.doc
|
|
669
|
-
.resolve(endPos)
|
|
670
|
-
.index(depth - 1);
|
|
671
|
-
// Number of the parent blockGroup's child blockContainer nodes.
|
|
672
|
-
const numNodes = this._tiptapEditor.state.doc
|
|
673
|
-
.resolve(endPos + 1)
|
|
674
|
-
.node().childCount;
|
|
675
|
-
|
|
676
|
-
// Gets previous blockContainer node at the same nesting level, if the current node isn't the first child.
|
|
677
|
-
let prevNode: Node | undefined = undefined;
|
|
678
|
-
if (nodeIndex > 0) {
|
|
679
|
-
prevNode = this._tiptapEditor.state.doc.resolve(startPos - 2).node();
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
// Gets next blockContainer node at the same nesting level, if the current node isn't the last child.
|
|
683
|
-
let nextNode: Node | undefined = undefined;
|
|
684
|
-
if (nodeIndex < numNodes - 1) {
|
|
685
|
-
nextNode = this._tiptapEditor.state.doc.resolve(endPos + 2).node();
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
return {
|
|
689
|
-
block: nodeToBlock(
|
|
690
|
-
node,
|
|
691
|
-
this.schema.blockSchema,
|
|
692
|
-
this.schema.inlineContentSchema,
|
|
693
|
-
this.schema.styleSchema,
|
|
694
|
-
this.blockCache
|
|
695
|
-
),
|
|
696
|
-
prevBlock:
|
|
697
|
-
prevNode === undefined
|
|
698
|
-
? undefined
|
|
699
|
-
: nodeToBlock(
|
|
700
|
-
prevNode,
|
|
701
|
-
this.schema.blockSchema,
|
|
702
|
-
this.schema.inlineContentSchema,
|
|
703
|
-
this.schema.styleSchema,
|
|
704
|
-
this.blockCache
|
|
705
|
-
),
|
|
706
|
-
nextBlock:
|
|
707
|
-
nextNode === undefined
|
|
708
|
-
? undefined
|
|
709
|
-
: nodeToBlock(
|
|
710
|
-
nextNode,
|
|
711
|
-
this.schema.blockSchema,
|
|
712
|
-
this.schema.inlineContentSchema,
|
|
713
|
-
this.schema.styleSchema,
|
|
714
|
-
this.blockCache
|
|
715
|
-
),
|
|
716
|
-
};
|
|
666
|
+
return getTextCursorPosition(this);
|
|
717
667
|
}
|
|
718
668
|
|
|
719
669
|
/**
|
|
@@ -726,44 +676,7 @@ export class BlockNoteEditor<
|
|
|
726
676
|
targetBlock: BlockIdentifier,
|
|
727
677
|
placement: "start" | "end" = "start"
|
|
728
678
|
) {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
const { posBeforeNode } = getNodeById(id, this._tiptapEditor.state.doc);
|
|
732
|
-
const { startPos, contentNode } = getBlockInfoFromPos(
|
|
733
|
-
this._tiptapEditor.state.doc,
|
|
734
|
-
posBeforeNode + 2
|
|
735
|
-
)!;
|
|
736
|
-
|
|
737
|
-
const contentType: "none" | "inline" | "table" =
|
|
738
|
-
this.schema.blockSchema[contentNode.type.name]!.content;
|
|
739
|
-
|
|
740
|
-
if (contentType === "none") {
|
|
741
|
-
this._tiptapEditor.commands.setNodeSelection(startPos);
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
if (contentType === "inline") {
|
|
746
|
-
if (placement === "start") {
|
|
747
|
-
this._tiptapEditor.commands.setTextSelection(startPos + 1);
|
|
748
|
-
} else {
|
|
749
|
-
this._tiptapEditor.commands.setTextSelection(
|
|
750
|
-
startPos + contentNode.nodeSize - 1
|
|
751
|
-
);
|
|
752
|
-
}
|
|
753
|
-
} else if (contentType === "table") {
|
|
754
|
-
if (placement === "start") {
|
|
755
|
-
// Need to offset the position as we have to get through the `tableRow`
|
|
756
|
-
// and `tableCell` nodes to get to the `tableParagraph` node we want to
|
|
757
|
-
// set the selection in.
|
|
758
|
-
this._tiptapEditor.commands.setTextSelection(startPos + 4);
|
|
759
|
-
} else {
|
|
760
|
-
this._tiptapEditor.commands.setTextSelection(
|
|
761
|
-
startPos + contentNode.nodeSize - 4
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
} else {
|
|
765
|
-
throw new UnreachableCaseError(contentType);
|
|
766
|
-
}
|
|
679
|
+
setTextCursorPosition(this, targetBlock, placement);
|
|
767
680
|
}
|
|
768
681
|
|
|
769
682
|
/**
|
|
@@ -858,14 +771,14 @@ export class BlockNoteEditor<
|
|
|
858
771
|
* @param blocksToInsert An array of partial blocks that should be inserted.
|
|
859
772
|
* @param referenceBlock An identifier for an existing block, at which the new blocks should be inserted.
|
|
860
773
|
* @param placement Whether the blocks should be inserted just before, just after, or nested inside the
|
|
861
|
-
* `referenceBlock`.
|
|
774
|
+
* `referenceBlock`.
|
|
862
775
|
*/
|
|
863
776
|
public insertBlocks(
|
|
864
777
|
blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[],
|
|
865
778
|
referenceBlock: BlockIdentifier,
|
|
866
|
-
placement: "before" | "after"
|
|
779
|
+
placement: "before" | "after" = "before"
|
|
867
780
|
) {
|
|
868
|
-
return insertBlocks(blocksToInsert, referenceBlock, placement
|
|
781
|
+
return insertBlocks(this, blocksToInsert, referenceBlock, placement);
|
|
869
782
|
}
|
|
870
783
|
|
|
871
784
|
/**
|
|
@@ -879,7 +792,7 @@ export class BlockNoteEditor<
|
|
|
879
792
|
blockToUpdate: BlockIdentifier,
|
|
880
793
|
update: PartialBlock<BSchema, ISchema, SSchema>
|
|
881
794
|
) {
|
|
882
|
-
return updateBlock(blockToUpdate, update
|
|
795
|
+
return updateBlock(this, blockToUpdate, update);
|
|
883
796
|
}
|
|
884
797
|
|
|
885
798
|
/**
|
|
@@ -887,7 +800,7 @@ export class BlockNoteEditor<
|
|
|
887
800
|
* @param blocksToRemove An array of identifiers for existing blocks that should be removed.
|
|
888
801
|
*/
|
|
889
802
|
public removeBlocks(blocksToRemove: BlockIdentifier[]) {
|
|
890
|
-
return removeBlocks(
|
|
803
|
+
return removeBlocks(this, blocksToRemove);
|
|
891
804
|
}
|
|
892
805
|
|
|
893
806
|
/**
|
|
@@ -901,7 +814,7 @@ export class BlockNoteEditor<
|
|
|
901
814
|
blocksToRemove: BlockIdentifier[],
|
|
902
815
|
blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[]
|
|
903
816
|
) {
|
|
904
|
-
return replaceBlocks(blocksToRemove, blocksToInsert
|
|
817
|
+
return replaceBlocks(this, blocksToRemove, blocksToInsert);
|
|
905
818
|
}
|
|
906
819
|
|
|
907
820
|
/**
|
|
@@ -1049,12 +962,14 @@ export class BlockNoteEditor<
|
|
|
1049
962
|
* Checks if the block containing the text cursor can be nested.
|
|
1050
963
|
*/
|
|
1051
964
|
public canNestBlock() {
|
|
1052
|
-
const {
|
|
1053
|
-
this._tiptapEditor.state
|
|
1054
|
-
|
|
1055
|
-
)!;
|
|
965
|
+
const { blockContainer } = getBlockInfoFromSelection(
|
|
966
|
+
this._tiptapEditor.state
|
|
967
|
+
);
|
|
1056
968
|
|
|
1057
|
-
return
|
|
969
|
+
return (
|
|
970
|
+
this._tiptapEditor.state.doc.resolve(blockContainer.beforePos)
|
|
971
|
+
.nodeBefore !== null
|
|
972
|
+
);
|
|
1058
973
|
}
|
|
1059
974
|
|
|
1060
975
|
/**
|
|
@@ -1068,12 +983,13 @@ export class BlockNoteEditor<
|
|
|
1068
983
|
* Checks if the block containing the text cursor is nested.
|
|
1069
984
|
*/
|
|
1070
985
|
public canUnnestBlock() {
|
|
1071
|
-
const {
|
|
1072
|
-
this._tiptapEditor.state
|
|
1073
|
-
|
|
1074
|
-
)!;
|
|
986
|
+
const { blockContainer } = getBlockInfoFromSelection(
|
|
987
|
+
this._tiptapEditor.state
|
|
988
|
+
);
|
|
1075
989
|
|
|
1076
|
-
return
|
|
990
|
+
return (
|
|
991
|
+
this._tiptapEditor.state.doc.resolve(blockContainer.beforePos).depth > 1
|
|
992
|
+
);
|
|
1077
993
|
}
|
|
1078
994
|
|
|
1079
995
|
/**
|
|
@@ -1083,6 +999,24 @@ export class BlockNoteEditor<
|
|
|
1083
999
|
this._tiptapEditor.commands.liftListItem("blockContainer");
|
|
1084
1000
|
}
|
|
1085
1001
|
|
|
1002
|
+
/**
|
|
1003
|
+
* Moves the block containing the text cursor up. If the previous block has
|
|
1004
|
+
* children, moves it to the end of its children. If there is no previous
|
|
1005
|
+
* block, but the current block is nested, moves it out of & before its parent.
|
|
1006
|
+
*/
|
|
1007
|
+
public moveBlockUp() {
|
|
1008
|
+
moveBlockUp(this);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
/**
|
|
1012
|
+
* Moves the block containing the text cursor down. If the next block has
|
|
1013
|
+
* children, moves it to the start of its children. If there is no next block,
|
|
1014
|
+
* but the current block is nested, moves it out of & after its parent.
|
|
1015
|
+
*/
|
|
1016
|
+
public moveBlockDown() {
|
|
1017
|
+
moveBlockDown(this);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1086
1020
|
/**
|
|
1087
1021
|
* Exports blocks into a simplified HTML string. To better conform to HTML standards, children of blocks which aren't list
|
|
1088
1022
|
* items are un-nested in the output HTML.
|
|
@@ -1093,7 +1027,6 @@ export class BlockNoteEditor<
|
|
|
1093
1027
|
public async blocksToHTMLLossy(
|
|
1094
1028
|
blocks: PartialBlock<BSchema, ISchema, SSchema>[] = this.document
|
|
1095
1029
|
): Promise<string> {
|
|
1096
|
-
await initializeESMDependencies();
|
|
1097
1030
|
const exporter = createExternalHTMLExporter(this.pmSchema, this);
|
|
1098
1031
|
return exporter.exportBlocks(blocks, {});
|
|
1099
1032
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Extension, Extensions, extensions } from "@tiptap/core";
|
|
2
2
|
|
|
3
|
-
import type { BlockNoteEditor } from "./BlockNoteEditor";
|
|
3
|
+
import type { BlockNoteEditor } from "./BlockNoteEditor.js";
|
|
4
4
|
|
|
5
5
|
import Collaboration from "@tiptap/extension-collaboration";
|
|
6
6
|
import CollaborationCursor from "@tiptap/extension-collaboration-cursor";
|
|
@@ -11,15 +11,16 @@ import { History } from "@tiptap/extension-history";
|
|
|
11
11
|
import { Link } from "@tiptap/extension-link";
|
|
12
12
|
import { Text } from "@tiptap/extension-text";
|
|
13
13
|
import * as Y from "yjs";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { BackgroundColorExtension } from "../extensions/BackgroundColor/BackgroundColorExtension";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import
|
|
22
|
-
import
|
|
14
|
+
import { createDropFileExtension } from "../api/clipboard/fromClipboard/fileDropExtension.js";
|
|
15
|
+
import { createPasteFromClipboardExtension } from "../api/clipboard/fromClipboard/pasteExtension.js";
|
|
16
|
+
import { createCopyToClipboardExtension } from "../api/clipboard/toClipboard/copyExtension.js";
|
|
17
|
+
import { BackgroundColorExtension } from "../extensions/BackgroundColor/BackgroundColorExtension.js";
|
|
18
|
+
import { KeyboardShortcutsExtension } from "../extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js";
|
|
19
|
+
import { TextAlignmentExtension } from "../extensions/TextAlignment/TextAlignmentExtension.js";
|
|
20
|
+
import { TextColorExtension } from "../extensions/TextColor/TextColorExtension.js";
|
|
21
|
+
import { TrailingNode } from "../extensions/TrailingNode/TrailingNodeExtension.js";
|
|
22
|
+
import UniqueID from "../extensions/UniqueID/UniqueID.js";
|
|
23
|
+
import { BlockContainer, BlockGroup, Doc } from "../pm-nodes/index.js";
|
|
23
24
|
import {
|
|
24
25
|
BlockNoteDOMAttributes,
|
|
25
26
|
BlockSchema,
|
|
@@ -28,7 +29,7 @@ import {
|
|
|
28
29
|
InlineContentSpecs,
|
|
29
30
|
StyleSchema,
|
|
30
31
|
StyleSpecs,
|
|
31
|
-
} from "../schema";
|
|
32
|
+
} from "../schema/index.js";
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Get all the Tiptap extensions BlockNote is configured with by default
|
|
@@ -120,6 +121,9 @@ export const getBlockNoteExtensions = <
|
|
|
120
121
|
editor: opts.editor,
|
|
121
122
|
domAttributes: opts.domAttributes,
|
|
122
123
|
}),
|
|
124
|
+
KeyboardShortcutsExtension.configure({
|
|
125
|
+
editor: opts.editor,
|
|
126
|
+
}),
|
|
123
127
|
BlockGroup.configure({
|
|
124
128
|
domAttributes: opts.domAttributes,
|
|
125
129
|
}),
|
|
@@ -2,7 +2,11 @@ import {
|
|
|
2
2
|
defaultBlockSpecs,
|
|
3
3
|
defaultInlineContentSpecs,
|
|
4
4
|
defaultStyleSpecs,
|
|
5
|
-
} from "../blocks/defaultBlocks";
|
|
5
|
+
} from "../blocks/defaultBlocks.js";
|
|
6
|
+
import type {
|
|
7
|
+
BlockNoDefaults,
|
|
8
|
+
PartialBlockNoDefaults,
|
|
9
|
+
} from "../schema/blocks/types.js";
|
|
6
10
|
import {
|
|
7
11
|
BlockSchema,
|
|
8
12
|
BlockSchemaFromSpecs,
|
|
@@ -16,12 +20,8 @@ import {
|
|
|
16
20
|
getBlockSchemaFromSpecs,
|
|
17
21
|
getInlineContentSchemaFromSpecs,
|
|
18
22
|
getStyleSchemaFromSpecs,
|
|
19
|
-
} from "../schema";
|
|
20
|
-
import type {
|
|
21
|
-
BlockNoDefaults,
|
|
22
|
-
PartialBlockNoDefaults,
|
|
23
|
-
} from "../schema/blocks/types";
|
|
24
|
-
import type { BlockNoteEditor } from "./BlockNoteEditor";
|
|
23
|
+
} from "../schema/index.js";
|
|
24
|
+
import type { BlockNoteEditor } from "./BlockNoteEditor.js";
|
|
25
25
|
|
|
26
26
|
function removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {
|
|
27
27
|
if (!obj) {
|