@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.
Files changed (245) hide show
  1. package/dist/blocknote.cjs +9 -9
  2. package/dist/blocknote.cjs.map +1 -1
  3. package/dist/blocknote.js +2771 -2245
  4. package/dist/blocknote.js.map +1 -1
  5. package/dist/comments.cjs.map +1 -1
  6. package/dist/comments.js.map +1 -1
  7. package/dist/{en-D4taoCs4.cjs → en-BXVKCwYt.cjs} +2 -2
  8. package/dist/en-BXVKCwYt.cjs.map +1 -0
  9. package/dist/{en-B7ycW7c8.js → en-qGo6sk9V.js} +2 -3
  10. package/dist/en-qGo6sk9V.js.map +1 -0
  11. package/dist/locales.cjs +1 -1
  12. package/dist/locales.cjs.map +1 -1
  13. package/dist/locales.js +20 -39
  14. package/dist/locales.js.map +1 -1
  15. package/dist/style.css +1 -1
  16. package/dist/webpack-stats.json +1 -1
  17. package/package.json +8 -7
  18. package/src/api/README.md +1 -1
  19. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
  20. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +7 -8
  21. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
  22. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +12 -12
  23. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +14 -14
  24. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +16 -16
  25. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +8 -8
  26. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
  27. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +8 -8
  28. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +10 -10
  29. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +2 -2
  30. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2816 -0
  31. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +200 -42
  32. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +104 -34
  33. package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
  34. package/src/api/blockManipulation/insertContentAt.ts +1 -1
  35. package/src/api/blockManipulation/selections/selection.ts +59 -12
  36. package/src/api/blockManipulation/selections/{textCursorPosition/textCursorPosition.ts → textCursorPosition.ts} +13 -13
  37. package/src/api/blockManipulation/tables/tables.test.ts +106 -106
  38. package/src/api/blockManipulation/tables/tables.ts +35 -35
  39. package/src/api/clipboard/fromClipboard/fileDropExtension.ts +2 -2
  40. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +9 -9
  41. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +3 -3
  42. package/src/api/clipboard/fromClipboard/pasteExtension.ts +3 -3
  43. package/src/api/clipboard/toClipboard/copyExtension.ts +22 -22
  44. package/src/api/exporters/html/externalHTMLExporter.ts +6 -6
  45. package/src/api/exporters/html/internalHTMLSerializer.ts +3 -3
  46. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +16 -16
  47. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +14 -14
  48. package/src/api/exporters/markdown/markdownExporter.ts +3 -3
  49. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +3 -3
  50. package/src/api/getBlockInfoFromPos.ts +6 -6
  51. package/src/api/nodeConversions/blockToNode.ts +31 -28
  52. package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
  53. package/src/api/nodeConversions/nodeToBlock.ts +240 -41
  54. package/src/api/nodeUtil.test.ts +16 -16
  55. package/src/api/nodeUtil.ts +10 -10
  56. package/src/api/parsers/html/parseHTML.ts +1 -1
  57. package/src/api/parsers/html/util/nestedLists.ts +2 -2
  58. package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
  59. package/src/api/pmUtil.ts +7 -7
  60. package/src/api/positionMapping.test.ts +3 -3
  61. package/src/api/positionMapping.ts +5 -5
  62. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +4 -4
  63. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +18 -18
  64. package/src/blocks/FileBlockContent/FileBlockContent.ts +2 -2
  65. package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
  66. package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +6 -6
  67. package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +2 -2
  68. package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +1 -1
  69. package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +7 -7
  70. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +1 -1
  71. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +1 -1
  72. package/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +2 -2
  73. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +6 -6
  74. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +4 -4
  75. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +4 -4
  76. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +10 -10
  77. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
  78. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
  79. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +4 -4
  80. package/src/blocks/ListItemBlockContent/getListItemContent.ts +5 -5
  81. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +1 -1
  82. package/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.ts +3 -3
  83. package/src/blocks/PageBreakBlockContent/schema.ts +2 -2
  84. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +3 -3
  85. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +4 -4
  86. package/src/blocks/README.md +1 -1
  87. package/src/blocks/TableBlockContent/TableBlockContent.ts +37 -7
  88. package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
  89. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +4 -4
  90. package/src/blocks/defaultBlockHelpers.ts +8 -8
  91. package/src/blocks/defaultBlockTypeGuards.ts +16 -16
  92. package/src/blocks/defaultBlocks.ts +3 -3
  93. package/src/comments/threadstore/DefaultThreadStoreAuth.ts +3 -3
  94. package/src/comments/threadstore/ThreadStore.ts +1 -1
  95. package/src/comments/threadstore/TipTapThreadStore.ts +10 -10
  96. package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +4 -4
  97. package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +2 -2
  98. package/src/comments/threadstore/yjs/YjsThreadStore.ts +14 -14
  99. package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +1 -1
  100. package/src/comments/threadstore/yjs/yjsHelpers.ts +6 -6
  101. package/src/editor/Block.css +35 -1
  102. package/src/editor/BlockNoteEditor.test.ts +10 -3
  103. package/src/editor/BlockNoteEditor.ts +95 -38
  104. package/src/editor/BlockNoteExtension.ts +26 -0
  105. package/src/editor/BlockNoteExtensions.ts +38 -22
  106. package/src/editor/BlockNoteSchema.ts +4 -4
  107. package/src/editor/BlockNoteTipTapEditor.ts +33 -12
  108. package/src/editor/README.md +1 -1
  109. package/src/editor/cursorPositionTypes.ts +1 -1
  110. package/src/editor/editor.css +15 -3
  111. package/src/editor/selectionTypes.ts +1 -1
  112. package/src/editor/transformPasted.ts +2 -2
  113. package/src/exporter/Exporter.ts +5 -5
  114. package/src/exporter/mapping.ts +7 -7
  115. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
  116. package/src/extensions/Collaboration/CursorPlugin.ts +15 -9
  117. package/src/extensions/Collaboration/ForkYDocPlugin.test.ts +166 -0
  118. package/src/extensions/Collaboration/ForkYDocPlugin.ts +174 -0
  119. package/src/extensions/Collaboration/SyncPlugin.ts +7 -4
  120. package/src/extensions/Collaboration/UndoPlugin.ts +7 -4
  121. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +30 -0
  122. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +30 -0
  123. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -0
  124. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -0
  125. package/src/extensions/Comments/CommentsPlugin.ts +80 -75
  126. package/src/extensions/Comments/userstore/UserStore.ts +2 -2
  127. package/src/extensions/FilePanel/FilePanelPlugin.ts +56 -55
  128. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +60 -30
  129. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +26 -26
  130. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +33 -32
  131. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +45 -42
  132. package/src/extensions/Placeholder/PlaceholderPlugin.ts +113 -110
  133. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +179 -170
  134. package/src/extensions/README.md +1 -1
  135. package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +22 -19
  136. package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
  137. package/src/extensions/SideMenu/SideMenuPlugin.ts +49 -48
  138. package/src/extensions/SideMenu/dragging.ts +8 -8
  139. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +176 -176
  140. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
  141. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +16 -16
  142. package/src/extensions/Suggestions/SuggestionMarks.ts +175 -0
  143. package/src/extensions/TableHandles/TableHandlesPlugin.ts +199 -195
  144. package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
  145. package/src/extensions/UniqueID/UniqueID.ts +6 -6
  146. package/src/extensions/getDraggableBlockFromElement.ts +1 -1
  147. package/src/fonts/inter.css +18 -9
  148. package/src/i18n/locales/ar.ts +0 -1
  149. package/src/i18n/locales/de.ts +0 -1
  150. package/src/i18n/locales/en.ts +0 -1
  151. package/src/i18n/locales/es.ts +0 -1
  152. package/src/i18n/locales/fr.ts +0 -1
  153. package/src/i18n/locales/hr.ts +0 -1
  154. package/src/i18n/locales/is.ts +0 -1
  155. package/src/i18n/locales/it.ts +0 -1
  156. package/src/i18n/locales/ja.ts +0 -1
  157. package/src/i18n/locales/ko.ts +0 -1
  158. package/src/i18n/locales/nl.ts +0 -1
  159. package/src/i18n/locales/no.ts +0 -1
  160. package/src/i18n/locales/pl.ts +0 -1
  161. package/src/i18n/locales/pt.ts +0 -1
  162. package/src/i18n/locales/ru.ts +0 -1
  163. package/src/i18n/locales/sk.ts +0 -1
  164. package/src/i18n/locales/uk.ts +0 -1
  165. package/src/i18n/locales/vi.ts +0 -1
  166. package/src/i18n/locales/zh-tw.ts +0 -1
  167. package/src/i18n/locales/zh.ts +0 -1
  168. package/src/index.ts +18 -8
  169. package/src/locales.ts +1 -1
  170. package/src/pm-nodes/BlockContainer.ts +1 -1
  171. package/src/pm-nodes/BlockGroup.ts +2 -2
  172. package/src/pm-nodes/Doc.ts +5 -4
  173. package/src/schema/README.md +1 -1
  174. package/src/schema/blocks/createSpec.ts +14 -14
  175. package/src/schema/blocks/internal.ts +17 -17
  176. package/src/schema/blocks/types.ts +25 -25
  177. package/src/schema/inlineContent/createSpec.ts +16 -20
  178. package/src/schema/inlineContent/internal.ts +9 -9
  179. package/src/schema/inlineContent/types.ts +26 -26
  180. package/src/schema/propTypes.ts +8 -8
  181. package/src/schema/styles/createSpec.ts +2 -2
  182. package/src/schema/styles/internal.ts +7 -7
  183. package/src/schema/styles/types.ts +2 -2
  184. package/src/util/EventEmitter.ts +4 -4
  185. package/src/util/README.md +1 -1
  186. package/src/util/combineByGroup.ts +1 -1
  187. package/src/util/table.ts +33 -30
  188. package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +1 -1
  189. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +4 -0
  190. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
  191. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +3 -1
  192. package/types/src/api/blockManipulation/selections/selection.d.ts +10 -0
  193. package/types/src/api/blockManipulation/selections/textCursorPosition.d.ts +5 -0
  194. package/types/src/api/blockManipulation/transactions.test.d.ts +0 -0
  195. package/types/src/api/clipboard/clipboardExternal.test.d.ts +1 -0
  196. package/types/src/api/clipboard/clipboardInternal.test.d.ts +1 -0
  197. package/types/src/api/clipboard/testUtil.d.ts +541 -0
  198. package/types/src/api/exporters/html/htmlConversion.test.d.ts +1 -0
  199. package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +1 -0
  200. package/types/src/api/nodeConversions/nodeConversions.test.d.ts +1 -0
  201. package/types/src/api/nodeConversions/nodeToBlock.d.ts +39 -2
  202. package/types/src/api/parsers/html/parseHTML.test.d.ts +1 -0
  203. package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +1 -0
  204. package/types/src/api/pmUtil.d.ts +3 -3
  205. package/types/src/api/testUtil/cases/customBlocks.d.ts +670 -0
  206. package/types/src/api/testUtil/cases/customInlineContent.d.ts +558 -0
  207. package/types/src/api/testUtil/cases/customStyles.d.ts +552 -0
  208. package/types/src/api/testUtil/cases/defaultSchema.d.ts +4 -0
  209. package/types/src/api/testUtil/index.d.ts +14 -0
  210. package/types/src/api/testUtil/partialBlockTestUtil.d.ts +9 -0
  211. package/types/src/api/testUtil/paste.d.ts +2 -0
  212. package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +6 -0
  213. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +9 -1
  214. package/types/src/editor/BlockNoteEditor.d.ts +58 -10
  215. package/types/src/editor/BlockNoteExtension.d.ts +9 -0
  216. package/types/src/editor/BlockNoteExtensions.d.ts +2 -2
  217. package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
  218. package/types/src/extensions/Collaboration/CursorPlugin.d.ts +3 -3
  219. package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +41 -0
  220. package/types/src/extensions/Collaboration/ForkYDocPlugin.test.d.ts +1 -0
  221. package/types/src/extensions/Collaboration/SyncPlugin.d.ts +3 -3
  222. package/types/src/extensions/Collaboration/UndoPlugin.d.ts +3 -3
  223. package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +17 -0
  224. package/types/src/extensions/Comments/CommentsPlugin.d.ts +2 -4
  225. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +3 -4
  226. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +5 -5
  227. package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +3 -4
  228. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -3
  229. package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +2 -3
  230. package/types/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.d.ts +2 -3
  231. package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +2 -3
  232. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +3 -4
  233. package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +2 -4
  234. package/types/src/extensions/Suggestions/SuggestionMarks.d.ts +4 -0
  235. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +5 -6
  236. package/types/src/i18n/locales/en.d.ts +0 -1
  237. package/types/src/i18n/locales/sk.d.ts +0 -1
  238. package/types/src/index.d.ts +15 -8
  239. package/dist/en-B7ycW7c8.js.map +0 -1
  240. package/dist/en-D4taoCs4.cjs.map +0 -1
  241. package/dist/tsconfig.tsbuildinfo +0 -1
  242. package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +0 -844
  243. package/src/api/blockManipulation/selections/selection.test.ts +0 -72
  244. package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +0 -316
  245. 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 EventEmitter<any> {
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.plugin = new Plugin({
179
- key: suggestionMenuPluginKey,
180
-
181
- view: () => {
182
- this.view = new SuggestionMenuView<BSchema, I, S>(
183
- editor,
184
- (triggerCharacter, state) => {
185
- this.emit(`update ${triggerCharacter}`, state);
186
- }
187
- );
188
- return this.view;
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
- // Apply changes to the plugin state from an editor transaction.
198
- apply: (
199
- transaction,
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
- const next = { ...prev };
208
+ // Ignore transactions in code blocks.
209
+ if (transaction.selection.$from.parent.type.spec.code) {
210
+ return prev;
211
+ }
281
212
 
282
- // Updates the current query.
283
- next.query = newState.doc.textBetween(
284
- prev.queryStartPos(),
285
- newState.selection.from
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
- return next;
289
- },
290
- },
291
-
292
- props: {
293
- handleTextInput(view, _from, _to, text) {
294
- if (triggerCharacters.includes(text)) {
295
- view.dispatch(view.state.tr.insertText(text));
296
- view.dispatch(
297
- view.state.tr
298
- .setMeta(suggestionMenuPluginKey, {
299
- triggerCharacter: text,
300
- })
301
- .scrollIntoView()
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 true;
305
- }
306
- return false;
287
+ return next;
288
+ },
307
289
  },
308
290
 
309
- // Setup decorator on the currently active suggestion.
310
- decorations(state) {
311
- const suggestionPluginState: SuggestionPluginState = (
312
- this as Plugin
313
- ).getState(state);
314
-
315
- if (suggestionPluginState === undefined) {
316
- return null;
317
- }
318
-
319
- // If the menu was opened programmatically by another extension, it may not use a trigger character. In this
320
- // case, the decoration is set on the whole block instead, as the decoration range would otherwise be empty.
321
- if (!suggestionPluginState.deleteTriggerCharacter) {
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
- // Creates an inline decoration around the trigger character.
338
- return DecorationSet.create(state.doc, [
339
- Decoration.inline(
340
- suggestionPluginState.queryStartPos() -
341
- suggestionPluginState.triggerCharacter!.length,
342
- suggestionPluginState.queryStartPos(),
343
- {
344
- nodeName: "span",
345
- class: "bn-suggestion-decorator",
346
- "data-decoration-id": suggestionPluginState.decorationId,
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!.plugin, {
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!.plugin, {
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!.plugin, {
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!.plugin, {
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
  }