@blocknote/core 0.38.0 → 0.39.1-capitol
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/BlockNoteSchema-Bsa_tSAC.cjs +11 -0
- package/dist/BlockNoteSchema-Bsa_tSAC.cjs.map +1 -0
- package/dist/BlockNoteSchema-CZez1nQf.js +4244 -0
- package/dist/BlockNoteSchema-CZez1nQf.js.map +1 -0
- package/dist/blocknote.cjs +4 -12
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +3401 -7305
- package/dist/blocknote.js.map +1 -1
- package/dist/blocks.cjs +2 -0
- package/dist/blocks.cjs.map +1 -0
- package/dist/blocks.js +71 -0
- package/dist/blocks.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +19 -17
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +2 -2
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +34 -25
- package/src/api/blockManipulation/setupTestEnv.ts +0 -1
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +6 -10
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
- package/src/api/clipboard/toClipboard/copyExtension.ts +1 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +128 -28
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +101 -41
- package/src/api/pmUtil.ts +1 -1
- package/src/api/positionMapping.test.ts +58 -15
- package/src/api/positionMapping.ts +2 -4
- package/src/blocks/Audio/block.ts +174 -0
- package/src/blocks/BlockNoteSchema.ts +59 -0
- package/src/blocks/Code/block.ts +299 -0
- package/src/blocks/File/block.ts +98 -0
- package/src/blocks/{FileBlockContent → File}/helpers/render/createAddFileButton.ts +5 -2
- package/src/blocks/{FileBlockContent → File}/helpers/render/createFileBlockWrapper.ts +15 -6
- package/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.ts +15 -2
- package/src/blocks/{FileBlockContent → File}/helpers/render/createResizableFileBlockWrapper.ts +21 -2
- package/src/blocks/Heading/block.ts +138 -0
- package/src/blocks/Image/block.ts +190 -0
- package/src/blocks/ListItem/BulletListItem/block.ts +116 -0
- package/src/blocks/ListItem/CheckListItem/block.ts +175 -0
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +173 -0
- package/src/blocks/ListItem/NumberedListItem/block.ts +133 -0
- package/src/blocks/ListItem/ToggleListItem/block.ts +78 -0
- package/src/blocks/PageBreak/block.ts +72 -0
- package/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.ts +9 -7
- package/src/blocks/Paragraph/block.ts +80 -0
- package/src/blocks/Quote/block.ts +90 -0
- package/src/blocks/{TableBlockContent/TableBlockContent.ts → Table/block.ts} +169 -51
- package/src/blocks/ToggleWrapper/createToggleWrapper.ts +1 -1
- package/src/blocks/Video/block.ts +143 -0
- package/src/blocks/defaultBlockHelpers.ts +2 -2
- package/src/blocks/defaultBlockTypeGuards.ts +143 -174
- package/src/blocks/defaultBlocks.ts +107 -35
- package/src/blocks/defaultProps.ts +145 -4
- package/src/blocks/index.ts +26 -0
- package/src/blocks/utils/listItemEnterHandler.ts +42 -0
- package/src/editor/Block.css +54 -18
- package/src/editor/BlockNoteEditor.ts +256 -211
- package/src/editor/BlockNoteExtension.ts +92 -0
- package/src/editor/BlockNoteExtensions.ts +18 -17
- package/src/editor/defaultColors.ts +2 -2
- package/src/exporter/Exporter.ts +1 -1
- package/src/exporter/mapping.ts +1 -1
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +3 -20
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +6 -8
- package/src/extensions/BlockChange/BlockChangePlugin.ts +2 -1
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +2 -2
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +2 -2
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
- package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +52 -0
- package/src/extensions/Collaboration/schemaMigration/migrationRules/index.ts +4 -0
- package/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.ts +4 -0
- package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.ts +78 -0
- package/src/extensions/Comments/CommentsPlugin.ts +1 -1
- package/src/extensions/FilePanel/FilePanelPlugin.ts +5 -10
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -1
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +4 -3
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +6 -6
- package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +1 -23
- package/src/extensions/SideMenu/SideMenuPlugin.ts +1 -3
- package/src/extensions/SideMenu/dragging.ts +2 -2
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +4 -7
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +6 -2
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +24 -17
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +8 -8
- package/src/extensions/TextAlignment/TextAlignmentExtension.ts +5 -11
- package/src/extensions/TextColor/TextColorExtension.ts +3 -17
- package/src/extensions/TextColor/TextColorMark.ts +4 -9
- package/src/extensions/UniqueID/UniqueID.ts +6 -13
- package/src/index.ts +2 -28
- package/src/schema/blocks/createSpec.ts +342 -169
- package/src/schema/blocks/internal.ts +77 -138
- package/src/schema/blocks/types.ts +264 -94
- package/src/schema/index.ts +1 -0
- package/src/schema/inlineContent/createSpec.ts +99 -21
- package/src/schema/inlineContent/internal.ts +16 -7
- package/src/schema/inlineContent/types.ts +24 -2
- package/src/schema/propTypes.ts +15 -9
- package/src/schema/schema.ts +209 -0
- package/src/schema/styles/createSpec.ts +79 -31
- package/src/schema/styles/internal.ts +61 -2
- package/src/schema/styles/types.ts +17 -3
- package/src/util/topo-sort.test.ts +125 -0
- package/src/util/topo-sort.ts +160 -0
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +29 -543
- package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +1 -1
- package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +1 -1
- package/types/src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.d.ts +2 -0
- package/types/src/api/exporters/markdown/util/removeUnderlinesRehypePlugin.d.ts +6 -0
- package/types/src/api/pmUtil.d.ts +1 -1
- package/types/src/blocks/Audio/block.d.ts +58 -0
- package/types/src/blocks/BlockNoteSchema.d.ts +18 -0
- package/types/src/blocks/{CodeBlockContent/CodeBlockContent.d.ts → Code/block.d.ts} +25 -26
- package/types/src/blocks/Code/shiki.d.ts +4 -0
- package/types/src/blocks/Divider/block.d.ts +3 -0
- package/types/src/blocks/File/block.d.ts +37 -0
- package/types/src/blocks/File/helpers/render/createAddFileButton.d.ts +6 -0
- package/types/src/blocks/File/helpers/render/createFileBlockWrapper.d.ts +25 -0
- package/types/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.d.ts +6 -2
- package/types/src/blocks/File/helpers/render/createResizableFileBlockWrapper.d.ts +31 -0
- package/types/src/blocks/Heading/block.d.ts +71 -0
- package/types/src/blocks/Image/block.d.ts +102 -0
- package/types/src/blocks/ListItem/BulletListItem/block.d.ts +25 -0
- package/types/src/blocks/ListItem/CheckListItem/block.d.ts +33 -0
- package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.d.ts +8 -0
- package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +33 -0
- package/types/src/blocks/ListItem/ToggleListItem/block.d.ts +25 -0
- package/types/src/blocks/PageBreak/block.d.ts +11 -0
- package/types/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.d.ts +4 -2
- package/types/src/blocks/Paragraph/block.d.ts +25 -0
- package/types/src/blocks/Quote/block.d.ts +17 -0
- package/types/src/blocks/Table/block.d.ts +21 -0
- package/types/src/blocks/Video/block.d.ts +67 -0
- package/types/src/blocks/defaultBlockHelpers.d.ts +1 -1
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +15 -36
- package/types/src/blocks/defaultBlocks.d.ts +221 -1060
- package/types/src/blocks/defaultProps.d.ts +17 -1
- package/types/src/blocks/index.d.ts +24 -0
- package/types/src/blocks/utils/listItemEnterHandler.d.ts +2 -0
- package/types/src/editor/BlockNoteEditor.d.ts +36 -67
- package/types/src/editor/BlockNoteExtension.d.ts +67 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +1 -1
- package/types/src/editor/defaultColors.d.ts +8 -76
- package/types/src/editor/managers/BlockManager.d.ts +114 -0
- package/types/src/editor/managers/CollaborationManager.d.ts +115 -0
- package/types/src/editor/managers/EventManager.d.ts +58 -0
- package/types/src/editor/managers/ExportManager.d.ts +64 -0
- package/types/src/editor/managers/ExtensionManager.d.ts +68 -0
- package/types/src/editor/managers/SelectionManager.d.ts +54 -0
- package/types/src/editor/managers/StateManager.d.ts +115 -0
- package/types/src/editor/managers/StyleManager.d.ts +48 -0
- package/types/src/editor/managers/index.d.ts +8 -0
- package/types/src/exporter/Exporter.d.ts +1 -1
- package/types/src/exporter/mapping.d.ts +1 -1
- package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +4 -1
- package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +7 -0
- package/types/src/extensions/Collaboration/schemaMigration/migrationRules/index.d.ts +3 -0
- package/types/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.d.ts +3 -0
- package/types/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.d.ts +2 -0
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +1 -1
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
- package/types/src/extensions/TextColor/TextColorMark.d.ts +4 -1
- package/types/src/index.d.ts +2 -25
- package/types/src/schema/blocks/createSpec.d.ts +16 -36
- package/types/src/schema/blocks/internal.d.ts +11 -33
- package/types/src/schema/blocks/types.d.ts +181 -57
- package/types/src/schema/index.d.ts +1 -0
- package/types/src/schema/inlineContent/createSpec.d.ts +36 -2
- package/types/src/schema/inlineContent/internal.d.ts +7 -15
- package/types/src/schema/inlineContent/types.d.ts +15 -1
- package/types/src/schema/propTypes.d.ts +4 -4
- package/types/src/schema/schema.d.ts +40 -0
- package/types/src/schema/styles/createSpec.d.ts +6 -4
- package/types/src/schema/styles/internal.d.ts +6 -3
- package/types/src/schema/styles/types.d.ts +11 -2
- package/types/src/util/topo-sort.d.ts +18 -0
- package/types/src/util/topo-sort.test.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +0 -144
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +0 -445
- package/src/blocks/FileBlockContent/FileBlockContent.ts +0 -100
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +0 -159
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +0 -159
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +0 -134
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +0 -299
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +0 -86
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +0 -172
- package/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.ts +0 -104
- package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +0 -49
- package/src/blocks/PageBreakBlockContent/schema.ts +0 -40
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +0 -78
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +0 -121
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +0 -158
- package/src/editor/BlockNoteSchema.ts +0 -107
- package/src/editor/BlockNoteTipTapEditor.ts +0 -335
- package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +0 -99
- package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +0 -90
- package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +0 -6
- package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +0 -9
- package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +0 -9
- package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +0 -67
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +0 -131
- package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -46
- package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +0 -55
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -2
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -58
- package/types/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.d.ts +0 -46
- package/types/src/blocks/PageBreakBlockContent/PageBreakBlockContent.d.ts +0 -31
- package/types/src/blocks/PageBreakBlockContent/schema.d.ts +0 -86
- package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -52
- package/types/src/blocks/QuoteBlockContent/QuoteBlockContent.d.ts +0 -52
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -39
- package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +0 -131
- package/types/src/editor/BlockNoteSchema.d.ts +0 -34
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +0 -43
- /package/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.ts +0 -0
- /package/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
- /package/src/blocks/{ImageBlockContent → Image}/parseImageElement.ts +0 -0
- /package/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.ts +0 -0
- /package/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.ts +0 -0
- /package/src/blocks/{TableBlockContent → Table}/TableExtension.ts +0 -0
- /package/src/blocks/{VideoBlockContent → Video}/parseVideoElement.ts +0 -0
- /package/types/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
- /package/types/src/blocks/{ImageBlockContent → Image}/parseImageElement.d.ts +0 -0
- /package/types/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.d.ts +0 -0
- /package/types/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.d.ts +0 -0
- /package/types/src/blocks/{TableBlockContent → Table}/TableExtension.d.ts +0 -0
- /package/types/src/blocks/{VideoBlockContent → Video}/parseVideoElement.d.ts +0 -0
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AnyExtension,
|
|
3
|
+
createDocument,
|
|
3
4
|
EditorOptions,
|
|
4
5
|
Extension,
|
|
5
6
|
getSchema,
|
|
7
|
+
InputRule,
|
|
6
8
|
isNodeSelection,
|
|
7
9
|
Mark,
|
|
8
10
|
posToDOMRect,
|
|
11
|
+
Editor as TiptapEditor,
|
|
9
12
|
Node as TipTapNode,
|
|
10
13
|
} from "@tiptap/core";
|
|
14
|
+
import { redo, undo } from "@tiptap/pm/history";
|
|
15
|
+
import {
|
|
16
|
+
TextSelection,
|
|
17
|
+
type Command,
|
|
18
|
+
type Plugin,
|
|
19
|
+
type Transaction,
|
|
20
|
+
} from "@tiptap/pm/state";
|
|
21
|
+
import { dropCursor } from "prosemirror-dropcursor";
|
|
11
22
|
import { Node, Schema } from "prosemirror-model";
|
|
12
|
-
|
|
23
|
+
import { redoCommand, undoCommand, ySyncPluginKey } from "y-prosemirror";
|
|
13
24
|
import * as Y from "yjs";
|
|
25
|
+
|
|
14
26
|
import { insertBlocks } from "../api/blockManipulation/commands/insertBlocks/insertBlocks.js";
|
|
15
27
|
import {
|
|
16
28
|
moveBlocksDown,
|
|
@@ -23,7 +35,10 @@ import {
|
|
|
23
35
|
unnestBlock,
|
|
24
36
|
} from "../api/blockManipulation/commands/nestBlock/nestBlock.js";
|
|
25
37
|
import { removeAndInsertBlocks } from "../api/blockManipulation/commands/replaceBlocks/replaceBlocks.js";
|
|
26
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
updateBlock,
|
|
40
|
+
updateBlockTr,
|
|
41
|
+
} from "../api/blockManipulation/commands/updateBlock/updateBlock.js";
|
|
27
42
|
import {
|
|
28
43
|
getBlock,
|
|
29
44
|
getNextBlock,
|
|
@@ -41,19 +56,28 @@ import {
|
|
|
41
56
|
setTextCursorPosition,
|
|
42
57
|
} from "../api/blockManipulation/selections/textCursorPosition.js";
|
|
43
58
|
import { createExternalHTMLExporter } from "../api/exporters/html/externalHTMLExporter.js";
|
|
59
|
+
import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer.js";
|
|
44
60
|
import { blocksToMarkdown } from "../api/exporters/markdown/markdownExporter.js";
|
|
61
|
+
import { getBlockInfoFromTransaction } from "../api/getBlockInfoFromPos.js";
|
|
62
|
+
import {
|
|
63
|
+
BlocksChanged,
|
|
64
|
+
getBlocksChangedByTransaction,
|
|
65
|
+
} from "../api/getBlocksChangedByTransaction.js";
|
|
66
|
+
import {
|
|
67
|
+
blockToNode,
|
|
68
|
+
inlineContentToNodes,
|
|
69
|
+
} from "../api/nodeConversions/blockToNode.js";
|
|
70
|
+
import { docToBlocks } from "../api/nodeConversions/nodeToBlock.js";
|
|
45
71
|
import { HTMLToBlocks } from "../api/parsers/html/parseHTML.js";
|
|
46
72
|
import {
|
|
47
73
|
markdownToBlocks,
|
|
48
74
|
markdownToHTML,
|
|
49
75
|
} from "../api/parsers/markdown/parseMarkdown.js";
|
|
50
|
-
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
PartialBlock,
|
|
56
|
-
} from "../blocks/defaultBlocks.js";
|
|
76
|
+
import { editorHasBlockWithType } from "../blocks/defaultBlockTypeGuards.js";
|
|
77
|
+
import type { ThreadStore, User } from "../comments/index.js";
|
|
78
|
+
import { BlockChangePlugin } from "../extensions/BlockChange/BlockChangePlugin.js";
|
|
79
|
+
import type { CursorPlugin } from "../extensions/Collaboration/CursorPlugin.js";
|
|
80
|
+
import type { ForkYDocPlugin } from "../extensions/Collaboration/ForkYDocPlugin.js";
|
|
57
81
|
import type { CommentsPlugin } from "../extensions/Comments/CommentsPlugin.js";
|
|
58
82
|
import { FilePanelProsemirrorPlugin } from "../extensions/FilePanel/FilePanelPlugin.js";
|
|
59
83
|
import { FormattingToolbarProsemirrorPlugin } from "../extensions/FormattingToolbar/FormattingToolbarPlugin.js";
|
|
@@ -63,11 +87,14 @@ import { SideMenuProsemirrorPlugin } from "../extensions/SideMenu/SideMenuPlugin
|
|
|
63
87
|
import { SuggestionMenuProseMirrorPlugin } from "../extensions/SuggestionMenu/SuggestionPlugin.js";
|
|
64
88
|
import { TableHandlesProsemirrorPlugin } from "../extensions/TableHandles/TableHandlesPlugin.js";
|
|
65
89
|
import { UniqueID } from "../extensions/UniqueID/UniqueID.js";
|
|
90
|
+
import { Dictionary } from "../i18n/dictionary.js";
|
|
91
|
+
import { en } from "../i18n/locales/index.js";
|
|
66
92
|
import {
|
|
67
93
|
BlockIdentifier,
|
|
68
94
|
BlockNoteDOMAttributes,
|
|
69
95
|
BlockSchema,
|
|
70
96
|
BlockSpecs,
|
|
97
|
+
CustomBlockNoteSchema,
|
|
71
98
|
InlineContentSchema,
|
|
72
99
|
InlineContentSpecs,
|
|
73
100
|
PartialInlineContent,
|
|
@@ -75,49 +102,25 @@ import {
|
|
|
75
102
|
StyleSchema,
|
|
76
103
|
StyleSpecs,
|
|
77
104
|
} from "../schema/index.js";
|
|
105
|
+
import "../style.css";
|
|
78
106
|
import { mergeCSSClasses } from "../util/browser.js";
|
|
107
|
+
import { EventEmitter } from "../util/EventEmitter.js";
|
|
79
108
|
import { NoInfer, UnreachableCaseError } from "../util/typescript.js";
|
|
80
|
-
|
|
109
|
+
import { BlockNoteExtension } from "./BlockNoteExtension.js";
|
|
81
110
|
import { getBlockNoteExtensions } from "./BlockNoteExtensions.js";
|
|
82
111
|
import { TextCursorPosition } from "./cursorPositionTypes.js";
|
|
83
|
-
|
|
84
112
|
import { Selection } from "./selectionTypes.js";
|
|
85
113
|
import { transformPasted } from "./transformPasted.js";
|
|
86
114
|
|
|
87
|
-
|
|
88
|
-
import { BlockNoteSchema } from "./BlockNoteSchema.js";
|
|
89
|
-
import {
|
|
90
|
-
BlockNoteTipTapEditor,
|
|
91
|
-
BlockNoteTipTapEditorOptions,
|
|
92
|
-
} from "./BlockNoteTipTapEditor.js";
|
|
93
|
-
|
|
94
|
-
import { Dictionary } from "../i18n/dictionary.js";
|
|
95
|
-
import { en } from "../i18n/locales/index.js";
|
|
96
|
-
|
|
97
|
-
import { redo, undo } from "@tiptap/pm/history";
|
|
98
|
-
import {
|
|
99
|
-
TextSelection,
|
|
100
|
-
type Command,
|
|
101
|
-
type Plugin,
|
|
102
|
-
type Transaction,
|
|
103
|
-
} from "@tiptap/pm/state";
|
|
104
|
-
import { dropCursor } from "prosemirror-dropcursor";
|
|
105
|
-
import { EditorView } from "prosemirror-view";
|
|
106
|
-
import { redoCommand, undoCommand, ySyncPluginKey } from "y-prosemirror";
|
|
107
|
-
import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer.js";
|
|
115
|
+
// TODO eventually we will want to de-couple this from the editor instance, for now it provides a default schema to use
|
|
108
116
|
import {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
import { BlockChangePlugin } from "../extensions/BlockChange/BlockChangePlugin.js";
|
|
117
|
-
import type { CursorPlugin } from "../extensions/Collaboration/CursorPlugin.js";
|
|
118
|
-
import type { ForkYDocPlugin } from "../extensions/Collaboration/ForkYDocPlugin.js";
|
|
119
|
-
import { EventEmitter } from "../util/EventEmitter.js";
|
|
120
|
-
import { BlockNoteExtension } from "./BlockNoteExtension.js";
|
|
117
|
+
Block,
|
|
118
|
+
BlockNoteSchema,
|
|
119
|
+
DefaultBlockSchema,
|
|
120
|
+
DefaultInlineContentSchema,
|
|
121
|
+
DefaultStyleSchema,
|
|
122
|
+
PartialBlock,
|
|
123
|
+
} from "../blocks/index.js";
|
|
121
124
|
|
|
122
125
|
import "../style.css";
|
|
123
126
|
|
|
@@ -188,11 +191,6 @@ export type BlockNoteEditorOptions<
|
|
|
188
191
|
showCursorLabels?: "always" | "activity";
|
|
189
192
|
};
|
|
190
193
|
|
|
191
|
-
/**
|
|
192
|
-
* Options for code blocks.
|
|
193
|
-
*/
|
|
194
|
-
codeBlock?: CodeBlockOptions;
|
|
195
|
-
|
|
196
194
|
/**
|
|
197
195
|
* Configuration for the comments feature, requires a `threadStore`.
|
|
198
196
|
*
|
|
@@ -252,18 +250,6 @@ export type BlockNoteEditorOptions<
|
|
|
252
250
|
class?: string;
|
|
253
251
|
}) => Plugin;
|
|
254
252
|
|
|
255
|
-
/**
|
|
256
|
-
* Configuration for headings
|
|
257
|
-
*/
|
|
258
|
-
heading?: {
|
|
259
|
-
/**
|
|
260
|
-
* The levels of headings that should be available in the editor.
|
|
261
|
-
* @note Configurable up to 6 levels of headings.
|
|
262
|
-
* @default [1, 2, 3]
|
|
263
|
-
*/
|
|
264
|
-
levels?: (1 | 2 | 3 | 4 | 5 | 6)[];
|
|
265
|
-
};
|
|
266
|
-
|
|
267
253
|
/**
|
|
268
254
|
* The content that should be in the editor when it's created, represented as an array of {@link PartialBlock} objects.
|
|
269
255
|
*
|
|
@@ -303,7 +289,11 @@ export type BlockNoteEditorOptions<
|
|
|
303
289
|
*/
|
|
304
290
|
pasteHandler?: (context: {
|
|
305
291
|
event: ClipboardEvent;
|
|
306
|
-
editor: BlockNoteEditor<
|
|
292
|
+
editor: BlockNoteEditor<
|
|
293
|
+
NoInfer<BSchema>,
|
|
294
|
+
NoInfer<ISchema>,
|
|
295
|
+
NoInfer<SSchema>
|
|
296
|
+
>;
|
|
307
297
|
/**
|
|
308
298
|
* The default paste handler
|
|
309
299
|
* @param context The context object
|
|
@@ -343,7 +333,7 @@ export type BlockNoteEditorOptions<
|
|
|
343
333
|
* See [Custom Schemas](https://www.blocknotejs.org/docs/custom-schemas) for more info.
|
|
344
334
|
* @remarks `BlockNoteSchema`
|
|
345
335
|
*/
|
|
346
|
-
schema:
|
|
336
|
+
schema: CustomBlockNoteSchema<BSchema, ISchema, SSchema>;
|
|
347
337
|
|
|
348
338
|
/**
|
|
349
339
|
* A flag indicating whether to set an HTML ID for every block
|
|
@@ -443,19 +433,11 @@ export type BlockNoteEditorOptions<
|
|
|
443
433
|
/**
|
|
444
434
|
* Register extensions to the editor.
|
|
445
435
|
*
|
|
446
|
-
*
|
|
447
|
-
*/
|
|
448
|
-
extensions?: Array<BlockNoteExtension | BlockNoteExtensionFactory>;
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Boolean indicating whether the editor is in headless mode.
|
|
452
|
-
* Headless mode means we can use features like importing / exporting blocks,
|
|
453
|
-
* but there's no underlying editor (UI) instantiated.
|
|
436
|
+
* See [Extensions](/docs/features/extensions) for more info.
|
|
454
437
|
*
|
|
455
|
-
*
|
|
456
|
-
* @internal
|
|
438
|
+
* @remarks `BlockNoteExtension[]`
|
|
457
439
|
*/
|
|
458
|
-
|
|
440
|
+
extensions?: Array<BlockNoteExtension | BlockNoteExtensionFactory>;
|
|
459
441
|
};
|
|
460
442
|
|
|
461
443
|
const blockNoteTipTapOptions = {
|
|
@@ -481,19 +463,9 @@ export class BlockNoteEditor<
|
|
|
481
463
|
*/
|
|
482
464
|
public extensions: Record<string, SupportedExtension> = {};
|
|
483
465
|
|
|
484
|
-
|
|
485
|
-
* Boolean indicating whether the editor is in headless mode.
|
|
486
|
-
* Headless mode means we can use features like importing / exporting blocks,
|
|
487
|
-
* but there's no underlying editor (UI) instantiated.
|
|
488
|
-
*
|
|
489
|
-
* You probably don't need to set this manually, but use the `server-util` package instead that uses this option internally
|
|
490
|
-
*/
|
|
491
|
-
public readonly headless: boolean = false;
|
|
492
|
-
|
|
493
|
-
public readonly _tiptapEditor: Omit<BlockNoteTipTapEditor, "view"> & {
|
|
494
|
-
view: EditorView | undefined;
|
|
466
|
+
public readonly _tiptapEditor: TiptapEditor & {
|
|
495
467
|
contentComponent: any;
|
|
496
|
-
}
|
|
468
|
+
};
|
|
497
469
|
|
|
498
470
|
/**
|
|
499
471
|
* Used by React to store a reference to an `ElementRenderer` helper utility to make sure we can render React elements
|
|
@@ -517,7 +489,7 @@ export class BlockNoteEditor<
|
|
|
517
489
|
/**
|
|
518
490
|
* The schema of the editor. The schema defines which Blocks, InlineContent, and Styles are available in the editor.
|
|
519
491
|
*/
|
|
520
|
-
public readonly schema:
|
|
492
|
+
public readonly schema: CustomBlockNoteSchema<BSchema, ISchema, SSchema>;
|
|
521
493
|
|
|
522
494
|
public readonly blockImplementations: BlockSpecs;
|
|
523
495
|
public readonly inlineContentImplementations: InlineContentSpecs;
|
|
@@ -580,22 +552,27 @@ export class BlockNoteEditor<
|
|
|
580
552
|
cellTextColor: boolean;
|
|
581
553
|
headers: boolean;
|
|
582
554
|
};
|
|
583
|
-
codeBlock: CodeBlockOptions;
|
|
584
|
-
heading: {
|
|
585
|
-
levels: (1 | 2 | 3 | 4 | 5 | 6)[];
|
|
586
|
-
};
|
|
587
555
|
};
|
|
588
|
-
|
|
589
556
|
public static create<
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
557
|
+
Options extends Partial<BlockNoteEditorOptions<any, any, any>> | undefined,
|
|
558
|
+
>(
|
|
559
|
+
options?: Options,
|
|
560
|
+
): Options extends {
|
|
561
|
+
schema: CustomBlockNoteSchema<infer BSchema, infer ISchema, infer SSchema>;
|
|
562
|
+
}
|
|
563
|
+
? BlockNoteEditor<BSchema, ISchema, SSchema>
|
|
564
|
+
: BlockNoteEditor<
|
|
565
|
+
DefaultBlockSchema,
|
|
566
|
+
DefaultInlineContentSchema,
|
|
567
|
+
DefaultStyleSchema
|
|
568
|
+
> {
|
|
569
|
+
return new BlockNoteEditor(options ?? {}) as any;
|
|
595
570
|
}
|
|
596
571
|
|
|
597
572
|
protected constructor(
|
|
598
|
-
protected readonly options: Partial<
|
|
573
|
+
protected readonly options: Partial<
|
|
574
|
+
BlockNoteEditorOptions<BSchema, ISchema, SSchema>
|
|
575
|
+
>,
|
|
599
576
|
) {
|
|
600
577
|
super();
|
|
601
578
|
const anyOpts = options as any;
|
|
@@ -631,22 +608,18 @@ export class BlockNoteEditor<
|
|
|
631
608
|
cellTextColor: options?.tables?.cellTextColor ?? false,
|
|
632
609
|
headers: options?.tables?.headers ?? false,
|
|
633
610
|
},
|
|
634
|
-
codeBlock: {
|
|
635
|
-
indentLineWithTab: options?.codeBlock?.indentLineWithTab ?? true,
|
|
636
|
-
defaultLanguage: options?.codeBlock?.defaultLanguage ?? "text",
|
|
637
|
-
supportedLanguages: options?.codeBlock?.supportedLanguages ?? {},
|
|
638
|
-
createHighlighter: options?.codeBlock?.createHighlighter ?? undefined,
|
|
639
|
-
},
|
|
640
|
-
heading: {
|
|
641
|
-
levels: options?.heading?.levels ?? [1, 2, 3],
|
|
642
|
-
},
|
|
643
611
|
};
|
|
644
612
|
|
|
645
613
|
// apply defaults
|
|
646
614
|
const newOptions = {
|
|
647
615
|
defaultStyles: true,
|
|
648
|
-
schema:
|
|
649
|
-
|
|
616
|
+
schema:
|
|
617
|
+
options.schema ||
|
|
618
|
+
(BlockNoteSchema.create() as unknown as CustomBlockNoteSchema<
|
|
619
|
+
BSchema,
|
|
620
|
+
ISchema,
|
|
621
|
+
SSchema
|
|
622
|
+
>),
|
|
650
623
|
...options,
|
|
651
624
|
placeholders: {
|
|
652
625
|
...this.dictionary.placeholders,
|
|
@@ -660,7 +633,6 @@ export class BlockNoteEditor<
|
|
|
660
633
|
|
|
661
634
|
this.resolveUsers = newOptions.resolveUsers;
|
|
662
635
|
|
|
663
|
-
// @ts-ignore
|
|
664
636
|
this.schema = newOptions.schema;
|
|
665
637
|
this.blockImplementations = newOptions.schema.blockSpecs;
|
|
666
638
|
this.inlineContentImplementations = newOptions.schema.inlineContentSpecs;
|
|
@@ -677,7 +649,7 @@ export class BlockNoteEditor<
|
|
|
677
649
|
disableExtensions: newOptions.disableExtensions,
|
|
678
650
|
setIdAttribute: newOptions.setIdAttribute,
|
|
679
651
|
animations: newOptions.animations ?? true,
|
|
680
|
-
tableHandles:
|
|
652
|
+
tableHandles: editorHasBlockWithType(this, "table"),
|
|
681
653
|
dropCursor: this.options.dropCursor ?? dropCursor,
|
|
682
654
|
placeholders: newOptions.placeholders,
|
|
683
655
|
tabBehavior: newOptions.tabBehavior,
|
|
@@ -696,7 +668,7 @@ export class BlockNoteEditor<
|
|
|
696
668
|
// factory
|
|
697
669
|
ext = ext(this);
|
|
698
670
|
}
|
|
699
|
-
const key = (ext.constructor as any).key();
|
|
671
|
+
const key = (ext as any).key ?? (ext.constructor as any).key();
|
|
700
672
|
if (!key) {
|
|
701
673
|
throw new Error(
|
|
702
674
|
`Extension ${ext.constructor.name} does not have a key method`,
|
|
@@ -763,7 +735,6 @@ export class BlockNoteEditor<
|
|
|
763
735
|
}
|
|
764
736
|
|
|
765
737
|
this.resolveFileUrl = newOptions.resolveFileUrl;
|
|
766
|
-
this.headless = newOptions._headless;
|
|
767
738
|
|
|
768
739
|
const collaborationEnabled =
|
|
769
740
|
"ySyncPlugin" in this.extensions ||
|
|
@@ -776,57 +747,109 @@ export class BlockNoteEditor<
|
|
|
776
747
|
);
|
|
777
748
|
}
|
|
778
749
|
|
|
779
|
-
const
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
},
|
|
787
|
-
]
|
|
788
|
-
: [
|
|
789
|
-
{
|
|
790
|
-
type: "paragraph",
|
|
791
|
-
id: UniqueID.options.generateID(),
|
|
792
|
-
},
|
|
793
|
-
]);
|
|
794
|
-
|
|
795
|
-
if (!Array.isArray(initialContent) || initialContent.length === 0) {
|
|
796
|
-
throw new Error(
|
|
797
|
-
"initialContent must be a non-empty array of blocks, received: " +
|
|
798
|
-
initialContent,
|
|
799
|
-
);
|
|
800
|
-
}
|
|
801
|
-
|
|
750
|
+
const blockExtensions = Object.fromEntries(
|
|
751
|
+
Object.values(this.schema.blockSpecs)
|
|
752
|
+
.map((block) => (block as any).extensions as any)
|
|
753
|
+
.filter((ext) => ext !== undefined)
|
|
754
|
+
.flat()
|
|
755
|
+
.map((ext) => [ext.key ?? ext.constructor.key(), ext]),
|
|
756
|
+
);
|
|
802
757
|
const tiptapExtensions = [
|
|
803
|
-
...Object.entries(this.extensions).map(
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
758
|
+
...Object.entries({ ...this.extensions, ...blockExtensions }).map(
|
|
759
|
+
([key, ext]) => {
|
|
760
|
+
if (
|
|
761
|
+
ext instanceof Extension ||
|
|
762
|
+
ext instanceof TipTapNode ||
|
|
763
|
+
ext instanceof Mark
|
|
764
|
+
) {
|
|
765
|
+
// tiptap extension
|
|
766
|
+
return ext;
|
|
767
|
+
}
|
|
812
768
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
769
|
+
if (ext instanceof BlockNoteExtension) {
|
|
770
|
+
if (
|
|
771
|
+
!ext.plugins.length &&
|
|
772
|
+
!ext.keyboardShortcuts &&
|
|
773
|
+
!ext.inputRules &&
|
|
774
|
+
!ext.tiptapExtensions
|
|
775
|
+
) {
|
|
776
|
+
return undefined;
|
|
777
|
+
}
|
|
778
|
+
// "blocknote" extensions (prosemirror plugins)
|
|
779
|
+
return Extension.create({
|
|
780
|
+
name: key,
|
|
781
|
+
priority: ext.priority,
|
|
782
|
+
addProseMirrorPlugins: () => ext.plugins,
|
|
783
|
+
addExtensions: () => ext.tiptapExtensions || [],
|
|
784
|
+
// TODO maybe collect all input rules from all extensions into one plugin
|
|
785
|
+
// TODO consider using the prosemirror-inputrules package instead
|
|
786
|
+
addInputRules: ext.inputRules
|
|
787
|
+
? () =>
|
|
788
|
+
ext.inputRules!.map(
|
|
789
|
+
(inputRule) =>
|
|
790
|
+
new InputRule({
|
|
791
|
+
find: inputRule.find,
|
|
792
|
+
handler: ({ range, match, state }) => {
|
|
793
|
+
const replaceWith = inputRule.replace({
|
|
794
|
+
match,
|
|
795
|
+
range,
|
|
796
|
+
editor: this,
|
|
797
|
+
});
|
|
798
|
+
if (replaceWith) {
|
|
799
|
+
const cursorPosition =
|
|
800
|
+
this.getTextCursorPosition();
|
|
801
|
+
|
|
802
|
+
if (
|
|
803
|
+
this.schema.blockSchema[
|
|
804
|
+
cursorPosition.block.type
|
|
805
|
+
].content !== "inline"
|
|
806
|
+
) {
|
|
807
|
+
return undefined;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
const blockInfo = getBlockInfoFromTransaction(
|
|
811
|
+
state.tr,
|
|
812
|
+
);
|
|
813
|
+
const tr = state.tr.deleteRange(
|
|
814
|
+
range.from,
|
|
815
|
+
range.to,
|
|
816
|
+
);
|
|
817
|
+
|
|
818
|
+
updateBlockTr(
|
|
819
|
+
tr,
|
|
820
|
+
blockInfo.bnBlock.beforePos,
|
|
821
|
+
replaceWith,
|
|
822
|
+
);
|
|
823
|
+
return undefined;
|
|
824
|
+
}
|
|
825
|
+
return null;
|
|
826
|
+
},
|
|
827
|
+
}),
|
|
828
|
+
)
|
|
829
|
+
: undefined,
|
|
830
|
+
addKeyboardShortcuts: ext.keyboardShortcuts
|
|
831
|
+
? () => {
|
|
832
|
+
return Object.fromEntries(
|
|
833
|
+
Object.entries(ext.keyboardShortcuts!).map(
|
|
834
|
+
([key, value]) => [
|
|
835
|
+
key,
|
|
836
|
+
() => value({ editor: this as any }),
|
|
837
|
+
],
|
|
838
|
+
),
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
: undefined,
|
|
842
|
+
});
|
|
843
|
+
}
|
|
816
844
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
priority: ext.priority,
|
|
821
|
-
addProseMirrorPlugins: () => ext.plugins,
|
|
822
|
-
});
|
|
823
|
-
}),
|
|
845
|
+
return undefined;
|
|
846
|
+
},
|
|
847
|
+
),
|
|
824
848
|
].filter((ext): ext is Extension => ext !== undefined);
|
|
825
|
-
|
|
826
|
-
const tiptapOptions: BlockNoteTipTapEditorOptions = {
|
|
849
|
+
const tiptapOptions: EditorOptions = {
|
|
827
850
|
...blockNoteTipTapOptions,
|
|
828
851
|
...newOptions._tiptapOptions,
|
|
829
|
-
|
|
852
|
+
element: null,
|
|
830
853
|
extensions: tiptapExtensions,
|
|
831
854
|
editorProps: {
|
|
832
855
|
...newOptions._tiptapOptions?.editorProps,
|
|
@@ -845,22 +868,61 @@ export class BlockNoteEditor<
|
|
|
845
868
|
},
|
|
846
869
|
transformPasted,
|
|
847
870
|
},
|
|
848
|
-
};
|
|
871
|
+
} as any;
|
|
849
872
|
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
873
|
+
try {
|
|
874
|
+
const initialContent =
|
|
875
|
+
newOptions.initialContent ||
|
|
876
|
+
(collaborationEnabled
|
|
877
|
+
? [
|
|
878
|
+
{
|
|
879
|
+
type: "paragraph",
|
|
880
|
+
id: "initialBlockId",
|
|
881
|
+
},
|
|
882
|
+
]
|
|
883
|
+
: [
|
|
884
|
+
{
|
|
885
|
+
type: "paragraph",
|
|
886
|
+
id: UniqueID.options.generateID(),
|
|
887
|
+
},
|
|
888
|
+
]);
|
|
889
|
+
|
|
890
|
+
if (!Array.isArray(initialContent) || initialContent.length === 0) {
|
|
891
|
+
throw new Error(
|
|
892
|
+
"initialContent must be a non-empty array of blocks, received: " +
|
|
893
|
+
initialContent,
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
const schema = getSchema(tiptapOptions.extensions!);
|
|
897
|
+
const pmNodes = initialContent.map((b) =>
|
|
898
|
+
blockToNode(b, schema, this.schema.styleSchema).toJSON(),
|
|
899
|
+
);
|
|
900
|
+
const doc = createDocument(
|
|
901
|
+
{
|
|
902
|
+
type: "doc",
|
|
903
|
+
content: [
|
|
904
|
+
{
|
|
905
|
+
type: "blockGroup",
|
|
906
|
+
content: pmNodes,
|
|
907
|
+
},
|
|
908
|
+
],
|
|
909
|
+
},
|
|
910
|
+
schema,
|
|
911
|
+
tiptapOptions.parseOptions,
|
|
912
|
+
);
|
|
913
|
+
|
|
914
|
+
this._tiptapEditor = new TiptapEditor({
|
|
915
|
+
...tiptapOptions,
|
|
916
|
+
content: doc.toJSON(),
|
|
917
|
+
}) as any;
|
|
858
918
|
this.pmSchema = this._tiptapEditor.schema;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
919
|
+
} catch (e) {
|
|
920
|
+
throw new Error(
|
|
921
|
+
"Error creating document from blocks passed as `initialContent`",
|
|
922
|
+
{ cause: e },
|
|
923
|
+
);
|
|
863
924
|
}
|
|
925
|
+
|
|
864
926
|
this.pmSchema.cached.blockNoteEditor = this;
|
|
865
927
|
this.emit("create");
|
|
866
928
|
}
|
|
@@ -890,7 +952,7 @@ export class BlockNoteEditor<
|
|
|
890
952
|
}
|
|
891
953
|
const state = this._tiptapEditor.state;
|
|
892
954
|
const view = this._tiptapEditor.view;
|
|
893
|
-
const dispatch = (tr: Transaction) =>
|
|
955
|
+
const dispatch = (tr: Transaction) => view.dispatch(tr);
|
|
894
956
|
|
|
895
957
|
return command(state, dispatch, view);
|
|
896
958
|
}
|
|
@@ -973,7 +1035,7 @@ export class BlockNoteEditor<
|
|
|
973
1035
|
!activeTr.isGeneric)
|
|
974
1036
|
) {
|
|
975
1037
|
// Dispatch the transaction if it was modified
|
|
976
|
-
this._tiptapEditor.dispatch(activeTr);
|
|
1038
|
+
this._tiptapEditor.view.dispatch(activeTr);
|
|
977
1039
|
}
|
|
978
1040
|
|
|
979
1041
|
return result;
|
|
@@ -1002,17 +1064,21 @@ export class BlockNoteEditor<
|
|
|
1002
1064
|
}
|
|
1003
1065
|
return extension;
|
|
1004
1066
|
}
|
|
1005
|
-
|
|
1006
1067
|
/**
|
|
1007
|
-
* Mount the editor to a
|
|
1068
|
+
* Mount the editor to a DOM element.
|
|
1008
1069
|
*
|
|
1009
1070
|
* @warning Not needed to call manually when using React, use BlockNoteView to take care of mounting
|
|
1010
1071
|
*/
|
|
1011
|
-
public mount = (
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1072
|
+
public mount = (element: HTMLElement) => {
|
|
1073
|
+
// TODO: Fix typing for this in a TipTap PR
|
|
1074
|
+
this._tiptapEditor.mount({ mount: element } as any);
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Unmount the editor from the DOM element it is bound to
|
|
1079
|
+
*/
|
|
1080
|
+
public unmount = () => {
|
|
1081
|
+
this._tiptapEditor.unmount();
|
|
1016
1082
|
};
|
|
1017
1083
|
|
|
1018
1084
|
/**
|
|
@@ -1045,8 +1111,15 @@ export class BlockNoteEditor<
|
|
|
1045
1111
|
return this.prosemirrorView?.hasFocus() || false;
|
|
1046
1112
|
}
|
|
1047
1113
|
|
|
1114
|
+
public get headless() {
|
|
1115
|
+
return !this._tiptapEditor.isInitialized;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1048
1118
|
public focus() {
|
|
1049
|
-
this.
|
|
1119
|
+
if (this.headless) {
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
this.prosemirrorView.focus();
|
|
1050
1123
|
}
|
|
1051
1124
|
|
|
1052
1125
|
public onUploadStart(callback: (blockId?: string) => void) {
|
|
@@ -1263,12 +1336,6 @@ export class BlockNoteEditor<
|
|
|
1263
1336
|
* @returns True if the editor is editable, false otherwise.
|
|
1264
1337
|
*/
|
|
1265
1338
|
public get isEditable(): boolean {
|
|
1266
|
-
if (!this._tiptapEditor) {
|
|
1267
|
-
if (!this.headless) {
|
|
1268
|
-
throw new Error("no editor, but also not headless?");
|
|
1269
|
-
}
|
|
1270
|
-
return false;
|
|
1271
|
-
}
|
|
1272
1339
|
return this._tiptapEditor.isEditable === undefined
|
|
1273
1340
|
? true
|
|
1274
1341
|
: this._tiptapEditor.isEditable;
|
|
@@ -1279,13 +1346,6 @@ export class BlockNoteEditor<
|
|
|
1279
1346
|
* @param editable True to make the editor editable, or false to lock it.
|
|
1280
1347
|
*/
|
|
1281
1348
|
public set isEditable(editable: boolean) {
|
|
1282
|
-
if (!this._tiptapEditor) {
|
|
1283
|
-
if (!this.headless) {
|
|
1284
|
-
throw new Error("no editor, but also not headless?");
|
|
1285
|
-
}
|
|
1286
|
-
// not relevant on headless
|
|
1287
|
-
return;
|
|
1288
|
-
}
|
|
1289
1349
|
if (this._tiptapEditor.options.editable !== editable) {
|
|
1290
1350
|
this._tiptapEditor.setEditable(editable);
|
|
1291
1351
|
}
|
|
@@ -1662,12 +1722,6 @@ export class BlockNoteEditor<
|
|
|
1662
1722
|
},
|
|
1663
1723
|
) => boolean | void,
|
|
1664
1724
|
): () => void {
|
|
1665
|
-
if (this.headless) {
|
|
1666
|
-
return () => {
|
|
1667
|
-
// noop
|
|
1668
|
-
};
|
|
1669
|
-
}
|
|
1670
|
-
|
|
1671
1725
|
return (this.extensions["blockChange"] as BlockChangePlugin).subscribe(
|
|
1672
1726
|
(context) => callback(this, context),
|
|
1673
1727
|
);
|
|
@@ -1690,11 +1744,6 @@ export class BlockNoteEditor<
|
|
|
1690
1744
|
},
|
|
1691
1745
|
) => void,
|
|
1692
1746
|
) {
|
|
1693
|
-
if (this.headless) {
|
|
1694
|
-
// Note: would be nice if this is possible in headless mode as well
|
|
1695
|
-
return;
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
1747
|
const cb = ({
|
|
1699
1748
|
transaction,
|
|
1700
1749
|
appendedTransactions,
|
|
@@ -1708,10 +1757,10 @@ export class BlockNoteEditor<
|
|
|
1708
1757
|
});
|
|
1709
1758
|
};
|
|
1710
1759
|
|
|
1711
|
-
this._tiptapEditor.on("
|
|
1760
|
+
this._tiptapEditor.on("update", cb);
|
|
1712
1761
|
|
|
1713
1762
|
return () => {
|
|
1714
|
-
this._tiptapEditor.off("
|
|
1763
|
+
this._tiptapEditor.off("update", cb);
|
|
1715
1764
|
};
|
|
1716
1765
|
}
|
|
1717
1766
|
|
|
@@ -1725,10 +1774,6 @@ export class BlockNoteEditor<
|
|
|
1725
1774
|
callback: (editor: BlockNoteEditor<BSchema, ISchema, SSchema>) => void,
|
|
1726
1775
|
includeSelectionChangedByRemote?: boolean,
|
|
1727
1776
|
) {
|
|
1728
|
-
if (this.headless) {
|
|
1729
|
-
return;
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
1777
|
const cb = (e: { transaction: Transaction }) => {
|
|
1733
1778
|
if (
|
|
1734
1779
|
e.transaction.getMeta(ySyncPluginKey) &&
|