@blocknote/core 0.51.4 → 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 (396) 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-DGsP5WKr.js → blocks-CiuUGa1E.js} +1093 -994
  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-Co4y7P63.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-Bcud0PIg.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 +9 -6
  101. package/src/blocks/Table/TableExtension.ts +20 -6
  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 +21 -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/extensions.d.ts +2 -2
  271. package/types/src/editor/managers/ExtensionManager/index.d.ts +13 -0
  272. package/types/src/editor/managers/SelectionManager.d.ts +1 -1
  273. package/types/src/extensions/PositionMapping/PositionMapping.d.ts +4 -0
  274. package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -6
  275. package/types/src/extensions/Versioning/Versioning.d.ts +352 -0
  276. package/types/src/extensions/Versioning/Versioning.test.d.ts +1 -0
  277. package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +37 -0
  278. package/types/src/extensions/Versioning/inMemoryVersioning.test.d.ts +1 -0
  279. package/types/src/extensions/Versioning/index.d.ts +2 -0
  280. package/types/src/extensions/index.d.ts +6 -9
  281. package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +1 -0
  282. package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.d.ts +6 -1
  283. package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.d.ts +4 -0
  284. package/types/src/extensions/tiptap-extensions/index.d.ts +1 -5
  285. package/types/src/i18n/locales/en.d.ts +9 -1
  286. package/types/src/i18n/locales/fa.d.ts +9 -1
  287. package/types/src/i18n/locales/sk.d.ts +9 -1
  288. package/types/src/index.d.ts +2 -0
  289. package/types/src/pm-nodes/suggestionMarks.d.ts +26 -0
  290. package/types/src/schema/blocks/createSpec.d.ts +4 -4
  291. package/types/src/schema/blocks/createSpec.test.d.ts +1 -0
  292. package/types/src/schema/blocks/extendBlockSpec.test.d.ts +1 -0
  293. package/types/src/schema/blocks/internal.d.ts +5 -7
  294. package/types/src/schema/blocks/types.d.ts +22 -14
  295. package/types/src/schema/contentTypePropagation.test.d.ts +1 -0
  296. package/types/src/schema/index.d.ts +1 -0
  297. package/types/src/schema/inlineContent/types.d.ts +3 -3
  298. package/types/src/schema/markGroups.d.ts +33 -0
  299. package/types/src/user/UserStore.d.ts +105 -0
  300. package/types/src/user/createUserStore.test.d.ts +1 -0
  301. package/types/src/user/index.d.ts +2 -0
  302. package/types/src/user/userColors.d.ts +36 -0
  303. package/types/src/y/comments/RESTYjsThreadStore.d.ts +77 -0
  304. package/types/src/y/comments/YjsThreadStore.d.ts +79 -0
  305. package/types/src/y/comments/YjsThreadStore.test.d.ts +1 -0
  306. package/types/src/y/comments/YjsThreadStoreBase.d.ts +15 -0
  307. package/types/src/y/comments/index.d.ts +3 -0
  308. package/types/src/y/comments/yjsHelpers.d.ts +13 -0
  309. package/types/src/y/extensions/AttributionExtension.d.ts +74 -0
  310. package/types/src/y/extensions/AttributionExtension.test.d.ts +1 -0
  311. package/types/src/y/extensions/DiffVersioningExtension.d.ts +69 -0
  312. package/types/src/y/extensions/DiffVersioningExtension.test.d.ts +1 -0
  313. package/types/src/{extensions/Collaboration → y/extensions}/ForkYDoc.d.ts +4 -2
  314. package/types/src/y/extensions/ForkYDoc.test.d.ts +1 -0
  315. package/types/src/y/extensions/RelativePositionMapping.d.ts +4 -0
  316. package/types/src/y/extensions/RelativePositionMapping.test.d.ts +1 -0
  317. package/types/src/y/extensions/Suggestions.d.ts +36 -0
  318. package/types/src/y/extensions/Versioning.d.ts +17 -0
  319. package/types/src/y/extensions/Versioning.test.d.ts +1 -0
  320. package/types/src/y/extensions/YAttributionMarks.d.ts +67 -0
  321. package/types/src/y/extensions/YCursorPlugin.d.ts +14 -0
  322. package/types/src/y/extensions/YSync.d.ts +32 -0
  323. package/types/src/y/extensions/blockMatchNodes.d.ts +25 -0
  324. package/types/src/y/extensions/index.d.ts +189 -0
  325. package/types/src/y/index.d.ts +4 -0
  326. package/types/src/y/utils.d.ts +82 -0
  327. package/types/src/y/utils.test.d.ts +1 -0
  328. package/types/src/y/versioning/__test__/yhub.test.d.ts +1 -0
  329. package/types/src/y/versioning/index.d.ts +1 -0
  330. package/types/src/y/versioning/yhub.d.ts +87 -0
  331. package/types/src/{comments/threadstore/yjs → yjs/comments}/RESTYjsThreadStore.d.ts +6 -10
  332. package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.d.ts +3 -3
  333. package/types/src/yjs/comments/YjsThreadStore.test.d.ts +1 -0
  334. package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.d.ts +3 -3
  335. package/types/src/yjs/comments/index.d.ts +3 -0
  336. package/types/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.d.ts +1 -1
  337. package/types/src/yjs/extensions/FixUpSchema.d.ts +3 -0
  338. package/types/src/yjs/extensions/FixUpSchema.test.d.ts +1 -0
  339. package/types/src/yjs/extensions/ForkYDoc.d.ts +27 -0
  340. package/types/src/yjs/extensions/ForkYDoc.test.d.ts +1 -0
  341. package/types/src/yjs/extensions/RelativePositionMapping.d.ts +4 -0
  342. package/types/src/yjs/extensions/RelativePositionMapping.test.d.ts +1 -0
  343. package/types/src/yjs/extensions/Versioning.d.ts +26 -0
  344. package/types/src/yjs/extensions/Versioning.test.d.ts +1 -0
  345. package/types/src/{extensions/Collaboration → yjs/extensions}/YCursorPlugin.d.ts +5 -2
  346. package/types/src/{extensions/Collaboration → yjs/extensions}/YSync.d.ts +1 -1
  347. package/types/src/{extensions/Collaboration/Collaboration.d.ts → yjs/extensions/index.d.ts} +36 -15
  348. package/types/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +1 -0
  349. package/types/src/yjs/index.d.ts +2 -0
  350. package/types/src/yjs/utils.d.ts +5 -0
  351. package/dist/BlockNoteExtension-B6RhuQ3V.js +0 -27
  352. package/dist/BlockNoteExtension-B6RhuQ3V.js.map +0 -1
  353. package/dist/BlockNoteExtension-ab0REuob.cjs +0 -2
  354. package/dist/BlockNoteExtension-ab0REuob.cjs.map +0 -1
  355. package/dist/EventEmitter-CuPnGDYt.js +0 -22
  356. package/dist/EventEmitter-CuPnGDYt.js.map +0 -1
  357. package/dist/EventEmitter-DHdSnYCD.cjs +0 -2
  358. package/dist/EventEmitter-DHdSnYCD.cjs.map +0 -1
  359. package/dist/ShowSelection-BsHFfdMi.js +0 -29
  360. package/dist/ShowSelection-BsHFfdMi.js.map +0 -1
  361. package/dist/ShowSelection-DhXglbt8.cjs +0 -2
  362. package/dist/ShowSelection-DhXglbt8.cjs.map +0 -1
  363. package/dist/blocks-Bm6IfL1R.cjs +0 -11
  364. package/dist/blocks-Bm6IfL1R.cjs.map +0 -1
  365. package/dist/blocks-DGsP5WKr.js.map +0 -1
  366. package/dist/en-B9hMApn4.js.map +0 -1
  367. package/dist/en-Cj5r8sW_.cjs.map +0 -1
  368. package/dist/extensions-Co4y7P63.js.map +0 -1
  369. package/dist/extensions-IJK3t0sz.cjs +0 -52
  370. package/dist/extensions-IJK3t0sz.cjs.map +0 -1
  371. package/dist/src-B6rlChSc.cjs +0 -21
  372. package/dist/src-B6rlChSc.cjs.map +0 -1
  373. package/dist/src-Bcud0PIg.js.map +0 -1
  374. package/src/comments/userstore/UserStore.ts +0 -72
  375. package/src/extensions/Collaboration/Collaboration.ts +0 -55
  376. package/src/extensions/Collaboration/ForkYDoc.test.ts +0 -179
  377. package/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.ts +0 -175
  378. package/types/src/comments/userstore/UserStore.d.ts +0 -31
  379. package/types/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.d.ts +0 -4
  380. /package/src/{extensions/Collaboration → yjs/extensions}/YUndo.ts +0 -0
  381. /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor-forked.json +0 -0
  382. /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor.json +0 -0
  383. /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-forked.html +0 -0
  384. /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap.html +0 -0
  385. /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.ts +0 -0
  386. /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.ts +0 -0
  387. /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.ts +0 -0
  388. /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.ts +0 -0
  389. /package/types/src/{comments/threadstore/yjs/YjsThreadStore.test.d.ts → api/getBlockInfoFromPos.test.d.ts} +0 -0
  390. /package/types/src/{extensions/Collaboration/ForkYDoc.test.d.ts → api/nodeConversions/blockToNode.test.d.ts} +0 -0
  391. /package/types/src/{extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.d.ts → editor/managers/ExtensionManager/ExtensionManager.test.d.ts} +0 -0
  392. /package/types/src/{extensions/Collaboration → yjs/extensions}/YUndo.d.ts +0 -0
  393. /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.d.ts +0 -0
  394. /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.d.ts +0 -0
  395. /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.d.ts +0 -0
  396. /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.d.ts +0 -0
@@ -0,0 +1 @@
1
+ export * from "./yhub.js";
@@ -0,0 +1,631 @@
1
+ import * as Y from "@y/y";
2
+ import { decodeAny, encodeAny } from "lib0/buffer";
3
+
4
+ import {
5
+ CURRENT_VERSION_ID,
6
+ sortSnapshotsNewestFirst,
7
+ VersioningEndpointsFactory,
8
+ type VersioningEndpoints,
9
+ type VersionSnapshot,
10
+ } from "../../extensions/Versioning/index.js";
11
+ import { uint32 } from "lib0/random";
12
+ import { YCursorExtension } from "../extensions/YCursorPlugin.js";
13
+ import { YSyncExtension } from "../extensions/YSync.js";
14
+
15
+ /**
16
+ * Name of the root {@link Y.Type} map on the live collaboration doc that stores
17
+ * a mutable `versionId -> name` mapping. Because YHub attributions are
18
+ * immutable, version names that need to be editable (renamed) live here on the
19
+ * Y.Doc instead of (or in addition to) the immutable `name` attribution.
20
+ */
21
+ const VERSION_NAMES_MAP = "__bn_version_names";
22
+
23
+ /**
24
+ * Options for creating a YHub versioning endpoints instance.
25
+ */
26
+ export interface YHubVersioningOptions {
27
+ /**
28
+ * Base URL of the YHub API (e.g. `"https://yhub.example.com"`).
29
+ * Must **not** include a trailing slash.
30
+ */
31
+ baseUrl: string;
32
+
33
+ /** YHub organisation identifier. */
34
+ org: string;
35
+
36
+ /** Document identifier within the organisation. */
37
+ docId: string;
38
+
39
+ /**
40
+ * Optional headers to include in every request (e.g. authentication tokens).
41
+ */
42
+ headers?: Record<string, string>;
43
+
44
+ /**
45
+ * Maximum number of activity entries to fetch when listing versions.
46
+ * @default 50
47
+ */
48
+ activityLimit?: number;
49
+
50
+ /**
51
+ * When set, forwarded as the `group` query param to the YHub activity API,
52
+ * controlling whether adjacent edits are grouped into single entries.
53
+ */
54
+ group?: boolean;
55
+
56
+ /**
57
+ * Maximum gap (in ms) between edits for them to be grouped together.
58
+ * Forwarded as the `groupMaxGap` query param.
59
+ * @default 10000
60
+ */
61
+ groupMaxGap?: number;
62
+
63
+ /**
64
+ * Maximum total duration (in ms) a single group of edits may span.
65
+ * When set, forwarded as the `groupMaxDuration` query param.
66
+ */
67
+ groupMaxDuration?: number;
68
+
69
+ // TODO mergeUsers is not in standard yhub, but it exists in our fork.
70
+ /**
71
+ * When `true`, adjacent edits are grouped together even when made by
72
+ * *different* users (their ids accumulate in the grouped entry's `by`).
73
+ * When `false` (the default), only same-user adjacent edits are merged.
74
+ * Forwarded as the `mergeUsers` query param.
75
+ * @default false
76
+ */
77
+ mergeUsers?: boolean;
78
+ }
79
+
80
+ /**
81
+ * Shape of a single activity entry returned by the YHub
82
+ * `GET /activity/{org}/{docId}` endpoint (after `decodeAny`).
83
+ */
84
+ interface YHubActivityEntry {
85
+ /** Start of the change window (unix-ms timestamp). */
86
+ from: number;
87
+ /** End of the change window (unix-ms timestamp). */
88
+ to: number;
89
+ /** Comma separated list of user-ids that matches the attribution */
90
+ by?: string;
91
+ /** Custom attribution key-value pairs (when `customAttributions=true`). */
92
+ customAttributions?: Array<{ k: string; v: string }>;
93
+ }
94
+
95
+ /**
96
+ * Shape returned by the YHub `GET /changeset/{org}/{docId}` endpoint (after
97
+ * `decodeAny`).
98
+ */
99
+ interface YHubChangeset {
100
+ /** Full Y.Doc state **before** the changeset window. */
101
+ prevDoc?: Uint8Array;
102
+ /** Full Y.Doc state **after** the changeset window. */
103
+ nextDoc?: Uint8Array;
104
+ /**
105
+ * Encoded {@link Y.ContentMap} describing who authored each change in the
106
+ * window and when. Present when the changeset is requested with
107
+ * `attributions=true`.
108
+ */
109
+ attributions?: Uint8Array;
110
+ }
111
+
112
+ /**
113
+ * Whether an activity entry is a version marker (created with a `type:version`
114
+ * custom attribution) as opposed to a plain edit.
115
+ */
116
+ function isVersionEntry(entry: YHubActivityEntry): boolean {
117
+ return (
118
+ entry.customAttributions?.some(
119
+ (a) => a.k === "type" && a.v === "version",
120
+ ) ?? false
121
+ );
122
+ }
123
+
124
+ /**
125
+ * Convert a YHub activity entry into a {@link VersionSnapshot}.
126
+ *
127
+ * Version markers (entries with a `type:version` custom attribution) map to
128
+ * named snapshots: the `id` attribution becomes the snapshot identifier and the
129
+ * `name` attribution its name. Any other (plain edit) entry maps to a
130
+ * history-only snapshot with a synthetic `history-<to>-<index>` id and no name.
131
+ * In both cases the entry's `by` user-ids are passed through raw on
132
+ * {@link VersionSnapshot.by} — resolving them to user info is the view layer's
133
+ * job.
134
+ *
135
+ * The history id embeds the entry's `index` within the activity response
136
+ * because YHub can emit multiple activity entries sharing the same `to`
137
+ * timestamp (e.g. distinct same-`insertAt` patches that grouping did not merge),
138
+ * and `to` alone would then produce colliding `history-<to>` ids — duplicate
139
+ * React keys in the sidebar. The `index` disambiguates them. The changeset
140
+ * lookups (`getContent`/`getAttributions`/`restore`) key off
141
+ * {@link VersionSnapshot.createdAt} (= `entry.to`), never the id, so embedding
142
+ * the index in the id is safe.
143
+ */
144
+ function activityToSnapshot(
145
+ entry: YHubActivityEntry,
146
+ index: number,
147
+ ): VersionSnapshot | undefined {
148
+ const by = entry.by
149
+ ?.split(",")
150
+ .map((s) => s.trim())
151
+ .filter(Boolean);
152
+ const byField = by && by.length > 0 ? by : undefined;
153
+
154
+ if (isVersionEntry(entry)) {
155
+ const id = entry.customAttributions?.find((a) => a.k === "id")?.v;
156
+ if (id === undefined) {
157
+ return undefined;
158
+ }
159
+ const attributionName = entry.customAttributions?.find(
160
+ (a) => a.k === "name",
161
+ )?.v;
162
+ return {
163
+ id,
164
+ name: attributionName,
165
+ createdAt: entry.to,
166
+ updatedAt: entry.to,
167
+ by: byField,
168
+ };
169
+ }
170
+
171
+ return {
172
+ id: `history-${entry.to}-${index}`,
173
+ createdAt: entry.to,
174
+ updatedAt: entry.to,
175
+ by: byField,
176
+ };
177
+ }
178
+
179
+ async function yhubFetch(
180
+ url: string,
181
+ headers: Record<string, string>,
182
+ init?: RequestInit,
183
+ ): Promise<ArrayBuffer> {
184
+ const res = await fetch(url, {
185
+ ...init,
186
+ headers: {
187
+ ...headers,
188
+ ...(init?.headers instanceof Headers
189
+ ? Object.fromEntries(init.headers.entries())
190
+ : Array.isArray(init?.headers)
191
+ ? Object.fromEntries(init.headers)
192
+ : init?.headers),
193
+ },
194
+ });
195
+ if (!res.ok) {
196
+ throw new Error(
197
+ `YHub request failed: ${res.status} ${res.statusText} (${url})`,
198
+ );
199
+ }
200
+ return res.arrayBuffer();
201
+ }
202
+
203
+ /**
204
+ * Create a {@link VersioningEndpoints} implementation backed by the
205
+ * [YHub](https://github.com/yjs/yhub) HTTP API.
206
+ *
207
+ * Versions are created by PATCHing the document with custom attributions
208
+ * (`type:version` + an optional `name`). The `list` endpoint returns the full
209
+ * activity timeline, mapping `type:version` markers to named versions and every
210
+ * other entry to a history-only snapshot, so the sidebar can show both the
211
+ * named versions and the complete edit history.
212
+ *
213
+ * A version's id lives in immutable YHub attributions (`type:version` + `id`),
214
+ * so it is fixed at creation time. Version *names*, however, are stored in a
215
+ * mutable `__bn_version_names` map on the live collaboration doc (see
216
+ * {@link VERSION_NAMES_MAP}), so `rename` is supported and simply updates that
217
+ * store.
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * import { withCollaboration } from "@blocknote/core/y";
222
+ * import { createYHubVersioningEndpoints } from "@blocknote/core/y";
223
+ *
224
+ * const editor = BlockNoteEditor.create(
225
+ * withCollaboration({
226
+ * collaboration: {
227
+ * fragment,
228
+ * user: { name: "Alice", color: "#ff0" },
229
+ * provider,
230
+ * versioningEndpoints: createYHubVersioningEndpoints({
231
+ * baseUrl: "https://yhub.example.com",
232
+ * org: "my-org",
233
+ * docId: "my-doc",
234
+ * }),
235
+ * },
236
+ * }),
237
+ * );
238
+ * ```
239
+ */
240
+ export function createYHubVersioningEndpoints(
241
+ options: YHubVersioningOptions,
242
+ ): VersioningEndpointsFactory<Y.Type, Uint8Array, Y.ContentMap> {
243
+ const {
244
+ baseUrl,
245
+ org,
246
+ docId,
247
+ headers = {},
248
+ activityLimit = 50,
249
+ group,
250
+ } = options;
251
+
252
+ const activityUrl = `${baseUrl}/activity/${org}/${docId}`;
253
+ const changesetUrl = `${baseUrl}/changeset/${org}/${docId}`;
254
+ const rollbackUrl = `${baseUrl}/rollback/${org}/${docId}`;
255
+
256
+ return (editor) => {
257
+ /**
258
+ * The mutable per-id version-name store on the live collaboration doc.
259
+ *
260
+ * Returns the root {@link VERSION_NAMES_MAP} map-typed {@link Y.Type}, which
261
+ * uses `setAttr`/`getAttr` for keyed access (this Yjs fork has a single
262
+ * unified `Y.Type` rather than a distinct `Y.Map`). `undefined` until the
263
+ * live doc has been captured from a `create` call.
264
+ */
265
+ const getVersionNamesMap = (): Y.Type | undefined => {
266
+ const fragment =
267
+ editor.getExtension<typeof YSyncExtension>("ySync")?.fragment.doc;
268
+ // `fragment` is undefined until the live doc has been captured (e.g. no
269
+ // ySync extension attached yet); return undefined rather than throwing so
270
+ // callers can gracefully fall back to the immutable name attribution.
271
+ return fragment?.get(VERSION_NAMES_MAP);
272
+ };
273
+
274
+ /**
275
+ * Build the synthetic "current version" snapshot, or `undefined` when the
276
+ * live document matches the latest saved version (no edits since).
277
+ *
278
+ * Both lookups are made here, independently of the grouped `list()` request:
279
+ *
280
+ * - the newest activity entry of *any* kind (ungrouped, so its `to` is the
281
+ * true last-edit time), and
282
+ * - the newest **version marker** (via the `withCustomAttributions`
283
+ * server-side filter).
284
+ *
285
+ * Deriving the marker time from `list()`'s grouped entries would be wrong:
286
+ * with grouping (especially `mergeUsers`) the newest marker's group absorbs
287
+ * the later unsaved edit, so the group's `to` equals the edit's `to` and the
288
+ * comparison below can never fire. Fetching the marker unmerged avoids that.
289
+ */
290
+ const getCurrentVersionEntry = async (): Promise<
291
+ VersionSnapshot | undefined
292
+ > => {
293
+ const latestParams = new URLSearchParams({
294
+ order: "desc",
295
+ limit: "1",
296
+ customAttributions: "true",
297
+ });
298
+ const latestVersionParams = new URLSearchParams({
299
+ order: "desc",
300
+ limit: "1",
301
+ customAttributions: "true",
302
+ // Server-side filter to `type:version` markers only, so this ignores the
303
+ // plain edits that would otherwise be the newest entries.
304
+ withCustomAttributions: "type:version",
305
+ });
306
+
307
+ const [latestBuf, latestVersionBuf] = await Promise.all([
308
+ yhubFetch(`${activityUrl}?${latestParams}`, headers),
309
+ yhubFetch(`${activityUrl}?${latestVersionParams}`, headers),
310
+ ]);
311
+ const latestEdit = (
312
+ decodeAny(new Uint8Array(latestBuf)) as YHubActivityEntry[]
313
+ )[0];
314
+ const latestVersion = (
315
+ decodeAny(new Uint8Array(latestVersionBuf)) as YHubActivityEntry[]
316
+ )[0];
317
+
318
+ if (!latestEdit || latestEdit.to <= (latestVersion?.to ?? 0)) {
319
+ return undefined;
320
+ }
321
+
322
+ // Build the synthetic entry directly rather than via `activityToSnapshot`,
323
+ // whose `id` comes from a string-typed wire attribution — the current
324
+ // entry's id is the `CURRENT_VERSION_ID` symbol, not a real version id.
325
+ const by =
326
+ latestEdit.by
327
+ ?.split(",")
328
+ .map((t) => t.trim())
329
+ .filter(Boolean) ?? [];
330
+ return {
331
+ id: CURRENT_VERSION_ID,
332
+ createdAt: latestEdit.to,
333
+ updatedAt: latestEdit.to,
334
+ by: by.length > 0 ? by : undefined,
335
+ };
336
+ };
337
+
338
+ /**
339
+ * PATCH the current document state to YHub, optionally with custom
340
+ * attributions. Used both for creating named version markers and for
341
+ * backing up the document before a restore.
342
+ */
343
+ const patchDoc = async (
344
+ fragment: Y.Type,
345
+ customAttributions: Array<{ k: string; v: any }>,
346
+ by?: string,
347
+ ) => {
348
+ const doc = fragment.doc;
349
+ if (!doc) {
350
+ throw new Error(
351
+ "Cannot patch document: the Y.Type is not attached to a Y.Doc.",
352
+ );
353
+ }
354
+
355
+ // YHub only records custom attributions when they attach to NEW content
356
+ // that survives its server-side diff. An update-less PATCH is rejected
357
+ // (400 — "at least one of update or awareness must be present"), and even
358
+ // if it weren't, there'd be no content for the attributions to ride on, so
359
+ // no activity entry is created. YHub has no metadata-only marker path.
360
+ //
361
+ // So we introduce a tiny piece of novel content for the marker to attach
362
+ // to: a single insert into a dedicated `__bn_version_markers` fragment that
363
+ // the editor never renders. A fresh Y.Doc guarantees a clientID/content the
364
+ // server has never seen, so the diff is non-empty and the attributions land
365
+ // on it. The reconstructed document at this version's timestamp still
366
+ // contains the full editor content — this marker only ever lives in the
367
+ // throwaway fragment.
368
+ const markerDoc = new Y.Doc();
369
+ markerDoc.get("__bn_version_markers", "XmlFragment").insert(0, ["v"]);
370
+ const update = Y.encodeStateAsUpdate(markerDoc);
371
+
372
+ const body: Record<string, unknown> = { update, customAttributions };
373
+
374
+ await yhubFetch(
375
+ `${baseUrl}/ydoc/${org}/${docId}${by ? `?userid=${by}` : ""}`,
376
+ headers,
377
+ {
378
+ method: "PATCH",
379
+ body: encodeAny(body) as BufferSource,
380
+ },
381
+ );
382
+ };
383
+
384
+ /**
385
+ * Create a named version marker for the current document state by PATCHing
386
+ * it with `type:version` custom attributions.
387
+ */
388
+ const create: VersioningEndpoints<
389
+ Y.Type,
390
+ Uint8Array,
391
+ Y.ContentMap
392
+ >["create"] = async (fragment, options) => {
393
+ const id = String(uint32());
394
+ const now = Date.now();
395
+
396
+ if (options?.name) {
397
+ getVersionNamesMap()?.setAttr(id, options.name);
398
+ }
399
+
400
+ const customAttributions: Array<{ k: string; v: string }> = [
401
+ { k: "type", v: "version" },
402
+ { k: "id", v: id },
403
+ ];
404
+ if (options?.name) {
405
+ customAttributions.push({ k: "name", v: options.name });
406
+ }
407
+
408
+ const user = editor
409
+ .getExtension<typeof YCursorExtension>("yCursor")
410
+ ?.getUser();
411
+ await patchDoc(fragment, customAttributions, user?.id);
412
+
413
+ return {
414
+ id,
415
+ name: options?.name,
416
+ createdAt: now,
417
+ updatedAt: now,
418
+ by: user?.id,
419
+ };
420
+ };
421
+
422
+ /**
423
+ * Reconstruct the full document state as it was at a given `to` timestamp.
424
+ *
425
+ * The changeset endpoint builds `nextDoc` purely from the `to` timestamp
426
+ * range — it ignores `withCustomAttributions` for doc reconstruction (that
427
+ * filter only scopes the attribution overlay). So historical document state
428
+ * can only be retrieved by timestamp, never by the version's `id`.
429
+ */
430
+ const getContentAt = async (to: number): Promise<Uint8Array> => {
431
+ const params = new URLSearchParams({
432
+ ydoc: "true",
433
+ to: String(to),
434
+ });
435
+
436
+ const buf = await yhubFetch(`${changesetUrl}?${params}`, headers);
437
+ const changeset = decodeAny(new Uint8Array(buf)) as YHubChangeset;
438
+
439
+ if (!changeset.nextDoc) {
440
+ throw new Error(`YHub returned no document state at timestamp ${to}.`);
441
+ }
442
+
443
+ return Y.convertUpdateFormatV1ToV2(changeset.nextDoc);
444
+ };
445
+
446
+ /**
447
+ * Fetch the full document content for a saved version snapshot.
448
+ *
449
+ * The snapshot's `createdAt` is the activity entry's `to` timestamp (see
450
+ * {@link activityToSnapshot}), which is exactly what the changeset API needs.
451
+ */
452
+ const getContent: VersioningEndpoints<
453
+ Y.Type,
454
+ Uint8Array,
455
+ Y.ContentMap
456
+ >["getContent"] = async (snapshot) => {
457
+ return getContentAt(snapshot.createdAt);
458
+ };
459
+
460
+ /**
461
+ * Fetch the authorship attributions for the changes between two snapshots
462
+ * (or from the start of the document when `compareTo` is omitted).
463
+ *
464
+ * Snapshots carry their `to` timestamp directly in `createdAt`, so no
465
+ * activity lookup is needed to resolve the changeset window.
466
+ */
467
+ const getAttributions: VersioningEndpoints<
468
+ Y.Type,
469
+ Uint8Array,
470
+ Y.ContentMap
471
+ >["getAttributions"] = async (snapshot, compareTo) => {
472
+ const to = snapshot.createdAt;
473
+ const from = compareTo !== undefined ? compareTo.createdAt : 0;
474
+
475
+ const params = new URLSearchParams({
476
+ from: String(from),
477
+ to: String(to),
478
+ attributions: "true",
479
+ });
480
+
481
+ const buf = await yhubFetch(`${changesetUrl}?${params}`, headers);
482
+ const changeset = decodeAny(new Uint8Array(buf)) as YHubChangeset;
483
+
484
+ if (!changeset.attributions) {
485
+ throw new Error(
486
+ `YHub returned no attributions for snapshot ${String(snapshot.id)}.`,
487
+ );
488
+ }
489
+
490
+ return Y.decodeContentMap(changeset.attributions);
491
+ };
492
+
493
+ /**
494
+ * Restore the document to a saved version: fetch the target version's
495
+ * content and roll back everything after it.
496
+ *
497
+ * The snapshot's `createdAt` is the activity entry's `to` timestamp.
498
+ */
499
+ const restore: VersioningEndpoints<
500
+ Y.Type,
501
+ Uint8Array,
502
+ Y.ContentMap
503
+ >["restore"] = async (_fragment, snapshot) => {
504
+ const to = snapshot.createdAt;
505
+ const snapshotContent = await getContentAt(to);
506
+
507
+ await yhubFetch(`${rollbackUrl}?from=${to}`, headers, {
508
+ method: "POST",
509
+ body: encodeAny({ from: to }) as BufferSource,
510
+ });
511
+
512
+ return snapshotContent;
513
+ };
514
+
515
+ /**
516
+ * Rename a saved version by updating its entry in the mutable
517
+ * {@link VERSION_NAMES_MAP} store on the live collaboration doc.
518
+ *
519
+ * The version's `id` remains fixed in its immutable YHub attributions —
520
+ * only the editable name in the map is changed. Passing an empty or
521
+ * `undefined` name clears the entry (falling back to the immutable `name`
522
+ * attribution captured at creation time).
523
+ */
524
+ const rename: VersioningEndpoints<
525
+ Y.Type,
526
+ Uint8Array,
527
+ Y.ContentMap
528
+ >["rename"] = async (snapshot, name) => {
529
+ if (typeof snapshot.id !== "string") {
530
+ // CURRENT_VERSION_ID (symbol) is not renameable.
531
+ return;
532
+ }
533
+ const map = getVersionNamesMap();
534
+ if (!map) {
535
+ throw new Error(
536
+ "Cannot rename version: no live collaboration document is available.",
537
+ );
538
+ }
539
+ if (name === undefined || name === "") {
540
+ map.deleteAttr(snapshot.id);
541
+ } else {
542
+ map.setAttr(snapshot.id, name);
543
+ }
544
+ };
545
+
546
+ /**
547
+ * List the full version timeline (newest first), plus a synthetic
548
+ * "current version" entry when the live document has unsaved edits.
549
+ *
550
+ * Returns the entire activity timeline: `type:version` markers are mapped
551
+ * to named snapshots and every other entry to a history-only snapshot (see
552
+ * {@link activityToSnapshot}), so the sidebar can offer both a "named
553
+ * versions" and a full "history" view. Author user-ids are passed through
554
+ * raw on {@link VersionSnapshot.by} — the view layer resolves them to user
555
+ * info via the versioning extension's user store.
556
+ */
557
+ const list: VersioningEndpoints<
558
+ Y.Type,
559
+ Uint8Array,
560
+ Y.ContentMap
561
+ >["list"] = async () => {
562
+ // Read the grouping knobs fresh from `options` so a caller mutating the
563
+ // object it passed in reconfigures grouping on the next refresh (see the
564
+ // note where these are deliberately left out of the destructure above).
565
+ const groupMaxGap = options.groupMaxGap ?? 10000;
566
+ const groupMaxDuration = options.groupMaxDuration;
567
+ const mergeUsers = options.mergeUsers;
568
+
569
+ const params = new URLSearchParams({
570
+ order: "desc",
571
+ limit: String(activityLimit),
572
+ customAttributions: "true",
573
+ });
574
+ // Always send a concrete `groupMaxGap`. Sending
575
+ // `String(undefined)` here would make the server `parseInt("undefined")`
576
+ // to NaN, silently disabling grouping — which surfaces every same-`to`
577
+ // attribution as its own history entry and produces duplicate React keys.
578
+ params.set("groupMaxGap", String(groupMaxGap));
579
+ if (group !== undefined) {
580
+ params.set("group", String(group));
581
+ }
582
+ if (groupMaxDuration !== undefined) {
583
+ params.set("groupMaxDuration", String(groupMaxDuration));
584
+ }
585
+ if (mergeUsers !== undefined) {
586
+ params.set("mergeUsers", String(mergeUsers));
587
+ }
588
+
589
+ const buf = await yhubFetch(`${activityUrl}?${params}`, headers);
590
+ const entries = decodeAny(new Uint8Array(buf)) as YHubActivityEntry[];
591
+
592
+ const snapshots = sortSnapshotsNewestFirst(
593
+ entries
594
+ .map((entry, i) => activityToSnapshot(entry, i))
595
+ .filter((s): s is VersionSnapshot => s !== undefined)
596
+ // Prefer the mutable per-id name from the live doc's
597
+ // `__bn_version_names` store over the immutable `name` attribution,
598
+ // so renames (which only mutate that store) are reflected here.
599
+ .map((snapshot) => {
600
+ const attributionName = snapshot.name;
601
+ const mappedName =
602
+ (typeof snapshot.id === "string"
603
+ ? (getVersionNamesMap()?.getAttr(snapshot.id) as
604
+ | string
605
+ | undefined)
606
+ : undefined) ?? attributionName;
607
+ return { ...snapshot, name: mappedName };
608
+ }),
609
+ );
610
+
611
+ // Surface a "current version" entry when the live document has edits
612
+ // beyond the most recent saved version marker. `getCurrentVersionEntry`
613
+ // makes its own unmerged lookups (see there), so it is unaffected by the
614
+ // grouping/mergeUsers params used for the list above.
615
+ //
616
+ // This only re-evaluates when `list()` runs (sidebar open / refresh),
617
+ // which matches how YHub versions load today.
618
+ const currentEntry = await getCurrentVersionEntry();
619
+ return currentEntry ? [currentEntry, ...snapshots] : snapshots;
620
+ };
621
+
622
+ return {
623
+ list,
624
+ create,
625
+ getContent,
626
+ getAttributions,
627
+ restore,
628
+ rename,
629
+ };
630
+ };
631
+ }
@@ -0,0 +1,5 @@
1
+ # @blocknote/core/yjs
2
+
3
+ This package contains integrations for Yjs (v13) with BlockNote (based on `yjs` & `y-prosemirror`). Given that we are going to support both Yjs v13 & v14, we need to have a way to support both versions independently.
4
+
5
+ If you want to use Yjs v14, you can use the `@blocknote/core/y` package instead which will use the `@y/y` & `@y/prosemirror` packages.