@blocknote/core 0.51.3 → 0.52.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 (397) hide show
  1. package/dist/BlockNoteExtension-B_IEJHS8.js +38 -0
  2. package/dist/BlockNoteExtension-B_IEJHS8.js.map +1 -0
  3. package/dist/BlockNoteExtension-M0znTzxP.cjs +2 -0
  4. package/dist/BlockNoteExtension-M0znTzxP.cjs.map +1 -0
  5. package/dist/ThreadStore-Bx-gSEh1.cjs +2 -0
  6. package/dist/ThreadStore-Bx-gSEh1.cjs.map +1 -0
  7. package/dist/ThreadStore-et9wB5Xt.js +11 -0
  8. package/dist/ThreadStore-et9wB5Xt.js.map +1 -0
  9. package/dist/UserStore-DCG6lsla.cjs +2 -0
  10. package/dist/UserStore-DCG6lsla.cjs.map +1 -0
  11. package/dist/UserStore-QbbPFj0z.js +73 -0
  12. package/dist/UserStore-QbbPFj0z.js.map +1 -0
  13. package/dist/blocknote.cjs +1 -1
  14. package/dist/blocknote.js +6 -7
  15. package/dist/blocks-BqHv0xhc.cjs +12 -0
  16. package/dist/blocks-BqHv0xhc.cjs.map +1 -0
  17. package/dist/{blocks-D0lMxErU.js → blocks-CiuUGa1E.js} +1096 -998
  18. package/dist/blocks-CiuUGa1E.js.map +1 -0
  19. package/dist/blocks.cjs +1 -1
  20. package/dist/blocks.js +2 -2
  21. package/dist/comments.cjs +1 -1
  22. package/dist/comments.cjs.map +1 -1
  23. package/dist/comments.js +75 -340
  24. package/dist/comments.js.map +1 -1
  25. package/dist/{en-Cj5r8sW_.cjs → en-C5Z4Ag9_.cjs} +2 -2
  26. package/dist/en-C5Z4Ag9_.cjs.map +1 -0
  27. package/dist/{en-B9hMApn4.js → en-CGKXfWma.js} +9 -1
  28. package/dist/en-CGKXfWma.js.map +1 -0
  29. package/dist/{extensions-D2mx2C9y.js → extensions-CrUGDOks.js} +655 -583
  30. package/dist/extensions-CrUGDOks.js.map +1 -0
  31. package/dist/extensions-Ghr9QqqR.cjs +52 -0
  32. package/dist/extensions-Ghr9QqqR.cjs.map +1 -0
  33. package/dist/extensions.cjs +1 -1
  34. package/dist/extensions.js +4 -4
  35. package/dist/locales.cjs +1 -1
  36. package/dist/locales.cjs.map +1 -1
  37. package/dist/locales.js +177 -1
  38. package/dist/locales.js.map +1 -1
  39. package/dist/{src-Dvmif2FY.js → src-DTF83Cl9.js} +1243 -1297
  40. package/dist/src-DTF83Cl9.js.map +1 -0
  41. package/dist/src-OfbaVbMw.cjs +21 -0
  42. package/dist/src-OfbaVbMw.cjs.map +1 -0
  43. package/dist/style.css +1 -1
  44. package/dist/webpack-stats.json +1 -1
  45. package/dist/y.cjs +2 -0
  46. package/dist/y.cjs.map +1 -0
  47. package/dist/y.js +989 -0
  48. package/dist/y.js.map +1 -0
  49. package/dist/yjs.cjs +1 -1
  50. package/dist/yjs.cjs.map +1 -1
  51. package/dist/yjs.js +535 -14
  52. package/dist/yjs.js.map +1 -1
  53. package/package.json +46 -19
  54. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +1 -1
  55. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
  56. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
  57. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +25 -20
  58. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +39 -29
  59. package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +2 -2
  60. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +4 -8
  61. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +1 -1
  62. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +21 -9
  63. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +6 -5
  64. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +362 -4
  65. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +240 -30
  66. package/src/api/blockManipulation/getBlock/getBlock.ts +4 -9
  67. package/src/api/blockManipulation/selections/selection.ts +3 -6
  68. package/src/api/blockManipulation/selections/textCursorPosition.ts +10 -10
  69. package/src/api/blockManipulation/setupTestEnv.ts +1 -1
  70. package/src/api/blockManipulation/tables/tables.test.ts +1 -1
  71. package/src/api/clipboard/fromClipboard/fileDropExtension.ts +1 -1
  72. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +8 -4
  73. package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
  74. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +2 -1
  75. package/src/api/exporters/markdown/htmlToMarkdown.ts +79 -43
  76. package/src/api/getBlockInfoFromPos.test.ts +256 -0
  77. package/src/api/getBlockInfoFromPos.ts +53 -15
  78. package/src/api/getBlocksChangedByTransaction.test.ts +2 -1
  79. package/src/api/getBlocksChangedByTransaction.ts +6 -6
  80. package/src/api/nodeConversions/blockToNode.test.ts +113 -0
  81. package/src/api/nodeConversions/blockToNode.ts +15 -3
  82. package/src/api/nodeConversions/fragmentToBlocks.ts +2 -4
  83. package/src/api/nodeConversions/nodeToBlock.ts +28 -58
  84. package/src/api/nodeUtil.ts +6 -2
  85. package/src/api/parsers/html/parseHTML.ts +1 -1
  86. package/src/api/parsers/html/util/nestedLists.test.ts +1 -1
  87. package/src/api/parsers/markdown/detectMarkdown.test.ts +1 -1
  88. package/src/api/parsers/markdown/markdownToHtml.ts +228 -82
  89. package/src/api/pmUtil.ts +18 -1
  90. package/src/api/positionMapping.test.ts +20 -345
  91. package/src/api/positionMapping.ts +13 -83
  92. package/src/blocks/Audio/block.ts +1 -1
  93. package/src/blocks/Code/block.test.ts +14 -7
  94. package/src/blocks/Code/block.ts +2 -2
  95. package/src/blocks/Image/block.ts +1 -1
  96. package/src/blocks/ListItem/CheckListItem/block.test.ts +1 -1
  97. package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +2 -2
  98. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +4 -11
  99. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +47 -50
  100. package/src/blocks/Table/TableExtension.test.ts +129 -0
  101. package/src/blocks/Table/TableExtension.ts +23 -20
  102. package/src/blocks/Table/block.ts +18 -5
  103. package/src/blocks/Video/block.ts +1 -1
  104. package/src/blocks/utils/listItemEnterHandler.ts +3 -2
  105. package/src/comments/extension.ts +30 -21
  106. package/src/comments/index.ts +0 -3
  107. package/src/comments/mark.ts +4 -0
  108. package/src/comments/threadstore/ThreadStore.ts +4 -8
  109. package/src/comments/types.ts +0 -8
  110. package/src/editor/Block.css +307 -3
  111. package/src/editor/BlockNoteEditor.test.ts +39 -18
  112. package/src/editor/BlockNoteEditor.ts +22 -57
  113. package/src/editor/BlockNoteExtension.test.ts +1 -1
  114. package/src/editor/managers/BlockManager.ts +1 -1
  115. package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +249 -0
  116. package/src/editor/managers/ExtensionManager/extensions.ts +7 -18
  117. package/src/editor/managers/ExtensionManager/index.ts +168 -68
  118. package/src/editor/managers/StateManager.ts +4 -3
  119. package/src/editor/performance.test.ts +14 -1
  120. package/src/editor/transformPasted.test.ts +1 -1
  121. package/src/extensions/Placeholder/Placeholder.ts +1 -0
  122. package/src/extensions/PositionMapping/PositionMapping.ts +68 -0
  123. package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +14 -1
  124. package/src/extensions/PreviousBlockType/PreviousBlockType.ts +14 -11
  125. package/src/extensions/SideMenu/SideMenu.ts +9 -2
  126. package/src/extensions/SuggestionMenu/SuggestionMenu.test.ts +1 -1
  127. package/src/extensions/TableHandles/TableHandles.ts +18 -20
  128. package/src/extensions/TrailingNode/TrailingNode.ts +33 -1
  129. package/src/extensions/Versioning/Versioning.test.ts +435 -0
  130. package/src/extensions/Versioning/Versioning.ts +628 -0
  131. package/src/extensions/Versioning/inMemoryVersioning.test.ts +469 -0
  132. package/src/extensions/Versioning/inMemoryVersioning.ts +263 -0
  133. package/src/extensions/Versioning/index.ts +2 -0
  134. package/src/extensions/index.ts +6 -9
  135. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +155 -0
  136. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +6 -8
  137. package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +9 -9
  138. package/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts +8 -10
  139. package/src/extensions/tiptap-extensions/Link/helpers/whitespace.ts +2 -2
  140. package/src/extensions/tiptap-extensions/Link/link.test.ts +26 -22
  141. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +187 -0
  142. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +37 -24
  143. package/src/extensions/tiptap-extensions/index.ts +1 -25
  144. package/src/i18n/locales/ar.ts +9 -0
  145. package/src/i18n/locales/de.ts +9 -0
  146. package/src/i18n/locales/en.ts +10 -1
  147. package/src/i18n/locales/es.ts +9 -0
  148. package/src/i18n/locales/fa.ts +11 -1
  149. package/src/i18n/locales/fr.ts +9 -0
  150. package/src/i18n/locales/he.ts +10 -1
  151. package/src/i18n/locales/hr.ts +10 -0
  152. package/src/i18n/locales/is.ts +10 -0
  153. package/src/i18n/locales/it.ts +9 -0
  154. package/src/i18n/locales/ja.ts +9 -0
  155. package/src/i18n/locales/ko.ts +9 -0
  156. package/src/i18n/locales/nl.ts +10 -0
  157. package/src/i18n/locales/no.ts +10 -0
  158. package/src/i18n/locales/pl.ts +9 -0
  159. package/src/i18n/locales/pt.ts +10 -0
  160. package/src/i18n/locales/ru.ts +10 -0
  161. package/src/i18n/locales/sk.ts +10 -1
  162. package/src/i18n/locales/uk.ts +9 -0
  163. package/src/i18n/locales/uz.ts +9 -0
  164. package/src/i18n/locales/vi.ts +9 -0
  165. package/src/i18n/locales/zh-tw.ts +9 -0
  166. package/src/i18n/locales/zh.ts +9 -0
  167. package/src/index.ts +2 -0
  168. package/src/pm-nodes/BlockContainer.ts +4 -1
  169. package/src/pm-nodes/BlockGroup.ts +4 -1
  170. package/src/pm-nodes/Doc.ts +4 -1
  171. package/src/pm-nodes/suggestionMarks.ts +43 -0
  172. package/src/schema/blocks/createSpec.test.ts +123 -0
  173. package/src/schema/blocks/createSpec.ts +82 -24
  174. package/src/schema/blocks/extendBlockSpec.test.ts +188 -0
  175. package/src/schema/blocks/internal.ts +13 -43
  176. package/src/schema/blocks/types.ts +69 -22
  177. package/src/schema/contentTypePropagation.test.ts +182 -0
  178. package/src/schema/index.ts +1 -0
  179. package/src/schema/inlineContent/internal.ts +1 -1
  180. package/src/schema/inlineContent/types.ts +3 -3
  181. package/src/schema/markGroups.ts +50 -0
  182. package/src/user/UserStore.ts +199 -0
  183. package/src/user/createUserStore.test.ts +126 -0
  184. package/src/user/index.ts +2 -0
  185. package/src/user/userColors.ts +72 -0
  186. package/src/util/string.ts +1 -1
  187. package/src/util/topo-sort.test.ts +1 -1
  188. package/src/util/typescript.ts +2 -1
  189. package/src/vite-env.d.ts +1 -1
  190. package/src/y/README.md +5 -0
  191. package/src/{comments/threadstore/yjs → y/comments}/RESTYjsThreadStore.ts +8 -14
  192. package/src/y/comments/YjsThreadStore.test.ts +295 -0
  193. package/src/y/comments/YjsThreadStore.ts +358 -0
  194. package/src/y/comments/YjsThreadStoreBase.ts +50 -0
  195. package/src/y/comments/index.ts +3 -0
  196. package/src/y/comments/yjsHelpers.ts +125 -0
  197. package/src/y/extensions/AttributionExtension.test.ts +86 -0
  198. package/src/y/extensions/AttributionExtension.ts +378 -0
  199. package/src/y/extensions/DiffVersioningExtension.test.ts +193 -0
  200. package/src/y/extensions/DiffVersioningExtension.ts +228 -0
  201. package/src/y/extensions/ForkYDoc.test.ts +253 -0
  202. package/src/y/extensions/ForkYDoc.ts +108 -0
  203. package/src/y/extensions/RelativePositionMapping.test.ts +418 -0
  204. package/src/y/extensions/RelativePositionMapping.ts +49 -0
  205. package/src/y/extensions/Suggestions.ts +174 -0
  206. package/src/y/extensions/Versioning.test.ts +395 -0
  207. package/src/y/extensions/Versioning.ts +115 -0
  208. package/src/y/extensions/YAttributionMarks.ts +320 -0
  209. package/src/{extensions/Collaboration → y/extensions}/YCursorPlugin.ts +15 -7
  210. package/src/y/extensions/YSync.ts +125 -0
  211. package/src/y/extensions/blockMatchNodes.ts +182 -0
  212. package/src/y/extensions/index.ts +156 -0
  213. package/src/y/index.ts +4 -0
  214. package/src/y/utils.test.ts +1042 -0
  215. package/src/y/utils.ts +242 -0
  216. package/src/y/versioning/__test__/fixtures/activity-all-after.bin +0 -0
  217. package/src/y/versioning/__test__/fixtures/activity-all-after.json +50 -0
  218. package/src/y/versioning/__test__/fixtures/activity-all.bin +0 -0
  219. package/src/y/versioning/__test__/fixtures/activity-all.json +20 -0
  220. package/src/y/versioning/__test__/fixtures/activity-filtered-after.bin +0 -0
  221. package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +32 -0
  222. package/src/y/versioning/__test__/fixtures/activity-filtered-before.json +1 -0
  223. package/src/y/versioning/__test__/fixtures/changeset.bin +0 -0
  224. package/src/y/versioning/__test__/fixtures/patch-response.json +4 -0
  225. package/src/y/versioning/__test__/yhub.test.ts +752 -0
  226. package/src/y/versioning/index.ts +1 -0
  227. package/src/y/versioning/yhub.ts +631 -0
  228. package/src/yjs/README.md +5 -0
  229. package/src/yjs/comments/RESTYjsThreadStore.ts +166 -0
  230. package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.test.ts +3 -3
  231. package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.ts +7 -3
  232. package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.ts +3 -3
  233. package/src/yjs/comments/index.ts +3 -0
  234. package/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.ts +5 -1
  235. package/src/yjs/extensions/FixUpSchema.test.ts +421 -0
  236. package/src/yjs/extensions/FixUpSchema.ts +88 -0
  237. package/src/yjs/extensions/ForkYDoc.test.ts +216 -0
  238. package/src/{extensions/Collaboration → yjs/extensions}/ForkYDoc.ts +38 -57
  239. package/src/yjs/extensions/RelativePositionMapping.test.ts +418 -0
  240. package/src/yjs/extensions/RelativePositionMapping.ts +71 -0
  241. package/src/yjs/extensions/Versioning.test.ts +549 -0
  242. package/src/yjs/extensions/Versioning.ts +83 -0
  243. package/src/yjs/extensions/YCursorPlugin.ts +201 -0
  244. package/src/{extensions/Collaboration → yjs/extensions}/YSync.ts +1 -1
  245. package/src/yjs/extensions/index.ts +89 -0
  246. package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.test.ts +1 -1
  247. package/src/yjs/index.ts +2 -0
  248. package/src/yjs/utils.test.ts +5 -15
  249. package/src/yjs/utils.ts +36 -0
  250. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +3 -1
  251. package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
  252. package/types/src/api/getBlockInfoFromPos.d.ts +5 -9
  253. package/types/src/api/nodeConversions/nodeToBlock.d.ts +4 -6
  254. package/types/src/api/pmUtil.d.ts +12 -1
  255. package/types/src/blocks/Audio/block.d.ts +2 -2
  256. package/types/src/blocks/Code/block.d.ts +2 -2
  257. package/types/src/blocks/File/block.d.ts +2 -2
  258. package/types/src/blocks/Heading/block.d.ts +21 -21
  259. package/types/src/blocks/Image/block.d.ts +3 -3
  260. package/types/src/blocks/ListItem/CheckListItem/block.d.ts +6 -6
  261. package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +6 -6
  262. package/types/src/blocks/Video/block.d.ts +3 -3
  263. package/types/src/blocks/defaultBlocks.d.ts +17 -17
  264. package/types/src/comments/extension.d.ts +18 -5
  265. package/types/src/comments/index.d.ts +0 -3
  266. package/types/src/comments/threadstore/ThreadStore.d.ts +4 -8
  267. package/types/src/comments/types.d.ts +0 -8
  268. package/types/src/editor/BlockNoteEditor.d.ts +8 -9
  269. package/types/src/editor/managers/BlockManager.d.ts +1 -1
  270. package/types/src/editor/managers/ExtensionManager/ExtensionManager.test.d.ts +1 -0
  271. package/types/src/editor/managers/ExtensionManager/extensions.d.ts +2 -2
  272. package/types/src/editor/managers/ExtensionManager/index.d.ts +13 -0
  273. package/types/src/editor/managers/SelectionManager.d.ts +1 -1
  274. package/types/src/extensions/PositionMapping/PositionMapping.d.ts +4 -0
  275. package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -6
  276. package/types/src/extensions/Versioning/Versioning.d.ts +352 -0
  277. package/types/src/extensions/Versioning/Versioning.test.d.ts +1 -0
  278. package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +37 -0
  279. package/types/src/extensions/Versioning/inMemoryVersioning.test.d.ts +1 -0
  280. package/types/src/extensions/Versioning/index.d.ts +2 -0
  281. package/types/src/extensions/index.d.ts +6 -9
  282. package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +1 -0
  283. package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.d.ts +6 -1
  284. package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.d.ts +4 -0
  285. package/types/src/extensions/tiptap-extensions/index.d.ts +1 -5
  286. package/types/src/i18n/locales/en.d.ts +9 -1
  287. package/types/src/i18n/locales/fa.d.ts +9 -1
  288. package/types/src/i18n/locales/sk.d.ts +9 -1
  289. package/types/src/index.d.ts +2 -0
  290. package/types/src/pm-nodes/suggestionMarks.d.ts +26 -0
  291. package/types/src/schema/blocks/createSpec.d.ts +4 -4
  292. package/types/src/schema/blocks/createSpec.test.d.ts +1 -0
  293. package/types/src/schema/blocks/extendBlockSpec.test.d.ts +1 -0
  294. package/types/src/schema/blocks/internal.d.ts +5 -7
  295. package/types/src/schema/blocks/types.d.ts +22 -14
  296. package/types/src/schema/contentTypePropagation.test.d.ts +1 -0
  297. package/types/src/schema/index.d.ts +1 -0
  298. package/types/src/schema/inlineContent/types.d.ts +3 -3
  299. package/types/src/schema/markGroups.d.ts +33 -0
  300. package/types/src/user/UserStore.d.ts +105 -0
  301. package/types/src/user/createUserStore.test.d.ts +1 -0
  302. package/types/src/user/index.d.ts +2 -0
  303. package/types/src/user/userColors.d.ts +36 -0
  304. package/types/src/y/comments/RESTYjsThreadStore.d.ts +77 -0
  305. package/types/src/y/comments/YjsThreadStore.d.ts +79 -0
  306. package/types/src/y/comments/YjsThreadStore.test.d.ts +1 -0
  307. package/types/src/y/comments/YjsThreadStoreBase.d.ts +15 -0
  308. package/types/src/y/comments/index.d.ts +3 -0
  309. package/types/src/y/comments/yjsHelpers.d.ts +13 -0
  310. package/types/src/y/extensions/AttributionExtension.d.ts +74 -0
  311. package/types/src/y/extensions/AttributionExtension.test.d.ts +1 -0
  312. package/types/src/y/extensions/DiffVersioningExtension.d.ts +69 -0
  313. package/types/src/y/extensions/DiffVersioningExtension.test.d.ts +1 -0
  314. package/types/src/{extensions/Collaboration → y/extensions}/ForkYDoc.d.ts +4 -2
  315. package/types/src/y/extensions/ForkYDoc.test.d.ts +1 -0
  316. package/types/src/y/extensions/RelativePositionMapping.d.ts +4 -0
  317. package/types/src/y/extensions/RelativePositionMapping.test.d.ts +1 -0
  318. package/types/src/y/extensions/Suggestions.d.ts +36 -0
  319. package/types/src/y/extensions/Versioning.d.ts +17 -0
  320. package/types/src/y/extensions/Versioning.test.d.ts +1 -0
  321. package/types/src/y/extensions/YAttributionMarks.d.ts +67 -0
  322. package/types/src/y/extensions/YCursorPlugin.d.ts +14 -0
  323. package/types/src/y/extensions/YSync.d.ts +32 -0
  324. package/types/src/y/extensions/blockMatchNodes.d.ts +25 -0
  325. package/types/src/y/extensions/index.d.ts +189 -0
  326. package/types/src/y/index.d.ts +4 -0
  327. package/types/src/y/utils.d.ts +82 -0
  328. package/types/src/y/utils.test.d.ts +1 -0
  329. package/types/src/y/versioning/__test__/yhub.test.d.ts +1 -0
  330. package/types/src/y/versioning/index.d.ts +1 -0
  331. package/types/src/y/versioning/yhub.d.ts +87 -0
  332. package/types/src/{comments/threadstore/yjs → yjs/comments}/RESTYjsThreadStore.d.ts +6 -10
  333. package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.d.ts +3 -3
  334. package/types/src/yjs/comments/YjsThreadStore.test.d.ts +1 -0
  335. package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.d.ts +3 -3
  336. package/types/src/yjs/comments/index.d.ts +3 -0
  337. package/types/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.d.ts +1 -1
  338. package/types/src/yjs/extensions/FixUpSchema.d.ts +3 -0
  339. package/types/src/yjs/extensions/FixUpSchema.test.d.ts +1 -0
  340. package/types/src/yjs/extensions/ForkYDoc.d.ts +27 -0
  341. package/types/src/yjs/extensions/ForkYDoc.test.d.ts +1 -0
  342. package/types/src/yjs/extensions/RelativePositionMapping.d.ts +4 -0
  343. package/types/src/yjs/extensions/RelativePositionMapping.test.d.ts +1 -0
  344. package/types/src/yjs/extensions/Versioning.d.ts +26 -0
  345. package/types/src/yjs/extensions/Versioning.test.d.ts +1 -0
  346. package/types/src/{extensions/Collaboration → yjs/extensions}/YCursorPlugin.d.ts +5 -2
  347. package/types/src/{extensions/Collaboration → yjs/extensions}/YSync.d.ts +1 -1
  348. package/types/src/{extensions/Collaboration/Collaboration.d.ts → yjs/extensions/index.d.ts} +36 -15
  349. package/types/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +1 -0
  350. package/types/src/yjs/index.d.ts +2 -0
  351. package/types/src/yjs/utils.d.ts +5 -0
  352. package/dist/BlockNoteExtension-B6RhuQ3V.js +0 -27
  353. package/dist/BlockNoteExtension-B6RhuQ3V.js.map +0 -1
  354. package/dist/BlockNoteExtension-ab0REuob.cjs +0 -2
  355. package/dist/BlockNoteExtension-ab0REuob.cjs.map +0 -1
  356. package/dist/EventEmitter-CuPnGDYt.js +0 -22
  357. package/dist/EventEmitter-CuPnGDYt.js.map +0 -1
  358. package/dist/EventEmitter-DHdSnYCD.cjs +0 -2
  359. package/dist/EventEmitter-DHdSnYCD.cjs.map +0 -1
  360. package/dist/ShowSelection-BsHFfdMi.js +0 -29
  361. package/dist/ShowSelection-BsHFfdMi.js.map +0 -1
  362. package/dist/ShowSelection-DhXglbt8.cjs +0 -2
  363. package/dist/ShowSelection-DhXglbt8.cjs.map +0 -1
  364. package/dist/blocks-D0lMxErU.js.map +0 -1
  365. package/dist/blocks-KyMOxPT3.cjs +0 -11
  366. package/dist/blocks-KyMOxPT3.cjs.map +0 -1
  367. package/dist/en-B9hMApn4.js.map +0 -1
  368. package/dist/en-Cj5r8sW_.cjs.map +0 -1
  369. package/dist/extensions-Cutrafjg.cjs +0 -52
  370. package/dist/extensions-Cutrafjg.cjs.map +0 -1
  371. package/dist/extensions-D2mx2C9y.js.map +0 -1
  372. package/dist/src-D5R5YzV7.cjs +0 -21
  373. package/dist/src-D5R5YzV7.cjs.map +0 -1
  374. package/dist/src-Dvmif2FY.js.map +0 -1
  375. package/src/comments/userstore/UserStore.ts +0 -72
  376. package/src/extensions/Collaboration/Collaboration.ts +0 -55
  377. package/src/extensions/Collaboration/ForkYDoc.test.ts +0 -179
  378. package/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.ts +0 -175
  379. package/types/src/comments/userstore/UserStore.d.ts +0 -31
  380. package/types/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.d.ts +0 -4
  381. /package/src/{extensions/Collaboration → yjs/extensions}/YUndo.ts +0 -0
  382. /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor-forked.json +0 -0
  383. /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor.json +0 -0
  384. /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-forked.html +0 -0
  385. /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap.html +0 -0
  386. /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.ts +0 -0
  387. /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.ts +0 -0
  388. /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.ts +0 -0
  389. /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.ts +0 -0
  390. /package/types/src/{comments/threadstore/yjs/YjsThreadStore.test.d.ts → api/getBlockInfoFromPos.test.d.ts} +0 -0
  391. /package/types/src/{extensions/Collaboration/ForkYDoc.test.d.ts → api/nodeConversions/blockToNode.test.d.ts} +0 -0
  392. /package/types/src/{extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.d.ts → blocks/Table/TableExtension.test.d.ts} +0 -0
  393. /package/types/src/{extensions/Collaboration → yjs/extensions}/YUndo.d.ts +0 -0
  394. /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.d.ts +0 -0
  395. /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.d.ts +0 -0
  396. /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.d.ts +0 -0
  397. /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.d.ts +0 -0
package/dist/yjs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"yjs.js","names":[],"sources":["../src/yjs/utils.ts"],"sourcesContent":["import {\n prosemirrorToYDoc,\n prosemirrorToYXmlFragment,\n yXmlFragmentToProseMirrorRootNode,\n} from \"y-prosemirror\";\nimport * as Y from \"yjs\";\n\nimport {\n type Block,\n type BlockNoteEditor,\n type BlockSchema,\n type InlineContentSchema,\n type PartialBlock,\n type StyleSchema,\n blockToNode,\n docToBlocks,\n} from \"../index.js\";\n\n/**\n * Turn Prosemirror JSON to BlockNote style JSON\n * @param editor BlockNote editor\n * @param json Prosemirror JSON\n * @returns BlockNote style JSON\n */\nexport function _prosemirrorJSONToBlocks<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(editor: BlockNoteEditor<BSchema, ISchema, SSchema>, json: any) {\n // note: theoretically this should also be possible without creating prosemirror nodes,\n // but this is definitely the easiest way\n const doc = editor.pmSchema.nodeFromJSON(json);\n return docToBlocks<BSchema, ISchema, SSchema>(doc);\n}\n\n/**\n * Turn BlockNote JSON to Prosemirror node / state\n * @param editor BlockNote editor\n * @param blocks BlockNote blocks\n * @returns Prosemirror root node\n */\nexport function _blocksToProsemirrorNode<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(\n editor: BlockNoteEditor<BSchema, ISchema, SSchema>,\n blocks: PartialBlock<BSchema, ISchema, SSchema>[],\n) {\n const pmNodes = blocks.map((b) => blockToNode(b, editor.pmSchema));\n\n const doc = editor.pmSchema.topNodeType.create(\n null,\n editor.pmSchema.nodes[\"blockGroup\"].create(null, pmNodes),\n );\n return doc;\n}\n\n/** YJS / BLOCKNOTE conversions */\n\n/**\n * Turn a Y.XmlFragment collaborative doc into a BlockNote document (BlockNote style JSON of all blocks)\n * @param editor BlockNote editor\n * @param xmlFragment Y.XmlFragment\n * @returns BlockNote document (BlockNote style JSON of all blocks)\n */\nexport function yXmlFragmentToBlocks<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(\n editor: BlockNoteEditor<BSchema, ISchema, SSchema>,\n xmlFragment: Y.XmlFragment,\n) {\n const pmNode = yXmlFragmentToProseMirrorRootNode(\n xmlFragment,\n editor.pmSchema,\n );\n return docToBlocks<BSchema, ISchema, SSchema>(pmNode);\n}\n\n/**\n * Convert blocks to a Y.XmlFragment\n *\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * @param editor BlockNote editor\n * @param blocks the blocks to convert\n * @param xmlFragment XML fragment name\n * @returns Y.XmlFragment\n */\nexport function blocksToYXmlFragment<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(\n editor: BlockNoteEditor<BSchema, ISchema, SSchema>,\n blocks: Block<BSchema, ISchema, SSchema>[],\n xmlFragment?: Y.XmlFragment,\n) {\n return prosemirrorToYXmlFragment(\n _blocksToProsemirrorNode(editor, blocks),\n xmlFragment,\n );\n}\n\n/**\n * Turn a Y.Doc collaborative doc into a BlockNote document (BlockNote style JSON of all blocks)\n * @param editor BlockNote editor\n * @param ydoc Y.Doc\n * @param xmlFragment XML fragment name\n * @returns BlockNote document (BlockNote style JSON of all blocks)\n */\nexport function yDocToBlocks<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(\n editor: BlockNoteEditor<BSchema, ISchema, SSchema>,\n ydoc: Y.Doc,\n xmlFragment = \"prosemirror\",\n) {\n return yXmlFragmentToBlocks(editor, ydoc.getXmlFragment(xmlFragment));\n}\n\n/**\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * @param editor BlockNote editor\n * @param blocks the blocks to convert\n * @param xmlFragment XML fragment name\n */\nexport function blocksToYDoc<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(\n editor: BlockNoteEditor<BSchema, ISchema, SSchema>,\n blocks: PartialBlock<BSchema, ISchema, SSchema>[],\n xmlFragment = \"prosemirror\",\n) {\n return prosemirrorToYDoc(\n _blocksToProsemirrorNode(editor, blocks),\n xmlFragment,\n );\n}\n"],"mappings":";;;AAwBA,SAAgB,EAId,GAAoD,GAAW;AAI/D,QAAO,EADK,EAAO,SAAS,aAAa,EAAK,CACI;;AASpD,SAAgB,EAKd,GACA,GACA;CACA,IAAM,IAAU,EAAO,KAAK,MAAM,EAAY,GAAG,EAAO,SAAS,CAAC;AAMlE,QAJY,EAAO,SAAS,YAAY,OACtC,MACA,EAAO,SAAS,MAAM,WAAc,OAAO,MAAM,EAAQ,CAC1D;;AAYH,SAAgB,EAKd,GACA,GACA;AAKA,QAAO,EAJQ,EACb,GACA,EAAO,SACR,CACoD;;AAevD,SAAgB,EAKd,GACA,GACA,GACA;AACA,QAAO,EACL,EAAyB,GAAQ,EAAO,EACxC,EACD;;AAUH,SAAgB,EAKd,GACA,GACA,IAAc,eACd;AACA,QAAO,EAAqB,GAAQ,EAAK,eAAe,EAAY,CAAC;;AAYvE,SAAgB,EAKd,GACA,GACA,IAAc,eACd;AACA,QAAO,EACL,EAAyB,GAAQ,EAAO,EACxC,EACD"}
1
+ {"version":3,"file":"yjs.js","names":[],"sources":["../src/yjs/utils.ts","../src/yjs/extensions/FixUpSchema.ts","../src/yjs/extensions/YCursorPlugin.ts","../src/yjs/extensions/YSync.ts","../src/yjs/extensions/YUndo.ts","../src/yjs/extensions/ForkYDoc.ts","../src/yjs/extensions/RelativePositionMapping.ts","../src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.ts","../src/yjs/extensions/schemaMigration/migrationRules/index.ts","../src/yjs/extensions/schemaMigration/SchemaMigration.ts","../src/yjs/extensions/Versioning.ts","../src/yjs/extensions/index.ts","../src/yjs/comments/yjsHelpers.ts","../src/yjs/comments/YjsThreadStoreBase.ts","../src/yjs/comments/RESTYjsThreadStore.ts","../src/yjs/comments/YjsThreadStore.ts"],"sourcesContent":["import {\n prosemirrorToYDoc,\n prosemirrorToYXmlFragment,\n yXmlFragmentToProseMirrorRootNode,\n} from \"y-prosemirror\";\nimport * as Y from \"yjs\";\n\nimport {\n type Block,\n type BlockNoteEditor,\n type BlockSchema,\n type InlineContentSchema,\n type PartialBlock,\n type StyleSchema,\n blockToNode,\n docToBlocks,\n} from \"../index.js\";\n\n/**\n * Find a Y.AbstractType in another Y.Doc that corresponds to the same\n * logical type in the original doc.\n */\nexport function findTypeInOtherYdoc<T extends Y.AbstractType<any>>(\n ytype: T,\n otherYdoc: Y.Doc,\n): T {\n const ydoc = ytype.doc;\n if (!ydoc) {\n throw new Error(\"type does not have a ydoc\");\n }\n if (ytype._item === null) {\n const rootKey = Array.from(ydoc.share.keys()).find(\n (key) => ydoc.share.get(key) === ytype,\n );\n if (rootKey == null) {\n throw new Error(\"type does not exist in other ydoc\");\n }\n return otherYdoc.get(rootKey, ytype.constructor as new () => T) as T;\n } else {\n const ytypeItem = ytype._item;\n const otherStructs = otherYdoc.store.clients.get(ytypeItem.id.client) ?? [];\n const itemIndex = Y.findIndexSS(otherStructs, ytypeItem.id.clock);\n const otherItem = otherStructs[itemIndex] as Y.Item | undefined;\n if (!otherItem) {\n throw new Error(\"type does not exist in other ydoc\");\n }\n const otherContent = otherItem.content as Y.ContentType | undefined;\n if (!otherContent) {\n throw new Error(\"type does not exist in other ydoc\");\n }\n return otherContent.type as T;\n }\n}\n\n/**\n * Turn Prosemirror JSON to BlockNote style JSON\n * @param editor BlockNote editor\n * @param json Prosemirror JSON\n * @returns BlockNote style JSON\n */\nexport function _prosemirrorJSONToBlocks<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(editor: BlockNoteEditor<BSchema, ISchema, SSchema>, json: any) {\n // note: theoretically this should also be possible without creating prosemirror nodes,\n // but this is definitely the easiest way\n const doc = editor.pmSchema.nodeFromJSON(json);\n return docToBlocks<BSchema, ISchema, SSchema>(doc);\n}\n\n/**\n * Turn BlockNote JSON to Prosemirror node / state\n * @param editor BlockNote editor\n * @param blocks BlockNote blocks\n * @returns Prosemirror root node\n */\nexport function _blocksToProsemirrorNode<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(\n editor: BlockNoteEditor<BSchema, ISchema, SSchema>,\n blocks: PartialBlock<BSchema, ISchema, SSchema>[],\n) {\n const pmNodes = blocks.map((b) => blockToNode(b, editor.pmSchema));\n\n const doc = editor.pmSchema.topNodeType.create(\n null,\n editor.pmSchema.nodes[\"blockGroup\"].create(null, pmNodes),\n );\n return doc;\n}\n\n/** YJS / BLOCKNOTE conversions */\n\n/**\n * Turn a Y.XmlFragment collaborative doc into a BlockNote document (BlockNote style JSON of all blocks)\n * @param editor BlockNote editor\n * @param xmlFragment Y.XmlFragment\n * @returns BlockNote document (BlockNote style JSON of all blocks)\n */\nexport function yXmlFragmentToBlocks<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(\n editor: BlockNoteEditor<BSchema, ISchema, SSchema>,\n xmlFragment: Y.XmlFragment,\n) {\n const pmNode = yXmlFragmentToProseMirrorRootNode(\n xmlFragment,\n editor.pmSchema,\n );\n return docToBlocks<BSchema, ISchema, SSchema>(pmNode);\n}\n\n/**\n * Convert blocks to a Y.XmlFragment\n *\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * @param editor BlockNote editor\n * @param blocks the blocks to convert\n * @param xmlFragment XML fragment name\n * @returns Y.XmlFragment\n */\nexport function blocksToYXmlFragment<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(\n editor: BlockNoteEditor<BSchema, ISchema, SSchema>,\n blocks: Block<BSchema, ISchema, SSchema>[],\n xmlFragment?: Y.XmlFragment,\n) {\n return prosemirrorToYXmlFragment(\n _blocksToProsemirrorNode(editor, blocks),\n xmlFragment,\n );\n}\n\n/**\n * Turn a Y.Doc collaborative doc into a BlockNote document (BlockNote style JSON of all blocks)\n * @param editor BlockNote editor\n * @param ydoc Y.Doc\n * @param xmlFragment XML fragment name\n * @returns BlockNote document (BlockNote style JSON of all blocks)\n */\nexport function yDocToBlocks<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(\n editor: BlockNoteEditor<BSchema, ISchema, SSchema>,\n ydoc: Y.Doc,\n xmlFragment = \"prosemirror\",\n) {\n return yXmlFragmentToBlocks(editor, ydoc.getXmlFragment(xmlFragment));\n}\n\n/**\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * @param editor BlockNote editor\n * @param blocks the blocks to convert\n * @param xmlFragment XML fragment name\n */\nexport function blocksToYDoc<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n>(\n editor: BlockNoteEditor<BSchema, ISchema, SSchema>,\n blocks: PartialBlock<BSchema, ISchema, SSchema>[],\n xmlFragment = \"prosemirror\",\n) {\n return prosemirrorToYDoc(\n _blocksToProsemirrorNode(editor, blocks),\n xmlFragment,\n );\n}\n","import { Attrs, Fragment, Mark, Node, NodeType } from \"prosemirror-model\";\n\nimport { isPlainContentNodeType } from \"../../api/pmUtil.js\";\nimport { createExtension } from \"../../editor/BlockNoteExtension.js\";\n\n// Collaboration-only patches to the live ProseMirror schema. Both are applied\n// once on `create`, before y-prosemirror binds and reconstructs the document.\nexport const FixUpSchemaExtension = createExtension(({ editor }) => {\n editor.on(\"create\", () => {\n const schema = editor.pmSchema;\n\n // 1. Preserve the initial block id.\n // When y-prosemirror creates an empty document, the `blockContainer` node is created with an `id` of `null`.\n // This causes the unique id extension to generate a new id for the initial block, which is not what we want\n // Since it will be randomly generated & cause there to be more updates to the ydoc\n // This is a hack to make it so that anytime `schema.doc.createAndFill` is called, the initial block id is already set to \"initialBlockId\"\n let cache: Node | undefined = undefined;\n // eslint-disable-next-line @typescript-eslint/unbound-method -- intentionally saving reference for monkey-patching\n const oldCreateAndFill = schema.nodes.doc.createAndFill;\n schema.nodes.doc.createAndFill = ((...args: any) => {\n if (cache) {\n return cache;\n }\n const ret = oldCreateAndFill.apply(schema.nodes.doc, args)!;\n\n // create a copy that we can mutate (otherwise, assigning attrs is not safe and corrupts the pm state)\n const jsonNode = JSON.parse(JSON.stringify(ret.toJSON()));\n jsonNode.content[0].content[0].attrs.id = \"initialBlockId\";\n\n cache = Node.fromJSON(schema, jsonNode);\n return cache;\n }) as unknown as typeof schema.nodes.doc.createAndFill;\n\n // 2. Drop marks a plain block no longer allows, instead of deleting the block.\n // When a block's content type changes across BlockNote versions — e.g. a\n // `codeBlock` that was `\"inline\"` (formatting marks like bold allowed) and is\n // now `\"plain\"` (only the `\"annotation\"` mark group: comments + suggestions) —\n // old Yjs documents carry text with marks the new node type disallows.\n //\n // y-prosemirror rebuilds each block by calling `schema.node(nodeName, attrs,\n // children)`, where `children` are text nodes that may still carry those\n // disallowed marks. `createChecked` then throws, and y-prosemirror's error\n // handler DELETES the whole block from the Yjs doc — a deletion that propagates\n // to every peer (data loss).\n //\n // Rather than mutating the Yjs doc to strip those marks, we leave them in place\n // (marks are just format attributes; they don't affect position counting, so\n // editing text is unaffected) and simply never materialize the disallowed ones\n // into ProseMirror. We do that by wrapping `schema.node` to filter each text\n // child's marks through the parent node type's `allowedMarks` before the node\n // is built. The wrapper is scoped to plain-content blocks (the only place this\n // migration applies); all other node types pass through untouched.\n //\n // NOTE: this covers marks that EXIST in the schema but aren't allowed on the\n // node. A mark whose type is entirely absent from the schema still hits\n // y-prosemirror's earlier `schema.mark` throw (and delete) path — that's a\n // different migration scenario and is out of scope here.\n // eslint-disable-next-line @typescript-eslint/unbound-method -- intentionally saving reference for monkey-patching\n const originalNode = schema.node;\n schema.node = function (\n this: typeof schema,\n type: string | NodeType,\n attrs?: Attrs | null,\n content?: Fragment | Node | readonly Node[],\n marks?: readonly Mark[],\n ) {\n const nodeType = typeof type === \"string\" ? this.nodes[type] : type;\n // y-prosemirror always passes `content` as a plain array of nodes; only\n // touch text children that carry marks.\n if (\n nodeType &&\n isPlainContentNodeType(this, nodeType) &&\n Array.isArray(content)\n ) {\n content = (content as readonly Node[]).map((child) =>\n child?.isText && child.marks.length\n ? child.mark(nodeType.allowedMarks(child.marks))\n : child,\n );\n }\n return originalNode.call(this, type, attrs, content, marks);\n } as typeof schema.node;\n });\n\n return {\n key: \"fixUpSchema\",\n } as const;\n});\n","import { defaultSelectionBuilder, yCursorPlugin } from \"y-prosemirror\";\nimport {\n createExtension,\n ExtensionOptions,\n} from \"../../editor/BlockNoteExtension.js\";\nimport type { CollaborationOptions } from \"./index.js\";\n\nexport type CollaborationUser = {\n id?: string;\n name: string;\n color: string;\n [key: string]: unknown;\n};\n\n/**\n * Determine whether the foreground color should be white or black based on a provided background color\n * Inspired by: https://stackoverflow.com/a/3943023\n */\nfunction isDarkColor(bgColor: string): boolean {\n const color = bgColor.charAt(0) === \"#\" ? bgColor.substring(1, 7) : bgColor;\n const r = parseInt(color.substring(0, 2), 16); // hexToR\n const g = parseInt(color.substring(2, 4), 16); // hexToG\n const b = parseInt(color.substring(4, 6), 16); // hexToB\n const uicolors = [r / 255, g / 255, b / 255];\n const c = uicolors.map((col) => {\n if (col <= 0.03928) {\n return col / 12.92;\n }\n return Math.pow((col + 0.055) / 1.055, 2.4);\n });\n const L = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];\n return L <= 0.179;\n}\n\nfunction defaultCursorRender(user: CollaborationUser) {\n const cursorElement = document.createElement(\"span\");\n\n cursorElement.classList.add(\"bn-collaboration-cursor__base\");\n\n const caretElement = document.createElement(\"span\");\n caretElement.setAttribute(\"contentedEditable\", \"false\");\n caretElement.classList.add(\"bn-collaboration-cursor__caret\");\n caretElement.setAttribute(\n \"style\",\n `background-color: ${user.color}; color: ${\n isDarkColor(user.color) ? \"white\" : \"black\"\n }`,\n );\n\n const labelElement = document.createElement(\"span\");\n\n labelElement.classList.add(\"bn-collaboration-cursor__label\");\n labelElement.setAttribute(\n \"style\",\n `background-color: ${user.color}; color: ${\n isDarkColor(user.color) ? \"white\" : \"black\"\n }`,\n );\n labelElement.insertBefore(document.createTextNode(user.name), null);\n\n caretElement.insertBefore(labelElement, null);\n\n cursorElement.insertBefore(document.createTextNode(\"\\u2060\"), null); // Non-breaking space\n cursorElement.insertBefore(caretElement, null);\n cursorElement.insertBefore(document.createTextNode(\"\\u2060\"), null); // Non-breaking space\n\n return cursorElement;\n}\n\nexport const YCursorExtension = createExtension(\n ({ options }: ExtensionOptions<CollaborationOptions>) => {\n const recentlyUpdatedCursors = new Map();\n const awareness =\n options.provider &&\n \"awareness\" in options.provider &&\n typeof options.provider.awareness === \"object\"\n ? options.provider.awareness\n : undefined;\n if (awareness) {\n if (\n \"setLocalStateField\" in awareness &&\n typeof awareness.setLocalStateField === \"function\"\n ) {\n awareness.setLocalStateField(\"user\", options.user);\n }\n }\n\n const handleAwarenessChange = ({\n updated,\n }: {\n added: Array<number>;\n updated: Array<number>;\n removed: Array<number>;\n }) => {\n for (const clientID of updated) {\n const cursor = recentlyUpdatedCursors.get(clientID);\n\n if (cursor) {\n setTimeout(() => {\n cursor.element.setAttribute(\"data-active\", \"\");\n }, 10);\n\n if (cursor.hideTimeout) {\n clearTimeout(cursor.hideTimeout);\n }\n\n recentlyUpdatedCursors.set(clientID, {\n element: cursor.element,\n hideTimeout: setTimeout(() => {\n cursor.element.removeAttribute(\"data-active\");\n }, 2000),\n });\n }\n }\n };\n\n return {\n key: \"yCursor\",\n mount() {\n if (\n awareness &&\n options.showCursorLabels !== \"always\" &&\n \"on\" in awareness &&\n typeof awareness.on === \"function\"\n ) {\n awareness.on(\"change\", handleAwarenessChange);\n\n return () => {\n if (\"off\" in awareness && typeof awareness.off === \"function\") {\n awareness.off(\"change\", handleAwarenessChange);\n }\n };\n }\n\n return undefined;\n },\n prosemirrorPlugins: [\n awareness\n ? yCursorPlugin(awareness, {\n selectionBuilder: defaultSelectionBuilder,\n cursorBuilder(user: CollaborationUser, clientID: number) {\n let cursorData = recentlyUpdatedCursors.get(clientID);\n\n if (!cursorData) {\n const cursorElement = (\n options.renderCursor ?? defaultCursorRender\n )(user);\n\n if (options.showCursorLabels !== \"always\") {\n cursorElement.addEventListener(\"mouseenter\", () => {\n const cursor = recentlyUpdatedCursors.get(clientID)!;\n cursor.element.setAttribute(\"data-active\", \"\");\n\n if (cursor.hideTimeout) {\n clearTimeout(cursor.hideTimeout);\n recentlyUpdatedCursors.set(clientID, {\n element: cursor.element,\n hideTimeout: undefined,\n });\n }\n });\n\n cursorElement.addEventListener(\"mouseleave\", () => {\n const cursor = recentlyUpdatedCursors.get(clientID)!;\n\n recentlyUpdatedCursors.set(clientID, {\n element: cursor.element,\n hideTimeout: setTimeout(() => {\n cursor.element.removeAttribute(\"data-active\");\n }, 2000),\n });\n });\n }\n\n cursorData = {\n element: cursorElement,\n hideTimeout: undefined,\n };\n\n recentlyUpdatedCursors.set(clientID, cursorData);\n }\n\n return cursorData.element;\n },\n })\n : undefined,\n ].filter(Boolean),\n dependsOn: [\"ySync\"],\n updateUser(user: { name: string; color: string; [key: string]: string }) {\n awareness?.setLocalStateField(\"user\", user);\n },\n getUser(): CollaborationUser | undefined {\n const state = awareness?.getLocalState();\n if (!state) {\n return undefined;\n }\n return state[\"user\"];\n },\n } as const;\n },\n);\n","import { ySyncPlugin } from \"y-prosemirror\";\nimport {\n ExtensionOptions,\n createExtension,\n} from \"../../editor/BlockNoteExtension.js\";\nimport type { CollaborationOptions } from \"./index.js\";\n\nexport const YSyncExtension = createExtension(\n ({ options }: ExtensionOptions<Pick<CollaborationOptions, \"fragment\">>) => {\n return {\n key: \"ySync\",\n prosemirrorPlugins: [ySyncPlugin(options.fragment)],\n runsBefore: [\"default\"],\n } as const;\n },\n);\n","import { redoCommand, undoCommand, yUndoPlugin } from \"y-prosemirror\";\nimport { createExtension } from \"../../editor/BlockNoteExtension.js\";\n\nexport const YUndoExtension = createExtension(() => {\n return {\n key: \"yUndo\",\n prosemirrorPlugins: [yUndoPlugin()],\n dependsOn: [\"yCursor\", \"ySync\"],\n undoCommand: undoCommand,\n redoCommand: redoCommand,\n } as const;\n});\n","import { yUndoPluginKey } from \"y-prosemirror\";\nimport * as Y from \"yjs\";\nimport {\n createExtension,\n createStore,\n ExtensionOptions,\n} from \"../../editor/BlockNoteExtension.js\";\nimport type { CollaborationOptions } from \"./index.js\";\nimport { YCursorExtension } from \"./YCursorPlugin.js\";\nimport { YSyncExtension } from \"./YSync.js\";\nimport { YUndoExtension } from \"./YUndo.js\";\nimport { findTypeInOtherYdoc } from \"../utils.js\";\n\nexport const ForkYDocExtension = createExtension(\n ({ editor, options }: ExtensionOptions<CollaborationOptions>) => {\n let forkedState:\n | {\n originalFragment: Y.XmlFragment;\n undoStack: Y.UndoManager[\"undoStack\"];\n forkedFragment: Y.XmlFragment;\n }\n | undefined = undefined;\n\n const store = createStore({ isForked: false });\n\n return {\n key: \"yForkDoc\",\n store,\n /**\n * Fork the Y.js document from syncing to the remote,\n * allowing modifications to the document without affecting the remote.\n * These changes can later be rolled back or applied to the remote.\n */\n fork({\n /**\n * The initial update to apply to the forked document.\n * If not provided, the current document state is used.\n */\n initialUpdate,\n }: {\n initialUpdate?: Uint8Array;\n } = {}) {\n if (forkedState) {\n return;\n }\n\n const originalFragment = options.fragment;\n\n if (!originalFragment) {\n throw new Error(\"No fragment to fork from\");\n }\n\n const doc = new Y.Doc();\n // Copy the original document (or apply the provided update) to a new Yjs document\n Y.applyUpdate(\n doc,\n initialUpdate ?? Y.encodeStateAsUpdate(originalFragment.doc!),\n );\n\n // Find the forked fragment in the new Yjs document\n const forkedFragment = findTypeInOtherYdoc(originalFragment, doc);\n\n forkedState = {\n undoStack: yUndoPluginKey.getState(editor.prosemirrorState)!\n .undoManager.undoStack,\n originalFragment,\n forkedFragment,\n };\n\n const newOptions = {\n ...options,\n fragment: forkedFragment,\n };\n\n // Atomically swap the yjs plugins to avoid re-entrant dispatch issues\n // where y-prosemirror's view hooks can dispatch a transaction between\n // separate unregister/register calls, re-introducing stale plugins.\n editor.replaceExtension(\n [\"ySync\", \"yCursor\", \"yUndo\"],\n [\n YSyncExtension(newOptions),\n // No need to register the cursor plugin again, it's a local fork\n YUndoExtension(),\n ],\n );\n\n // Tell the store that the editor is now forked\n store.setState({ isForked: true });\n },\n\n /**\n * Resume syncing the Y.js document to the remote\n * If `keepChanges` is true, any changes that have been made to the forked document will be applied to the original document.\n * Otherwise, the original document will be restored and the changes will be discarded.\n */\n merge({ keepChanges }: { keepChanges: boolean }) {\n if (!forkedState) {\n return;\n }\n\n const { originalFragment, forkedFragment, undoStack } = forkedState;\n\n // Atomically swap the forked plugins back to the original ones\n editor.replaceExtension(\n [\"ySync\", \"yCursor\", \"yUndo\"],\n [\n YSyncExtension(options),\n YCursorExtension(options),\n YUndoExtension(),\n ],\n );\n\n // Reset the undo stack to the original undo stack\n yUndoPluginKey.getState(\n editor.prosemirrorState,\n )!.undoManager.undoStack = undoStack;\n\n if (keepChanges) {\n // Apply any changes that have been made to the fork, onto the original doc\n const update = Y.encodeStateAsUpdate(\n forkedFragment.doc!,\n Y.encodeStateVector(originalFragment.doc!),\n );\n // Applying this change will add to the undo stack, allowing it to be undone normally\n Y.applyUpdate(originalFragment.doc!, update, editor);\n }\n // Reset the forked state\n forkedState = undefined;\n // Tell the store that the editor is no longer forked\n store.setState({ isForked: false });\n },\n } as const;\n },\n);\n","import {\n absolutePositionToRelativePosition,\n relativePositionToAbsolutePosition,\n ySyncPluginKey,\n} from \"y-prosemirror\";\nimport { createExtension } from \"../../editor/BlockNoteExtension.js\";\nimport type { PositionMappingExtension } from \"../../extensions/index.js\";\n\nexport const RelativePositionMappingExtension = createExtension(\n ({ editor }) => {\n return {\n key: \"yPositionMapping\",\n mapPosition: (position: number, side: \"left\" | \"right\" = \"left\") => {\n const ySyncPluginState = ySyncPluginKey.getState(\n editor.prosemirrorState,\n );\n if (!ySyncPluginState) {\n throw new Error(\"YSync plugin state not found\");\n }\n\n // 0 is a special case & always should map to itself\n if (position === 0) {\n return () => 0;\n }\n\n // If the document is empty, it has not been synced yet\n if (ySyncPluginState.binding.type.length === 0) {\n // so, we just fallback to the prosemirror position mapping extension\n // If a remote transaction or sync happens in this case. The position map will be invalidated,\n // and the positions will be moved to the end of the document\n // This is acceptable, because the document had not been synced so there are no positions to map properly into\n const fallback =\n editor.getExtension<typeof PositionMappingExtension>(\n \"positionMapping\",\n );\n if (!fallback) {\n throw new Error(\n \"positionMapping extension is not available; cannot map position before sync\",\n );\n }\n return fallback.mapPosition(position, side);\n }\n\n const relativePosition = absolutePositionToRelativePosition(\n position + (side === \"right\" ? 1 : -1),\n ySyncPluginState.binding.type,\n ySyncPluginState.binding.mapping,\n );\n\n return () => {\n const curYSyncPluginState = ySyncPluginKey.getState(\n editor.prosemirrorState,\n ) as typeof ySyncPluginState;\n const pos = relativePositionToAbsolutePosition(\n curYSyncPluginState.doc,\n curYSyncPluginState.binding.type,\n relativePosition,\n curYSyncPluginState.binding.mapping,\n );\n\n // This can happen if the element is garbage collected\n if (pos === null) {\n throw new Error(\"Position not found, cannot track positions\");\n }\n\n return pos + (side === \"right\" ? -1 : 1);\n };\n },\n } as const;\n },\n);\n","import * as Y from \"yjs\";\n\nimport { MigrationRule } from \"./migrationRule.js\";\nimport { defaultProps } from \"../../../../blocks/defaultProps.js\";\n\n// Helper function to recursively traverse a `Y.XMLElement` and its descendant\n// elements.\nconst traverseElement = (\n rootElement: Y.XmlElement,\n cb: (element: Y.XmlElement) => void,\n) => {\n cb(rootElement);\n rootElement.forEach((element) => {\n if (element instanceof Y.XmlElement) {\n traverseElement(element, cb);\n }\n });\n};\n\n// Moves `textColor` and `backgroundColor` attributes from `blockContainer`\n// nodes to their child `blockContent` nodes. This is due to a schema change\n// introduced in PR #TODO.\nexport const moveColorAttributes: MigrationRule = (fragment, tr) => {\n // Stores necessary info for all `blockContainer` nodes which still have\n // `textColor` or `backgroundColor` attributes that need to be moved.\n const targetBlockContainers: Map<\n string,\n {\n textColor: string | undefined;\n backgroundColor: string | undefined;\n }\n > = new Map();\n // Finds all elements which still have `textColor` or `backgroundColor`\n // attributes in the current Yjs fragment.\n fragment.forEach((element) => {\n if (element instanceof Y.XmlElement) {\n traverseElement(element, (element) => {\n if (\n element.nodeName === \"blockContainer\" &&\n element.hasAttribute(\"id\")\n ) {\n const textColor = element.getAttribute(\"textColor\");\n const backgroundColor = element.getAttribute(\"backgroundColor\");\n\n const colors = {\n textColor:\n textColor === defaultProps.textColor.default\n ? undefined\n : textColor,\n backgroundColor:\n backgroundColor === defaultProps.backgroundColor.default\n ? undefined\n : backgroundColor,\n };\n\n if (colors.textColor || colors.backgroundColor) {\n targetBlockContainers.set(element.getAttribute(\"id\")!, colors);\n }\n }\n });\n }\n });\n\n if (targetBlockContainers.size === 0) {\n return false;\n }\n\n // Appends transactions to add the `textColor` and `backgroundColor`\n // attributes found on each `blockContainer` node to move them to the child\n // `blockContent` node.\n tr.doc.descendants((node, pos) => {\n if (\n node.type.name === \"blockContainer\" &&\n targetBlockContainers.has(node.attrs.id)\n ) {\n const el = tr.doc.nodeAt(pos + 1);\n if (!el) {\n throw new Error(\"No element found\");\n }\n\n tr.setNodeMarkup(pos + 1, undefined, {\n // preserve existing attributes\n ...el.attrs,\n // add the textColor and backgroundColor attributes\n ...targetBlockContainers.get(node.attrs.id),\n });\n }\n });\n\n return true;\n};\n","import { MigrationRule } from \"./migrationRule.js\";\nimport { moveColorAttributes } from \"./moveColorAttributes.js\";\n\nexport default [moveColorAttributes] as MigrationRule[];\n","import { Plugin, PluginKey } from \"@tiptap/pm/state\";\nimport * as Y from \"yjs\";\n\nimport {\n createExtension,\n ExtensionOptions,\n} from \"../../../editor/BlockNoteExtension.js\";\nimport migrationRules from \"./migrationRules/index.js\";\n\n// This plugin allows us to update collaboration YDocs whenever BlockNote's\n// underlying ProseMirror schema changes. The plugin reads the current Yjs\n// fragment and dispatches additional transactions to the ProseMirror state, in\n// case things are found in the fragment that don't adhere to the editor schema\n// and need to be fixed. These fixes are defined as `MigrationRule`s within the\n// `migrationRules` directory.\nexport const SchemaMigration = createExtension(\n ({ options }: ExtensionOptions<{ fragment: Y.XmlFragment }>) => {\n let migrationDone = false;\n const pluginKey = new PluginKey(\"schemaMigration\");\n\n return {\n key: \"schemaMigration\",\n prosemirrorPlugins: [\n new Plugin({\n key: pluginKey,\n appendTransaction: (transactions, _oldState, newState) => {\n if (migrationDone) {\n return undefined;\n }\n\n if (\n // If any of the transactions are not due to a yjs sync, we don't need to run the migration\n !transactions.some((tr) => tr.getMeta(\"y-sync$\")) ||\n // If none of the transactions result in a document change, we don't need to run the migration\n transactions.every((tr) => !tr.docChanged) ||\n // If the fragment is still empty, we can't run the migration (since it has not yet been applied to the Y.Doc)\n !options.fragment.firstChild\n ) {\n return undefined;\n }\n\n const tr = newState.tr;\n for (const migrationRule of migrationRules) {\n migrationRule(options.fragment, tr);\n }\n\n migrationDone = true;\n\n if (!tr.docChanged) {\n return undefined;\n }\n\n return tr;\n },\n }),\n ],\n } as const;\n },\n);\n","import * as Y from \"yjs\";\n\nimport type { BlockNoteEditor } from \"../../editor/BlockNoteEditor.js\";\nimport type { PreviewController } from \"../../extensions/Versioning/index.js\";\nimport type { CollaborationOptions } from \"./index.js\";\nimport { ForkYDocExtension } from \"./ForkYDoc.js\";\n\n/**\n * Creates a Yjs v13 adapter that provides the {@link PreviewController}\n * and `getCurrentDocument` callback required by the base\n * {@link VersioningExtension}.\n *\n * Delegates to the {@link ForkYDocExtension} for entering/exiting preview:\n * - **enterPreview**: calls `fork({ initialUpdate: snapshotContent })` to\n * switch the editor to a temporary doc built from the snapshot.\n * - **exitPreview**: calls `merge({ keepChanges: false })` to discard the\n * preview and restore the live document.\n * - **applyRestore**: calls `merge({ keepChanges: true })` to apply the\n * snapshot content back to the live document.\n */\nexport function createYjsVersioningAdapter(\n /** The BlockNote editor instance (must have ForkYDocExtension). */\n editor: BlockNoteEditor<any, any, any>,\n /** The full collaboration options (used for `fragment` access). */\n options: CollaborationOptions,\n): {\n preview: PreviewController<Uint8Array>;\n getCurrentDocument: () => Y.XmlFragment;\n serializeCurrentContent: () => Uint8Array;\n} {\n const { fragment } = options;\n\n function getForkYDoc() {\n const ext = editor.getExtension(ForkYDocExtension);\n if (!ext) {\n throw new Error(\n \"ForkYDocExtension is required for the Yjs versioning adapter. \" +\n \"Make sure it is registered before the VersioningExtension.\",\n );\n }\n return ext;\n }\n\n return {\n getCurrentDocument: () => fragment,\n serializeCurrentContent: () => Y.encodeStateAsUpdateV2(fragment.doc!),\n preview: {\n // Yjs v13 can only fork the document to a single snapshot; it has no way\n // to diff two versions, so comparison is unsupported.\n supportsComparison: false,\n enterPreview(\n snapshotContent: Uint8Array,\n _compareToContent?: Uint8Array,\n ) {\n const forkYDoc = getForkYDoc();\n\n // If already in a preview (forked state), exit first.\n if (forkYDoc.store.state.isForked) {\n forkYDoc.merge({ keepChanges: false });\n }\n\n forkYDoc.fork({ initialUpdate: snapshotContent });\n },\n\n exitPreview() {\n const forkYDoc = getForkYDoc();\n if (forkYDoc.store.state.isForked) {\n forkYDoc.merge({ keepChanges: false });\n }\n },\n\n applyRestore(_snapshotContent: Uint8Array) {\n // Restoring to an older Yjs state cannot be done by merging a fork\n // because the original doc already contains all CRDT state vectors\n // from the snapshot. Restore must be handled at the endpoint/server\n // level (e.g., the server creates a new Y.Doc and syncs it).\n throw new Error(\n \"Restore is not yet implemented for Yjs v13 versioning adapter.\",\n );\n },\n },\n };\n}\n","import type { Awareness } from \"y-protocols/awareness\";\nimport type * as Y from \"yjs\";\nimport type { BlockNoteEditorOptions } from \"../../editor/BlockNoteEditor\";\nimport {\n createExtension,\n type ExtensionOptions,\n} from \"../../editor/BlockNoteExtension.js\";\nimport { FixUpSchemaExtension } from \"./FixUpSchema.js\";\nimport { ForkYDocExtension } from \"./ForkYDoc.js\";\nimport { RelativePositionMappingExtension } from \"./RelativePositionMapping.js\";\nimport { SchemaMigration } from \"./schemaMigration/SchemaMigration.js\";\nimport { CollaborationUser, YCursorExtension } from \"./YCursorPlugin.js\";\nimport { YSyncExtension } from \"./YSync.js\";\nimport { YUndoExtension } from \"./YUndo.js\";\n\nexport type CollaborationOptions = {\n /**\n * The Yjs XML fragment that's used for collaboration.\n */\n fragment: Y.XmlFragment;\n /**\n * The user info for the current user that's shown to other collaborators.\n */\n user: CollaborationUser;\n /**\n * A Yjs provider (used for awareness / cursor information)\n */\n provider?: { awareness?: Awareness };\n /**\n * Optional function to customize how cursors of users are rendered\n */\n renderCursor?: (user: CollaborationUser) => HTMLElement;\n /**\n * Optional flag to set when the user label should be shown with the default\n * collaboration cursor. Setting to \"always\" will always show the label,\n * while \"activity\" will only show the label when the user moves the cursor\n * or types. Defaults to \"activity\".\n */\n showCursorLabels?: \"always\" | \"activity\";\n};\n\nexport const CollaborationExtension = createExtension(\n ({ options }: ExtensionOptions<CollaborationOptions>) => {\n return {\n key: \"collaboration\",\n blockNoteExtensions: [\n FixUpSchemaExtension(),\n ForkYDocExtension(options),\n RelativePositionMappingExtension(),\n SchemaMigration(options),\n YCursorExtension(options),\n YSyncExtension(options),\n YUndoExtension(),\n ],\n } as const;\n },\n);\n\nexport function withCollaboration<\n Options extends Partial<BlockNoteEditorOptions<any, any, any>>,\n>(\n options: Options & {\n /**\n * Options for configuring the collaboration functionality.\n */\n collaboration: CollaborationOptions;\n },\n): Options {\n return {\n ...options,\n extensions: [\n ...(options.extensions ?? []),\n CollaborationExtension(options.collaboration),\n ],\n // We disable the default prosemirror history plugin, since it's not compatible with yjs\n disableExtensions: [\"history\", ...(options.disableExtensions ?? [])],\n // We don't want the default initial content, since it will generate a random id for the initial block on each client,\n // leading to conflicts when syncing happens afterwards.\n initialContent: [{ type: \"paragraph\", id: \"initialBlockId\" }],\n };\n}\n\nexport * from \"./ForkYDoc.js\";\nexport * from \"./RelativePositionMapping.js\";\nexport * from \"./schemaMigration/SchemaMigration.js\";\nexport * from \"./Versioning.js\";\nexport * from \"./YCursorPlugin.js\";\nexport * from \"./YSync.js\";\nexport * from \"./YUndo.js\";\n","import * as Y from \"yjs\";\nimport type {\n CommentData,\n CommentReactionData,\n ThreadData,\n} from \"../../comments/types.js\";\n\nexport function commentToYMap(comment: CommentData) {\n const yMap = new Y.Map<any>();\n yMap.set(\"id\", comment.id);\n yMap.set(\"userId\", comment.userId);\n yMap.set(\"createdAt\", comment.createdAt.getTime());\n yMap.set(\"updatedAt\", comment.updatedAt.getTime());\n if (comment.deletedAt) {\n yMap.set(\"deletedAt\", comment.deletedAt.getTime());\n yMap.set(\"body\", undefined);\n } else {\n yMap.set(\"body\", comment.body);\n }\n if (comment.reactions.length > 0) {\n throw new Error(\"Reactions should be empty in commentToYMap\");\n }\n\n /**\n * Reactions are stored in a map keyed by {userId-emoji},\n * this makes it easy to add / remove reactions and in a way that works local-first.\n * The cost is that \"reading\" the reactions is a bit more complex (see yMapToReactions).\n */\n yMap.set(\"reactionsByUser\", new Y.Map());\n yMap.set(\"metadata\", comment.metadata);\n\n return yMap;\n}\n\nexport function threadToYMap(thread: ThreadData) {\n const yMap = new Y.Map();\n yMap.set(\"id\", thread.id);\n yMap.set(\"createdAt\", thread.createdAt.getTime());\n yMap.set(\"updatedAt\", thread.updatedAt.getTime());\n const commentsArray = new Y.Array<Y.Map<any>>();\n\n commentsArray.push(thread.comments.map((comment) => commentToYMap(comment)));\n\n yMap.set(\"comments\", commentsArray);\n yMap.set(\"resolved\", thread.resolved);\n yMap.set(\"resolvedUpdatedAt\", thread.resolvedUpdatedAt?.getTime());\n yMap.set(\"resolvedBy\", thread.resolvedBy);\n yMap.set(\"metadata\", thread.metadata);\n return yMap;\n}\n\ntype SingleUserCommentReactionData = {\n emoji: string;\n createdAt: Date;\n userId: string;\n};\n\nexport function yMapToReaction(\n yMap: Y.Map<any>,\n): SingleUserCommentReactionData {\n return {\n emoji: yMap.get(\"emoji\"),\n createdAt: new Date(yMap.get(\"createdAt\")),\n userId: yMap.get(\"userId\"),\n };\n}\n\nfunction yMapToReactions(yMap: Y.Map<any>): CommentReactionData[] {\n const flatReactions = [...yMap.values()].map((reaction: Y.Map<any>) =>\n yMapToReaction(reaction),\n );\n // combine reactions by the same emoji\n return flatReactions.reduce(\n (acc: CommentReactionData[], reaction: SingleUserCommentReactionData) => {\n const existingReaction = acc.find((r) => r.emoji === reaction.emoji);\n if (existingReaction) {\n existingReaction.userIds.push(reaction.userId);\n existingReaction.createdAt = new Date(\n Math.min(\n existingReaction.createdAt.getTime(),\n reaction.createdAt.getTime(),\n ),\n );\n } else {\n acc.push({\n emoji: reaction.emoji,\n createdAt: reaction.createdAt,\n userIds: [reaction.userId],\n });\n }\n return acc;\n },\n [] as CommentReactionData[],\n );\n}\n\nexport function yMapToComment(yMap: Y.Map<any>): CommentData {\n return {\n type: \"comment\",\n id: yMap.get(\"id\"),\n userId: yMap.get(\"userId\"),\n createdAt: new Date(yMap.get(\"createdAt\")),\n updatedAt: new Date(yMap.get(\"updatedAt\")),\n deletedAt: yMap.get(\"deletedAt\")\n ? new Date(yMap.get(\"deletedAt\"))\n : undefined,\n reactions: yMapToReactions(yMap.get(\"reactionsByUser\")),\n metadata: yMap.get(\"metadata\"),\n body: yMap.get(\"body\"),\n };\n}\n\nexport function yMapToThread(yMap: Y.Map<any>): ThreadData {\n return {\n type: \"thread\",\n id: yMap.get(\"id\"),\n createdAt: new Date(yMap.get(\"createdAt\")),\n updatedAt: new Date(yMap.get(\"updatedAt\")),\n comments: ((yMap.get(\"comments\") as Y.Array<Y.Map<any>>) || []).map(\n (comment) => yMapToComment(comment),\n ),\n resolved: yMap.get(\"resolved\"),\n resolvedUpdatedAt: new Date(yMap.get(\"resolvedUpdatedAt\")),\n resolvedBy: yMap.get(\"resolvedBy\"),\n metadata: yMap.get(\"metadata\"),\n };\n}\n","import * as Y from \"yjs\";\nimport type { ThreadData } from \"../../comments/types.js\";\nimport { ThreadStore } from \"../../comments/threadstore/ThreadStore.js\";\nimport type { ThreadStoreAuth } from \"../../comments/threadstore/ThreadStoreAuth.js\";\nimport { yMapToThread } from \"./yjsHelpers.js\";\n\n/**\n * This is an abstract class that only implements the READ methods required by the ThreadStore interface.\n * The data is read from a Yjs Map.\n */\nexport abstract class YjsThreadStoreBase extends ThreadStore {\n constructor(\n protected readonly threadsYMap: Y.Map<any>,\n auth: ThreadStoreAuth,\n ) {\n super(auth);\n }\n\n // TODO: async / reactive interface?\n public getThread(threadId: string) {\n const yThread = this.threadsYMap.get(threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n const thread = yMapToThread(yThread);\n return thread;\n }\n\n public getThreads(): Map<string, ThreadData> {\n const threadMap = new Map<string, ThreadData>();\n this.threadsYMap.forEach((yThread, id) => {\n if (yThread instanceof Y.Map) {\n threadMap.set(id, yMapToThread(yThread));\n }\n });\n return threadMap;\n }\n\n public subscribe(cb: (threads: Map<string, ThreadData>) => void) {\n const observer = () => {\n cb(this.getThreads());\n };\n\n this.threadsYMap.observeDeep(observer);\n\n return () => {\n this.threadsYMap.unobserveDeep(observer);\n };\n }\n}\n","import * as Y from \"yjs\";\nimport {\n absolutePositionToRelativePosition,\n ySyncPluginKey,\n} from \"y-prosemirror\";\nimport type { CommentBody } from \"../../comments/types.js\";\nimport type { ThreadStoreAuth } from \"../../comments/threadstore/ThreadStoreAuth.js\";\nimport { YjsThreadStoreBase } from \"./YjsThreadStoreBase.js\";\nimport { BlockNoteEditor } from \"../../editor/BlockNoteEditor.js\";\n\n/**\n * This is a REST-based implementation of the YjsThreadStoreBase.\n * It Reads data directly from the underlying document (same as YjsThreadStore),\n * but for Writes, it sends data to a REST API that should:\n * - check the user has the correct permissions to make the desired changes\n * - apply the updates to the underlying Yjs document\n *\n * (see https://github.com/TypeCellOS/BlockNote-demo-nextjs-hocuspocus)\n *\n * The reason we still use the Yjs document as underlying storage is that it makes it easy to\n * sync updates in real-time to other collaborators.\n * (but technically, you could also implement a different storage altogether\n * and not store the thread related data in the Yjs document)\n */\nexport class RESTYjsThreadStore extends YjsThreadStoreBase {\n constructor(\n private readonly BASE_URL: string,\n private readonly headers: Record<string, string>,\n threadsYMap: Y.Map<any>,\n auth: ThreadStoreAuth,\n ) {\n super(threadsYMap, auth);\n }\n\n private doRequest = async (path: string, method: string, body?: any) => {\n const response = await fetch(`${this.BASE_URL}${path}`, {\n method,\n body: JSON.stringify(body),\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.headers,\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to ${method} ${path}: ${response.statusText}`);\n }\n\n return response.json();\n };\n\n public addThreadToDocument = async (options: {\n threadId: string;\n selection: {\n head: number;\n anchor: number;\n };\n editor: BlockNoteEditor<any, any, any>;\n }) => {\n const { threadId, selection } = options;\n\n const binding = ySyncPluginKey.getState(options.editor.prosemirrorState);\n const yjsSelection = binding\n ? {\n head: absolutePositionToRelativePosition(\n selection.head,\n binding.type,\n binding.mapping,\n ),\n anchor: absolutePositionToRelativePosition(\n selection.anchor,\n binding.type,\n binding.mapping,\n ),\n }\n : undefined;\n\n return this.doRequest(`/${threadId}/addToDocument`, \"POST\", {\n selection: {\n prosemirror: selection,\n yjs: yjsSelection,\n },\n });\n };\n\n public createThread = async (options: {\n initialComment: {\n body: CommentBody;\n metadata?: any;\n };\n metadata?: any;\n }) => {\n return this.doRequest(\"\", \"POST\", options);\n };\n\n public addComment = (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n }) => {\n const { threadId, ...rest } = options;\n return this.doRequest(`/${threadId}/comments`, \"POST\", rest);\n };\n\n public updateComment = (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n commentId: string;\n }) => {\n const { threadId, commentId, ...rest } = options;\n return this.doRequest(`/${threadId}/comments/${commentId}`, \"PUT\", rest);\n };\n\n public deleteComment = (options: {\n threadId: string;\n commentId: string;\n softDelete?: boolean;\n }) => {\n const { threadId, commentId, ...rest } = options;\n return this.doRequest(\n `/${threadId}/comments/${commentId}?soft=${!!rest.softDelete}`,\n \"DELETE\",\n );\n };\n\n public deleteThread = (options: { threadId: string }) => {\n return this.doRequest(`/${options.threadId}`, \"DELETE\");\n };\n\n public resolveThread = (options: { threadId: string }) => {\n return this.doRequest(`/${options.threadId}/resolve`, \"POST\");\n };\n\n public unresolveThread = (options: { threadId: string }) => {\n return this.doRequest(`/${options.threadId}/unresolve`, \"POST\");\n };\n\n public addReaction = (options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }) => {\n const { threadId, commentId, ...rest } = options;\n return this.doRequest(\n `/${threadId}/comments/${commentId}/reactions`,\n \"POST\",\n rest,\n );\n };\n\n public deleteReaction = (options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }) => {\n return this.doRequest(\n `/${options.threadId}/comments/${options.commentId}/reactions/${options.emoji}`,\n \"DELETE\",\n );\n };\n}\n","import * as Y from \"yjs\";\nimport { uuidv4 } from \"lib0/random\";\nimport type {\n CommentBody,\n CommentData,\n ThreadData,\n} from \"../../comments/types.js\";\nimport type { ThreadStoreAuth } from \"../../comments/threadstore/ThreadStoreAuth.js\";\nimport { YjsThreadStoreBase } from \"./YjsThreadStoreBase.js\";\nimport {\n commentToYMap,\n threadToYMap,\n yMapToComment,\n yMapToThread,\n} from \"./yjsHelpers.js\";\n\n/**\n * This is a Yjs-based implementation of the ThreadStore interface.\n *\n * It reads and writes thread / comments information directly to the underlying Yjs Document.\n *\n * @important While this is the easiest to add to your app, there are two challenges:\n * - The user needs to be able to write to the Yjs document to store the information.\n * So a user without write access to the Yjs document cannot leave any comments.\n * - Even with write access, the operations are not secure. Unless your Yjs server\n * guards against malicious operations, it's technically possible for one user to make changes to another user's comments, etc.\n * (even though these options are not visible in the UI, a malicious user can make unauthorized changes to the underlying Yjs document)\n */\nexport class YjsThreadStore extends YjsThreadStoreBase {\n constructor(\n private readonly userId: string,\n threadsYMap: Y.Map<any>,\n auth: ThreadStoreAuth,\n ) {\n super(threadsYMap, auth);\n }\n\n private transact = <T, R>(\n fn: (options: T) => R,\n ): ((options: T) => Promise<R>) => {\n return async (options: T) => {\n return this.threadsYMap.doc!.transact(() => {\n return fn(options);\n });\n };\n };\n\n public createThread = this.transact(\n (options: {\n initialComment: {\n body: CommentBody;\n metadata?: any;\n };\n metadata?: any;\n }) => {\n if (!this.auth.canCreateThread()) {\n throw new Error(\"Not authorized\");\n }\n\n const date = new Date();\n\n const comment: CommentData = {\n type: \"comment\",\n id: uuidv4(),\n userId: this.userId,\n createdAt: date,\n updatedAt: date,\n reactions: [],\n metadata: options.initialComment.metadata,\n body: options.initialComment.body,\n };\n\n const thread: ThreadData = {\n type: \"thread\",\n id: uuidv4(),\n createdAt: date,\n updatedAt: date,\n comments: [comment],\n resolved: false,\n metadata: options.metadata,\n };\n\n this.threadsYMap.set(thread.id, threadToYMap(thread));\n\n return thread;\n },\n );\n\n // YjsThreadStore does not support addThreadToDocument\n public addThreadToDocument = undefined;\n\n public addComment = this.transact(\n (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n if (!this.auth.canAddComment(yMapToThread(yThread))) {\n throw new Error(\"Not authorized\");\n }\n\n const date = new Date();\n const comment: CommentData = {\n type: \"comment\",\n id: uuidv4(),\n userId: this.userId,\n createdAt: date,\n updatedAt: date,\n deletedAt: undefined,\n reactions: [],\n metadata: options.comment.metadata,\n body: options.comment.body,\n };\n\n (yThread.get(\"comments\") as Y.Array<Y.Map<any>>).push([\n commentToYMap(comment),\n ]);\n\n yThread.set(\"updatedAt\", new Date().getTime());\n return comment;\n },\n );\n\n public updateComment = this.transact(\n (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n commentId: string;\n }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (!this.auth.canUpdateComment(yMapToComment(yComment))) {\n throw new Error(\"Not authorized\");\n }\n\n yComment.set(\"body\", options.comment.body);\n yComment.set(\"updatedAt\", new Date().getTime());\n yComment.set(\"metadata\", options.comment.metadata);\n },\n );\n\n public deleteComment = this.transact(\n (options: {\n threadId: string;\n commentId: string;\n softDelete?: boolean;\n }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (!this.auth.canDeleteComment(yMapToComment(yComment))) {\n throw new Error(\"Not authorized\");\n }\n\n if (yComment.get(\"deletedAt\")) {\n throw new Error(\"Comment already deleted\");\n }\n\n if (options.softDelete) {\n yComment.set(\"deletedAt\", new Date().getTime());\n yComment.set(\"body\", undefined);\n } else {\n yThread.get(\"comments\").delete(yCommentIndex);\n }\n\n if (\n (yThread.get(\"comments\") as Y.Array<any>)\n .toArray()\n .every((comment) => comment.get(\"deletedAt\"))\n ) {\n // all comments deleted\n if (options.softDelete) {\n yThread.set(\"deletedAt\", new Date().getTime());\n } else {\n this.threadsYMap.delete(options.threadId);\n }\n }\n\n yThread.set(\"updatedAt\", new Date().getTime());\n },\n );\n\n public deleteThread = this.transact((options: { threadId: string }) => {\n if (\n !this.auth.canDeleteThread(\n yMapToThread(this.threadsYMap.get(options.threadId)),\n )\n ) {\n throw new Error(\"Not authorized\");\n }\n\n this.threadsYMap.delete(options.threadId);\n });\n\n public resolveThread = this.transact((options: { threadId: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n if (!this.auth.canResolveThread(yMapToThread(yThread))) {\n throw new Error(\"Not authorized\");\n }\n\n yThread.set(\"resolved\", true);\n yThread.set(\"resolvedUpdatedAt\", new Date().getTime());\n yThread.set(\"resolvedBy\", this.userId);\n });\n\n public unresolveThread = this.transact((options: { threadId: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n if (!this.auth.canUnresolveThread(yMapToThread(yThread))) {\n throw new Error(\"Not authorized\");\n }\n\n yThread.set(\"resolved\", false);\n yThread.set(\"resolvedUpdatedAt\", new Date().getTime());\n });\n\n public addReaction = this.transact(\n (options: { threadId: string; commentId: string; emoji: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (!this.auth.canAddReaction(yMapToComment(yComment), options.emoji)) {\n throw new Error(\"Not authorized\");\n }\n\n const date = new Date();\n\n const key = `${this.userId}-${options.emoji}`;\n\n const reactionsByUser = yComment.get(\"reactionsByUser\");\n\n if (reactionsByUser.has(key)) {\n // already exists\n return;\n } else {\n const reaction = new Y.Map();\n reaction.set(\"emoji\", options.emoji);\n reaction.set(\"createdAt\", date.getTime());\n reaction.set(\"userId\", this.userId);\n reactionsByUser.set(key, reaction);\n }\n },\n );\n\n public deleteReaction = this.transact(\n (options: { threadId: string; commentId: string; emoji: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (\n !this.auth.canDeleteReaction(yMapToComment(yComment), options.emoji)\n ) {\n throw new Error(\"Not authorized\");\n }\n\n const key = `${this.userId}-${options.emoji}`;\n\n const reactionsByUser = yComment.get(\"reactionsByUser\");\n\n reactionsByUser.delete(key);\n },\n );\n}\n\nfunction yArrayFindIndex(\n yArray: Y.Array<any>,\n predicate: (item: any) => boolean,\n) {\n for (let i = 0; i < yArray.length; i++) {\n if (predicate(yArray.get(i))) {\n return i;\n }\n }\n return -1;\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,E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EAAQ,KAAK,GAClE,MAAU,MAAM,gBAAgB;EAGlC,IAAM,oBAAO,IAAI,KAAK,GAEhB,IAAM,GAAG,KAAK,OAAO,GAAG,EAAQ,SAEhC,IAAkB,EAAS,IAAI,iBAAiB;EAElD,OAAgB,IAAI,CAAG,GAGpB;GACL,IAAM,IAAW,IAAI,EAAE,IAAI;GAI3B,AAHA,EAAS,IAAI,SAAS,EAAQ,KAAK,GACnC,EAAS,IAAI,aAAa,EAAK,QAAQ,CAAC,GACxC,EAAS,IAAI,UAAU,KAAK,MAAM,GAClC,EAAgB,IAAI,GAAK,CAAQ;EACnC;CACF,CACF;CAEA,iBAAwB,KAAK,UAC1B,MAAoE;EACnE,IAAM,IAAU,KAAK,YAAY,IAAI,EAAQ,QAAQ;EACrD,IAAI,CAAC,GACH,MAAU,MAAM,kBAAkB;EAGpC,IAAM,IAAgB,EACpB,EAAQ,IAAI,UAAU,IACrB,MAAY,EAAQ,IAAI,IAAI,MAAM,EAAQ,SAC7C;EAEA,IAAI,MAAkB,IACpB,MAAU,MAAM,mBAAmB;EAGrC,IAAM,IAAW,EAAQ,IAAI,UAAU,EAAE,IAAI,CAAa;EAE1D,IACE,CAAC,KAAK,KAAK,kBAAkB,EAAc,CAAQ,GAAG,EAAQ,KAAK,GAEnE,MAAU,MAAM,gBAAgB;EAGlC,IAAM,IAAM,GAAG,KAAK,OAAO,GAAG,EAAQ;EAItC,EAFiC,IAAI,iBAErC,EAAgB,OAAO,CAAG;CAC5B,CACF;AACF;AAEA,SAAS,EACP,GACA,GACA;CACA,KAAK,IAAI,IAAI,GAAG,IAAI,EAAO,QAAQ,KACjC,IAAI,EAAU,EAAO,IAAI,CAAC,CAAC,GACzB,OAAO;CAGX,OAAO;AACT"}
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "directory": "packages/core"
12
12
  },
13
13
  "license": "MPL-2.0",
14
- "version": "0.51.3",
14
+ "version": "0.52.0",
15
15
  "files": [
16
16
  "dist",
17
17
  "types",
@@ -76,6 +76,11 @@
76
76
  "types": "./types/src/yjs/index.d.ts",
77
77
  "import": "./dist/yjs.js",
78
78
  "require": "./dist/yjs.cjs"
79
+ },
80
+ "./y": {
81
+ "types": "./types/src/y/index.d.ts",
82
+ "import": "./dist/y.js",
83
+ "require": "./dist/y.cjs"
79
84
  }
80
85
  },
81
86
  "dependencies": {
@@ -86,9 +91,7 @@
86
91
  "@tiptap/core": "^3.13.0",
87
92
  "@tiptap/extension-bold": "^3.13.0",
88
93
  "@tiptap/extension-code": "^3.13.0",
89
- "@tiptap/extension-horizontal-rule": "^3.13.0",
90
94
  "@tiptap/extension-italic": "^3.13.0",
91
- "@tiptap/extension-paragraph": "^3.13.0",
92
95
  "@tiptap/extension-strike": "^3.13.0",
93
96
  "@tiptap/extension-text": "^3.13.0",
94
97
  "@tiptap/extension-underline": "^3.13.0",
@@ -96,26 +99,51 @@
96
99
  "@tiptap/pm": "^3.13.0",
97
100
  "emoji-mart": "^5.6.0",
98
101
  "fast-deep-equal": "^3.1.3",
99
- "lib0": "^0.2.99",
102
+ "lib0": "1.0.0-rc.22",
100
103
  "prosemirror-highlight": "^0.15.1",
101
104
  "prosemirror-model": "^1.25.4",
102
105
  "prosemirror-state": "^1.4.4",
103
106
  "prosemirror-tables": "^1.8.3",
104
107
  "prosemirror-transform": "^1.11.0",
105
- "prosemirror-view": "^1.41.4",
106
- "y-prosemirror": "^1.3.7",
107
- "y-protocols": "^1.0.6",
108
- "yjs": "^13.6.27"
108
+ "prosemirror-view": "^1.41.4"
109
109
  },
110
110
  "devDependencies": {
111
- "eslint": "^8.57.1",
112
111
  "jsdom": "^29.0.2",
113
112
  "rimraf": "^5.0.10",
114
113
  "rollup-plugin-webpack-stats": "^0.2.6",
115
114
  "typescript": "^5.9.3",
116
- "vite": "^8.0.8",
117
- "vite-plugin-eslint": "^1.8.1",
118
- "vitest": "^4.1.2"
115
+ "vite-plus": "^0.1.24",
116
+ "y-prosemirror": "^1.3.7",
117
+ "y-protocols": "^1.0.6",
118
+ "yjs": "^13.6.27"
119
+ },
120
+ "peerDependencies": {
121
+ "y-prosemirror": "^1.3.7",
122
+ "y-protocols": "^1.0.6",
123
+ "yjs": "^13.6.27",
124
+ "@y/y": "^14.0.0-rc.23",
125
+ "@y/prosemirror": "^2.0.0-6",
126
+ "@y/protocols": "^1.0.6-rc.1"
127
+ },
128
+ "peerDependenciesMeta": {
129
+ "y-prosemirror": {
130
+ "optional": true
131
+ },
132
+ "y-protocols": {
133
+ "optional": true
134
+ },
135
+ "yjs": {
136
+ "optional": true
137
+ },
138
+ "@y/y": {
139
+ "optional": true
140
+ },
141
+ "@y/prosemirror": {
142
+ "optional": true
143
+ },
144
+ "@y/protocols": {
145
+ "optional": true
146
+ }
119
147
  },
120
148
  "eslintConfig": {
121
149
  "extends": [
@@ -124,13 +152,12 @@
124
152
  },
125
153
  "gitHead": "37614ab348dcc7faa830a9a88437b37197a2162d",
126
154
  "scripts": {
127
- "dev": "vite",
128
- "build": "tsc && vite build",
129
- "build-bundled": "tsc && vite build --config vite.config.bundled.ts && git checkout tmp-releases && rm -rf ../../release && mv ../../release-tmp ../../release",
130
- "preview": "vite preview",
131
- "lint": "eslint src --max-warnings 0",
132
- "test": "vitest --run",
133
- "test-watch": "vitest watch",
155
+ "dev": "vp dev",
156
+ "build-bundled": "tsgo && vp build --config vite.config.bundled.ts && git checkout tmp-releases && rm -rf ../../release && mv ../../release-tmp ../../release",
157
+ "preview": "vp preview",
158
+ "lint": "vp lint src",
159
+ "test": "vp test --run",
160
+ "test-watch": "vp test watch",
134
161
  "clean": "rimraf dist && rimraf types",
135
162
  "update-tlds": "node scripts/update-tlds.mjs"
136
163
  }
@@ -1,4 +1,4 @@
1
- import { describe, expect, it } from "vitest";
1
+ import { describe, expect, it } from "vite-plus/test";
2
2
 
3
3
  import { setupTestEnv } from "../../setupTestEnv.js";
4
4
  import { insertBlocks as insertBlocksTr } from "./insertBlocks.js";
@@ -49,7 +49,7 @@ export function insertBlocks<
49
49
  // Now that the `PartialBlock`s have been converted to nodes, we can
50
50
  // re-convert them into full `Block`s.
51
51
  const insertedBlocks = nodesToInsert.map((node) =>
52
- nodeToBlock(node, pmSchema),
52
+ nodeToBlock(node, tr.doc),
53
53
  ) as Block<BSchema, I, S>[];
54
54
 
55
55
  return insertedBlocks;
@@ -1,6 +1,6 @@
1
- import { describe, expect, it } from "vitest";
1
+ import { describe, expect, it } from "vite-plus/test";
2
2
 
3
- import { getBlockInfoFromTransaction } from "../../../getBlockInfoFromPos.js";
3
+ import { getBlockInfoFromSelection } from "../../../getBlockInfoFromPos.js";
4
4
  import { setupTestEnv } from "../../setupTestEnv.js";
5
5
  import { getParentBlockInfo, mergeBlocksCommand } from "./mergeBlocks.js";
6
6
 
@@ -14,7 +14,7 @@ function mergeBlocks(posBetweenBlocks: number) {
14
14
 
15
15
  function getPosBeforeSelectedBlock() {
16
16
  return getEditor().transact(
17
- (tr) => getBlockInfoFromTransaction(tr).bnBlock.beforePos,
17
+ (tr) => getBlockInfoFromSelection(tr).bnBlock.beforePos,
18
18
  );
19
19
  }
20
20
 
@@ -1,10 +1,11 @@
1
1
  import { NodeSelection, TextSelection } from "prosemirror-state";
2
2
  import { CellSelection } from "prosemirror-tables";
3
- import { describe, expect, it } from "vitest";
3
+ import { describe, expect, it } from "vite-plus/test";
4
4
 
5
5
  import {
6
- getBlockInfoFromTransaction,
7
- getNearestBlockPos,
6
+ getBlockInfoAtNearest,
7
+ getBlockInfoFromSelection,
8
+ getNodeId,
8
9
  } from "../../../getBlockInfoFromPos.js";
9
10
  import { setupTestEnv } from "../../setupTestEnv.js";
10
11
  import {
@@ -16,9 +17,7 @@ import {
16
17
  const getEditor = setupTestEnv();
17
18
 
18
19
  function makeSelectionSpanContent(selectionType: "text" | "node" | "cell") {
19
- const blockInfo = getEditor().transact((tr) =>
20
- getBlockInfoFromTransaction(tr),
21
- );
20
+ const blockInfo = getEditor().transact((tr) => getBlockInfoFromSelection(tr));
22
21
  if (!blockInfo.isBlockContainer) {
23
22
  throw new Error(
24
23
  `Selection points to a ${blockInfo.blockNoteType} node, not a blockContainer node`,
@@ -222,13 +221,16 @@ describe("Test moveBlocksUp", () => {
222
221
 
223
222
  moveBlocksUp(getEditor(), "paragraph-2");
224
223
 
225
- const { anchor, head } = getEditor().transact((tr) => tr.selection);
226
- const anchorBlockId = getEditor().transact(
227
- (tr) => getNearestBlockPos(tr.doc, anchor).node.attrs.id,
228
- );
229
- const headBlockId = getEditor().transact(
230
- (tr) => getNearestBlockPos(tr.doc, head).node.attrs.id,
231
- );
224
+ const { anchorBlockId, headBlockId } = getEditor().transact((tr) => ({
225
+ anchorBlockId: getNodeId(
226
+ getBlockInfoAtNearest(tr, tr.selection.anchor).bnBlock.node,
227
+ tr.doc,
228
+ ),
229
+ headBlockId: getNodeId(
230
+ getBlockInfoAtNearest(tr, tr.selection.head).bnBlock.node,
231
+ tr.doc,
232
+ ),
233
+ }));
232
234
  expect(anchorBlockId).toBe("paragraph-1");
233
235
  expect(headBlockId).toBe("paragraph-1");
234
236
  });
@@ -343,13 +345,16 @@ describe("Test moveBlocksDown", () => {
343
345
 
344
346
  moveBlocksDown(getEditor(), "paragraph-0");
345
347
 
346
- const { anchor, head } = getEditor().transact((tr) => tr.selection);
347
- const anchorBlockId = getEditor().transact(
348
- (tr) => getNearestBlockPos(tr.doc, anchor).node.attrs.id,
349
- );
350
- const headBlockId = getEditor().transact(
351
- (tr) => getNearestBlockPos(tr.doc, head).node.attrs.id,
352
- );
348
+ const { anchorBlockId, headBlockId } = getEditor().transact((tr) => ({
349
+ anchorBlockId: getNodeId(
350
+ getBlockInfoAtNearest(tr, tr.selection.anchor).bnBlock.node,
351
+ tr.doc,
352
+ ),
353
+ headBlockId: getNodeId(
354
+ getBlockInfoAtNearest(tr, tr.selection.head).bnBlock.node,
355
+ tr.doc,
356
+ ),
357
+ }));
353
358
  expect(anchorBlockId).toBe("paragraph-1");
354
359
  expect(headBlockId).toBe("paragraph-1");
355
360
  });
@@ -9,8 +9,13 @@ import { CellSelection } from "prosemirror-tables";
9
9
  import { Block } from "../../../../blocks/defaultBlocks.js";
10
10
  import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor";
11
11
  import { BlockIdentifier } from "../../../../schema/index.js";
12
- import { getNearestBlockPos } from "../../../getBlockInfoFromPos.js";
12
+ import {
13
+ getBlockInfoAtNearest,
14
+ getNodeId,
15
+ } from "../../../getBlockInfoFromPos.js";
13
16
  import { getNodeById } from "../../../nodeUtil.js";
17
+ import { insertBlocks } from "../insertBlocks/insertBlocks.js";
18
+ import { removeAndInsertBlocks } from "../replaceBlocks/replaceBlocks.js";
14
19
 
15
20
  type BlockSelectionData = (
16
21
  | {
@@ -44,31 +49,34 @@ function getBlockSelectionData(
44
49
  editor: BlockNoteEditor<any, any, any>,
45
50
  ): BlockSelectionData {
46
51
  return editor.transact((tr) => {
47
- const anchorBlockPosInfo = getNearestBlockPos(tr.doc, tr.selection.anchor);
52
+ const anchorBlockPosInfo = getBlockInfoAtNearest(tr, tr.selection.anchor);
53
+
54
+ const anchorBlockId = getNodeId(anchorBlockPosInfo.bnBlock.node, tr.doc);
48
55
 
49
56
  if (tr.selection instanceof CellSelection) {
50
57
  return {
51
58
  type: "cell" as const,
52
- anchorBlockId: anchorBlockPosInfo.node.attrs.id,
59
+ anchorBlockId,
53
60
  anchorCellOffset:
54
- tr.selection.$anchorCell.pos - anchorBlockPosInfo.posBeforeNode,
61
+ tr.selection.$anchorCell.pos - anchorBlockPosInfo.bnBlock.beforePos,
55
62
  headCellOffset:
56
- tr.selection.$headCell.pos - anchorBlockPosInfo.posBeforeNode,
63
+ tr.selection.$headCell.pos - anchorBlockPosInfo.bnBlock.beforePos,
57
64
  };
58
65
  } else if (tr.selection instanceof NodeSelection) {
59
66
  return {
60
67
  type: "node" as const,
61
- anchorBlockId: anchorBlockPosInfo.node.attrs.id,
68
+ anchorBlockId,
62
69
  };
63
70
  } else {
64
- const headBlockPosInfo = getNearestBlockPos(tr.doc, tr.selection.head);
71
+ const headBlockPosInfo = getBlockInfoAtNearest(tr, tr.selection.head);
65
72
 
66
73
  return {
67
74
  type: "text" as const,
68
- anchorBlockId: anchorBlockPosInfo.node.attrs.id,
69
- headBlockId: headBlockPosInfo.node.attrs.id,
70
- anchorOffset: tr.selection.anchor - anchorBlockPosInfo.posBeforeNode,
71
- headOffset: tr.selection.head - headBlockPosInfo.posBeforeNode,
75
+ anchorBlockId,
76
+ headBlockId: getNodeId(headBlockPosInfo.bnBlock.node, tr.doc),
77
+ anchorOffset:
78
+ tr.selection.anchor - anchorBlockPosInfo.bnBlock.beforePos,
79
+ headOffset: tr.selection.head - headBlockPosInfo.bnBlock.beforePos,
72
80
  };
73
81
  }
74
82
  });
@@ -148,24 +156,26 @@ export function moveBlocks(
148
156
  referenceBlock: BlockIdentifier,
149
157
  placement: "before" | "after",
150
158
  ) {
151
- editor.transact(() => {
152
- // A `columnList` reference can be dissolved by `fixColumnList` when its
153
- // `column`s are removed, leaving its ID invalid for re-insertion. Anchor
154
- // to an adjacent block instead, which is unaffected by the removal.
155
- const refBlock = editor.getBlock(referenceBlock);
156
- if (refBlock?.type === "columnList") {
157
- const adjacent =
158
- placement === "after"
159
- ? editor.getNextBlock(refBlock)
160
- : editor.getPrevBlock(refBlock);
161
- if (adjacent) {
162
- referenceBlock = adjacent;
163
- placement = placement === "after" ? "before" : "after";
164
- }
165
- }
166
-
167
- editor.removeBlocks(blocks);
168
- editor.insertBlocks(flattenColumns(blocks), referenceBlock, placement);
159
+ editor.transact((tr) => {
160
+ // Don't fix columns/columnLists in the removal step. Since a move is a
161
+ // rearrangement rather than a deletion, columns that it empties out are
162
+ // deliberately left as-is instead of being collapsed - this keeps moves
163
+ // free of side effects (and reversible by moving back), and matches
164
+ // dragging a block out of a column, which doesn't collapse it either.
165
+ // Fixing them mid-move also broke the following case:
166
+ // <column>
167
+ // <paragraph></paragraph>
168
+ // <paragraph>Paragraph</paragraph>
169
+ // </column>
170
+ // When the non-empty block is moved up, the column is seen as empty and
171
+ // collapsed in the removal step, so the following insertion fails.
172
+ removeAndInsertBlocks(tr, blocks, [], { fixColumns: false });
173
+ insertBlocks<any, any, any>(
174
+ tr,
175
+ flattenColumns(blocks),
176
+ referenceBlock,
177
+ placement,
178
+ );
169
179
  });
170
180
  }
171
181
 
@@ -1,6 +1,6 @@
1
- import { describe, expect, it } from "vitest";
1
+ import { describe, expect, it } from "vite-plus/test";
2
2
 
3
- import { afterAll, beforeAll } from "vitest";
3
+ import { afterAll, beforeAll } from "vite-plus/test";
4
4
  import { PartialBlock } from "../../../../blocks/defaultBlocks.js";
5
5
  import { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
6
6
 
@@ -3,7 +3,7 @@ import { Transaction } from "prosemirror-state";
3
3
  import { canJoin, liftTarget, ReplaceAroundStep } from "prosemirror-transform";
4
4
 
5
5
  import { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
6
- import { getBlockInfoFromTransaction } from "../../../getBlockInfoFromPos.js";
6
+ import { getBlockInfoFromSelection } from "../../../getBlockInfoFromPos.js";
7
7
 
8
8
  /**
9
9
  * Modified version of prosemirror-schema-list's sinkItem.
@@ -15,11 +15,7 @@ import { getBlockInfoFromTransaction } from "../../../getBlockInfoFromPos.js";
15
15
  * 3. Slice creates groupType instead of parent.type
16
16
  * 4. Operates on Transaction directly instead of state+dispatch
17
17
  */
18
- function sinkItem(
19
- tr: Transaction,
20
- itemType: NodeType,
21
- groupType: NodeType,
22
- ) {
18
+ function sinkItem(tr: Transaction, itemType: NodeType, groupType: NodeType) {
23
19
  const { $from, $to } = tr.selection;
24
20
  const range = $from.blockRange(
25
21
  $to,
@@ -197,7 +193,7 @@ export function unnestBlock(editor: BlockNoteEditor<any, any, any>) {
197
193
 
198
194
  export function canNestBlock(editor: BlockNoteEditor<any, any, any>) {
199
195
  return editor.transact((tr) => {
200
- const { bnBlock: blockContainer } = getBlockInfoFromTransaction(tr);
196
+ const { bnBlock: blockContainer } = getBlockInfoFromSelection(tr);
201
197
 
202
198
  return tr.doc.resolve(blockContainer.beforePos).nodeBefore !== null;
203
199
  });
@@ -205,7 +201,7 @@ export function canNestBlock(editor: BlockNoteEditor<any, any, any>) {
205
201
 
206
202
  export function canUnnestBlock(editor: BlockNoteEditor<any, any, any>) {
207
203
  return editor.transact((tr) => {
208
- const { bnBlock: blockContainer } = getBlockInfoFromTransaction(tr);
204
+ const { bnBlock: blockContainer } = getBlockInfoFromSelection(tr);
209
205
 
210
206
  return tr.doc.resolve(blockContainer.beforePos).depth > 1;
211
207
  });
@@ -1,4 +1,4 @@
1
- import { describe, expect, it } from "vitest";
1
+ import { describe, expect, it } from "vite-plus/test";
2
2
 
3
3
  import { setupTestEnv } from "../../setupTestEnv.js";
4
4
  import { removeAndInsertBlocks } from "./replaceBlocks.js";