@blocknote/core 0.28.0 → 0.29.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 (381) hide show
  1. package/dist/blocknote.cjs +9 -9
  2. package/dist/blocknote.cjs.map +1 -1
  3. package/dist/blocknote.js +3221 -3351
  4. package/dist/blocknote.js.map +1 -1
  5. package/dist/tsconfig.tsbuildinfo +1 -1
  6. package/dist/webpack-stats.json +1 -1
  7. package/package.json +2 -2
  8. package/src/api/__snapshots__/blocks-deleted-nested-deep.json +26 -0
  9. package/src/api/__snapshots__/blocks-deleted-nested.json +68 -0
  10. package/src/api/__snapshots__/blocks-deleted.json +26 -0
  11. package/src/api/__snapshots__/blocks-inserted-nested.json +62 -0
  12. package/src/api/__snapshots__/blocks-inserted.json +20 -0
  13. package/src/api/__snapshots__/blocks-updated-content-inserted.json +42 -0
  14. package/src/api/__snapshots__/blocks-updated-multiple-insert.json +50 -0
  15. package/src/api/__snapshots__/blocks-updated-multiple.json +82 -0
  16. package/src/api/__snapshots__/blocks-updated-nested-deep.json +42 -0
  17. package/src/api/__snapshots__/blocks-updated-nested-multiple.json +118 -0
  18. package/src/api/__snapshots__/blocks-updated-nested.json +78 -0
  19. package/src/api/__snapshots__/blocks-updated-single.json +42 -0
  20. package/src/api/__snapshots__/blocks-updated.json +42 -0
  21. package/src/api/blockManipulation/__snapshots__/transactions.test.ts.snap +34 -0
  22. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +312 -0
  23. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +127 -94
  24. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +19 -37
  25. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +8 -6
  26. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +25 -31
  27. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +93 -91
  28. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +16 -20
  29. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +14 -1
  30. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +18 -56
  31. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +52 -46
  32. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +1051 -0
  33. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +247 -154
  34. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +109 -142
  35. package/src/api/blockManipulation/getBlock/getBlock.ts +23 -48
  36. package/src/api/blockManipulation/insertContentAt.ts +4 -17
  37. package/src/api/blockManipulation/selections/selection.test.ts +32 -16
  38. package/src/api/blockManipulation/selections/selection.ts +25 -51
  39. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +35 -14
  40. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +34 -65
  41. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +8 -10
  42. package/src/api/clipboard/toClipboard/copyExtension.ts +7 -7
  43. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +7 -16
  44. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +3 -17
  45. package/src/api/getBlockInfoFromPos.ts +13 -1
  46. package/src/api/nodeConversions/blockToNode.ts +21 -10
  47. package/src/api/nodeConversions/fragmentToBlocks.ts +5 -18
  48. package/src/api/nodeConversions/nodeToBlock.ts +11 -8
  49. package/src/api/nodeUtil.test.ts +228 -0
  50. package/src/api/nodeUtil.ts +235 -2
  51. package/src/api/parsers/html/parseHTML.ts +2 -10
  52. package/src/api/parsers/markdown/parseMarkdown.ts +2 -8
  53. package/src/api/pmUtil.ts +54 -0
  54. package/src/api/positionMapping.ts +4 -2
  55. package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +2 -2
  56. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +9 -13
  57. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +5 -9
  58. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +19 -31
  59. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +10 -8
  60. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +9 -13
  61. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +1 -1
  62. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +5 -9
  63. package/src/blocks/defaultBlockHelpers.ts +1 -1
  64. package/src/editor/BlockNoteEditor.test.ts +1 -1
  65. package/src/editor/BlockNoteEditor.ts +259 -131
  66. package/src/editor/BlockNoteTipTapEditor.ts +91 -8
  67. package/src/extensions/Comments/CommentsPlugin.ts +32 -34
  68. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +4 -8
  69. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +12 -13
  70. package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +1 -3
  71. package/src/extensions/SideMenu/MultipleNodeSelection.ts +3 -1
  72. package/src/extensions/SideMenu/dragging.ts +1 -1
  73. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +22 -19
  74. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +8 -8
  75. package/src/extensions/TableHandles/TableHandlesPlugin.ts +150 -136
  76. package/src/index.ts +4 -3
  77. package/src/schema/inlineContent/createSpec.ts +1 -5
  78. package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +2 -2
  79. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +4 -8
  80. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +9 -10
  81. package/types/src/api/blockManipulation/getBlock/getBlock.d.ts +7 -7
  82. package/types/src/api/blockManipulation/insertContentAt.d.ts +5 -3
  83. package/types/src/api/blockManipulation/selections/selection.d.ts +3 -3
  84. package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.d.ts +5 -5
  85. package/types/src/api/getBlockInfoFromPos.d.ts +8 -1
  86. package/types/src/api/nodeConversions/blockToNode.d.ts +3 -3
  87. package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +1 -2
  88. package/types/src/api/nodeConversions/nodeToBlock.d.ts +2 -2
  89. package/types/src/api/nodeUtil.d.ts +67 -1
  90. package/types/src/api/parsers/html/parseHTML.d.ts +1 -1
  91. package/types/src/api/parsers/markdown/parseMarkdown.d.ts +1 -1
  92. package/types/src/api/pmUtil.d.ts +12 -0
  93. package/types/src/editor/BlockNoteEditor.d.ts +72 -10
  94. package/types/src/editor/BlockNoteTipTapEditor.d.ts +15 -2
  95. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +1 -1
  96. package/types/src/index.d.ts +1 -2
  97. package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +0 -1859
  98. package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.ts +0 -40
  99. package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts +0 -20
  100. package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraph.html +0 -138
  101. package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraphText.html +0 -138
  102. package/src/api/clipboard/__snapshots__/external/pasteImage.html +0 -153
  103. package/src/api/clipboard/__snapshots__/external/pasteParagraphInCustomBlock.html +0 -138
  104. package/src/api/clipboard/__snapshots__/external/pasteTable.html +0 -233
  105. package/src/api/clipboard/__snapshots__/external/pasteTableInExistingTable.html +0 -216
  106. package/src/api/clipboard/__snapshots__/internal/basicBlocks.html +0 -1
  107. package/src/api/clipboard/__snapshots__/internal/basicBlocksWithProps.html +0 -1
  108. package/src/api/clipboard/__snapshots__/internal/childToParent.html +0 -1
  109. package/src/api/clipboard/__snapshots__/internal/childrenToNextParent.html +0 -1
  110. package/src/api/clipboard/__snapshots__/internal/childrenToNextParentsChildren.html +0 -1
  111. package/src/api/clipboard/__snapshots__/internal/image.html +0 -1
  112. package/src/api/clipboard/__snapshots__/internal/multipleChildren.html +0 -1
  113. package/src/api/clipboard/__snapshots__/internal/multipleStyledText.html +0 -1
  114. package/src/api/clipboard/__snapshots__/internal/nestedImage.html +0 -1
  115. package/src/api/clipboard/__snapshots__/internal/paragraphInCustomBlock.html +0 -1
  116. package/src/api/clipboard/__snapshots__/internal/partialChildToParent.html +0 -1
  117. package/src/api/clipboard/__snapshots__/internal/styledText.html +0 -1
  118. package/src/api/clipboard/__snapshots__/internal/tableAllCells.html +0 -1
  119. package/src/api/clipboard/__snapshots__/internal/tableCell.html +0 -1
  120. package/src/api/clipboard/__snapshots__/internal/tableCellText.html +0 -1
  121. package/src/api/clipboard/__snapshots__/internal/tableRow.html +0 -1
  122. package/src/api/clipboard/__snapshots__/internal/unstyledText.html +0 -1
  123. package/src/api/clipboard/clipboardExternal.test.ts +0 -161
  124. package/src/api/clipboard/clipboardInternal.test.ts +0 -435
  125. package/src/api/clipboard/testUtil.ts +0 -27
  126. package/src/api/exporters/html/__snapshots__/codeBlock/contains-newlines/external.html +0 -1
  127. package/src/api/exporters/html/__snapshots__/codeBlock/contains-newlines/internal.html +0 -3
  128. package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/external.html +0 -1
  129. package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/internal.html +0 -1
  130. package/src/api/exporters/html/__snapshots__/codeBlock/empty/external.html +0 -1
  131. package/src/api/exporters/html/__snapshots__/codeBlock/empty/internal.html +0 -1
  132. package/src/api/exporters/html/__snapshots__/codeBlock/python/external.html +0 -1
  133. package/src/api/exporters/html/__snapshots__/codeBlock/python/internal.html +0 -1
  134. package/src/api/exporters/html/__snapshots__/complex/misc/external.html +0 -1
  135. package/src/api/exporters/html/__snapshots__/complex/misc/internal.html +0 -1
  136. package/src/api/exporters/html/__snapshots__/customBlock/basic/external.html +0 -1
  137. package/src/api/exporters/html/__snapshots__/customBlock/basic/internal.html +0 -1
  138. package/src/api/exporters/html/__snapshots__/customParagraph/basic/external.html +0 -1
  139. package/src/api/exporters/html/__snapshots__/customParagraph/basic/internal.html +0 -1
  140. package/src/api/exporters/html/__snapshots__/customParagraph/lineBreaks/external.html +0 -1
  141. package/src/api/exporters/html/__snapshots__/customParagraph/lineBreaks/internal.html +0 -1
  142. package/src/api/exporters/html/__snapshots__/customParagraph/nested/external.html +0 -1
  143. package/src/api/exporters/html/__snapshots__/customParagraph/nested/internal.html +0 -1
  144. package/src/api/exporters/html/__snapshots__/customParagraph/styled/external.html +0 -1
  145. package/src/api/exporters/html/__snapshots__/customParagraph/styled/internal.html +0 -1
  146. package/src/api/exporters/html/__snapshots__/file/basic/external.html +0 -1
  147. package/src/api/exporters/html/__snapshots__/file/basic/internal.html +0 -1
  148. package/src/api/exporters/html/__snapshots__/file/button/external.html +0 -1
  149. package/src/api/exporters/html/__snapshots__/file/button/internal.html +0 -1
  150. package/src/api/exporters/html/__snapshots__/file/nested/external.html +0 -1
  151. package/src/api/exporters/html/__snapshots__/file/nested/internal.html +0 -1
  152. package/src/api/exporters/html/__snapshots__/file/noCaption/external.html +0 -1
  153. package/src/api/exporters/html/__snapshots__/file/noCaption/internal.html +0 -1
  154. package/src/api/exporters/html/__snapshots__/file/noName/external.html +0 -1
  155. package/src/api/exporters/html/__snapshots__/file/noName/internal.html +0 -1
  156. package/src/api/exporters/html/__snapshots__/fontSize/basic/external.html +0 -1
  157. package/src/api/exporters/html/__snapshots__/fontSize/basic/internal.html +0 -1
  158. package/src/api/exporters/html/__snapshots__/hardbreak/basic/external.html +0 -1
  159. package/src/api/exporters/html/__snapshots__/hardbreak/basic/internal.html +0 -1
  160. package/src/api/exporters/html/__snapshots__/hardbreak/between-links/external.html +0 -1
  161. package/src/api/exporters/html/__snapshots__/hardbreak/between-links/internal.html +0 -1
  162. package/src/api/exporters/html/__snapshots__/hardbreak/end/external.html +0 -1
  163. package/src/api/exporters/html/__snapshots__/hardbreak/end/internal.html +0 -1
  164. package/src/api/exporters/html/__snapshots__/hardbreak/link/external.html +0 -1
  165. package/src/api/exporters/html/__snapshots__/hardbreak/link/internal.html +0 -1
  166. package/src/api/exporters/html/__snapshots__/hardbreak/multiple/external.html +0 -1
  167. package/src/api/exporters/html/__snapshots__/hardbreak/multiple/internal.html +0 -1
  168. package/src/api/exporters/html/__snapshots__/hardbreak/only/external.html +0 -1
  169. package/src/api/exporters/html/__snapshots__/hardbreak/only/internal.html +0 -1
  170. package/src/api/exporters/html/__snapshots__/hardbreak/start/external.html +0 -1
  171. package/src/api/exporters/html/__snapshots__/hardbreak/start/internal.html +0 -1
  172. package/src/api/exporters/html/__snapshots__/hardbreak/styles/external.html +0 -1
  173. package/src/api/exporters/html/__snapshots__/hardbreak/styles/internal.html +0 -1
  174. package/src/api/exporters/html/__snapshots__/image/basic/external.html +0 -1
  175. package/src/api/exporters/html/__snapshots__/image/basic/internal.html +0 -1
  176. package/src/api/exporters/html/__snapshots__/image/button/external.html +0 -1
  177. package/src/api/exporters/html/__snapshots__/image/button/internal.html +0 -1
  178. package/src/api/exporters/html/__snapshots__/image/nested/external.html +0 -1
  179. package/src/api/exporters/html/__snapshots__/image/nested/internal.html +0 -1
  180. package/src/api/exporters/html/__snapshots__/image/noCaption/external.html +0 -1
  181. package/src/api/exporters/html/__snapshots__/image/noCaption/internal.html +0 -1
  182. package/src/api/exporters/html/__snapshots__/image/noName/external.html +0 -1
  183. package/src/api/exporters/html/__snapshots__/image/noName/internal.html +0 -1
  184. package/src/api/exporters/html/__snapshots__/image/noPreview/external.html +0 -1
  185. package/src/api/exporters/html/__snapshots__/image/noPreview/internal.html +0 -1
  186. package/src/api/exporters/html/__snapshots__/link/adjacent/external.html +0 -1
  187. package/src/api/exporters/html/__snapshots__/link/adjacent/internal.html +0 -1
  188. package/src/api/exporters/html/__snapshots__/link/basic/external.html +0 -1
  189. package/src/api/exporters/html/__snapshots__/link/basic/internal.html +0 -1
  190. package/src/api/exporters/html/__snapshots__/link/styled/external.html +0 -1
  191. package/src/api/exporters/html/__snapshots__/link/styled/internal.html +0 -1
  192. package/src/api/exporters/html/__snapshots__/lists/basic/external.html +0 -1
  193. package/src/api/exporters/html/__snapshots__/lists/basic/internal.html +0 -1
  194. package/src/api/exporters/html/__snapshots__/lists/nested/external.html +0 -1
  195. package/src/api/exporters/html/__snapshots__/lists/nested/internal.html +0 -1
  196. package/src/api/exporters/html/__snapshots__/mention/basic/external.html +0 -1
  197. package/src/api/exporters/html/__snapshots__/mention/basic/internal.html +0 -1
  198. package/src/api/exporters/html/__snapshots__/pageBreak/basic/external.html +0 -1
  199. package/src/api/exporters/html/__snapshots__/pageBreak/basic/internal.html +0 -1
  200. package/src/api/exporters/html/__snapshots__/paragraph/basic/external.html +0 -1
  201. package/src/api/exporters/html/__snapshots__/paragraph/basic/internal.html +0 -1
  202. package/src/api/exporters/html/__snapshots__/paragraph/empty/external.html +0 -1
  203. package/src/api/exporters/html/__snapshots__/paragraph/empty/internal.html +0 -1
  204. package/src/api/exporters/html/__snapshots__/paragraph/lineBreaks/external.html +0 -1
  205. package/src/api/exporters/html/__snapshots__/paragraph/lineBreaks/internal.html +0 -1
  206. package/src/api/exporters/html/__snapshots__/paragraph/nested/external.html +0 -1
  207. package/src/api/exporters/html/__snapshots__/paragraph/nested/internal.html +0 -1
  208. package/src/api/exporters/html/__snapshots__/paragraph/styled/external.html +0 -1
  209. package/src/api/exporters/html/__snapshots__/paragraph/styled/internal.html +0 -1
  210. package/src/api/exporters/html/__snapshots__/paste/parse-basic-block-types.json +0 -140
  211. package/src/api/exporters/html/__snapshots__/paste/parse-deep-nested-content.json +0 -240
  212. package/src/api/exporters/html/__snapshots__/paste/parse-div-with-inline-content.json +0 -91
  213. package/src/api/exporters/html/__snapshots__/paste/parse-divs.json +0 -19
  214. package/src/api/exporters/html/__snapshots__/paste/parse-fake-image-caption.json +0 -31
  215. package/src/api/exporters/html/__snapshots__/paste/parse-mixed-nested-lists.json +0 -70
  216. package/src/api/exporters/html/__snapshots__/paste/parse-nested-lists-with-paragraphs.json +0 -70
  217. package/src/api/exporters/html/__snapshots__/paste/parse-nested-lists.json +0 -70
  218. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/external.html +0 -1
  219. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/internal.html +0 -1
  220. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/external.html +0 -1
  221. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/internal.html +0 -1
  222. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/external.html +0 -1
  223. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/internal.html +0 -1
  224. package/src/api/exporters/html/__snapshots__/simpleFile/basic/external.html +0 -1
  225. package/src/api/exporters/html/__snapshots__/simpleFile/basic/internal.html +0 -1
  226. package/src/api/exporters/html/__snapshots__/simpleFile/button/external.html +0 -1
  227. package/src/api/exporters/html/__snapshots__/simpleFile/button/internal.html +0 -1
  228. package/src/api/exporters/html/__snapshots__/simpleFile/nested/external.html +0 -1
  229. package/src/api/exporters/html/__snapshots__/simpleFile/nested/internal.html +0 -1
  230. package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +0 -1
  231. package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +0 -1
  232. package/src/api/exporters/html/__snapshots__/simpleImage/button/external.html +0 -1
  233. package/src/api/exporters/html/__snapshots__/simpleImage/button/internal.html +0 -1
  234. package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +0 -1
  235. package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +0 -1
  236. package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +0 -1
  237. package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/internal.html +0 -1
  238. package/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +0 -1
  239. package/src/api/exporters/html/__snapshots__/simpleImage/noName/internal.html +0 -1
  240. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +0 -1
  241. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/internal.html +0 -1
  242. package/src/api/exporters/html/__snapshots__/small/basic/external.html +0 -1
  243. package/src/api/exporters/html/__snapshots__/small/basic/internal.html +0 -1
  244. package/src/api/exporters/html/__snapshots__/table/allColWidths/external.html +0 -1
  245. package/src/api/exporters/html/__snapshots__/table/allColWidths/internal.html +0 -1
  246. package/src/api/exporters/html/__snapshots__/table/basic/external.html +0 -1
  247. package/src/api/exporters/html/__snapshots__/table/basic/internal.html +0 -1
  248. package/src/api/exporters/html/__snapshots__/table/headerCols/external.html +0 -1
  249. package/src/api/exporters/html/__snapshots__/table/headerCols/internal.html +0 -1
  250. package/src/api/exporters/html/__snapshots__/table/headerRows/external.html +0 -1
  251. package/src/api/exporters/html/__snapshots__/table/headerRows/internal.html +0 -1
  252. package/src/api/exporters/html/__snapshots__/table/headersRows/external.html +0 -1
  253. package/src/api/exporters/html/__snapshots__/table/headersRows/internal.html +0 -1
  254. package/src/api/exporters/html/__snapshots__/table/mixedCellColors/external.html +0 -1
  255. package/src/api/exporters/html/__snapshots__/table/mixedCellColors/internal.html +0 -1
  256. package/src/api/exporters/html/__snapshots__/table/mixedColWidths/external.html +0 -1
  257. package/src/api/exporters/html/__snapshots__/table/mixedColWidths/internal.html +0 -1
  258. package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/external.html +0 -1
  259. package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/internal.html +0 -1
  260. package/src/api/exporters/html/__snapshots__/tag/basic/external.html +0 -1
  261. package/src/api/exporters/html/__snapshots__/tag/basic/internal.html +0 -1
  262. package/src/api/exporters/html/htmlConversion.test.ts +0 -110
  263. package/src/api/exporters/markdown/__snapshots__/codeBlock/contains-newlines/markdown.md +0 -4
  264. package/src/api/exporters/markdown/__snapshots__/codeBlock/defaultLanguage/markdown.md +0 -3
  265. package/src/api/exporters/markdown/__snapshots__/codeBlock/empty/markdown.md +0 -2
  266. package/src/api/exporters/markdown/__snapshots__/codeBlock/python/markdown.md +0 -3
  267. package/src/api/exporters/markdown/__snapshots__/complex/misc/markdown.md +0 -5
  268. package/src/api/exporters/markdown/__snapshots__/customBlock/basic/markdown.md +0 -5
  269. package/src/api/exporters/markdown/__snapshots__/customParagraph/basic/markdown.md +0 -1
  270. package/src/api/exporters/markdown/__snapshots__/customParagraph/lineBreaks/markdown.md +0 -1
  271. package/src/api/exporters/markdown/__snapshots__/customParagraph/nested/markdown.md +0 -5
  272. package/src/api/exporters/markdown/__snapshots__/customParagraph/styled/markdown.md +0 -1
  273. package/src/api/exporters/markdown/__snapshots__/file/basic/markdown.md +0 -3
  274. package/src/api/exporters/markdown/__snapshots__/file/button/markdown.md +0 -1
  275. package/src/api/exporters/markdown/__snapshots__/file/nested/markdown.md +0 -7
  276. package/src/api/exporters/markdown/__snapshots__/file/noCaption/markdown.md +0 -1
  277. package/src/api/exporters/markdown/__snapshots__/file/noName/markdown.md +0 -3
  278. package/src/api/exporters/markdown/__snapshots__/fontSize/basic/markdown.md +0 -1
  279. package/src/api/exporters/markdown/__snapshots__/hardbreak/basic/markdown.md +0 -2
  280. package/src/api/exporters/markdown/__snapshots__/hardbreak/between-links/markdown.md +0 -2
  281. package/src/api/exporters/markdown/__snapshots__/hardbreak/end/markdown.md +0 -1
  282. package/src/api/exporters/markdown/__snapshots__/hardbreak/link/markdown.md +0 -2
  283. package/src/api/exporters/markdown/__snapshots__/hardbreak/multiple/markdown.md +0 -3
  284. package/src/api/exporters/markdown/__snapshots__/hardbreak/only/markdown.md +0 -0
  285. package/src/api/exporters/markdown/__snapshots__/hardbreak/start/markdown.md +0 -1
  286. package/src/api/exporters/markdown/__snapshots__/hardbreak/styles/markdown.md +0 -2
  287. package/src/api/exporters/markdown/__snapshots__/image/basic/markdown.md +0 -3
  288. package/src/api/exporters/markdown/__snapshots__/image/button/markdown.md +0 -1
  289. package/src/api/exporters/markdown/__snapshots__/image/nested/markdown.md +0 -7
  290. package/src/api/exporters/markdown/__snapshots__/image/noCaption/markdown.md +0 -1
  291. package/src/api/exporters/markdown/__snapshots__/image/noName/markdown.md +0 -3
  292. package/src/api/exporters/markdown/__snapshots__/image/noPreview/markdown.md +0 -3
  293. package/src/api/exporters/markdown/__snapshots__/link/adjacent/markdown.md +0 -1
  294. package/src/api/exporters/markdown/__snapshots__/link/basic/markdown.md +0 -1
  295. package/src/api/exporters/markdown/__snapshots__/link/styled/markdown.md +0 -1
  296. package/src/api/exporters/markdown/__snapshots__/lists/basic/markdown.md +0 -10
  297. package/src/api/exporters/markdown/__snapshots__/lists/nested/markdown.md +0 -10
  298. package/src/api/exporters/markdown/__snapshots__/mention/basic/markdown.md +0 -1
  299. package/src/api/exporters/markdown/__snapshots__/pageBreak/basic/markdown.md +0 -0
  300. package/src/api/exporters/markdown/__snapshots__/paragraph/basic/markdown.md +0 -1
  301. package/src/api/exporters/markdown/__snapshots__/paragraph/empty/markdown.md +0 -0
  302. package/src/api/exporters/markdown/__snapshots__/paragraph/lineBreaks/markdown.md +0 -2
  303. package/src/api/exporters/markdown/__snapshots__/paragraph/nested/markdown.md +0 -5
  304. package/src/api/exporters/markdown/__snapshots__/paragraph/styled/markdown.md +0 -1
  305. package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/basic/markdown.md +0 -1
  306. package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/nested/markdown.md +0 -5
  307. package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/styled/markdown.md +0 -1
  308. package/src/api/exporters/markdown/__snapshots__/simpleFile/basic/markdown.md +0 -3
  309. package/src/api/exporters/markdown/__snapshots__/simpleFile/button/markdown.md +0 -1
  310. package/src/api/exporters/markdown/__snapshots__/simpleFile/nested/markdown.md +0 -7
  311. package/src/api/exporters/markdown/__snapshots__/simpleImage/basic/markdown.md +0 -3
  312. package/src/api/exporters/markdown/__snapshots__/simpleImage/button/markdown.md +0 -1
  313. package/src/api/exporters/markdown/__snapshots__/simpleImage/nested/markdown.md +0 -7
  314. package/src/api/exporters/markdown/__snapshots__/simpleImage/noCaption/markdown.md +0 -1
  315. package/src/api/exporters/markdown/__snapshots__/simpleImage/noName/markdown.md +0 -3
  316. package/src/api/exporters/markdown/__snapshots__/simpleImage/noPreview/markdown.md +0 -3
  317. package/src/api/exporters/markdown/__snapshots__/small/basic/markdown.md +0 -1
  318. package/src/api/exporters/markdown/__snapshots__/table/allColWidths/markdown.md +0 -5
  319. package/src/api/exporters/markdown/__snapshots__/table/basic/markdown.md +0 -5
  320. package/src/api/exporters/markdown/__snapshots__/table/headerCols/markdown.md +0 -4
  321. package/src/api/exporters/markdown/__snapshots__/table/headerRows/markdown.md +0 -4
  322. package/src/api/exporters/markdown/__snapshots__/table/mixedCellColors/markdown.md +0 -5
  323. package/src/api/exporters/markdown/__snapshots__/table/mixedColWidths/markdown.md +0 -5
  324. package/src/api/exporters/markdown/__snapshots__/table/mixedRowspansAndColspans/markdown.md +0 -5
  325. package/src/api/exporters/markdown/__snapshots__/tag/basic/markdown.md +0 -1
  326. package/src/api/exporters/markdown/markdownExporter.test.ts +0 -86
  327. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +0 -3473
  328. package/src/api/nodeConversions/nodeConversions.test.ts +0 -83
  329. package/src/api/parsers/html/__snapshots__/list-test.json +0 -177
  330. package/src/api/parsers/html/__snapshots__/parse-2-tables.json +0 -129
  331. package/src/api/parsers/html/__snapshots__/parse-basic-block-types.json +0 -142
  332. package/src/api/parsers/html/__snapshots__/parse-codeblocks.json +0 -62
  333. package/src/api/parsers/html/__snapshots__/parse-div-with-inline-content.json +0 -91
  334. package/src/api/parsers/html/__snapshots__/parse-divs.json +0 -121
  335. package/src/api/parsers/html/__snapshots__/parse-fake-image-caption.json +0 -33
  336. package/src/api/parsers/html/__snapshots__/parse-image-in-paragraph.json +0 -16
  337. package/src/api/parsers/html/__snapshots__/parse-mixed-nested-lists.json +0 -265
  338. package/src/api/parsers/html/__snapshots__/parse-nested-lists-with-paragraphs.json +0 -265
  339. package/src/api/parsers/html/__snapshots__/parse-nested-lists.json +0 -265
  340. package/src/api/parsers/html/__snapshots__/parse-notion-html.json +0 -565
  341. package/src/api/parsers/html/__snapshots__/parse-two-divs.json +0 -36
  342. package/src/api/parsers/html/parseHTML.test.ts +0 -563
  343. package/src/api/parsers/markdown/__snapshots__/complex.json +0 -353
  344. package/src/api/parsers/markdown/__snapshots__/issue-226-1.json +0 -71
  345. package/src/api/parsers/markdown/__snapshots__/issue-226-2.json +0 -144
  346. package/src/api/parsers/markdown/__snapshots__/nested.json +0 -72
  347. package/src/api/parsers/markdown/__snapshots__/non-nested.json +0 -71
  348. package/src/api/parsers/markdown/__snapshots__/pasted/complex.json +0 -319
  349. package/src/api/parsers/markdown/__snapshots__/pasted/issue-226-1.json +0 -81
  350. package/src/api/parsers/markdown/__snapshots__/pasted/issue-226-2.json +0 -165
  351. package/src/api/parsers/markdown/__snapshots__/pasted/nested.json +0 -81
  352. package/src/api/parsers/markdown/__snapshots__/pasted/non-nested.json +0 -81
  353. package/src/api/parsers/markdown/__snapshots__/pasted/styled.json +0 -61
  354. package/src/api/parsers/markdown/__snapshots__/pasted/whitespace bold.json +0 -42
  355. package/src/api/parsers/markdown/__snapshots__/styled.json +0 -58
  356. package/src/api/parsers/markdown/__snapshots__/whitespace bold.json +0 -19
  357. package/src/api/parsers/markdown/parseMarkdown.test.ts +0 -135
  358. package/src/api/testUtil/cases/customBlocks.ts +0 -342
  359. package/src/api/testUtil/cases/customInlineContent.ts +0 -113
  360. package/src/api/testUtil/cases/customStyles.ts +0 -102
  361. package/src/api/testUtil/cases/defaultSchema.ts +0 -1493
  362. package/src/api/testUtil/index.ts +0 -19
  363. package/src/api/testUtil/partialBlockTestUtil.ts +0 -198
  364. package/src/api/testUtil/paste.ts +0 -46
  365. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +0 -4
  366. package/types/src/api/clipboard/clipboardExternal.test.d.ts +0 -1
  367. package/types/src/api/clipboard/clipboardInternal.test.d.ts +0 -1
  368. package/types/src/api/clipboard/testUtil.d.ts +0 -541
  369. package/types/src/api/exporters/html/htmlConversion.test.d.ts +0 -1
  370. package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +0 -1
  371. package/types/src/api/nodeConversions/nodeConversions.test.d.ts +0 -1
  372. package/types/src/api/parsers/html/parseHTML.test.d.ts +0 -1
  373. package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +0 -1
  374. package/types/src/api/testUtil/cases/customBlocks.d.ts +0 -670
  375. package/types/src/api/testUtil/cases/customInlineContent.d.ts +0 -558
  376. package/types/src/api/testUtil/cases/customStyles.d.ts +0 -552
  377. package/types/src/api/testUtil/cases/defaultSchema.d.ts +0 -4
  378. package/types/src/api/testUtil/index.d.ts +0 -14
  379. package/types/src/api/testUtil/partialBlockTestUtil.d.ts +0 -9
  380. package/types/src/api/testUtil/paste.d.ts +0 -2
  381. /package/types/src/api/{blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts → nodeUtil.test.d.ts} +0 -0
@@ -1,8 +1,7 @@
1
- import { TextSelection } from "prosemirror-state";
1
+ import { TextSelection, type Transaction } from "prosemirror-state";
2
2
  import { TableMap } from "prosemirror-tables";
3
3
 
4
4
  import { Block } from "../../../blocks/defaultBlocks.js";
5
- import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
6
5
  import { Selection } from "../../../editor/selectionTypes.js";
7
6
  import {
8
7
  BlockIdentifier,
@@ -13,26 +12,24 @@ import {
13
12
  import { getBlockInfo, getNearestBlockPos } from "../../getBlockInfoFromPos.js";
14
13
  import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
15
14
  import { getNodeById } from "../../nodeUtil.js";
15
+ import { getBlockNoteSchema, getPmSchema } from "../../pmUtil.js";
16
16
 
17
17
  export function getSelection<
18
18
  BSchema extends BlockSchema,
19
19
  I extends InlineContentSchema,
20
20
  S extends StyleSchema
21
- >(
22
- editor: BlockNoteEditor<BSchema, I, S>
23
- ): Selection<BSchema, I, S> | undefined {
24
- const state = editor._tiptapEditor.state;
25
-
21
+ >(tr: Transaction): Selection<BSchema, I, S> | undefined {
22
+ const pmSchema = getPmSchema(tr);
26
23
  // Return undefined if the selection is collapsed or a node is selected.
27
- if (state.selection.empty || "node" in state.selection) {
24
+ if (tr.selection.empty || "node" in tr.selection) {
28
25
  return undefined;
29
26
  }
30
27
 
31
- const $startBlockBeforePos = state.doc.resolve(
32
- getNearestBlockPos(state.doc, state.selection.from).posBeforeNode
28
+ const $startBlockBeforePos = tr.doc.resolve(
29
+ getNearestBlockPos(tr.doc, tr.selection.from).posBeforeNode
33
30
  );
34
- const $endBlockBeforePos = state.doc.resolve(
35
- getNearestBlockPos(state.doc, state.selection.to).posBeforeNode
31
+ const $endBlockBeforePos = tr.doc.resolve(
32
+ getNearestBlockPos(tr.doc, tr.selection.to).posBeforeNode
36
33
  );
37
34
 
38
35
  // Converts the node at the given index and depth around `$startBlockBeforePos`
@@ -43,7 +40,7 @@ export function getSelection<
43
40
  depth?: number
44
41
  ): Block<BSchema, I, S> => {
45
42
  const pos = $startBlockBeforePos.posAtIndex(index, depth);
46
- const node = state.doc.resolve(pos).nodeAfter;
43
+ const node = tr.doc.resolve(pos).nodeAfter;
47
44
 
48
45
  if (!node) {
49
46
  throw new Error(
@@ -51,13 +48,7 @@ export function getSelection<
51
48
  );
52
49
  }
53
50
 
54
- return nodeToBlock(
55
- node,
56
- editor.schema.blockSchema,
57
- editor.schema.inlineContentSchema,
58
- editor.schema.styleSchema,
59
- editor.blockCache
60
- );
51
+ return nodeToBlock(node, pmSchema);
61
52
  };
62
53
 
63
54
  const blocks: Block<BSchema, I, S>[] = [];
@@ -98,15 +89,7 @@ export function getSelection<
98
89
  // [ id-2, id-3, id-4, id-6, id-7, id-8, id-9 ]
99
90
  if ($startBlockBeforePos.depth > sharedDepth) {
100
91
  // Adds the block that the selection starts in.
101
- blocks.push(
102
- nodeToBlock(
103
- $startBlockBeforePos.nodeAfter!,
104
- editor.schema.blockSchema,
105
- editor.schema.inlineContentSchema,
106
- editor.schema.styleSchema,
107
- editor.blockCache
108
- )
109
- );
92
+ blocks.push(nodeToBlock($startBlockBeforePos.nodeAfter!, pmSchema));
110
93
 
111
94
  // Traverses all depths from the depth of the block in which the selection
112
95
  // starts, up to the shared depth.
@@ -137,7 +120,7 @@ export function getSelection<
137
120
 
138
121
  if (blocks.length === 0) {
139
122
  throw new Error(
140
- `Error getting selection - selection doesn't span any blocks (${state.selection})`
123
+ `Error getting selection - selection doesn't span any blocks (${tr.selection})`
141
124
  );
142
125
  }
143
126
 
@@ -146,32 +129,27 @@ export function getSelection<
146
129
  };
147
130
  }
148
131
 
149
- export function setSelection<
150
- BSchema extends BlockSchema,
151
- I extends InlineContentSchema,
152
- S extends StyleSchema
153
- >(
154
- editor: BlockNoteEditor<BSchema, I, S>,
132
+ export function setSelection(
133
+ tr: Transaction,
155
134
  startBlock: BlockIdentifier,
156
135
  endBlock: BlockIdentifier
157
136
  ) {
158
137
  const startBlockId =
159
138
  typeof startBlock === "string" ? startBlock : startBlock.id;
160
139
  const endBlockId = typeof endBlock === "string" ? endBlock : endBlock.id;
140
+ const pmSchema = getPmSchema(tr);
141
+ const schema = getBlockNoteSchema(pmSchema);
161
142
 
162
143
  if (startBlockId === endBlockId) {
163
144
  throw new Error(
164
145
  `Attempting to set selection with the same anchor and head blocks (id ${startBlockId})`
165
146
  );
166
147
  }
167
-
168
- const doc = editor._tiptapEditor.state.doc;
169
-
170
- const anchorPosInfo = getNodeById(startBlockId, doc);
148
+ const anchorPosInfo = getNodeById(startBlockId, tr.doc);
171
149
  if (!anchorPosInfo) {
172
150
  throw new Error(`Block with ID ${startBlockId} not found`);
173
151
  }
174
- const headPosInfo = getNodeById(endBlockId, doc);
152
+ const headPosInfo = getNodeById(endBlockId, tr.doc);
175
153
  if (!headPosInfo) {
176
154
  throw new Error(`Block with ID ${endBlockId} not found`);
177
155
  }
@@ -180,12 +158,12 @@ export function setSelection<
180
158
  const headBlockInfo = getBlockInfo(headPosInfo);
181
159
 
182
160
  const anchorBlockConfig =
183
- editor.schema.blockSchema[
184
- anchorBlockInfo.blockNoteType as keyof typeof editor.schema.blockSchema
161
+ schema.blockSchema[
162
+ anchorBlockInfo.blockNoteType as keyof typeof schema.blockSchema
185
163
  ];
186
164
  const headBlockConfig =
187
- editor.schema.blockSchema[
188
- headBlockInfo.blockNoteType as keyof typeof editor.schema.blockSchema
165
+ schema.blockSchema[
166
+ headBlockInfo.blockNoteType as keyof typeof schema.blockSchema
189
167
  ];
190
168
 
191
169
  if (
@@ -226,7 +204,7 @@ export function setSelection<
226
204
  headBlockInfo.blockContent.node
227
205
  ) +
228
206
  1;
229
- const lastCellNodeSize = doc.resolve(lastCellPos).nodeAfter!.nodeSize;
207
+ const lastCellNodeSize = tr.doc.resolve(lastCellPos).nodeAfter!.nodeSize;
230
208
  endPos = lastCellPos + lastCellNodeSize - 2;
231
209
  } else {
232
210
  endPos = headBlockInfo.blockContent.afterPos - 1;
@@ -236,9 +214,5 @@ export function setSelection<
236
214
  // Right now it's missing a few things like a jsonID and styling to show
237
215
  // which nodes are selected. `TextSelection` is ok for now, but has the
238
216
  // restriction that the start/end blocks must have content.
239
- editor._tiptapEditor.dispatch(
240
- editor._tiptapEditor.state.tr.setSelection(
241
- TextSelection.create(editor._tiptapEditor.state.doc, startPos, endPos)
242
- )
243
- );
217
+ tr.setSelection(TextSelection.create(tr.doc, startPos, endPos));
244
218
  }
@@ -10,44 +10,65 @@ const getEditor = setupTestEnv();
10
10
 
11
11
  describe("Test getTextCursorPosition & setTextCursorPosition", () => {
12
12
  it("Basic", () => {
13
- setTextCursorPosition(getEditor(), "paragraph-1");
13
+ getEditor().transact((tr) => {
14
+ setTextCursorPosition(tr, "paragraph-1");
15
+ });
14
16
 
15
- expect(getTextCursorPosition(getEditor())).toMatchSnapshot();
17
+ expect(
18
+ getEditor().transact((tr) => getTextCursorPosition(tr))
19
+ ).toMatchSnapshot();
16
20
  });
17
21
 
18
22
  it("First block", () => {
19
- setTextCursorPosition(getEditor(), "paragraph-0");
23
+ getEditor().transact((tr) => {
24
+ setTextCursorPosition(tr, "paragraph-0");
25
+ });
20
26
 
21
- expect(getTextCursorPosition(getEditor())).toMatchSnapshot();
27
+ expect(
28
+ getEditor().transact((tr) => getTextCursorPosition(tr))
29
+ ).toMatchSnapshot();
22
30
  });
23
31
 
24
32
  it("Last block", () => {
25
- setTextCursorPosition(getEditor(), "trailing-paragraph");
33
+ getEditor().transact((tr) => {
34
+ setTextCursorPosition(tr, "trailing-paragraph");
35
+ });
26
36
 
27
- expect(getTextCursorPosition(getEditor())).toMatchSnapshot();
37
+ expect(
38
+ getEditor().transact((tr) => getTextCursorPosition(tr))
39
+ ).toMatchSnapshot();
28
40
  });
29
41
 
30
42
  it("Nested block", () => {
31
- setTextCursorPosition(getEditor(), "nested-paragraph-0");
43
+ getEditor().transact((tr) => {
44
+ setTextCursorPosition(tr, "nested-paragraph-0");
45
+ });
32
46
 
33
- expect(getTextCursorPosition(getEditor())).toMatchSnapshot();
47
+ expect(
48
+ getEditor().transact((tr) => getTextCursorPosition(tr))
49
+ ).toMatchSnapshot();
34
50
  });
35
51
 
36
52
  it("Set to start", () => {
37
- setTextCursorPosition(getEditor(), "paragraph-1", "start");
53
+ getEditor().transact((tr) => {
54
+ setTextCursorPosition(tr, "paragraph-1", "start");
55
+ });
38
56
 
39
57
  expect(
40
- getEditor()._tiptapEditor.state.selection.$from.parentOffset === 0
58
+ getEditor().transact((tr) => tr.selection.$from.parentOffset) === 0
41
59
  ).toBeTruthy();
42
60
  });
43
61
 
44
62
  it("Set to end", () => {
45
- setTextCursorPosition(getEditor(), "paragraph-1", "end");
63
+ getEditor().transact((tr) => {
64
+ setTextCursorPosition(tr, "paragraph-1", "end");
65
+ });
46
66
 
47
67
  expect(
48
- getEditor()._tiptapEditor.state.selection.$from.parentOffset ===
49
- getEditor()._tiptapEditor.state.selection.$from.node().firstChild!
50
- .nodeSize
68
+ getEditor().transact((tr) => tr.selection.$from.parentOffset) ===
69
+ getEditor().transact(
70
+ (tr) => tr.selection.$from.node().firstChild!.nodeSize
71
+ )
51
72
  ).toBeTruthy();
52
73
  });
53
74
  });
@@ -1,8 +1,11 @@
1
- import { Node } from "prosemirror-model";
2
-
3
- import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
4
- import { TextCursorPosition } from "../../../../editor/cursorPositionTypes.js";
1
+ import type { Node } from "prosemirror-model";
5
2
  import {
3
+ NodeSelection,
4
+ TextSelection,
5
+ type Transaction,
6
+ } from "prosemirror-state";
7
+ import type { TextCursorPosition } from "../../../../editor/cursorPositionTypes.js";
8
+ import type {
6
9
  BlockIdentifier,
7
10
  BlockSchema,
8
11
  InlineContentSchema,
@@ -11,26 +14,26 @@ import {
11
14
  import { UnreachableCaseError } from "../../../../util/typescript.js";
12
15
  import {
13
16
  getBlockInfo,
14
- getBlockInfoFromSelection,
17
+ getBlockInfoFromTransaction,
15
18
  } from "../../../getBlockInfoFromPos.js";
16
19
  import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js";
17
20
  import { getNodeById } from "../../../nodeUtil.js";
21
+ import { getBlockNoteSchema, getPmSchema } from "../../../pmUtil.js";
18
22
 
19
23
  export function getTextCursorPosition<
20
24
  BSchema extends BlockSchema,
21
25
  I extends InlineContentSchema,
22
26
  S extends StyleSchema
23
- >(editor: BlockNoteEditor<BSchema, I, S>): TextCursorPosition<BSchema, I, S> {
24
- const { bnBlock } = getBlockInfoFromSelection(editor._tiptapEditor.state);
27
+ >(tr: Transaction): TextCursorPosition<BSchema, I, S> {
28
+ const { bnBlock } = getBlockInfoFromTransaction(tr);
29
+ const pmSchema = getPmSchema(tr.doc);
25
30
 
26
- const resolvedPos = editor._tiptapEditor.state.doc.resolve(bnBlock.beforePos);
31
+ const resolvedPos = tr.doc.resolve(bnBlock.beforePos);
27
32
  // Gets previous blockContainer node at the same nesting level, if the current node isn't the first child.
28
33
  const prevNode = resolvedPos.nodeBefore;
29
34
 
30
35
  // Gets next blockContainer node at the same nesting level, if the current node isn't the last child.
31
- const nextNode = editor._tiptapEditor.state.doc.resolve(
32
- bnBlock.afterPos
33
- ).nodeAfter;
36
+ const nextNode = tr.doc.resolve(bnBlock.afterPos).nodeAfter;
34
37
 
35
38
  // Gets parent blockContainer node, if the current node is nested.
36
39
  let parentNode: Node | undefined = undefined;
@@ -44,58 +47,24 @@ export function getTextCursorPosition<
44
47
  }
45
48
 
46
49
  return {
47
- block: nodeToBlock(
48
- bnBlock.node,
49
- editor.schema.blockSchema,
50
- editor.schema.inlineContentSchema,
51
- editor.schema.styleSchema,
52
- editor.blockCache
53
- ),
54
- prevBlock:
55
- prevNode === null
56
- ? undefined
57
- : nodeToBlock(
58
- prevNode,
59
- editor.schema.blockSchema,
60
- editor.schema.inlineContentSchema,
61
- editor.schema.styleSchema,
62
- editor.blockCache
63
- ),
64
- nextBlock:
65
- nextNode === null
66
- ? undefined
67
- : nodeToBlock(
68
- nextNode,
69
- editor.schema.blockSchema,
70
- editor.schema.inlineContentSchema,
71
- editor.schema.styleSchema,
72
- editor.blockCache
73
- ),
50
+ block: nodeToBlock(bnBlock.node, pmSchema),
51
+ prevBlock: prevNode === null ? undefined : nodeToBlock(prevNode, pmSchema),
52
+ nextBlock: nextNode === null ? undefined : nodeToBlock(nextNode, pmSchema),
74
53
  parentBlock:
75
- parentNode === undefined
76
- ? undefined
77
- : nodeToBlock(
78
- parentNode,
79
- editor.schema.blockSchema,
80
- editor.schema.inlineContentSchema,
81
- editor.schema.styleSchema,
82
- editor.blockCache
83
- ),
54
+ parentNode === undefined ? undefined : nodeToBlock(parentNode, pmSchema),
84
55
  };
85
56
  }
86
57
 
87
- export function setTextCursorPosition<
88
- BSchema extends BlockSchema,
89
- I extends InlineContentSchema,
90
- S extends StyleSchema
91
- >(
92
- editor: BlockNoteEditor<BSchema, I, S>,
58
+ export function setTextCursorPosition(
59
+ tr: Transaction,
93
60
  targetBlock: BlockIdentifier,
94
61
  placement: "start" | "end" = "start"
95
62
  ) {
96
63
  const id = typeof targetBlock === "string" ? targetBlock : targetBlock.id;
64
+ const pmSchema = getPmSchema(tr.doc);
65
+ const schema = getBlockNoteSchema(pmSchema);
97
66
 
98
- const posInfo = getNodeById(id, editor._tiptapEditor.state.doc);
67
+ const posInfo = getNodeById(id, tr.doc);
99
68
  if (!posInfo) {
100
69
  throw new Error(`Block with ID ${id} not found`);
101
70
  }
@@ -103,23 +72,23 @@ export function setTextCursorPosition<
103
72
  const info = getBlockInfo(posInfo);
104
73
 
105
74
  const contentType: "none" | "inline" | "table" =
106
- editor.schema.blockSchema[info.blockNoteType]!.content;
75
+ schema.blockSchema[info.blockNoteType]!.content;
107
76
 
108
77
  if (info.isBlockContainer) {
109
78
  const blockContent = info.blockContent;
110
79
  if (contentType === "none") {
111
- editor._tiptapEditor.commands.setNodeSelection(blockContent.beforePos);
80
+ tr.setSelection(NodeSelection.create(tr.doc, blockContent.beforePos));
112
81
  return;
113
82
  }
114
83
 
115
84
  if (contentType === "inline") {
116
85
  if (placement === "start") {
117
- editor._tiptapEditor.commands.setTextSelection(
118
- blockContent.beforePos + 1
86
+ tr.setSelection(
87
+ TextSelection.create(tr.doc, blockContent.beforePos + 1)
119
88
  );
120
89
  } else {
121
- editor._tiptapEditor.commands.setTextSelection(
122
- blockContent.afterPos - 1
90
+ tr.setSelection(
91
+ TextSelection.create(tr.doc, blockContent.afterPos - 1)
123
92
  );
124
93
  }
125
94
  } else if (contentType === "table") {
@@ -127,12 +96,12 @@ export function setTextCursorPosition<
127
96
  // Need to offset the position as we have to get through the `tableRow`
128
97
  // and `tableCell` nodes to get to the `tableParagraph` node we want to
129
98
  // set the selection in.
130
- editor._tiptapEditor.commands.setTextSelection(
131
- blockContent.beforePos + 4
99
+ tr.setSelection(
100
+ TextSelection.create(tr.doc, blockContent.beforePos + 4)
132
101
  );
133
102
  } else {
134
- editor._tiptapEditor.commands.setTextSelection(
135
- blockContent.afterPos - 4
103
+ tr.setSelection(
104
+ TextSelection.create(tr.doc, blockContent.afterPos - 4)
136
105
  );
137
106
  }
138
107
  } else {
@@ -144,6 +113,6 @@ export function setTextCursorPosition<
144
113
  ? info.childContainer.node.firstChild!
145
114
  : info.childContainer.node.lastChild!;
146
115
 
147
- setTextCursorPosition(editor, child.attrs.id, placement);
116
+ setTextCursorPosition(tr, child.attrs.id, placement);
148
117
  }
149
118
  }
@@ -160,16 +160,14 @@ export async function handleFileInsertion<
160
160
  return;
161
161
  }
162
162
 
163
- const posInfo = getNearestBlockPos(
164
- editor._tiptapEditor.state.doc,
165
- pos.pos
166
- );
167
-
168
- insertedBlockId = insertOrUpdateBlock(
169
- editor,
170
- editor.getBlock(posInfo.node.attrs.id)!,
171
- fileBlock
172
- );
163
+ insertedBlockId = editor.transact((tr) => {
164
+ const posInfo = getNearestBlockPos(tr.doc, pos.pos);
165
+ return insertOrUpdateBlock(
166
+ editor,
167
+ editor.getBlock(posInfo.node.attrs.id)!,
168
+ fileBlock
169
+ );
170
+ });
173
171
  } else {
174
172
  return;
175
173
  }
@@ -94,7 +94,7 @@ function fragmentToExternalHTML<
94
94
  );
95
95
  externalHTML = externalHTMLExporter.exportInlineContent(ic, {});
96
96
  } else {
97
- const blocks = fragmentToBlocks(selectedFragment, editor.schema);
97
+ const blocks = fragmentToBlocks(selectedFragment);
98
98
  externalHTML = externalHTMLExporter.exportBlocks(blocks, {});
99
99
  }
100
100
  return externalHTML;
@@ -120,9 +120,9 @@ export function selectedFragmentToHTML<
120
120
  "node" in view.state.selection &&
121
121
  (view.state.selection.node as Node).type.spec.group === "blockContent"
122
122
  ) {
123
- editor.dispatch(
124
- editor._tiptapEditor.state.tr.setSelection(
125
- new NodeSelection(view.state.doc.resolve(view.state.selection.from - 1))
123
+ editor.transact((tr) =>
124
+ tr.setSelection(
125
+ new NodeSelection(tr.doc.resolve(view.state.selection.from - 1))
126
126
  )
127
127
  );
128
128
  }
@@ -251,10 +251,10 @@ export const createCopyToClipboardExtension = <
251
251
  }
252
252
 
253
253
  // Expands the selection to the parent `blockContainer` node.
254
- editor.dispatch(
255
- editor._tiptapEditor.state.tr.setSelection(
254
+ editor.transact((tr) =>
255
+ tr.setSelection(
256
256
  new NodeSelection(
257
- view.state.doc.resolve(view.state.selection.from - 1)
257
+ tr.doc.resolve(view.state.selection.from - 1)
258
258
  )
259
259
  )
260
260
  );
@@ -43,23 +43,11 @@ export function serializeInlineContentExternalHTML<
43
43
  if (!blockContent) {
44
44
  throw new Error("blockContent is required");
45
45
  } else if (typeof blockContent === "string") {
46
- nodes = inlineContentToNodes(
47
- [blockContent],
48
- editor.pmSchema,
49
- editor.schema.styleSchema
50
- );
46
+ nodes = inlineContentToNodes([blockContent], editor.pmSchema);
51
47
  } else if (Array.isArray(blockContent)) {
52
- nodes = inlineContentToNodes(
53
- blockContent,
54
- editor.pmSchema,
55
- editor.schema.styleSchema
56
- );
48
+ nodes = inlineContentToNodes(blockContent, editor.pmSchema);
57
49
  } else if (blockContent.type === "tableContent") {
58
- nodes = tableContentToNodes(
59
- blockContent,
60
- editor.pmSchema,
61
- editor.schema.styleSchema
62
- );
50
+ nodes = tableContentToNodes(blockContent, editor.pmSchema);
63
51
  } else {
64
52
  throw new UnreachableCaseError(blockContent.type);
65
53
  }
@@ -130,7 +118,10 @@ function serializeBlock<
130
118
 
131
119
  const elementFragment = doc.createDocumentFragment();
132
120
  if (ret.dom.classList.contains("bn-block-content")) {
133
- const blockContentDataAttributes = [...attrs, ...Array.from(ret.dom.attributes)].filter(
121
+ const blockContentDataAttributes = [
122
+ ...attrs,
123
+ ...Array.from(ret.dom.attributes),
124
+ ].filter(
134
125
  (attr) =>
135
126
  attr.name.startsWith("data") &&
136
127
  attr.name !== "data-content-type" &&
@@ -30,25 +30,11 @@ export function serializeInlineContentInternalHTML<
30
30
  if (!blockContent) {
31
31
  throw new Error("blockContent is required");
32
32
  } else if (typeof blockContent === "string") {
33
- nodes = inlineContentToNodes(
34
- [blockContent],
35
- editor.pmSchema,
36
- editor.schema.styleSchema,
37
- blockType
38
- );
33
+ nodes = inlineContentToNodes([blockContent], editor.pmSchema, blockType);
39
34
  } else if (Array.isArray(blockContent)) {
40
- nodes = inlineContentToNodes(
41
- blockContent,
42
- editor.pmSchema,
43
- editor.schema.styleSchema,
44
- blockType
45
- );
35
+ nodes = inlineContentToNodes(blockContent, editor.pmSchema, blockType);
46
36
  } else if (blockContent.type === "tableContent") {
47
- nodes = tableContentToNodes(
48
- blockContent,
49
- editor.pmSchema,
50
- editor.schema.styleSchema
51
- );
37
+ nodes = tableContentToNodes(blockContent, editor.pmSchema);
52
38
  } else {
53
39
  throw new UnreachableCaseError(blockContent.type);
54
40
  }
@@ -1,5 +1,5 @@
1
1
  import { Node, ResolvedPos } from "prosemirror-model";
2
- import { EditorState } from "prosemirror-state";
2
+ import { EditorState, Transaction } from "prosemirror-state";
3
3
 
4
4
  type SingleBlockInfo = {
5
5
  node: Node;
@@ -239,3 +239,15 @@ export function getBlockInfoFromSelection(state: EditorState) {
239
239
 
240
240
  return getBlockInfo(posInfo);
241
241
  }
242
+
243
+ /**
244
+ * Gets information regarding the ProseMirror nodes that make up a block. The
245
+ * block chosen is the one currently containing the current ProseMirror
246
+ * selection.
247
+ * @param tr The ProseMirror transaction.
248
+ */
249
+ export function getBlockInfoFromTransaction(tr: Transaction) {
250
+ const posInfo = getNearestBlockPos(tr.doc, tr.selection.anchor);
251
+
252
+ return getBlockInfo(posInfo);
253
+ }
@@ -19,6 +19,7 @@ import {
19
19
  import { getColspan, isPartialTableCell } from "../../util/table.js";
20
20
  import { UnreachableCaseError } from "../../util/typescript.js";
21
21
  import { getAbsoluteTableCells } from "../blockManipulation/tables/tables.js";
22
+ import { getStyleSchema } from "../pmUtil.js";
22
23
 
23
24
  /**
24
25
  * Convert a StyledText inline element to a
@@ -139,8 +140,8 @@ export function inlineContentToNodes<
139
140
  >(
140
141
  blockContent: PartialInlineContent<I, S>,
141
142
  schema: Schema,
142
- styleSchema: S,
143
- blockType?: string
143
+ blockType?: string,
144
+ styleSchema: S = getStyleSchema(schema)
144
145
  ): Node[] {
145
146
  const nodes: Node[] = [];
146
147
 
@@ -173,7 +174,7 @@ export function tableContentToNodes<
173
174
  >(
174
175
  tableContent: PartialTableContent<I, S>,
175
176
  schema: Schema,
176
- styleSchema: StyleSchema
177
+ styleSchema: StyleSchema = getStyleSchema(schema)
177
178
  ): Node[] {
178
179
  const rowNodes: Node[] = [];
179
180
  // Header rows and columns are used to determine the type of the cell
@@ -222,7 +223,12 @@ export function tableContentToNodes<
222
223
  content = schema.text(cell);
223
224
  } else if (isPartialTableCell(cell)) {
224
225
  if (cell.content) {
225
- content = inlineContentToNodes(cell.content, schema, styleSchema);
226
+ content = inlineContentToNodes(
227
+ cell.content,
228
+ schema,
229
+ "tableParagraph",
230
+ styleSchema
231
+ );
226
232
  }
227
233
  const colspan = getColspan(cell);
228
234
 
@@ -234,7 +240,12 @@ export function tableContentToNodes<
234
240
  });
235
241
  }
236
242
  } else {
237
- content = inlineContentToNodes(cell, schema, styleSchema);
243
+ content = inlineContentToNodes(
244
+ cell,
245
+ schema,
246
+ "tableParagraph",
247
+ styleSchema
248
+ );
238
249
  }
239
250
 
240
251
  const cellNode = schema.nodes[
@@ -279,16 +290,16 @@ function blockOrInlineContentToContentNode(
279
290
  const nodes = inlineContentToNodes(
280
291
  [block.content],
281
292
  schema,
282
- styleSchema,
283
- type
293
+ type,
294
+ styleSchema
284
295
  );
285
296
  contentNode = schema.nodes[type].createChecked(block.props, nodes);
286
297
  } else if (Array.isArray(block.content)) {
287
298
  const nodes = inlineContentToNodes(
288
299
  block.content,
289
300
  schema,
290
- styleSchema,
291
- type
301
+ type,
302
+ styleSchema
292
303
  );
293
304
  contentNode = schema.nodes[type].createChecked(block.props, nodes);
294
305
  } else if (block.content.type === "tableContent") {
@@ -306,7 +317,7 @@ function blockOrInlineContentToContentNode(
306
317
  export function blockToNode(
307
318
  block: PartialBlock<any, any, any>,
308
319
  schema: Schema,
309
- styleSchema: StyleSchema
320
+ styleSchema: StyleSchema = getStyleSchema(schema)
310
321
  ) {
311
322
  let id = block.id;
312
323