@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
@@ -12,6 +12,7 @@ import type {
12
12
  InlineContent,
13
13
  InlineContentSchema,
14
14
  PartialInlineContent,
15
+ StyledText,
15
16
  } from "../inlineContent/types.js";
16
17
  import type { PropSchema, Props } from "../propTypes.js";
17
18
  import type { StyleSchema } from "../styles/types.js";
@@ -67,7 +68,11 @@ export interface BlockConfigMeta {
67
68
  export interface BlockConfig<
68
69
  T extends string = string,
69
70
  PS extends PropSchema = PropSchema,
70
- C extends "inline" | "none" | "table" = "inline" | "none" | "table",
71
+ C extends "inline" | "none" | "table" | "plain" =
72
+ | "inline"
73
+ | "none"
74
+ | "table"
75
+ | "plain",
71
76
  > {
72
77
  /**
73
78
  * The type of the block (unique identifier within a schema)
@@ -93,7 +98,7 @@ export interface BlockConfig<
93
98
  export type BlockConfigOrCreator<
94
99
  TName extends string = string,
95
100
  TProps extends PropSchema = PropSchema,
96
- TContent extends "inline" | "none" = "inline" | "none",
101
+ TContent extends "inline" | "none" | "plain" = "inline" | "none" | "plain",
97
102
  TOptions extends Record<string, any> | undefined =
98
103
  | Record<string, any>
99
104
  | undefined,
@@ -108,8 +113,10 @@ export type BlockConfigOrCreator<
108
113
  */
109
114
  export type ExtractBlockConfigFromConfigOrCreator<
110
115
  ConfigOrCreator extends
111
- | BlockConfig<string, PropSchema, "inline" | "none">
112
- | ((...args: any[]) => BlockConfig<string, PropSchema, "inline" | "none">),
116
+ | BlockConfig<string, PropSchema, "inline" | "none" | "plain">
117
+ | ((
118
+ ...args: any[]
119
+ ) => BlockConfig<string, PropSchema, "inline" | "none" | "plain">),
113
120
  > = ConfigOrCreator extends (...args: any[]) => infer Config
114
121
  ? Config
115
122
  : ConfigOrCreator;
@@ -118,14 +125,18 @@ export type ExtractBlockConfigFromConfigOrCreator<
118
125
  export type CustomBlockConfig<
119
126
  T extends string = string,
120
127
  PS extends PropSchema = PropSchema,
121
- C extends "inline" | "none" = "inline" | "none",
128
+ C extends "inline" | "none" | "plain" = "inline" | "none" | "plain",
122
129
  > = BlockConfig<T, PS, C>;
123
130
 
124
131
  // A Spec contains both the Config and Implementation
125
132
  export type BlockSpec<
126
133
  T extends string = string,
127
134
  PS extends PropSchema = PropSchema,
128
- C extends "inline" | "none" | "table" = "inline" | "none" | "table",
135
+ C extends "inline" | "none" | "table" | "plain" =
136
+ | "inline"
137
+ | "none"
138
+ | "table"
139
+ | "plain",
129
140
  > = {
130
141
  config: BlockConfig<T, PS, C>;
131
142
  implementation: BlockImplementation<T, PS, C>;
@@ -139,7 +150,11 @@ export type BlockSpec<
139
150
  export type BlockSpecOrCreator<
140
151
  T extends string = string,
141
152
  PS extends PropSchema = PropSchema,
142
- C extends "inline" | "none" | "table" = "inline" | "none" | "table",
153
+ C extends "inline" | "none" | "table" | "plain" =
154
+ | "inline"
155
+ | "none"
156
+ | "table"
157
+ | "plain",
143
158
  TOptions extends Record<string, any> | undefined =
144
159
  | Record<string, any>
145
160
  | undefined,
@@ -154,8 +169,10 @@ export type BlockSpecOrCreator<
154
169
  */
155
170
  export type ExtractBlockSpecFromSpecOrCreator<
156
171
  SpecOrCreator extends
157
- | BlockSpec<string, PropSchema, "inline" | "none">
158
- | ((...args: any[]) => BlockSpec<string, PropSchema, "inline" | "none">),
172
+ | BlockSpec<string, PropSchema, "inline" | "none" | "plain">
173
+ | ((
174
+ ...args: any[]
175
+ ) => BlockSpec<string, PropSchema, "inline" | "none" | "plain">),
159
176
  > = SpecOrCreator extends (...args: any[]) => infer Spec ? Spec : SpecOrCreator;
160
177
 
161
178
  /**
@@ -167,7 +184,11 @@ export type ExtractBlockSpecFromSpecOrCreator<
167
184
  export type LooseBlockSpec<
168
185
  T extends string = string,
169
186
  PS extends PropSchema = PropSchema,
170
- C extends "inline" | "none" | "table" = "inline" | "none" | "table",
187
+ C extends "inline" | "none" | "table" | "plain" =
188
+ | "inline"
189
+ | "none"
190
+ | "table"
191
+ | "plain",
171
192
  > = {
172
193
  config: BlockConfig<T, PS, C>;
173
194
  implementation: Omit<
@@ -321,6 +342,18 @@ export type TableContent<
321
342
  }[];
322
343
  };
323
344
 
345
+ // The content of a block with "plain" content (e.g. a code block): unstyled
346
+ // text, represented as StyledText items whose `styles` is always empty.
347
+ export type PlainContent = (StyledText<{}> & {
348
+ styles: Record<string, never>;
349
+ })[];
350
+
351
+ // Partial form of PlainContent: also accepts bare strings (both as the whole
352
+ // content and as array items), which are normalized on write.
353
+ export type PartialPlainContent =
354
+ | string
355
+ | (string | (StyledText<{}> & { styles: Record<string, never> }))[];
356
+
324
357
  // A BlockConfig has all the information to get the type of a Block (which is a specific instance of the BlockConfig.
325
358
  // i.e.: paragraphConfig: BlockConfig defines what a "paragraph" is / supports, and BlockFromConfigNoChildren<paragraphConfig> is the shape of a specific paragraph block.
326
359
  // (for internal use)
@@ -336,9 +369,11 @@ export type BlockFromConfigNoChildren<
336
369
  ? InlineContent<I, S>[]
337
370
  : B["content"] extends "table"
338
371
  ? TableContent<I, S>
339
- : B["content"] extends "none"
340
- ? undefined
341
- : never;
372
+ : B["content"] extends "plain"
373
+ ? PlainContent
374
+ : B["content"] extends "none"
375
+ ? undefined
376
+ : never;
342
377
  };
343
378
 
344
379
  export type BlockFromConfig<
@@ -420,9 +455,11 @@ type PartialBlockFromConfigNoChildren<
420
455
  ? PartialInlineContent<I, S>
421
456
  : B["content"] extends "table"
422
457
  ? PartialTableContent<I, S>
423
- : B["content"] extends "none"
424
- ? undefined
425
- : never;
458
+ : B["content"] extends "plain"
459
+ ? PartialPlainContent
460
+ : B["content"] extends "none"
461
+ ? undefined
462
+ : never;
426
463
  };
427
464
 
428
465
  type PartialBlocksWithoutChildren<
@@ -472,7 +509,11 @@ export type BlockIdentifier = { id: string } | string;
472
509
  export type BlockImplementation<
473
510
  TName extends string = string,
474
511
  TProps extends PropSchema = PropSchema,
475
- TContent extends "inline" | "none" | "table" = "inline" | "none" | "table",
512
+ TContent extends "inline" | "none" | "table" | "plain" =
513
+ | "inline"
514
+ | "none"
515
+ | "table"
516
+ | "plain",
476
517
  > = {
477
518
  /**
478
519
  * Metadata
@@ -486,6 +527,7 @@ export type BlockImplementation<
486
527
  | Record<string, never>
487
528
  | ({
488
529
  blockContentDOMAttributes: Record<string, string>;
530
+ propSchema?: TProps;
489
531
  } & (
490
532
  | {
491
533
  renderType: "nodeView";
@@ -520,6 +562,7 @@ export type BlockImplementation<
520
562
  toExternalHTML?: (
521
563
  this: Partial<{
522
564
  blockContentDOMAttributes: Record<string, string>;
565
+ propSchema: TProps;
523
566
  }>,
524
567
  block: BlockFromConfig<BlockConfig<TName, TProps, TContent>, any, any>,
525
568
  editor: BlockNoteEditor<
@@ -566,8 +609,8 @@ export type BlockImplementationOrCreator<
566
609
  TOptions extends Record<string, any> | undefined =
567
610
  | Record<string, any>
568
611
  | undefined,
569
- Config extends
570
- ExtractBlockConfigFromConfigOrCreator<ConfigOrCreator> = ExtractBlockConfigFromConfigOrCreator<ConfigOrCreator>,
612
+ Config extends ExtractBlockConfigFromConfigOrCreator<ConfigOrCreator> =
613
+ ExtractBlockConfigFromConfigOrCreator<ConfigOrCreator>,
571
614
  > =
572
615
  | BlockImplementation<Config["type"], Config["propSchema"], Config["content"]>
573
616
  | (TOptions extends undefined
@@ -589,10 +632,14 @@ export type BlockImplementationOrCreator<
589
632
  */
590
633
  export type ExtractBlockImplementationFromImplementationOrCreator<
591
634
  ImplementationOrCreator extends
592
- | BlockImplementation<string, PropSchema, "inline" | "none">
635
+ | BlockImplementation<string, PropSchema, "inline" | "none" | "plain">
593
636
  | ((
594
637
  ...args: any[]
595
- ) => BlockImplementation<string, PropSchema, "inline" | "none">),
638
+ ) => BlockImplementation<
639
+ string,
640
+ PropSchema,
641
+ "inline" | "none" | "plain"
642
+ >),
596
643
  > = ImplementationOrCreator extends (...args: any[]) => infer Implementation
597
644
  ? Implementation
598
645
  : ImplementationOrCreator;
@@ -601,5 +648,5 @@ export type ExtractBlockImplementationFromImplementationOrCreator<
601
648
  export type CustomBlockImplementation<
602
649
  T extends string = string,
603
650
  PS extends PropSchema = PropSchema,
604
- C extends "inline" | "none" = "inline" | "none",
651
+ C extends "inline" | "none" | "plain" = "inline" | "none" | "plain",
605
652
  > = BlockImplementation<T, PS, C>;
@@ -0,0 +1,182 @@
1
+ import { describe, expect, it } from "vite-plus/test";
2
+
3
+ import { createBlockSpec } from "./blocks/createSpec.js";
4
+ import type {
5
+ BlockConfig,
6
+ BlockFromConfig,
7
+ PartialBlockFromConfig,
8
+ PartialPlainContent as CorePartialPlainContent,
9
+ PlainContent as CorePlainContent,
10
+ } from "./blocks/types.js";
11
+ import { createInlineContentSpec } from "./inlineContent/createSpec.js";
12
+ import type {
13
+ CustomInlineContentFromConfig,
14
+ PartialCustomInlineContentFromConfig,
15
+ } from "./inlineContent/types.js";
16
+ import type { StyleSchema } from "./styles/types.js";
17
+
18
+ /**
19
+ * Type-level tests asserting that a block's / inline content's `content` field
20
+ * is inferred correctly from its config's `content` discriminant — in
21
+ * particular that a block's `"plain"` content type propagates to an unstyled
22
+ * StyledText array (`PlainContent`), an inline content's `"plain"` propagates
23
+ * to `string`, `"inline"`/`"styled"` propagate to arrays and `"none"` to
24
+ * `undefined`.
25
+ *
26
+ * The assertions are the type annotations and `@ts-expect-error` directives: if
27
+ * propagation breaks, this file stops compiling, which `vp lint` / `tsgo`
28
+ * catches in CI (note that `vp test`, which strips types via esbuild, does not
29
+ * — these tests are guarded by the type-checker, not the runner). The `it`
30
+ * bodies otherwise contain no meaningful runtime logic, mirroring the existing
31
+ * typing tests in `updateBlock.test.ts`.
32
+ */
33
+
34
+ // Exact type-equality check: resolves to `true` only when X and Y are identical.
35
+ type Equal<X, Y> =
36
+ (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
37
+ ? true
38
+ : false;
39
+
40
+ describe("block content type propagation", () => {
41
+ type PlainContent = BlockFromConfig<
42
+ BlockConfig<"plainBlock", {}, "plain">,
43
+ any,
44
+ any
45
+ >["content"];
46
+ type NoneContent = BlockFromConfig<
47
+ BlockConfig<"noneBlock", {}, "none">,
48
+ any,
49
+ any
50
+ >["content"];
51
+ type InlineContent = BlockFromConfig<
52
+ BlockConfig<"inlineBlock", {}, "inline">,
53
+ any,
54
+ any
55
+ >["content"];
56
+
57
+ it("'plain' content is an unstyled StyledText array", () => {
58
+ const isPlainContent: Equal<PlainContent, CorePlainContent> = true;
59
+ expect(isPlainContent).toBe(true);
60
+
61
+ // @ts-expect-error 'plain' content is a StyledText array, not a string
62
+ const bad: PlainContent = "x";
63
+ void bad;
64
+ });
65
+
66
+ it("'none' content is undefined", () => {
67
+ const isUndefined: Equal<NoneContent, undefined> = true;
68
+ expect(isUndefined).toBe(true);
69
+ });
70
+
71
+ it("'inline' content is distinct from 'plain' (an array, not a string)", () => {
72
+ // @ts-expect-error 'inline' content is an array, not a string
73
+ const bad: InlineContent = "hello";
74
+ void bad;
75
+ });
76
+ });
77
+
78
+ describe("partial block content type propagation", () => {
79
+ type PartialPlainContent = PartialBlockFromConfig<
80
+ BlockConfig<"plainBlock", {}, "plain">,
81
+ any,
82
+ any
83
+ >["content"];
84
+
85
+ it("'plain' partial content is optional unstyled text", () => {
86
+ const isPartialPlainContent: Equal<
87
+ PartialPlainContent,
88
+ CorePartialPlainContent | undefined
89
+ > = true;
90
+ expect(isPartialPlainContent).toBe(true);
91
+
92
+ const good: PartialPlainContent = [{ type: "text", text: "x", styles: {} }];
93
+ void good;
94
+
95
+ const bad: PartialPlainContent = [
96
+ // @ts-expect-error bold is not a valid style for plain content
97
+ { type: "text", text: "x", styles: { bold: true } },
98
+ ];
99
+ void bad;
100
+ });
101
+ });
102
+
103
+ describe("inline content type propagation", () => {
104
+ type PlainContent = CustomInlineContentFromConfig<
105
+ { type: "plainIC"; content: "plain"; readonly propSchema: {} },
106
+ StyleSchema
107
+ >["content"];
108
+ type NoneContent = CustomInlineContentFromConfig<
109
+ { type: "noneIC"; content: "none"; readonly propSchema: {} },
110
+ StyleSchema
111
+ >["content"];
112
+ type StyledContent = CustomInlineContentFromConfig<
113
+ { type: "styledIC"; content: "styled"; readonly propSchema: {} },
114
+ StyleSchema
115
+ >["content"];
116
+
117
+ it("'plain' inline content is a string", () => {
118
+ const isString: Equal<PlainContent, string> = true;
119
+ expect(isString).toBe(true);
120
+
121
+ // @ts-expect-error 'plain' inline content is a string, not a StyledText array
122
+ const bad: PlainContent = [];
123
+ void bad;
124
+ });
125
+
126
+ it("'none' inline content is undefined", () => {
127
+ const isUndefined: Equal<NoneContent, undefined> = true;
128
+ expect(isUndefined).toBe(true);
129
+ });
130
+
131
+ it("'styled' inline content is distinct from 'plain' (an array, not a string)", () => {
132
+ // @ts-expect-error 'styled' inline content is a StyledText array, not a string
133
+ const bad: StyledContent = "hello";
134
+ void bad;
135
+ });
136
+ });
137
+
138
+ describe("partial inline content type propagation", () => {
139
+ type PartialPlainContent = PartialCustomInlineContentFromConfig<
140
+ { type: "plainIC"; content: "plain"; readonly propSchema: {} },
141
+ StyleSchema
142
+ >["content"];
143
+
144
+ it("'plain' partial inline content is an optional string", () => {
145
+ const isOptionalString: Equal<PartialPlainContent, string | undefined> =
146
+ true;
147
+ expect(isOptionalString).toBe(true);
148
+ });
149
+ });
150
+
151
+ describe("content type propagation through the spec factories", () => {
152
+ it("createBlockSpec propagates 'plain' to the block's content type", () => {
153
+ const plainBlock = createBlockSpec(
154
+ { type: "plainBlock", propSchema: {}, content: "plain" },
155
+ { render: () => ({ dom: undefined as unknown as HTMLElement }) },
156
+ );
157
+
158
+ type Content = BlockFromConfig<
159
+ ReturnType<typeof plainBlock>["config"],
160
+ any,
161
+ any
162
+ >["content"];
163
+
164
+ const isPlainContent: Equal<Content, CorePlainContent> = true;
165
+ expect(isPlainContent).toBe(true);
166
+ });
167
+
168
+ it("createInlineContentSpec propagates 'plain' to the inline content's content type", () => {
169
+ const plainIC = createInlineContentSpec(
170
+ { type: "plainIC", propSchema: {}, content: "plain" },
171
+ { render: () => ({ dom: undefined as unknown as HTMLElement }) },
172
+ );
173
+
174
+ type Content = CustomInlineContentFromConfig<
175
+ (typeof plainIC)["config"],
176
+ StyleSchema
177
+ >["content"];
178
+
179
+ const isString: Equal<Content, string> = true;
180
+ expect(isString).toBe(true);
181
+ });
182
+ });
@@ -4,6 +4,7 @@ export * from "./blocks/types.js";
4
4
  export * from "./inlineContent/createSpec.js";
5
5
  export * from "./inlineContent/internal.js";
6
6
  export * from "./inlineContent/types.js";
7
+ export * from "./markGroups.js";
7
8
  export * from "./propTypes.js";
8
9
  export * from "./styles/createSpec.js";
9
10
  export * from "./styles/internal.js";
@@ -35,7 +35,7 @@ export function addInlineContentAttributes<
35
35
  Object.entries(inlineContentProps)
36
36
  .filter(([prop, value]) => {
37
37
  const spec = propSchema[prop];
38
- return value !== spec.default;
38
+ return value !== spec?.default;
39
39
  })
40
40
  .map(([prop, value]) => {
41
41
  return [camelToDataKebab(prop), value];
@@ -1,12 +1,12 @@
1
1
  import { Node } from "@tiptap/core";
2
+ import { ViewMutationRecord } from "prosemirror-view";
3
+ import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
2
4
  import { PropSchema, Props } from "../propTypes.js";
3
5
  import { StyleSchema, Styles } from "../styles/types.js";
4
- import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
5
- import { ViewMutationRecord } from "prosemirror-view";
6
6
 
7
7
  export type CustomInlineContentConfig = {
8
8
  type: string;
9
- content: "styled" | "none"; // | "plain"
9
+ content: "styled" | "none" | "plain";
10
10
  readonly propSchema: PropSchema;
11
11
  };
12
12
  // InlineContentConfig contains the "schema" info about an InlineContent type
@@ -0,0 +1,50 @@
1
+ import { Editor, getExtensionField } from "@tiptap/core";
2
+
3
+ /**
4
+ * ProseMirror mark group for "non-formatting" marks: comments and the
5
+ * suggestion/diff marks (the AI `insertion`/`deletion`/`modification` marks and
6
+ * the Yjs `y-attributed-*` marks). These annotate content without representing
7
+ * inline formatting and are ignored by BlockNote's content model
8
+ * (`blocknoteIgnore`).
9
+ *
10
+ * They are the only marks allowed on `"plain"` blocks (e.g. code blocks), which
11
+ * otherwise disallow all formatting marks. A block references this group rather
12
+ * than the individual marks because each of them comes from an optional
13
+ * extension (comments, AI suggestions, Yjs attribution) and so is only present
14
+ * when that extension is configured.
15
+ */
16
+ export const NON_FORMATTING_MARK_GROUP = "annotation";
17
+
18
+ /**
19
+ * The `marks` field value for `"plain"` blocks (e.g. code blocks), which hold
20
+ * unstyled text and so disallow formatting marks but still allow the
21
+ * non-formatting ones.
22
+ *
23
+ * Every mark in {@link NON_FORMATTING_MARK_GROUP} comes from an optional
24
+ * extension, so a node spec that referenced the group unconditionally would make
25
+ * ProseMirror throw "Unknown mark type: 'annotation'" while building the schema
26
+ * of an editor that has none of them registered — an empty mark group is an
27
+ * unknown reference just like a missing mark is. (This mirrors `suggestionMarks`
28
+ * for the block-level suggestion group.)
29
+ *
30
+ * Returns the group name (which ProseMirror expands to every mark in it) when at
31
+ * least one such mark is registered, or `""` otherwise. Evaluated at
32
+ * schema-build time, where the tiptap editor's fully-flattened extension list is
33
+ * available on `this.editor`.
34
+ */
35
+ export function nonFormattingMarks(editor: Editor | undefined): string {
36
+ if (!editor) {
37
+ return "";
38
+ }
39
+ const hasNonFormattingMark = editor.options.extensions.some((extension) => {
40
+ if (extension.type !== "mark") {
41
+ return false;
42
+ }
43
+ const group = getExtensionField(extension, "group") as string | undefined;
44
+ return (
45
+ typeof group === "string" &&
46
+ group.split(" ").includes(NON_FORMATTING_MARK_GROUP)
47
+ );
48
+ });
49
+ return hasNonFormattingMark ? NON_FORMATTING_MARK_GROUP : "";
50
+ }
@@ -0,0 +1,199 @@
1
+ import { Store } from "@tanstack/store";
2
+ import { createStore } from "../editor/BlockNoteExtension.js";
3
+
4
+ /**
5
+ * A collaborator of the document.
6
+ */
7
+ export type User = {
8
+ /**
9
+ * The {@link User}'s unique identifier
10
+ */
11
+ id: string;
12
+ /**
13
+ * The {@link User}'s name/label
14
+ */
15
+ username: string;
16
+ /**
17
+ * The {@link User}'s profile image
18
+ */
19
+ avatarUrl: string;
20
+ /**
21
+ * The color used to represent the user (e.g. for collaboration cursors).
22
+ */
23
+ color?: string;
24
+ /**
25
+ * A lighter variant of {@link color}.
26
+ */
27
+ colorLight?: string;
28
+ };
29
+
30
+ /**
31
+ * A store that retrieves and caches information about users, generic over the
32
+ * resolved user type `U`.
33
+ *
34
+ * Created via {@link createUserStore}. Features that need to resolve user ids to
35
+ * user information (comments, suggestions, versions) build one internally and
36
+ * expose it on their extension instance so their UI can read from it.
37
+ */
38
+ export type UserStore<U extends User = User> = {
39
+ /**
40
+ * A store mapping user ids to the resolved {@link User} information.
41
+ */
42
+ store: Store<Map<User["id"], U>>;
43
+ /**
44
+ * Load information about users based on an array of user ids.
45
+ *
46
+ * Users that are already cached or currently being loaded are skipped, so
47
+ * it is safe to call this often (e.g. on every render).
48
+ */
49
+ loadUsers: (userIds: User["id"][]) => Promise<void>;
50
+ /**
51
+ * Re-fetch information about users, ignoring the cache. Users that are
52
+ * currently being loaded are still skipped to avoid duplicate requests.
53
+ */
54
+ refetchUsers: (userIds: User["id"][]) => Promise<void>;
55
+ /**
56
+ * Retrieve information about a user based on their id, if cached.
57
+ *
58
+ * The user has to be loaded via `loadUsers` first.
59
+ */
60
+ getUser: (userId: User["id"]) => U | undefined;
61
+ /**
62
+ * Manually set information about a user. This is useful if you have a
63
+ * resolver that returns partial information (e.g. just the username) and you
64
+ * want to fill in the rest later (e.g. avatarUrl).
65
+ */
66
+ setUser: (user: U | U[]) => void;
67
+ };
68
+
69
+ export type UserStoreResolver<U extends User = User> = (
70
+ /**
71
+ * The user ids to resolve. The resolver should return information for all of
72
+ * these users, or an empty array if none could be resolved.
73
+ */
74
+ userIds: User["id"][],
75
+ /**
76
+ * The {@link UserStore} that is calling this resolver. This allows you to return a user synchronously, and update the store later if you need to fetch additional information asynchronously.
77
+ */
78
+ store: UserStore<any>,
79
+ ) => Promise<U[]>;
80
+
81
+ /**
82
+ * A resolver callback or an already-built {@link UserStore} — the shape that
83
+ * user-facing options (comments, collaboration) accept so callers can either let
84
+ * the extension build a store or pass a shared one.
85
+ */
86
+ export type UserStoreOrResolver<U extends User = User> =
87
+ | ((userIds: User["id"][], store: UserStore<any>) => Promise<U[]>)
88
+ | UserStore<any>;
89
+
90
+ /**
91
+ * Creates a {@link UserStore} that retrieves and caches information about users.
92
+ *
93
+ * It does this by calling `resolveUsers` for users that are not yet cached, and
94
+ * stores the results in a BlockNote store so they can be subscribed to (e.g. via
95
+ * `useStore` in React).
96
+ *
97
+ * `resolveUsers` is called with the ids of users that are not yet cached, and
98
+ * should return the information for those users. The type of the returned users
99
+ * is inferred and flows through to {@link UserStore.getUser} and the store, so
100
+ * you can return a type with additional properties and have them be reported
101
+ * back.
102
+ *
103
+ * See [Comments](https://www.blocknotejs.org/docs/features/collaboration/comments) for more info.
104
+ */
105
+ export function createUserStore<U extends User = User>(
106
+ resolveUsers: (userIds: User["id"][], store: UserStore<any>) => Promise<U[]>,
107
+ ): UserStore<U> {
108
+ if (!resolveUsers) {
109
+ throw new Error("resolveUsers is required to create a user store");
110
+ }
111
+
112
+ const store = createStore(new Map<User["id"], U>());
113
+
114
+ // Tracks users that are currently being fetched, to avoid duplicate
115
+ // in-flight requests. This is intentionally kept out of the store as it is
116
+ // not state that consumers need to subscribe to.
117
+ const loadingUsers = new Set<User["id"]>();
118
+
119
+ const userStore: UserStore<U> = {
120
+ store,
121
+ async loadUsers(userIds) {
122
+ const missingUsers = userIds.filter(
123
+ (id) => !store.state.has(id) && !loadingUsers.has(id),
124
+ );
125
+ await fetchUsers(missingUsers);
126
+ },
127
+ async refetchUsers(userIds) {
128
+ const usersToFetch = userIds.filter((id) => !loadingUsers.has(id));
129
+ await fetchUsers(usersToFetch);
130
+ },
131
+ getUser(userId) {
132
+ return store.state.get(userId);
133
+ },
134
+ setUser(users) {
135
+ const usersArray = Array.isArray(users) ? users : [users];
136
+ store.setState((prevState) => {
137
+ const nextState = new Map(prevState);
138
+ for (const user of usersArray) {
139
+ nextState.set(user.id, user);
140
+ }
141
+ return nextState;
142
+ });
143
+ },
144
+ };
145
+
146
+ async function fetchUsers(userIds: User["id"][]) {
147
+ if (userIds.length === 0) {
148
+ return;
149
+ }
150
+
151
+ for (const id of userIds) {
152
+ loadingUsers.add(id);
153
+ }
154
+
155
+ try {
156
+ const users = await resolveUsers(userIds, userStore);
157
+ // Only update the store if any users were actually resolved. Emitting
158
+ // an update when nothing changed (e.g. when the resolver can't find a
159
+ // user) would needlessly notify subscribers and, combined with a
160
+ // subscriber that re-triggers loading, could cause an infinite loop.
161
+ // See https://github.com/TypeCellOS/BlockNote/issues/1548
162
+ if (users.length > 0) {
163
+ store.setState((prevState) => {
164
+ const nextState = new Map(prevState);
165
+ for (const user of users) {
166
+ nextState.set(user.id, user);
167
+ }
168
+ return nextState;
169
+ });
170
+ }
171
+ } finally {
172
+ for (const id of userIds) {
173
+ // Remove the users from the loading set. On a next call to `loadUsers`
174
+ // we will either return the cached user, or retry loading the user if
175
+ // the request failed.
176
+ loadingUsers.delete(id);
177
+ }
178
+ }
179
+ }
180
+
181
+ return userStore;
182
+ }
183
+
184
+ /**
185
+ * Normalize a {@link UserStoreOrResolver} to a {@link UserStore}:
186
+ * - an existing store is returned as-is (so a single de-duped cache can be
187
+ * shared across extensions),
188
+ * - a resolver function is wrapped with {@link createUserStore},
189
+ * - `undefined` yields an empty store that resolves nothing (consumers then fall
190
+ * back to showing raw user ids).
191
+ */
192
+ export function normalizeToUserStore<U extends User = User>(
193
+ resolveUsersOrStore?: UserStoreOrResolver<U>,
194
+ ): UserStore<U> {
195
+ if (typeof resolveUsersOrStore === "function") {
196
+ return createUserStore(resolveUsersOrStore);
197
+ }
198
+ return resolveUsersOrStore ?? createUserStore<U>(async () => []);
199
+ }