@blocknote/core 0.30.0 → 0.31.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.cjs +9 -9
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +2771 -2245
- package/dist/blocknote.js.map +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js.map +1 -1
- package/dist/{en-D4taoCs4.cjs → en-BXVKCwYt.cjs} +2 -2
- package/dist/en-BXVKCwYt.cjs.map +1 -0
- package/dist/{en-B7ycW7c8.js → en-qGo6sk9V.js} +2 -3
- package/dist/en-qGo6sk9V.js.map +1 -0
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +20 -39
- package/dist/locales.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +8 -7
- package/src/api/README.md +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +7 -8
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +12 -12
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +14 -14
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +16 -16
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +8 -8
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +8 -8
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +10 -10
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +2 -2
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2816 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +200 -42
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +104 -34
- package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
- package/src/api/blockManipulation/insertContentAt.ts +1 -1
- package/src/api/blockManipulation/selections/selection.ts +59 -12
- package/src/api/blockManipulation/selections/{textCursorPosition/textCursorPosition.ts → textCursorPosition.ts} +13 -13
- package/src/api/blockManipulation/tables/tables.test.ts +106 -106
- package/src/api/blockManipulation/tables/tables.ts +35 -35
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +2 -2
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +9 -9
- package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +3 -3
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +3 -3
- package/src/api/clipboard/toClipboard/copyExtension.ts +22 -22
- package/src/api/exporters/html/externalHTMLExporter.ts +6 -6
- package/src/api/exporters/html/internalHTMLSerializer.ts +3 -3
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +16 -16
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +14 -14
- package/src/api/exporters/markdown/markdownExporter.ts +3 -3
- package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +3 -3
- package/src/api/getBlockInfoFromPos.ts +6 -6
- package/src/api/nodeConversions/blockToNode.ts +31 -28
- package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
- package/src/api/nodeConversions/nodeToBlock.ts +240 -41
- package/src/api/nodeUtil.test.ts +16 -16
- package/src/api/nodeUtil.ts +10 -10
- package/src/api/parsers/html/parseHTML.ts +1 -1
- package/src/api/parsers/html/util/nestedLists.ts +2 -2
- package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
- package/src/api/pmUtil.ts +7 -7
- package/src/api/positionMapping.test.ts +3 -3
- package/src/api/positionMapping.ts +5 -5
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +4 -4
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +18 -18
- package/src/blocks/FileBlockContent/FileBlockContent.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +6 -6
- package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +1 -1
- package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +7 -7
- package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +1 -1
- package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +1 -1
- package/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +2 -2
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +6 -6
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +4 -4
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +4 -4
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +10 -10
- package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +4 -4
- package/src/blocks/ListItemBlockContent/getListItemContent.ts +5 -5
- package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +1 -1
- package/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.ts +3 -3
- package/src/blocks/PageBreakBlockContent/schema.ts +2 -2
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +3 -3
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +4 -4
- package/src/blocks/README.md +1 -1
- package/src/blocks/TableBlockContent/TableBlockContent.ts +37 -7
- package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +4 -4
- package/src/blocks/defaultBlockHelpers.ts +8 -8
- package/src/blocks/defaultBlockTypeGuards.ts +16 -16
- package/src/blocks/defaultBlocks.ts +3 -3
- package/src/comments/threadstore/DefaultThreadStoreAuth.ts +3 -3
- package/src/comments/threadstore/ThreadStore.ts +1 -1
- package/src/comments/threadstore/TipTapThreadStore.ts +10 -10
- package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +4 -4
- package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +2 -2
- package/src/comments/threadstore/yjs/YjsThreadStore.ts +14 -14
- package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +1 -1
- package/src/comments/threadstore/yjs/yjsHelpers.ts +6 -6
- package/src/editor/Block.css +35 -1
- package/src/editor/BlockNoteEditor.test.ts +10 -3
- package/src/editor/BlockNoteEditor.ts +95 -38
- package/src/editor/BlockNoteExtension.ts +26 -0
- package/src/editor/BlockNoteExtensions.ts +38 -22
- package/src/editor/BlockNoteSchema.ts +4 -4
- package/src/editor/BlockNoteTipTapEditor.ts +33 -12
- package/src/editor/README.md +1 -1
- package/src/editor/cursorPositionTypes.ts +1 -1
- package/src/editor/editor.css +15 -3
- package/src/editor/selectionTypes.ts +1 -1
- package/src/editor/transformPasted.ts +2 -2
- package/src/exporter/Exporter.ts +5 -5
- package/src/exporter/mapping.ts +7 -7
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
- package/src/extensions/Collaboration/CursorPlugin.ts +15 -9
- package/src/extensions/Collaboration/ForkYDocPlugin.test.ts +166 -0
- package/src/extensions/Collaboration/ForkYDocPlugin.ts +174 -0
- package/src/extensions/Collaboration/SyncPlugin.ts +7 -4
- package/src/extensions/Collaboration/UndoPlugin.ts +7 -4
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +30 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +30 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -0
- package/src/extensions/Comments/CommentsPlugin.ts +80 -75
- package/src/extensions/Comments/userstore/UserStore.ts +2 -2
- package/src/extensions/FilePanel/FilePanelPlugin.ts +56 -55
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +60 -30
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +26 -26
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +33 -32
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +45 -42
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +113 -110
- package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +179 -170
- package/src/extensions/README.md +1 -1
- package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +22 -19
- package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
- package/src/extensions/SideMenu/SideMenuPlugin.ts +49 -48
- package/src/extensions/SideMenu/dragging.ts +8 -8
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +176 -176
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +16 -16
- package/src/extensions/Suggestions/SuggestionMarks.ts +175 -0
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +199 -195
- package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
- package/src/extensions/UniqueID/UniqueID.ts +6 -6
- package/src/extensions/getDraggableBlockFromElement.ts +1 -1
- package/src/fonts/inter.css +18 -9
- package/src/i18n/locales/ar.ts +0 -1
- package/src/i18n/locales/de.ts +0 -1
- package/src/i18n/locales/en.ts +0 -1
- package/src/i18n/locales/es.ts +0 -1
- package/src/i18n/locales/fr.ts +0 -1
- package/src/i18n/locales/hr.ts +0 -1
- package/src/i18n/locales/is.ts +0 -1
- package/src/i18n/locales/it.ts +0 -1
- package/src/i18n/locales/ja.ts +0 -1
- package/src/i18n/locales/ko.ts +0 -1
- package/src/i18n/locales/nl.ts +0 -1
- package/src/i18n/locales/no.ts +0 -1
- package/src/i18n/locales/pl.ts +0 -1
- package/src/i18n/locales/pt.ts +0 -1
- package/src/i18n/locales/ru.ts +0 -1
- package/src/i18n/locales/sk.ts +0 -1
- package/src/i18n/locales/uk.ts +0 -1
- package/src/i18n/locales/vi.ts +0 -1
- package/src/i18n/locales/zh-tw.ts +0 -1
- package/src/i18n/locales/zh.ts +0 -1
- package/src/index.ts +18 -8
- package/src/locales.ts +1 -1
- package/src/pm-nodes/BlockContainer.ts +1 -1
- package/src/pm-nodes/BlockGroup.ts +2 -2
- package/src/pm-nodes/Doc.ts +5 -4
- package/src/schema/README.md +1 -1
- package/src/schema/blocks/createSpec.ts +14 -14
- package/src/schema/blocks/internal.ts +17 -17
- package/src/schema/blocks/types.ts +25 -25
- package/src/schema/inlineContent/createSpec.ts +16 -20
- package/src/schema/inlineContent/internal.ts +9 -9
- package/src/schema/inlineContent/types.ts +26 -26
- package/src/schema/propTypes.ts +8 -8
- package/src/schema/styles/createSpec.ts +2 -2
- package/src/schema/styles/internal.ts +7 -7
- package/src/schema/styles/types.ts +2 -2
- package/src/util/EventEmitter.ts +4 -4
- package/src/util/README.md +1 -1
- package/src/util/combineByGroup.ts +1 -1
- package/src/util/table.ts +33 -30
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +1 -1
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +4 -0
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +3 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +10 -0
- package/types/src/api/blockManipulation/selections/textCursorPosition.d.ts +5 -0
- package/types/src/api/blockManipulation/transactions.test.d.ts +0 -0
- package/types/src/api/clipboard/clipboardExternal.test.d.ts +1 -0
- package/types/src/api/clipboard/clipboardInternal.test.d.ts +1 -0
- package/types/src/api/clipboard/testUtil.d.ts +541 -0
- package/types/src/api/exporters/html/htmlConversion.test.d.ts +1 -0
- package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +1 -0
- package/types/src/api/nodeConversions/nodeConversions.test.d.ts +1 -0
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +39 -2
- package/types/src/api/parsers/html/parseHTML.test.d.ts +1 -0
- package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +1 -0
- package/types/src/api/pmUtil.d.ts +3 -3
- package/types/src/api/testUtil/cases/customBlocks.d.ts +670 -0
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +558 -0
- package/types/src/api/testUtil/cases/customStyles.d.ts +552 -0
- package/types/src/api/testUtil/cases/defaultSchema.d.ts +4 -0
- package/types/src/api/testUtil/index.d.ts +14 -0
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +9 -0
- package/types/src/api/testUtil/paste.d.ts +2 -0
- package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +6 -0
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +9 -1
- package/types/src/editor/BlockNoteEditor.d.ts +58 -10
- package/types/src/editor/BlockNoteExtension.d.ts +9 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +2 -2
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
- package/types/src/extensions/Collaboration/CursorPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +41 -0
- package/types/src/extensions/Collaboration/ForkYDocPlugin.test.d.ts +1 -0
- package/types/src/extensions/Collaboration/SyncPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/UndoPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +17 -0
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +2 -4
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +3 -4
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +5 -5
- package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +3 -4
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -3
- package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +2 -3
- package/types/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.d.ts +2 -3
- package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +2 -3
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +3 -4
- package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +2 -4
- package/types/src/extensions/Suggestions/SuggestionMarks.d.ts +4 -0
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +5 -6
- package/types/src/i18n/locales/en.d.ts +0 -1
- package/types/src/i18n/locales/sk.d.ts +0 -1
- package/types/src/index.d.ts +15 -8
- package/dist/en-B7ycW7c8.js.map +0 -1
- package/dist/en-D4taoCs4.cjs.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +0 -844
- package/src/api/blockManipulation/selections/selection.test.ts +0 -72
- package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +0 -316
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +0 -74
|
@@ -3,20 +3,20 @@ import {
|
|
|
3
3
|
EditorState,
|
|
4
4
|
Plugin,
|
|
5
5
|
PluginKey,
|
|
6
|
-
TextSelection,
|
|
7
6
|
PluginView,
|
|
7
|
+
TextSelection,
|
|
8
8
|
} from "@tiptap/pm/state";
|
|
9
9
|
import { EditorView } from "@tiptap/pm/view";
|
|
10
10
|
|
|
11
11
|
import { Block } from "../../blocks/defaultBlocks.js";
|
|
12
12
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
13
|
+
import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
13
14
|
import { UiElementPosition } from "../../extensions-shared/UiElementPosition.js";
|
|
14
15
|
import {
|
|
15
16
|
BlockSchema,
|
|
16
17
|
InlineContentSchema,
|
|
17
18
|
StyleSchema,
|
|
18
19
|
} from "../../schema/index.js";
|
|
19
|
-
import { EventEmitter } from "../../util/EventEmitter.js";
|
|
20
20
|
import { initializeESMDependencies } from "../../util/esmDependencies.js";
|
|
21
21
|
import { getDraggableBlockFromElement } from "../getDraggableBlockFromElement.js";
|
|
22
22
|
import { dragStart, unsetDragImage } from "./dragging.js";
|
|
@@ -24,7 +24,7 @@ import { dragStart, unsetDragImage } from "./dragging.js";
|
|
|
24
24
|
export type SideMenuState<
|
|
25
25
|
BSchema extends BlockSchema,
|
|
26
26
|
I extends InlineContentSchema,
|
|
27
|
-
S extends StyleSchema
|
|
27
|
+
S extends StyleSchema,
|
|
28
28
|
> = UiElementPosition & {
|
|
29
29
|
// The block that the side menu is attached to.
|
|
30
30
|
block: Block<BSchema, I, S>;
|
|
@@ -36,12 +36,12 @@ function getBlockFromCoords(
|
|
|
36
36
|
view: EditorView,
|
|
37
37
|
coords: { left: number; top: number },
|
|
38
38
|
sideMenuDetection: "viewport" | "editor",
|
|
39
|
-
adjustForColumns = true
|
|
39
|
+
adjustForColumns = true,
|
|
40
40
|
) {
|
|
41
41
|
const elements = view.root.elementsFromPoint(
|
|
42
42
|
// bit hacky - offset x position to right to account for the width of sidemenu itself
|
|
43
43
|
coords.left + (sideMenuDetection === "editor" ? 50 : 0),
|
|
44
|
-
coords.top
|
|
44
|
+
coords.top,
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
for (const element of elements) {
|
|
@@ -59,7 +59,7 @@ function getBlockFromCoords(
|
|
|
59
59
|
top: coords.top,
|
|
60
60
|
},
|
|
61
61
|
sideMenuDetection,
|
|
62
|
-
false
|
|
62
|
+
false,
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -74,7 +74,7 @@ function getBlockFromMousePos(
|
|
|
74
74
|
y: number;
|
|
75
75
|
},
|
|
76
76
|
view: EditorView,
|
|
77
|
-
sideMenuDetection: "viewport" | "editor"
|
|
77
|
+
sideMenuDetection: "viewport" | "editor",
|
|
78
78
|
): { node: HTMLElement; id: string } | undefined {
|
|
79
79
|
// Editor itself may have padding or other styling which affects
|
|
80
80
|
// size/position, so we get the boundingRect of the first child (i.e. the
|
|
@@ -137,7 +137,7 @@ function getBlockFromMousePos(
|
|
|
137
137
|
export class SideMenuView<
|
|
138
138
|
BSchema extends BlockSchema,
|
|
139
139
|
I extends InlineContentSchema,
|
|
140
|
-
S extends StyleSchema
|
|
140
|
+
S extends StyleSchema,
|
|
141
141
|
> implements PluginView
|
|
142
142
|
{
|
|
143
143
|
public state?: SideMenuState<BSchema, I, S>;
|
|
@@ -155,7 +155,7 @@ export class SideMenuView<
|
|
|
155
155
|
private readonly editor: BlockNoteEditor<BSchema, I, S>,
|
|
156
156
|
private readonly sideMenuDetection: "viewport" | "editor",
|
|
157
157
|
private readonly pmView: EditorView,
|
|
158
|
-
emitUpdate: (state: SideMenuState<BSchema, I, S>) => void
|
|
158
|
+
emitUpdate: (state: SideMenuState<BSchema, I, S>) => void,
|
|
159
159
|
) {
|
|
160
160
|
this.emitUpdate = () => {
|
|
161
161
|
if (!this.state) {
|
|
@@ -167,21 +167,21 @@ export class SideMenuView<
|
|
|
167
167
|
|
|
168
168
|
this.pmView.root.addEventListener(
|
|
169
169
|
"dragstart",
|
|
170
|
-
this.onDragStart as EventListener
|
|
170
|
+
this.onDragStart as EventListener,
|
|
171
171
|
);
|
|
172
172
|
this.pmView.root.addEventListener(
|
|
173
173
|
"dragover",
|
|
174
|
-
this.onDragOver as EventListener
|
|
174
|
+
this.onDragOver as EventListener,
|
|
175
175
|
);
|
|
176
176
|
this.pmView.root.addEventListener(
|
|
177
177
|
"drop",
|
|
178
178
|
this.onDrop as EventListener,
|
|
179
|
-
true
|
|
179
|
+
true,
|
|
180
180
|
);
|
|
181
181
|
this.pmView.root.addEventListener(
|
|
182
182
|
"dragend",
|
|
183
183
|
this.onDragEnd as EventListener,
|
|
184
|
-
true
|
|
184
|
+
true,
|
|
185
185
|
);
|
|
186
186
|
initializeESMDependencies();
|
|
187
187
|
|
|
@@ -189,14 +189,14 @@ export class SideMenuView<
|
|
|
189
189
|
this.pmView.root.addEventListener(
|
|
190
190
|
"mousemove",
|
|
191
191
|
this.onMouseMove as EventListener,
|
|
192
|
-
true
|
|
192
|
+
true,
|
|
193
193
|
);
|
|
194
194
|
|
|
195
195
|
// Hides and unfreezes the menu whenever the user presses a key.
|
|
196
196
|
this.pmView.root.addEventListener(
|
|
197
197
|
"keydown",
|
|
198
198
|
this.onKeyDown as EventListener,
|
|
199
|
-
true
|
|
199
|
+
true,
|
|
200
200
|
);
|
|
201
201
|
|
|
202
202
|
// Setting capture=true ensures that any parent container of the editor that
|
|
@@ -218,7 +218,7 @@ export class SideMenuView<
|
|
|
218
218
|
const block = getBlockFromMousePos(
|
|
219
219
|
this.mousePos,
|
|
220
220
|
this.pmView,
|
|
221
|
-
this.sideMenuDetection
|
|
221
|
+
this.sideMenuDetection,
|
|
222
222
|
);
|
|
223
223
|
|
|
224
224
|
// Closes the menu if the mouse cursor is beyond the editor vertically.
|
|
@@ -270,10 +270,10 @@ export class SideMenuView<
|
|
|
270
270
|
).getBoundingClientRect().x,
|
|
271
271
|
blockContentBoundingBox.y,
|
|
272
272
|
blockContentBoundingBox.width,
|
|
273
|
-
blockContentBoundingBox.height
|
|
273
|
+
blockContentBoundingBox.height,
|
|
274
274
|
),
|
|
275
275
|
block: this.editor.getBlock(
|
|
276
|
-
this.hoveredBlock!.getAttribute("data-id")
|
|
276
|
+
this.hoveredBlock!.getAttribute("data-id")!,
|
|
277
277
|
)!,
|
|
278
278
|
});
|
|
279
279
|
}
|
|
@@ -312,9 +312,9 @@ export class SideMenuView<
|
|
|
312
312
|
this.pmView.state.tr.setSelection(
|
|
313
313
|
TextSelection.create(
|
|
314
314
|
this.pmView.state.tr.doc,
|
|
315
|
-
this.pmView.state.tr.selection.to
|
|
316
|
-
)
|
|
317
|
-
)
|
|
315
|
+
this.pmView.state.tr.selection.to,
|
|
316
|
+
),
|
|
317
|
+
),
|
|
318
318
|
);
|
|
319
319
|
} else if (this.isDragOrigin && this.pmView.dom !== parentEditorElement) {
|
|
320
320
|
// Because the editor from which the block originates doesn't get a drop
|
|
@@ -330,7 +330,7 @@ export class SideMenuView<
|
|
|
330
330
|
// handle the event.
|
|
331
331
|
setTimeout(
|
|
332
332
|
() => this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),
|
|
333
|
-
0
|
|
333
|
+
0,
|
|
334
334
|
);
|
|
335
335
|
}
|
|
336
336
|
}
|
|
@@ -535,7 +535,7 @@ export class SideMenuView<
|
|
|
535
535
|
|
|
536
536
|
evt.clientY = Math.min(
|
|
537
537
|
Math.max(event.clientY, editorBoundingBox.top),
|
|
538
|
-
editorBoundingBox.top + editorBoundingBox.height
|
|
538
|
+
editorBoundingBox.top + editorBoundingBox.height,
|
|
539
539
|
);
|
|
540
540
|
|
|
541
541
|
evt.dataTransfer = event.dataTransfer;
|
|
@@ -573,30 +573,30 @@ export class SideMenuView<
|
|
|
573
573
|
this.pmView.root.removeEventListener(
|
|
574
574
|
"mousemove",
|
|
575
575
|
this.onMouseMove as EventListener,
|
|
576
|
-
true
|
|
576
|
+
true,
|
|
577
577
|
);
|
|
578
578
|
this.pmView.root.removeEventListener(
|
|
579
579
|
"dragstart",
|
|
580
|
-
this.onDragStart as EventListener
|
|
580
|
+
this.onDragStart as EventListener,
|
|
581
581
|
);
|
|
582
582
|
this.pmView.root.removeEventListener(
|
|
583
583
|
"dragover",
|
|
584
|
-
this.onDragOver as EventListener
|
|
584
|
+
this.onDragOver as EventListener,
|
|
585
585
|
);
|
|
586
586
|
this.pmView.root.removeEventListener(
|
|
587
587
|
"drop",
|
|
588
588
|
this.onDrop as EventListener,
|
|
589
|
-
true
|
|
589
|
+
true,
|
|
590
590
|
);
|
|
591
591
|
this.pmView.root.removeEventListener(
|
|
592
592
|
"dragend",
|
|
593
593
|
this.onDragEnd as EventListener,
|
|
594
|
-
true
|
|
594
|
+
true,
|
|
595
595
|
);
|
|
596
596
|
this.pmView.root.removeEventListener(
|
|
597
597
|
"keydown",
|
|
598
598
|
this.onKeyDown as EventListener,
|
|
599
|
-
true
|
|
599
|
+
true,
|
|
600
600
|
);
|
|
601
601
|
this.pmView.root.removeEventListener("scroll", this.onScroll, true);
|
|
602
602
|
}
|
|
@@ -607,30 +607,31 @@ export const sideMenuPluginKey = new PluginKey("SideMenuPlugin");
|
|
|
607
607
|
export class SideMenuProsemirrorPlugin<
|
|
608
608
|
BSchema extends BlockSchema,
|
|
609
609
|
I extends InlineContentSchema,
|
|
610
|
-
S extends StyleSchema
|
|
611
|
-
> extends
|
|
610
|
+
S extends StyleSchema,
|
|
611
|
+
> extends BlockNoteExtension {
|
|
612
612
|
public view: SideMenuView<BSchema, I, S> | undefined;
|
|
613
|
-
public readonly plugin: Plugin;
|
|
614
613
|
|
|
615
614
|
constructor(
|
|
616
615
|
private readonly editor: BlockNoteEditor<BSchema, I, S>,
|
|
617
|
-
sideMenuDetection: "viewport" | "editor"
|
|
616
|
+
sideMenuDetection: "viewport" | "editor",
|
|
618
617
|
) {
|
|
619
618
|
super();
|
|
620
|
-
this.
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
619
|
+
this.addProsemirrorPlugin(
|
|
620
|
+
new Plugin({
|
|
621
|
+
key: sideMenuPluginKey,
|
|
622
|
+
view: (editorView) => {
|
|
623
|
+
this.view = new SideMenuView(
|
|
624
|
+
editor,
|
|
625
|
+
sideMenuDetection,
|
|
626
|
+
editorView,
|
|
627
|
+
(state) => {
|
|
628
|
+
this.emit("update", state);
|
|
629
|
+
},
|
|
630
|
+
);
|
|
631
|
+
return this.view;
|
|
632
|
+
},
|
|
633
|
+
}),
|
|
634
|
+
);
|
|
634
635
|
}
|
|
635
636
|
|
|
636
637
|
public onUpdate(callback: (state: SideMenuState<BSchema, I, S>) => void) {
|
|
@@ -645,7 +646,7 @@ export class SideMenuProsemirrorPlugin<
|
|
|
645
646
|
dataTransfer: DataTransfer | null;
|
|
646
647
|
clientY: number;
|
|
647
648
|
},
|
|
648
|
-
block: Block<BSchema, I, S
|
|
649
|
+
block: Block<BSchema, I, S>,
|
|
649
650
|
) => {
|
|
650
651
|
if (this.view) {
|
|
651
652
|
this.view.isDragOrigin = true;
|
|
@@ -21,7 +21,7 @@ let dragImageElement: Element | undefined;
|
|
|
21
21
|
export type SideMenuState<
|
|
22
22
|
BSchema extends BlockSchema,
|
|
23
23
|
I extends InlineContentSchema,
|
|
24
|
-
S extends StyleSchema
|
|
24
|
+
S extends StyleSchema,
|
|
25
25
|
> = UiElementPosition & {
|
|
26
26
|
// The block that the side menu is attached to.
|
|
27
27
|
block: Block<BSchema, I, S>;
|
|
@@ -81,12 +81,12 @@ function setDragImage(view: EditorView, from: number, to = from) {
|
|
|
81
81
|
const firstSelectedBlockIndex = getElementIndex(
|
|
82
82
|
parent,
|
|
83
83
|
// Expects from position to be just before the first selected block.
|
|
84
|
-
view.domAtPos(from + 1).node.parentElement
|
|
84
|
+
view.domAtPos(from + 1).node.parentElement!,
|
|
85
85
|
);
|
|
86
86
|
const lastSelectedBlockIndex = getElementIndex(
|
|
87
87
|
parent,
|
|
88
88
|
// Expects to position to be just after the last selected block.
|
|
89
|
-
view.domAtPos(to - 1).node.parentElement
|
|
89
|
+
view.domAtPos(to - 1).node.parentElement!,
|
|
90
90
|
);
|
|
91
91
|
|
|
92
92
|
for (let i = parent.childElementCount - 1; i >= 0; i--) {
|
|
@@ -120,7 +120,7 @@ function setDragImage(view: EditorView, from: number, to = from) {
|
|
|
120
120
|
(className) =>
|
|
121
121
|
className !== "ProseMirror" &&
|
|
122
122
|
className !== "bn-root" &&
|
|
123
|
-
className !== "bn-editor"
|
|
123
|
+
className !== "bn-editor",
|
|
124
124
|
)
|
|
125
125
|
.join(" ");
|
|
126
126
|
|
|
@@ -149,11 +149,11 @@ export function unsetDragImage(rootEl: Document | ShadowRoot) {
|
|
|
149
149
|
export function dragStart<
|
|
150
150
|
BSchema extends BlockSchema,
|
|
151
151
|
I extends InlineContentSchema,
|
|
152
|
-
S extends StyleSchema
|
|
152
|
+
S extends StyleSchema,
|
|
153
153
|
>(
|
|
154
154
|
e: { dataTransfer: DataTransfer | null; clientY: number },
|
|
155
155
|
block: Block<BSchema, I, S>,
|
|
156
|
-
editor: BlockNoteEditor<BSchema, I, S
|
|
156
|
+
editor: BlockNoteEditor<BSchema, I, S>,
|
|
157
157
|
) {
|
|
158
158
|
if (!e.dataTransfer) {
|
|
159
159
|
return;
|
|
@@ -183,12 +183,12 @@ export function dragStart<
|
|
|
183
183
|
|
|
184
184
|
if (draggedBlockInSelection && multipleBlocksSelected) {
|
|
185
185
|
view.dispatch(
|
|
186
|
-
view.state.tr.setSelection(MultipleNodeSelection.create(doc, from, to))
|
|
186
|
+
view.state.tr.setSelection(MultipleNodeSelection.create(doc, from, to)),
|
|
187
187
|
);
|
|
188
188
|
setDragImage(view, from, to);
|
|
189
189
|
} else {
|
|
190
190
|
view.dispatch(
|
|
191
|
-
view.state.tr.setSelection(NodeSelection.create(view.state.doc, pos))
|
|
191
|
+
view.state.tr.setSelection(NodeSelection.create(view.state.doc, pos)),
|
|
192
192
|
);
|
|
193
193
|
setDragImage(view, pos);
|
|
194
194
|
}
|