@blocknote/core 0.9.6 → 0.10.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 (367) hide show
  1. package/dist/blocknote.js +3697 -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 +8 -4
  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/empty/markdown.md +0 -0
  110. package/src/api/exporters/markdown/__snapshots__/paragraph/nested/markdown.md +5 -0
  111. package/src/api/exporters/markdown/__snapshots__/paragraph/styled/markdown.md +1 -0
  112. package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/basic/markdown.md +1 -0
  113. package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/nested/markdown.md +5 -0
  114. package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/styled/markdown.md +1 -0
  115. package/src/api/exporters/markdown/__snapshots__/simpleImage/basic/markdown.md +1 -0
  116. package/src/api/exporters/markdown/__snapshots__/simpleImage/button/markdown.md +1 -0
  117. package/src/api/exporters/markdown/__snapshots__/simpleImage/nested/markdown.md +3 -0
  118. package/src/api/exporters/markdown/__snapshots__/small/basic/markdown.md +1 -0
  119. package/src/api/exporters/markdown/__snapshots__/tag/basic/markdown.md +1 -0
  120. package/src/api/exporters/markdown/markdownExporter.test.ts +85 -0
  121. package/src/api/exporters/markdown/markdownExporter.ts +42 -0
  122. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +486 -125
  123. package/src/api/nodeConversions/nodeConversions.test.ts +67 -498
  124. package/src/api/nodeConversions/nodeConversions.ts +311 -85
  125. package/src/api/parsers/html/__snapshots__/paste/list-test.json +105 -0
  126. package/src/api/parsers/html/__snapshots__/paste/parse-basic-block-types.json +140 -0
  127. package/src/api/parsers/html/__snapshots__/paste/parse-deep-nested-content.json +240 -0
  128. package/src/api/parsers/html/__snapshots__/paste/parse-div-with-inline-content.json +91 -0
  129. package/src/api/parsers/html/__snapshots__/paste/parse-divs.json +121 -0
  130. package/src/api/parsers/html/__snapshots__/paste/parse-fake-image-caption.json +31 -0
  131. package/src/api/parsers/html/__snapshots__/paste/parse-google-docs-html.json +476 -0
  132. package/src/api/parsers/html/__snapshots__/paste/parse-mixed-nested-lists.json +140 -0
  133. package/src/api/parsers/html/__snapshots__/paste/parse-nested-lists-with-paragraphs.json +140 -0
  134. package/src/api/parsers/html/__snapshots__/paste/parse-nested-lists.json +157 -0
  135. package/src/api/parsers/html/__snapshots__/paste/parse-notion-html.json +470 -0
  136. package/src/api/parsers/html/__snapshots__/paste/parse-two-divs.json +36 -0
  137. package/src/api/parsers/html/parseHTML.test.ts +440 -0
  138. package/src/api/parsers/html/parseHTML.ts +42 -0
  139. package/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap +129 -0
  140. package/src/api/parsers/html/util/nestedLists.test.ts +176 -0
  141. package/src/api/parsers/html/util/nestedLists.ts +113 -0
  142. package/src/api/parsers/markdown/__snapshots__/complex.json +353 -0
  143. package/src/api/parsers/markdown/__snapshots__/issue-226-1.json +71 -0
  144. package/src/api/parsers/markdown/__snapshots__/issue-226-2.json +144 -0
  145. package/src/api/parsers/markdown/__snapshots__/nested.json +72 -0
  146. package/src/api/parsers/markdown/__snapshots__/non-nested.json +71 -0
  147. package/src/api/parsers/markdown/__snapshots__/styled.json +58 -0
  148. package/src/api/parsers/markdown/parseMarkdown.test.ts +114 -0
  149. package/src/api/parsers/markdown/parseMarkdown.ts +84 -0
  150. package/src/api/parsers/pasteExtension.ts +59 -0
  151. package/src/api/testUtil/cases/customBlocks.ts +282 -0
  152. package/src/api/testUtil/cases/customInlineContent.ts +114 -0
  153. package/src/api/testUtil/cases/customStyles.ts +100 -0
  154. package/src/api/testUtil/cases/defaultSchema.ts +399 -0
  155. package/src/api/testUtil/index.ts +17 -0
  156. package/src/api/testUtil/partialBlockTestUtil.ts +127 -0
  157. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +136 -0
  158. package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/ImageBlockContent.ts +87 -31
  159. package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +34 -47
  160. package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
  161. package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
  162. package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +34 -56
  163. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +43 -0
  164. package/src/blocks/README.md +3 -0
  165. package/src/blocks/TableBlockContent/TableBlockContent.ts +74 -0
  166. package/src/blocks/TableBlockContent/TableExtension.ts +63 -0
  167. package/src/blocks/defaultBlockHelpers.ts +95 -0
  168. package/src/blocks/defaultBlocks.ts +60 -0
  169. package/src/blocks/defaultProps.ts +24 -0
  170. package/src/{extensions/Blocks/nodes/Block.module.css → editor/Block.css} +69 -62
  171. package/src/{BlockNoteEditor.test.ts → editor/BlockNoteEditor.test.ts} +2 -2
  172. package/src/{BlockNoteEditor.ts → editor/BlockNoteEditor.ts} +364 -153
  173. package/src/{BlockNoteExtensions.ts → editor/BlockNoteExtensions.ts} +59 -40
  174. package/src/editor/README.md +3 -0
  175. package/src/editor/cursorPositionTypes.ts +16 -0
  176. package/src/{editor.module.css → editor/editor.css} +42 -15
  177. package/src/editor/selectionTypes.ts +14 -0
  178. package/src/editor/transformPasted.ts +58 -0
  179. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -36
  180. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +12 -27
  181. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +16 -24
  182. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +12 -10
  183. package/src/extensions/ImageToolbar/ImageToolbarPlugin.ts +35 -73
  184. package/src/extensions/Placeholder/PlaceholderExtension.ts +4 -4
  185. package/src/extensions/README.md +3 -0
  186. package/src/extensions/SideMenu/SideMenuPlugin.ts +66 -37
  187. package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +7 -6
  188. package/src/extensions/SlashMenu/SlashMenuPlugin.ts +9 -7
  189. package/src/extensions/SlashMenu/defaultSlashMenuItems.ts +98 -35
  190. package/src/extensions/TableHandles/TableHandlesPlugin.ts +617 -0
  191. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +3 -51
  192. package/src/extensions/TextColor/TextColorExtension.ts +1 -29
  193. package/src/extensions/TextColor/TextColorMark.ts +7 -27
  194. package/src/extensions/UniqueID/UniqueID.ts +28 -2
  195. package/src/extensions-shared/README.md +3 -0
  196. package/src/{shared/plugins → extensions-shared}/suggestion/SuggestionPlugin.ts +19 -13
  197. package/src/index.ts +21 -15
  198. package/src/{extensions/Blocks/nodes → pm-nodes}/BlockContainer.ts +161 -96
  199. package/src/pm-nodes/BlockGroup.ts +54 -0
  200. package/src/pm-nodes/Doc.ts +7 -0
  201. package/src/pm-nodes/README.md +42 -0
  202. package/src/pm-nodes/index.ts +3 -0
  203. package/src/schema/README.md +3 -0
  204. package/src/schema/blocks/createSpec.ts +220 -0
  205. package/src/schema/blocks/internal.ts +253 -0
  206. package/src/schema/blocks/types.ts +252 -0
  207. package/src/schema/index.ts +10 -0
  208. package/src/schema/inlineContent/createSpec.ts +119 -0
  209. package/src/schema/inlineContent/internal.ts +105 -0
  210. package/src/schema/inlineContent/types.ts +144 -0
  211. package/src/schema/propTypes.ts +32 -0
  212. package/src/schema/styles/createSpec.ts +85 -0
  213. package/src/schema/styles/internal.ts +96 -0
  214. package/src/schema/styles/types.ts +42 -0
  215. package/src/util/README.md +3 -0
  216. package/src/{shared/utils.ts → util/browser.ts} +4 -8
  217. package/src/util/string.ts +3 -0
  218. package/src/util/typescript.ts +5 -0
  219. package/types/src/BlockNoteEditor.d.ts +49 -36
  220. package/types/src/BlockNoteExtensions.d.ts +8 -3
  221. package/types/src/api/blockManipulation/blockManipulation.d.ts +5 -4
  222. package/types/src/api/exporters/copyExtension.d.ts +6 -0
  223. package/types/src/api/exporters/html/externalHTMLExporter.d.ts +8 -0
  224. package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +8 -0
  225. package/types/src/api/exporters/html/util/sharedHTMLConversion.d.ts +7 -0
  226. package/types/src/api/exporters/markdown/markdownExporter.d.ts +5 -0
  227. package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +1 -0
  228. package/types/src/api/getBlockInfoFromPos.d.ts +27 -0
  229. package/types/src/api/nodeConversions/nodeConversions.d.ts +14 -6
  230. package/types/src/api/nodeConversions/testUtil.d.ts +7 -2
  231. package/types/src/api/nodeUtil.d.ts +8 -0
  232. package/types/src/api/parsers/html/parseHTML.d.ts +3 -0
  233. package/types/src/api/parsers/html/parseHTML.test.d.ts +1 -0
  234. package/types/src/api/parsers/html/util/nestedLists.d.ts +1 -0
  235. package/types/src/api/parsers/html/util/nestedLists.test.d.ts +1 -0
  236. package/types/src/api/parsers/markdown/parseMarkdown.d.ts +3 -0
  237. package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +1 -0
  238. package/types/src/api/parsers/pasteExtension.d.ts +6 -0
  239. package/types/src/api/testCases/cases/customBlocks.d.ts +345 -0
  240. package/types/src/api/testCases/cases/customInlineContent.d.ts +29 -0
  241. package/types/src/api/testCases/cases/customStyles.d.ts +64 -0
  242. package/types/src/api/testCases/cases/defaultSchema.d.ts +3 -0
  243. package/types/src/api/testCases/index.d.ts +12 -0
  244. package/types/src/api/testUtil/cases/customBlocks.d.ts +345 -0
  245. package/types/src/api/testUtil/cases/customInlineContent.d.ts +29 -0
  246. package/types/src/api/testUtil/cases/customStyles.d.ts +64 -0
  247. package/types/src/api/testUtil/cases/defaultSchema.d.ts +3 -0
  248. package/types/src/api/testUtil/index.d.ts +12 -0
  249. package/types/src/api/testUtil/partialBlockTestUtil.d.ts +7 -0
  250. package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +58 -0
  251. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +93 -0
  252. package/types/src/blocks/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +1 -0
  253. package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +46 -0
  254. package/types/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +2 -0
  255. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +2 -0
  256. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +46 -0
  257. package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +52 -0
  258. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +53 -0
  259. package/types/src/blocks/TableBlockContent/TableExtension.d.ts +2 -0
  260. package/types/src/blocks/defaultBlockHelpers.d.ts +10 -0
  261. package/types/src/blocks/defaultBlocks.d.ts +577 -0
  262. package/types/src/blocks/defaultProps.d.ts +15 -0
  263. package/types/src/editor/BlockNoteEditor.d.ts +299 -0
  264. package/types/src/editor/BlockNoteEditor.test.d.ts +1 -0
  265. package/types/src/editor/BlockNoteExtensions.d.ts +24 -0
  266. package/types/src/editor/cursorPositionTypes.d.ts +6 -0
  267. package/types/src/editor/selectionTypes.d.ts +4 -0
  268. package/types/src/editor/transformPasted.d.ts +12 -0
  269. package/types/src/extensions/BackgroundColor/BackgroundColorExtension.d.ts +0 -7
  270. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +7 -9
  271. package/types/src/extensions/Blocks/api/blocks/createSpec.d.ts +35 -0
  272. package/types/src/extensions/Blocks/api/blocks/internal.d.ts +45 -0
  273. package/types/src/extensions/Blocks/api/blocks/types.d.ts +114 -0
  274. package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +7 -5
  275. package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +573 -113
  276. package/types/src/extensions/Blocks/api/defaultProps.d.ts +2 -1
  277. package/types/src/extensions/Blocks/api/inlineContent/createSpec.d.ts +21 -0
  278. package/types/src/extensions/Blocks/api/inlineContent/internal.d.ts +25 -0
  279. package/types/src/extensions/Blocks/api/inlineContent/types.d.ts +62 -0
  280. package/types/src/extensions/Blocks/api/selectionTypes.d.ts +5 -3
  281. package/types/src/extensions/Blocks/api/styles/createSpec.d.ts +13 -0
  282. package/types/src/extensions/Blocks/api/styles/internal.d.ts +22 -0
  283. package/types/src/extensions/Blocks/api/styles/types.d.ts +21 -0
  284. package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +8 -4
  285. package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +38 -23
  286. package/types/src/extensions/Blocks/nodes/BlockContent/ImageBlockContent/ImageBlockContent.d.ts +75 -17
  287. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +30 -19
  288. package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +30 -19
  289. package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +36 -28
  290. package/types/src/extensions/Blocks/nodes/BlockContent/TableBlockContent/TableBlockContent.d.ts +53 -0
  291. package/types/src/extensions/Blocks/nodes/BlockContent/TableBlockContent/TableExtension.d.ts +2 -0
  292. package/types/src/extensions/Blocks/nodes/BlockContent/defaultBlockHelpers.d.ts +12 -0
  293. package/types/src/extensions/Blocks/nodes/BlockGroup.d.ts +1 -1
  294. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +8 -6
  295. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +6 -6
  296. package/types/src/extensions/ImageToolbar/ImageToolbarPlugin.d.ts +11 -16
  297. package/types/src/extensions/NonEditableBlocks/NonEditableBlockPlugin.d.ts +2 -0
  298. package/types/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.d.ts +14 -0
  299. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +18 -11
  300. package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +5 -6
  301. package/types/src/extensions/SlashMenu/SlashMenuPlugin.d.ts +6 -6
  302. package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +2 -1
  303. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +74 -0
  304. package/types/src/extensions/TextAlignment/TextAlignmentExtension.d.ts +0 -7
  305. package/types/src/extensions/TextColor/TextColorExtension.d.ts +0 -7
  306. package/types/src/extensions/TextColor/TextColorMark.d.ts +7 -9
  307. package/types/src/extensions/UniqueID/UniqueID.d.ts +1 -1
  308. package/types/src/extensions-shared/BaseUiElementTypes.d.ts +7 -0
  309. package/types/src/extensions-shared/suggestion/SuggestionItem.d.ts +3 -0
  310. package/types/src/extensions-shared/suggestion/SuggestionPlugin.d.ts +36 -0
  311. package/types/src/index.d.ts +20 -15
  312. package/types/src/pm-nodes/BlockContainer.d.ts +28 -0
  313. package/types/src/pm-nodes/BlockGroup.d.ts +10 -0
  314. package/types/src/pm-nodes/Doc.d.ts +2 -0
  315. package/types/src/pm-nodes/index.d.ts +3 -0
  316. package/types/src/schema/blocks/createSpec.d.ts +35 -0
  317. package/types/src/schema/blocks/internal.d.ts +45 -0
  318. package/types/src/schema/blocks/types.d.ts +107 -0
  319. package/types/src/schema/index.d.ts +10 -0
  320. package/types/src/schema/inlineContent/createSpec.d.ts +21 -0
  321. package/types/src/schema/inlineContent/internal.d.ts +28 -0
  322. package/types/src/schema/inlineContent/types.d.ts +62 -0
  323. package/types/src/schema/propTypes.d.ts +8 -0
  324. package/types/src/schema/styles/createSpec.d.ts +13 -0
  325. package/types/src/schema/styles/internal.d.ts +22 -0
  326. package/types/src/schema/styles/types.d.ts +21 -0
  327. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +4 -2
  328. package/types/src/util/EventEmitter.d.ts +11 -0
  329. package/types/src/util/browser.d.ts +3 -0
  330. package/types/src/util/string.d.ts +1 -0
  331. package/types/src/util/typescript.d.ts +3 -0
  332. package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +0 -346
  333. package/src/api/formatConversions/formatConversions.test.ts +0 -753
  334. package/src/api/formatConversions/formatConversions.ts +0 -133
  335. package/src/api/nodeConversions/testUtil.ts +0 -65
  336. package/src/extensions/Blocks/api/block.ts +0 -307
  337. package/src/extensions/Blocks/api/blockTypes.ts +0 -249
  338. package/src/extensions/Blocks/api/cursorPositionTypes.ts +0 -7
  339. package/src/extensions/Blocks/api/defaultBlocks.ts +0 -16
  340. package/src/extensions/Blocks/api/defaultProps.ts +0 -16
  341. package/src/extensions/Blocks/api/inlineContentTypes.ts +0 -36
  342. package/src/extensions/Blocks/api/selectionTypes.ts +0 -5
  343. package/src/extensions/Blocks/api/serialization.ts +0 -29
  344. package/src/extensions/Blocks/helpers/findBlock.ts +0 -5
  345. package/src/extensions/Blocks/index.ts +0 -8
  346. package/src/extensions/Blocks/nodes/BlockAttributes.ts +0 -10
  347. package/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.ts +0 -142
  348. package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +0 -62
  349. package/src/extensions/Blocks/nodes/BlockGroup.ts +0 -53
  350. package/types/src/api/formatConversions/formatConversions.d.ts +0 -6
  351. package/types/src/extensions/Blocks/api/block.d.ts +0 -20
  352. package/types/src/extensions/Blocks/api/blockTypes.d.ts +0 -103
  353. package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +0 -30
  354. package/types/src/extensions/Blocks/api/serialization.d.ts +0 -2
  355. /package/src/{shared/EditorElement.ts → api/exporters/markdown/__snapshots__/hardbreak/only/markdown.md} +0 -0
  356. /package/src/api/{formatConversions → exporters/markdown}/removeUnderlinesRehypePlugin.ts +0 -0
  357. /package/src/{extensions/Blocks/helpers → api}/getBlockInfoFromPos.ts +0 -0
  358. /package/src/api/{util/nodeUtil.ts → nodeUtil.ts} +0 -0
  359. /package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
  360. /package/src/extensions/{Blocks → NonEditableBlocks}/NonEditableBlockPlugin.ts +0 -0
  361. /package/src/extensions/{Blocks → PreviousBlockType}/PreviousBlockTypePlugin.ts +0 -0
  362. /package/src/{shared → extensions-shared}/BaseUiElementTypes.ts +0 -0
  363. /package/src/{shared/plugins → extensions-shared}/suggestion/SuggestionItem.ts +0 -0
  364. /package/src/{shared → util}/EventEmitter.ts +0 -0
  365. /package/types/src/api/{formatConversions/formatConversions.test.d.ts → exporters/html/htmlConversion.test.d.ts} +0 -0
  366. /package/types/src/api/{formatConversions → exporters/html/util}/simplifyBlocksRehypePlugin.d.ts +0 -0
  367. /package/types/src/api/{formatConversions → exporters/markdown}/removeUnderlinesRehypePlugin.d.ts +0 -0
@@ -0,0 +1,85 @@
1
+ import { Mark } from "@tiptap/core";
2
+ import { ParseRule } from "@tiptap/pm/model";
3
+ import {
4
+ addStyleAttributes,
5
+ createInternalStyleSpec,
6
+ stylePropsToAttributes,
7
+ } from "./internal";
8
+ import { StyleConfig, StyleSpec } from "./types";
9
+ import {UnreachableCaseError} from "../../util/typescript";
10
+
11
+ export type CustomStyleImplementation<T extends StyleConfig> = {
12
+ render: T["propSchema"] extends "boolean"
13
+ ? () => {
14
+ dom: HTMLElement;
15
+ contentDOM?: HTMLElement;
16
+ }
17
+ : (value: string) => {
18
+ dom: HTMLElement;
19
+ contentDOM?: HTMLElement;
20
+ };
21
+ };
22
+
23
+ // TODO: support serialization
24
+
25
+ export function getStyleParseRules(config: StyleConfig): ParseRule[] {
26
+ return [
27
+ {
28
+ tag: `[data-style-type="${config.type}"]`,
29
+ contentElement: (element) => {
30
+ const htmlElement = element as HTMLElement;
31
+
32
+ if (htmlElement.matches("[data-editable]")) {
33
+ return htmlElement;
34
+ }
35
+
36
+ return htmlElement.querySelector("[data-editable]") || htmlElement;
37
+ },
38
+ },
39
+ ];
40
+ }
41
+
42
+ export function createStyleSpec<T extends StyleConfig>(
43
+ styleConfig: T,
44
+ styleImplementation: CustomStyleImplementation<T>
45
+ ): StyleSpec<T> {
46
+ const mark = Mark.create({
47
+ name: styleConfig.type,
48
+
49
+ addAttributes() {
50
+ return stylePropsToAttributes(styleConfig.propSchema);
51
+ },
52
+
53
+ parseHTML() {
54
+ return getStyleParseRules(styleConfig);
55
+ },
56
+
57
+ renderHTML({ mark }) {
58
+ let renderResult: {
59
+ dom: HTMLElement;
60
+ contentDOM?: HTMLElement;
61
+ };
62
+
63
+ if (styleConfig.propSchema === "boolean") {
64
+ // @ts-ignore not sure why this is complaining
65
+ renderResult = styleImplementation.render();
66
+ } else if (styleConfig.propSchema === "string") {
67
+ renderResult = styleImplementation.render(mark.attrs.stringValue);
68
+ } else {
69
+ throw new UnreachableCaseError(styleConfig.propSchema);
70
+ }
71
+
72
+ // const renderResult = styleImplementation.render();
73
+ return addStyleAttributes(
74
+ renderResult,
75
+ styleConfig.type,
76
+ mark.attrs.stringValue,
77
+ styleConfig.propSchema
78
+ );
79
+ },
80
+ });
81
+
82
+ return createInternalStyleSpec(styleConfig, {
83
+ mark,
84
+ });
85
+ }
@@ -0,0 +1,96 @@
1
+ import { Attributes, Mark } from "@tiptap/core";
2
+ import {
3
+ StyleConfig,
4
+ StyleImplementation,
5
+ StylePropSchema,
6
+ StyleSchemaFromSpecs,
7
+ StyleSpec,
8
+ StyleSpecs,
9
+ } from "./types";
10
+
11
+ export function stylePropsToAttributes(
12
+ propSchema: StylePropSchema
13
+ ): Attributes {
14
+ if (propSchema === "boolean") {
15
+ return {};
16
+ }
17
+ return {
18
+ stringValue: {
19
+ default: undefined,
20
+ keepOnSplit: true,
21
+ parseHTML: (element) => element.getAttribute("data-value"),
22
+ renderHTML: (attributes) =>
23
+ attributes.stringValue !== undefined
24
+ ? {
25
+ "data-value": attributes.stringValue,
26
+ }
27
+ : {},
28
+ },
29
+ };
30
+ }
31
+
32
+ // Function that adds necessary classes and attributes to the `dom` element
33
+ // returned from a custom style's 'render' function, to ensure no data is lost
34
+ // on internal copy & paste.
35
+ export function addStyleAttributes<
36
+ SType extends string,
37
+ PSchema extends StylePropSchema
38
+ >(
39
+ element: {
40
+ dom: HTMLElement;
41
+ contentDOM?: HTMLElement;
42
+ },
43
+ styleType: SType,
44
+ styleValue: PSchema extends "boolean" ? undefined : string,
45
+ propSchema: PSchema
46
+ ): {
47
+ dom: HTMLElement;
48
+ contentDOM?: HTMLElement;
49
+ } {
50
+ // Sets content type attribute
51
+ element.dom.setAttribute("data-style-type", styleType);
52
+ // Adds style value as an HTML attribute in kebab-case with "data-" prefix, if
53
+ // the style takes a string value.
54
+ if (propSchema === "string") {
55
+ element.dom.setAttribute("data-value", styleValue as string);
56
+ }
57
+
58
+ if (element.contentDOM !== undefined) {
59
+ element.contentDOM.setAttribute("data-editable", "");
60
+ }
61
+
62
+ return element;
63
+ }
64
+
65
+ // This helper function helps to instantiate a stylespec with a
66
+ // config and implementation that conform to the type of Config
67
+ export function createInternalStyleSpec<T extends StyleConfig>(
68
+ config: T,
69
+ implementation: StyleImplementation
70
+ ) {
71
+ return {
72
+ config,
73
+ implementation,
74
+ } satisfies StyleSpec<T>;
75
+ }
76
+
77
+ export function createStyleSpecFromTipTapMark<
78
+ T extends Mark,
79
+ P extends StylePropSchema
80
+ >(mark: T, propSchema: P) {
81
+ return createInternalStyleSpec(
82
+ {
83
+ type: mark.name as T["name"],
84
+ propSchema,
85
+ },
86
+ {
87
+ mark,
88
+ }
89
+ );
90
+ }
91
+
92
+ export function getStyleSchemaFromSpecs<T extends StyleSpecs>(specs: T) {
93
+ return Object.fromEntries(
94
+ Object.entries(specs).map(([key, value]) => [key, value.config])
95
+ ) as StyleSchemaFromSpecs<T>;
96
+ }
@@ -0,0 +1,42 @@
1
+ import { Mark } from "@tiptap/core";
2
+
3
+ export type StylePropSchema = "boolean" | "string"; // TODO: use PropSchema as name? Use objects as type similar to blocks?
4
+
5
+ // StyleConfig contains the "schema" info about a Style type
6
+ // i.e. what props it supports, what content it supports, etc.
7
+ export type StyleConfig = {
8
+ type: string;
9
+ readonly propSchema: StylePropSchema;
10
+ // content: "inline" | "none" | "table";
11
+ };
12
+
13
+ // StyleImplementation contains the "implementation" info about a Style element.
14
+ // Currently, the implementation is always a TipTap Mark
15
+ export type StyleImplementation = {
16
+ mark: Mark;
17
+ };
18
+
19
+ // Container for both the config and implementation of a Style,
20
+ // and the type of `implementation` is based on that of the config
21
+ export type StyleSpec<T extends StyleConfig> = {
22
+ config: T;
23
+ implementation: StyleImplementation;
24
+ };
25
+
26
+ // A Schema contains all the types (Configs) supported in an editor
27
+ // The keys are the "type" of Styles supported
28
+ export type StyleSchema = Record<string, StyleConfig>;
29
+
30
+ export type StyleSpecs = Record<string, StyleSpec<StyleConfig>>;
31
+
32
+ export type StyleSchemaFromSpecs<T extends StyleSpecs> = {
33
+ [K in keyof T]: T[K]["config"];
34
+ };
35
+
36
+ export type Styles<T extends StyleSchema> = {
37
+ [K in keyof T]?: T[K]["propSchema"] extends "boolean"
38
+ ? boolean
39
+ : T[K]["propSchema"] extends "string"
40
+ ? string
41
+ : never;
42
+ };
@@ -0,0 +1,3 @@
1
+ ### @blocknote/core/src/@util
2
+
3
+ Contains generic utility files with helper functions / classes.
@@ -1,7 +1,8 @@
1
1
  export const isAppleOS = () =>
2
- /Mac/.test(navigator.platform) ||
3
- (/AppleWebKit/.test(navigator.userAgent) &&
4
- /Mobile\/\w+/.test(navigator.userAgent));
2
+ typeof navigator !== "undefined" &&
3
+ (/Mac/.test(navigator.platform) ||
4
+ (/AppleWebKit/.test(navigator.userAgent) &&
5
+ /Mobile\/\w+/.test(navigator.userAgent)));
5
6
 
6
7
  export function formatKeyboardShortcut(shortcut: string) {
7
8
  if (isAppleOS()) {
@@ -15,8 +16,3 @@ export function mergeCSSClasses(...classes: string[]) {
15
16
  return classes.filter((c) => c).join(" ");
16
17
  }
17
18
 
18
- export class UnreachableCaseError extends Error {
19
- constructor(val: never) {
20
- super(`Unreachable case: ${val}`);
21
- }
22
- }
@@ -0,0 +1,3 @@
1
+ export function camelToDataKebab(str: string): string {
2
+ return "data-" + str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
3
+ }
@@ -0,0 +1,5 @@
1
+ export class UnreachableCaseError extends Error {
2
+ constructor(val: never) {
3
+ super(`Unreachable case: ${val}`);
4
+ }
5
+ }
@@ -2,18 +2,22 @@ import { EditorOptions } from "@tiptap/core";
2
2
  import { Node } from "prosemirror-model";
3
3
  import { Editor as TiptapEditor } from "@tiptap/core/dist/packages/core/src/Editor";
4
4
  import * as Y from "yjs";
5
- import { Block, BlockIdentifier, BlockNoteDOMAttributes, BlockSchema, PartialBlock } from "./extensions/Blocks/api/blockTypes";
6
- import { TextCursorPosition } from "./extensions/Blocks/api/cursorPositionTypes";
7
- import { DefaultBlockSchema } from "./extensions/Blocks/api/defaultBlocks";
8
- import { Styles } from "./extensions/Blocks/api/inlineContentTypes";
5
+ import { Block, BlockIdentifier, BlockNoteDOMAttributes, BlockSchema, BlockSchemaFromSpecs, BlockSchemaWithBlock, BlockSpecs, PartialBlock } from "./extensions/Blocks/api/blocks/types";
6
+ import { DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema, defaultBlockSpecs, defaultInlineContentSpecs, defaultStyleSpecs } from "./extensions/Blocks/api/defaultBlocks";
9
7
  import { Selection } from "./extensions/Blocks/api/selectionTypes";
8
+ import { StyleSchema, StyleSchemaFromSpecs, StyleSpecs, Styles } from "./extensions/Blocks/api/styles/types";
9
+ import "prosemirror-tables/style/tables.css";
10
+ import "./editor.css";
11
+ import { TextCursorPosition } from "./extensions/Blocks/api/cursorPositionTypes";
12
+ import { InlineContentSchema, InlineContentSchemaFromSpecs, InlineContentSpecs } from "./extensions/Blocks/api/inlineContent/types";
10
13
  import { FormattingToolbarProsemirrorPlugin } from "./extensions/FormattingToolbar/FormattingToolbarPlugin";
11
14
  import { HyperlinkToolbarProsemirrorPlugin } from "./extensions/HyperlinkToolbar/HyperlinkToolbarPlugin";
12
15
  import { ImageToolbarProsemirrorPlugin } from "./extensions/ImageToolbar/ImageToolbarPlugin";
13
16
  import { SideMenuProsemirrorPlugin } from "./extensions/SideMenu/SideMenuPlugin";
14
17
  import { BaseSlashMenuItem } from "./extensions/SlashMenu/BaseSlashMenuItem";
15
18
  import { SlashMenuProsemirrorPlugin } from "./extensions/SlashMenu/SlashMenuPlugin";
16
- export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
19
+ import { TableHandlesProsemirrorPlugin } from "./extensions/TableHandles/TableHandlesPlugin";
20
+ export type BlockNoteEditorOptions<BSpecs extends BlockSpecs, ISpecs extends InlineContentSpecs, SSpecs extends StyleSpecs> = {
17
21
  enableBlockNoteExtensions: boolean;
18
22
  /**
19
23
  *
@@ -21,7 +25,7 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
21
25
  *
22
26
  * @default defaultSlashMenuItems from `./extensions/SlashMenu`
23
27
  */
24
- slashMenuItems: BaseSlashMenuItem<any>[];
28
+ slashMenuItems: BaseSlashMenuItem<BlockSchemaFromSpecs<BSpecs>, InlineContentSchemaFromSpecs<ISpecs>, StyleSchemaFromSpecs<SSpecs>>[];
25
29
  /**
26
30
  * The HTML element that should be used as the parent element for the editor.
27
31
  *
@@ -37,15 +41,15 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
37
41
  /**
38
42
  * A callback function that runs when the editor is ready to be used.
39
43
  */
40
- onEditorReady: (editor: BlockNoteEditor<BSchema>) => void;
44
+ onEditorReady: (editor: BlockNoteEditor<BlockSchemaFromSpecs<BSpecs>, InlineContentSchemaFromSpecs<ISpecs>, StyleSchemaFromSpecs<SSpecs>>) => void;
41
45
  /**
42
46
  * A callback function that runs whenever the editor's contents change.
43
47
  */
44
- onEditorContentChange: (editor: BlockNoteEditor<BSchema>) => void;
48
+ onEditorContentChange: (editor: BlockNoteEditor<BlockSchemaFromSpecs<BSpecs>, InlineContentSchemaFromSpecs<ISpecs>, StyleSchemaFromSpecs<SSpecs>>) => void;
45
49
  /**
46
50
  * A callback function that runs whenever the text cursor position changes.
47
51
  */
48
- onTextCursorPositionChange: (editor: BlockNoteEditor<BSchema>) => void;
52
+ onTextCursorPositionChange: (editor: BlockNoteEditor<BlockSchemaFromSpecs<BSpecs>, InlineContentSchemaFromSpecs<ISpecs>, StyleSchemaFromSpecs<SSpecs>>) => void;
49
53
  /**
50
54
  * Locks the editor from being editable by the user if set to `false`.
51
55
  */
@@ -53,7 +57,7 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
53
57
  /**
54
58
  * The content that should be in the editor when it's created, represented as an array of partial block objects.
55
59
  */
56
- initialContent: PartialBlock<BSchema>[];
60
+ initialContent: PartialBlock<BlockSchemaFromSpecs<BSpecs>, InlineContentSchemaFromSpecs<ISpecs>, StyleSchemaFromSpecs<SSpecs>>[];
57
61
  /**
58
62
  * Use default BlockNote font and reset the styles of <p> <li> <h1> elements etc., that are used in BlockNote.
59
63
  *
@@ -63,7 +67,9 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
63
67
  /**
64
68
  * A list of block types that should be available in the editor.
65
69
  */
66
- blockSchema: BSchema;
70
+ blockSpecs: BSpecs;
71
+ styleSpecs: SSpecs;
72
+ inlineContentSpecs: ISpecs;
67
73
  /**
68
74
  * A custom function to handle file uploads.
69
75
  * @param file The file that should be uploaded.
@@ -96,21 +102,28 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
96
102
  };
97
103
  _tiptapOptions: Partial<EditorOptions>;
98
104
  };
99
- export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
105
+ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema> {
100
106
  private readonly options;
101
107
  readonly _tiptapEditor: TiptapEditor & {
102
108
  contentComponent: any;
103
109
  };
104
- blockCache: WeakMap<Node, Block<BSchema>>;
105
- readonly schema: BSchema;
110
+ blockCache: WeakMap<Node, Block<any, any, any>>;
111
+ readonly blockSchema: BSchema;
112
+ readonly inlineContentSchema: ISchema;
113
+ readonly styleSchema: SSchema;
114
+ readonly blockImplementations: BlockSpecs;
115
+ readonly inlineContentImplementations: InlineContentSpecs;
116
+ readonly styleImplementations: StyleSpecs;
106
117
  ready: boolean;
107
- readonly sideMenu: SideMenuProsemirrorPlugin<BSchema>;
108
- readonly formattingToolbar: FormattingToolbarProsemirrorPlugin<BSchema>;
109
- readonly slashMenu: SlashMenuProsemirrorPlugin<BSchema, any>;
110
- readonly hyperlinkToolbar: HyperlinkToolbarProsemirrorPlugin<BSchema>;
111
- readonly imageToolbar: ImageToolbarProsemirrorPlugin<BSchema>;
118
+ readonly sideMenu: SideMenuProsemirrorPlugin<BSchema, ISchema, SSchema>;
119
+ readonly formattingToolbar: FormattingToolbarProsemirrorPlugin;
120
+ readonly slashMenu: SlashMenuProsemirrorPlugin<BSchema, ISchema, SSchema, any>;
121
+ readonly hyperlinkToolbar: HyperlinkToolbarProsemirrorPlugin<BSchema, ISchema, SSchema>;
122
+ readonly imageToolbar: ImageToolbarProsemirrorPlugin<BSchema, ISchema, SSchema>;
123
+ readonly tableHandles: TableHandlesProsemirrorPlugin<BSchema extends BlockSchemaWithBlock<"table", DefaultBlockSchema["table"]> ? BSchema : any, ISchema, SSchema> | undefined;
112
124
  readonly uploadFile: ((file: File) => Promise<string>) | undefined;
113
- constructor(options?: Partial<BlockNoteEditorOptions<BSchema>>);
125
+ static create<BSpecs extends BlockSpecs = typeof defaultBlockSpecs, ISpecs extends InlineContentSpecs = typeof defaultInlineContentSpecs, SSpecs extends StyleSpecs = typeof defaultStyleSpecs>(options?: Partial<BlockNoteEditorOptions<BSpecs, ISpecs, SSpecs>>): BlockNoteEditor<BlockSchemaFromSpecs<BSpecs>, InlineContentSchemaFromSpecs<ISpecs>, StyleSchemaFromSpecs<SSpecs>>;
126
+ private constructor();
114
127
  get prosemirrorView(): import("prosemirror-view").EditorView;
115
128
  get domElement(): HTMLDivElement;
116
129
  isFocused(): boolean;
@@ -119,19 +132,19 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
119
132
  * Gets a snapshot of all top-level (non-nested) blocks in the editor.
120
133
  * @returns A snapshot of all top-level (non-nested) blocks in the editor.
121
134
  */
122
- get topLevelBlocks(): Block<BSchema>[];
135
+ get topLevelBlocks(): Block<BSchema, ISchema, SSchema>[];
123
136
  /**
124
137
  * Gets a snapshot of an existing block from the editor.
125
138
  * @param blockIdentifier The identifier of an existing block that should be retrieved.
126
139
  * @returns The block that matches the identifier, or `undefined` if no matching block was found.
127
140
  */
128
- getBlock(blockIdentifier: BlockIdentifier): Block<BSchema> | undefined;
141
+ getBlock(blockIdentifier: BlockIdentifier): Block<BSchema, ISchema, SSchema> | undefined;
129
142
  /**
130
143
  * Traverses all blocks in the editor depth-first, and executes a callback for each.
131
144
  * @param callback The callback to execute for each block. Returning `false` stops the traversal.
132
145
  * @param reverse Whether the blocks should be traversed in reverse order.
133
146
  */
134
- forEachBlock(callback: (block: Block<BSchema>) => boolean, reverse?: boolean): void;
147
+ forEachBlock(callback: (block: Block<BSchema, ISchema, SSchema>) => boolean, reverse?: boolean): void;
135
148
  /**
136
149
  * Executes a callback whenever the editor's contents change.
137
150
  * @param callback The callback to execute.
@@ -146,7 +159,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
146
159
  * Gets a snapshot of the current text cursor position.
147
160
  * @returns A snapshot of the current text cursor position.
148
161
  */
149
- getTextCursorPosition(): TextCursorPosition<BSchema>;
162
+ getTextCursorPosition(): TextCursorPosition<BSchema, ISchema, SSchema>;
150
163
  /**
151
164
  * Sets the text cursor position to the start or end of an existing block. Throws an error if the target block could
152
165
  * not be found.
@@ -157,7 +170,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
157
170
  /**
158
171
  * Gets a snapshot of the current selection.
159
172
  */
160
- getSelection(): Selection<BSchema> | undefined;
173
+ getSelection(): Selection<BSchema, ISchema, SSchema> | undefined;
161
174
  /**
162
175
  * Checks if the editor is currently editable, or if it's locked.
163
176
  * @returns True if the editor is editable, false otherwise.
@@ -176,7 +189,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
176
189
  * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
177
190
  * `referenceBlock`. Inserts the blocks at the start of the existing block's children if "nested" is used.
178
191
  */
179
- insertBlocks(blocksToInsert: PartialBlock<BSchema>[], referenceBlock: BlockIdentifier, placement?: "before" | "after" | "nested"): void;
192
+ insertBlocks(blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[], referenceBlock: BlockIdentifier, placement?: "before" | "after" | "nested"): void;
180
193
  /**
181
194
  * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
182
195
  * defined. These undefined fields are kept as-is from the existing block. Throws an error if the block to update could
@@ -184,7 +197,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
184
197
  * @param blockToUpdate The block that should be updated.
185
198
  * @param update A partial block which defines how the existing block should be changed.
186
199
  */
187
- updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema>): void;
200
+ updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema, ISchema, SSchema>): void;
188
201
  /**
189
202
  * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
190
203
  * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
@@ -197,26 +210,26 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
197
210
  * @param blocksToRemove An array of blocks that should be replaced.
198
211
  * @param blocksToInsert An array of partial blocks to replace the old ones with.
199
212
  */
200
- replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock<BSchema>[]): void;
213
+ replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[]): void;
201
214
  /**
202
215
  * Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
203
216
  */
204
- getActiveStyles(): Styles;
217
+ getActiveStyles(): Styles<SSchema>;
205
218
  /**
206
219
  * Adds styles to the currently selected content.
207
220
  * @param styles The styles to add.
208
221
  */
209
- addStyles(styles: Styles): void;
222
+ addStyles(styles: Styles<SSchema>): void;
210
223
  /**
211
224
  * Removes styles from the currently selected content.
212
225
  * @param styles The styles to remove.
213
226
  */
214
- removeStyles(styles: Styles): void;
227
+ removeStyles(styles: Styles<SSchema>): void;
215
228
  /**
216
229
  * Toggles styles on the currently selected content.
217
230
  * @param styles The styles to toggle.
218
231
  */
219
- toggleStyles(styles: Styles): void;
232
+ toggleStyles(styles: Styles<SSchema>): void;
220
233
  /**
221
234
  * Gets the currently selected text.
222
235
  */
@@ -253,7 +266,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
253
266
  * @param blocks An array of blocks that should be serialized into HTML.
254
267
  * @returns The blocks, serialized as an HTML string.
255
268
  */
256
- blocksToHTML(blocks: Block<BSchema>[]): Promise<string>;
269
+ blocksToHTMLLossy(blocks?: Block<BSchema, ISchema, SSchema>[]): Promise<string>;
257
270
  /**
258
271
  * Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
259
272
  * `InlineNode` objects from any HTML inline elements, though not all element types are recognized. If BlockNote
@@ -261,14 +274,14 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
261
274
  * @param html The HTML string to parse blocks from.
262
275
  * @returns The blocks parsed from the HTML string.
263
276
  */
264
- HTMLToBlocks(html: string): Promise<Block<BSchema>[]>;
277
+ tryParseHTMLToBlocks(html: string): Promise<Block<BSchema, ISchema, SSchema>[]>;
265
278
  /**
266
279
  * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
267
280
  * BlockNote - children of blocks which aren't list items are un-nested and certain styles are removed.
268
281
  * @param blocks An array of blocks that should be serialized into Markdown.
269
282
  * @returns The blocks, serialized as a Markdown string.
270
283
  */
271
- blocksToMarkdown(blocks: Block<BSchema>[]): Promise<string>;
284
+ blocksToMarkdownLossy(blocks?: Block<BSchema, ISchema, SSchema>[]): Promise<string>;
272
285
  /**
273
286
  * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
274
287
  * Markdown syntax, though not all symbols are recognized. If BlockNote doesn't recognize a symbol, it will parse it
@@ -276,7 +289,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
276
289
  * @param markdown The Markdown string to parse blocks from.
277
290
  * @returns The blocks parsed from the Markdown string.
278
291
  */
279
- markdownToBlocks(markdown: string): Promise<Block<BSchema>[]>;
292
+ tryParseMarkdownToBlocks(markdown: string): Promise<Block<BSchema, ISchema, SSchema>[]>;
280
293
  /**
281
294
  * Updates the user info for the current user that's shown to other collaborators.
282
295
  */
@@ -1,14 +1,19 @@
1
1
  import { Extensions } from "@tiptap/core";
2
2
  import { BlockNoteEditor } from "./BlockNoteEditor";
3
3
  import * as Y from "yjs";
4
- import { BlockNoteDOMAttributes } from "./extensions/Blocks/api/blockTypes";
4
+ import { BlockNoteDOMAttributes, BlockSpecs } from "./extensions/Blocks/api/blocks/types";
5
+ import { InlineContentSchema, InlineContentSpecs } from "./extensions/Blocks/api/inlineContent/types";
6
+ import { StyleSchema, StyleSpecs } from "./extensions/Blocks/api/styles/types";
5
7
  /**
6
8
  * Get all the Tiptap extensions BlockNote is configured with by default
7
9
  */
8
- export declare const getBlockNoteExtensions: <BSchema extends Record<string, import("./extensions/Blocks/api/blockTypes").BlockSpec<string, import("./extensions/Blocks/api/blockTypes").PropSchema, boolean>>>(opts: {
9
- editor: BlockNoteEditor<BSchema>;
10
+ export declare const getBlockNoteExtensions: <BSchema extends Record<string, import("./extensions/Blocks/api/blocks/types").BlockConfig>, I extends InlineContentSchema, S extends StyleSchema>(opts: {
11
+ editor: BlockNoteEditor<BSchema, I, S>;
10
12
  domAttributes: Partial<BlockNoteDOMAttributes>;
11
13
  blockSchema: BSchema;
14
+ blockSpecs: BlockSpecs;
15
+ inlineContentSpecs: InlineContentSpecs;
16
+ styleSpecs: StyleSpecs;
12
17
  collaboration?: {
13
18
  fragment: Y.XmlFragment;
14
19
  user: {
@@ -1,6 +1,7 @@
1
1
  import { Editor } from "@tiptap/core";
2
- import { BlockIdentifier, BlockSchema, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
3
- export declare function insertBlocks<BSchema extends BlockSchema>(blocksToInsert: PartialBlock<BSchema>[], referenceBlock: BlockIdentifier, placement: "before" | "after" | "nested" | undefined, editor: Editor): void;
4
- export declare function updateBlock<BSchema extends BlockSchema>(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema>, editor: Editor): void;
2
+ import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
3
+ import { BlockIdentifier, BlockSchema, InlineContentSchema, PartialBlock, StyleSchema } from "../../schema";
4
+ export declare function insertBlocks<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blocksToInsert: PartialBlock<BSchema, I, S>[], referenceBlock: BlockIdentifier, placement: "before" | "after" | "nested" | undefined, editor: BlockNoteEditor<BSchema, I, S>): void;
5
+ export declare function updateBlock<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema, I, S>, editor: Editor): void;
5
6
  export declare function removeBlocks(blocksToRemove: BlockIdentifier[], editor: Editor): void;
6
- export declare function replaceBlocks<BSchema extends BlockSchema>(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock<BSchema>[], editor: Editor): void;
7
+ export declare function replaceBlocks<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock<BSchema, I, S>[], editor: BlockNoteEditor<BSchema, I, S>): void;
@@ -0,0 +1,6 @@
1
+ import { Extension } from "@tiptap/core";
2
+ import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
3
+ import { InlineContentSchema, StyleSchema } from "../../schema";
4
+ export declare const createCopyToClipboardExtension: <BSchema extends Record<string, import("../../schema").BlockConfig>, I extends InlineContentSchema, S extends StyleSchema>(editor: BlockNoteEditor<BSchema, I, S>) => Extension<{
5
+ editor: BlockNoteEditor<BSchema, I, S>;
6
+ }, undefined>;
@@ -0,0 +1,8 @@
1
+ import { Fragment, Schema } from "prosemirror-model";
2
+ import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
3
+ import { BlockSchema, InlineContentSchema, PartialBlock, StyleSchema } from "../../../schema";
4
+ export interface ExternalHTMLExporter<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema> {
5
+ exportBlocks: (blocks: PartialBlock<BSchema, I, S>[]) => string;
6
+ exportProseMirrorFragment: (fragment: Fragment) => string;
7
+ }
8
+ export declare const createExternalHTMLExporter: <BSchema extends Record<string, import("../../../schema").BlockConfig>, I extends InlineContentSchema, S extends StyleSchema>(schema: Schema, editor: BlockNoteEditor<BSchema, I, S>) => ExternalHTMLExporter<BSchema, I, S>;
@@ -0,0 +1,8 @@
1
+ import { Fragment, Schema } from "prosemirror-model";
2
+ import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
3
+ import { BlockSchema, InlineContentSchema, PartialBlock, StyleSchema } from "../../../schema";
4
+ export interface InternalHTMLSerializer<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema> {
5
+ serializeProseMirrorFragment: (fragment: Fragment) => string;
6
+ serializeBlocks: (blocks: PartialBlock<BSchema, I, S>[]) => string;
7
+ }
8
+ export declare const createInternalHTMLSerializer: <BSchema extends Record<string, import("../../../schema").BlockConfig>, I extends InlineContentSchema, S extends StyleSchema>(schema: Schema, editor: BlockNoteEditor<BSchema, I, S>) => InternalHTMLSerializer<BSchema, I, S>;
@@ -0,0 +1,7 @@
1
+ import { DOMSerializer, Fragment, Node } from "prosemirror-model";
2
+ import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor";
3
+ import { InlineContentSchema, StyleSchema } from "../../../../schema";
4
+ export declare const serializeNodeInner: <BSchema extends Record<string, import("../../../../schema").BlockConfig>, I extends InlineContentSchema, S extends StyleSchema>(node: Node, options: {
5
+ document?: Document;
6
+ }, serializer: DOMSerializer, editor: BlockNoteEditor<BSchema, I, S>, toExternalHTML: boolean) => HTMLElement;
7
+ export declare const serializeProseMirrorFragment: (fragment: Fragment, serializer: DOMSerializer) => string;
@@ -0,0 +1,5 @@
1
+ import { Schema } from "prosemirror-model";
2
+ import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
3
+ import { Block, BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
4
+ export declare function cleanHTMLToMarkdown(cleanHTMLString: string): string;
5
+ export declare function blocksToMarkdown<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blocks: Block<BSchema, I, S>[], schema: Schema, editor: BlockNoteEditor<BSchema, I, S>): string;
@@ -0,0 +1,27 @@
1
+ import { Node, NodeType } from "prosemirror-model";
2
+ export type BlockInfoWithoutPositions = {
3
+ id: string;
4
+ node: Node;
5
+ contentNode: Node;
6
+ contentType: NodeType;
7
+ numChildBlocks: number;
8
+ };
9
+ export type BlockInfo = BlockInfoWithoutPositions & {
10
+ startPos: number;
11
+ endPos: number;
12
+ depth: number;
13
+ };
14
+ /**
15
+ * Helper function for `getBlockInfoFromPos`, returns information regarding
16
+ * provided blockContainer node.
17
+ * @param blockContainer The blockContainer node to retrieve info for.
18
+ */
19
+ export declare function getBlockInfo(blockContainer: Node): BlockInfoWithoutPositions;
20
+ /**
21
+ * Retrieves information regarding the nearest blockContainer node in a
22
+ * ProseMirror doc, relative to a position.
23
+ * @param doc The ProseMirror doc.
24
+ * @param pos An integer position.
25
+ * @returns A BlockInfo object for the nearest blockContainer node.
26
+ */
27
+ export declare function getBlockInfoFromPos(doc: Node, pos: number): BlockInfo;
@@ -1,15 +1,23 @@
1
- import { Node, Schema } from "prosemirror-model";
2
- import { Block, BlockSchema, PartialBlock } from "../../extensions/Blocks/api/blockTypes";
3
- import { PartialInlineContent } from "../../extensions/Blocks/api/inlineContentTypes";
1
+ import { Node, Schema } from "@tiptap/pm/model";
2
+ import type { Block, BlockSchema, InlineContent, InlineContentSchema, PartialBlock, PartialInlineContent, PartialTableContent, StyleSchema } from "../../schema";
4
3
  /**
5
4
  * converts an array of inline content elements to prosemirror nodes
6
5
  */
7
- export declare function inlineContentToNodes(blockContent: PartialInlineContent[], schema: Schema): Node[];
6
+ export declare function inlineContentToNodes<I extends InlineContentSchema, S extends StyleSchema>(blockContent: PartialInlineContent<I, S>, schema: Schema, styleSchema: S): Node[];
7
+ /**
8
+ * converts an array of inline content elements to prosemirror nodes
9
+ */
10
+ export declare function tableContentToNodes<I extends InlineContentSchema, S extends StyleSchema>(tableContent: PartialTableContent<I, S>, schema: Schema, styleSchema: StyleSchema): Node[];
8
11
  /**
9
12
  * Converts a BlockNote block to a TipTap node.
10
13
  */
11
- export declare function blockToNode<BSchema extends BlockSchema>(block: PartialBlock<BSchema>, schema: Schema): Node;
14
+ export declare function blockToNode(block: PartialBlock<any, any, any>, schema: Schema, styleSchema: StyleSchema): Node;
15
+ /**
16
+ * Converts an internal (prosemirror) content node to a BlockNote InlineContent array.
17
+ */
18
+ export declare function contentNodeToInlineContent<I extends InlineContentSchema, S extends StyleSchema>(contentNode: Node, inlineContentSchema: I, styleSchema: S): InlineContent<I, S>[];
19
+ export declare function nodeToCustomInlineContent<I extends InlineContentSchema, S extends StyleSchema>(node: Node, inlineContentSchema: I, styleSchema: S): InlineContent<I, S>;
12
20
  /**
13
21
  * Convert a TipTap node to a BlockNote block.
14
22
  */
15
- export declare function nodeToBlock<BSchema extends BlockSchema>(node: Node, blockSchema: BSchema, blockCache?: WeakMap<Node, Block<BSchema>>): Block<BSchema>;
23
+ export declare function nodeToBlock<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(node: Node, blockSchema: BSchema, inlineContentSchema: I, styleSchema: S, blockCache?: WeakMap<Node, Block<BSchema, I, S>>): Block<BSchema, I, S>;