@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
@@ -1,11 +1,8 @@
1
+ import type { FrameView } from "./frame.js";
1
2
  /** Define the main block types **/
2
3
  // import { Extension, Node } from "@tiptap/core";
3
4
  import type { Node, NodeViewRendererProps } from "@tiptap/core";
4
- import type {
5
- Fragment,
6
- Node as ProsemirrorNode,
7
- Schema,
8
- } from "prosemirror-model";
5
+ import type { Fragment, Node as PMNode, Schema } from "prosemirror-model";
9
6
  import type { ViewMutationRecord } from "prosemirror-view";
10
7
  import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
11
8
  import type {
@@ -19,6 +16,7 @@ import type {
19
16
  StyledText,
20
17
  } from "../inlineContent/types.js";
21
18
  import type { PropSchema, Props } from "../propTypes.js";
19
+ import type { BlockKeyboard, BlockKeyboardOption } from "./keyboard.js";
22
20
  import type { StyleSchema } from "../styles/types.js";
23
21
 
24
22
  export type BlockNoteDOMElement =
@@ -39,6 +37,10 @@ export interface BlockConfigMeta<
39
37
  /**
40
38
  * Defines which keyboard shortcut should be used to insert a hard break into the block's inline content.
41
39
  * @default "shift+enter"
40
+ * @deprecated Use `experimental_keyboard.enter` and
41
+ * `experimental_keyboard.shiftEnter` instead: `"enter"` is
42
+ * `experimental_keyboard: { enter: "line-break" }`, and `"none"` is
43
+ * `experimental_keyboard: { shiftEnter: "same-as-enter" }`.
42
44
  */
43
45
  hardBreakShortcut?: "shift+enter" | "enter" | "none";
44
46
 
@@ -67,6 +69,25 @@ export interface BlockConfigMeta<
67
69
  */
68
70
  isolating?: boolean;
69
71
 
72
+ /**
73
+ * Whether this block type gets a side menu drag handle (and can be dragged
74
+ * by it). Applies to any block type, layout block or not: e.g. a
75
+ * "locked" block can opt out of dragging entirely. A block that opts out is
76
+ * skipped when looking for a drag handle, so the handle falls through to the
77
+ * nearest draggable ancestor.
78
+ * @default `true`, or `false` for a layout block placeable `"namedOnly"`, which
79
+ * can only live in its parent
80
+ */
81
+ draggable?: boolean;
82
+
83
+ /**
84
+ * Whether a block dragged onto this block's content or frame chrome becomes
85
+ * its first child (as in Notion's toggles), instead of going before or after
86
+ * it. A block dragged onto its children still goes between them.
87
+ * @default false
88
+ */
89
+ dropsIntoChildren?(block: { type: TName; props: Props<TProps> }): boolean;
90
+
70
91
  /**
71
92
  * Enables syntax highlighting of the contents of the block with the result of this callback
72
93
  */
@@ -81,9 +102,82 @@ export interface BlockConfigMeta<
81
102
  }
82
103
 
83
104
  /**
84
- * BlockConfig contains the "schema" info about a Block type
85
- * i.e. what props it supports, what content it supports, etc.
105
+ * A block's `meta` with every default applied: what a block spec in a schema
106
+ * holds, so readers never see a missing setting (see `resolveBlockMeta`).
107
+ */
108
+ export type ResolvedBlockConfigMeta<
109
+ TName extends string = string,
110
+ TProps extends PropSchema = PropSchema,
111
+ > = BlockConfigMeta<TName, TProps> &
112
+ Required<
113
+ Pick<
114
+ BlockConfigMeta<TName, TProps>,
115
+ "selectable" | "code" | "defining" | "isolating" | "draggable"
116
+ >
117
+ >;
118
+
119
+ /**
120
+ * The type name of a layout block, as used in {@link ChildrenConfig.allow}.
121
+ */
122
+ export type AllowedChildType = string;
123
+
124
+ /**
125
+ * What may appear as a child of a layout block.
126
+ *
127
+ * - `"blocks"`: any regular block, or any layout block placeable anywhere.
128
+ * This cannot be narrowed to specific regular block types: every regular
129
+ * block is the *same* ProseMirror node (`blockContainer`), so paragraphs,
130
+ * headings and code blocks are indistinguishable at the node level.
131
+ * - `readonly AllowedChildType[]`: only these layout block types, enforced exactly
132
+ * by the schema. Naming a regular block type is a startup error; per-type
133
+ * regular-block filtering can be added to this same form later, with no API
134
+ * change.
135
+ *
136
+ * Neither form includes `placeable: "namedOnly"` types. Those appear only
137
+ * where a parent names them explicitly in an array.
138
+ */
139
+ export type ChildrenAllow = "blocks" | readonly AllowedChildType[];
140
+
141
+ /**
142
+ * Which child blocks a layout block holds (`layoutOnly: true`), exposed as
143
+ * `block.children` at runtime.
144
+ *
145
+ * The config describes one uniform set of children, semantically a single
146
+ * implicit slot. Ordered multi-slot children (a `sequence` of slots) can be
147
+ * added later as a sibling form.
86
148
  */
149
+ export type ChildrenConfig =
150
+ | {
151
+ /**
152
+ * Any blocks, the default. When its last child is removed, the
153
+ * layout block is removed too.
154
+ */
155
+ allow?: "blocks";
156
+ /**
157
+ * Layout block types the block does not hold, out of those placeable
158
+ * anywhere: a column holds any block except a column list. Regular
159
+ * block types can't be excluded, as every regular block is the same
160
+ * ProseMirror node.
161
+ */
162
+ exclude?: readonly AllowedChildType[];
163
+ }
164
+ | {
165
+ /** Which layout block types may appear as a child. */
166
+ allow: readonly AllowedChildType[];
167
+ /**
168
+ * How few children the layout block may hold; `0` lets it be empty.
169
+ * @default 1
170
+ */
171
+ min?: number;
172
+ /**
173
+ * Whether a layout block with too few children dissolves into what they
174
+ * hold, like a column list with one column left. `false` keeps the
175
+ * layout block and its empty children, like a tab set.
176
+ * @default true
177
+ */
178
+ dissolve?: boolean;
179
+ };
180
+
87
181
  export interface BlockConfig<
88
182
  T extends string = string,
89
183
  PS extends PropSchema = PropSchema,
@@ -106,8 +200,55 @@ export interface BlockConfig<
106
200
  * The content that the block supports
107
201
  */
108
202
  content: C;
109
- // TODO: how do you represent things that have nested content?
110
- // e.g. tables, alerts (with title & content)
203
+ /**
204
+ * `true` makes the block a layout block: a block without content of its own
205
+ * (`content: "none"`) whose own node holds its child blocks. Its
206
+ * `renderFrame` puts them in its slot (React: `slotRef`). With `false` (the
207
+ * default), the block's child blocks are indented below it. Only a block
208
+ * with `content: "none"` can set `true`.
209
+ */
210
+ layoutOnly?: C extends "none" ? boolean : false;
211
+ /**
212
+ * Which child blocks the block may have. Every block can have any child
213
+ * blocks (`{ allow: "blocks" }`, the default). Only a layout block
214
+ * (`layoutOnly: true`) can restrict them to certain types or a minimum
215
+ * count, since the child blocks of other blocks all share one untyped
216
+ * group. How the keyboard treats a block's children (e.g. whether Enter in
217
+ * the block's text starts them) is set with its `experimental_keyboard`
218
+ * settings.
219
+ */
220
+ children?: C extends "none"
221
+ ? ChildrenConfig
222
+ : {
223
+ allow?: "blocks";
224
+ exclude?: undefined;
225
+ min?: undefined;
226
+ dissolve?: undefined;
227
+ };
228
+ /**
229
+ * Where this block may be placed.
230
+ *
231
+ * - `"anywhere"` (default): anywhere a regular block goes, the document
232
+ * root or nested under any other block.
233
+ * - `"namedOnly"`: only inside a layout block that names this type in its
234
+ * `children.allow` array (e.g. a `column` inside a `columnList`).
235
+ *
236
+ * Only meaningful for layout blocks; regular blocks are always placeable
237
+ * anywhere.
238
+ */
239
+ placeable?: "anywhere" | "namedOnly";
240
+ }
241
+
242
+ declare module "prosemirror-model" {
243
+ interface NodeSpec {
244
+ /**
245
+ * The config of the BlockNote block this node was built from, so code
246
+ * holding a bare `Node` can read block-level facts (like the content
247
+ * kind) without an editor or schema reference. Set on every node built
248
+ * from a block spec.
249
+ */
250
+ blockConfig?: BlockConfig;
251
+ }
111
252
  }
112
253
 
113
254
  /**
@@ -212,10 +353,19 @@ export type LooseBlockSpec<
212
353
  config: BlockConfig<T, PS, C>;
213
354
  implementation: Omit<
214
355
  BlockImplementation<T, PS, C>,
215
- "render" | "toExternalHTML"
356
+ | "render"
357
+ | "renderFrame"
358
+ | "toExternalHTML"
359
+ | "experimental_keyboard"
360
+ | "meta"
216
361
  > & {
362
+ /** Every keyboard setting of the block, with defaults filled in. */
363
+ keyboard: (block: any) => BlockKeyboard;
364
+ /** The block's `meta`, with defaults filled in. */
365
+ meta: ResolvedBlockConfigMeta<T, PS>;
217
366
  // purposefully stub the types for render and toExternalHTML since they reference the block
218
- render: (
367
+ // A layout block declares `renderFrame` instead of `render`.
368
+ render?: (
219
369
  /**
220
370
  * The custom block to render
221
371
  */
@@ -228,9 +378,21 @@ export type LooseBlockSpec<
228
378
  dom: HTMLElement | DocumentFragment;
229
379
  contentDOM?: HTMLElement;
230
380
  ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
231
- update?: (node: ProsemirrorNode) => boolean;
232
381
  destroy?: () => void;
382
+ update?: (node: PMNode) => boolean | void;
233
383
  };
384
+ renderFrame?: <I extends InlineContentSchema, S extends StyleSchema>(
385
+ block: any,
386
+ editor: BlockNoteEditor<any, I, S>,
387
+ ) =>
388
+ | {
389
+ dom: HTMLElement;
390
+ slot: HTMLElement;
391
+ /** Releases resources when the live frame is replaced or destroyed. */
392
+ destroy?: () => void;
393
+ update?: (block: any) => boolean | void;
394
+ }
395
+ | undefined;
234
396
  toExternalHTML?: (
235
397
  block: any,
236
398
  editor: BlockNoteEditor<any>,
@@ -271,10 +433,12 @@ export type BlockSpecs = {
271
433
  config: BlockSpec<k>["config"];
272
434
  implementation: Omit<
273
435
  BlockSpec<k>["implementation"],
274
- "render" | "toExternalHTML"
436
+ "render" | "renderFrame" | "toExternalHTML" | "experimental_keyboard"
275
437
  > & {
438
+ experimental_keyboard?: BlockKeyboardOption<any>;
276
439
  // purposefully stub the types for render and toExternalHTML since they reference the block
277
- render: (
440
+ // A layout block declares `renderFrame` instead of `render`.
441
+ render?: (
278
442
  /**
279
443
  * The custom block to render
280
444
  */
@@ -287,9 +451,21 @@ export type BlockSpecs = {
287
451
  dom: HTMLElement | DocumentFragment;
288
452
  contentDOM?: HTMLElement;
289
453
  ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
290
- update?: (node: ProsemirrorNode) => boolean;
291
454
  destroy?: () => void;
455
+ update?: (node: PMNode) => boolean | void;
292
456
  };
457
+ renderFrame?: <I extends InlineContentSchema, S extends StyleSchema>(
458
+ block: any,
459
+ editor: BlockNoteEditor<any, I, S>,
460
+ ) =>
461
+ | {
462
+ dom: HTMLElement;
463
+ slot: HTMLElement;
464
+ /** Releases resources when the live frame is replaced or destroyed. */
465
+ destroy?: () => void;
466
+ update?: (block: any) => boolean | void;
467
+ }
468
+ | undefined;
293
469
  toExternalHTML?: (
294
470
  block: any,
295
471
  editor: BlockNoteEditor<any>,
@@ -554,14 +730,40 @@ export type BlockImplementation<
554
730
  | "table"
555
731
  | "plain",
556
732
  > = {
733
+ /**
734
+ * @internal Framework adapter (React): draws the block's frame in the
735
+ * editor, for the node view of a framed block's `blockContainer` or of a
736
+ * layout block. Core uses it instead of the vanilla `renderFrame` when present.
737
+ *
738
+ * TODO: the content node view has no such hook yet: React builds it inside
739
+ * `render` (see the `TODO` there). Add one, so `render` / `renderFrame`
740
+ * only draw.
741
+ */
742
+ frameView?: (props: NodeViewRendererProps) => FrameView;
557
743
  /**
558
744
  * Metadata
559
745
  */
560
746
  meta?: BlockConfigMeta<TName, TProps>;
561
747
  /**
562
- * A function that converts the block into a DOM element
748
+ * Experimental: how the keyboard treats the block and its children (Enter,
749
+ * Shift-Enter, Backspace, and outdenting): the settings that differ from the
750
+ * defaults, or a function of the block that returns them. See
751
+ * {@link BlockKeyboard}. This API may change.
752
+ */
753
+ experimental_keyboard?: BlockKeyboardOption<
754
+ BlockFromConfig<BlockConfig<TName, TProps, TContent>, any, any>
755
+ >;
756
+ /**
757
+ * A function that converts the block into a DOM element. Every block
758
+ * declares it, except a layout block (`layoutOnly: true`), which has no content
759
+ * to draw and declares only `renderFrame`.
760
+ *
761
+ * FIXME: optional for every block here, checked at runtime
762
+ * (`validateRenderHooks`). The types could require exactly one of `render`
763
+ * and `renderFrame`, but core's first `createBlockSpec` overload can't see
764
+ * `layoutOnly`.
563
765
  */
564
- render: (
766
+ render?: (
565
767
  this:
566
768
  | Record<string, never>
567
769
  | ({
@@ -591,6 +793,7 @@ export type BlockImplementation<
591
793
  dom: HTMLElement | DocumentFragment;
592
794
  contentDOM?: HTMLElement;
593
795
  ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
796
+ destroy?: () => void;
594
797
  /**
595
798
  * Called by ProseMirror when this block's node is updated (e.g. its content
596
799
  * or props change). Return `true` to handle the update in place - keeping
@@ -601,13 +804,74 @@ export type BlockImplementation<
601
804
  * Useful for blocks whose `render` builds custom DOM that needs to stay in
602
805
  * sync with the node (e.g. a code block rendering a preview of its content).
603
806
  */
604
- update?: (node: ProsemirrorNode) => boolean;
605
- destroy?: () => void;
807
+ update?: (node: PMNode) => boolean | void;
606
808
  };
607
809
 
810
+ /**
811
+ * Draws the chrome *around* a block's content and children: the author's
812
+ * markup wraps both, and the `slot` is where BlockNote mounts them.
813
+ *
814
+ * The slot holds the content first and the children after it. A layout block
815
+ * (`layoutOnly: true`) has no content, so it draws only its frame, with its
816
+ * child blocks in the slot. The frame's root is then the block's element,
817
+ * and a layout block must always draw it.
818
+ *
819
+ * `render` stays the knob for the block's own content. A block may use
820
+ * both: `render` draws the title, `renderFrame` draws the box around title
821
+ * and body. Returning `undefined` declines — the block renders plain — so
822
+ * a block can decide from its props, content, or children whether it is framed.
823
+ *
824
+ * Chrome outside the slot is the author's: ProseMirror leaves its events
825
+ * alone. An `update` hook receives the current block on updates and patches
826
+ * the frame in place. Return `false` to rebuild (or decline) the frame.
827
+ * Without an update hook, a change to the block's props rebuilds the frame;
828
+ * its content and children are in the slot, so typing doesn't. A frame
829
+ * whose chrome shows the block's content or children needs an `update`
830
+ * hook. Whether a block declines may depend only on its props: a declined
831
+ * frame is asked again when the block's props change.
832
+ */
833
+ renderFrame?: <I extends InlineContentSchema, S extends StyleSchema>(
834
+ this:
835
+ | Record<string, never>
836
+ | ({
837
+ propSchema?: TProps;
838
+ } & (
839
+ | {
840
+ renderType: "nodeView";
841
+ props: NodeViewRendererProps;
842
+ }
843
+ | {
844
+ renderType: "dom";
845
+ props: undefined;
846
+ }
847
+ )),
848
+ block: BlockFromConfig<BlockConfig<TName, TProps, TContent>, any, any>,
849
+ editor: BlockNoteEditor<
850
+ Record<TName, BlockConfig<TName, TProps, TContent>>,
851
+ I,
852
+ S
853
+ >,
854
+ ) =>
855
+ | {
856
+ dom: HTMLElement;
857
+ /** Where BlockNote mounts the block's content and/or children. */
858
+ slot: HTMLElement;
859
+ /** Releases resources when the live frame is replaced or destroyed. */
860
+ destroy?: () => void;
861
+ update?: (
862
+ block: BlockFromConfig<
863
+ BlockConfig<TName, TProps, TContent>,
864
+ any,
865
+ any
866
+ >,
867
+ ) => boolean | void;
868
+ }
869
+ | undefined;
870
+
608
871
  /**
609
872
  * Exports block to external HTML. If not defined, the output will be the same
610
- * as `render(...).dom`.
873
+ * as `render(...).dom`, inside the block's frame (`renderFrame`) if it has
874
+ * one. When defined, it replaces both.
611
875
  */
612
876
  toExternalHTML?: (
613
877
  this: Partial<{
@@ -699,4 +963,4 @@ export type CustomBlockImplementation<
699
963
  T extends string = string,
700
964
  PS extends PropSchema = PropSchema,
701
965
  C extends "inline" | "none" | "plain" = "inline" | "none" | "plain",
702
- > = BlockImplementation<T, PS, C>;
966
+ > = Omit<BlockImplementation<T, PS, C>, "frameView">;
@@ -0,0 +1,156 @@
1
+ import type { BlockConfig, ChildrenAllow } from "./types.js";
2
+
3
+ /** Reject declarations ProseMirror would accept with different semantics. */
4
+ export function validateChildrenConfigs(
5
+ blockSpecs: Record<
6
+ string,
7
+ {
8
+ config: Pick<
9
+ BlockConfig,
10
+ "content" | "placeable" | "layoutOnly" | "children"
11
+ >;
12
+ }
13
+ >,
14
+ ) {
15
+ for (const [type, { config }] of Object.entries(blockSpecs)) {
16
+ if (config.layoutOnly === true && config.content !== "none") {
17
+ fail(
18
+ type,
19
+ '`layoutOnly: true` is only for blocks without content (`content: "none"`). A layout block holds only child blocks, no content of its own.',
20
+ );
21
+ }
22
+ if (config.placeable === "namedOnly" && config.layoutOnly !== true) {
23
+ fail(
24
+ type,
25
+ '`placeable: "namedOnly"` is only for layout blocks (`layoutOnly: true`). Only a layout block can be limited to the blocks that name it in `children.allow`.',
26
+ );
27
+ }
28
+ if (!config.children) {
29
+ continue;
30
+ }
31
+
32
+ // Typed loosely: a JS caller can put anything here.
33
+ const {
34
+ allow = "blocks",
35
+ min,
36
+ exclude,
37
+ dissolve,
38
+ } = config.children as {
39
+ allow?: ChildrenAllow;
40
+ min?: number;
41
+ exclude?: readonly string[];
42
+ dissolve?: boolean;
43
+ };
44
+
45
+ // The child blocks of a block that isn't a layout block share one untyped
46
+ // group, which can't enforce types or counts.
47
+ if (config.layoutOnly !== true) {
48
+ if (
49
+ allow !== "blocks" ||
50
+ min !== undefined ||
51
+ exclude !== undefined ||
52
+ dissolve !== undefined
53
+ ) {
54
+ fail(
55
+ type,
56
+ 'restricting child types, a minimum count or `dissolve` requires `layoutOnly: true`. Other blocks can always have any child blocks (`{ allow: "blocks" }`).',
57
+ );
58
+ }
59
+ continue;
60
+ }
61
+
62
+ // A layout block that accepts any blocks always holds at least one, and
63
+ // dissolves when it loses it. A minimum, and whether the layout block
64
+ // dissolves, only mean something for a set of named layout block types (two
65
+ // columns, one tab). A key can move the last block out of a layout block
66
+ // that accepts any blocks, so one that does not dissolve could never be
67
+ // removed with the keyboard.
68
+ if (allow === "blocks" && (min !== undefined || dissolve !== undefined)) {
69
+ fail(
70
+ type,
71
+ `\`children.${min !== undefined ? "min" : "dissolve"}\` needs an \`allow\` list. A layout block that accepts any blocks always holds at least one child, and dissolves when its last child is removed.`,
72
+ );
73
+ }
74
+
75
+ if (min !== undefined && !(Number.isInteger(min) && min >= 0)) {
76
+ fail(
77
+ type,
78
+ `\`children.min\` must be a whole number that is 0 or more, not ${String(min)}.`,
79
+ );
80
+ }
81
+
82
+ if (exclude !== undefined) {
83
+ if (allow !== "blocks") {
84
+ fail(
85
+ type,
86
+ "`children.exclude` is only for a layout block that accepts any blocks. An `allow` list already names exactly what the layout block holds.",
87
+ );
88
+ }
89
+ for (const excluded of exclude) {
90
+ if (!Object.prototype.hasOwnProperty.call(blockSpecs, excluded)) {
91
+ fail(
92
+ type,
93
+ `\`exclude\` contains "${excluded}", which is not a configured block type.`,
94
+ );
95
+ }
96
+ const { config: excludedConfig } = blockSpecs[excluded];
97
+ if (excludedConfig.layoutOnly !== true) {
98
+ fail(
99
+ type,
100
+ `\`exclude\` contains "${excluded}", which is not a layout block. ` +
101
+ "Only layout blocks (`layoutOnly: true`) can be excluded.",
102
+ );
103
+ }
104
+ if (excludedConfig.placeable === "namedOnly") {
105
+ fail(
106
+ type,
107
+ `\`exclude\` contains "${excluded}", which is \`placeable: "namedOnly"\` and never a child of a layout block that accepts any blocks.`,
108
+ );
109
+ }
110
+ }
111
+ }
112
+
113
+ // Every regular block is the same node (`blockContainer`), so naming one
114
+ // here compiles to a valid schema that restricts nothing.
115
+ if (allow !== "blocks") {
116
+ for (const allowed of allow) {
117
+ if (!Object.prototype.hasOwnProperty.call(blockSpecs, allowed)) {
118
+ fail(
119
+ type,
120
+ `\`allow\` contains "${allowed}", which is not a configured block type.`,
121
+ );
122
+ }
123
+ if (blockSpecs[allowed].config.layoutOnly !== true) {
124
+ fail(
125
+ type,
126
+ `\`allow\` contains "${allowed}", which is not a layout block. ` +
127
+ "An `allow` list can name only layout blocks (`layoutOnly: true`); naming other blocks is not supported yet. " +
128
+ 'Use `allow: "blocks"` to accept all other blocks.',
129
+ );
130
+ }
131
+ }
132
+ }
133
+ }
134
+
135
+ // A `namedOnly` block can only be a child of a block that names it in
136
+ // `children.allow`. Without such a block, the editor cannot insert it.
137
+ const named = new Set(
138
+ Object.values(blockSpecs).flatMap(({ config }) =>
139
+ config.children?.allow && config.children.allow !== "blocks"
140
+ ? config.children.allow
141
+ : [],
142
+ ),
143
+ );
144
+ for (const [type, { config }] of Object.entries(blockSpecs)) {
145
+ if (config.placeable === "namedOnly" && !named.has(type)) {
146
+ fail(
147
+ type,
148
+ '`placeable: "namedOnly"` limits this block to the blocks that name it in `children.allow`, but no block names it. Name it in the `allow` list of a layout block.',
149
+ );
150
+ }
151
+ }
152
+ }
153
+
154
+ function fail(type: string, message: string): never {
155
+ throw new Error(`Invalid config for block "${type}": ${message}`);
156
+ }
@@ -0,0 +1,72 @@
1
+ import { describe, expect, it } from "vite-plus/test";
2
+
3
+ import {
4
+ applyDataAttributes,
5
+ propsToDataAttributes,
6
+ setDataAttributes,
7
+ } from "./dataAttributes.js";
8
+
9
+ // The one rule props and their `data-*` attributes share: a prop becomes a
10
+ // kebab-case attribute, except at its default, which has none.
11
+
12
+ const propSchema = {
13
+ textAlignment: { default: "left", values: ["left", "center"] },
14
+ previewWidth: { default: undefined, type: "number" },
15
+ checked: { default: false },
16
+ } as const;
17
+
18
+ describe("propsToDataAttributes", () => {
19
+ it("leaves out props at their default or absent, and stringifies the rest", () => {
20
+ expect(
21
+ propsToDataAttributes(
22
+ { textAlignment: "center", checked: true },
23
+ propSchema,
24
+ ),
25
+ ).toEqual({ "data-text-alignment": "center", "data-checked": "true" });
26
+ expect(
27
+ propsToDataAttributes(
28
+ { textAlignment: "left", previewWidth: 256, checked: false },
29
+ propSchema,
30
+ ),
31
+ ).toEqual({ "data-preview-width": "256" });
32
+ expect(propsToDataAttributes({}, propSchema)).toEqual({});
33
+ });
34
+
35
+ it("keeps the props' own order, and has no attribute for an unknown prop", () => {
36
+ expect(
37
+ Object.keys(
38
+ propsToDataAttributes(
39
+ { checked: true, unknown: "x", textAlignment: "center" } as any,
40
+ propSchema,
41
+ ),
42
+ ),
43
+ ).toEqual(["data-checked", "data-text-alignment"]);
44
+ });
45
+ });
46
+
47
+ describe("setDataAttributes", () => {
48
+ it("sets the attributes and removes nothing", () => {
49
+ const element = document.createElement("div");
50
+ element.setAttribute("data-checked", "author");
51
+ setDataAttributes(
52
+ element,
53
+ propsToDataAttributes({ textAlignment: "center" }, propSchema),
54
+ );
55
+ expect(element.getAttribute("data-text-alignment")).toBe("center");
56
+ expect(element.getAttribute("data-checked")).toBe("author");
57
+ });
58
+ });
59
+
60
+ describe("applyDataAttributes", () => {
61
+ it("sets non-default props and removes the attributes of the others", () => {
62
+ const element = document.createElement("div");
63
+ element.setAttribute("data-text-alignment", "center");
64
+ element.setAttribute("data-checked", "author");
65
+ element.setAttribute("data-other", "kept");
66
+ applyDataAttributes(element, { previewWidth: 100 }, propSchema);
67
+ expect(element.getAttribute("data-preview-width")).toBe("100");
68
+ expect(element.hasAttribute("data-text-alignment")).toBe(false);
69
+ expect(element.hasAttribute("data-checked")).toBe(false);
70
+ expect(element.getAttribute("data-other")).toBe("kept");
71
+ });
72
+ });