@blocknote/core 0.29.1 → 0.30.1
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/README.md +125 -0
- package/dist/blocknote.cjs +9 -9
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +1501 -1359
- package/dist/blocknote.js.map +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js.map +1 -1
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +751 -9
- package/dist/locales.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +7 -8
- package/src/api/README.md +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +0 -7
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +5 -5
- package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +0 -5
- 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/__snapshots__/moveBlocks.test.ts.snap +0 -20
- 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/__snapshots__/replaceBlocks.test.ts.snap +0 -12
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +7 -7
- package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +0 -6
- 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 +0 -17
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +42 -42
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +18 -18
- package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
- package/src/api/blockManipulation/insertContentAt.ts +1 -1
- package/src/api/blockManipulation/selections/selection.ts +11 -11
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +7 -7
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +6 -6
- 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 +21 -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 +26 -26
- package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
- package/src/api/nodeConversions/nodeToBlock.ts +37 -33
- 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 +4 -4
- package/src/api/positionMapping.test.ts +3 -3
- package/src/api/positionMapping.ts +5 -5
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +9 -4
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +40 -26
- package/src/blocks/FileBlockContent/FileBlockContent.ts +7 -2
- package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +5 -5
- 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 +15 -8
- 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 +9 -6
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +14 -6
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +13 -29
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +24 -13
- package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +13 -30
- package/src/blocks/ListItemBlockContent/getListItemContent.ts +115 -0
- 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 +9 -5
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +10 -5
- package/src/blocks/README.md +1 -1
- package/src/blocks/TableBlockContent/TableBlockContent.ts +76 -19
- package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +14 -6
- package/src/blocks/defaultBlockHelpers.ts +24 -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 +10 -1
- package/src/editor/BlockNoteEditor.test.ts +3 -3
- package/src/editor/BlockNoteEditor.ts +110 -61
- package/src/editor/BlockNoteExtensions.ts +24 -15
- package/src/editor/BlockNoteSchema.ts +4 -4
- package/src/editor/BlockNoteTipTapEditor.ts +10 -10
- 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 +152 -0
- package/src/extensions/Collaboration/SyncPlugin.ts +15 -0
- package/src/extensions/Collaboration/UndoPlugin.ts +14 -0
- package/src/extensions/Comments/CommentsPlugin.ts +9 -9
- package/src/extensions/Comments/userstore/UserStore.ts +2 -2
- package/src/extensions/FilePanel/FilePanelPlugin.ts +37 -28
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +6 -8
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +29 -26
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +11 -11
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +4 -4
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +10 -10
- package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +2 -2
- package/src/extensions/README.md +1 -1
- package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
- package/src/extensions/SideMenu/SideMenuPlugin.ts +31 -31
- package/src/extensions/SideMenu/dragging.ts +8 -8
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +17 -17
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +12 -12
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +54 -53
- 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/index.ts +2 -0
- package/src/i18n/locales/ru.ts +2 -2
- package/src/i18n/locales/sk.ts +355 -0
- package/src/i18n/locales/zh-tw.ts +390 -0
- package/src/locales.ts +1 -1
- package/src/pm-nodes/BlockContainer.ts +7 -6
- package/src/pm-nodes/BlockGroup.ts +1 -1
- package/src/pm-nodes/Doc.ts +4 -4
- package/src/schema/README.md +1 -1
- package/src/schema/blocks/createSpec.ts +15 -15
- package/src/schema/blocks/internal.ts +17 -18
- package/src/schema/blocks/types.ts +27 -26
- 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/setupTestEnv.d.ts +8 -4
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +8 -4
- package/types/src/blocks/ListItemBlockContent/getListItemContent.d.ts +28 -0
- package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +8 -4
- package/types/src/blocks/defaultBlockHelpers.d.ts +1 -0
- package/types/src/blocks/defaultBlocks.d.ts +16 -8
- package/types/src/editor/BlockNoteEditor.d.ts +21 -2
- package/types/src/extensions/Collaboration/CursorPlugin.d.ts +31 -0
- package/types/src/extensions/Collaboration/SyncPlugin.d.ts +7 -0
- package/types/src/extensions/Collaboration/UndoPlugin.d.ts +6 -0
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +1 -1
- package/types/src/i18n/locales/index.d.ts +2 -0
- package/types/src/i18n/locales/sk.d.ts +313 -0
- package/types/src/i18n/locales/zh-tw.d.ts +2 -0
- package/types/src/schema/blocks/types.d.ts +2 -1
- package/src/extensions/Collaboration/createCollaborationExtensions.ts +0 -147
- package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +0 -17
|
@@ -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,14 +607,14 @@ 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
|
|
610
|
+
S extends StyleSchema,
|
|
611
611
|
> extends EventEmitter<any> {
|
|
612
612
|
public view: SideMenuView<BSchema, I, S> | undefined;
|
|
613
613
|
public readonly plugin: Plugin;
|
|
614
614
|
|
|
615
615
|
constructor(
|
|
616
616
|
private readonly editor: BlockNoteEditor<BSchema, I, S>,
|
|
617
|
-
sideMenuDetection: "viewport" | "editor"
|
|
617
|
+
sideMenuDetection: "viewport" | "editor",
|
|
618
618
|
) {
|
|
619
619
|
super();
|
|
620
620
|
this.plugin = new Plugin({
|
|
@@ -626,7 +626,7 @@ export class SideMenuProsemirrorPlugin<
|
|
|
626
626
|
editorView,
|
|
627
627
|
(state) => {
|
|
628
628
|
this.emit("update", state);
|
|
629
|
-
}
|
|
629
|
+
},
|
|
630
630
|
);
|
|
631
631
|
return this.view;
|
|
632
632
|
},
|
|
@@ -645,7 +645,7 @@ export class SideMenuProsemirrorPlugin<
|
|
|
645
645
|
dataTransfer: DataTransfer | null;
|
|
646
646
|
clientY: number;
|
|
647
647
|
},
|
|
648
|
-
block: Block<BSchema, I, S
|
|
648
|
+
block: Block<BSchema, I, S>,
|
|
649
649
|
) => {
|
|
650
650
|
if (this.view) {
|
|
651
651
|
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
|
}
|
|
@@ -22,7 +22,7 @@ export type SuggestionMenuState = UiElementPosition & {
|
|
|
22
22
|
class SuggestionMenuView<
|
|
23
23
|
BSchema extends BlockSchema,
|
|
24
24
|
I extends InlineContentSchema,
|
|
25
|
-
S extends StyleSchema
|
|
25
|
+
S extends StyleSchema,
|
|
26
26
|
> {
|
|
27
27
|
public state?: SuggestionMenuState;
|
|
28
28
|
public emitUpdate: (triggerCharacter: string) => void;
|
|
@@ -31,7 +31,7 @@ class SuggestionMenuView<
|
|
|
31
31
|
|
|
32
32
|
constructor(
|
|
33
33
|
private readonly editor: BlockNoteEditor<BSchema, I, S>,
|
|
34
|
-
emitUpdate: (menuName: string, state: SuggestionMenuState) => void
|
|
34
|
+
emitUpdate: (menuName: string, state: SuggestionMenuState) => void,
|
|
35
35
|
) {
|
|
36
36
|
this.pluginState = undefined;
|
|
37
37
|
|
|
@@ -57,7 +57,7 @@ class SuggestionMenuView<
|
|
|
57
57
|
handleScroll = () => {
|
|
58
58
|
if (this.state?.show) {
|
|
59
59
|
const decorationNode = this.rootEl?.querySelector(
|
|
60
|
-
`[data-decoration-id="${this.pluginState!.decorationId}"]
|
|
60
|
+
`[data-decoration-id="${this.pluginState!.decorationId}"]`,
|
|
61
61
|
);
|
|
62
62
|
if (!decorationNode) {
|
|
63
63
|
return;
|
|
@@ -71,7 +71,7 @@ class SuggestionMenuView<
|
|
|
71
71
|
const prev: SuggestionPluginState =
|
|
72
72
|
suggestionMenuPluginKey.getState(prevState);
|
|
73
73
|
const next: SuggestionPluginState = suggestionMenuPluginKey.getState(
|
|
74
|
-
view.state
|
|
74
|
+
view.state,
|
|
75
75
|
);
|
|
76
76
|
|
|
77
77
|
// See how the state changed
|
|
@@ -96,7 +96,7 @@ class SuggestionMenuView<
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
const decorationNode = this.rootEl?.querySelector(
|
|
99
|
-
`[data-decoration-id="${this.pluginState!.decorationId}"]
|
|
99
|
+
`[data-decoration-id="${this.pluginState!.decorationId}"]`,
|
|
100
100
|
);
|
|
101
101
|
|
|
102
102
|
if (this.editor.isEditable && decorationNode) {
|
|
@@ -165,7 +165,7 @@ const suggestionMenuPluginKey = new PluginKey("SuggestionMenuPlugin");
|
|
|
165
165
|
export class SuggestionMenuProseMirrorPlugin<
|
|
166
166
|
BSchema extends BlockSchema,
|
|
167
167
|
I extends InlineContentSchema,
|
|
168
|
-
S extends StyleSchema
|
|
168
|
+
S extends StyleSchema,
|
|
169
169
|
> extends EventEmitter<any> {
|
|
170
170
|
private view: SuggestionMenuView<BSchema, I, S> | undefined;
|
|
171
171
|
public readonly plugin: Plugin;
|
|
@@ -183,7 +183,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
183
183
|
editor,
|
|
184
184
|
(triggerCharacter, state) => {
|
|
185
185
|
this.emit(`update ${triggerCharacter}`, state);
|
|
186
|
-
}
|
|
186
|
+
},
|
|
187
187
|
);
|
|
188
188
|
return this.view;
|
|
189
189
|
},
|
|
@@ -199,7 +199,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
199
199
|
transaction,
|
|
200
200
|
prev,
|
|
201
201
|
_oldState,
|
|
202
|
-
newState
|
|
202
|
+
newState,
|
|
203
203
|
): SuggestionPluginState => {
|
|
204
204
|
// TODO: More clearly define which transactions should be ignored.
|
|
205
205
|
if (transaction.getMeta("orderedListIndexing") !== undefined) {
|
|
@@ -231,7 +231,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
231
231
|
editor,
|
|
232
232
|
newState.selection.from -
|
|
233
233
|
// Need to account for the trigger char that was inserted, so we offset the position by the length of the trigger character.
|
|
234
|
-
suggestionPluginTransactionMeta.triggerCharacter.length
|
|
234
|
+
suggestionPluginTransactionMeta.triggerCharacter.length,
|
|
235
235
|
);
|
|
236
236
|
return {
|
|
237
237
|
triggerCharacter:
|
|
@@ -271,7 +271,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
271
271
|
newState.selection.from < prev.queryStartPos()) ||
|
|
272
272
|
// Moving the caret to a new block should hide the menu.
|
|
273
273
|
!newState.selection.$from.sameParent(
|
|
274
|
-
newState.doc.resolve(prev.queryStartPos())
|
|
274
|
+
newState.doc.resolve(prev.queryStartPos()),
|
|
275
275
|
)
|
|
276
276
|
) {
|
|
277
277
|
return undefined;
|
|
@@ -282,7 +282,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
282
282
|
// Updates the current query.
|
|
283
283
|
next.query = newState.doc.textBetween(
|
|
284
284
|
prev.queryStartPos(),
|
|
285
|
-
newState.selection.from
|
|
285
|
+
newState.selection.from,
|
|
286
286
|
);
|
|
287
287
|
|
|
288
288
|
return next;
|
|
@@ -298,7 +298,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
298
298
|
.setMeta(suggestionMenuPluginKey, {
|
|
299
299
|
triggerCharacter: text,
|
|
300
300
|
})
|
|
301
|
-
.scrollIntoView()
|
|
301
|
+
.scrollIntoView(),
|
|
302
302
|
);
|
|
303
303
|
|
|
304
304
|
return true;
|
|
@@ -329,7 +329,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
329
329
|
nodeName: "span",
|
|
330
330
|
class: "bn-suggestion-decorator",
|
|
331
331
|
"data-decoration-id": suggestionPluginState.decorationId,
|
|
332
|
-
}
|
|
332
|
+
},
|
|
333
333
|
),
|
|
334
334
|
]);
|
|
335
335
|
}
|
|
@@ -344,7 +344,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
344
344
|
nodeName: "span",
|
|
345
345
|
class: "bn-suggestion-decorator",
|
|
346
346
|
"data-decoration-id": suggestionPluginState.decorationId,
|
|
347
|
-
}
|
|
347
|
+
},
|
|
348
348
|
),
|
|
349
349
|
]);
|
|
350
350
|
},
|
|
@@ -354,7 +354,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
354
354
|
|
|
355
355
|
public onUpdate(
|
|
356
356
|
triggerCharacter: string,
|
|
357
|
-
callback: (state: SuggestionMenuState) => void
|
|
357
|
+
callback: (state: SuggestionMenuState) => void,
|
|
358
358
|
) {
|
|
359
359
|
if (!this.triggerCharacters.includes(triggerCharacter)) {
|
|
360
360
|
this.addTriggerCharacter(triggerCharacter);
|
|
@@ -370,7 +370,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
370
370
|
// TODO: Should this be called automatically when listeners are removed?
|
|
371
371
|
removeTriggerCharacter = (triggerCharacter: string) => {
|
|
372
372
|
this.triggerCharacters = this.triggerCharacters.filter(
|
|
373
|
-
(c) => c !== triggerCharacter
|
|
373
|
+
(c) => c !== triggerCharacter,
|
|
374
374
|
);
|
|
375
375
|
};
|
|
376
376
|
|
|
@@ -386,7 +386,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
386
386
|
export function createSuggestionMenu<
|
|
387
387
|
BSchema extends BlockSchema,
|
|
388
388
|
I extends InlineContentSchema,
|
|
389
|
-
S extends StyleSchema
|
|
389
|
+
S extends StyleSchema,
|
|
390
390
|
>(editor: BlockNoteEditor<BSchema, I, S>, triggerCharacter: string) {
|
|
391
391
|
editor.suggestionMenus.addTriggerCharacter(triggerCharacter);
|
|
392
392
|
}
|
|
@@ -49,10 +49,10 @@ async function loadEmojiMart() {
|
|
|
49
49
|
export async function getDefaultEmojiPickerItems<
|
|
50
50
|
BSchema extends BlockSchema,
|
|
51
51
|
I extends InlineContentSchema,
|
|
52
|
-
S extends StyleSchema
|
|
52
|
+
S extends StyleSchema,
|
|
53
53
|
>(
|
|
54
54
|
editor: BlockNoteEditor<BSchema, I, S>,
|
|
55
|
-
query: string
|
|
55
|
+
query: string,
|
|
56
56
|
): Promise<DefaultGridSuggestionItem[]> {
|
|
57
57
|
if (!checkDefaultInlineContentTypeInSchema("text", editor)) {
|
|
58
58
|
return [];
|
|
@@ -18,7 +18,7 @@ import { DefaultSuggestionItem } from "./DefaultSuggestionItem.js";
|
|
|
18
18
|
function setSelectionToNextContentEditableBlock<
|
|
19
19
|
BSchema extends BlockSchema,
|
|
20
20
|
I extends InlineContentSchema,
|
|
21
|
-
S extends StyleSchema
|
|
21
|
+
S extends StyleSchema,
|
|
22
22
|
>(editor: BlockNoteEditor<BSchema, I, S>) {
|
|
23
23
|
let block: Block<BSchema, I, S> | undefined =
|
|
24
24
|
editor.getTextCursorPosition().block;
|
|
@@ -44,10 +44,10 @@ function setSelectionToNextContentEditableBlock<
|
|
|
44
44
|
export function insertOrUpdateBlock<
|
|
45
45
|
BSchema extends BlockSchema,
|
|
46
46
|
I extends InlineContentSchema,
|
|
47
|
-
S extends StyleSchema
|
|
47
|
+
S extends StyleSchema,
|
|
48
48
|
>(
|
|
49
49
|
editor: BlockNoteEditor<BSchema, I, S>,
|
|
50
|
-
block: PartialBlock<BSchema, I, S
|
|
50
|
+
block: PartialBlock<BSchema, I, S>,
|
|
51
51
|
): Block<BSchema, I, S> {
|
|
52
52
|
const currentBlock = editor.getTextCursorPosition().block;
|
|
53
53
|
|
|
@@ -83,7 +83,7 @@ export function insertOrUpdateBlock<
|
|
|
83
83
|
export function getDefaultSlashMenuItems<
|
|
84
84
|
BSchema extends BlockSchema,
|
|
85
85
|
I extends InlineContentSchema,
|
|
86
|
-
S extends StyleSchema
|
|
86
|
+
S extends StyleSchema,
|
|
87
87
|
>(editor: BlockNoteEditor<BSchema, I, S>) {
|
|
88
88
|
const items: DefaultSuggestionItem[] = [];
|
|
89
89
|
|
|
@@ -121,7 +121,7 @@ export function getDefaultSlashMenuItems<
|
|
|
121
121
|
badge: formatKeyboardShortcut("Mod-Alt-3"),
|
|
122
122
|
key: "heading_3",
|
|
123
123
|
...editor.dictionary.slash_menu.heading_3,
|
|
124
|
-
}
|
|
124
|
+
},
|
|
125
125
|
);
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -237,7 +237,7 @@ export function getDefaultSlashMenuItems<
|
|
|
237
237
|
editor.transact((tr) =>
|
|
238
238
|
tr.setMeta(editor.filePanel!.plugin, {
|
|
239
239
|
block: insertedBlock,
|
|
240
|
-
})
|
|
240
|
+
}),
|
|
241
241
|
);
|
|
242
242
|
},
|
|
243
243
|
key: "image",
|
|
@@ -256,7 +256,7 @@ export function getDefaultSlashMenuItems<
|
|
|
256
256
|
editor.transact((tr) =>
|
|
257
257
|
tr.setMeta(editor.filePanel!.plugin, {
|
|
258
258
|
block: insertedBlock,
|
|
259
|
-
})
|
|
259
|
+
}),
|
|
260
260
|
);
|
|
261
261
|
},
|
|
262
262
|
key: "video",
|
|
@@ -275,7 +275,7 @@ export function getDefaultSlashMenuItems<
|
|
|
275
275
|
editor.transact((tr) =>
|
|
276
276
|
tr.setMeta(editor.filePanel!.plugin, {
|
|
277
277
|
block: insertedBlock,
|
|
278
|
-
})
|
|
278
|
+
}),
|
|
279
279
|
);
|
|
280
280
|
},
|
|
281
281
|
key: "audio",
|
|
@@ -294,7 +294,7 @@ export function getDefaultSlashMenuItems<
|
|
|
294
294
|
editor.transact((tr) =>
|
|
295
295
|
tr.setMeta(editor.filePanel!.plugin, {
|
|
296
296
|
block: insertedBlock,
|
|
297
|
-
})
|
|
297
|
+
}),
|
|
298
298
|
);
|
|
299
299
|
},
|
|
300
300
|
key: "file",
|
|
@@ -317,14 +317,14 @@ export function getDefaultSlashMenuItems<
|
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
export function filterSuggestionItems<
|
|
320
|
-
T extends { title: string; aliases?: readonly string[] }
|
|
320
|
+
T extends { title: string; aliases?: readonly string[] },
|
|
321
321
|
>(items: T[], query: string) {
|
|
322
322
|
return items.filter(
|
|
323
323
|
({ title, aliases }) =>
|
|
324
324
|
title.toLowerCase().includes(query.toLowerCase()) ||
|
|
325
325
|
(aliases &&
|
|
326
326
|
aliases.filter((alias) =>
|
|
327
|
-
alias.toLowerCase().includes(query.toLowerCase())
|
|
328
|
-
).length !== 0)
|
|
327
|
+
alias.toLowerCase().includes(query.toLowerCase()),
|
|
328
|
+
).length !== 0),
|
|
329
329
|
);
|
|
330
330
|
}
|