@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
|
@@ -2,15 +2,15 @@ import { findParentNode } from "@tiptap/core";
|
|
|
2
2
|
import { EditorState, Plugin, PluginKey } from "prosemirror-state";
|
|
3
3
|
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
|
|
4
4
|
|
|
5
|
+
import { trackPosition } from "../../api/positionMapping.js";
|
|
5
6
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
7
|
+
import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
6
8
|
import { UiElementPosition } from "../../extensions-shared/UiElementPosition.js";
|
|
7
9
|
import {
|
|
8
10
|
BlockSchema,
|
|
9
11
|
InlineContentSchema,
|
|
10
12
|
StyleSchema,
|
|
11
13
|
} from "../../schema/index.js";
|
|
12
|
-
import { EventEmitter } from "../../util/EventEmitter.js";
|
|
13
|
-
import { trackPosition } from "../../api/positionMapping.js";
|
|
14
14
|
|
|
15
15
|
const findBlock = findParentNode((node) => node.type.name === "blockContainer");
|
|
16
16
|
|
|
@@ -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,196 +165,196 @@ const suggestionMenuPluginKey = new PluginKey("SuggestionMenuPlugin");
|
|
|
165
165
|
export class SuggestionMenuProseMirrorPlugin<
|
|
166
166
|
BSchema extends BlockSchema,
|
|
167
167
|
I extends InlineContentSchema,
|
|
168
|
-
S extends StyleSchema
|
|
169
|
-
> extends
|
|
168
|
+
S extends StyleSchema,
|
|
169
|
+
> extends BlockNoteExtension {
|
|
170
170
|
private view: SuggestionMenuView<BSchema, I, S> | undefined;
|
|
171
|
-
public readonly plugin: Plugin;
|
|
172
|
-
|
|
173
171
|
private triggerCharacters: string[] = [];
|
|
174
172
|
|
|
175
173
|
constructor(editor: BlockNoteEditor<BSchema, I, S>) {
|
|
176
174
|
super();
|
|
177
175
|
const triggerCharacters = this.triggerCharacters;
|
|
178
|
-
this.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
state: {
|
|
192
|
-
// Initialize the plugin's internal state.
|
|
193
|
-
init(): SuggestionPluginState {
|
|
194
|
-
return undefined;
|
|
176
|
+
this.addProsemirrorPlugin(
|
|
177
|
+
new Plugin({
|
|
178
|
+
key: suggestionMenuPluginKey,
|
|
179
|
+
|
|
180
|
+
view: () => {
|
|
181
|
+
this.view = new SuggestionMenuView<BSchema, I, S>(
|
|
182
|
+
editor,
|
|
183
|
+
(triggerCharacter, state) => {
|
|
184
|
+
this.emit(`update ${triggerCharacter}`, state);
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
return this.view;
|
|
195
188
|
},
|
|
196
189
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
prev,
|
|
201
|
-
_oldState,
|
|
202
|
-
newState
|
|
203
|
-
): SuggestionPluginState => {
|
|
204
|
-
// TODO: More clearly define which transactions should be ignored.
|
|
205
|
-
if (transaction.getMeta("orderedListIndexing") !== undefined) {
|
|
206
|
-
return prev;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Ignore transactions in code blocks.
|
|
210
|
-
if (transaction.selection.$from.parent.type.spec.code) {
|
|
211
|
-
return prev;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Either contains the trigger character if the menu should be shown,
|
|
215
|
-
// or null if it should be hidden.
|
|
216
|
-
const suggestionPluginTransactionMeta: {
|
|
217
|
-
triggerCharacter: string;
|
|
218
|
-
deleteTriggerCharacter?: boolean;
|
|
219
|
-
ignoreQueryLength?: boolean;
|
|
220
|
-
} | null = transaction.getMeta(suggestionMenuPluginKey);
|
|
221
|
-
|
|
222
|
-
if (
|
|
223
|
-
typeof suggestionPluginTransactionMeta === "object" &&
|
|
224
|
-
suggestionPluginTransactionMeta !== null
|
|
225
|
-
) {
|
|
226
|
-
if (prev) {
|
|
227
|
-
// Close the previous menu if it exists
|
|
228
|
-
this.closeMenu();
|
|
229
|
-
}
|
|
230
|
-
const trackedPosition = trackPosition(
|
|
231
|
-
editor,
|
|
232
|
-
newState.selection.from -
|
|
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
|
|
235
|
-
);
|
|
236
|
-
return {
|
|
237
|
-
triggerCharacter:
|
|
238
|
-
suggestionPluginTransactionMeta.triggerCharacter,
|
|
239
|
-
deleteTriggerCharacter:
|
|
240
|
-
suggestionPluginTransactionMeta.deleteTriggerCharacter !==
|
|
241
|
-
false,
|
|
242
|
-
// When reading the queryStartPos, we offset the result by the length of the trigger character, to make it easy on the caller
|
|
243
|
-
queryStartPos: () =>
|
|
244
|
-
trackedPosition() +
|
|
245
|
-
suggestionPluginTransactionMeta.triggerCharacter.length,
|
|
246
|
-
query: "",
|
|
247
|
-
decorationId: `id_${Math.floor(Math.random() * 0xffffffff)}`,
|
|
248
|
-
ignoreQueryLength:
|
|
249
|
-
suggestionPluginTransactionMeta?.ignoreQueryLength,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Checks if the menu is hidden, in which case it doesn't need to be hidden or updated.
|
|
254
|
-
if (prev === undefined) {
|
|
255
|
-
return prev;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// Checks if the menu should be hidden.
|
|
259
|
-
if (
|
|
260
|
-
// Highlighting text should hide the menu.
|
|
261
|
-
newState.selection.from !== newState.selection.to ||
|
|
262
|
-
// Transactions with plugin metadata should hide the menu.
|
|
263
|
-
suggestionPluginTransactionMeta === null ||
|
|
264
|
-
// Certain mouse events should hide the menu.
|
|
265
|
-
// TODO: Change to global mousedown listener.
|
|
266
|
-
transaction.getMeta("focus") ||
|
|
267
|
-
transaction.getMeta("blur") ||
|
|
268
|
-
transaction.getMeta("pointer") ||
|
|
269
|
-
// Moving the caret before the character which triggered the menu should hide it.
|
|
270
|
-
(prev.triggerCharacter !== undefined &&
|
|
271
|
-
newState.selection.from < prev.queryStartPos()) ||
|
|
272
|
-
// Moving the caret to a new block should hide the menu.
|
|
273
|
-
!newState.selection.$from.sameParent(
|
|
274
|
-
newState.doc.resolve(prev.queryStartPos())
|
|
275
|
-
)
|
|
276
|
-
) {
|
|
190
|
+
state: {
|
|
191
|
+
// Initialize the plugin's internal state.
|
|
192
|
+
init(): SuggestionPluginState {
|
|
277
193
|
return undefined;
|
|
278
|
-
}
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
// Apply changes to the plugin state from an editor transaction.
|
|
197
|
+
apply: (
|
|
198
|
+
transaction,
|
|
199
|
+
prev,
|
|
200
|
+
_oldState,
|
|
201
|
+
newState,
|
|
202
|
+
): SuggestionPluginState => {
|
|
203
|
+
// TODO: More clearly define which transactions should be ignored.
|
|
204
|
+
if (transaction.getMeta("orderedListIndexing") !== undefined) {
|
|
205
|
+
return prev;
|
|
206
|
+
}
|
|
279
207
|
|
|
280
|
-
|
|
208
|
+
// Ignore transactions in code blocks.
|
|
209
|
+
if (transaction.selection.$from.parent.type.spec.code) {
|
|
210
|
+
return prev;
|
|
211
|
+
}
|
|
281
212
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
213
|
+
// Either contains the trigger character if the menu should be shown,
|
|
214
|
+
// or null if it should be hidden.
|
|
215
|
+
const suggestionPluginTransactionMeta: {
|
|
216
|
+
triggerCharacter: string;
|
|
217
|
+
deleteTriggerCharacter?: boolean;
|
|
218
|
+
ignoreQueryLength?: boolean;
|
|
219
|
+
} | null = transaction.getMeta(suggestionMenuPluginKey);
|
|
220
|
+
|
|
221
|
+
if (
|
|
222
|
+
typeof suggestionPluginTransactionMeta === "object" &&
|
|
223
|
+
suggestionPluginTransactionMeta !== null
|
|
224
|
+
) {
|
|
225
|
+
if (prev) {
|
|
226
|
+
// Close the previous menu if it exists
|
|
227
|
+
this.closeMenu();
|
|
228
|
+
}
|
|
229
|
+
const trackedPosition = trackPosition(
|
|
230
|
+
editor,
|
|
231
|
+
newState.selection.from -
|
|
232
|
+
// Need to account for the trigger char that was inserted, so we offset the position by the length of the trigger character.
|
|
233
|
+
suggestionPluginTransactionMeta.triggerCharacter.length,
|
|
234
|
+
);
|
|
235
|
+
return {
|
|
236
|
+
triggerCharacter:
|
|
237
|
+
suggestionPluginTransactionMeta.triggerCharacter,
|
|
238
|
+
deleteTriggerCharacter:
|
|
239
|
+
suggestionPluginTransactionMeta.deleteTriggerCharacter !==
|
|
240
|
+
false,
|
|
241
|
+
// When reading the queryStartPos, we offset the result by the length of the trigger character, to make it easy on the caller
|
|
242
|
+
queryStartPos: () =>
|
|
243
|
+
trackedPosition() +
|
|
244
|
+
suggestionPluginTransactionMeta.triggerCharacter.length,
|
|
245
|
+
query: "",
|
|
246
|
+
decorationId: `id_${Math.floor(Math.random() * 0xffffffff)}`,
|
|
247
|
+
ignoreQueryLength:
|
|
248
|
+
suggestionPluginTransactionMeta?.ignoreQueryLength,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
287
251
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
252
|
+
// Checks if the menu is hidden, in which case it doesn't need to be hidden or updated.
|
|
253
|
+
if (prev === undefined) {
|
|
254
|
+
return prev;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Checks if the menu should be hidden.
|
|
258
|
+
if (
|
|
259
|
+
// Highlighting text should hide the menu.
|
|
260
|
+
newState.selection.from !== newState.selection.to ||
|
|
261
|
+
// Transactions with plugin metadata should hide the menu.
|
|
262
|
+
suggestionPluginTransactionMeta === null ||
|
|
263
|
+
// Certain mouse events should hide the menu.
|
|
264
|
+
// TODO: Change to global mousedown listener.
|
|
265
|
+
transaction.getMeta("focus") ||
|
|
266
|
+
transaction.getMeta("blur") ||
|
|
267
|
+
transaction.getMeta("pointer") ||
|
|
268
|
+
// Moving the caret before the character which triggered the menu should hide it.
|
|
269
|
+
(prev.triggerCharacter !== undefined &&
|
|
270
|
+
newState.selection.from < prev.queryStartPos()) ||
|
|
271
|
+
// Moving the caret to a new block should hide the menu.
|
|
272
|
+
!newState.selection.$from.sameParent(
|
|
273
|
+
newState.doc.resolve(prev.queryStartPos()),
|
|
274
|
+
)
|
|
275
|
+
) {
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const next = { ...prev };
|
|
280
|
+
|
|
281
|
+
// Updates the current query.
|
|
282
|
+
next.query = newState.doc.textBetween(
|
|
283
|
+
prev.queryStartPos(),
|
|
284
|
+
newState.selection.from,
|
|
302
285
|
);
|
|
303
286
|
|
|
304
|
-
return
|
|
305
|
-
}
|
|
306
|
-
return false;
|
|
287
|
+
return next;
|
|
288
|
+
},
|
|
307
289
|
},
|
|
308
290
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const blockNode = findBlock(state.selection);
|
|
323
|
-
if (blockNode) {
|
|
324
|
-
return DecorationSet.create(state.doc, [
|
|
325
|
-
Decoration.node(
|
|
326
|
-
blockNode.pos,
|
|
327
|
-
blockNode.pos + blockNode.node.nodeSize,
|
|
328
|
-
{
|
|
329
|
-
nodeName: "span",
|
|
330
|
-
class: "bn-suggestion-decorator",
|
|
331
|
-
"data-decoration-id": suggestionPluginState.decorationId,
|
|
332
|
-
}
|
|
333
|
-
),
|
|
334
|
-
]);
|
|
291
|
+
props: {
|
|
292
|
+
handleTextInput(view, _from, _to, text) {
|
|
293
|
+
if (triggerCharacters.includes(text)) {
|
|
294
|
+
view.dispatch(view.state.tr.insertText(text));
|
|
295
|
+
view.dispatch(
|
|
296
|
+
view.state.tr
|
|
297
|
+
.setMeta(suggestionMenuPluginKey, {
|
|
298
|
+
triggerCharacter: text,
|
|
299
|
+
})
|
|
300
|
+
.scrollIntoView(),
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
return true;
|
|
335
304
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
305
|
+
return false;
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
// Setup decorator on the currently active suggestion.
|
|
309
|
+
decorations(state) {
|
|
310
|
+
const suggestionPluginState: SuggestionPluginState = (
|
|
311
|
+
this as Plugin
|
|
312
|
+
).getState(state);
|
|
313
|
+
|
|
314
|
+
if (suggestionPluginState === undefined) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// If the menu was opened programmatically by another extension, it may not use a trigger character. In this
|
|
319
|
+
// case, the decoration is set on the whole block instead, as the decoration range would otherwise be empty.
|
|
320
|
+
if (!suggestionPluginState.deleteTriggerCharacter) {
|
|
321
|
+
const blockNode = findBlock(state.selection);
|
|
322
|
+
if (blockNode) {
|
|
323
|
+
return DecorationSet.create(state.doc, [
|
|
324
|
+
Decoration.node(
|
|
325
|
+
blockNode.pos,
|
|
326
|
+
blockNode.pos + blockNode.node.nodeSize,
|
|
327
|
+
{
|
|
328
|
+
nodeName: "span",
|
|
329
|
+
class: "bn-suggestion-decorator",
|
|
330
|
+
"data-decoration-id": suggestionPluginState.decorationId,
|
|
331
|
+
},
|
|
332
|
+
),
|
|
333
|
+
]);
|
|
347
334
|
}
|
|
348
|
-
|
|
349
|
-
|
|
335
|
+
}
|
|
336
|
+
// Creates an inline decoration around the trigger character.
|
|
337
|
+
return DecorationSet.create(state.doc, [
|
|
338
|
+
Decoration.inline(
|
|
339
|
+
suggestionPluginState.queryStartPos() -
|
|
340
|
+
suggestionPluginState.triggerCharacter!.length,
|
|
341
|
+
suggestionPluginState.queryStartPos(),
|
|
342
|
+
{
|
|
343
|
+
nodeName: "span",
|
|
344
|
+
class: "bn-suggestion-decorator",
|
|
345
|
+
"data-decoration-id": suggestionPluginState.decorationId,
|
|
346
|
+
},
|
|
347
|
+
),
|
|
348
|
+
]);
|
|
349
|
+
},
|
|
350
350
|
},
|
|
351
|
-
},
|
|
352
|
-
|
|
351
|
+
}),
|
|
352
|
+
);
|
|
353
353
|
}
|
|
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
|
|
|
@@ -235,9 +235,9 @@ export function getDefaultSlashMenuItems<
|
|
|
235
235
|
|
|
236
236
|
// Immediately open the file toolbar
|
|
237
237
|
editor.transact((tr) =>
|
|
238
|
-
tr.setMeta(editor.filePanel!.
|
|
238
|
+
tr.setMeta(editor.filePanel!.plugins[0], {
|
|
239
239
|
block: insertedBlock,
|
|
240
|
-
})
|
|
240
|
+
}),
|
|
241
241
|
);
|
|
242
242
|
},
|
|
243
243
|
key: "image",
|
|
@@ -254,9 +254,9 @@ export function getDefaultSlashMenuItems<
|
|
|
254
254
|
|
|
255
255
|
// Immediately open the file toolbar
|
|
256
256
|
editor.transact((tr) =>
|
|
257
|
-
tr.setMeta(editor.filePanel!.
|
|
257
|
+
tr.setMeta(editor.filePanel!.plugins[0], {
|
|
258
258
|
block: insertedBlock,
|
|
259
|
-
})
|
|
259
|
+
}),
|
|
260
260
|
);
|
|
261
261
|
},
|
|
262
262
|
key: "video",
|
|
@@ -273,9 +273,9 @@ export function getDefaultSlashMenuItems<
|
|
|
273
273
|
|
|
274
274
|
// Immediately open the file toolbar
|
|
275
275
|
editor.transact((tr) =>
|
|
276
|
-
tr.setMeta(editor.filePanel!.
|
|
276
|
+
tr.setMeta(editor.filePanel!.plugins[0], {
|
|
277
277
|
block: insertedBlock,
|
|
278
|
-
})
|
|
278
|
+
}),
|
|
279
279
|
);
|
|
280
280
|
},
|
|
281
281
|
key: "audio",
|
|
@@ -292,9 +292,9 @@ export function getDefaultSlashMenuItems<
|
|
|
292
292
|
|
|
293
293
|
// Immediately open the file toolbar
|
|
294
294
|
editor.transact((tr) =>
|
|
295
|
-
tr.setMeta(editor.filePanel!.
|
|
295
|
+
tr.setMeta(editor.filePanel!.plugins[0], {
|
|
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
|
}
|