@blocknote/core 0.51.4 → 0.52.1

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
package/dist/y.js ADDED
@@ -0,0 +1,989 @@
1
+ import { D as e, jt as t, vn as n } from "./blocks-CiuUGa1E.js";
2
+ import { i as r, n as i, t as a } from "./BlockNoteExtension-B_IEJHS8.js";
3
+ import { _ as o, h as s, v as c, y as l } from "./src-DTF83Cl9.js";
4
+ import { a as u, i as d, o as f } from "./extensions-CrUGDOks.js";
5
+ import { n as p } from "./UserStore-QbbPFj0z.js";
6
+ import { t as m } from "./ThreadStore-et9wB5Xt.js";
7
+ import { Mark as h, getChangedRanges as g, getMarkRange as _, posToDOMRect as ee } from "@tiptap/core";
8
+ import { uint32 as te, uuidv4 as v } from "lib0/random";
9
+ import { Plugin as ne, PluginKey as re } from "prosemirror-state";
10
+ import { acceptAllChanges as ie, acceptChanges as ae, configureYProsemirror as y, defaultSelectionBuilder as oe, deltaAttributionToFormat as se, deltaToPNode as ce, deltaToPSteps as le, docToDelta as b, nodeToDelta as x, pauseSync as ue, pmToFragment as de, rejectAllChanges as fe, rejectChanges as pe, relativePositionStore as me, syncPlugin as he, yCursorPlugin as ge, ySyncPluginKey as S } from "@y/prosemirror";
11
+ import * as C from "lib0/delta";
12
+ import * as w from "@y/y";
13
+ import { decodeAny as T, encodeAny as E } from "lib0/buffer";
14
+ //#region src/y/extensions/YAttributionMarks.ts
15
+ var D = (e, t) => e === void 0 ? void 0 : typeof e == "string" ? e : e[t], O = (e, t) => ({ mark: n, inline: r }) => {
16
+ let i = t?.editor, a = e === "insert" ? "ins" : e === "delete" ? "del" : r ? "span" : "div", s = document.createElement(a);
17
+ Object.assign(s.dataset, {
18
+ userIds: JSON.stringify(n.attrs.userIds),
19
+ inline: String(r)
20
+ }), e === "modification" && (s.dataset.type = "modification", s.dataset.format = JSON.stringify(n.attrs.format));
21
+ let u = D(t?.getAttributionMarkClassName?.({
22
+ contentType: r ? "inline-content" : "block",
23
+ modificationType: e === "modification" ? "format" : e
24
+ }), "content"), d = (n.attrs.userIds ?? [])[0], f = d ? o(d) : c[0];
25
+ if (u) s.style.cssText = "display: contents";
26
+ else {
27
+ let e = d ? `var(${l(d).light}, ${f.light})` : f.light, t = d ? `var(${l(d).dark}, ${f.dark})` : f.dark;
28
+ s.style.cssText = `display: contents; --user-color-light: ${e}; --user-color-dark: ${t}`;
29
+ }
30
+ let p = document.createElement("span");
31
+ if (r) p.className = u ?? (e === "delete" ? "bn-suggestion-mark bn-suggestion-mark--delete" : "bn-suggestion-mark");
32
+ else if (p.style.display = "contents", p.className = u ?? (e === "delete" ? "bn-suggestion-node bn-suggestion-node--delete" : "bn-suggestion-node"), e === "delete") {
33
+ let e = i?.dictionary.suggestion_changes.deleted;
34
+ e && p.style.setProperty("--deleted-label", JSON.stringify(e));
35
+ }
36
+ return s.appendChild(p), {
37
+ dom: s,
38
+ contentDOM: p
39
+ };
40
+ }, k = h.create({
41
+ name: "y-attributed-insert",
42
+ inclusive: !1,
43
+ excludes: "",
44
+ group: `${e} ${r}`,
45
+ addAttributes() {
46
+ return { userIds: { default: null } };
47
+ },
48
+ addMarkView() {
49
+ return O("insert", { getAttributionMarkClassName: this.options.getAttributionMarkClassName });
50
+ },
51
+ extendMarkSchema(e) {
52
+ return e.name === this.name ? { blocknoteIgnore: !0 } : {};
53
+ }
54
+ }), _e = h.create({
55
+ name: "y-attributed-delete",
56
+ inclusive: !1,
57
+ excludes: "",
58
+ group: `${e} ${r}`,
59
+ addAttributes() {
60
+ return { userIds: { default: null } };
61
+ },
62
+ addMarkView() {
63
+ return O("delete", {
64
+ editor: this.options.editor,
65
+ getAttributionMarkClassName: this.options.getAttributionMarkClassName
66
+ });
67
+ },
68
+ extendMarkSchema(e) {
69
+ return e.name === this.name ? { blocknoteIgnore: !0 } : {};
70
+ }
71
+ }), A = h.create({
72
+ name: "y-attributed-format",
73
+ inclusive: !1,
74
+ excludes: "",
75
+ group: `${e} ${r}`,
76
+ addAttributes() {
77
+ return {
78
+ userIds: { default: null },
79
+ format: { default: null }
80
+ };
81
+ },
82
+ addMarkView() {
83
+ return O("modification", { getAttributionMarkClassName: this.options.getAttributionMarkClassName });
84
+ },
85
+ extendMarkSchema(e) {
86
+ return e.name === this.name ? { blocknoteIgnore: !0 } : {};
87
+ }
88
+ }), j = a(({ options: e }) => ({
89
+ key: "yAttributionMarks",
90
+ tiptapExtensions: [
91
+ k.configure({ getAttributionMarkClassName: e?.getAttributionMarkClassName }),
92
+ _e.configure({ getAttributionMarkClassName: e?.getAttributionMarkClassName }),
93
+ A.configure({ getAttributionMarkClassName: e?.getAttributionMarkClassName })
94
+ ]
95
+ })), ve = {
96
+ "y-attributed-insert": "insert",
97
+ "y-attributed-delete": "delete",
98
+ "y-attributed-format": "format"
99
+ }, ye = new re("attributionLoadUsers"), M = "[data-user-ids]", N = (e) => {
100
+ if (!e) return [];
101
+ let t;
102
+ try {
103
+ t = JSON.parse(e);
104
+ } catch {
105
+ return [];
106
+ }
107
+ return Array.isArray(t) ? t.map(String) : [];
108
+ }, P = (e) => {
109
+ if (!e) return [];
110
+ let t;
111
+ try {
112
+ t = JSON.parse(e);
113
+ } catch {
114
+ return [];
115
+ }
116
+ return typeof t != "object" || !t ? [] : Object.keys(t);
117
+ }, F = (e) => {
118
+ let t = e.firstElementChild ?? e, n = t.getBoundingClientRect();
119
+ return n.width || n.height ? t : t.firstElementChild ?? t;
120
+ }, be = (e) => F(e).getBoundingClientRect(), xe = (e) => F(e).getClientRects(), I = a(({ options: e }) => {
121
+ let t = p(e?.resolveUsers), n = e?.getAttributionMarkClassName, r = i(void 0), a = (e) => {
122
+ let n = g(e);
123
+ if (n.length === 0) return;
124
+ let r = Infinity, i = -Infinity;
125
+ for (let { newRange: e } of n) r = Math.min(r, e.from), i = Math.max(i, e.to);
126
+ let a = /* @__PURE__ */ new Set();
127
+ e.doc.nodesBetween(r, i, (e) => {
128
+ for (let t of e.marks) ve[t.type.name] && t.attrs.userIds?.forEach((e) => a.add(e));
129
+ return !0;
130
+ }), a.size > 0 && t.loadUsers(Array.from(a));
131
+ };
132
+ return {
133
+ key: "attribution",
134
+ userStore: t,
135
+ store: r,
136
+ prosemirrorPlugins: [new ne({
137
+ key: ye,
138
+ state: {
139
+ init: () => null,
140
+ apply: (e) => (e.docChanged && a(e), null)
141
+ }
142
+ })],
143
+ mount({ dom: e, root: i, signal: a }) {
144
+ let o = () => {
145
+ for (let [n, r] of t.store.state) {
146
+ let { light: t, dark: i } = l(n);
147
+ r.color && r.colorLight ? (e.style.setProperty(t, r.colorLight), e.style.setProperty(i, r.color)) : (e.style.removeProperty(t), e.style.removeProperty(i));
148
+ }
149
+ }, c, u = (e) => N(e).map((e) => t.getUser(e)?.username ?? e), d = (e) => {
150
+ let t = N(e.dataset.userIds);
151
+ return t.length === 0 ? "" : `${P(e.dataset.format).join(",")}:${t.join(",")}`;
152
+ }, f = (e) => {
153
+ let r = e.dataset.format !== void 0, i = r ? "format" : e.tagName === "INS" ? "insert" : "delete", a = e.dataset.inline === "false" ? "block" : "inline-content";
154
+ return {
155
+ anchor: e,
156
+ color: s(t, N(e.dataset.userIds)).dark,
157
+ modificationType: i,
158
+ contentType: a,
159
+ users: u(e.dataset.userIds),
160
+ format: r ? P(e.dataset.format) : void 0,
161
+ className: D(n?.({
162
+ contentType: a,
163
+ modificationType: i
164
+ }), "tooltip")
165
+ };
166
+ }, p = () => {
167
+ c && (c = void 0, r.setState(void 0));
168
+ }, m = (e) => {
169
+ for (; e;) {
170
+ let t = e.closest(M);
171
+ if (!t) return;
172
+ if (d(t)) return t;
173
+ e = t.parentElement;
174
+ }
175
+ };
176
+ i.addEventListener("mouseover", (e) => {
177
+ let n = m(e.target instanceof Element ? e.target : null);
178
+ if (!n) {
179
+ p();
180
+ return;
181
+ }
182
+ let i = d(n), a = n, o = n.parentElement;
183
+ for (; o;) {
184
+ let e = o.closest(M);
185
+ if (!e) break;
186
+ let t = d(e);
187
+ if (t === i) a = e;
188
+ else if (t) break;
189
+ o = e.parentElement;
190
+ }
191
+ if (c === a) return;
192
+ c = a, r.setState(f(a));
193
+ let s = N(a.dataset.userIds);
194
+ s.length > 0 && t.loadUsers(s).then(() => {
195
+ c === a && r.setState(f(a));
196
+ });
197
+ }, { signal: a }), a.addEventListener("abort", p), o();
198
+ let h = t.store.subscribe(o);
199
+ a.addEventListener("abort", h);
200
+ },
201
+ blockNoteExtensions: [j({ getAttributionMarkClassName: e?.getAttributionMarkClassName })]
202
+ };
203
+ }), L = a(({ editor: e }) => ({
204
+ key: "yPositionMapping",
205
+ mapPosition: (t, n = "left") => {
206
+ let r = S.getState(e.prosemirrorState);
207
+ if (!r?.ytype) throw Error("YSync plugin state not found");
208
+ if (t === 0) return () => 0;
209
+ let i = me(e.prosemirrorState.doc.resolve(t + (n === "right" ? 1 : -1)), r.ytype, r.renderer);
210
+ return () => {
211
+ let t = S.getState(e.prosemirrorState), r = i(e.prosemirrorState.doc, t.ytype, t.renderer);
212
+ if (r === null) throw Error("Position not found, cannot track positions");
213
+ return r + (n === "right" ? -1 : 1);
214
+ };
215
+ }
216
+ })), R = (e) => {
217
+ for (let t of e.children) if (C.$insertOp.check(t)) {
218
+ for (let e of t.insert) if (C.$deltaAny.check(e)) return e;
219
+ }
220
+ return null;
221
+ }, z = (e) => {
222
+ for (let t of e.children) if (C.$insertOp.check(t)) {
223
+ for (let e of t.insert) if (C.$deltaAny.check(e) && e.name === "blockGroup") return !0;
224
+ }
225
+ return !1;
226
+ };
227
+ function B(e) {
228
+ if (e.name !== "table") return null;
229
+ let t = [];
230
+ for (let n of e.children) if (C.$insertOp.check(n)) for (let e of n.insert) {
231
+ if (e.name !== "tableRow") return null;
232
+ let n = [];
233
+ for (let t of e.children) if (C.$insertOp.check(t)) for (let e of t.insert) {
234
+ if (e.name !== "tableCell" && e.name !== "tableHeader") return null;
235
+ n.push({
236
+ colspan: Number(e.attrs.colspan) || 1,
237
+ rowspan: Number(e.attrs.rowspan) || 1
238
+ });
239
+ }
240
+ t.push(n);
241
+ }
242
+ if (t.length === 0) return null;
243
+ let n = [];
244
+ for (let e = 0; e < t.length; e++) {
245
+ n[e] || (n[e] = []);
246
+ let r = 0;
247
+ for (let i of t[e]) {
248
+ for (; n[e][r];) r++;
249
+ for (let t = 0; t < i.rowspan; t++) {
250
+ n[e + t] || (n[e + t] = []);
251
+ for (let a = 0; a < i.colspan; a++) n[e + t][r + a] = !0;
252
+ }
253
+ r += i.colspan;
254
+ }
255
+ }
256
+ let r = Math.max(...n.map((e) => e.length));
257
+ return {
258
+ rows: t.length,
259
+ cols: r
260
+ };
261
+ }
262
+ var V = (e, t) => {
263
+ if (e.name !== t.name) return !1;
264
+ if (e.name !== "blockContainer") return !0;
265
+ let n = R(e), r = R(t);
266
+ if (n?.name !== r?.name || z(e) !== z(t)) return !1;
267
+ if (n?.name === "table" && r?.name === "table") {
268
+ let e = B(n), t = B(r);
269
+ if (e !== null && t !== null && e.rows !== t.rows && e.cols !== t.cols) return !1;
270
+ }
271
+ return !0;
272
+ }, H = (e, t) => {
273
+ let n = { ...e };
274
+ return t.insert && (n["y-attributed-insert"] = { userIds: t.insert }), t.delete && (n["y-attributed-delete"] = { userIds: t.delete }), t.format && (n["y-attributed-format"] = {
275
+ userIds: [...new Set(Object.values(t.format).flat())],
276
+ format: t.format
277
+ }), n;
278
+ }, U = a(({ options: e, editor: t }) => ({
279
+ key: "ySync",
280
+ fragment: e.fragment,
281
+ mount: () => {
282
+ let n = () => {
283
+ t.exec(y({ ytype: e.fragment }));
284
+ };
285
+ if (e.provider && "synced" in e.provider && typeof e.provider.synced == "boolean") if (e.provider.synced) n();
286
+ else if ("on" in e.provider && typeof e.provider.on == "function") e.provider.on("synced", (e) => {
287
+ e && n();
288
+ });
289
+ else throw Error("YSyncExtension: provider must have a 'synced' boolean or an 'on' method to listen for 'sync'");
290
+ else n();
291
+ },
292
+ prosemirrorPlugins: [he({
293
+ suggestionDoc: e.suggestionDoc,
294
+ mapAttributionToMark: H,
295
+ customCompare: V
296
+ })],
297
+ runsBefore: ["default"]
298
+ }));
299
+ //#endregion
300
+ //#region src/y/utils.ts
301
+ function W(e, t) {
302
+ let n = e.doc;
303
+ if (!n) throw Error("type does not have a ydoc");
304
+ if (e._item === null) {
305
+ let r = Array.from(n.share.keys()).find((t) => n.share.get(t) === e);
306
+ if (r == null) throw Error("type does not exist in other ydoc");
307
+ return t.get(r, e.constructor);
308
+ } else {
309
+ let n = e._item, r = t.store.clients.get(n.id.client) ?? [], i = r[w.findIndexSS(r, n.id.clock)];
310
+ if (!i) throw Error("type does not exist in other ydoc");
311
+ let a = i.content;
312
+ if (!a) throw Error("type does not exist in other ydoc");
313
+ return a.type;
314
+ }
315
+ }
316
+ function Se(e, t) {
317
+ return n(e.pmSchema.nodeFromJSON(t));
318
+ }
319
+ function G(e, n) {
320
+ let r = n.map((n) => t(n, e.pmSchema));
321
+ return e.pmSchema.topNodeType.create(null, e.pmSchema.nodes.blockGroup.create(null, r));
322
+ }
323
+ function K(e, t) {
324
+ let r = ce(t.toDeltaDeep(), e.pmSchema, null);
325
+ return r === null ? [] : n(r);
326
+ }
327
+ function Ce(e, t, n) {
328
+ return n ||= new w.Doc().get("prosemirror"), de(G(e, t), n);
329
+ }
330
+ function we(e, t, n = "prosemirror") {
331
+ return K(e, t.get(n));
332
+ }
333
+ function Te(e, t, n = "prosemirror") {
334
+ let r = b(G(e, t)), i = new w.Doc();
335
+ return i.get(n).applyDelta(r), i;
336
+ }
337
+ function q(e, t) {
338
+ let n = x(e), r = x(t);
339
+ return C.diff(n.done(), r.done(), { compare: V });
340
+ }
341
+ function J({ tr: e, fragment: t, renderer: n }) {
342
+ let r = se(t.toDeltaDeep({ renderer: n }), H), i = x(e.doc, void 0, !0);
343
+ return le(e, C.diff(i.done(), r.done(), { compare: V }), void 0, void 0);
344
+ }
345
+ //#endregion
346
+ //#region src/y/extensions/Suggestions.ts
347
+ var Ee = a(({ editor: e, options: t }) => {
348
+ let n = t.suggestionDoc;
349
+ if (!n) throw Error("Suggestion doc not found");
350
+ let r = p(t.resolveUsers);
351
+ function i(t) {
352
+ let n = e.prosemirrorView.nodeDOM(t);
353
+ for (; n && n.parentElement;) {
354
+ if (n.nodeName === "INS" || n.nodeName === "DEL") return n;
355
+ n = n.parentElement;
356
+ }
357
+ return null;
358
+ }
359
+ function a(t, n) {
360
+ return e.transact((r) => {
361
+ let i = r.doc.resolve(t), a = i.marks().find((e) => e.type.name === n);
362
+ if (!a) return;
363
+ let o = _(i, a.type);
364
+ if (o) return {
365
+ range: o,
366
+ mark: a,
367
+ get text() {
368
+ return r.doc.textBetween(o.from, o.to);
369
+ },
370
+ get position() {
371
+ return ee(e.prosemirrorView, o.from, o.to).toJSON();
372
+ }
373
+ };
374
+ });
375
+ }
376
+ function o() {
377
+ return e.transact((e) => {
378
+ let t = e.selection;
379
+ if (t.empty) return a(t.anchor, "insertion") || a(t.anchor, "deletion") || a(t.anchor, "modification");
380
+ });
381
+ }
382
+ return {
383
+ key: "suggestions",
384
+ userStore: r,
385
+ runsBefore: ["ySync"],
386
+ viewSuggestions: () => {
387
+ t.renderer && (t.renderer.suggestionMode = !1), e.exec(y({
388
+ ytype: W(t.fragment, n),
389
+ renderer: t.renderer
390
+ }));
391
+ },
392
+ enableSuggestions: () => {
393
+ t.renderer && (t.renderer.suggestionMode = !0), e.exec(y({
394
+ ytype: W(t.fragment, n),
395
+ renderer: t.renderer
396
+ }));
397
+ },
398
+ disableSuggestions: () => {
399
+ e.exec(y({
400
+ ytype: t.fragment,
401
+ renderer: null
402
+ }));
403
+ },
404
+ applyAllSuggestions: () => e.exec(ie()),
405
+ applySuggestion: (t, n) => e.exec(ae(t, n)),
406
+ revertSuggestion: (t, n) => e.exec(pe(t, n)),
407
+ revertAllSuggestions: () => e.exec(fe()),
408
+ getSuggestionElementAtPos: i,
409
+ getMarkAtPos: a,
410
+ getSuggestionAtSelection: o,
411
+ getSuggestionAtCoords: (t) => e.transact(() => {
412
+ let n = e.prosemirrorView.posAtCoords(t);
413
+ if (!(n === null || n?.inside === -1)) return a(n.pos, "y-attributed-insert") || a(n.pos, "y-attributed-delete") || a(n.pos, "y-attributed-format");
414
+ }),
415
+ checkUnresolvedSuggestions: () => {
416
+ let t = !1;
417
+ return e.prosemirrorState.doc.descendants((e) => t ? !1 : (t = e.marks.findIndex((e) => e.type.name === "y-attributed-insert" || e.type.name === "y-attributed-delete" || e.type.name === "y-attributed-format") !== -1, !0)), t;
418
+ }
419
+ };
420
+ });
421
+ //#endregion
422
+ //#region src/y/extensions/Versioning.ts
423
+ function De(e) {
424
+ e.exec(ue), e.removeBlocks(e.document);
425
+ }
426
+ function Oe(e, t) {
427
+ return {
428
+ getCurrentDocument: () => t,
429
+ serializeCurrentContent: () => w.encodeStateAsUpdateV2(t.doc),
430
+ preview: {
431
+ enterPreview: (n, r, i) => {
432
+ let a;
433
+ if (r) {
434
+ let e = new w.Doc({ isSuggestionDoc: !0 });
435
+ w.applyUpdateV2(e, r), a = { fragment: W(t, e) };
436
+ }
437
+ let o = new w.Doc();
438
+ w.applyUpdateV2(o, n), De(e), e.exec((e, n) => {
439
+ let r = J({
440
+ tr: e.tr,
441
+ fragment: W(t, o),
442
+ renderer: a ? w.createDiffRenderer(a.fragment.doc, o, i ? { attrs: i } : void 0) : void 0
443
+ });
444
+ return n && n(r), !0;
445
+ });
446
+ },
447
+ exitPreview: () => {
448
+ De(e), e.exec(y({ ytype: t }));
449
+ },
450
+ applyRestore: (e) => {}
451
+ }
452
+ };
453
+ }
454
+ //#endregion
455
+ //#region src/y/extensions/YCursorPlugin.ts
456
+ function ke(e) {
457
+ let t = e.charAt(0) === "#" ? e.substring(1, 7) : e, n = parseInt(t.substring(0, 2), 16), r = parseInt(t.substring(2, 4), 16), i = parseInt(t.substring(4, 6), 16), a = [
458
+ n / 255,
459
+ r / 255,
460
+ i / 255
461
+ ].map((e) => e <= .03928 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4);
462
+ return .2126 * a[0] + .7152 * a[1] + .0722 * a[2] <= .179;
463
+ }
464
+ function Ae(e) {
465
+ let t = document.createElement("span");
466
+ t.classList.add("bn-collaboration-cursor__base");
467
+ let n = document.createElement("span");
468
+ n.setAttribute("contentedEditable", "false"), n.classList.add("bn-collaboration-cursor__caret"), n.setAttribute("style", `background-color: ${e.color}; color: ${ke(e.color) ? "white" : "black"}`);
469
+ let r = document.createElement("span");
470
+ return r.classList.add("bn-collaboration-cursor__label"), r.setAttribute("style", `background-color: ${e.color}; color: ${ke(e.color) ? "white" : "black"}`), r.insertBefore(document.createTextNode(e.name), null), n.insertBefore(r, null), t.insertBefore(document.createTextNode("⁠"), null), t.insertBefore(n, null), t.insertBefore(document.createTextNode("⁠"), null), t;
471
+ }
472
+ var je = a(({ options: e }) => {
473
+ let t = /* @__PURE__ */ new Map(), n = e.provider && "awareness" in e.provider && typeof e.provider.awareness == "object" ? e.provider.awareness : void 0;
474
+ return n && ("setLocalStateField" in n && typeof n.setLocalStateField == "function" && n.setLocalStateField("user", e.user), "on" in n && typeof n.on == "function" && e.showCursorLabels !== "always" && n.on("change", ({ updated: e }) => {
475
+ for (let n of e) {
476
+ let e = t.get(n);
477
+ e && (setTimeout(() => {
478
+ e.element.setAttribute("data-active", "");
479
+ }, 10), e.hideTimeout && clearTimeout(e.hideTimeout), t.set(n, {
480
+ element: e.element,
481
+ hideTimeout: setTimeout(() => {
482
+ e.element.removeAttribute("data-active");
483
+ }, 2e3)
484
+ }));
485
+ }
486
+ })), {
487
+ key: "yCursor",
488
+ prosemirrorPlugins: [n ? ge(n, {
489
+ selectionBuilder: oe,
490
+ cursorBuilder(n, r) {
491
+ let i = t.get(r);
492
+ if (!i) {
493
+ let a = (e.renderCursor ?? Ae)(n);
494
+ e.showCursorLabels !== "always" && (a.addEventListener("mouseenter", () => {
495
+ let e = t.get(r);
496
+ e.element.setAttribute("data-active", ""), e.hideTimeout && (clearTimeout(e.hideTimeout), t.set(r, {
497
+ element: e.element,
498
+ hideTimeout: void 0
499
+ }));
500
+ }), a.addEventListener("mouseleave", () => {
501
+ let e = t.get(r);
502
+ t.set(r, {
503
+ element: e.element,
504
+ hideTimeout: setTimeout(() => {
505
+ e.element.removeAttribute("data-active");
506
+ }, 2e3)
507
+ });
508
+ })), i = {
509
+ element: a,
510
+ hideTimeout: void 0
511
+ }, t.set(r, i);
512
+ }
513
+ return i.element;
514
+ }
515
+ }) : void 0].filter((e) => e !== void 0),
516
+ dependsOn: ["ySync"],
517
+ updateUser(e) {
518
+ n?.setLocalStateField("user", e);
519
+ },
520
+ getUser() {
521
+ let e = n?.getLocalState();
522
+ if (e) return e.user;
523
+ }
524
+ };
525
+ }), Me = "version:", Ne = (e) => Me + e, Pe = "This version", Fe = "#4363d8";
526
+ function Ie(e, t) {
527
+ let n = new w.Attributions();
528
+ return e.on("beforeObserverCalls", (e) => {
529
+ e.insertSet.isEmpty() || w.insertIntoIdMap(n.inserts, w.createIdMapFromIdSet(e.insertSet, [w.createContentAttribute("insert", t)])), e.deleteSet.isEmpty() || w.insertIntoIdMap(n.deletes, w.createIdMapFromIdSet(e.deleteSet, [w.createContentAttribute("delete", t)]));
530
+ }), n;
531
+ }
532
+ var Le = a(({ options: e, editor: t }) => {
533
+ let n = e?.color ?? Fe;
534
+ return {
535
+ key: "diffVersioning",
536
+ blockNoteExtensions: [I({
537
+ resolveUsers: async (e) => e.filter((e) => e.startsWith(Me)).map((e) => ({
538
+ id: e,
539
+ username: e.slice(8),
540
+ avatarUrl: "",
541
+ color: n
542
+ })),
543
+ getAttributionMarkClassName: e?.getAttributionMarkClassName
544
+ })],
545
+ renderDiff: (e, n, r = Pe) => {
546
+ let i = Ne(r);
547
+ if (!t.pmSchema.marks["y-attributed-insert"]) throw Error("DiffVersioningExtension: the y-attributed-* marks are missing from the schema. This should not happen — the extension registers them via AttributionExtension.");
548
+ let a = G(t, n), o = G(t, e), s = new w.Doc({ gc: !1 }), c = s.get("prosemirror");
549
+ s.transact(() => {
550
+ c.applyDelta(b(a));
551
+ });
552
+ let l = new w.Doc({ gc: !1 });
553
+ w.applyUpdateV2(l, w.encodeStateAsUpdateV2(s));
554
+ let u = W(c, l), d = Ie(l, i), f = q(a, o);
555
+ l.transact(() => {
556
+ u.applyDelta(f);
557
+ }, i);
558
+ let p = w.createDiffRenderer(s, l, { attrs: d });
559
+ t.replaceBlocks(t.document, []), t.exec((e, t) => {
560
+ let n = J({
561
+ tr: e.tr,
562
+ fragment: u,
563
+ renderer: p
564
+ });
565
+ return t && t(n), !0;
566
+ }), s.destroy(), l.destroy();
567
+ },
568
+ clearDiff: (e) => {
569
+ t.replaceBlocks(t.document, []), t.replaceBlocks(t.document, e);
570
+ }
571
+ };
572
+ }), Re = a(({ editor: e, options: t }) => {
573
+ let n = p(t.resolveUsers), r = {
574
+ ...t,
575
+ resolveUsers: n
576
+ };
577
+ return {
578
+ key: "collaboration",
579
+ userStore: n,
580
+ blockNoteExtensions: [
581
+ t.suggestionDoc ? Ee(r) : null,
582
+ L(),
583
+ U(r),
584
+ je(t),
585
+ t.versioningEndpoints ? u({
586
+ ...Oe(e, t.fragment),
587
+ endpoints: t.versioningEndpoints,
588
+ resolveUsers: n
589
+ }) : null,
590
+ I({
591
+ resolveUsers: n,
592
+ getAttributionMarkClassName: t.getAttributionMarkClassName
593
+ })
594
+ ].filter((e) => e !== null)
595
+ };
596
+ });
597
+ function ze(e) {
598
+ return e.initialContent && console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider"), {
599
+ ...e,
600
+ extensions: [...e.extensions ?? [], Re(e.collaboration)],
601
+ disableExtensions: ["history", ...e.disableExtensions ?? []],
602
+ initialContent: [{
603
+ type: "paragraph",
604
+ id: "initialBlockId"
605
+ }]
606
+ };
607
+ }
608
+ //#endregion
609
+ //#region src/y/comments/yjsHelpers.ts
610
+ function Be(e) {
611
+ let t = new w.Type();
612
+ if (t.setAttr("id", e.id), t.setAttr("userId", e.userId), t.setAttr("createdAt", e.createdAt.getTime()), t.setAttr("updatedAt", e.updatedAt.getTime()), e.deletedAt ? (t.setAttr("deletedAt", e.deletedAt.getTime()), t.setAttr("body", void 0)) : t.setAttr("body", e.body), e.reactions.length > 0) throw Error("Reactions should be empty in commentToYType");
613
+ return t.setAttr("reactionsByUser", new w.Type()), t.setAttr("metadata", e.metadata), t;
614
+ }
615
+ function Ve(e) {
616
+ let t = new w.Type();
617
+ t.setAttr("id", e.id), t.setAttr("createdAt", e.createdAt.getTime()), t.setAttr("updatedAt", e.updatedAt.getTime());
618
+ let n = new w.Type();
619
+ return n.push(e.comments.map((e) => Be(e))), t.setAttr("comments", n), t.setAttr("resolved", e.resolved), t.setAttr("resolvedUpdatedAt", e.resolvedUpdatedAt?.getTime()), t.setAttr("resolvedBy", e.resolvedBy), t.setAttr("metadata", e.metadata), t;
620
+ }
621
+ function He(e) {
622
+ return {
623
+ emoji: e.getAttr("emoji"),
624
+ createdAt: new Date(e.getAttr("createdAt")),
625
+ userId: e.getAttr("userId")
626
+ };
627
+ }
628
+ function Ue(e) {
629
+ return [...e.attrValues()].map((e) => He(e)).reduce((e, t) => {
630
+ let n = e.find((e) => e.emoji === t.emoji);
631
+ return n ? (n.userIds.push(t.userId), n.createdAt = new Date(Math.min(n.createdAt.getTime(), t.createdAt.getTime()))) : e.push({
632
+ emoji: t.emoji,
633
+ createdAt: t.createdAt,
634
+ userIds: [t.userId]
635
+ }), e;
636
+ }, []);
637
+ }
638
+ function Y(e) {
639
+ return {
640
+ type: "comment",
641
+ id: e.getAttr("id"),
642
+ userId: e.getAttr("userId"),
643
+ createdAt: new Date(e.getAttr("createdAt")),
644
+ updatedAt: new Date(e.getAttr("updatedAt")),
645
+ deletedAt: e.getAttr("deletedAt") ? new Date(e.getAttr("deletedAt")) : void 0,
646
+ reactions: Ue(e.getAttr("reactionsByUser")),
647
+ metadata: e.getAttr("metadata"),
648
+ body: e.getAttr("body")
649
+ };
650
+ }
651
+ function X(e) {
652
+ return {
653
+ type: "thread",
654
+ id: e.getAttr("id"),
655
+ createdAt: new Date(e.getAttr("createdAt")),
656
+ updatedAt: new Date(e.getAttr("updatedAt")),
657
+ comments: (e.getAttr("comments")?.toArray() || []).map((e) => Y(e)),
658
+ resolved: e.getAttr("resolved"),
659
+ resolvedUpdatedAt: new Date(e.getAttr("resolvedUpdatedAt")),
660
+ resolvedBy: e.getAttr("resolvedBy"),
661
+ metadata: e.getAttr("metadata")
662
+ };
663
+ }
664
+ //#endregion
665
+ //#region src/y/comments/YjsThreadStoreBase.ts
666
+ var Z = class extends m {
667
+ threadsYType;
668
+ constructor(e, t) {
669
+ super(t), this.threadsYType = e;
670
+ }
671
+ getThread(e) {
672
+ let t = this.threadsYType.getAttr(e);
673
+ if (!t) throw Error("Thread not found");
674
+ return X(t);
675
+ }
676
+ getThreads() {
677
+ let e = /* @__PURE__ */ new Map();
678
+ return this.threadsYType.forEachAttr((t, n) => {
679
+ t instanceof w.Type && e.set(String(n), X(t));
680
+ }), e;
681
+ }
682
+ subscribe(e) {
683
+ let t = () => {
684
+ e(this.getThreads());
685
+ };
686
+ return this.threadsYType.observeDeep(t), () => {
687
+ this.threadsYType.unobserveDeep(t);
688
+ };
689
+ }
690
+ }, We = class extends Z {
691
+ BASE_URL;
692
+ headers;
693
+ constructor(e, t, n, r) {
694
+ super(n, r), this.BASE_URL = e, this.headers = t;
695
+ }
696
+ doRequest = async (e, t, n) => {
697
+ let r = await fetch(`${this.BASE_URL}${e}`, {
698
+ method: t,
699
+ body: JSON.stringify(n),
700
+ headers: {
701
+ "Content-Type": "application/json",
702
+ ...this.headers
703
+ }
704
+ });
705
+ if (!r.ok) throw Error(`Failed to ${t} ${e}: ${r.statusText}`);
706
+ return r.json();
707
+ };
708
+ addThreadToDocument = async (e) => {
709
+ let { threadId: t, ...n } = e;
710
+ return this.doRequest(`/${t}/addToDocument`, "POST", n);
711
+ };
712
+ createThread = async (e) => this.doRequest("", "POST", e);
713
+ addComment = (e) => {
714
+ let { threadId: t, ...n } = e;
715
+ return this.doRequest(`/${t}/comments`, "POST", n);
716
+ };
717
+ updateComment = (e) => {
718
+ let { threadId: t, commentId: n, ...r } = e;
719
+ return this.doRequest(`/${t}/comments/${n}`, "PUT", r);
720
+ };
721
+ deleteComment = (e) => {
722
+ let { threadId: t, commentId: n, ...r } = e;
723
+ return this.doRequest(`/${t}/comments/${n}?soft=${!!r.softDelete}`, "DELETE");
724
+ };
725
+ deleteThread = (e) => this.doRequest(`/${e.threadId}`, "DELETE");
726
+ resolveThread = (e) => this.doRequest(`/${e.threadId}/resolve`, "POST");
727
+ unresolveThread = (e) => this.doRequest(`/${e.threadId}/unresolve`, "POST");
728
+ addReaction = (e) => {
729
+ let { threadId: t, commentId: n, ...r } = e;
730
+ return this.doRequest(`/${t}/comments/${n}/reactions`, "POST", r);
731
+ };
732
+ deleteReaction = (e) => this.doRequest(`/${e.threadId}/comments/${e.commentId}/reactions/${e.emoji}`, "DELETE");
733
+ }, Ge = class extends Z {
734
+ userId;
735
+ constructor(e, t, n) {
736
+ super(t, n), this.userId = e;
737
+ }
738
+ transact = (e) => async (t) => this.threadsYType.doc.transact(() => e(t));
739
+ createThread = this.transact((e) => {
740
+ if (!this.auth.canCreateThread()) throw Error("Not authorized");
741
+ let t = /* @__PURE__ */ new Date(), n = {
742
+ type: "comment",
743
+ id: v(),
744
+ userId: this.userId,
745
+ createdAt: t,
746
+ updatedAt: t,
747
+ reactions: [],
748
+ metadata: e.initialComment.metadata,
749
+ body: e.initialComment.body
750
+ }, r = {
751
+ type: "thread",
752
+ id: v(),
753
+ createdAt: t,
754
+ updatedAt: t,
755
+ comments: [n],
756
+ resolved: !1,
757
+ metadata: e.metadata
758
+ };
759
+ return this.threadsYType.setAttr(r.id, Ve(r)), r;
760
+ });
761
+ addThreadToDocument = void 0;
762
+ addComment = this.transact((e) => {
763
+ let t = this.threadsYType.getAttr(e.threadId);
764
+ if (!t) throw Error("Thread not found");
765
+ if (!this.auth.canAddComment(X(t))) throw Error("Not authorized");
766
+ let n = /* @__PURE__ */ new Date(), r = {
767
+ type: "comment",
768
+ id: v(),
769
+ userId: this.userId,
770
+ createdAt: n,
771
+ updatedAt: n,
772
+ deletedAt: void 0,
773
+ reactions: [],
774
+ metadata: e.comment.metadata,
775
+ body: e.comment.body
776
+ };
777
+ return t.getAttr("comments").push([Be(r)]), t.setAttr("updatedAt", (/* @__PURE__ */ new Date()).getTime()), r;
778
+ });
779
+ updateComment = this.transact((e) => {
780
+ let t = this.threadsYType.getAttr(e.threadId);
781
+ if (!t) throw Error("Thread not found");
782
+ let n = t.getAttr("comments"), r = Q(n, (t) => t.getAttr("id") === e.commentId);
783
+ if (r === -1) throw Error("Comment not found");
784
+ let i = n.get(r);
785
+ if (!this.auth.canUpdateComment(Y(i))) throw Error("Not authorized");
786
+ i.setAttr("body", e.comment.body), i.setAttr("updatedAt", (/* @__PURE__ */ new Date()).getTime()), i.setAttr("metadata", e.comment.metadata);
787
+ });
788
+ deleteComment = this.transact((e) => {
789
+ let t = this.threadsYType.getAttr(e.threadId);
790
+ if (!t) throw Error("Thread not found");
791
+ let n = t.getAttr("comments"), r = Q(n, (t) => t.getAttr("id") === e.commentId);
792
+ if (r === -1) throw Error("Comment not found");
793
+ let i = n.get(r);
794
+ if (!this.auth.canDeleteComment(Y(i))) throw Error("Not authorized");
795
+ if (i.getAttr("deletedAt")) throw Error("Comment already deleted");
796
+ e.softDelete ? (i.setAttr("deletedAt", (/* @__PURE__ */ new Date()).getTime()), i.setAttr("body", void 0)) : n.delete(r), n.toArray().every((e) => e.getAttr("deletedAt")) && (e.softDelete ? t.setAttr("deletedAt", (/* @__PURE__ */ new Date()).getTime()) : this.threadsYType.deleteAttr(e.threadId)), t.setAttr("updatedAt", (/* @__PURE__ */ new Date()).getTime());
797
+ });
798
+ deleteThread = this.transact((e) => {
799
+ if (!this.auth.canDeleteThread(X(this.threadsYType.getAttr(e.threadId)))) throw Error("Not authorized");
800
+ this.threadsYType.deleteAttr(e.threadId);
801
+ });
802
+ resolveThread = this.transact((e) => {
803
+ let t = this.threadsYType.getAttr(e.threadId);
804
+ if (!t) throw Error("Thread not found");
805
+ if (!this.auth.canResolveThread(X(t))) throw Error("Not authorized");
806
+ t.setAttr("resolved", !0), t.setAttr("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime()), t.setAttr("resolvedBy", this.userId);
807
+ });
808
+ unresolveThread = this.transact((e) => {
809
+ let t = this.threadsYType.getAttr(e.threadId);
810
+ if (!t) throw Error("Thread not found");
811
+ if (!this.auth.canUnresolveThread(X(t))) throw Error("Not authorized");
812
+ t.setAttr("resolved", !1), t.setAttr("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime());
813
+ });
814
+ addReaction = this.transact((e) => {
815
+ let t = this.threadsYType.getAttr(e.threadId);
816
+ if (!t) throw Error("Thread not found");
817
+ let n = t.getAttr("comments"), r = Q(n, (t) => t.getAttr("id") === e.commentId);
818
+ if (r === -1) throw Error("Comment not found");
819
+ let i = n.get(r);
820
+ if (!this.auth.canAddReaction(Y(i), e.emoji)) throw Error("Not authorized");
821
+ let a = /* @__PURE__ */ new Date(), o = `${this.userId}-${e.emoji}`, s = i.getAttr("reactionsByUser");
822
+ if (!s.hasAttr(o)) {
823
+ let t = new w.Type();
824
+ t.setAttr("emoji", e.emoji), t.setAttr("createdAt", a.getTime()), t.setAttr("userId", this.userId), s.setAttr(o, t);
825
+ }
826
+ });
827
+ deleteReaction = this.transact((e) => {
828
+ let t = this.threadsYType.getAttr(e.threadId);
829
+ if (!t) throw Error("Thread not found");
830
+ let n = t.getAttr("comments"), r = Q(n, (t) => t.getAttr("id") === e.commentId);
831
+ if (r === -1) throw Error("Comment not found");
832
+ let i = n.get(r);
833
+ if (!this.auth.canDeleteReaction(Y(i), e.emoji)) throw Error("Not authorized");
834
+ let a = `${this.userId}-${e.emoji}`;
835
+ i.getAttr("reactionsByUser").deleteAttr(a);
836
+ });
837
+ };
838
+ function Q(e, t) {
839
+ for (let n = 0; n < e.length; n++) if (t(e.get(n))) return n;
840
+ return -1;
841
+ }
842
+ //#endregion
843
+ //#region src/y/versioning/yhub.ts
844
+ var Ke = "__bn_version_names";
845
+ function qe(e) {
846
+ return e.customAttributions?.some((e) => e.k === "type" && e.v === "version") ?? !1;
847
+ }
848
+ function Je(e, t) {
849
+ let n = e.by?.split(",").map((e) => e.trim()).filter(Boolean), r = n && n.length > 0 ? n : void 0;
850
+ if (qe(e)) {
851
+ let t = e.customAttributions?.find((e) => e.k === "id")?.v;
852
+ return t === void 0 ? void 0 : {
853
+ id: t,
854
+ name: e.customAttributions?.find((e) => e.k === "name")?.v,
855
+ createdAt: e.to,
856
+ updatedAt: e.to,
857
+ by: r
858
+ };
859
+ }
860
+ return {
861
+ id: `history-${e.to}-${t}`,
862
+ createdAt: e.to,
863
+ updatedAt: e.to,
864
+ by: r
865
+ };
866
+ }
867
+ async function $(e, t, n) {
868
+ let r = await fetch(e, {
869
+ ...n,
870
+ headers: {
871
+ ...t,
872
+ ...n?.headers instanceof Headers ? Object.fromEntries(n.headers.entries()) : Array.isArray(n?.headers) ? Object.fromEntries(n.headers) : n?.headers
873
+ }
874
+ });
875
+ if (!r.ok) throw Error(`YHub request failed: ${r.status} ${r.statusText} (${e})`);
876
+ return r.arrayBuffer();
877
+ }
878
+ function Ye(e) {
879
+ let { baseUrl: t, org: n, docId: r, headers: i = {}, activityLimit: a = 50, group: o } = e, s = `${t}/activity/${n}/${r}`, c = `${t}/changeset/${n}/${r}`, l = `${t}/rollback/${n}/${r}`;
880
+ return (u) => {
881
+ let p = () => (u.getExtension("ySync")?.fragment.doc)?.get(Ke), m = async () => {
882
+ let e = new URLSearchParams({
883
+ order: "desc",
884
+ limit: "1",
885
+ customAttributions: "true"
886
+ }), t = new URLSearchParams({
887
+ order: "desc",
888
+ limit: "1",
889
+ customAttributions: "true",
890
+ withCustomAttributions: "type:version"
891
+ }), [n, r] = await Promise.all([$(`${s}?${e}`, i), $(`${s}?${t}`, i)]), a = T(new Uint8Array(n))[0], o = T(new Uint8Array(r))[0];
892
+ if (!a || a.to <= (o?.to ?? 0)) return;
893
+ let c = a.by?.split(",").map((e) => e.trim()).filter(Boolean) ?? [];
894
+ return {
895
+ id: d,
896
+ createdAt: a.to,
897
+ updatedAt: a.to,
898
+ by: c.length > 0 ? c : void 0
899
+ };
900
+ }, h = async (e, a, o) => {
901
+ if (!e.doc) throw Error("Cannot patch document: the Y.Type is not attached to a Y.Doc.");
902
+ let s = new w.Doc();
903
+ s.get("__bn_version_markers", "XmlFragment").insert(0, ["v"]);
904
+ let c = {
905
+ update: w.encodeStateAsUpdate(s),
906
+ customAttributions: a
907
+ };
908
+ await $(`${t}/ydoc/${n}/${r}${o ? `?userid=${o}` : ""}`, i, {
909
+ method: "PATCH",
910
+ body: E(c)
911
+ });
912
+ }, g = async (e, t) => {
913
+ let n = String(te()), r = Date.now();
914
+ t?.name && p()?.setAttr(n, t.name);
915
+ let i = [{
916
+ k: "type",
917
+ v: "version"
918
+ }, {
919
+ k: "id",
920
+ v: n
921
+ }];
922
+ t?.name && i.push({
923
+ k: "name",
924
+ v: t.name
925
+ });
926
+ let a = u.getExtension("yCursor")?.getUser();
927
+ return await h(e, i, a?.id), {
928
+ id: n,
929
+ name: t?.name,
930
+ createdAt: r,
931
+ updatedAt: r,
932
+ by: a?.id
933
+ };
934
+ }, _ = async (e) => {
935
+ let t = await $(`${c}?${new URLSearchParams({
936
+ ydoc: "true",
937
+ to: String(e)
938
+ })}`, i), n = T(new Uint8Array(t));
939
+ if (!n.nextDoc) throw Error(`YHub returned no document state at timestamp ${e}.`);
940
+ return w.convertUpdateFormatV1ToV2(n.nextDoc);
941
+ };
942
+ return {
943
+ list: async () => {
944
+ let t = e.groupMaxGap ?? 1e4, n = e.groupMaxDuration, r = e.mergeUsers, c = new URLSearchParams({
945
+ order: "desc",
946
+ limit: String(a),
947
+ customAttributions: "true"
948
+ });
949
+ c.set("groupMaxGap", String(t)), o !== void 0 && c.set("group", String(o)), n !== void 0 && c.set("groupMaxDuration", String(n)), r !== void 0 && c.set("mergeUsers", String(r));
950
+ let l = await $(`${s}?${c}`, i), u = f(T(new Uint8Array(l)).map((e, t) => Je(e, t)).filter((e) => e !== void 0).map((e) => {
951
+ let t = e.name, n = (typeof e.id == "string" ? p()?.getAttr(e.id) : void 0) ?? t;
952
+ return {
953
+ ...e,
954
+ name: n
955
+ };
956
+ })), d = await m();
957
+ return d ? [d, ...u] : u;
958
+ },
959
+ create: g,
960
+ getContent: async (e) => _(e.createdAt),
961
+ getAttributions: async (e, t) => {
962
+ let n = e.createdAt, r = t === void 0 ? 0 : t.createdAt, a = await $(`${c}?${new URLSearchParams({
963
+ from: String(r),
964
+ to: String(n),
965
+ attributions: "true"
966
+ })}`, i), o = T(new Uint8Array(a));
967
+ if (!o.attributions) throw Error(`YHub returned no attributions for snapshot ${String(e.id)}.`);
968
+ return w.decodeContentMap(o.attributions);
969
+ },
970
+ restore: async (e, t) => {
971
+ let n = t.createdAt, r = await _(n);
972
+ return await $(`${l}?from=${n}`, i, {
973
+ method: "POST",
974
+ body: E({ from: n })
975
+ }), r;
976
+ },
977
+ rename: async (e, t) => {
978
+ if (typeof e.id != "string") return;
979
+ let n = p();
980
+ if (!n) throw Error("Cannot rename version: no live collaboration document is available.");
981
+ t === void 0 || t === "" ? n.deleteAttr(e.id) : n.setAttr(e.id, t);
982
+ }
983
+ };
984
+ };
985
+ }
986
+ //#endregion
987
+ export { I as AttributionExtension, Re as CollaborationExtension, Le as DiffVersioningExtension, We as RESTYjsThreadStore, L as RelativePositionMappingExtension, Ee as SuggestionsExtension, _e as YAttributedDeletion, A as YAttributedFormat, k as YAttributedInsertion, j as YAttributionMarksExtension, je as YCursorExtension, U as YSyncExtension, Ge as YjsThreadStore, Z as YjsThreadStoreBase, G as _blocksToProsemirrorNode, Se as _prosemirrorJSONToBlocks, Te as blocksToYDoc, Ce as blocksToYType, Ye as createYHubVersioningEndpoints, Oe as createYjsVersioningAdapter, q as docDiffToDelta, W as findTypeInOtherYdoc, J as getProseMirrorTrFromYFragment, xe as getReferenceClientRects, be as getReferenceRect, H as mapAttributionToMark, D as resolveAttributionMarkClassName, ze as withCollaboration, we as yDocToBlocks, K as yfragmentToBlocks };
988
+
989
+ //# sourceMappingURL=y.js.map