@blocknote/core 0.9.6 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. package/dist/blocknote.js +3696 -2609
  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/webpack-stats.json +1 -0
  7. package/package.json +11 -5
  8. package/src/api/README.md +8 -0
  9. package/src/api/blockManipulation/blockManipulation.test.ts +72 -10
  10. package/src/api/blockManipulation/blockManipulation.ts +38 -18
  11. package/src/api/exporters/copyExtension.ts +68 -0
  12. package/src/api/exporters/html/__snapshots__/complex/misc/external.html +1 -0
  13. package/src/api/exporters/html/__snapshots__/complex/misc/internal.html +1 -0
  14. package/src/api/exporters/html/__snapshots__/customParagraph/basic/external.html +1 -0
  15. package/src/api/exporters/html/__snapshots__/customParagraph/basic/internal.html +1 -0
  16. package/src/api/exporters/html/__snapshots__/customParagraph/nested/external.html +1 -0
  17. package/src/api/exporters/html/__snapshots__/customParagraph/nested/internal.html +1 -0
  18. package/src/api/exporters/html/__snapshots__/customParagraph/styled/external.html +1 -0
  19. package/src/api/exporters/html/__snapshots__/customParagraph/styled/internal.html +1 -0
  20. package/src/api/exporters/html/__snapshots__/fontSize/basic/external.html +1 -0
  21. package/src/api/exporters/html/__snapshots__/fontSize/basic/internal.html +1 -0
  22. package/src/api/exporters/html/__snapshots__/hardbreak/basic/external.html +1 -0
  23. package/src/api/exporters/html/__snapshots__/hardbreak/basic/internal.html +1 -0
  24. package/src/api/exporters/html/__snapshots__/hardbreak/between-links/external.html +1 -0
  25. package/src/api/exporters/html/__snapshots__/hardbreak/between-links/internal.html +1 -0
  26. package/src/api/exporters/html/__snapshots__/hardbreak/end/external.html +1 -0
  27. package/src/api/exporters/html/__snapshots__/hardbreak/end/internal.html +1 -0
  28. package/src/api/exporters/html/__snapshots__/hardbreak/link/external.html +1 -0
  29. package/src/api/exporters/html/__snapshots__/hardbreak/link/internal.html +1 -0
  30. package/src/api/exporters/html/__snapshots__/hardbreak/multiple/external.html +1 -0
  31. package/src/api/exporters/html/__snapshots__/hardbreak/multiple/internal.html +1 -0
  32. package/src/api/exporters/html/__snapshots__/hardbreak/only/external.html +1 -0
  33. package/src/api/exporters/html/__snapshots__/hardbreak/only/internal.html +1 -0
  34. package/src/api/exporters/html/__snapshots__/hardbreak/start/external.html +1 -0
  35. package/src/api/exporters/html/__snapshots__/hardbreak/start/internal.html +1 -0
  36. package/src/api/exporters/html/__snapshots__/hardbreak/styles/external.html +1 -0
  37. package/src/api/exporters/html/__snapshots__/hardbreak/styles/internal.html +1 -0
  38. package/src/api/exporters/html/__snapshots__/image/basic/external.html +1 -0
  39. package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -0
  40. package/src/api/exporters/html/__snapshots__/image/button/external.html +1 -0
  41. package/src/api/exporters/html/__snapshots__/image/button/internal.html +1 -0
  42. package/src/api/exporters/html/__snapshots__/image/nested/external.html +1 -0
  43. package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -0
  44. package/src/api/exporters/html/__snapshots__/link/adjacent/external.html +1 -0
  45. package/src/api/exporters/html/__snapshots__/link/adjacent/internal.html +1 -0
  46. package/src/api/exporters/html/__snapshots__/link/basic/external.html +1 -0
  47. package/src/api/exporters/html/__snapshots__/link/basic/internal.html +1 -0
  48. package/src/api/exporters/html/__snapshots__/link/styled/external.html +1 -0
  49. package/src/api/exporters/html/__snapshots__/link/styled/internal.html +1 -0
  50. package/src/api/exporters/html/__snapshots__/mention/basic/external.html +1 -0
  51. package/src/api/exporters/html/__snapshots__/mention/basic/internal.html +1 -0
  52. package/src/api/exporters/html/__snapshots__/paragraph/basic/external.html +1 -0
  53. package/src/api/exporters/html/__snapshots__/paragraph/basic/internal.html +1 -0
  54. package/src/api/exporters/html/__snapshots__/paragraph/empty/external.html +1 -0
  55. package/src/api/exporters/html/__snapshots__/paragraph/empty/internal.html +1 -0
  56. package/src/api/exporters/html/__snapshots__/paragraph/nested/external.html +1 -0
  57. package/src/api/exporters/html/__snapshots__/paragraph/nested/internal.html +1 -0
  58. package/src/api/exporters/html/__snapshots__/paragraph/styled/external.html +1 -0
  59. package/src/api/exporters/html/__snapshots__/paragraph/styled/internal.html +1 -0
  60. package/src/api/exporters/html/__snapshots__/paste/parse-basic-block-types.json +140 -0
  61. package/src/api/exporters/html/__snapshots__/paste/parse-deep-nested-content.json +240 -0
  62. package/src/api/exporters/html/__snapshots__/paste/parse-div-with-inline-content.json +91 -0
  63. package/src/api/exporters/html/__snapshots__/paste/parse-divs.json +19 -0
  64. package/src/api/exporters/html/__snapshots__/paste/parse-fake-image-caption.json +31 -0
  65. package/src/api/exporters/html/__snapshots__/paste/parse-mixed-nested-lists.json +70 -0
  66. package/src/api/exporters/html/__snapshots__/paste/parse-nested-lists-with-paragraphs.json +70 -0
  67. package/src/api/exporters/html/__snapshots__/paste/parse-nested-lists.json +70 -0
  68. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/external.html +1 -0
  69. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/internal.html +1 -0
  70. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/external.html +1 -0
  71. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/internal.html +1 -0
  72. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/external.html +1 -0
  73. package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/internal.html +1 -0
  74. package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -0
  75. package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -0
  76. package/src/api/exporters/html/__snapshots__/simpleImage/button/external.html +1 -0
  77. package/src/api/exporters/html/__snapshots__/simpleImage/button/internal.html +1 -0
  78. package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -0
  79. package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -0
  80. package/src/api/exporters/html/__snapshots__/small/basic/external.html +1 -0
  81. package/src/api/exporters/html/__snapshots__/small/basic/internal.html +1 -0
  82. package/src/api/exporters/html/__snapshots__/tag/basic/external.html +1 -0
  83. package/src/api/exporters/html/__snapshots__/tag/basic/internal.html +1 -0
  84. package/src/api/exporters/html/externalHTMLExporter.ts +98 -0
  85. package/src/api/exporters/html/htmlConversion.test.ts +100 -0
  86. package/src/api/exporters/html/internalHTMLSerializer.ts +80 -0
  87. package/src/api/exporters/html/util/sharedHTMLConversion.ts +128 -0
  88. package/src/api/{formatConversions → exporters/html/util}/simplifyBlocksRehypePlugin.ts +13 -0
  89. package/src/api/exporters/markdown/__snapshots__/complex/misc/markdown.md +5 -0
  90. package/src/api/exporters/markdown/__snapshots__/customParagraph/basic/markdown.md +1 -0
  91. package/src/api/exporters/markdown/__snapshots__/customParagraph/nested/markdown.md +5 -0
  92. package/src/api/exporters/markdown/__snapshots__/customParagraph/styled/markdown.md +1 -0
  93. package/src/api/exporters/markdown/__snapshots__/fontSize/basic/markdown.md +1 -0
  94. package/src/api/exporters/markdown/__snapshots__/hardbreak/basic/markdown.md +2 -0
  95. package/src/api/exporters/markdown/__snapshots__/hardbreak/between-links/markdown.md +2 -0
  96. package/src/api/exporters/markdown/__snapshots__/hardbreak/end/markdown.md +1 -0
  97. package/src/api/exporters/markdown/__snapshots__/hardbreak/link/markdown.md +2 -0
  98. package/src/api/exporters/markdown/__snapshots__/hardbreak/multiple/markdown.md +3 -0
  99. package/src/api/exporters/markdown/__snapshots__/hardbreak/start/markdown.md +1 -0
  100. package/src/api/exporters/markdown/__snapshots__/hardbreak/styles/markdown.md +2 -0
  101. package/src/api/exporters/markdown/__snapshots__/image/basic/markdown.md +3 -0
  102. package/src/api/exporters/markdown/__snapshots__/image/button/markdown.md +1 -0
  103. package/src/api/exporters/markdown/__snapshots__/image/nested/markdown.md +7 -0
  104. package/src/api/exporters/markdown/__snapshots__/link/adjacent/markdown.md +1 -0
  105. package/src/api/exporters/markdown/__snapshots__/link/basic/markdown.md +1 -0
  106. package/src/api/exporters/markdown/__snapshots__/link/styled/markdown.md +1 -0
  107. package/src/api/exporters/markdown/__snapshots__/mention/basic/markdown.md +1 -0
  108. package/src/api/exporters/markdown/__snapshots__/paragraph/basic/markdown.md +1 -0
  109. package/src/api/exporters/markdown/__snapshots__/paragraph/nested/markdown.md +5 -0
  110. package/src/api/exporters/markdown/__snapshots__/paragraph/styled/markdown.md +1 -0
  111. package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/basic/markdown.md +1 -0
  112. package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/nested/markdown.md +5 -0
  113. package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/styled/markdown.md +1 -0
  114. package/src/api/exporters/markdown/__snapshots__/simpleImage/basic/markdown.md +1 -0
  115. package/src/api/exporters/markdown/__snapshots__/simpleImage/button/markdown.md +1 -0
  116. package/src/api/exporters/markdown/__snapshots__/simpleImage/nested/markdown.md +3 -0
  117. package/src/api/exporters/markdown/__snapshots__/small/basic/markdown.md +1 -0
  118. package/src/api/exporters/markdown/__snapshots__/tag/basic/markdown.md +1 -0
  119. package/src/api/exporters/markdown/markdownExporter.test.ts +85 -0
  120. package/src/api/exporters/markdown/markdownExporter.ts +42 -0
  121. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +486 -125
  122. package/src/api/nodeConversions/nodeConversions.test.ts +67 -498
  123. package/src/api/nodeConversions/nodeConversions.ts +311 -85
  124. package/src/api/parsers/html/__snapshots__/paste/list-test.json +105 -0
  125. package/src/api/parsers/html/__snapshots__/paste/parse-basic-block-types.json +140 -0
  126. package/src/api/parsers/html/__snapshots__/paste/parse-deep-nested-content.json +240 -0
  127. package/src/api/parsers/html/__snapshots__/paste/parse-div-with-inline-content.json +91 -0
  128. package/src/api/parsers/html/__snapshots__/paste/parse-divs.json +121 -0
  129. package/src/api/parsers/html/__snapshots__/paste/parse-fake-image-caption.json +31 -0
  130. package/src/api/parsers/html/__snapshots__/paste/parse-google-docs-html.json +476 -0
  131. package/src/api/parsers/html/__snapshots__/paste/parse-mixed-nested-lists.json +140 -0
  132. package/src/api/parsers/html/__snapshots__/paste/parse-nested-lists-with-paragraphs.json +140 -0
  133. package/src/api/parsers/html/__snapshots__/paste/parse-nested-lists.json +157 -0
  134. package/src/api/parsers/html/__snapshots__/paste/parse-notion-html.json +470 -0
  135. package/src/api/parsers/html/__snapshots__/paste/parse-two-divs.json +36 -0
  136. package/src/api/parsers/html/parseHTML.test.ts +440 -0
  137. package/src/api/parsers/html/parseHTML.ts +42 -0
  138. package/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap +129 -0
  139. package/src/api/parsers/html/util/nestedLists.test.ts +176 -0
  140. package/src/api/parsers/html/util/nestedLists.ts +113 -0
  141. package/src/api/parsers/markdown/__snapshots__/complex.json +353 -0
  142. package/src/api/parsers/markdown/__snapshots__/issue-226-1.json +71 -0
  143. package/src/api/parsers/markdown/__snapshots__/issue-226-2.json +144 -0
  144. package/src/api/parsers/markdown/__snapshots__/nested.json +72 -0
  145. package/src/api/parsers/markdown/__snapshots__/non-nested.json +71 -0
  146. package/src/api/parsers/markdown/__snapshots__/styled.json +58 -0
  147. package/src/api/parsers/markdown/parseMarkdown.test.ts +114 -0
  148. package/src/api/parsers/markdown/parseMarkdown.ts +84 -0
  149. package/src/api/parsers/pasteExtension.ts +59 -0
  150. package/src/api/testUtil/cases/customBlocks.ts +282 -0
  151. package/src/api/testUtil/cases/customInlineContent.ts +114 -0
  152. package/src/api/testUtil/cases/customStyles.ts +100 -0
  153. package/src/api/testUtil/cases/defaultSchema.ts +399 -0
  154. package/src/api/testUtil/index.ts +17 -0
  155. package/src/api/testUtil/partialBlockTestUtil.ts +127 -0
  156. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +136 -0
  157. package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/ImageBlockContent.ts +87 -31
  158. package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +34 -47
  159. package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
  160. package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
  161. package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +34 -56
  162. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +43 -0
  163. package/src/blocks/README.md +3 -0
  164. package/src/blocks/TableBlockContent/TableBlockContent.ts +74 -0
  165. package/src/blocks/TableBlockContent/TableExtension.ts +63 -0
  166. package/src/blocks/defaultBlockHelpers.ts +95 -0
  167. package/src/blocks/defaultBlocks.ts +60 -0
  168. package/src/blocks/defaultProps.ts +24 -0
  169. package/src/{extensions/Blocks/nodes/Block.module.css → editor/Block.css} +69 -62
  170. package/src/{BlockNoteEditor.test.ts → editor/BlockNoteEditor.test.ts} +2 -2
  171. package/src/{BlockNoteEditor.ts → editor/BlockNoteEditor.ts} +363 -153
  172. package/src/{BlockNoteExtensions.ts → editor/BlockNoteExtensions.ts} +59 -40
  173. package/src/editor/README.md +3 -0
  174. package/src/editor/cursorPositionTypes.ts +16 -0
  175. package/src/{editor.module.css → editor/editor.css} +43 -15
  176. package/src/editor/selectionTypes.ts +14 -0
  177. package/src/editor/transformPasted.ts +58 -0
  178. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -36
  179. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +12 -27
  180. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +16 -24
  181. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +12 -10
  182. package/src/extensions/ImageToolbar/ImageToolbarPlugin.ts +35 -73
  183. package/src/extensions/Placeholder/PlaceholderExtension.ts +4 -4
  184. package/src/extensions/README.md +3 -0
  185. package/src/extensions/SideMenu/SideMenuPlugin.ts +66 -37
  186. package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +7 -6
  187. package/src/extensions/SlashMenu/SlashMenuPlugin.ts +9 -7
  188. package/src/extensions/SlashMenu/defaultSlashMenuItems.ts +98 -35
  189. package/src/extensions/TableHandles/TableHandlesPlugin.ts +617 -0
  190. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +3 -51
  191. package/src/extensions/TextColor/TextColorExtension.ts +1 -29
  192. package/src/extensions/TextColor/TextColorMark.ts +7 -27
  193. package/src/extensions/UniqueID/UniqueID.ts +28 -2
  194. package/src/extensions-shared/README.md +3 -0
  195. package/src/{shared/plugins → extensions-shared}/suggestion/SuggestionPlugin.ts +19 -13
  196. package/src/index.ts +21 -15
  197. package/src/{extensions/Blocks/nodes → pm-nodes}/BlockContainer.ts +161 -96
  198. package/src/pm-nodes/BlockGroup.ts +54 -0
  199. package/src/pm-nodes/Doc.ts +7 -0
  200. package/src/pm-nodes/README.md +42 -0
  201. package/src/pm-nodes/index.ts +3 -0
  202. package/src/schema/README.md +3 -0
  203. package/src/schema/blocks/createSpec.ts +220 -0
  204. package/src/schema/blocks/internal.ts +253 -0
  205. package/src/schema/blocks/types.ts +252 -0
  206. package/src/schema/index.ts +10 -0
  207. package/src/schema/inlineContent/createSpec.ts +119 -0
  208. package/src/schema/inlineContent/internal.ts +105 -0
  209. package/src/schema/inlineContent/types.ts +144 -0
  210. package/src/schema/propTypes.ts +32 -0
  211. package/src/schema/styles/createSpec.ts +85 -0
  212. package/src/schema/styles/internal.ts +96 -0
  213. package/src/schema/styles/types.ts +42 -0
  214. package/src/util/README.md +3 -0
  215. package/src/{shared/utils.ts → util/browser.ts} +4 -8
  216. package/src/util/string.ts +3 -0
  217. package/src/util/typescript.ts +5 -0
  218. package/types/src/api/blockManipulation/blockManipulation.d.ts +5 -4
  219. package/types/src/api/exporters/copyExtension.d.ts +6 -0
  220. package/types/src/api/exporters/html/externalHTMLExporter.d.ts +8 -0
  221. package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +8 -0
  222. package/types/src/api/exporters/html/util/sharedHTMLConversion.d.ts +7 -0
  223. package/types/src/api/exporters/markdown/markdownExporter.d.ts +5 -0
  224. package/types/src/api/nodeConversions/nodeConversions.d.ts +14 -6
  225. package/types/src/api/parsers/html/parseHTML.d.ts +3 -0
  226. package/types/src/api/parsers/html/parseHTML.test.d.ts +1 -0
  227. package/types/src/api/parsers/html/util/nestedLists.d.ts +1 -0
  228. package/types/src/api/parsers/html/util/nestedLists.test.d.ts +1 -0
  229. package/types/src/api/parsers/markdown/parseMarkdown.d.ts +3 -0
  230. package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +1 -0
  231. package/types/src/api/parsers/pasteExtension.d.ts +6 -0
  232. package/types/src/api/testUtil/cases/customBlocks.d.ts +345 -0
  233. package/types/src/api/testUtil/cases/customInlineContent.d.ts +29 -0
  234. package/types/src/api/testUtil/cases/customStyles.d.ts +64 -0
  235. package/types/src/api/testUtil/cases/defaultSchema.d.ts +3 -0
  236. package/types/src/api/testUtil/index.d.ts +12 -0
  237. package/types/src/api/testUtil/partialBlockTestUtil.d.ts +7 -0
  238. package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +58 -0
  239. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +93 -0
  240. package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +46 -0
  241. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +46 -0
  242. package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +52 -0
  243. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +53 -0
  244. package/types/src/blocks/TableBlockContent/TableExtension.d.ts +2 -0
  245. package/types/src/blocks/defaultBlockHelpers.d.ts +10 -0
  246. package/types/src/blocks/defaultBlocks.d.ts +577 -0
  247. package/types/src/{extensions/Blocks/api → blocks}/defaultProps.d.ts +2 -1
  248. package/types/src/{BlockNoteEditor.d.ts → editor/BlockNoteEditor.d.ts} +54 -43
  249. package/types/src/editor/BlockNoteEditor.test.d.ts +1 -0
  250. package/types/src/{BlockNoteExtensions.d.ts → editor/BlockNoteExtensions.d.ts} +7 -4
  251. package/types/src/editor/cursorPositionTypes.d.ts +6 -0
  252. package/types/src/editor/selectionTypes.d.ts +4 -0
  253. package/types/src/editor/transformPasted.d.ts +12 -0
  254. package/types/src/extensions/BackgroundColor/BackgroundColorExtension.d.ts +0 -7
  255. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +7 -9
  256. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +8 -6
  257. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +6 -6
  258. package/types/src/extensions/ImageToolbar/ImageToolbarPlugin.d.ts +11 -16
  259. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +18 -11
  260. package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +5 -6
  261. package/types/src/extensions/SlashMenu/SlashMenuPlugin.d.ts +6 -6
  262. package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +2 -1
  263. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +74 -0
  264. package/types/src/extensions/TextAlignment/TextAlignmentExtension.d.ts +0 -7
  265. package/types/src/extensions/TextColor/TextColorExtension.d.ts +0 -7
  266. package/types/src/extensions/TextColor/TextColorMark.d.ts +7 -9
  267. package/types/src/extensions/UniqueID/UniqueID.d.ts +1 -1
  268. package/types/src/{shared/plugins → extensions-shared}/suggestion/SuggestionPlugin.d.ts +5 -4
  269. package/types/src/index.d.ts +20 -15
  270. package/types/src/{extensions/Blocks/nodes → pm-nodes}/BlockContainer.d.ts +5 -3
  271. package/types/src/pm-nodes/Doc.d.ts +2 -0
  272. package/types/src/pm-nodes/index.d.ts +3 -0
  273. package/types/src/schema/blocks/createSpec.d.ts +35 -0
  274. package/types/src/schema/blocks/internal.d.ts +45 -0
  275. package/types/src/schema/blocks/types.d.ts +107 -0
  276. package/types/src/schema/index.d.ts +10 -0
  277. package/types/src/schema/inlineContent/createSpec.d.ts +21 -0
  278. package/types/src/schema/inlineContent/internal.d.ts +28 -0
  279. package/types/src/schema/inlineContent/types.d.ts +62 -0
  280. package/types/src/schema/propTypes.d.ts +8 -0
  281. package/types/src/schema/styles/createSpec.d.ts +13 -0
  282. package/types/src/schema/styles/internal.d.ts +22 -0
  283. package/types/src/schema/styles/types.d.ts +21 -0
  284. package/types/src/{shared/utils.d.ts → util/browser.d.ts} +0 -3
  285. package/types/src/util/string.d.ts +1 -0
  286. package/types/src/util/typescript.d.ts +3 -0
  287. package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +0 -346
  288. package/src/api/formatConversions/formatConversions.test.ts +0 -753
  289. package/src/api/formatConversions/formatConversions.ts +0 -133
  290. package/src/api/nodeConversions/testUtil.ts +0 -65
  291. package/src/extensions/Blocks/api/block.ts +0 -307
  292. package/src/extensions/Blocks/api/blockTypes.ts +0 -249
  293. package/src/extensions/Blocks/api/cursorPositionTypes.ts +0 -7
  294. package/src/extensions/Blocks/api/defaultBlocks.ts +0 -16
  295. package/src/extensions/Blocks/api/defaultProps.ts +0 -16
  296. package/src/extensions/Blocks/api/inlineContentTypes.ts +0 -36
  297. package/src/extensions/Blocks/api/selectionTypes.ts +0 -5
  298. package/src/extensions/Blocks/api/serialization.ts +0 -29
  299. package/src/extensions/Blocks/helpers/findBlock.ts +0 -5
  300. package/src/extensions/Blocks/index.ts +0 -8
  301. package/src/extensions/Blocks/nodes/BlockAttributes.ts +0 -10
  302. package/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.ts +0 -142
  303. package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +0 -62
  304. package/src/extensions/Blocks/nodes/BlockGroup.ts +0 -53
  305. package/types/src/api/formatConversions/formatConversions.d.ts +0 -6
  306. package/types/src/api/nodeConversions/testUtil.d.ts +0 -2
  307. package/types/src/extensions/Blocks/api/block.d.ts +0 -20
  308. package/types/src/extensions/Blocks/api/blockTypes.d.ts +0 -103
  309. package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +0 -6
  310. package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +0 -117
  311. package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +0 -30
  312. package/types/src/extensions/Blocks/api/selectionTypes.d.ts +0 -4
  313. package/types/src/extensions/Blocks/api/serialization.d.ts +0 -2
  314. package/types/src/extensions/Blocks/helpers/findBlock.d.ts +0 -6
  315. package/types/src/extensions/Blocks/index.d.ts +0 -4
  316. package/types/src/extensions/Blocks/nodes/BlockAttributes.d.ts +0 -2
  317. package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +0 -43
  318. package/types/src/extensions/Blocks/nodes/BlockContent/ImageBlockContent/ImageBlockContent.d.ts +0 -37
  319. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -35
  320. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -35
  321. package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -44
  322. /package/src/{shared/EditorElement.ts → api/exporters/markdown/__snapshots__/hardbreak/only/markdown.md} +0 -0
  323. /package/{types/src/shared/EditorElement.d.ts → src/api/exporters/markdown/__snapshots__/paragraph/empty/markdown.md} +0 -0
  324. /package/src/api/{formatConversions → exporters/markdown}/removeUnderlinesRehypePlugin.ts +0 -0
  325. /package/src/{extensions/Blocks/helpers → api}/getBlockInfoFromPos.ts +0 -0
  326. /package/src/api/{util/nodeUtil.ts → nodeUtil.ts} +0 -0
  327. /package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
  328. /package/src/extensions/{Blocks → NonEditableBlocks}/NonEditableBlockPlugin.ts +0 -0
  329. /package/src/extensions/{Blocks → PreviousBlockType}/PreviousBlockTypePlugin.ts +0 -0
  330. /package/src/{shared → extensions-shared}/BaseUiElementTypes.ts +0 -0
  331. /package/src/{shared/plugins → extensions-shared}/suggestion/SuggestionItem.ts +0 -0
  332. /package/src/{shared → util}/EventEmitter.ts +0 -0
  333. /package/types/src/{BlockNoteEditor.test.d.ts → api/exporters/html/htmlConversion.test.d.ts} +0 -0
  334. /package/types/src/api/{formatConversions → exporters/html/util}/simplifyBlocksRehypePlugin.d.ts +0 -0
  335. /package/types/src/api/{formatConversions/formatConversions.test.d.ts → exporters/markdown/markdownExporter.test.d.ts} +0 -0
  336. /package/types/src/api/{formatConversions → exporters/markdown}/removeUnderlinesRehypePlugin.d.ts +0 -0
  337. /package/types/src/{extensions/Blocks/helpers → api}/getBlockInfoFromPos.d.ts +0 -0
  338. /package/types/src/api/{util/nodeUtil.d.ts → nodeUtil.d.ts} +0 -0
  339. /package/types/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
  340. /package/types/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +0 -0
  341. /package/types/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -0
  342. /package/types/src/extensions/{Blocks → NonEditableBlocks}/NonEditableBlockPlugin.d.ts +0 -0
  343. /package/types/src/extensions/{Blocks → PreviousBlockType}/PreviousBlockTypePlugin.d.ts +0 -0
  344. /package/types/src/{shared → extensions-shared}/BaseUiElementTypes.d.ts +0 -0
  345. /package/types/src/{shared/plugins → extensions-shared}/suggestion/SuggestionItem.d.ts +0 -0
  346. /package/types/src/{extensions/Blocks/nodes → pm-nodes}/BlockGroup.d.ts +0 -0
  347. /package/types/src/{shared → util}/EventEmitter.d.ts +0 -0
@@ -1,44 +1,56 @@
1
- import { Mark } from "@tiptap/pm/model";
2
- import { Node, Schema } from "prosemirror-model";
3
- import {
1
+ import { Mark, Node, Schema } from "@tiptap/pm/model";
2
+
3
+ import UniqueID from "../../extensions/UniqueID/UniqueID";
4
+ import type {
4
5
  Block,
5
6
  BlockSchema,
6
- PartialBlock,
7
- } from "../../extensions/Blocks/api/blockTypes";
8
- import {
9
- ColorStyle,
7
+ CustomInlineContentConfig,
8
+ CustomInlineContentFromConfig,
10
9
  InlineContent,
10
+ InlineContentFromConfig,
11
+ InlineContentSchema,
12
+ PartialBlock,
13
+ PartialCustomInlineContentFromConfig,
11
14
  PartialInlineContent,
12
15
  PartialLink,
16
+ PartialTableContent,
17
+ StyleSchema,
13
18
  StyledText,
14
19
  Styles,
15
- ToggledStyle,
16
- } from "../../extensions/Blocks/api/inlineContentTypes";
17
- import { getBlockInfo } from "../../extensions/Blocks/helpers/getBlockInfoFromPos";
18
- import UniqueID from "../../extensions/UniqueID/UniqueID";
19
- import { UnreachableCaseError } from "../../shared/utils";
20
+ TableContent,
21
+ } from "../../schema";
22
+ import { getBlockInfo } from "../getBlockInfoFromPos";
20
23
 
21
- const toggleStyles = new Set<ToggledStyle>([
22
- "bold",
23
- "italic",
24
- "underline",
25
- "strike",
26
- "code",
27
- ]);
28
- const colorStyles = new Set<ColorStyle>(["textColor", "backgroundColor"]);
24
+ import {
25
+ isLinkInlineContent,
26
+ isPartialLinkInlineContent,
27
+ isStyledTextInlineContent,
28
+ } from "../../schema/inlineContent/types";
29
+ import { UnreachableCaseError } from "../../util/typescript";
29
30
 
30
31
  /**
31
32
  * Convert a StyledText inline element to a
32
33
  * prosemirror text node with the appropriate marks
33
34
  */
34
- function styledTextToNodes(styledText: StyledText, schema: Schema): Node[] {
35
+ function styledTextToNodes<T extends StyleSchema>(
36
+ styledText: StyledText<T>,
37
+ schema: Schema,
38
+ styleSchema: T
39
+ ): Node[] {
35
40
  const marks: Mark[] = [];
36
41
 
37
42
  for (const [style, value] of Object.entries(styledText.styles)) {
38
- if (toggleStyles.has(style as ToggledStyle)) {
43
+ const config = styleSchema[style];
44
+ if (!config) {
45
+ throw new Error(`style ${style} not found in styleSchema`);
46
+ }
47
+
48
+ if (config.propSchema === "boolean") {
39
49
  marks.push(schema.mark(style));
40
- } else if (colorStyles.has(style as ColorStyle)) {
41
- marks.push(schema.mark(style, { color: value }));
50
+ } else if (config.propSchema === "string") {
51
+ marks.push(schema.mark(style, { stringValue: value }));
52
+ } else {
53
+ throw new UnreachableCaseError(config.propSchema);
42
54
  }
43
55
  }
44
56
 
@@ -64,42 +76,53 @@ function styledTextToNodes(styledText: StyledText, schema: Schema): Node[] {
64
76
  * Converts a Link inline content element to
65
77
  * prosemirror text nodes with the appropriate marks
66
78
  */
67
- function linkToNodes(link: PartialLink, schema: Schema): Node[] {
79
+ function linkToNodes(
80
+ link: PartialLink<StyleSchema>,
81
+ schema: Schema,
82
+ styleSchema: StyleSchema
83
+ ): Node[] {
68
84
  const linkMark = schema.marks.link.create({
69
85
  href: link.href,
70
86
  });
71
87
 
72
- return styledTextArrayToNodes(link.content, schema).map((node) => {
73
- if (node.type.name === "text") {
74
- return node.mark([...node.marks, linkMark]);
75
- }
88
+ return styledTextArrayToNodes(link.content, schema, styleSchema).map(
89
+ (node) => {
90
+ if (node.type.name === "text") {
91
+ return node.mark([...node.marks, linkMark]);
92
+ }
76
93
 
77
- if (node.type.name === "hardBreak") {
78
- return node;
94
+ if (node.type.name === "hardBreak") {
95
+ return node;
96
+ }
97
+ throw new Error("unexpected node type");
79
98
  }
80
- throw new Error("unexpected node type");
81
- });
99
+ );
82
100
  }
83
101
 
84
102
  /**
85
103
  * Converts an array of StyledText inline content elements to
86
104
  * prosemirror text nodes with the appropriate marks
87
105
  */
88
- function styledTextArrayToNodes(
89
- content: string | StyledText[],
90
- schema: Schema
106
+ function styledTextArrayToNodes<S extends StyleSchema>(
107
+ content: string | StyledText<S>[],
108
+ schema: Schema,
109
+ styleSchema: S
91
110
  ): Node[] {
92
111
  const nodes: Node[] = [];
93
112
 
94
113
  if (typeof content === "string") {
95
114
  nodes.push(
96
- ...styledTextToNodes({ type: "text", text: content, styles: {} }, schema)
115
+ ...styledTextToNodes(
116
+ { type: "text", text: content, styles: {} },
117
+ schema,
118
+ styleSchema
119
+ )
97
120
  );
98
121
  return nodes;
99
122
  }
100
123
 
101
124
  for (const styledText of content) {
102
- nodes.push(...styledTextToNodes(styledText, schema));
125
+ nodes.push(...styledTextToNodes(styledText, schema, styleSchema));
103
126
  }
104
127
  return nodes;
105
128
  }
@@ -107,44 +130,85 @@ function styledTextArrayToNodes(
107
130
  /**
108
131
  * converts an array of inline content elements to prosemirror nodes
109
132
  */
110
- export function inlineContentToNodes(
111
- blockContent: PartialInlineContent[],
112
- schema: Schema
133
+ export function inlineContentToNodes<
134
+ I extends InlineContentSchema,
135
+ S extends StyleSchema
136
+ >(
137
+ blockContent: PartialInlineContent<I, S>,
138
+ schema: Schema,
139
+ styleSchema: S
113
140
  ): Node[] {
114
141
  const nodes: Node[] = [];
115
142
 
116
143
  for (const content of blockContent) {
117
- if (content.type === "link") {
118
- nodes.push(...linkToNodes(content, schema));
119
- } else if (content.type === "text") {
120
- nodes.push(...styledTextArrayToNodes([content], schema));
144
+ if (typeof content === "string") {
145
+ nodes.push(...styledTextArrayToNodes(content, schema, styleSchema));
146
+ } else if (isPartialLinkInlineContent(content)) {
147
+ nodes.push(...linkToNodes(content, schema, styleSchema));
148
+ } else if (isStyledTextInlineContent(content)) {
149
+ nodes.push(...styledTextArrayToNodes([content], schema, styleSchema));
121
150
  } else {
122
- throw new UnreachableCaseError(content);
151
+ nodes.push(
152
+ blockOrInlineContentToContentNode(content, schema, styleSchema)
153
+ );
123
154
  }
124
155
  }
125
156
  return nodes;
126
157
  }
127
158
 
128
159
  /**
129
- * Converts a BlockNote block to a TipTap node.
160
+ * converts an array of inline content elements to prosemirror nodes
130
161
  */
131
- export function blockToNode<BSchema extends BlockSchema>(
132
- block: PartialBlock<BSchema>,
133
- schema: Schema
134
- ) {
135
- let id = block.id;
162
+ export function tableContentToNodes<
163
+ I extends InlineContentSchema,
164
+ S extends StyleSchema
165
+ >(
166
+ tableContent: PartialTableContent<I, S>,
167
+ schema: Schema,
168
+ styleSchema: StyleSchema
169
+ ): Node[] {
170
+ const rowNodes: Node[] = [];
171
+
172
+ for (const row of tableContent.rows) {
173
+ const columnNodes: Node[] = [];
174
+ for (const cell of row.cells) {
175
+ let pNode: Node;
176
+ if (!cell) {
177
+ pNode = schema.nodes["tableParagraph"].create({});
178
+ } else if (typeof cell === "string") {
179
+ pNode = schema.nodes["tableParagraph"].create({}, schema.text(cell));
180
+ } else {
181
+ const textNodes = inlineContentToNodes(cell, schema, styleSchema);
182
+ pNode = schema.nodes["tableParagraph"].create({}, textNodes);
183
+ }
136
184
 
137
- if (id === undefined) {
138
- id = UniqueID.options.generateID();
185
+ const cellNode = schema.nodes["tableCell"].create({}, pNode);
186
+ columnNodes.push(cellNode);
187
+ }
188
+ const rowNode = schema.nodes["tableRow"].create({}, columnNodes);
189
+ rowNodes.push(rowNode);
139
190
  }
191
+ return rowNodes;
192
+ }
140
193
 
194
+ function blockOrInlineContentToContentNode(
195
+ block:
196
+ | PartialBlock<any, any, any>
197
+ | PartialCustomInlineContentFromConfig<any, any>,
198
+ schema: Schema,
199
+ styleSchema: StyleSchema
200
+ ) {
201
+ let contentNode: Node;
141
202
  let type = block.type;
142
203
 
204
+ // TODO: needed? came from previous code
143
205
  if (type === undefined) {
144
206
  type = "paragraph";
145
207
  }
146
208
 
147
- let contentNode: Node;
209
+ if (!schema.nodes[type]) {
210
+ throw new Error(`node type ${type} not found in schema`);
211
+ }
148
212
 
149
213
  if (!block.content) {
150
214
  contentNode = schema.nodes[type].create(block.props);
@@ -153,16 +217,42 @@ export function blockToNode<BSchema extends BlockSchema>(
153
217
  block.props,
154
218
  schema.text(block.content)
155
219
  );
156
- } else {
157
- const nodes = inlineContentToNodes(block.content, schema);
220
+ } else if (Array.isArray(block.content)) {
221
+ const nodes = inlineContentToNodes(block.content, schema, styleSchema);
158
222
  contentNode = schema.nodes[type].create(block.props, nodes);
223
+ } else if (block.content.type === "tableContent") {
224
+ const nodes = tableContentToNodes(block.content, schema, styleSchema);
225
+ contentNode = schema.nodes[type].create(block.props, nodes);
226
+ } else {
227
+ throw new UnreachableCaseError(block.content.type);
228
+ }
229
+ return contentNode;
230
+ }
231
+ /**
232
+ * Converts a BlockNote block to a TipTap node.
233
+ */
234
+ export function blockToNode(
235
+ block: PartialBlock<any, any, any>,
236
+ schema: Schema,
237
+ styleSchema: StyleSchema
238
+ ) {
239
+ let id = block.id;
240
+
241
+ if (id === undefined) {
242
+ id = UniqueID.options.generateID();
159
243
  }
160
244
 
245
+ const contentNode = blockOrInlineContentToContentNode(
246
+ block,
247
+ schema,
248
+ styleSchema
249
+ );
250
+
161
251
  const children: Node[] = [];
162
252
 
163
253
  if (block.children) {
164
254
  for (const child of block.children) {
165
- children.push(blockToNode(child, schema));
255
+ children.push(blockToNode(child, schema, styleSchema));
166
256
  }
167
257
  }
168
258
 
@@ -177,12 +267,48 @@ export function blockToNode<BSchema extends BlockSchema>(
177
267
  );
178
268
  }
179
269
 
270
+ /**
271
+ * Converts an internal (prosemirror) table node contentto a BlockNote Tablecontent
272
+ */
273
+ function contentNodeToTableContent<
274
+ I extends InlineContentSchema,
275
+ S extends StyleSchema
276
+ >(contentNode: Node, inlineContentSchema: I, styleSchema: S) {
277
+ const ret: TableContent<I, S> = {
278
+ type: "tableContent",
279
+ rows: [],
280
+ };
281
+
282
+ contentNode.content.forEach((rowNode) => {
283
+ const row: TableContent<I, S>["rows"][0] = {
284
+ cells: [],
285
+ };
286
+
287
+ rowNode.content.forEach((cellNode) => {
288
+ row.cells.push(
289
+ contentNodeToInlineContent(
290
+ cellNode.firstChild!,
291
+ inlineContentSchema,
292
+ styleSchema
293
+ )
294
+ );
295
+ });
296
+
297
+ ret.rows.push(row);
298
+ });
299
+
300
+ return ret;
301
+ }
302
+
180
303
  /**
181
304
  * Converts an internal (prosemirror) content node to a BlockNote InlineContent array.
182
305
  */
183
- function contentNodeToInlineContent(contentNode: Node) {
184
- const content: InlineContent[] = [];
185
- let currentContent: InlineContent | undefined = undefined;
306
+ export function contentNodeToInlineContent<
307
+ I extends InlineContentSchema,
308
+ S extends StyleSchema
309
+ >(contentNode: Node, inlineContentSchema: I, styleSchema: S) {
310
+ const content: InlineContent<any, S>[] = [];
311
+ let currentContent: InlineContent<any, S> | undefined = undefined;
186
312
 
187
313
  // Most of the logic below is for handling links because in ProseMirror links are marks
188
314
  // while in BlockNote links are a type of inline content
@@ -192,13 +318,15 @@ function contentNodeToInlineContent(contentNode: Node) {
192
318
  if (node.type.name === "hardBreak") {
193
319
  if (currentContent) {
194
320
  // Current content exists.
195
- if (currentContent.type === "text") {
321
+ if (isStyledTextInlineContent(currentContent)) {
196
322
  // Current content is text.
197
323
  currentContent.text += "\n";
198
- } else if (currentContent.type === "link") {
324
+ } else if (isLinkInlineContent(currentContent)) {
199
325
  // Current content is a link.
200
326
  currentContent.content[currentContent.content.length - 1].text +=
201
327
  "\n";
328
+ } else {
329
+ throw new Error("unexpected");
202
330
  }
203
331
  } else {
204
332
  // Current content does not exist.
@@ -212,18 +340,41 @@ function contentNodeToInlineContent(contentNode: Node) {
212
340
  return;
213
341
  }
214
342
 
215
- const styles: Styles = {};
343
+ if (
344
+ node.type.name !== "link" &&
345
+ node.type.name !== "text" &&
346
+ inlineContentSchema[node.type.name]
347
+ ) {
348
+ if (currentContent) {
349
+ content.push(currentContent);
350
+ currentContent = undefined;
351
+ }
352
+
353
+ content.push(
354
+ nodeToCustomInlineContent(node, inlineContentSchema, styleSchema)
355
+ );
356
+
357
+ return;
358
+ }
359
+
360
+ const styles: Styles<S> = {};
216
361
  let linkMark: Mark | undefined;
217
362
 
218
363
  for (const mark of node.marks) {
219
364
  if (mark.type.name === "link") {
220
365
  linkMark = mark;
221
- } else if (toggleStyles.has(mark.type.name as ToggledStyle)) {
222
- styles[mark.type.name as ToggledStyle] = true;
223
- } else if (colorStyles.has(mark.type.name as ColorStyle)) {
224
- styles[mark.type.name as ColorStyle] = mark.attrs.color;
225
366
  } else {
226
- throw Error("Mark is of an unrecognized type: " + mark.type.name);
367
+ const config = styleSchema[mark.type.name];
368
+ if (!config) {
369
+ throw new Error(`style ${mark.type.name} not found in styleSchema`);
370
+ }
371
+ if (config.propSchema === "boolean") {
372
+ (styles as any)[config.type] = true;
373
+ } else if (config.propSchema === "string") {
374
+ (styles as any)[config.type] = mark.attrs.stringValue;
375
+ } else {
376
+ throw new UnreachableCaseError(config.propSchema);
377
+ }
227
378
  }
228
379
  }
229
380
 
@@ -231,7 +382,7 @@ function contentNodeToInlineContent(contentNode: Node) {
231
382
  // Current content exists.
232
383
  if (currentContent) {
233
384
  // Current content is text.
234
- if (currentContent.type === "text") {
385
+ if (isStyledTextInlineContent(currentContent)) {
235
386
  if (!linkMark) {
236
387
  // Node is text (same type as current content).
237
388
  if (
@@ -263,7 +414,7 @@ function contentNodeToInlineContent(contentNode: Node) {
263
414
  ],
264
415
  };
265
416
  }
266
- } else if (currentContent.type === "link") {
417
+ } else if (isLinkInlineContent(currentContent)) {
267
418
  // Current content is a link.
268
419
  if (linkMark) {
269
420
  // Node is a link (same type as current content).
@@ -309,6 +460,8 @@ function contentNodeToInlineContent(contentNode: Node) {
309
460
  styles,
310
461
  };
311
462
  }
463
+ } else {
464
+ // TODO
312
465
  }
313
466
  }
314
467
  // Current content does not exist.
@@ -342,17 +495,66 @@ function contentNodeToInlineContent(contentNode: Node) {
342
495
  content.push(currentContent);
343
496
  }
344
497
 
345
- return content;
498
+ return content as InlineContent<I, S>[];
499
+ }
500
+
501
+ export function nodeToCustomInlineContent<
502
+ I extends InlineContentSchema,
503
+ S extends StyleSchema
504
+ >(node: Node, inlineContentSchema: I, styleSchema: S): InlineContent<I, S> {
505
+ if (node.type.name === "text" || node.type.name === "link") {
506
+ throw new Error("unexpected");
507
+ }
508
+ const props: any = {};
509
+ const icConfig = inlineContentSchema[
510
+ node.type.name
511
+ ] as CustomInlineContentConfig;
512
+ for (const [attr, value] of Object.entries(node.attrs)) {
513
+ if (!icConfig) {
514
+ throw Error("ic node is of an unrecognized type: " + node.type.name);
515
+ }
516
+
517
+ const propSchema = icConfig.propSchema;
518
+
519
+ if (attr in propSchema) {
520
+ props[attr] = value;
521
+ }
522
+ }
523
+
524
+ let content: CustomInlineContentFromConfig<any, any>["content"];
525
+
526
+ if (icConfig.content === "styled") {
527
+ content = contentNodeToInlineContent(
528
+ node,
529
+ inlineContentSchema,
530
+ styleSchema
531
+ ) as any; // TODO: is this safe? could we have Links here that are undesired?
532
+ } else {
533
+ content = undefined;
534
+ }
535
+
536
+ const ic = {
537
+ type: node.type.name,
538
+ props,
539
+ content,
540
+ } as InlineContentFromConfig<I[keyof I], S>;
541
+ return ic;
346
542
  }
347
543
 
348
544
  /**
349
545
  * Convert a TipTap node to a BlockNote block.
350
546
  */
351
- export function nodeToBlock<BSchema extends BlockSchema>(
547
+ export function nodeToBlock<
548
+ BSchema extends BlockSchema,
549
+ I extends InlineContentSchema,
550
+ S extends StyleSchema
551
+ >(
352
552
  node: Node,
353
553
  blockSchema: BSchema,
354
- blockCache?: WeakMap<Node, Block<BSchema>>
355
- ): Block<BSchema> {
554
+ inlineContentSchema: I,
555
+ styleSchema: S,
556
+ blockCache?: WeakMap<Node, Block<BSchema, I, S>>
557
+ ): Block<BSchema, I, S> {
356
558
  if (node.type.name !== "blockContainer") {
357
559
  throw Error(
358
560
  "Node must be of type blockContainer, but is of type" +
@@ -382,6 +584,7 @@ export function nodeToBlock<BSchema extends BlockSchema>(
382
584
  ...blockInfo.contentNode.attrs,
383
585
  })) {
384
586
  const blockSpec = blockSchema[blockInfo.contentType.name];
587
+
385
588
  if (!blockSpec) {
386
589
  throw Error(
387
590
  "Block is of an unrecognized type: " + blockInfo.contentType.name
@@ -395,25 +598,48 @@ export function nodeToBlock<BSchema extends BlockSchema>(
395
598
  }
396
599
  }
397
600
 
398
- const blockSpec = blockSchema[blockInfo.contentType.name];
601
+ const blockConfig = blockSchema[blockInfo.contentType.name];
399
602
 
400
- const children: Block<BSchema>[] = [];
603
+ const children: Block<BSchema, I, S>[] = [];
401
604
  for (let i = 0; i < blockInfo.numChildBlocks; i++) {
402
605
  children.push(
403
- nodeToBlock(node.lastChild!.child(i), blockSchema, blockCache)
606
+ nodeToBlock(
607
+ node.lastChild!.child(i),
608
+ blockSchema,
609
+ inlineContentSchema,
610
+ styleSchema,
611
+ blockCache
612
+ )
404
613
  );
405
614
  }
406
615
 
407
- const block: Block<BSchema> = {
616
+ let content: Block<any, any, any>["content"];
617
+
618
+ if (blockConfig.content === "inline") {
619
+ content = contentNodeToInlineContent(
620
+ blockInfo.contentNode,
621
+ inlineContentSchema,
622
+ styleSchema
623
+ );
624
+ } else if (blockConfig.content === "table") {
625
+ content = contentNodeToTableContent(
626
+ blockInfo.contentNode,
627
+ inlineContentSchema,
628
+ styleSchema
629
+ );
630
+ } else if (blockConfig.content === "none") {
631
+ content = undefined;
632
+ } else {
633
+ throw new UnreachableCaseError(blockConfig.content);
634
+ }
635
+
636
+ const block = {
408
637
  id,
409
- type: blockSpec.node.name,
638
+ type: blockConfig.type,
410
639
  props,
411
- content:
412
- blockSpec.node.config.content === "inline*"
413
- ? contentNodeToInlineContent(blockInfo.contentNode)
414
- : undefined,
640
+ content,
415
641
  children,
416
- } as Block<BSchema>;
642
+ } as Block<BSchema, I, S>;
417
643
 
418
644
  blockCache?.set(node, block);
419
645
 
@@ -0,0 +1,105 @@
1
+ [
2
+ {
3
+ "id": "1",
4
+ "type": "bulletListItem",
5
+ "props": {
6
+ "textColor": "default",
7
+ "backgroundColor": "default",
8
+ "textAlignment": "left"
9
+ },
10
+ "content": [
11
+ {
12
+ "type": "text",
13
+ "text": "First",
14
+ "styles": {}
15
+ }
16
+ ],
17
+ "children": []
18
+ },
19
+ {
20
+ "id": "2",
21
+ "type": "bulletListItem",
22
+ "props": {
23
+ "textColor": "default",
24
+ "backgroundColor": "default",
25
+ "textAlignment": "left"
26
+ },
27
+ "content": [
28
+ {
29
+ "type": "text",
30
+ "text": "Second",
31
+ "styles": {}
32
+ }
33
+ ],
34
+ "children": []
35
+ },
36
+ {
37
+ "id": "3",
38
+ "type": "bulletListItem",
39
+ "props": {
40
+ "textColor": "default",
41
+ "backgroundColor": "default",
42
+ "textAlignment": "left"
43
+ },
44
+ "content": [
45
+ {
46
+ "type": "text",
47
+ "text": "Third",
48
+ "styles": {}
49
+ }
50
+ ],
51
+ "children": []
52
+ },
53
+ {
54
+ "id": "4",
55
+ "type": "bulletListItem",
56
+ "props": {
57
+ "textColor": "default",
58
+ "backgroundColor": "default",
59
+ "textAlignment": "left"
60
+ },
61
+ "content": [
62
+ {
63
+ "type": "text",
64
+ "text": "Five Parent",
65
+ "styles": {}
66
+ }
67
+ ],
68
+ "children": [
69
+ {
70
+ "id": "5",
71
+ "type": "bulletListItem",
72
+ "props": {
73
+ "textColor": "default",
74
+ "backgroundColor": "default",
75
+ "textAlignment": "left"
76
+ },
77
+ "content": [
78
+ {
79
+ "type": "text",
80
+ "text": "Child 1",
81
+ "styles": {}
82
+ }
83
+ ],
84
+ "children": []
85
+ },
86
+ {
87
+ "id": "6",
88
+ "type": "bulletListItem",
89
+ "props": {
90
+ "textColor": "default",
91
+ "backgroundColor": "default",
92
+ "textAlignment": "left"
93
+ },
94
+ "content": [
95
+ {
96
+ "type": "text",
97
+ "text": "Child 2",
98
+ "styles": {}
99
+ }
100
+ ],
101
+ "children": []
102
+ }
103
+ ]
104
+ }
105
+ ]