@blocknote/core 0.55.0 → 0.56.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 (460) hide show
  1. package/dist/BlockNoteExtension-DjEkXkR5.cjs +2 -0
  2. package/dist/BlockNoteExtension-DjEkXkR5.cjs.map +1 -0
  3. package/dist/{BlockNoteExtension-CbvDA0F7.js → BlockNoteExtension-TsTGtIeX.js} +34 -27
  4. package/dist/BlockNoteExtension-TsTGtIeX.js.map +1 -0
  5. package/dist/{UserStore-mj3fXW4D.cjs → UserStore-CTVzVGh-.cjs} +2 -2
  6. package/dist/{UserStore-mj3fXW4D.cjs.map → UserStore-CTVzVGh-.cjs.map} +1 -1
  7. package/dist/{UserStore-C4TzkGEn.js → UserStore-OZJP3K8T.js} +2 -2
  8. package/dist/{UserStore-C4TzkGEn.js.map → UserStore-OZJP3K8T.js.map} +1 -1
  9. package/dist/blocknote.cjs +1 -1
  10. package/dist/blocknote.js +6 -6
  11. package/dist/blocks-COVwe5Cf.cjs +12 -0
  12. package/dist/blocks-COVwe5Cf.cjs.map +1 -0
  13. package/dist/{blocks-DaEUT0O1.js → blocks-COYcDVg7.js} +1572 -1156
  14. package/dist/blocks-COYcDVg7.js.map +1 -0
  15. package/dist/blocks.cjs +1 -1
  16. package/dist/blocks.js +2 -2
  17. package/dist/comments.cjs +1 -1
  18. package/dist/comments.js +12 -12
  19. package/dist/{en-BAn9gxr-.js → en-Ch-vvt5e.js} +36 -2
  20. package/dist/en-Ch-vvt5e.js.map +1 -0
  21. package/dist/en-N5lu0-j8.cjs +2 -0
  22. package/dist/en-N5lu0-j8.cjs.map +1 -0
  23. package/dist/extensions-BbM81hHa.js +3069 -0
  24. package/dist/extensions-BbM81hHa.js.map +1 -0
  25. package/dist/extensions-D_WkAfSt.cjs +58 -0
  26. package/dist/extensions-D_WkAfSt.cjs.map +1 -0
  27. package/dist/extensions.cjs +1 -1
  28. package/dist/extensions.js +4 -4
  29. package/dist/locales.cjs +1 -1
  30. package/dist/locales.cjs.map +1 -1
  31. package/dist/locales.js +771 -23
  32. package/dist/locales.js.map +1 -1
  33. package/dist/src-4OQT3z5S.cjs +23 -0
  34. package/dist/src-4OQT3z5S.cjs.map +1 -0
  35. package/dist/{src-D5w0XAHX.js → src-BmLsLZfE.js} +1390 -1278
  36. package/dist/src-BmLsLZfE.js.map +1 -0
  37. package/dist/style.css +1 -1
  38. package/dist/webpack-stats.json +1 -1
  39. package/dist/y.cjs +1 -1
  40. package/dist/y.cjs.map +1 -1
  41. package/dist/y.js +1284 -554
  42. package/dist/y.js.map +1 -1
  43. package/dist/yjs.cjs +1 -1
  44. package/dist/yjs.cjs.map +1 -1
  45. package/dist/yjs.js +189 -148
  46. package/dist/yjs.js.map +1 -1
  47. package/package.json +8 -8
  48. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +45 -6
  49. package/src/api/blockManipulation/commands/insertBlocks/insertPlacement.test.ts +217 -0
  50. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +113 -9
  51. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +151 -163
  52. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +47 -31
  53. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +122 -181
  54. package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +256 -0
  55. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +80 -40
  56. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +71 -0
  57. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +39 -31
  58. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +221 -8
  59. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +40 -8
  60. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +272 -40
  61. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +138 -117
  62. package/src/api/blockManipulation/getBlock/getBlock.ts +4 -11
  63. package/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.ts +173 -0
  64. package/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.ts +293 -0
  65. package/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.ts +145 -0
  66. package/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.ts +783 -0
  67. package/src/api/blockManipulation/layoutBlocks/plainBlocks.test.ts +180 -0
  68. package/src/api/blockManipulation/layoutBlocks/titledBlocks.test.ts +365 -0
  69. package/src/api/blockManipulation/selections/selection.ts +20 -53
  70. package/src/api/blockManipulation/selections/textCursorPosition.ts +17 -72
  71. package/src/api/blockManipulation/setupTestEnv.ts +38 -6
  72. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +4 -4
  73. package/src/api/clipboard/toClipboard/copyExtension.ts +3 -3
  74. package/src/api/combineTransactionSteps.ts +22 -0
  75. package/src/api/exporters/html/externalHTMLExporter.ts +1 -1
  76. package/src/api/exporters/html/internalHTMLSerializer.ts +4 -4
  77. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +111 -36
  78. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +51 -21
  79. package/src/api/exporters/markdown/htmlToMarkdown.ts +12 -1
  80. package/src/api/exporters/markdown/markdownExporter.ts +1 -1
  81. package/src/api/getBlockInfoFromPos.test.ts +428 -3
  82. package/src/api/getBlockInfoFromPos.ts +531 -129
  83. package/src/api/getBlocksChangedByTransaction.test.ts +7 -7
  84. package/src/api/getBlocksChangedByTransaction.ts +3 -3
  85. package/src/api/{getChangedRange.ts → getChangedRangeWithAttrs.ts} +2 -2
  86. package/src/api/getChangedRanges.test.ts +391 -0
  87. package/src/api/getChangedRanges.ts +368 -0
  88. package/src/api/nodeConversions/blockToNode.ts +44 -16
  89. package/src/api/nodeConversions/fragmentToBlocks.ts +29 -44
  90. package/src/api/nodeConversions/nodeToBlock.ts +120 -68
  91. package/src/api/nodeUtil.ts +1 -1
  92. package/src/api/parsers/markdown/autolink.ts +23 -0
  93. package/src/api/parsers/markdown/markdownToHtml.ts +115 -11
  94. package/src/blocks/Code/block.test.ts +4 -4
  95. package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +6 -1
  96. package/src/blocks/Heading/block.ts +54 -15
  97. package/src/blocks/ListItem/BulletListItem/block.ts +6 -4
  98. package/src/blocks/ListItem/CheckListItem/block.test.ts +2 -2
  99. package/src/blocks/ListItem/CheckListItem/block.ts +6 -4
  100. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +14 -17
  101. package/src/blocks/ListItem/NumberedListItem/block.ts +6 -4
  102. package/src/blocks/ListItem/ToggleListItem/block.ts +23 -12
  103. package/src/blocks/Table/block.ts +2 -10
  104. package/src/blocks/ToggleWrapper/createToggleFrame.ts +126 -0
  105. package/src/blocks/ToggleWrapper/toggleBlocks.browser.test.ts +1056 -0
  106. package/src/blocks/defaultBlockTypeItems.test.ts +70 -0
  107. package/src/blocks/defaultBlockTypeItems.ts +99 -0
  108. package/src/blocks/defaultBlocks.test.ts +67 -0
  109. package/src/blocks/defaultBlocks.ts +7 -1
  110. package/src/blocks/index.ts +2 -1
  111. package/src/editor/Block.css +286 -154
  112. package/src/editor/BlockNoteEditor.node.test.ts +35 -0
  113. package/src/editor/BlockNoteEditor.test.ts +2 -2
  114. package/src/editor/BlockNoteEditor.ts +71 -9
  115. package/src/editor/BlockNoteExtension.ts +5 -5
  116. package/src/editor/blockColors.browser.test.ts +127 -0
  117. package/src/editor/editor.css +60 -0
  118. package/src/editor/managers/BlockManager.ts +4 -3
  119. package/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.ts +45 -0
  120. package/src/editor/managers/ExtensionManager/ExtensionManager.node.test.ts +209 -0
  121. package/src/editor/managers/ExtensionManager/extensions.ts +10 -1
  122. package/src/editor/managers/ExtensionManager/index.ts +135 -68
  123. package/src/editor/managers/StateManager.ts +14 -4
  124. package/src/editor/transformPasted.ts +14 -13
  125. package/src/exporter/Exporter.test.ts +70 -1
  126. package/src/exporter/Exporter.ts +34 -4
  127. package/src/exporter/mapping.ts +41 -10
  128. package/src/extensions/DropCursor/DropCursor.ts +119 -6
  129. package/src/extensions/DropCursor/dropIntoChildren.ts +80 -0
  130. package/src/extensions/FormattingToolbar/FormattingToolbar.ts +7 -1
  131. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.ts +190 -0
  132. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +41 -4
  133. package/src/extensions/Placeholder/Placeholder.test.ts +23 -0
  134. package/src/extensions/Placeholder/Placeholder.ts +8 -7
  135. package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +36 -0
  136. package/src/extensions/PreviousBlockType/PreviousBlockType.ts +8 -4
  137. package/src/extensions/ReadOnly/ReadOnly.test.ts +181 -0
  138. package/src/extensions/ReadOnly/ReadOnly.ts +73 -0
  139. package/src/extensions/SideMenu/SideMenu.ts +401 -764
  140. package/src/extensions/SideMenu/blockDropHandling.ts +372 -0
  141. package/src/extensions/SideMenu/blockGeometry.browser.test.ts +148 -0
  142. package/src/extensions/SideMenu/blockGeometry.test.ts +46 -0
  143. package/src/extensions/SideMenu/blockGeometry.ts +53 -0
  144. package/src/extensions/SideMenu/dragging.ts +19 -32
  145. package/src/extensions/SideMenu/sideMenuHover.test.ts +36 -0
  146. package/src/extensions/SideMenu/sideMenuHover.ts +270 -0
  147. package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +5 -4
  148. package/src/extensions/SuggestionMenu/SuggestionMenu.ts +10 -1
  149. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +36 -136
  150. package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +14 -4
  151. package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +1 -1
  152. package/src/extensions/SyntaxHighlighting/shiki.ts +1 -1
  153. package/src/extensions/TableHandles/TableHandles.ts +4 -6
  154. package/src/extensions/Versioning/Versioning.browser.test.ts +151 -0
  155. package/src/extensions/Versioning/Versioning.node.test.ts +177 -0
  156. package/src/extensions/Versioning/Versioning.ts +145 -612
  157. package/src/extensions/Versioning/__test__/result.ts +12 -0
  158. package/src/extensions/Versioning/comparison.test.ts +40 -0
  159. package/src/extensions/Versioning/createVersioning.test.ts +867 -0
  160. package/src/extensions/Versioning/createVersioning.ts +499 -0
  161. package/src/extensions/Versioning/formatVersionDate.ts +24 -0
  162. package/src/extensions/Versioning/inMemoryVersioning.test.ts +533 -430
  163. package/src/extensions/Versioning/inMemoryVersioning.ts +246 -251
  164. package/src/extensions/Versioning/index.ts +4 -0
  165. package/src/extensions/Versioning/scrollScheduling.test.ts +51 -0
  166. package/src/extensions/Versioning/scrollToFirstChange.test.ts +320 -0
  167. package/src/extensions/Versioning/scrollToFirstChange.ts +139 -0
  168. package/src/extensions/Versioning/types.ts +219 -0
  169. package/src/extensions/Versioning/versioningState.ts +154 -0
  170. package/src/extensions/blockDOM.browser.test.ts +102 -0
  171. package/src/extensions/blockDOM.test.ts +178 -0
  172. package/src/extensions/blockDOM.ts +135 -0
  173. package/src/extensions/index.ts +2 -0
  174. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +1719 -53
  175. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +645 -531
  176. package/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.ts +152 -0
  177. package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +4 -9
  178. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +10 -24
  179. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +22 -19
  180. package/src/fonts/inter.browser.test.ts +57 -0
  181. package/src/fonts/inter.css +111 -0
  182. package/src/i18n/locales/ar.ts +32 -0
  183. package/src/i18n/locales/de.ts +32 -0
  184. package/src/i18n/locales/en.ts +32 -0
  185. package/src/i18n/locales/es.ts +32 -0
  186. package/src/i18n/locales/fa.ts +32 -0
  187. package/src/i18n/locales/fr.ts +32 -0
  188. package/src/i18n/locales/he.ts +32 -0
  189. package/src/i18n/locales/hr.ts +32 -0
  190. package/src/i18n/locales/is.ts +32 -0
  191. package/src/i18n/locales/it.ts +32 -0
  192. package/src/i18n/locales/ja.ts +32 -0
  193. package/src/i18n/locales/ko.ts +32 -0
  194. package/src/i18n/locales/nl.ts +32 -0
  195. package/src/i18n/locales/no.ts +32 -0
  196. package/src/i18n/locales/pl.ts +32 -0
  197. package/src/i18n/locales/pt.ts +32 -0
  198. package/src/i18n/locales/ru.ts +32 -0
  199. package/src/i18n/locales/sk.ts +32 -0
  200. package/src/i18n/locales/uk.ts +32 -0
  201. package/src/i18n/locales/uz.ts +32 -0
  202. package/src/i18n/locales/vi.ts +32 -0
  203. package/src/i18n/locales/zh-tw.ts +32 -0
  204. package/src/i18n/locales/zh.ts +32 -0
  205. package/src/index.ts +13 -3
  206. package/src/pm-nodes/BlockContainer.test.ts +101 -0
  207. package/src/pm-nodes/BlockContainer.ts +110 -1
  208. package/src/pm-nodes/BlockGroup.ts +2 -1
  209. package/src/pm-nodes/README.md +2 -0
  210. package/src/schema/blocks/children.test.ts +288 -0
  211. package/src/schema/blocks/children.ts +136 -0
  212. package/src/schema/blocks/createSpec.browser.test.ts +176 -0
  213. package/src/schema/blocks/createSpec.test.ts +231 -0
  214. package/src/schema/blocks/createSpec.ts +493 -267
  215. package/src/schema/blocks/frame.test.ts +112 -0
  216. package/src/schema/blocks/frame.ts +337 -0
  217. package/src/schema/blocks/internal.ts +50 -17
  218. package/src/schema/blocks/keyboard.ts +154 -0
  219. package/src/schema/blocks/layoutBlockAttributes.ts +29 -0
  220. package/src/schema/blocks/meta.test.ts +53 -0
  221. package/src/schema/blocks/meta.ts +35 -0
  222. package/src/schema/blocks/renderFrame.test.ts +691 -0
  223. package/src/schema/blocks/types.ts +285 -21
  224. package/src/schema/blocks/validateChildren.ts +156 -0
  225. package/src/schema/dataAttributes.test.ts +72 -0
  226. package/src/schema/dataAttributes.ts +69 -0
  227. package/src/schema/index.ts +3 -0
  228. package/src/schema/inlineContent/internal.ts +7 -12
  229. package/src/schema/markGroups.ts +34 -2
  230. package/src/schema/schema.ts +8 -1
  231. package/src/user/userColors.test.ts +108 -0
  232. package/src/user/userColors.ts +42 -13
  233. package/src/y/comments/RESTYjsThreadStore.ts +1 -1
  234. package/src/y/comments/YjsThreadStore.test.ts +1 -1
  235. package/src/y/comments/YjsThreadStore.ts +27 -27
  236. package/src/y/comments/YjsThreadStoreBase.ts +2 -2
  237. package/src/y/comments/yjsHelpers.ts +11 -11
  238. package/src/y/extensions/AttributionExtension.test.ts +271 -2
  239. package/src/y/extensions/AttributionExtension.ts +146 -123
  240. package/src/y/extensions/DiffVersioningExtension.test.ts +67 -18
  241. package/src/y/extensions/DiffVersioningExtension.ts +95 -123
  242. package/src/y/extensions/EmptyDocBinding.test.ts +282 -0
  243. package/src/y/extensions/ForkYDoc.node.test.ts +77 -0
  244. package/src/y/extensions/ForkYDoc.test.ts +93 -2
  245. package/src/y/extensions/ForkYDoc.ts +22 -13
  246. package/src/y/extensions/History.test.ts +125 -0
  247. package/src/y/extensions/RelativePositionMapping.test.ts +35 -0
  248. package/src/y/extensions/RelativePositionMapping.ts +7 -11
  249. package/src/y/extensions/Versioning.node.test.ts +126 -0
  250. package/src/y/extensions/Versioning.test.ts +110 -401
  251. package/src/y/extensions/Versioning.ts +66 -107
  252. package/src/y/extensions/YAttributionMarks.ts +111 -9
  253. package/src/y/extensions/YCursorPlugin.ts +3 -0
  254. package/src/y/extensions/YSync.node.test.ts +75 -0
  255. package/src/y/extensions/YSync.ts +76 -4
  256. package/src/y/extensions/YSyncRemount.test.ts +99 -0
  257. package/src/y/extensions/blockMatchNodes.ts +20 -29
  258. package/src/y/extensions/index.ts +10 -26
  259. package/src/y/extensions/legacyYjsDocBinding.test.ts +652 -0
  260. package/src/y/extensions/nestingChanges.test.ts +326 -0
  261. package/src/y/extensions/persistentBlockGroups.test.ts +1709 -0
  262. package/src/y/extensions/persistentBlockGroups.ts +953 -0
  263. package/src/y/extensions/snapshotCodec.test.ts +105 -0
  264. package/src/y/extensions/snapshotCodec.ts +39 -0
  265. package/src/y/extensions/snapshotPreview.test.ts +201 -0
  266. package/src/y/extensions/snapshotPreview.ts +292 -0
  267. package/src/y/extensions/tableReshape.test.ts +121 -0
  268. package/src/y/extensions/v1BindingSnapshotDiff.test.ts +121 -0
  269. package/src/y/extensions/versionDiffAttribution.test.ts +944 -0
  270. package/src/y/extensions/versionDiffPerformance.test.ts +101 -0
  271. package/src/y/index.ts +1 -0
  272. package/src/y/utils.test.ts +289 -22
  273. package/src/y/utils.ts +167 -43
  274. package/src/y/versioning/__test__/fixtures/activity-all-after.json +5 -5
  275. package/src/y/versioning/__test__/fixtures/activity-all.json +3 -3
  276. package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +2 -2
  277. package/src/y/versioning/__test__/yhub.test.ts +902 -721
  278. package/src/y/versioning/index.ts +6 -1
  279. package/src/y/versioning/yhub.ts +316 -603
  280. package/src/y/versioning/yhubClient.ts +345 -0
  281. package/src/yjs/comments/RESTYjsThreadStore.test.ts +10 -0
  282. package/src/yjs/extensions/FixUpSchema.ts +11 -0
  283. package/src/yjs/extensions/ForkYDoc.browser.test.ts +84 -0
  284. package/src/yjs/extensions/ForkYDoc.node.test.ts +231 -0
  285. package/src/yjs/extensions/ForkYDoc.test.ts +68 -1
  286. package/src/yjs/extensions/ForkYDoc.ts +57 -39
  287. package/src/yjs/extensions/Versioning.test.ts +345 -530
  288. package/src/yjs/extensions/Versioning.ts +111 -68
  289. package/src/yjs/extensions/index.ts +1 -1
  290. package/src/yjs/index.ts +4 -0
  291. package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +2 -1
  292. package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +24 -24
  293. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +3 -2
  294. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +1 -1
  295. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -2
  296. package/types/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.d.ts +34 -0
  297. package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.d.ts +1 -0
  298. package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.d.ts +460 -0
  299. package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.d.ts +1 -0
  300. package/types/src/api/blockManipulation/layoutBlocks/plainBlocks.test.d.ts +1 -0
  301. package/types/src/api/blockManipulation/layoutBlocks/titledBlocks.test.d.ts +1 -0
  302. package/types/src/api/blockManipulation/setupTestEnv.d.ts +15 -69
  303. package/types/src/api/combineTransactionSteps.d.ts +12 -0
  304. package/types/src/api/getBlockInfoFromPos.d.ts +218 -44
  305. package/types/src/api/{getChangedRange.d.ts → getChangedRangeWithAttrs.d.ts} +1 -1
  306. package/types/src/api/getChangedRanges.d.ts +23 -0
  307. package/types/src/api/getChangedRanges.test.d.ts +1 -0
  308. package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +0 -3
  309. package/types/src/api/parsers/markdown/autolink.d.ts +5 -0
  310. package/types/src/blocks/ToggleWrapper/createToggleFrame.d.ts +29 -0
  311. package/types/src/blocks/ToggleWrapper/toggleBlocks.browser.test.d.ts +1 -0
  312. package/types/src/blocks/defaultBlockTypeItems.d.ts +37 -0
  313. package/types/src/blocks/defaultBlockTypeItems.test.d.ts +1 -0
  314. package/types/src/blocks/defaultBlocks.test.d.ts +1 -0
  315. package/types/src/blocks/index.d.ts +2 -1
  316. package/types/src/editor/BlockNoteEditor.d.ts +36 -8
  317. package/types/src/editor/BlockNoteEditor.node.test.d.ts +1 -0
  318. package/types/src/editor/blockColors.browser.test.d.ts +1 -0
  319. package/types/src/editor/managers/BlockManager.d.ts +4 -3
  320. package/types/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.d.ts +1 -0
  321. package/types/src/editor/managers/ExtensionManager/ExtensionManager.node.test.d.ts +1 -0
  322. package/types/src/editor/managers/ExtensionManager/index.d.ts +15 -3
  323. package/types/src/editor/managers/StateManager.d.ts +1 -1
  324. package/types/src/editor/transformPasted.d.ts +1 -1
  325. package/types/src/exporter/Exporter.d.ts +11 -4
  326. package/types/src/exporter/mapping.d.ts +13 -1
  327. package/types/src/extensions/DropCursor/DropCursor.d.ts +1 -1
  328. package/types/src/extensions/DropCursor/dropIntoChildren.d.ts +38 -0
  329. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.d.ts +1 -1
  330. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.d.ts +1 -0
  331. package/types/src/extensions/Placeholder/Placeholder.test.d.ts +1 -0
  332. package/types/src/extensions/ReadOnly/ReadOnly.d.ts +21 -0
  333. package/types/src/extensions/ReadOnly/ReadOnly.test.d.ts +1 -0
  334. package/types/src/extensions/SideMenu/SideMenu.d.ts +49 -88
  335. package/types/src/extensions/SideMenu/blockDropHandling.d.ts +11 -0
  336. package/types/src/extensions/SideMenu/blockGeometry.browser.test.d.ts +1 -0
  337. package/types/src/extensions/SideMenu/blockGeometry.d.ts +22 -0
  338. package/types/src/extensions/SideMenu/blockGeometry.test.d.ts +1 -0
  339. package/types/src/extensions/SideMenu/dragging.d.ts +0 -4
  340. package/types/src/extensions/SideMenu/sideMenuHover.d.ts +58 -0
  341. package/types/src/extensions/SideMenu/sideMenuHover.test.d.ts +1 -0
  342. package/types/src/extensions/Versioning/Versioning.browser.test.d.ts +1 -0
  343. package/types/src/extensions/Versioning/Versioning.d.ts +34 -311
  344. package/types/src/extensions/Versioning/Versioning.node.test.d.ts +1 -0
  345. package/types/src/extensions/Versioning/__test__/result.d.ts +3 -0
  346. package/types/src/extensions/Versioning/comparison.test.d.ts +1 -0
  347. package/types/src/extensions/Versioning/createVersioning.d.ts +32 -0
  348. package/types/src/extensions/Versioning/createVersioning.test.d.ts +1 -0
  349. package/types/src/extensions/Versioning/formatVersionDate.d.ts +7 -0
  350. package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +64 -36
  351. package/types/src/extensions/Versioning/index.d.ts +4 -0
  352. package/types/src/extensions/Versioning/scrollScheduling.test.d.ts +1 -0
  353. package/types/src/extensions/Versioning/scrollToFirstChange.d.ts +18 -0
  354. package/types/src/extensions/Versioning/scrollToFirstChange.test.d.ts +1 -0
  355. package/types/src/extensions/Versioning/types.d.ts +239 -0
  356. package/types/src/extensions/Versioning/versioningState.d.ts +43 -0
  357. package/types/src/extensions/blockDOM.browser.test.d.ts +1 -0
  358. package/types/src/extensions/blockDOM.d.ts +37 -0
  359. package/types/src/extensions/blockDOM.test.d.ts +1 -0
  360. package/types/src/extensions/index.d.ts +2 -0
  361. package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +1 -0
  362. package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +3 -0
  363. package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.d.ts +1 -0
  364. package/types/src/fonts/inter.browser.test.d.ts +2 -0
  365. package/types/src/i18n/locales/en.d.ts +32 -0
  366. package/types/src/i18n/locales/fa.d.ts +32 -0
  367. package/types/src/i18n/locales/sk.d.ts +32 -0
  368. package/types/src/index.d.ts +6 -3
  369. package/types/src/pm-nodes/BlockContainer.d.ts +6 -0
  370. package/types/src/pm-nodes/BlockContainer.test.d.ts +1 -0
  371. package/types/src/schema/blocks/children.d.ts +39 -0
  372. package/types/src/schema/blocks/children.test.d.ts +1 -0
  373. package/types/src/schema/blocks/createSpec.browser.test.d.ts +1 -0
  374. package/types/src/schema/blocks/createSpec.d.ts +13 -0
  375. package/types/src/schema/blocks/frame.d.ts +109 -0
  376. package/types/src/schema/blocks/frame.test.d.ts +1 -0
  377. package/types/src/schema/blocks/internal.d.ts +6 -0
  378. package/types/src/schema/blocks/keyboard.d.ts +111 -0
  379. package/types/src/schema/blocks/layoutBlockAttributes.d.ts +9 -0
  380. package/types/src/schema/blocks/meta.d.ts +14 -0
  381. package/types/src/schema/blocks/meta.test.d.ts +1 -0
  382. package/types/src/schema/blocks/renderFrame.test.d.ts +1 -0
  383. package/types/src/schema/blocks/types.d.ts +228 -15
  384. package/types/src/schema/blocks/validateChildren.d.ts +5 -0
  385. package/types/src/schema/dataAttributes.d.ts +19 -0
  386. package/types/src/schema/dataAttributes.test.d.ts +1 -0
  387. package/types/src/schema/index.d.ts +3 -0
  388. package/types/src/schema/markGroups.d.ts +8 -0
  389. package/types/src/user/userColors.d.ts +24 -3
  390. package/types/src/user/userColors.test.d.ts +1 -0
  391. package/types/src/y/comments/RESTYjsThreadStore.d.ts +1 -1
  392. package/types/src/y/comments/YjsThreadStore.d.ts +1 -1
  393. package/types/src/y/comments/YjsThreadStoreBase.d.ts +2 -2
  394. package/types/src/y/comments/yjsHelpers.d.ts +5 -5
  395. package/types/src/y/extensions/AttributionExtension.d.ts +19 -21
  396. package/types/src/y/extensions/DiffVersioningExtension.d.ts +9 -4
  397. package/types/src/y/extensions/EmptyDocBinding.test.d.ts +1 -0
  398. package/types/src/y/extensions/ForkYDoc.d.ts +3 -1
  399. package/types/src/y/extensions/ForkYDoc.node.test.d.ts +1 -0
  400. package/types/src/y/extensions/History.test.d.ts +1 -0
  401. package/types/src/y/extensions/Versioning.d.ts +4 -15
  402. package/types/src/y/extensions/Versioning.node.test.d.ts +1 -0
  403. package/types/src/y/extensions/YAttributionMarks.d.ts +13 -2
  404. package/types/src/y/extensions/YCursorPlugin.d.ts +1 -0
  405. package/types/src/y/extensions/YSync.d.ts +4 -18
  406. package/types/src/y/extensions/YSync.node.test.d.ts +1 -0
  407. package/types/src/y/extensions/YSyncRemount.test.d.ts +1 -0
  408. package/types/src/y/extensions/blockMatchNodes.d.ts +0 -22
  409. package/types/src/y/extensions/index.d.ts +27 -44
  410. package/types/src/y/extensions/legacyYjsDocBinding.test.d.ts +1 -0
  411. package/types/src/y/extensions/nestingChanges.test.d.ts +1 -0
  412. package/types/src/y/extensions/persistentBlockGroups.d.ts +189 -0
  413. package/types/src/y/extensions/persistentBlockGroups.test.d.ts +1 -0
  414. package/types/src/y/extensions/snapshotCodec.d.ts +13 -0
  415. package/types/src/y/extensions/snapshotCodec.test.d.ts +1 -0
  416. package/types/src/y/extensions/snapshotPreview.d.ts +21 -0
  417. package/types/src/y/extensions/snapshotPreview.test.d.ts +1 -0
  418. package/types/src/y/extensions/tableReshape.test.d.ts +1 -0
  419. package/types/src/y/extensions/v1BindingSnapshotDiff.test.d.ts +1 -0
  420. package/types/src/y/extensions/versionDiffAttribution.test.d.ts +1 -0
  421. package/types/src/y/extensions/versionDiffPerformance.test.d.ts +1 -0
  422. package/types/src/y/index.d.ts +1 -0
  423. package/types/src/y/utils.d.ts +39 -19
  424. package/types/src/y/versioning/index.d.ts +1 -1
  425. package/types/src/y/versioning/yhub.d.ts +69 -86
  426. package/types/src/y/versioning/yhubClient.d.ts +67 -0
  427. package/types/src/yjs/extensions/ForkYDoc.browser.test.d.ts +1 -0
  428. package/types/src/yjs/extensions/ForkYDoc.d.ts +2 -0
  429. package/types/src/yjs/extensions/ForkYDoc.node.test.d.ts +1 -0
  430. package/types/src/yjs/extensions/Versioning.d.ts +36 -22
  431. package/types/src/yjs/extensions/index.d.ts +2 -1
  432. package/types/src/yjs/index.d.ts +1 -0
  433. package/dist/BlockNoteExtension-BJCLnwrE.cjs +0 -2
  434. package/dist/BlockNoteExtension-BJCLnwrE.cjs.map +0 -1
  435. package/dist/BlockNoteExtension-CbvDA0F7.js.map +0 -1
  436. package/dist/blocks-DLgTreVu.cjs +0 -12
  437. package/dist/blocks-DLgTreVu.cjs.map +0 -1
  438. package/dist/blocks-DaEUT0O1.js.map +0 -1
  439. package/dist/en-BAn9gxr-.js.map +0 -1
  440. package/dist/en-CHnrV5l8.cjs +0 -2
  441. package/dist/en-CHnrV5l8.cjs.map +0 -1
  442. package/dist/extensions-B1JQURVF.js +0 -2138
  443. package/dist/extensions-B1JQURVF.js.map +0 -1
  444. package/dist/extensions-CZkqKzJO.cjs +0 -58
  445. package/dist/extensions-CZkqKzJO.cjs.map +0 -1
  446. package/dist/src-D5w0XAHX.js.map +0 -1
  447. package/dist/src-th5uZEvx.cjs +0 -23
  448. package/dist/src-th5uZEvx.cjs.map +0 -1
  449. package/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.ts +0 -173
  450. package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +0 -63
  451. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +0 -197
  452. package/src/blocks/utils/listItemEnterHandler.ts +0 -43
  453. package/src/extensions/Versioning/Versioning.test.ts +0 -435
  454. package/src/extensions/getDraggableBlockFromElement.ts +0 -19
  455. package/types/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.d.ts +0 -32
  456. package/types/src/blocks/ListItem/ListItemKeyboardShortcuts.d.ts +0 -2
  457. package/types/src/blocks/ToggleWrapper/createToggleWrapper.d.ts +0 -15
  458. package/types/src/blocks/utils/listItemEnterHandler.d.ts +0 -2
  459. package/types/src/extensions/getDraggableBlockFromElement.d.ts +0 -5
  460. /package/types/src/{extensions/Versioning/Versioning.test.d.ts → api/blockManipulation/commands/insertBlocks/insertPlacement.test.d.ts} +0 -0
@@ -0,0 +1,69 @@
1
+ import { camelToDataKebab } from "../util/string.js";
2
+ import type { PropSchema, Props } from "./propTypes.js";
3
+
4
+ /**
5
+ * The prop names to visit: the props' own order first, so an element's
6
+ * attributes keep the order its props were given in, then the schema's for
7
+ * the props left out. A prop the schema does not know has no attribute.
8
+ */
9
+ function propNames<PSchema extends PropSchema>(
10
+ props: Partial<Props<PSchema>>,
11
+ propSchema: PSchema,
12
+ ): (keyof PSchema & string)[] {
13
+ const names = new Set([...Object.keys(props), ...Object.keys(propSchema)]);
14
+ return [...names].filter((name) => name in propSchema);
15
+ }
16
+
17
+ /**
18
+ * The `data-*` attributes `props` serialize to: a `data-kebab-case` attribute
19
+ * holding each prop's value as a string, except props at their default (or
20
+ * absent), which have none. Parsing (`propsToAttributes`' `parseHTML`) reads
21
+ * these names back, so the rule lives here only. The result is what a new
22
+ * element gets set, what React spreads, and what tiptap merges into a node's
23
+ * HTML attributes.
24
+ */
25
+ export function propsToDataAttributes<PSchema extends PropSchema>(
26
+ props: Partial<Props<PSchema>>,
27
+ propSchema: PSchema,
28
+ ): Record<string, string> {
29
+ const attributes: Record<string, string> = {};
30
+ for (const name of propNames(props, propSchema)) {
31
+ const value = props[name];
32
+ if (value !== undefined && value !== propSchema[name].default) {
33
+ attributes[camelToDataKebab(name)] = String(value);
34
+ }
35
+ }
36
+ return attributes;
37
+ }
38
+
39
+ /** Sets `attributes` on a new element. Nothing is removed. */
40
+ export function setDataAttributes(
41
+ element: HTMLElement,
42
+ attributes: Record<string, string>,
43
+ ) {
44
+ for (const [name, value] of Object.entries(attributes)) {
45
+ element.setAttribute(name, value);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Makes an element's prop attributes follow `props`: sets those of the
51
+ * non-default props and removes those of every other prop in the schema, so
52
+ * an element that lives across updates (a layout block's root, the table view)
53
+ * drops stale attributes, including ones its author set.
54
+ */
55
+ export function applyDataAttributes<PSchema extends PropSchema>(
56
+ element: HTMLElement,
57
+ props: Partial<Props<PSchema>>,
58
+ propSchema: PSchema,
59
+ ) {
60
+ const attributes = propsToDataAttributes(props, propSchema);
61
+ for (const name of propNames(props, propSchema)) {
62
+ const attribute = camelToDataKebab(name);
63
+ if (attribute in attributes) {
64
+ element.setAttribute(attribute, attributes[attribute]);
65
+ } else {
66
+ element.removeAttribute(attribute);
67
+ }
68
+ }
69
+ }
@@ -1,6 +1,9 @@
1
1
  export * from "./blocks/createSpec.js";
2
+ export * from "./blocks/frame.js";
2
3
  export * from "./blocks/internal.js";
3
4
  export * from "./blocks/types.js";
5
+ export * from "./dataAttributes.js";
6
+ export type { BlockKeyboard, BlockKeyboardOption } from "./blocks/keyboard.js";
4
7
  export * from "./inlineContent/createSpec.js";
5
8
  export * from "./inlineContent/internal.js";
6
9
  export * from "./inlineContent/types.js";
@@ -4,7 +4,7 @@ import {
4
4
  Extension,
5
5
  ExtensionFactoryInstance,
6
6
  } from "../../editor/BlockNoteExtension.js";
7
- import { camelToDataKebab } from "../../util/string.js";
7
+ import { propsToDataAttributes, setDataAttributes } from "../dataAttributes.js";
8
8
  import { PropSchema, Props } from "../propTypes.js";
9
9
  import {
10
10
  CustomInlineContentConfig,
@@ -34,17 +34,12 @@ export function addInlineContentAttributes<
34
34
  } {
35
35
  // Sets content type attribute
36
36
  element.dom.setAttribute("data-inline-content-type", inlineContentType);
37
- // Adds props as HTML attributes in kebab-case with "data-" prefix. Skips props
38
- // set to their default values.
39
- Object.entries(inlineContentProps)
40
- .filter(([prop, value]) => {
41
- const spec = propSchema[prop];
42
- return value !== spec?.default;
43
- })
44
- .map(([prop, value]) => {
45
- return [camelToDataKebab(prop), value];
46
- })
47
- .forEach(([prop, value]) => element.dom.setAttribute(prop, value));
37
+ // Adds the props as `data-*` attributes, leaving out those at their default.
38
+ // Set only: the element is the author's, and their own attributes stay.
39
+ setDataAttributes(
40
+ element.dom,
41
+ propsToDataAttributes(inlineContentProps, propSchema),
42
+ );
48
43
 
49
44
  if (element.contentDOM) {
50
45
  element.contentDOM.setAttribute("data-editable", "");
@@ -1,4 +1,4 @@
1
- import { Editor, getExtensionField } from "@tiptap/core";
1
+ import { Editor, flattenExtensions, getExtensionField } from "@tiptap/core";
2
2
 
3
3
  /**
4
4
  * ProseMirror mark group for "non-formatting" marks: comments and the
@@ -36,7 +36,9 @@ export function nonFormattingMarks(editor: Editor | undefined): string {
36
36
  if (!editor) {
37
37
  return "";
38
38
  }
39
- const hasNonFormattingMark = editor.options.extensions.some((extension) => {
39
+ const hasNonFormattingMark = flattenExtensions(
40
+ editor.options.extensions,
41
+ ).some((extension) => {
40
42
  if (extension.type !== "mark") {
41
43
  return false;
42
44
  }
@@ -48,3 +50,33 @@ export function nonFormattingMarks(editor: Editor | undefined): string {
48
50
  });
49
51
  return hasNonFormattingMark ? NON_FORMATTING_MARK_GROUP : "";
50
52
  }
53
+
54
+ /**
55
+ * The `excludes` field value for marks which may coexist with annotation marks
56
+ * but should exclude all other marks.
57
+ *
58
+ * Returns `"_"` when no editor is available, preserving ProseMirror's default
59
+ * behavior for schema creation outside an editor.
60
+ */
61
+ export function marksExcludingNonFormattingMarks(
62
+ editor: Editor | undefined,
63
+ ): string {
64
+ if (!editor) {
65
+ return "_";
66
+ }
67
+
68
+ return flattenExtensions(editor.options.extensions)
69
+ .filter((extension) => {
70
+ if (extension.type !== "mark") {
71
+ return false;
72
+ }
73
+
74
+ const group = getExtensionField(extension, "group") as string | undefined;
75
+ return (
76
+ typeof group !== "string" ||
77
+ !group.split(" ").includes(NON_FORMATTING_MARK_GROUP)
78
+ );
79
+ })
80
+ .map((extension) => extension.name)
81
+ .join(" ");
82
+ }
@@ -16,6 +16,7 @@ import {
16
16
  getInlineContentSchemaFromSpecs,
17
17
  getStyleSchemaFromSpecs,
18
18
  } from "./index.js";
19
+ import { validateChildrenConfigs } from "./blocks/validateChildren.js";
19
20
 
20
21
  function removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {
21
22
  if (!obj) {
@@ -91,6 +92,10 @@ export class CustomBlockNoteSchema<
91
92
  })),
92
93
  );
93
94
 
95
+ // Validation runs before the nodes are built, so the misconfigurations
96
+ // ProseMirror cannot report on its own surface as clear errors.
97
+ validateChildrenConfigs(this.opts.blockSpecs);
98
+
94
99
  const blockSpecs = Object.fromEntries(
95
100
  Object.entries(this.opts.blockSpecs).map(([key, blockSpec]) => {
96
101
  return [
@@ -193,7 +198,9 @@ export class CustomBlockNoteSchema<
193
198
  AdditionalInlineContentSpecs extends undefined | Record<string, never>
194
199
  ? ISchema
195
200
  : ISchema & {
196
- [K in keyof AdditionalInlineContentSpecs]: AdditionalInlineContentSpecs[K]["config"];
201
+ [
202
+ K in keyof AdditionalInlineContentSpecs
203
+ ]: AdditionalInlineContentSpecs[K]["config"];
197
204
  },
198
205
  AdditionalStyleSpecs extends undefined | Record<string, never>
199
206
  ? SSchema
@@ -0,0 +1,108 @@
1
+ import { describe, expect, it } from "vite-plus/test";
2
+
3
+ import type { User } from "./UserStore.js";
4
+ import { createUserStore } from "./UserStore.js";
5
+ import {
6
+ colorsForUserIds,
7
+ fallbackColorForUserId,
8
+ userColorPalette,
9
+ userMarkColors,
10
+ } from "./userColors.js";
11
+
12
+ describe("userColorPalette", () => {
13
+ it("contains no red or green", () => {
14
+ // The palette tints insertions as well as deletions, and diffs use red for
15
+ // deleted and green for inserted content. Guard the property rather than
16
+ // the exact hexes: no entry may have a red or a green hue.
17
+ for (const { light, dark } of userColorPalette) {
18
+ for (const color of [light, dark]) {
19
+ const [r, g, b] = [1, 3, 5].map(
20
+ (offset) => parseInt(color.slice(offset, offset + 2), 16) / 255,
21
+ );
22
+ const max = Math.max(r, g, b);
23
+ const delta = max - Math.min(r, g, b);
24
+ if (delta < 0.05) {
25
+ continue; // grey: no hue
26
+ }
27
+ const hue =
28
+ (60 *
29
+ (max === r
30
+ ? ((g - b) / delta) % 6
31
+ : max === g
32
+ ? (b - r) / delta + 2
33
+ : (r - g) / delta + 4) +
34
+ 360) %
35
+ 360;
36
+ expect(hue >= 340 || hue <= 20, `${color} reads as red`).toBe(false);
37
+ expect(hue >= 90 && hue <= 160, `${color} reads as green`).toBe(false);
38
+ }
39
+ }
40
+ });
41
+
42
+ it("assigns a stable entry per user id", () => {
43
+ expect(fallbackColorForUserId("alice")).toEqual(
44
+ fallbackColorForUserId("alice"),
45
+ );
46
+ expect(userColorPalette).toContainEqual(fallbackColorForUserId("alice"));
47
+ });
48
+ });
49
+
50
+ describe("userMarkColors", () => {
51
+ it("is undefined for a user with no color", () => {
52
+ expect(userMarkColors(undefined)).toBeUndefined();
53
+ expect(userMarkColors({})).toBeUndefined();
54
+ });
55
+
56
+ it("uses both colors when the app supplies both", () => {
57
+ expect(userMarkColors({ color: "#123456", colorLight: "#abcdef" })).toEqual(
58
+ {
59
+ light: "#abcdef",
60
+ dark: "#123456",
61
+ },
62
+ );
63
+ });
64
+
65
+ it("derives the light tint when only `color` is set", () => {
66
+ expect(userMarkColors({ color: "#123456" })).toEqual({
67
+ light: "color-mix(in srgb, #123456 30%, white)",
68
+ dark: "#123456",
69
+ });
70
+ });
71
+ });
72
+
73
+ describe("colorsForUserIds", () => {
74
+ it("falls back to the first palette entry with no ids", () => {
75
+ const store = createUserStore<User>(async () => []);
76
+ expect(colorsForUserIds(store, undefined)).toEqual(userColorPalette[0]);
77
+ expect(colorsForUserIds(store, [])).toEqual(userColorPalette[0]);
78
+ });
79
+
80
+ it("falls back to the id's palette entry for an unresolved user", () => {
81
+ const store = createUserStore<User>(async () => []);
82
+ expect(colorsForUserIds(store, ["alice"])).toEqual(
83
+ fallbackColorForUserId("alice"),
84
+ );
85
+ });
86
+
87
+ it("uses the resolved user's own colors, deriving the tint when needed", async () => {
88
+ const store = createUserStore<User>(async (ids: string[]) =>
89
+ ids.map((id) => ({
90
+ id,
91
+ username: id,
92
+ avatarUrl: "",
93
+ color: id === "both" ? "#123456" : "#654321",
94
+ ...(id === "both" ? { colorLight: "#abcdef" } : {}),
95
+ })),
96
+ );
97
+ await store.loadUsers(["both", "dark-only"]);
98
+
99
+ expect(colorsForUserIds(store, ["both"])).toEqual({
100
+ light: "#abcdef",
101
+ dark: "#123456",
102
+ });
103
+ expect(colorsForUserIds(store, ["dark-only"])).toEqual({
104
+ light: "color-mix(in srgb, #654321 30%, white)",
105
+ dark: "#654321",
106
+ });
107
+ });
108
+ });
@@ -1,5 +1,5 @@
1
1
  import { digestString } from "lib0/hash/fnv1a";
2
- import type { UserStore } from "./UserStore.js";
2
+ import type { User, UserStore } from "./UserStore.js";
3
3
 
4
4
  /**
5
5
  * Deterministic hash of a string to an unsigned 32-bit integer.
@@ -12,13 +12,22 @@ const hashStr = (s: string): number => {
12
12
  return Math.abs(hash);
13
13
  };
14
14
 
15
- /** Fallback palette used when a user has no resolved color of their own. */
15
+ /**
16
+ * Fallback palette used when a user has no resolved color of their own.
17
+ *
18
+ * Deliberately free of red and green: these colors tint *insertions* as well as
19
+ * deletions, and diffs conventionally use red for deleted and green for
20
+ * inserted content. A red insertion would read as a deletion, and a green
21
+ * deletion as an insertion. The hues are spread far enough apart to stay
22
+ * distinguishable for the most common forms of colour-vision deficiency.
23
+ */
16
24
  export const userColorPalette: Array<{ light: string; dark: string }> = [
17
- { light: "#fff0c2", dark: "#8a6d1a" },
18
- { light: "#fcc9c3", dark: "#8a2e24" },
19
- { light: "#d4e8eb", dark: "#4a7178" },
20
- { light: "#c2eeff", dark: "#1a6e8a" },
21
- { light: "#bef3ff", dark: "#0a7a8a" },
25
+ { light: "#fff0c2", dark: "#8a6d1a" }, // amber
26
+ { light: "#cdeffd", dark: "#0b6a8a" }, // sky
27
+ { light: "#d6defd", dark: "#2948b3" }, // blue
28
+ { light: "#eadcfb", dark: "#6b2fa3" }, // violet
29
+ { light: "#f1e2d3", dark: "#7a4a1e" }, // brown
30
+ { light: "#dfe4ea", dark: "#46525f" }, // slate
22
31
  ];
23
32
 
24
33
  /** The deterministic {@link userColorPalette} entry for a single user id. */
@@ -28,7 +37,28 @@ export const fallbackColorForUserId = (
28
37
  userColorPalette[hashStr(id) % userColorPalette.length];
29
38
 
30
39
  /**
31
- * The (first) user's resolved color from the {@link UserStore}, or their
40
+ * A user's own mark colors, or `undefined` when they have none.
41
+ *
42
+ * `color` is the saturated color the app already uses for that user (cursors,
43
+ * avatars); `colorLight` is the pale background a mark is highlighted with. Most
44
+ * applications only set the former, so derive the latter rather than fall back
45
+ * to a palette entry that has nothing to do with the user's actual color — a
46
+ * user whose cursor is green shouldn't have amber marks.
47
+ */
48
+ export const userMarkColors = (
49
+ user: Pick<User, "color" | "colorLight"> | undefined,
50
+ ): { light: string; dark: string } | undefined => {
51
+ if (!user?.color) {
52
+ return undefined;
53
+ }
54
+ return {
55
+ light: user.colorLight ?? `color-mix(in srgb, ${user.color} 30%, white)`,
56
+ dark: user.color,
57
+ };
58
+ };
59
+
60
+ /**
61
+ * The (first) user's {@link userMarkColors}, or their
32
62
  * {@link fallbackColorForUserId} palette entry. Used where a concrete color
33
63
  * string is needed (the portaled hover tooltip); marks themselves use the
34
64
  * cascaded {@link userColorVarNames} properties instead.
@@ -41,11 +71,10 @@ export const colorsForUserIds = (
41
71
  return userColorPalette[0];
42
72
  }
43
73
  const firstId = userIds[0];
44
- const user = userStore.getUser(firstId);
45
- if (user?.color && user.colorLight) {
46
- return { light: user.colorLight, dark: user.color };
47
- }
48
- return fallbackColorForUserId(firstId);
74
+ return (
75
+ userMarkColors(userStore.getUser(firstId)) ??
76
+ fallbackColorForUserId(firstId)
77
+ );
49
78
  };
50
79
 
51
80
  /**
@@ -21,7 +21,7 @@ export class RESTYjsThreadStore extends YjsThreadStoreBase {
21
21
  constructor(
22
22
  private readonly BASE_URL: string,
23
23
  private readonly headers: Record<string, string>,
24
- threadsYType: Y.Type,
24
+ threadsYType: Y.Node,
25
25
  auth: ThreadStoreAuth,
26
26
  ) {
27
27
  super(threadsYType, auth);
@@ -14,7 +14,7 @@ vi.mock("lib0/random", async (importOriginal) => ({
14
14
  describe("YjsThreadStore (@y/y v14)", () => {
15
15
  let store: YjsThreadStore;
16
16
  let doc: Y.Doc;
17
- let threadsYType: Y.Type;
17
+ let threadsYType: Y.Node;
18
18
 
19
19
  beforeEach(() => {
20
20
  // Reset mocks and create fresh instances
@@ -29,7 +29,7 @@ import {
29
29
  export class YjsThreadStore extends YjsThreadStoreBase {
30
30
  constructor(
31
31
  private readonly userId: string,
32
- threadsYType: Y.Type,
32
+ threadsYType: Y.Node,
33
33
  auth: ThreadStoreAuth,
34
34
  ) {
35
35
  super(threadsYType, auth);
@@ -98,7 +98,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
98
98
  threadId: string;
99
99
  }) => {
100
100
  const yThread = this.threadsYType.getAttr(options.threadId) as
101
- | Y.Type
101
+ | Y.Node
102
102
  | undefined;
103
103
  if (!yThread) {
104
104
  throw new Error("Thread not found");
@@ -121,7 +121,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
121
121
  body: options.comment.body,
122
122
  };
123
123
 
124
- (yThread.getAttr("comments") as Y.Type).push([commentToYType(comment)]);
124
+ (yThread.getAttr("comments") as Y.Node).push([commentToYType(comment)]);
125
125
 
126
126
  yThread.setAttr("updatedAt", new Date().getTime());
127
127
  return comment;
@@ -138,23 +138,23 @@ export class YjsThreadStore extends YjsThreadStoreBase {
138
138
  commentId: string;
139
139
  }) => {
140
140
  const yThread = this.threadsYType.getAttr(options.threadId) as
141
- | Y.Type
141
+ | Y.Node
142
142
  | undefined;
143
143
  if (!yThread) {
144
144
  throw new Error("Thread not found");
145
145
  }
146
146
 
147
- const commentsType = yThread.getAttr("comments") as Y.Type;
147
+ const commentsType = yThread.getAttr("comments") as Y.Node;
148
148
  const yCommentIndex = yTypeFindIndex(
149
149
  commentsType,
150
- (comment) => (comment as Y.Type).getAttr("id") === options.commentId,
150
+ (comment) => (comment as Y.Node).getAttr("id") === options.commentId,
151
151
  );
152
152
 
153
153
  if (yCommentIndex === -1) {
154
154
  throw new Error("Comment not found");
155
155
  }
156
156
 
157
- const yComment = commentsType.get(yCommentIndex) as Y.Type;
157
+ const yComment = commentsType.get(yCommentIndex) as Y.Node;
158
158
 
159
159
  if (!this.auth.canUpdateComment(yTypeToComment(yComment))) {
160
160
  throw new Error("Not authorized");
@@ -173,23 +173,23 @@ export class YjsThreadStore extends YjsThreadStoreBase {
173
173
  softDelete?: boolean;
174
174
  }) => {
175
175
  const yThread = this.threadsYType.getAttr(options.threadId) as
176
- | Y.Type
176
+ | Y.Node
177
177
  | undefined;
178
178
  if (!yThread) {
179
179
  throw new Error("Thread not found");
180
180
  }
181
181
 
182
- const commentsType = yThread.getAttr("comments") as Y.Type;
182
+ const commentsType = yThread.getAttr("comments") as Y.Node;
183
183
  const yCommentIndex = yTypeFindIndex(
184
184
  commentsType,
185
- (comment) => (comment as Y.Type).getAttr("id") === options.commentId,
185
+ (comment) => (comment as Y.Node).getAttr("id") === options.commentId,
186
186
  );
187
187
 
188
188
  if (yCommentIndex === -1) {
189
189
  throw new Error("Comment not found");
190
190
  }
191
191
 
192
- const yComment = commentsType.get(yCommentIndex) as Y.Type;
192
+ const yComment = commentsType.get(yCommentIndex) as Y.Node;
193
193
 
194
194
  if (!this.auth.canDeleteComment(yTypeToComment(yComment))) {
195
195
  throw new Error("Not authorized");
@@ -209,7 +209,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
209
209
  if (
210
210
  commentsType
211
211
  .toArray()
212
- .every((comment) => (comment as Y.Type).getAttr("deletedAt"))
212
+ .every((comment) => (comment as Y.Node).getAttr("deletedAt"))
213
213
  ) {
214
214
  // all comments deleted
215
215
  if (options.softDelete) {
@@ -226,7 +226,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
226
226
  public deleteThread = this.transact((options: { threadId: string }) => {
227
227
  if (
228
228
  !this.auth.canDeleteThread(
229
- yTypeToThread(this.threadsYType.getAttr(options.threadId) as Y.Type),
229
+ yTypeToThread(this.threadsYType.getAttr(options.threadId) as Y.Node),
230
230
  )
231
231
  ) {
232
232
  throw new Error("Not authorized");
@@ -237,7 +237,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
237
237
 
238
238
  public resolveThread = this.transact((options: { threadId: string }) => {
239
239
  const yThread = this.threadsYType.getAttr(options.threadId) as
240
- | Y.Type
240
+ | Y.Node
241
241
  | undefined;
242
242
  if (!yThread) {
243
243
  throw new Error("Thread not found");
@@ -254,7 +254,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
254
254
 
255
255
  public unresolveThread = this.transact((options: { threadId: string }) => {
256
256
  const yThread = this.threadsYType.getAttr(options.threadId) as
257
- | Y.Type
257
+ | Y.Node
258
258
  | undefined;
259
259
  if (!yThread) {
260
260
  throw new Error("Thread not found");
@@ -271,23 +271,23 @@ export class YjsThreadStore extends YjsThreadStoreBase {
271
271
  public addReaction = this.transact(
272
272
  (options: { threadId: string; commentId: string; emoji: string }) => {
273
273
  const yThread = this.threadsYType.getAttr(options.threadId) as
274
- | Y.Type
274
+ | Y.Node
275
275
  | undefined;
276
276
  if (!yThread) {
277
277
  throw new Error("Thread not found");
278
278
  }
279
279
 
280
- const commentsType = yThread.getAttr("comments") as Y.Type;
280
+ const commentsType = yThread.getAttr("comments") as Y.Node;
281
281
  const yCommentIndex = yTypeFindIndex(
282
282
  commentsType,
283
- (comment) => (comment as Y.Type).getAttr("id") === options.commentId,
283
+ (comment) => (comment as Y.Node).getAttr("id") === options.commentId,
284
284
  );
285
285
 
286
286
  if (yCommentIndex === -1) {
287
287
  throw new Error("Comment not found");
288
288
  }
289
289
 
290
- const yComment = commentsType.get(yCommentIndex) as Y.Type;
290
+ const yComment = commentsType.get(yCommentIndex) as Y.Node;
291
291
 
292
292
  if (!this.auth.canAddReaction(yTypeToComment(yComment), options.emoji)) {
293
293
  throw new Error("Not authorized");
@@ -297,13 +297,13 @@ export class YjsThreadStore extends YjsThreadStoreBase {
297
297
 
298
298
  const key = `${this.userId}-${options.emoji}`;
299
299
 
300
- const reactionsByUser = yComment.getAttr("reactionsByUser") as Y.Type;
300
+ const reactionsByUser = yComment.getAttr("reactionsByUser") as Y.Node;
301
301
 
302
302
  if (reactionsByUser.hasAttr(key)) {
303
303
  // already exists
304
304
  return;
305
305
  } else {
306
- const reaction = new Y.Type();
306
+ const reaction = new Y.Node();
307
307
  reaction.setAttr("emoji", options.emoji);
308
308
  reaction.setAttr("createdAt", date.getTime());
309
309
  reaction.setAttr("userId", this.userId);
@@ -315,23 +315,23 @@ export class YjsThreadStore extends YjsThreadStoreBase {
315
315
  public deleteReaction = this.transact(
316
316
  (options: { threadId: string; commentId: string; emoji: string }) => {
317
317
  const yThread = this.threadsYType.getAttr(options.threadId) as
318
- | Y.Type
318
+ | Y.Node
319
319
  | undefined;
320
320
  if (!yThread) {
321
321
  throw new Error("Thread not found");
322
322
  }
323
323
 
324
- const commentsType = yThread.getAttr("comments") as Y.Type;
324
+ const commentsType = yThread.getAttr("comments") as Y.Node;
325
325
  const yCommentIndex = yTypeFindIndex(
326
326
  commentsType,
327
- (comment) => (comment as Y.Type).getAttr("id") === options.commentId,
327
+ (comment) => (comment as Y.Node).getAttr("id") === options.commentId,
328
328
  );
329
329
 
330
330
  if (yCommentIndex === -1) {
331
331
  throw new Error("Comment not found");
332
332
  }
333
333
 
334
- const yComment = commentsType.get(yCommentIndex) as Y.Type;
334
+ const yComment = commentsType.get(yCommentIndex) as Y.Node;
335
335
 
336
336
  if (
337
337
  !this.auth.canDeleteReaction(yTypeToComment(yComment), options.emoji)
@@ -341,14 +341,14 @@ export class YjsThreadStore extends YjsThreadStoreBase {
341
341
 
342
342
  const key = `${this.userId}-${options.emoji}`;
343
343
 
344
- const reactionsByUser = yComment.getAttr("reactionsByUser") as Y.Type;
344
+ const reactionsByUser = yComment.getAttr("reactionsByUser") as Y.Node;
345
345
 
346
346
  reactionsByUser.deleteAttr(key);
347
347
  },
348
348
  );
349
349
  }
350
350
 
351
- function yTypeFindIndex(yType: Y.Type, predicate: (item: any) => boolean) {
351
+ function yTypeFindIndex(yType: Y.Node, predicate: (item: any) => boolean) {
352
352
  for (let i = 0; i < yType.length; i++) {
353
353
  if (predicate(yType.get(i))) {
354
354
  return i;
@@ -10,7 +10,7 @@ import { yTypeToThread } from "./yjsHelpers.js";
10
10
  */
11
11
  export abstract class YjsThreadStoreBase extends ThreadStore {
12
12
  constructor(
13
- protected readonly threadsYType: Y.Type,
13
+ protected readonly threadsYType: Y.Node,
14
14
  auth: ThreadStoreAuth,
15
15
  ) {
16
16
  super(auth);
@@ -29,7 +29,7 @@ export abstract class YjsThreadStoreBase extends ThreadStore {
29
29
  public getThreads(): Map<string, ThreadData> {
30
30
  const threadMap = new Map<string, ThreadData>();
31
31
  this.threadsYType.forEachAttr((yThread: any, id: string | number) => {
32
- if (yThread instanceof Y.Type) {
32
+ if (yThread instanceof Y.Node) {
33
33
  threadMap.set(String(id), yTypeToThread(yThread));
34
34
  }
35
35
  });