@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
@@ -32,13 +32,13 @@ import {
32
32
  } from "../../blocks/defaultBlockTypeGuards.js";
33
33
  import { DefaultBlockSchema } from "../../blocks/defaultBlocks.js";
34
34
  import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
35
+ import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
35
36
  import {
36
37
  BlockFromConfigNoChildren,
37
38
  BlockSchemaWithBlock,
38
39
  InlineContentSchema,
39
40
  StyleSchema,
40
41
  } from "../../schema/index.js";
41
- import { EventEmitter } from "../../util/EventEmitter.js";
42
42
  import { getDraggableBlockFromElement } from "../getDraggableBlockFromElement.js";
43
43
 
44
44
  let dragImageElement: HTMLElement | undefined;
@@ -46,7 +46,7 @@ let dragImageElement: HTMLElement | undefined;
46
46
  // TODO consider switching this to jotai, it is a bit messy and noisy
47
47
  export type TableHandlesState<
48
48
  I extends InlineContentSchema,
49
- S extends StyleSchema
49
+ S extends StyleSchema,
50
50
  > = {
51
51
  show: boolean;
52
52
  showAddOrRemoveRowsButton: boolean;
@@ -146,7 +146,7 @@ function hideElements(selector: string, rootEl: Document | ShadowRoot) {
146
146
 
147
147
  export class TableHandlesView<
148
148
  I extends InlineContentSchema,
149
- S extends StyleSchema
149
+ S extends StyleSchema,
150
150
  > implements PluginView
151
151
  {
152
152
  public state?: TableHandlesState<I, S>;
@@ -169,7 +169,7 @@ export class TableHandlesView<
169
169
  S
170
170
  >,
171
171
  private readonly pmView: EditorView,
172
- emitUpdate: (state: TableHandlesState<I, S>) => void
172
+ emitUpdate: (state: TableHandlesState<I, S>) => void,
173
173
  ) {
174
174
  this.emitUpdate = () => {
175
175
  if (!this.state) {
@@ -185,11 +185,11 @@ export class TableHandlesView<
185
185
 
186
186
  pmView.root.addEventListener(
187
187
  "dragover",
188
- this.dragOverHandler as EventListener
188
+ this.dragOverHandler as EventListener,
189
189
  );
190
190
  pmView.root.addEventListener(
191
191
  "drop",
192
- this.dropHandler as unknown as EventListener
192
+ this.dropHandler as unknown as EventListener,
193
193
  );
194
194
  }
195
195
 
@@ -264,7 +264,7 @@ export class TableHandlesView<
264
264
  | undefined;
265
265
 
266
266
  const pmNodeInfo = this.editor.transact((tr) =>
267
- getNodeById(blockEl.id, tr.doc)
267
+ getNodeById(blockEl.id, tr.doc),
268
268
  );
269
269
  if (!pmNodeInfo) {
270
270
  throw new Error(`Block with ID ${blockEl.id} not found`);
@@ -275,7 +275,7 @@ export class TableHandlesView<
275
275
  this.editor.pmSchema,
276
276
  this.editor.schema.blockSchema,
277
277
  this.editor.schema.inlineContentSchema,
278
- this.editor.schema.styleSchema
278
+ this.editor.schema.styleSchema,
279
279
  );
280
280
 
281
281
  if (checkBlockIsDefaultType("table", block, this.editor)) {
@@ -368,7 +368,7 @@ export class TableHandlesView<
368
368
 
369
369
  hideElements(
370
370
  ".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",
371
- this.pmView.root
371
+ this.pmView.root,
372
372
  );
373
373
 
374
374
  // The mouse cursor coordinates, bounded to the table's bounding box. The
@@ -377,11 +377,11 @@ export class TableHandlesView<
377
377
  const boundedMouseCoords = {
378
378
  left: Math.min(
379
379
  Math.max(event.clientX, this.state.referencePosTable.left + 1),
380
- this.state.referencePosTable.right - 1
380
+ this.state.referencePosTable.right - 1,
381
381
  ),
382
382
  top: Math.min(
383
383
  Math.max(event.clientY, this.state.referencePosTable.top + 1),
384
- this.state.referencePosTable.bottom - 1
384
+ this.state.referencePosTable.bottom - 1,
385
385
  ),
386
386
  };
387
387
 
@@ -390,7 +390,7 @@ export class TableHandlesView<
390
390
  const tableCellElements = this.pmView.root
391
391
  .elementsFromPoint(boundedMouseCoords.left, boundedMouseCoords.top)
392
392
  .filter(
393
- (element) => element.tagName === "TD" || element.tagName === "TH"
393
+ (element) => element.tagName === "TD" || element.tagName === "TH",
394
394
  );
395
395
  if (tableCellElements.length === 0) {
396
396
  return;
@@ -461,7 +461,7 @@ export class TableHandlesView<
461
461
  this.state.colIndex === undefined
462
462
  ) {
463
463
  throw new Error(
464
- "Attempted to drop table row or column, but no table block was hovered prior."
464
+ "Attempted to drop table row or column, but no table block was hovered prior.",
465
465
  );
466
466
  }
467
467
 
@@ -476,7 +476,7 @@ export class TableHandlesView<
476
476
  !canRowBeDraggedInto(
477
477
  this.state.block,
478
478
  draggingState.originalIndex,
479
- rowIndex
479
+ rowIndex,
480
480
  )
481
481
  ) {
482
482
  // If the target row is invalid, don't move the row
@@ -485,7 +485,7 @@ export class TableHandlesView<
485
485
  const newTable = moveRow(
486
486
  this.state.block,
487
487
  draggingState.originalIndex,
488
- rowIndex
488
+ rowIndex,
489
489
  );
490
490
  this.editor.updateBlock(this.state.block, {
491
491
  type: "table",
@@ -499,7 +499,7 @@ export class TableHandlesView<
499
499
  !canColumnBeDraggedInto(
500
500
  this.state.block,
501
501
  draggingState.originalIndex,
502
- colIndex
502
+ colIndex,
503
503
  )
504
504
  ) {
505
505
  // If the target column is invalid, don't move the column
@@ -508,7 +508,7 @@ export class TableHandlesView<
508
508
  const newTable = moveColumn(
509
509
  this.state.block,
510
510
  draggingState.originalIndex,
511
- colIndex
511
+ colIndex,
512
512
  );
513
513
  const [columnWidth] = columnWidths.splice(draggingState.originalIndex, 1);
514
514
  columnWidths.splice(colIndex, 0, columnWidth);
@@ -538,6 +538,7 @@ export class TableHandlesView<
538
538
  this.state.block = this.editor.getBlock(this.state.block.id)!;
539
539
  if (
540
540
  !this.state.block ||
541
+ this.state.block.type !== "table" ||
541
542
  // when collaborating, the table element might be replaced and out of date
542
543
  // because yjs replaces the element when for example you change the color via the side menu
543
544
  !this.tableElement?.isConnected
@@ -551,7 +552,7 @@ export class TableHandlesView<
551
552
  }
552
553
 
553
554
  const { height: rowCount, width: colCount } = getDimensionsOfTable(
554
- this.state.block
555
+ this.state.block,
555
556
  );
556
557
 
557
558
  if (
@@ -574,7 +575,7 @@ export class TableHandlesView<
574
575
 
575
576
  if (!tableBody) {
576
577
  throw new Error(
577
- "Table block does not contain a 'tbody' HTML element. This should never happen."
578
+ "Table block does not contain a 'tbody' HTML element. This should never happen.",
578
579
  );
579
580
  }
580
581
 
@@ -602,11 +603,11 @@ export class TableHandlesView<
602
603
  this.pmView.dom.removeEventListener("mousedown", this.viewMousedownHandler);
603
604
  this.pmView.root.removeEventListener(
604
605
  "dragover",
605
- this.dragOverHandler as EventListener
606
+ this.dragOverHandler as EventListener,
606
607
  );
607
608
  this.pmView.root.removeEventListener(
608
609
  "drop",
609
- this.dropHandler as unknown as EventListener
610
+ this.dropHandler as unknown as EventListener,
610
611
  );
611
612
  }
612
613
  }
@@ -615,172 +616,175 @@ export const tableHandlesPluginKey = new PluginKey("TableHandlesPlugin");
615
616
 
616
617
  export class TableHandlesProsemirrorPlugin<
617
618
  I extends InlineContentSchema,
618
- S extends StyleSchema
619
- > extends EventEmitter<any> {
619
+ S extends StyleSchema,
620
+ > extends BlockNoteExtension {
620
621
  private view: TableHandlesView<I, S> | undefined;
621
- public readonly plugin: Plugin;
622
622
 
623
623
  constructor(
624
624
  private readonly editor: BlockNoteEditor<
625
625
  BlockSchemaWithBlock<"table", DefaultBlockSchema["table"]>,
626
626
  I,
627
627
  S
628
- >
628
+ >,
629
629
  ) {
630
630
  super();
631
- this.plugin = new Plugin({
632
- key: tableHandlesPluginKey,
633
- view: (editorView) => {
634
- this.view = new TableHandlesView(editor, editorView, (state) => {
635
- this.emit("update", state);
636
- });
637
- return this.view;
638
- },
639
- // We use decorations to render the drop cursor when dragging a table row
640
- // or column. The decorations are updated in the `dragOverHandler` method.
641
- props: {
642
- decorations: (state) => {
643
- if (
644
- this.view === undefined ||
645
- this.view.state === undefined ||
646
- this.view.state.draggingState === undefined ||
647
- this.view.tablePos === undefined
648
- ) {
649
- return;
650
- }
651
-
652
- const newIndex =
653
- this.view.state.draggingState.draggedCellOrientation === "row"
654
- ? this.view.state.rowIndex
655
- : this.view.state.colIndex;
656
-
657
- if (newIndex === undefined) {
658
- return;
659
- }
660
-
661
- const decorations: Decoration[] = [];
662
- const { block, draggingState } = this.view.state;
663
- const { originalIndex, draggedCellOrientation } = draggingState;
664
-
665
- // Return empty decorations if:
666
- // - Dragging to same position
667
- // - No block exists
668
- // - Row drag not allowed
669
- // - Column drag not allowed
670
- if (
671
- newIndex === originalIndex ||
672
- !block ||
673
- (draggedCellOrientation === "row" &&
674
- !canRowBeDraggedInto(block, originalIndex, newIndex)) ||
675
- (draggedCellOrientation === "col" &&
676
- !canColumnBeDraggedInto(block, originalIndex, newIndex))
677
- ) {
678
- return DecorationSet.create(state.doc, decorations);
679
- }
680
-
681
- // Gets the table to show the drop cursor in.
682
- const tableResolvedPos = state.doc.resolve(this.view.tablePos + 1);
683
-
684
- if (this.view.state.draggingState.draggedCellOrientation === "row") {
685
- const cellsInRow = getCellsAtRowHandle(
686
- this.view.state.block,
687
- newIndex
688
- );
689
-
690
- cellsInRow.forEach(({ row, col }) => {
691
- // Gets each row in the table.
692
- const rowResolvedPos = state.doc.resolve(
693
- tableResolvedPos.posAtIndex(row) + 1
631
+ this.addProsemirrorPlugin(
632
+ new Plugin({
633
+ key: tableHandlesPluginKey,
634
+ view: (editorView) => {
635
+ this.view = new TableHandlesView(editor, editorView, (state) => {
636
+ this.emit("update", state);
637
+ });
638
+ return this.view;
639
+ },
640
+ // We use decorations to render the drop cursor when dragging a table row
641
+ // or column. The decorations are updated in the `dragOverHandler` method.
642
+ props: {
643
+ decorations: (state) => {
644
+ if (
645
+ this.view === undefined ||
646
+ this.view.state === undefined ||
647
+ this.view.state.draggingState === undefined ||
648
+ this.view.tablePos === undefined
649
+ ) {
650
+ return;
651
+ }
652
+
653
+ const newIndex =
654
+ this.view.state.draggingState.draggedCellOrientation === "row"
655
+ ? this.view.state.rowIndex
656
+ : this.view.state.colIndex;
657
+
658
+ if (newIndex === undefined) {
659
+ return;
660
+ }
661
+
662
+ const decorations: Decoration[] = [];
663
+ const { block, draggingState } = this.view.state;
664
+ const { originalIndex, draggedCellOrientation } = draggingState;
665
+
666
+ // Return empty decorations if:
667
+ // - Dragging to same position
668
+ // - No block exists
669
+ // - Row drag not allowed
670
+ // - Column drag not allowed
671
+ if (
672
+ newIndex === originalIndex ||
673
+ !block ||
674
+ (draggedCellOrientation === "row" &&
675
+ !canRowBeDraggedInto(block, originalIndex, newIndex)) ||
676
+ (draggedCellOrientation === "col" &&
677
+ !canColumnBeDraggedInto(block, originalIndex, newIndex))
678
+ ) {
679
+ return DecorationSet.create(state.doc, decorations);
680
+ }
681
+
682
+ // Gets the table to show the drop cursor in.
683
+ const tableResolvedPos = state.doc.resolve(this.view.tablePos + 1);
684
+
685
+ if (
686
+ this.view.state.draggingState.draggedCellOrientation === "row"
687
+ ) {
688
+ const cellsInRow = getCellsAtRowHandle(
689
+ this.view.state.block,
690
+ newIndex,
694
691
  );
695
692
 
696
- // Gets the cell within the row.
697
- const cellResolvedPos = state.doc.resolve(
698
- rowResolvedPos.posAtIndex(col) + 1
699
- );
700
- const cellNode = cellResolvedPos.node();
701
- // Creates a decoration at the start or end of each cell,
702
- // depending on whether the new index is before or after the
703
- // original index.
704
- const decorationPos =
705
- cellResolvedPos.pos +
706
- (newIndex > originalIndex ? cellNode.nodeSize - 2 : 0);
707
- decorations.push(
708
- // The widget is a small bar which spans the width of the cell.
709
- Decoration.widget(decorationPos, () => {
710
- const widget = document.createElement("div");
711
- widget.className = "bn-table-drop-cursor";
712
- widget.style.left = "0";
713
- widget.style.right = "0";
714
- // This is only necessary because the drop indicator's height
715
- // is an even number of pixels, whereas the border between
716
- // table cells is an odd number of pixels. So this makes the
717
- // positioning slightly more consistent regardless of where
718
- // the row is being dropped.
719
- if (newIndex > originalIndex) {
720
- widget.style.bottom = "-2px";
721
- } else {
722
- widget.style.top = "-3px";
723
- }
724
- widget.style.height = "4px";
725
-
726
- return widget;
727
- })
728
- );
729
- });
730
- } else {
731
- const cellsInColumn = getCellsAtColumnHandle(
732
- this.view.state.block,
733
- newIndex
734
- );
735
-
736
- cellsInColumn.forEach(({ row, col }) => {
737
- // Gets each row in the table.
738
- const rowResolvedPos = state.doc.resolve(
739
- tableResolvedPos.posAtIndex(row) + 1
693
+ cellsInRow.forEach(({ row, col }) => {
694
+ // Gets each row in the table.
695
+ const rowResolvedPos = state.doc.resolve(
696
+ tableResolvedPos.posAtIndex(row) + 1,
697
+ );
698
+
699
+ // Gets the cell within the row.
700
+ const cellResolvedPos = state.doc.resolve(
701
+ rowResolvedPos.posAtIndex(col) + 1,
702
+ );
703
+ const cellNode = cellResolvedPos.node();
704
+ // Creates a decoration at the start or end of each cell,
705
+ // depending on whether the new index is before or after the
706
+ // original index.
707
+ const decorationPos =
708
+ cellResolvedPos.pos +
709
+ (newIndex > originalIndex ? cellNode.nodeSize - 2 : 0);
710
+ decorations.push(
711
+ // The widget is a small bar which spans the width of the cell.
712
+ Decoration.widget(decorationPos, () => {
713
+ const widget = document.createElement("div");
714
+ widget.className = "bn-table-drop-cursor";
715
+ widget.style.left = "0";
716
+ widget.style.right = "0";
717
+ // This is only necessary because the drop indicator's height
718
+ // is an even number of pixels, whereas the border between
719
+ // table cells is an odd number of pixels. So this makes the
720
+ // positioning slightly more consistent regardless of where
721
+ // the row is being dropped.
722
+ if (newIndex > originalIndex) {
723
+ widget.style.bottom = "-2px";
724
+ } else {
725
+ widget.style.top = "-3px";
726
+ }
727
+ widget.style.height = "4px";
728
+
729
+ return widget;
730
+ }),
731
+ );
732
+ });
733
+ } else {
734
+ const cellsInColumn = getCellsAtColumnHandle(
735
+ this.view.state.block,
736
+ newIndex,
740
737
  );
741
738
 
742
- // Gets the cell within the row.
743
- const cellResolvedPos = state.doc.resolve(
744
- rowResolvedPos.posAtIndex(col) + 1
745
- );
746
- const cellNode = cellResolvedPos.node();
747
-
748
- // Creates a decoration at the start or end of each cell,
749
- // depending on whether the new index is before or after the
750
- // original index.
751
- const decorationPos =
752
- cellResolvedPos.pos +
753
- (newIndex > originalIndex ? cellNode.nodeSize - 2 : 0);
754
-
755
- decorations.push(
756
- // The widget is a small bar which spans the height of the cell.
757
- Decoration.widget(decorationPos, () => {
758
- const widget = document.createElement("div");
759
- widget.className = "bn-table-drop-cursor";
760
- widget.style.top = "0";
761
- widget.style.bottom = "0";
762
- // This is only necessary because the drop indicator's width
763
- // is an even number of pixels, whereas the border between
764
- // table cells is an odd number of pixels. So this makes the
765
- // positioning slightly more consistent regardless of where
766
- // the column is being dropped.
767
- if (newIndex > originalIndex) {
768
- widget.style.right = "-2px";
769
- } else {
770
- widget.style.left = "-3px";
771
- }
772
- widget.style.width = "4px";
773
-
774
- return widget;
775
- })
776
- );
777
- });
778
- }
739
+ cellsInColumn.forEach(({ row, col }) => {
740
+ // Gets each row in the table.
741
+ const rowResolvedPos = state.doc.resolve(
742
+ tableResolvedPos.posAtIndex(row) + 1,
743
+ );
744
+
745
+ // Gets the cell within the row.
746
+ const cellResolvedPos = state.doc.resolve(
747
+ rowResolvedPos.posAtIndex(col) + 1,
748
+ );
749
+ const cellNode = cellResolvedPos.node();
750
+
751
+ // Creates a decoration at the start or end of each cell,
752
+ // depending on whether the new index is before or after the
753
+ // original index.
754
+ const decorationPos =
755
+ cellResolvedPos.pos +
756
+ (newIndex > originalIndex ? cellNode.nodeSize - 2 : 0);
757
+
758
+ decorations.push(
759
+ // The widget is a small bar which spans the height of the cell.
760
+ Decoration.widget(decorationPos, () => {
761
+ const widget = document.createElement("div");
762
+ widget.className = "bn-table-drop-cursor";
763
+ widget.style.top = "0";
764
+ widget.style.bottom = "0";
765
+ // This is only necessary because the drop indicator's width
766
+ // is an even number of pixels, whereas the border between
767
+ // table cells is an odd number of pixels. So this makes the
768
+ // positioning slightly more consistent regardless of where
769
+ // the column is being dropped.
770
+ if (newIndex > originalIndex) {
771
+ widget.style.right = "-2px";
772
+ } else {
773
+ widget.style.left = "-3px";
774
+ }
775
+ widget.style.width = "4px";
776
+
777
+ return widget;
778
+ }),
779
+ );
780
+ });
781
+ }
779
782
 
780
- return DecorationSet.create(state.doc, decorations);
783
+ return DecorationSet.create(state.doc, decorations);
784
+ },
781
785
  },
782
- },
783
- });
786
+ }),
787
+ );
784
788
  }
785
789
 
786
790
  public onUpdate(callback: (state: TableHandlesState<I, S>) => void) {
@@ -800,7 +804,7 @@ export class TableHandlesProsemirrorPlugin<
800
804
  this.view!.state.colIndex === undefined
801
805
  ) {
802
806
  throw new Error(
803
- "Attempted to drag table column, but no table block was hovered prior."
807
+ "Attempted to drag table column, but no table block was hovered prior.",
804
808
  );
805
809
  }
806
810
 
@@ -818,7 +822,7 @@ export class TableHandlesProsemirrorPlugin<
818
822
  originalIndex: this.view!.state!.colIndex,
819
823
  newIndex: this.view!.state!.colIndex,
820
824
  tablePos: this.view!.tablePos,
821
- })
825
+ }),
822
826
  );
823
827
 
824
828
  if (!this.editor.prosemirrorView) {
@@ -843,7 +847,7 @@ export class TableHandlesProsemirrorPlugin<
843
847
  this.view!.state.rowIndex === undefined
844
848
  ) {
845
849
  throw new Error(
846
- "Attempted to drag table row, but no table block was hovered prior."
850
+ "Attempted to drag table row, but no table block was hovered prior.",
847
851
  );
848
852
  }
849
853
 
@@ -861,7 +865,7 @@ export class TableHandlesProsemirrorPlugin<
861
865
  originalIndex: this.view!.state!.rowIndex,
862
866
  newIndex: this.view!.state!.rowIndex,
863
867
  tablePos: this.view!.tablePos,
864
- })
868
+ }),
865
869
  );
866
870
 
867
871
  if (!this.editor.prosemirrorView) {
@@ -880,7 +884,7 @@ export class TableHandlesProsemirrorPlugin<
880
884
  dragEnd = () => {
881
885
  if (this.view!.state === undefined) {
882
886
  throw new Error(
883
- "Attempted to drag table row, but no table block was hovered prior."
887
+ "Attempted to drag table row, but no table block was hovered prior.",
884
888
  );
885
889
  }
886
890
 
@@ -914,7 +918,7 @@ export class TableHandlesProsemirrorPlugin<
914
918
 
915
919
  getCellsAtRowHandle = (
916
920
  block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>,
917
- relativeRowIndex: RelativeCellIndices["row"]
921
+ relativeRowIndex: RelativeCellIndices["row"],
918
922
  ) => {
919
923
  return getCellsAtRowHandle(block, relativeRowIndex);
920
924
  };
@@ -924,7 +928,7 @@ export class TableHandlesProsemirrorPlugin<
924
928
  */
925
929
  getCellsAtColumnHandle = (
926
930
  block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>,
927
- relativeColumnIndex: RelativeCellIndices["col"]
931
+ relativeColumnIndex: RelativeCellIndices["col"],
928
932
  ) => {
929
933
  return getCellsAtColumnHandle(block, relativeColumnIndex);
930
934
  };
@@ -936,7 +940,7 @@ export class TableHandlesProsemirrorPlugin<
936
940
  private setCellSelection = (
937
941
  state: EditorState,
938
942
  relativeStartCell: RelativeCellIndices,
939
- relativeEndCell: RelativeCellIndices = relativeStartCell
943
+ relativeEndCell: RelativeCellIndices = relativeStartCell,
940
944
  ) => {
941
945
  const view = this.view;
942
946
 
@@ -946,18 +950,18 @@ export class TableHandlesProsemirrorPlugin<
946
950
 
947
951
  const tableResolvedPos = state.doc.resolve(view.tablePos! + 1);
948
952
  const startRowResolvedPos = state.doc.resolve(
949
- tableResolvedPos.posAtIndex(relativeStartCell.row) + 1
953
+ tableResolvedPos.posAtIndex(relativeStartCell.row) + 1,
950
954
  );
951
955
  const startCellResolvedPos = state.doc.resolve(
952
956
  // No need for +1, since CellSelection expects the position before the cell
953
- startRowResolvedPos.posAtIndex(relativeStartCell.col)
957
+ startRowResolvedPos.posAtIndex(relativeStartCell.col),
954
958
  );
955
959
  const endRowResolvedPos = state.doc.resolve(
956
- tableResolvedPos.posAtIndex(relativeEndCell.row) + 1
960
+ tableResolvedPos.posAtIndex(relativeEndCell.row) + 1,
957
961
  );
958
962
  const endCellResolvedPos = state.doc.resolve(
959
963
  // No need for +1, since CellSelection expects the position before the cell
960
- endRowResolvedPos.posAtIndex(relativeEndCell.col)
964
+ endRowResolvedPos.posAtIndex(relativeEndCell.col),
961
965
  );
962
966
 
963
967
  // Begin a new transaction to set the selection
@@ -965,7 +969,7 @@ export class TableHandlesProsemirrorPlugin<
965
969
 
966
970
  // Set the selection to the given cell or a range of cells
967
971
  tr.setSelection(
968
- new CellSelection(startCellResolvedPos, endCellResolvedPos)
972
+ new CellSelection(startCellResolvedPos, endCellResolvedPos),
969
973
  );
970
974
 
971
975
  // Quickly apply the transaction to get the new state to update the selection before splitting the cell
@@ -979,14 +983,14 @@ export class TableHandlesProsemirrorPlugin<
979
983
  index: RelativeCellIndices["row"] | RelativeCellIndices["col"],
980
984
  direction:
981
985
  | { orientation: "row"; side: "above" | "below" }
982
- | { orientation: "column"; side: "left" | "right" }
986
+ | { orientation: "column"; side: "left" | "right" },
983
987
  ) => {
984
988
  this.editor.exec((beforeState, dispatch) => {
985
989
  const state = this.setCellSelection(
986
990
  beforeState,
987
991
  direction.orientation === "row"
988
992
  ? { row: index, col: 0 }
989
- : { row: 0, col: index }
993
+ : { row: 0, col: index },
990
994
  );
991
995
 
992
996
  if (direction.orientation === "row") {
@@ -1010,7 +1014,7 @@ export class TableHandlesProsemirrorPlugin<
1010
1014
  */
1011
1015
  removeRowOrColumn = (
1012
1016
  index: RelativeCellIndices["row"] | RelativeCellIndices["col"],
1013
- direction: "row" | "column"
1017
+ direction: "row" | "column",
1014
1018
  ) => {
1015
1019
  if (direction === "row") {
1016
1020
  return this.editor.exec((beforeState, dispatch) => {
@@ -1043,7 +1047,7 @@ export class TableHandlesProsemirrorPlugin<
1043
1047
  ? this.setCellSelection(
1044
1048
  beforeState,
1045
1049
  cellsToMerge.relativeStartCell,
1046
- cellsToMerge.relativeEndCell
1050
+ cellsToMerge.relativeEndCell,
1047
1051
  )
1048
1052
  : beforeState;
1049
1053
 
@@ -1099,10 +1103,10 @@ export class TableHandlesProsemirrorPlugin<
1099
1103
  // Assumes we are within a tableParagraph
1100
1104
  // And find the from and to cells by resolving the positions
1101
1105
  $fromCell = tr.doc.resolve(
1102
- selection.$from.pos - selection.$from.parentOffset - 1
1106
+ selection.$from.pos - selection.$from.parentOffset - 1,
1103
1107
  );
1104
1108
  $toCell = tr.doc.resolve(
1105
- selection.$to.pos - selection.$to.parentOffset - 1
1109
+ selection.$to.pos - selection.$to.parentOffset - 1,
1106
1110
  );
1107
1111
 
1108
1112
  // Opt-out when the selection is not pointing into cells
@@ -1113,7 +1117,7 @@ export class TableHandlesProsemirrorPlugin<
1113
1117
 
1114
1118
  // Find the row and table that the from and to cells are in
1115
1119
  const $fromRow = tr.doc.resolve(
1116
- $fromCell.pos - $fromCell.parentOffset - 1
1120
+ $fromCell.pos - $fromCell.parentOffset - 1,
1117
1121
  );
1118
1122
  const $toRow = tr.doc.resolve($toCell.pos - $toCell.parentOffset - 1);
1119
1123
 
@@ -1155,7 +1159,7 @@ export class TableHandlesProsemirrorPlugin<
1155
1159
  getMergeDirection = (
1156
1160
  block:
1157
1161
  | BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>
1158
- | undefined
1162
+ | undefined,
1159
1163
  ) => {
1160
1164
  return this.editor.transact((tr) => {
1161
1165
  const isSelectingTableCells = isTableCellSelection(tr.selection)
@@ -1187,7 +1191,7 @@ export class TableHandlesProsemirrorPlugin<
1187
1191
 
1188
1192
  cropEmptyRowsOrColumns = (
1189
1193
  block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>,
1190
- removeEmpty: "columns" | "rows"
1194
+ removeEmpty: "columns" | "rows",
1191
1195
  ) => {
1192
1196
  return cropEmptyRowsOrColumns(block, removeEmpty);
1193
1197
  };
@@ -1195,7 +1199,7 @@ export class TableHandlesProsemirrorPlugin<
1195
1199
  addRowsOrColumns = (
1196
1200
  block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>,
1197
1201
  addType: "columns" | "rows",
1198
- numToAdd: number
1202
+ numToAdd: number,
1199
1203
  ) => {
1200
1204
  return addRowsOrColumns(block, addType, numToAdd);
1201
1205
  };