@blocknote/core 0.21.0 → 0.22.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 (391) hide show
  1. package/dist/blocknote.js +1023 -999
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +7 -7
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/style.css +1 -1
  6. package/dist/tsconfig.tsbuildinfo +1 -1
  7. package/dist/webpack-stats.json +1 -1
  8. package/package.json +3 -3
  9. package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraph.html +96 -0
  10. package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraphText.html +96 -0
  11. package/src/api/clipboard/__snapshots__/external/pasteImage.html +111 -0
  12. package/src/api/clipboard/__snapshots__/external/pasteParagraphInCustomBlock.html +96 -0
  13. package/src/api/clipboard/__snapshots__/external/pasteTable.html +149 -0
  14. package/src/api/clipboard/__snapshots__/external/pasteTableInExistingTable.html +124 -0
  15. package/src/api/clipboard/__snapshots__/internal/paragraphInCustomBlock.html +1 -0
  16. package/src/api/clipboard/clipboardExternal.test.ts +161 -0
  17. package/src/api/clipboard/{clipboard.test.ts → clipboardInternal.test.ts} +60 -38
  18. package/src/api/clipboard/testUtil.ts +27 -0
  19. package/src/api/clipboard/toClipboard/copyExtension.ts +1 -0
  20. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +7 -1
  21. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +3 -1
  22. package/src/api/nodeConversions/nodeToBlock.ts +4 -1
  23. package/src/api/parsers/markdown/__snapshots__/pasted/styled.json +2 -2
  24. package/src/api/testUtil/partialBlockTestUtil.ts +4 -1
  25. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +3 -19
  26. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +3 -15
  27. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +11 -3
  28. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +25 -5
  29. package/src/editor/Block.css +3 -3
  30. package/src/editor/BlockNoteEditor.test.ts +21 -1
  31. package/src/editor/editor.css +6 -6
  32. package/src/editor/transformPasted.ts +57 -4
  33. package/src/schema/blocks/createSpec.ts +1 -1
  34. package/src/schema/blocks/internal.ts +16 -6
  35. package/src/schema/inlineContent/internal.ts +4 -1
  36. package/src/schema/propTypes.ts +41 -18
  37. package/types/src/api/blockManipulation/setupTestEnv.d.ts +8 -0
  38. package/types/src/api/clipboard/clipboardInternal.test.d.ts +1 -0
  39. package/types/src/api/clipboard/testUtil.d.ts +509 -0
  40. package/types/src/api/testUtil/cases/customBlocks.d.ts +8 -0
  41. package/types/src/api/testUtil/cases/customInlineContent.d.ts +8 -0
  42. package/types/src/api/testUtil/cases/customStyles.d.ts +8 -0
  43. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +12 -0
  44. package/types/src/blocks/defaultBlocks.d.ts +16 -0
  45. package/types/src/editor/transformPasted.d.ts +8 -4
  46. package/types/src/schema/propTypes.d.ts +20 -2
  47. package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js +0 -30
  48. package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js.map +0 -1
  49. package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.js +0 -99
  50. package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.js.map +0 -1
  51. package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.js +0 -97
  52. package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.js.map +0 -1
  53. package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.js +0 -88
  54. package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.js.map +0 -1
  55. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.js +0 -219
  56. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.js.map +0 -1
  57. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.js +0 -175
  58. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.js.map +0 -1
  59. package/dist/src/api/blockManipulation/commands/nestBlock/nestBlock.js +0 -57
  60. package/dist/src/api/blockManipulation/commands/nestBlock/nestBlock.js.map +0 -1
  61. package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.js +0 -5
  62. package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.js.map +0 -1
  63. package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.js +0 -31
  64. package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.js.map +0 -1
  65. package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.js +0 -71
  66. package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.js.map +0 -1
  67. package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.js +0 -157
  68. package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.js.map +0 -1
  69. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.js +0 -27
  70. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.js.map +0 -1
  71. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js +0 -67
  72. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js.map +0 -1
  73. package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js +0 -148
  74. package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js.map +0 -1
  75. package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.test.js +0 -252
  76. package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.test.js.map +0 -1
  77. package/dist/src/api/blockManipulation/getBlock/getBlock.js +0 -56
  78. package/dist/src/api/blockManipulation/getBlock/getBlock.js.map +0 -1
  79. package/dist/src/api/blockManipulation/insertContentAt.js +0 -64
  80. package/dist/src/api/blockManipulation/insertContentAt.js.map +0 -1
  81. package/dist/src/api/blockManipulation/selections/selection.js +0 -149
  82. package/dist/src/api/blockManipulation/selections/selection.js.map +0 -1
  83. package/dist/src/api/blockManipulation/selections/selection.test.js +0 -39
  84. package/dist/src/api/blockManipulation/selections/selection.test.js.map +0 -1
  85. package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js +0 -79
  86. package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js.map +0 -1
  87. package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.js +0 -33
  88. package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.js.map +0 -1
  89. package/dist/src/api/blockManipulation/setupTestEnv.js +0 -172
  90. package/dist/src/api/blockManipulation/setupTestEnv.js.map +0 -1
  91. package/dist/src/api/clipboard/clipboard.test.js +0 -249
  92. package/dist/src/api/clipboard/clipboard.test.js.map +0 -1
  93. package/dist/src/api/clipboard/fromClipboard/acceptedMIMETypes.js +0 -8
  94. package/dist/src/api/clipboard/fromClipboard/acceptedMIMETypes.js.map +0 -1
  95. package/dist/src/api/clipboard/fromClipboard/fileDropExtension.js +0 -38
  96. package/dist/src/api/clipboard/fromClipboard/fileDropExtension.js.map +0 -1
  97. package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js +0 -111
  98. package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js.map +0 -1
  99. package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js +0 -25
  100. package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js.map +0 -1
  101. package/dist/src/api/clipboard/fromClipboard/pasteExtension.js +0 -57
  102. package/dist/src/api/clipboard/fromClipboard/pasteExtension.js.map +0 -1
  103. package/dist/src/api/clipboard/toClipboard/copyExtension.js +0 -134
  104. package/dist/src/api/clipboard/toClipboard/copyExtension.js.map +0 -1
  105. package/dist/src/api/exporters/html/externalHTMLExporter.js +0 -35
  106. package/dist/src/api/exporters/html/externalHTMLExporter.js.map +0 -1
  107. package/dist/src/api/exporters/html/htmlConversion.test.js +0 -72
  108. package/dist/src/api/exporters/html/htmlConversion.test.js.map +0 -1
  109. package/dist/src/api/exporters/html/internalHTMLSerializer.js +0 -21
  110. package/dist/src/api/exporters/html/internalHTMLSerializer.js.map +0 -1
  111. package/dist/src/api/exporters/html/util/serializeBlocksExternalHTML.js +0 -141
  112. package/dist/src/api/exporters/html/util/serializeBlocksExternalHTML.js.map +0 -1
  113. package/dist/src/api/exporters/html/util/serializeBlocksInternalHTML.js +0 -96
  114. package/dist/src/api/exporters/html/util/serializeBlocksInternalHTML.js.map +0 -1
  115. package/dist/src/api/exporters/markdown/markdownExporter.js +0 -31
  116. package/dist/src/api/exporters/markdown/markdownExporter.js.map +0 -1
  117. package/dist/src/api/exporters/markdown/markdownExporter.test.js +0 -57
  118. package/dist/src/api/exporters/markdown/markdownExporter.test.js.map +0 -1
  119. package/dist/src/api/exporters/markdown/removeUnderlinesRehypePlugin.js +0 -33
  120. package/dist/src/api/exporters/markdown/removeUnderlinesRehypePlugin.js.map +0 -1
  121. package/dist/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.js +0 -37
  122. package/dist/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.js.map +0 -1
  123. package/dist/src/api/getBlockInfoFromPos.js +0 -165
  124. package/dist/src/api/getBlockInfoFromPos.js.map +0 -1
  125. package/dist/src/api/nodeConversions/blockToNode.js +0 -197
  126. package/dist/src/api/nodeConversions/blockToNode.js.map +0 -1
  127. package/dist/src/api/nodeConversions/fragmentToBlocks.js +0 -50
  128. package/dist/src/api/nodeConversions/fragmentToBlocks.js.map +0 -1
  129. package/dist/src/api/nodeConversions/nodeConversions.test.js +0 -54
  130. package/dist/src/api/nodeConversions/nodeConversions.test.js.map +0 -1
  131. package/dist/src/api/nodeConversions/nodeToBlock.js +0 -316
  132. package/dist/src/api/nodeConversions/nodeToBlock.js.map +0 -1
  133. package/dist/src/api/nodeUtil.js +0 -28
  134. package/dist/src/api/nodeUtil.js.map +0 -1
  135. package/dist/src/api/parsers/html/parseHTML.js +0 -19
  136. package/dist/src/api/parsers/html/parseHTML.js.map +0 -1
  137. package/dist/src/api/parsers/html/parseHTML.test.js +0 -470
  138. package/dist/src/api/parsers/html/parseHTML.test.js.map +0 -1
  139. package/dist/src/api/parsers/html/util/nestedLists.js +0 -106
  140. package/dist/src/api/parsers/html/util/nestedLists.js.map +0 -1
  141. package/dist/src/api/parsers/html/util/nestedLists.test.js +0 -166
  142. package/dist/src/api/parsers/html/util/nestedLists.test.js.map +0 -1
  143. package/dist/src/api/parsers/markdown/parseMarkdown.js +0 -52
  144. package/dist/src/api/parsers/markdown/parseMarkdown.js.map +0 -1
  145. package/dist/src/api/parsers/markdown/parseMarkdown.test.js +0 -112
  146. package/dist/src/api/parsers/markdown/parseMarkdown.test.js.map +0 -1
  147. package/dist/src/api/testUtil/cases/customBlocks.js +0 -313
  148. package/dist/src/api/testUtil/cases/customBlocks.js.map +0 -1
  149. package/dist/src/api/testUtil/cases/customInlineContent.js +0 -91
  150. package/dist/src/api/testUtil/cases/customInlineContent.js.map +0 -1
  151. package/dist/src/api/testUtil/cases/customStyles.js +0 -83
  152. package/dist/src/api/testUtil/cases/customStyles.js.map +0 -1
  153. package/dist/src/api/testUtil/cases/defaultSchema.js +0 -673
  154. package/dist/src/api/testUtil/cases/defaultSchema.js.map +0 -1
  155. package/dist/src/api/testUtil/index.js +0 -2
  156. package/dist/src/api/testUtil/index.js.map +0 -1
  157. package/dist/src/api/testUtil/partialBlockTestUtil.js +0 -114
  158. package/dist/src/api/testUtil/partialBlockTestUtil.js.map +0 -1
  159. package/dist/src/api/testUtil/paste.js +0 -29
  160. package/dist/src/api/testUtil/paste.js.map +0 -1
  161. package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js +0 -104
  162. package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js.map +0 -1
  163. package/dist/src/blocks/AudioBlockContent/parseAudioElement.js +0 -5
  164. package/dist/src/blocks/AudioBlockContent/parseAudioElement.js.map +0 -1
  165. package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js +0 -281
  166. package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js.map +0 -1
  167. package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js +0 -110
  168. package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js.map +0 -1
  169. package/dist/src/blocks/FileBlockContent/FileBlockContent.js +0 -71
  170. package/dist/src/blocks/FileBlockContent/FileBlockContent.js.map +0 -1
  171. package/dist/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.js +0 -5
  172. package/dist/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.js.map +0 -1
  173. package/dist/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.js +0 -10
  174. package/dist/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.js.map +0 -1
  175. package/dist/src/blocks/FileBlockContent/helpers/render/createAddFileButton.js +0 -39
  176. package/dist/src/blocks/FileBlockContent/helpers/render/createAddFileButton.js.map +0 -1
  177. package/dist/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js +0 -51
  178. package/dist/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js.map +0 -1
  179. package/dist/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js +0 -17
  180. package/dist/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js.map +0 -1
  181. package/dist/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js +0 -147
  182. package/dist/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js.map +0 -1
  183. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js +0 -9
  184. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js.map +0 -1
  185. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js +0 -11
  186. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js.map +0 -1
  187. package/dist/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js +0 -15
  188. package/dist/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js.map +0 -1
  189. package/dist/src/blocks/HeadingBlockContent/HeadingBlockContent.js +0 -145
  190. package/dist/src/blocks/HeadingBlockContent/HeadingBlockContent.js.map +0 -1
  191. package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js +0 -114
  192. package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js.map +0 -1
  193. package/dist/src/blocks/ImageBlockContent/parseImageElement.js +0 -6
  194. package/dist/src/blocks/ImageBlockContent/parseImageElement.js.map +0 -1
  195. package/dist/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.js +0 -113
  196. package/dist/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.js.map +0 -1
  197. package/dist/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.js +0 -224
  198. package/dist/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.js.map +0 -1
  199. package/dist/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.js +0 -45
  200. package/dist/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.js.map +0 -1
  201. package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.js +0 -58
  202. package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.js.map +0 -1
  203. package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.js +0 -130
  204. package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.js.map +0 -1
  205. package/dist/src/blocks/ParagraphBlockContent/ParagraphBlockContent.js +0 -52
  206. package/dist/src/blocks/ParagraphBlockContent/ParagraphBlockContent.js.map +0 -1
  207. package/dist/src/blocks/TableBlockContent/TableBlockContent.js +0 -129
  208. package/dist/src/blocks/TableBlockContent/TableBlockContent.js.map +0 -1
  209. package/dist/src/blocks/TableBlockContent/TableExtension.js +0 -64
  210. package/dist/src/blocks/TableBlockContent/TableExtension.js.map +0 -1
  211. package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js +0 -114
  212. package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js.map +0 -1
  213. package/dist/src/blocks/VideoBlockContent/parseVideoElement.js +0 -6
  214. package/dist/src/blocks/VideoBlockContent/parseVideoElement.js.map +0 -1
  215. package/dist/src/blocks/defaultBlockHelpers.js +0 -50
  216. package/dist/src/blocks/defaultBlockHelpers.js.map +0 -1
  217. package/dist/src/blocks/defaultBlockTypeGuards.js +0 -40
  218. package/dist/src/blocks/defaultBlockTypeGuards.js.map +0 -1
  219. package/dist/src/blocks/defaultBlocks.js +0 -50
  220. package/dist/src/blocks/defaultBlocks.js.map +0 -1
  221. package/dist/src/blocks/defaultProps.js +0 -19
  222. package/dist/src/blocks/defaultProps.js.map +0 -1
  223. package/dist/src/editor/BlockNoteEditor.js +0 -751
  224. package/dist/src/editor/BlockNoteEditor.js.map +0 -1
  225. package/dist/src/editor/BlockNoteEditor.test.js +0 -65
  226. package/dist/src/editor/BlockNoteEditor.test.js.map +0 -1
  227. package/dist/src/editor/BlockNoteExtensions.js +0 -192
  228. package/dist/src/editor/BlockNoteExtensions.js.map +0 -1
  229. package/dist/src/editor/BlockNoteSchema.js +0 -38
  230. package/dist/src/editor/BlockNoteSchema.js.map +0 -1
  231. package/dist/src/editor/BlockNoteTipTapEditor.js +0 -169
  232. package/dist/src/editor/BlockNoteTipTapEditor.js.map +0 -1
  233. package/dist/src/editor/cursorPositionTypes.js +0 -2
  234. package/dist/src/editor/cursorPositionTypes.js.map +0 -1
  235. package/dist/src/editor/defaultColors.js +0 -77
  236. package/dist/src/editor/defaultColors.js.map +0 -1
  237. package/dist/src/editor/selectionTypes.js +0 -2
  238. package/dist/src/editor/selectionTypes.js.map +0 -1
  239. package/dist/src/editor/transformPasted.js +0 -79
  240. package/dist/src/editor/transformPasted.js.map +0 -1
  241. package/dist/src/exporter/Exporter.js +0 -36
  242. package/dist/src/exporter/Exporter.js.map +0 -1
  243. package/dist/src/exporter/index.js +0 -3
  244. package/dist/src/exporter/index.js.map +0 -1
  245. package/dist/src/exporter/mapping.js +0 -12
  246. package/dist/src/exporter/mapping.js.map +0 -1
  247. package/dist/src/extensions/BackgroundColor/BackgroundColorExtension.js +0 -30
  248. package/dist/src/extensions/BackgroundColor/BackgroundColorExtension.js.map +0 -1
  249. package/dist/src/extensions/BackgroundColor/BackgroundColorMark.js +0 -39
  250. package/dist/src/extensions/BackgroundColor/BackgroundColorMark.js.map +0 -1
  251. package/dist/src/extensions/FilePanel/FilePanelPlugin.js +0 -131
  252. package/dist/src/extensions/FilePanel/FilePanelPlugin.js.map +0 -1
  253. package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js +0 -197
  254. package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js.map +0 -1
  255. package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js +0 -341
  256. package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js.map +0 -1
  257. package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js +0 -251
  258. package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js.map +0 -1
  259. package/dist/src/extensions/LinkToolbar/protocols.js +0 -14
  260. package/dist/src/extensions/LinkToolbar/protocols.js.map +0 -1
  261. package/dist/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js +0 -54
  262. package/dist/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js.map +0 -1
  263. package/dist/src/extensions/Placeholder/PlaceholderPlugin.js +0 -90
  264. package/dist/src/extensions/Placeholder/PlaceholderPlugin.js.map +0 -1
  265. package/dist/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.js +0 -187
  266. package/dist/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.js.map +0 -1
  267. package/dist/src/extensions/SideMenu/MultipleNodeSelection.js +0 -68
  268. package/dist/src/extensions/SideMenu/MultipleNodeSelection.js.map +0 -1
  269. package/dist/src/extensions/SideMenu/SideMenuPlugin.js +0 -347
  270. package/dist/src/extensions/SideMenu/SideMenuPlugin.js.map +0 -1
  271. package/dist/src/extensions/SideMenu/dragging.js +0 -135
  272. package/dist/src/extensions/SideMenu/dragging.js.map +0 -1
  273. package/dist/src/extensions/SuggestionMenu/DefaultGridSuggestionItem.js +0 -2
  274. package/dist/src/extensions/SuggestionMenu/DefaultGridSuggestionItem.js.map +0 -1
  275. package/dist/src/extensions/SuggestionMenu/DefaultSuggestionItem.js +0 -2
  276. package/dist/src/extensions/SuggestionMenu/DefaultSuggestionItem.js.map +0 -1
  277. package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js +0 -245
  278. package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js.map +0 -1
  279. package/dist/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.js +0 -26
  280. package/dist/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.js.map +0 -1
  281. package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.js +0 -241
  282. package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.js.map +0 -1
  283. package/dist/src/extensions/TableHandles/TableHandlesPlugin.js +0 -579
  284. package/dist/src/extensions/TableHandles/TableHandlesPlugin.js.map +0 -1
  285. package/dist/src/extensions/TextAlignment/TextAlignmentExtension.js +0 -36
  286. package/dist/src/extensions/TextAlignment/TextAlignmentExtension.js.map +0 -1
  287. package/dist/src/extensions/TextColor/TextColorExtension.js +0 -29
  288. package/dist/src/extensions/TextColor/TextColorExtension.js.map +0 -1
  289. package/dist/src/extensions/TextColor/TextColorMark.js +0 -37
  290. package/dist/src/extensions/TextColor/TextColorMark.js.map +0 -1
  291. package/dist/src/extensions/TrailingNode/TrailingNodeExtension.js +0 -58
  292. package/dist/src/extensions/TrailingNode/TrailingNodeExtension.js.map +0 -1
  293. package/dist/src/extensions/UniqueID/UniqueID.js +0 -283
  294. package/dist/src/extensions/UniqueID/UniqueID.js.map +0 -1
  295. package/dist/src/extensions/getDraggableBlockFromElement.js +0 -13
  296. package/dist/src/extensions/getDraggableBlockFromElement.js.map +0 -1
  297. package/dist/src/extensions-shared/UiElementPosition.js +0 -2
  298. package/dist/src/extensions-shared/UiElementPosition.js.map +0 -1
  299. package/dist/src/i18n/dictionary.js +0 -4
  300. package/dist/src/i18n/dictionary.js.map +0 -1
  301. package/dist/src/i18n/locales/ar.js +0 -298
  302. package/dist/src/i18n/locales/ar.js.map +0 -1
  303. package/dist/src/i18n/locales/de.js +0 -313
  304. package/dist/src/i18n/locales/de.js.map +0 -1
  305. package/dist/src/i18n/locales/en.js +0 -314
  306. package/dist/src/i18n/locales/en.js.map +0 -1
  307. package/dist/src/i18n/locales/es.js +0 -312
  308. package/dist/src/i18n/locales/es.js.map +0 -1
  309. package/dist/src/i18n/locales/fr.js +0 -313
  310. package/dist/src/i18n/locales/fr.js.map +0 -1
  311. package/dist/src/i18n/locales/hr.js +0 -308
  312. package/dist/src/i18n/locales/hr.js.map +0 -1
  313. package/dist/src/i18n/locales/index.js +0 -16
  314. package/dist/src/i18n/locales/index.js.map +0 -1
  315. package/dist/src/i18n/locales/is.js +0 -305
  316. package/dist/src/i18n/locales/is.js.map +0 -1
  317. package/dist/src/i18n/locales/ja.js +0 -333
  318. package/dist/src/i18n/locales/ja.js.map +0 -1
  319. package/dist/src/i18n/locales/ko.js +0 -326
  320. package/dist/src/i18n/locales/ko.js.map +0 -1
  321. package/dist/src/i18n/locales/nl.js +0 -313
  322. package/dist/src/i18n/locales/nl.js.map +0 -1
  323. package/dist/src/i18n/locales/pl.js +0 -297
  324. package/dist/src/i18n/locales/pl.js.map +0 -1
  325. package/dist/src/i18n/locales/pt.js +0 -305
  326. package/dist/src/i18n/locales/pt.js.map +0 -1
  327. package/dist/src/i18n/locales/ru.js +0 -340
  328. package/dist/src/i18n/locales/ru.js.map +0 -1
  329. package/dist/src/i18n/locales/vi.js +0 -312
  330. package/dist/src/i18n/locales/vi.js.map +0 -1
  331. package/dist/src/i18n/locales/zh.js +0 -346
  332. package/dist/src/i18n/locales/zh.js.map +0 -1
  333. package/dist/src/index.js +0 -63
  334. package/dist/src/index.js.map +0 -1
  335. package/dist/src/pm-nodes/BlockContainer.js +0 -72
  336. package/dist/src/pm-nodes/BlockContainer.js.map +0 -1
  337. package/dist/src/pm-nodes/BlockGroup.js +0 -43
  338. package/dist/src/pm-nodes/BlockGroup.js.map +0 -1
  339. package/dist/src/pm-nodes/Doc.js +0 -7
  340. package/dist/src/pm-nodes/Doc.js.map +0 -1
  341. package/dist/src/pm-nodes/index.js +0 -4
  342. package/dist/src/pm-nodes/index.js.map +0 -1
  343. package/dist/src/schema/blocks/createSpec.js +0 -126
  344. package/dist/src/schema/blocks/createSpec.js.map +0 -1
  345. package/dist/src/schema/blocks/internal.js +0 -147
  346. package/dist/src/schema/blocks/internal.js.map +0 -1
  347. package/dist/src/schema/blocks/types.js +0 -2
  348. package/dist/src/schema/blocks/types.js.map +0 -1
  349. package/dist/src/schema/index.js +0 -11
  350. package/dist/src/schema/index.js.map +0 -1
  351. package/dist/src/schema/inlineContent/createSpec.js +0 -64
  352. package/dist/src/schema/inlineContent/createSpec.js.map +0 -1
  353. package/dist/src/schema/inlineContent/internal.js +0 -52
  354. package/dist/src/schema/inlineContent/internal.js.map +0 -1
  355. package/dist/src/schema/inlineContent/types.js +0 -10
  356. package/dist/src/schema/inlineContent/types.js.map +0 -1
  357. package/dist/src/schema/propTypes.js +0 -2
  358. package/dist/src/schema/propTypes.js.map +0 -1
  359. package/dist/src/schema/styles/createSpec.js +0 -48
  360. package/dist/src/schema/styles/createSpec.js.map +0 -1
  361. package/dist/src/schema/styles/internal.js +0 -53
  362. package/dist/src/schema/styles/internal.js.map +0 -1
  363. package/dist/src/schema/styles/types.js +0 -2
  364. package/dist/src/schema/styles/types.js.map +0 -1
  365. package/dist/src/util/EventEmitter.js +0 -33
  366. package/dist/src/util/EventEmitter.js.map +0 -1
  367. package/dist/src/util/browser.js +0 -17
  368. package/dist/src/util/browser.js.map +0 -1
  369. package/dist/src/util/combineByGroup.js +0 -20
  370. package/dist/src/util/combineByGroup.js.map +0 -1
  371. package/dist/src/util/esmDependencies.js +0 -35
  372. package/dist/src/util/esmDependencies.js.map +0 -1
  373. package/dist/src/util/string.js +0 -14
  374. package/dist/src/util/string.js.map +0 -1
  375. package/dist/src/util/typescript.js +0 -12
  376. package/dist/src/util/typescript.js.map +0 -1
  377. /package/src/api/clipboard/__snapshots__/{childToParent.html → internal/childToParent.html} +0 -0
  378. /package/src/api/clipboard/__snapshots__/{childrenToNextParent.html → internal/childrenToNextParent.html} +0 -0
  379. /package/src/api/clipboard/__snapshots__/{childrenToNextParentsChildren.html → internal/childrenToNextParentsChildren.html} +0 -0
  380. /package/src/api/clipboard/__snapshots__/{image.html → internal/image.html} +0 -0
  381. /package/src/api/clipboard/__snapshots__/{multipleChildren.html → internal/multipleChildren.html} +0 -0
  382. /package/src/api/clipboard/__snapshots__/{multipleStyledText.html → internal/multipleStyledText.html} +0 -0
  383. /package/src/api/clipboard/__snapshots__/{nestedImage.html → internal/nestedImage.html} +0 -0
  384. /package/src/api/clipboard/__snapshots__/{partialChildToParent.html → internal/partialChildToParent.html} +0 -0
  385. /package/src/api/clipboard/__snapshots__/{styledText.html → internal/styledText.html} +0 -0
  386. /package/src/api/clipboard/__snapshots__/{tableAllCells.html → internal/tableAllCells.html} +0 -0
  387. /package/src/api/clipboard/__snapshots__/{tableCell.html → internal/tableCell.html} +0 -0
  388. /package/src/api/clipboard/__snapshots__/{tableCellText.html → internal/tableCellText.html} +0 -0
  389. /package/src/api/clipboard/__snapshots__/{tableRow.html → internal/tableRow.html} +0 -0
  390. /package/src/api/clipboard/__snapshots__/{unstyledText.html → internal/unstyledText.html} +0 -0
  391. /package/types/src/api/clipboard/{clipboard.test.d.ts → clipboardExternal.test.d.ts} +0 -0
@@ -20,7 +20,7 @@ export const NumberedListIndexingPlugin = () => {
20
20
  node.type.name === "blockContainer" &&
21
21
  node.firstChild!.type.name === "numberedListItem"
22
22
  ) {
23
- let newIndex = "1";
23
+ let newIndex = `${node.firstChild!.attrs["start"] || 1}`;
24
24
 
25
25
  const blockInfo = getBlockInfo({
26
26
  posBeforeNode: pos,
@@ -60,13 +60,21 @@ export const NumberedListIndexingPlugin = () => {
60
60
 
61
61
  const contentNode = blockInfo.blockContent.node;
62
62
  const index = contentNode.attrs["index"];
63
+ const isFirst =
64
+ prevBlock?.firstChild?.type.name !== "numberedListItem";
63
65
 
64
- if (index !== newIndex) {
66
+ if (index !== newIndex || (contentNode.attrs.start && !isFirst)) {
65
67
  modified = true;
66
68
 
69
+ const { start, ...attrs } = contentNode.attrs;
70
+
67
71
  tr.setNodeMarkup(blockInfo.blockContent.beforePos, undefined, {
68
- ...contentNode.attrs,
72
+ ...attrs,
69
73
  index: newIndex,
74
+ ...(typeof start === "number" &&
75
+ isFirst && {
76
+ start,
77
+ }),
70
78
  });
71
79
  }
72
80
  }
@@ -5,6 +5,7 @@ import {
5
5
  PropSchema,
6
6
  createBlockSpecFromStronglyTypedTiptapNode,
7
7
  createStronglyTypedTiptapNode,
8
+ propsToAttributes,
8
9
  } from "../../../schema/index.js";
9
10
  import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers.js";
10
11
  import { defaultProps } from "../../defaultProps.js";
@@ -13,6 +14,7 @@ import { NumberedListIndexingPlugin } from "./NumberedListIndexingPlugin.js";
13
14
 
14
15
  export const numberedListItemPropSchema = {
15
16
  ...defaultProps,
17
+ start: { default: undefined, type: "number" },
16
18
  } satisfies PropSchema;
17
19
 
18
20
  const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
@@ -22,6 +24,9 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
22
24
  priority: 90,
23
25
  addAttributes() {
24
26
  return {
27
+ ...propsToAttributes(numberedListItemPropSchema),
28
+ // the index attribute is only used internally (it's not part of the blocknote schema)
29
+ // that's why it's defined explicitly here, and not part of the prop schema
25
30
  index: {
26
31
  default: null,
27
32
  parseHTML: (element) => element.getAttribute("data-index"),
@@ -38,15 +43,17 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
38
43
  return [
39
44
  // Creates an ordered list when starting with "1.".
40
45
  new InputRule({
41
- find: new RegExp(`^1\\.\\s$`),
42
- handler: ({ state, chain, range }) => {
46
+ find: new RegExp(`^(\\d+)\\.\\s$`),
47
+ handler: ({ state, chain, range, match }) => {
43
48
  const blockInfo = getBlockInfoFromSelection(state);
44
49
  if (
45
50
  !blockInfo.isBlockContainer ||
46
- blockInfo.blockContent.node.type.spec.content !== "inline*"
51
+ blockInfo.blockContent.node.type.spec.content !== "inline*" ||
52
+ blockInfo.blockNoteType === "numberedListItem"
47
53
  ) {
48
54
  return;
49
55
  }
56
+ const startIndex = parseInt(match[1]);
50
57
 
51
58
  chain()
52
59
  .command(
@@ -55,7 +62,11 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
55
62
  blockInfo.bnBlock.beforePos,
56
63
  {
57
64
  type: "numberedListItem",
58
- props: {},
65
+ props:
66
+ (startIndex === 1 && {}) ||
67
+ ({
68
+ start: startIndex,
69
+ } as any),
59
70
  }
60
71
  )
61
72
  )
@@ -116,7 +127,16 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
116
127
  parent.tagName === "OL" ||
117
128
  (parent.tagName === "DIV" && parent.parentElement!.tagName === "OL")
118
129
  ) {
119
- return {};
130
+ const startIndex =
131
+ parseInt(parent.getAttribute("start") || "1") || 1;
132
+
133
+ if (element.previousSibling || startIndex === 1) {
134
+ return {};
135
+ }
136
+
137
+ return {
138
+ start: startIndex,
139
+ };
120
140
  }
121
141
 
122
142
  return false;
@@ -114,13 +114,13 @@ NESTED BLOCKS
114
114
  }
115
115
 
116
116
  /* HEADINGS*/
117
- [data-level="1"] {
117
+ [data-content-type="heading"] {
118
118
  --level: 3em;
119
119
  }
120
- [data-level="2"] {
120
+ [data-content-type="heading"][data-level="2"] {
121
121
  --level: 2em;
122
122
  }
123
- [data-level="3"] {
123
+ [data-content-type="heading"][data-level="3"] {
124
124
  --level: 1.3em;
125
125
  }
126
126
 
@@ -71,6 +71,26 @@ it("adds id attribute when requested", async () => {
71
71
  );
72
72
  editor.replaceBlocks(editor.document, blocks);
73
73
  expect(await editor.blocksToFullHTML(editor.document)).toMatchInlineSnapshot(
74
- `"<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1" id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1" id="1"><div class="bn-block-content" data-content-type="paragraph"><p class="bn-inline-content">This is a normal text</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="2" id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2" id="2"><div class="bn-block-content" data-content-type="heading" data-level="1"><h1 class="bn-inline-content">And this is a large heading</h1></div></div></div></div>"`
74
+ `"<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1" id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1" id="1"><div class="bn-block-content" data-content-type="paragraph"><p class="bn-inline-content">This is a normal text</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="2" id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2" id="2"><div class="bn-block-content" data-content-type="heading"><h1 class="bn-inline-content">And this is a large heading</h1></div></div></div></div>"`
75
75
  );
76
76
  });
77
+
78
+ it("block prop types", () => {
79
+ // this test checks whether the block props are correctly typed in typescript
80
+ const editor = BlockNoteEditor.create();
81
+ const block = editor.document[0];
82
+ if (block.type === "paragraph") {
83
+ // @ts-expect-error
84
+ const level = block.props.level; // doesn't have level prop
85
+
86
+ // eslint-disable-next-line
87
+ expect(level).toBe(undefined);
88
+ }
89
+
90
+ if (block.type === "heading") {
91
+ const level = block.props.level; // does have level prop
92
+
93
+ // eslint-disable-next-line
94
+ expect(level).toBe(1);
95
+ }
96
+ });
@@ -109,7 +109,7 @@ Tippy popups that are appended to document.body directly
109
109
  padding
110
110
  } */
111
111
 
112
- .ProseMirror .tableWrapper {
112
+ .bn-editor [data-content-type="table"] .tableWrapper {
113
113
  position: relative;
114
114
  top: -16px;
115
115
  left: -16px;
@@ -119,7 +119,7 @@ Tippy popups that are appended to document.body directly
119
119
  overflow-y: hidden;
120
120
  }
121
121
 
122
- .ProseMirror .tableWrapper-inner {
122
+ .bn-editor [data-content-type="table"] .tableWrapper-inner {
123
123
  /* position: relative; */
124
124
  /* top: -16px;
125
125
  left: -16px; */
@@ -127,17 +127,17 @@ Tippy popups that are appended to document.body directly
127
127
  }
128
128
 
129
129
  /* table related: */
130
- .bn-editor table {
130
+ .bn-editor [data-content-type="table"] table {
131
131
  width: auto !important;
132
132
  word-break: break-word;
133
133
  }
134
- .bn-editor th,
135
- .bn-editor td {
134
+ .bn-editor [data-content-type="table"] th,
135
+ .bn-editor [data-content-type="table"] td {
136
136
  border: 1px solid #ddd;
137
137
  padding: 3px 5px;
138
138
  }
139
139
 
140
- .bn-editor th {
140
+ .bn-editor [data-content-type="table"] th {
141
141
  font-weight: bold;
142
142
  text-align: left;
143
143
  }
@@ -1,6 +1,8 @@
1
1
  import { Fragment, Schema, Slice } from "@tiptap/pm/model";
2
2
  import { EditorView } from "@tiptap/pm/view";
3
3
 
4
+ import { getBlockInfoFromSelection } from "../api/getBlockInfoFromPos.js";
5
+
4
6
  // helper function to remove a child from a fragment
5
7
  function removeChild(node: Fragment, n: number) {
6
8
  const children: any[] = [];
@@ -49,16 +51,25 @@ export function wrapTableRows(f: Fragment, schema: Schema) {
49
51
  /**
50
52
  * fix for https://github.com/ProseMirror/prosemirror/issues/1430#issuecomment-1822570821
51
53
  *
52
- * Without this fix, pasting two paragraphs would cause the second one to be indented in the other
53
- * this fix wraps every element in the slice in it's own blockContainer, to prevent Prosemirror from nesting the
54
- * elements on paste.
54
+ * This fix wraps pasted ProseMirror nodes in their own `blockContainer` nodes
55
+ * in most cases. This is to ensure that ProseMirror inserts them as separate
56
+ * blocks, which it sometimes doesn't do because it doesn't have enough context
57
+ * about the hierarchy of the pasted nodes. The issue can be seen when pasting
58
+ * e.g. an image or two consecutive paragraphs, where PM tries to nest the
59
+ * pasted block(s) when it shouldn't.
55
60
  *
56
- * The exception is when we encounter blockGroups with listitems, because those actually should be nested
61
+ * However, the fix is not applied in a few cases. See `shouldApplyFix` for
62
+ * which cases are excluded.
57
63
  */
58
64
  export function transformPasted(slice: Slice, view: EditorView) {
59
65
  let f = Fragment.from(slice.content);
60
66
  f = wrapTableRows(f, view.state.schema);
61
67
 
68
+ if (!shouldApplyFix(f, view)) {
69
+ // Don't apply the fix.
70
+ return new Slice(f, slice.openStart, slice.openEnd);
71
+ }
72
+
62
73
  for (let i = 0; i < f.childCount; i++) {
63
74
  if (f.child(i).type.spec.group === "blockContent") {
64
75
  const content = [f.child(i)];
@@ -92,3 +103,45 @@ export function transformPasted(slice: Slice, view: EditorView) {
92
103
  }
93
104
  return new Slice(f, slice.openStart, slice.openEnd);
94
105
  }
106
+
107
+ /**
108
+ * Used in `transformPasted` to check if the fix there should be applied, i.e.
109
+ * if the pasted fragment should be wrapped in a `blockContainer` node. This
110
+ * will explicitly tell ProseMirror to treat it as a separate block.
111
+ */
112
+ function shouldApplyFix(fragment: Fragment, view: EditorView) {
113
+ const nodeHasSingleChild = fragment.childCount === 1;
114
+ const nodeHasInlineContent =
115
+ fragment.firstChild?.type.spec.content === "inline*";
116
+ const nodeHasTableContent =
117
+ fragment.firstChild?.type.spec.content === "tableRow+";
118
+
119
+ if (nodeHasSingleChild) {
120
+ if (nodeHasInlineContent) {
121
+ // Case when we paste a single node with inline content, e.g. a paragraph
122
+ // or heading. We want to insert the content in-line for better UX instead
123
+ // of a separate block, so we return false.
124
+ return false;
125
+ }
126
+
127
+ if (nodeHasTableContent) {
128
+ // Not ideal that we check selection here, as `transformPasted` is called
129
+ // for both paste and drop events. Drop events can potentially cause
130
+ // issues as they don't always happen at the current selection.
131
+ const blockInfo = getBlockInfoFromSelection(view.state);
132
+ if (blockInfo.isBlockContainer) {
133
+ const selectedBlockHasTableContent =
134
+ blockInfo.blockContent.node.type.spec.content === "tableRow+";
135
+
136
+ // Case for when we paste a single node with table content, i.e. a
137
+ // table. Normally, we return true as we want to ensure the table is
138
+ // inserted as a separate block. However, if the selection is in an
139
+ // existing table, we return false, as we want the content of the pasted
140
+ // table to be added to the existing one for better UX.
141
+ return !selectedBlockHasTableContent;
142
+ }
143
+ }
144
+ }
145
+
146
+ return true;
147
+ }
@@ -148,7 +148,7 @@ export function createBlockSpec<
148
148
  : "") as T["content"] extends "inline" ? "inline*" : "",
149
149
  group: "blockContent",
150
150
  selectable: blockConfig.isSelectable ?? true,
151
-
151
+ isolating: true,
152
152
  addAttributes() {
153
153
  return propsToAttributes(blockConfig.propSchema);
154
154
  },
@@ -46,7 +46,10 @@ export function propsToAttributes(propSchema: PropSchema): Attributes {
46
46
  return null;
47
47
  }
48
48
 
49
- if (typeof spec.default === "boolean") {
49
+ if (
50
+ (spec.default === undefined && spec.type === "boolean") ||
51
+ (spec.default !== undefined && typeof spec.default === "boolean")
52
+ ) {
50
53
  if (value === "true") {
51
54
  return true;
52
55
  }
@@ -58,7 +61,10 @@ export function propsToAttributes(propSchema: PropSchema): Attributes {
58
61
  return null;
59
62
  }
60
63
 
61
- if (typeof spec.default === "number") {
64
+ if (
65
+ (spec.default === undefined && spec.type === "number") ||
66
+ (spec.default !== undefined && typeof spec.default === "number")
67
+ ) {
62
68
  const asNumber = parseFloat(value);
63
69
  const isNumeric =
64
70
  !Number.isNaN(asNumber) && Number.isFinite(asNumber);
@@ -72,12 +78,14 @@ export function propsToAttributes(propSchema: PropSchema): Attributes {
72
78
 
73
79
  return value;
74
80
  },
75
- renderHTML: (attributes) =>
76
- attributes[name] !== spec.default
81
+ renderHTML: (attributes) => {
82
+ // don't render to html if the value is the same as the default
83
+ return attributes[name] !== spec.default
77
84
  ? {
78
85
  [camelToDataKebab(name)]: attributes[name],
79
86
  }
80
- : {},
87
+ : {};
88
+ },
81
89
  };
82
90
  });
83
91
 
@@ -173,7 +181,9 @@ export function wrapInBlockStructure<
173
181
  // which are already added as HTML attributes to the parent `blockContent`
174
182
  // element (inheritedProps) and props set to their default values.
175
183
  for (const [prop, value] of Object.entries(blockProps)) {
176
- if (!inheritedProps.includes(prop) && value !== propSchema[prop].default) {
184
+ const spec = propSchema[prop];
185
+ const defaultValue = spec.default;
186
+ if (!inheritedProps.includes(prop) && value !== defaultValue) {
177
187
  blockContent.setAttribute(camelToDataKebab(prop), value);
178
188
  }
179
189
  }
@@ -34,7 +34,10 @@ export function addInlineContentAttributes<
34
34
  // Adds props as HTML attributes in kebab-case with "data-" prefix. Skips props
35
35
  // set to their default values.
36
36
  Object.entries(inlineContentProps)
37
- .filter(([prop, value]) => value !== propSchema[prop].default)
37
+ .filter(([prop, value]) => {
38
+ const spec = propSchema[prop];
39
+ return value !== spec.default;
40
+ })
38
41
  .map(([prop, value]) => {
39
42
  return [camelToDataKebab(prop), value];
40
43
  })
@@ -1,9 +1,24 @@
1
- // Defines a single prop spec, which includes the default value the prop should
2
- // take and possible values it can take.
3
- export type PropSpec<PType extends boolean | number | string> = {
4
- values?: readonly PType[];
5
- default: PType;
6
- };
1
+ // The PropSpec specifies the type of a prop and possibly a default value.
2
+ // Note that props are always optional when used as "input"
3
+ // (i.e., when creating a PartialBlock, for example by calling `insertBlocks({...})`)
4
+ //
5
+ // However, internally they're always set to `default`, unless a prop is marked optional
6
+ //
7
+ // At some point we should migrate this to zod or effect-schema
8
+ export type PropSpec<PType extends boolean | number | string> =
9
+ | {
10
+ // We infer the type of the prop from the default value
11
+ default: PType;
12
+ // a list of possible values, for example for a string prop (this will then be used as a string union type)
13
+ values?: readonly PType[];
14
+ }
15
+ | {
16
+ default: undefined;
17
+ // Because there is no default value (for an optional prop, the default value is undefined),
18
+ // we need to specify the type of the prop manually (we can't infer it from the default value)
19
+ type: "string" | "number" | "boolean";
20
+ values?: readonly PType[];
21
+ };
7
22
 
8
23
  // Defines multiple block prop specs. The key of each prop is the name of the
9
24
  // prop, while the value is a corresponding prop spec. This should be included
@@ -16,17 +31,25 @@ export type PropSchema = Record<string, PropSpec<boolean | number | string>>;
16
31
  // each prop spec into a union type of its possible values, or a string if no
17
32
  // values are specified.
18
33
  export type Props<PSchema extends PropSchema> = {
19
- [PName in keyof PSchema]: PSchema[PName]["default"] extends boolean
20
- ? PSchema[PName]["values"] extends readonly boolean[]
21
- ? PSchema[PName]["values"][number]
22
- : boolean
23
- : PSchema[PName]["default"] extends number
24
- ? PSchema[PName]["values"] extends readonly number[]
25
- ? PSchema[PName]["values"][number]
26
- : number
27
- : PSchema[PName]["default"] extends string
28
- ? PSchema[PName]["values"] extends readonly string[]
29
- ? PSchema[PName]["values"][number]
30
- : string
34
+ // for required props, get type from type of "default" value,
35
+ // and if values are specified, get type from values
36
+ [PName in keyof PSchema]: (
37
+ PSchema[PName] extends { default: boolean } | { type: "boolean" }
38
+ ? PSchema[PName]["values"] extends readonly boolean[]
39
+ ? PSchema[PName]["values"][number]
40
+ : boolean
41
+ : PSchema[PName] extends { default: number } | { type: "number" }
42
+ ? PSchema[PName]["values"] extends readonly number[]
43
+ ? PSchema[PName]["values"][number]
44
+ : number
45
+ : PSchema[PName] extends { default: string } | { type: "string" }
46
+ ? PSchema[PName]["values"] extends readonly string[]
47
+ ? PSchema[PName]["values"][number]
48
+ : string
49
+ : never
50
+ ) extends infer T
51
+ ? PSchema[PName] extends { optional: true }
52
+ ? T | undefined
53
+ : T
31
54
  : never;
32
55
  };
@@ -137,6 +137,10 @@ export declare function setupTestEnv(): () => BlockNoteEditor<import("../../inde
137
137
  type: "numberedListItem";
138
138
  content: "inline";
139
139
  propSchema: {
140
+ start: {
141
+ default: undefined;
142
+ type: "number";
143
+ };
140
144
  backgroundColor: {
141
145
  default: "default";
142
146
  };
@@ -153,6 +157,10 @@ export declare function setupTestEnv(): () => BlockNoteEditor<import("../../inde
153
157
  type: "numberedListItem";
154
158
  content: "inline";
155
159
  propSchema: {
160
+ start: {
161
+ default: undefined;
162
+ type: "number";
163
+ };
156
164
  backgroundColor: {
157
165
  default: "default";
158
166
  };