@blocknote/core 0.15.11 → 0.17.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 (292) hide show
  1. package/dist/blocknote.js +3349 -2773
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +6 -6
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/webpack-stats.json +1 -1
  6. package/package.json +5 -2
  7. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +3087 -0
  8. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +132 -0
  9. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +71 -0
  10. package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +2276 -0
  11. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +131 -0
  12. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +103 -0
  13. package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +3767 -0
  14. package/src/api/blockManipulation/commands/moveBlock/moveBlock.test.ts +192 -0
  15. package/src/api/blockManipulation/commands/moveBlock/moveBlock.ts +178 -0
  16. package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +1136 -0
  17. package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.ts +34 -0
  18. package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts +100 -0
  19. package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +4931 -0
  20. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +222 -0
  21. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +70 -0
  22. package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +2924 -0
  23. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +136 -0
  24. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +48 -0
  25. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +8376 -0
  26. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +300 -0
  27. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +199 -0
  28. package/src/api/blockManipulation/insertContentAt.ts +96 -0
  29. package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +316 -0
  30. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +53 -0
  31. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +130 -0
  32. package/src/api/blockManipulation/setupTestEnv.ts +179 -0
  33. package/src/api/clipboard/__snapshots__/childToParent.html +1 -0
  34. package/src/api/clipboard/__snapshots__/childrenToNextParent.html +1 -0
  35. package/src/api/clipboard/__snapshots__/childrenToNextParentsChildren.html +1 -0
  36. package/src/api/clipboard/__snapshots__/image.html +1 -0
  37. package/src/api/clipboard/__snapshots__/multipleStyledText.html +1 -0
  38. package/src/api/clipboard/__snapshots__/nestedImage.html +1 -0
  39. package/src/api/clipboard/__snapshots__/partialChildToParent.html +1 -0
  40. package/src/api/clipboard/__snapshots__/styledText.html +1 -0
  41. package/src/api/clipboard/__snapshots__/tableAllCells.html +1 -0
  42. package/src/api/clipboard/__snapshots__/tableCell.html +1 -0
  43. package/src/api/clipboard/__snapshots__/tableCellText.html +1 -0
  44. package/src/api/clipboard/__snapshots__/tableRow.html +1 -0
  45. package/src/api/clipboard/__snapshots__/unstyledText.html +1 -0
  46. package/src/api/clipboard/clipboard.test.ts +283 -0
  47. package/src/api/{parsers → clipboard/fromClipboard}/fileDropExtension.ts +8 -4
  48. package/src/api/{parsers → clipboard/fromClipboard}/handleFileInsertion.ts +12 -7
  49. package/src/api/{parsers → clipboard/fromClipboard}/pasteExtension.ts +19 -8
  50. package/src/api/clipboard/toClipboard/copyExtension.ts +243 -0
  51. package/src/api/exporters/html/__snapshots__/complex/misc/external.html +1 -1
  52. package/src/api/exporters/html/__snapshots__/lists/basic/external.html +1 -1
  53. package/src/api/exporters/html/__snapshots__/lists/nested/external.html +1 -1
  54. package/src/api/exporters/html/externalHTMLExporter.ts +42 -87
  55. package/src/api/exporters/html/htmlConversion.test.ts +19 -156
  56. package/src/api/exporters/html/internalHTMLSerializer.ts +21 -69
  57. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +263 -0
  58. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +158 -0
  59. package/src/api/exporters/markdown/markdownExporter.test.ts +10 -10
  60. package/src/api/exporters/markdown/markdownExporter.ts +11 -7
  61. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +2 -2
  62. package/src/api/getBlockInfoFromPos.ts +172 -90
  63. package/src/api/nodeConversions/blockToNode.ts +257 -0
  64. package/src/api/nodeConversions/fragmentToBlocks.ts +60 -0
  65. package/src/api/nodeConversions/nodeConversions.test.ts +9 -8
  66. package/src/api/nodeConversions/{nodeConversions.ts → nodeToBlock.ts} +20 -262
  67. package/src/api/parsers/html/parseHTML.test.ts +5 -8
  68. package/src/api/parsers/html/parseHTML.ts +8 -4
  69. package/src/api/parsers/html/util/nestedLists.test.ts +2 -2
  70. package/src/api/parsers/markdown/__snapshots__/pasted/complex.json +319 -0
  71. package/src/api/parsers/markdown/__snapshots__/pasted/issue-226-1.json +81 -0
  72. package/src/api/parsers/{html/__snapshots__/paste/parse-deep-nested-content.json → markdown/__snapshots__/pasted/issue-226-2.json} +35 -110
  73. package/src/api/parsers/markdown/__snapshots__/pasted/nested.json +81 -0
  74. package/src/api/parsers/markdown/__snapshots__/pasted/non-nested.json +81 -0
  75. package/src/api/parsers/markdown/__snapshots__/pasted/styled.json +61 -0
  76. package/src/api/parsers/markdown/parseMarkdown.test.ts +16 -1
  77. package/src/api/parsers/markdown/parseMarkdown.ts +8 -4
  78. package/src/api/testUtil/cases/customBlocks.ts +11 -11
  79. package/src/api/testUtil/cases/customInlineContent.ts +6 -6
  80. package/src/api/testUtil/cases/customStyles.ts +6 -6
  81. package/src/api/testUtil/cases/defaultSchema.ts +4 -4
  82. package/src/api/testUtil/index.ts +6 -6
  83. package/src/api/testUtil/partialBlockTestUtil.ts +5 -5
  84. package/src/api/testUtil/paste.ts +46 -0
  85. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +5 -5
  86. package/src/blocks/FileBlockContent/FileBlockContent.ts +4 -4
  87. package/src/blocks/FileBlockContent/fileBlockHelpers.ts +2 -2
  88. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +61 -39
  89. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +5 -5
  90. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +30 -18
  91. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +67 -33
  92. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +23 -19
  93. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +22 -24
  94. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +31 -19
  95. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +16 -11
  96. package/src/blocks/TableBlockContent/TableBlockContent.ts +4 -5
  97. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +5 -5
  98. package/src/blocks/defaultBlockHelpers.ts +4 -4
  99. package/src/blocks/defaultBlockTypeGuards.ts +5 -5
  100. package/src/blocks/defaultBlocks.ts +13 -13
  101. package/src/blocks/defaultProps.ts +1 -1
  102. package/src/editor/BlockNoteEditor.test.ts +14 -7
  103. package/src/editor/BlockNoteEditor.ts +82 -149
  104. package/src/editor/BlockNoteExtensions.ts +15 -11
  105. package/src/editor/BlockNoteSchema.ts +7 -7
  106. package/src/editor/BlockNoteTipTapEditor.ts +5 -3
  107. package/src/editor/cursorPositionTypes.ts +7 -2
  108. package/src/editor/selectionTypes.ts +6 -2
  109. package/src/editor/transformPasted.ts +34 -2
  110. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -1
  111. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
  112. package/src/extensions/FilePanel/FilePanelPlugin.ts +4 -4
  113. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +8 -4
  114. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +333 -0
  115. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +9 -4
  116. package/src/extensions/{NonEditableBlocks/NonEditableBlockPlugin.ts → NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts} +2 -2
  117. package/src/extensions/Placeholder/PlaceholderPlugin.ts +1 -1
  118. package/src/extensions/SideMenu/SideMenuPlugin.ts +72 -402
  119. package/src/extensions/SideMenu/dragging.ts +251 -0
  120. package/src/extensions/SuggestionMenu/DefaultSuggestionItem.ts +1 -1
  121. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +8 -4
  122. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +8 -4
  123. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +19 -15
  124. package/src/extensions/TableHandles/TableHandlesPlugin.ts +11 -7
  125. package/src/extensions/TextColor/TextColorExtension.ts +1 -1
  126. package/src/extensions/TextColor/TextColorMark.ts +1 -1
  127. package/src/i18n/dictionary.ts +1 -1
  128. package/src/i18n/locales/ar.ts +1 -1
  129. package/src/i18n/locales/fr.ts +1 -1
  130. package/src/i18n/locales/hr.ts +308 -0
  131. package/src/i18n/locales/index.ts +15 -14
  132. package/src/i18n/locales/is.ts +1 -1
  133. package/src/i18n/locales/ja.ts +1 -1
  134. package/src/i18n/locales/ko.ts +1 -1
  135. package/src/i18n/locales/nl.ts +1 -1
  136. package/src/i18n/locales/pl.ts +1 -1
  137. package/src/i18n/locales/pt.ts +1 -1
  138. package/src/i18n/locales/ru.ts +1 -1
  139. package/src/i18n/locales/vi.ts +1 -1
  140. package/src/i18n/locales/zh.ts +1 -1
  141. package/src/index.ts +45 -44
  142. package/src/pm-nodes/BlockContainer.ts +3 -647
  143. package/src/pm-nodes/BlockGroup.ts +2 -2
  144. package/src/pm-nodes/index.ts +3 -3
  145. package/src/schema/blocks/createSpec.ts +24 -14
  146. package/src/schema/blocks/internal.ts +9 -9
  147. package/src/schema/blocks/types.ts +4 -4
  148. package/src/schema/index.ts +10 -10
  149. package/src/schema/inlineContent/createSpec.ts +9 -10
  150. package/src/schema/inlineContent/internal.ts +3 -3
  151. package/src/schema/inlineContent/types.ts +2 -2
  152. package/src/schema/styles/createSpec.ts +4 -3
  153. package/src/schema/styles/internal.ts +1 -1
  154. package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +4 -0
  155. package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +7 -0
  156. package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.d.ts +1 -0
  157. package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.d.ts +5 -0
  158. package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.test.d.ts +1 -0
  159. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +7 -0
  160. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
  161. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +7 -0
  162. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.d.ts +1 -0
  163. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +5 -0
  164. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.test.d.ts +1 -0
  165. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +11 -0
  166. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.test.d.ts +1 -0
  167. package/types/src/api/blockManipulation/insertContentAt.d.ts +6 -0
  168. package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.d.ts +5 -0
  169. package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.d.ts +1 -0
  170. package/types/src/api/blockManipulation/setupTestEnv.d.ts +492 -0
  171. package/types/src/api/clipboard/clipboard.test.d.ts +1 -0
  172. package/types/src/api/clipboard/fromClipboard/fileDropExtension.d.ts +6 -0
  173. package/types/src/api/{parsers → clipboard/fromClipboard}/handleFileInsertion.d.ts +2 -2
  174. package/types/src/api/clipboard/fromClipboard/pasteExtension.d.ts +6 -0
  175. package/types/src/api/clipboard/toClipboard/copyExtension.d.ts +12 -0
  176. package/types/src/api/exporters/html/externalHTMLExporter.d.ts +7 -8
  177. package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +6 -10
  178. package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +10 -0
  179. package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +11 -0
  180. package/types/src/api/exporters/markdown/markdownExporter.d.ts +3 -3
  181. package/types/src/api/getBlockInfoFromPos.d.ts +63 -20
  182. package/types/src/api/nodeConversions/blockToNode.d.ts +15 -0
  183. package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +7 -0
  184. package/types/src/api/nodeConversions/nodeToBlock.d.ts +16 -0
  185. package/types/src/api/parsers/html/parseHTML.d.ts +2 -2
  186. package/types/src/api/parsers/markdown/parseMarkdown.d.ts +2 -2
  187. package/types/src/api/testUtil/cases/customBlocks.d.ts +39 -39
  188. package/types/src/api/testUtil/cases/customInlineContent.d.ts +35 -35
  189. package/types/src/api/testUtil/cases/customStyles.d.ts +35 -35
  190. package/types/src/api/testUtil/cases/defaultSchema.d.ts +2 -2
  191. package/types/src/api/testUtil/index.d.ts +6 -6
  192. package/types/src/api/testUtil/partialBlockTestUtil.d.ts +4 -4
  193. package/types/src/api/testUtil/paste.d.ts +2 -0
  194. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +4 -4
  195. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +4 -4
  196. package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +2 -2
  197. package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +2 -2
  198. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +4 -4
  199. package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +2 -2
  200. package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +2 -2
  201. package/types/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +2 -2
  202. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +2 -2
  203. package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +2 -2
  204. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +2 -2
  205. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +4 -4
  206. package/types/src/blocks/defaultBlockHelpers.d.ts +3 -3
  207. package/types/src/blocks/defaultBlockTypeGuards.d.ts +4 -4
  208. package/types/src/blocks/defaultBlocks.d.ts +38 -38
  209. package/types/src/blocks/defaultProps.d.ts +1 -1
  210. package/types/src/editor/BlockNoteEditor.d.ts +28 -16
  211. package/types/src/editor/BlockNoteExtensions.d.ts +3 -3
  212. package/types/src/editor/BlockNoteSchema.d.ts +4 -4
  213. package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
  214. package/types/src/editor/cursorPositionTypes.d.ts +3 -2
  215. package/types/src/editor/selectionTypes.d.ts +2 -2
  216. package/types/src/editor/transformPasted.d.ts +8 -1
  217. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +1 -1
  218. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
  219. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +4 -4
  220. package/types/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +5 -0
  221. package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +4 -4
  222. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -0
  223. package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +1 -1
  224. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +12 -28
  225. package/types/src/extensions/SideMenu/dragging.d.ts +17 -0
  226. package/types/src/extensions/SuggestionMenu/DefaultSuggestionItem.d.ts +1 -1
  227. package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +4 -4
  228. package/types/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.d.ts +3 -3
  229. package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +4 -4
  230. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +4 -4
  231. package/types/src/extensions/TextColor/TextColorMark.d.ts +1 -1
  232. package/types/src/i18n/dictionary.d.ts +1 -1
  233. package/types/src/i18n/locales/ar.d.ts +1 -1
  234. package/types/src/i18n/locales/fr.d.ts +1 -1
  235. package/types/src/i18n/locales/hr.d.ts +239 -0
  236. package/types/src/i18n/locales/index.d.ts +15 -14
  237. package/types/src/i18n/locales/is.d.ts +1 -1
  238. package/types/src/i18n/locales/ja.d.ts +1 -1
  239. package/types/src/i18n/locales/ko.d.ts +1 -1
  240. package/types/src/i18n/locales/nl.d.ts +1 -1
  241. package/types/src/i18n/locales/pl.d.ts +1 -1
  242. package/types/src/i18n/locales/pt.d.ts +1 -1
  243. package/types/src/i18n/locales/ru.d.ts +1 -1
  244. package/types/src/i18n/locales/vi.d.ts +1 -1
  245. package/types/src/i18n/locales/zh.d.ts +1 -1
  246. package/types/src/index.d.ts +45 -44
  247. package/types/src/pm-nodes/BlockContainer.d.ts +2 -16
  248. package/types/src/pm-nodes/BlockGroup.d.ts +1 -1
  249. package/types/src/pm-nodes/index.d.ts +3 -3
  250. package/types/src/schema/blocks/createSpec.d.ts +5 -5
  251. package/types/src/schema/blocks/internal.d.ts +5 -5
  252. package/types/src/schema/blocks/types.d.ts +4 -4
  253. package/types/src/schema/index.d.ts +10 -10
  254. package/types/src/schema/inlineContent/createSpec.d.ts +3 -3
  255. package/types/src/schema/inlineContent/internal.d.ts +2 -2
  256. package/types/src/schema/inlineContent/types.d.ts +2 -2
  257. package/types/src/schema/styles/createSpec.d.ts +1 -1
  258. package/types/src/schema/styles/internal.d.ts +1 -1
  259. package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +0 -714
  260. package/src/api/blockManipulation/blockManipulation.test.ts +0 -292
  261. package/src/api/blockManipulation/blockManipulation.ts +0 -350
  262. package/src/api/exporters/copyExtension.ts +0 -164
  263. package/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionLeavesBlockChildren.html +0 -1
  264. package/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionSpansBlocksChildren.html +0 -1
  265. package/src/api/exporters/html/util/sharedHTMLConversion.ts +0 -130
  266. package/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts +0 -218
  267. package/src/api/getCurrentBlockContentType.ts +0 -14
  268. package/src/api/parsers/html/__snapshots__/paste/parse-google-docs-html.json +0 -476
  269. package/types/src/api/blockManipulation/blockManipulation.d.ts +0 -14
  270. package/types/src/api/exporters/copyExtension.d.ts +0 -6
  271. package/types/src/api/exporters/html/util/sharedHTMLConversion.d.ts +0 -9
  272. package/types/src/api/exporters/html/util/simplifyBlocksRehypePlugin.d.ts +0 -16
  273. package/types/src/api/getCurrentBlockContentType.d.ts +0 -2
  274. package/types/src/api/nodeConversions/nodeConversions.d.ts +0 -24
  275. package/types/src/api/parsers/fileDropExtension.d.ts +0 -6
  276. package/types/src/api/parsers/pasteExtension.d.ts +0 -6
  277. package/types/src/extensions/NonEditableBlocks/NonEditableBlockPlugin.d.ts +0 -2
  278. /package/src/api/{exporters/html/__snapshots_fragment_edge_cases__/selectionWithinBlockChildren.html → clipboard/__snapshots__/multipleChildren.html} +0 -0
  279. /package/src/api/{parsers → clipboard/fromClipboard}/acceptedMIMETypes.ts +0 -0
  280. /package/src/api/parsers/html/__snapshots__/{paste/list-test.json → list-test.json} +0 -0
  281. /package/src/api/parsers/html/__snapshots__/{paste/parse-basic-block-types.json → parse-basic-block-types.json} +0 -0
  282. /package/src/api/parsers/html/__snapshots__/{paste/parse-div-with-inline-content.json → parse-div-with-inline-content.json} +0 -0
  283. /package/src/api/parsers/html/__snapshots__/{paste/parse-divs.json → parse-divs.json} +0 -0
  284. /package/src/api/parsers/html/__snapshots__/{paste/parse-fake-image-caption.json → parse-fake-image-caption.json} +0 -0
  285. /package/src/api/parsers/html/__snapshots__/{paste/parse-image-in-paragraph.json → parse-image-in-paragraph.json} +0 -0
  286. /package/src/api/parsers/html/__snapshots__/{paste/parse-mixed-nested-lists.json → parse-mixed-nested-lists.json} +0 -0
  287. /package/src/api/parsers/html/__snapshots__/{paste/parse-nested-lists-with-paragraphs.json → parse-nested-lists-with-paragraphs.json} +0 -0
  288. /package/src/api/parsers/html/__snapshots__/{paste/parse-nested-lists.json → parse-nested-lists.json} +0 -0
  289. /package/src/api/parsers/html/__snapshots__/{paste/parse-notion-html.json → parse-notion-html.json} +0 -0
  290. /package/src/api/parsers/html/__snapshots__/{paste/parse-two-divs.json → parse-two-divs.json} +0 -0
  291. /package/types/src/api/blockManipulation/{blockManipulation.test.d.ts → commands/insertBlocks/insertBlocks.test.d.ts} +0 -0
  292. /package/types/src/api/{parsers → clipboard/fromClipboard}/acceptedMIMETypes.d.ts +0 -0
@@ -1,164 +0,0 @@
1
- import { Extension } from "@tiptap/core";
2
- import { Node } from "prosemirror-model";
3
- import { NodeSelection, Plugin } from "prosemirror-state";
4
-
5
- import { EditorView } from "prosemirror-view";
6
- import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
7
- import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema";
8
- import { initializeESMDependencies } from "../../util/esmDependencies";
9
- import { createExternalHTMLExporter } from "./html/externalHTMLExporter";
10
- import { createInternalHTMLSerializer } from "./html/internalHTMLSerializer";
11
- import { cleanHTMLToMarkdown } from "./markdown/markdownExporter";
12
-
13
- async function selectedFragmentToHTML<
14
- BSchema extends BlockSchema,
15
- I extends InlineContentSchema,
16
- S extends StyleSchema
17
- >(
18
- view: EditorView,
19
- editor: BlockNoteEditor<BSchema, I, S>
20
- ): Promise<{
21
- internalHTML: string;
22
- externalHTML: string;
23
- plainText: string;
24
- }> {
25
- const selectedFragment = view.state.selection.content().content;
26
-
27
- const internalHTMLSerializer = createInternalHTMLSerializer(
28
- view.state.schema,
29
- editor
30
- );
31
- const internalHTML = internalHTMLSerializer.serializeProseMirrorFragment(
32
- selectedFragment,
33
- {}
34
- );
35
-
36
- await initializeESMDependencies();
37
- const externalHTMLExporter = createExternalHTMLExporter(
38
- view.state.schema,
39
- editor
40
- );
41
- const externalHTML = externalHTMLExporter.exportProseMirrorFragment(
42
- selectedFragment,
43
- {}
44
- );
45
-
46
- const plainText = await cleanHTMLToMarkdown(externalHTML);
47
-
48
- return { internalHTML, externalHTML, plainText };
49
- }
50
-
51
- const copyToClipboard = <
52
- BSchema extends BlockSchema,
53
- I extends InlineContentSchema,
54
- S extends StyleSchema
55
- >(
56
- editor: BlockNoteEditor<BSchema, I, S>,
57
- view: EditorView,
58
- event: ClipboardEvent
59
- ) => {
60
- // Stops the default browser copy behaviour.
61
- event.preventDefault();
62
- event.clipboardData!.clearData();
63
-
64
- // Checks if a `blockContent` node is being copied and expands
65
- // the selection to the parent `blockContainer` node. This is
66
- // for the use-case in which only a block without content is
67
- // selected, e.g. an image block.
68
- if (
69
- "node" in view.state.selection &&
70
- (view.state.selection.node as Node).type.spec.group === "blockContent"
71
- ) {
72
- editor.dispatch(
73
- editor._tiptapEditor.state.tr.setSelection(
74
- new NodeSelection(view.state.doc.resolve(view.state.selection.from - 1))
75
- )
76
- );
77
- }
78
-
79
- (async () => {
80
- const { internalHTML, externalHTML, plainText } =
81
- await selectedFragmentToHTML(view, editor);
82
-
83
- // TODO: Writing to other MIME types not working in Safari for
84
- // some reason.
85
- event.clipboardData!.setData("blocknote/html", internalHTML);
86
- event.clipboardData!.setData("text/html", externalHTML);
87
- event.clipboardData!.setData("text/plain", plainText);
88
- })();
89
- };
90
-
91
- export const createCopyToClipboardExtension = <
92
- BSchema extends BlockSchema,
93
- I extends InlineContentSchema,
94
- S extends StyleSchema
95
- >(
96
- editor: BlockNoteEditor<BSchema, I, S>
97
- ) =>
98
- Extension.create<{ editor: BlockNoteEditor<BSchema, I, S> }, undefined>({
99
- name: "copyToClipboard",
100
- addProseMirrorPlugins() {
101
- return [
102
- new Plugin({
103
- props: {
104
- handleDOMEvents: {
105
- copy(view, event) {
106
- copyToClipboard(editor, view, event);
107
- // Prevent default PM handler to be called
108
- return true;
109
- },
110
- cut(view, event) {
111
- copyToClipboard(editor, view, event);
112
- view.dispatch(view.state.tr.deleteSelection());
113
- // Prevent default PM handler to be called
114
- return true;
115
- },
116
- // This is for the use-case in which only a block without content
117
- // is selected, e.g. an image block, and dragged (not using the
118
- // drag handle).
119
- dragstart(view, event) {
120
- // Checks if a `NodeSelection` is active.
121
- if (!("node" in view.state.selection)) {
122
- return;
123
- }
124
-
125
- // Checks if a `blockContent` node is being dragged.
126
- if (
127
- (view.state.selection.node as Node).type.spec.group !==
128
- "blockContent"
129
- ) {
130
- return;
131
- }
132
-
133
- // Expands the selection to the parent `blockContainer` node.
134
- editor.dispatch(
135
- editor._tiptapEditor.state.tr.setSelection(
136
- new NodeSelection(
137
- view.state.doc.resolve(view.state.selection.from - 1)
138
- )
139
- )
140
- );
141
-
142
- // Stops the default browser drag start behaviour.
143
- event.preventDefault();
144
- event.dataTransfer!.clearData();
145
-
146
- (async () => {
147
- const { internalHTML, externalHTML, plainText } =
148
- await selectedFragmentToHTML(view, editor);
149
-
150
- // TODO: Writing to other MIME types not working in Safari for
151
- // some reason.
152
- event.dataTransfer!.setData("blocknote/html", internalHTML);
153
- event.dataTransfer!.setData("text/html", externalHTML);
154
- event.dataTransfer!.setData("text/plain", plainText);
155
- })();
156
- // Prevent default PM handler to be called
157
- return true;
158
- },
159
- },
160
- },
161
- }),
162
- ];
163
- },
164
- });
@@ -1 +0,0 @@
1
- <p>Nested Paragraph 1</p><p>Nested Paragraph 2</p><p>Nested Paragraph 3</p><p>Paragraph 2</p>
@@ -1 +0,0 @@
1
- <p>Nested Paragraph 1</p><p>Nested Paragraph 2</p><p>Nested Paragraph 3</p><p>Paragraph 2</p><p>Nested Paragraph 1</p><p>Nested Paragraph 2</p><p>Nested Paragraph 3</p>
@@ -1,130 +0,0 @@
1
- import { DOMSerializer, Fragment, Node } from "prosemirror-model";
2
-
3
- import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor";
4
- import {
5
- BlockSchema,
6
- InlineContentSchema,
7
- StyleSchema,
8
- } from "../../../../schema";
9
- import { nodeToBlock } from "../../../nodeConversions/nodeConversions";
10
-
11
- function doc(options: { document?: Document }) {
12
- return options.document || window.document;
13
- }
14
-
15
- // Used to implement `serializeNodeInner` for the `internalHTMLSerializer` and
16
- // `externalHTMLExporter`. Changes how the content of `blockContainer` nodes is
17
- // serialized vs the default `DOMSerializer` implementation. For the
18
- // `blockContent` node, the `toInternalHTML` or `toExternalHTML` function of its
19
- // corresponding block is used for serialization instead of the node's
20
- // `renderHTML` method.
21
- export const serializeNodeInner = <
22
- BSchema extends BlockSchema,
23
- I extends InlineContentSchema,
24
- S extends StyleSchema
25
- >(
26
- node: Node,
27
- options: { document?: Document },
28
- serializer: DOMSerializer,
29
- editor: BlockNoteEditor<BSchema, I, S>,
30
- toExternalHTML: boolean
31
- ) => {
32
- if (!serializer.nodes[node.type.name]) {
33
- throw new Error("Serializer is missing a node type: " + node.type.name);
34
- }
35
-
36
- const { dom, contentDOM } = DOMSerializer.renderSpec(
37
- doc(options),
38
- serializer.nodes[node.type.name](node)
39
- );
40
-
41
- if (contentDOM) {
42
- if (node.isLeaf) {
43
- throw new RangeError("Content hole not allowed in a leaf node spec");
44
- }
45
-
46
- // Handles converting `blockContainer` nodes to HTML.
47
- if (node.type.name === "blockContainer") {
48
- const blockContentNode =
49
- node.childCount > 0 &&
50
- node.firstChild!.type.spec.group === "blockContent"
51
- ? node.firstChild!
52
- : undefined;
53
- const blockGroupNode =
54
- node.childCount > 0 && node.lastChild!.type.spec.group === "blockGroup"
55
- ? node.lastChild!
56
- : undefined;
57
-
58
- // Converts `blockContent` node using the custom `blockSpec`'s
59
- // `toExternalHTML` or `toInternalHTML` function.
60
- // Note: While `blockContainer` nodes should always contain a
61
- // `blockContent` node according to the schema, PM Fragments don't always
62
- // conform to the schema. This is unintuitive but important as it occurs
63
- // when copying only nested blocks.
64
- if (blockContentNode !== undefined) {
65
- const impl =
66
- editor.blockImplementations[blockContentNode.type.name]
67
- .implementation;
68
- const toHTML = toExternalHTML
69
- ? impl.toExternalHTML
70
- : impl.toInternalHTML;
71
- const blockContent = toHTML(
72
- nodeToBlock(
73
- node,
74
- editor.schema.blockSchema,
75
- editor.schema.inlineContentSchema,
76
- editor.schema.styleSchema,
77
- editor.blockCache
78
- ),
79
- editor as any
80
- );
81
-
82
- // Converts inline nodes in the `blockContent` node's content to HTML
83
- // using their `renderHTML` methods.
84
- if (blockContent.contentDOM !== undefined) {
85
- if (node.isLeaf) {
86
- throw new RangeError(
87
- "Content hole not allowed in a leaf node spec"
88
- );
89
- }
90
-
91
- blockContent.contentDOM.appendChild(
92
- serializer.serializeFragment(blockContentNode.content, options)
93
- );
94
- }
95
-
96
- contentDOM.appendChild(blockContent.dom);
97
- }
98
-
99
- // Converts `blockGroup` node to HTML using its `renderHTML` method.
100
- if (blockGroupNode !== undefined) {
101
- serializer.serializeFragment(
102
- Fragment.from(blockGroupNode),
103
- options,
104
- contentDOM
105
- );
106
- }
107
- } else {
108
- // Converts the node normally, i.e. using its `renderHTML method`.
109
- serializer.serializeFragment(node.content, options, contentDOM);
110
- }
111
- }
112
-
113
- return dom as HTMLElement;
114
- };
115
-
116
- // Used to implement `serializeProseMirrorFragment` for the
117
- // `internalHTMLSerializer` and `externalHTMLExporter`. Does basically the same
118
- // thing as `serializer.serializeFragment`, but takes fewer arguments and
119
- // returns a string instead, to make it easier to use.
120
- export const serializeProseMirrorFragment = (
121
- fragment: Fragment,
122
- serializer: DOMSerializer,
123
- options?: { document?: Document }
124
- ) => {
125
- const internalHTML = serializer.serializeFragment(fragment, options);
126
- const parent = document.createElement("div");
127
- parent.appendChild(internalHTML);
128
-
129
- return parent.innerHTML;
130
- };
@@ -1,218 +0,0 @@
1
- import { Element as HASTElement, Parent as HASTParent } from "hast";
2
- import { esmDependencies } from "../../../../util/esmDependencies";
3
-
4
- type SimplifyBlocksOptions = {
5
- orderedListItemBlockTypes: Set<string>;
6
- unorderedListItemBlockTypes: Set<string>;
7
- };
8
-
9
- function addAttributesAndRemoveClasses(
10
- element: HASTElement,
11
- attributes: Record<string, unknown>
12
- ) {
13
- // Removes all BlockNote specific class names.
14
- const className =
15
- ((element.properties?.className as string[]) || []).filter(
16
- (className) => !className.startsWith("bn-")
17
- ) || [];
18
- // Adds all block props as data attributes.
19
- element.properties = {
20
- ...element.properties,
21
- ...attributes,
22
- className: className.length > 0 ? className : undefined,
23
- };
24
- }
25
-
26
- /**
27
- * Rehype plugin which converts the HTML output string rendered by BlockNote into a simplified structure which better
28
- * follows HTML standards. It does several things:
29
- * - Removes all block related div elements, leaving only the actual content inside the block.
30
- * - Lifts nested blocks to a higher level for all block types that don't represent list items.
31
- * - Wraps blocks which represent list items in corresponding ul/ol HTML elements and restructures them to comply
32
- * with HTML list structure.
33
- * @param options Options for specifying which block types represent ordered and unordered list items.
34
- */
35
- export function simplifyBlocks(options: SimplifyBlocksOptions) {
36
- const deps = esmDependencies;
37
-
38
- if (!deps) {
39
- throw new Error(
40
- "simplifyBlocks requires ESM dependencies to be initialized"
41
- );
42
- }
43
-
44
- const listItemBlockTypes = new Set<string>([
45
- ...options.orderedListItemBlockTypes,
46
- ...options.unorderedListItemBlockTypes,
47
- ]);
48
-
49
- const simplifyBlocksHelper = (tree: HASTParent) => {
50
- // Checks whether blocks in the tree are wrapped by a parent `blockGroup`
51
- // element, in which case the `blockGroup`'s children are lifted out, and it
52
- // is removed.
53
- if (
54
- tree.children.length === 1 &&
55
- (tree.children[0] as HASTElement).properties?.["dataNodeType"] ===
56
- "blockGroup"
57
- ) {
58
- const blockGroup = tree.children[0] as HASTElement;
59
- tree.children.pop();
60
- tree.children.push(...blockGroup.children);
61
- }
62
-
63
- let numChildElements = tree.children.length;
64
- let activeList: HASTElement | undefined;
65
-
66
- for (let i = 0; i < numChildElements; i++) {
67
- const blockOuter = tree.children[i] as HASTElement;
68
- const blockContainer = blockOuter.children[0] as HASTElement;
69
- const blockContent = blockContainer.children.find((child) => {
70
- const properties = (child as HASTElement).properties;
71
- const classNames = properties?.["className"] as string[] | undefined;
72
-
73
- return classNames?.includes("bn-block-content");
74
- }) as HASTElement | undefined;
75
- const blockGroup = blockContainer.children.find((child) => {
76
- const properties = (child as HASTElement).properties;
77
- const classNames = properties?.["className"] as string[] | undefined;
78
-
79
- return classNames?.includes("bn-block-group");
80
- }) as HASTElement | undefined;
81
-
82
- // Saves the data attributes of the block container, excluding the block
83
- // ID and node type as we're removing the block structure. This means that
84
- // only attributes for the block's props are saved.
85
- const blockContainerDataAttributes = Object.fromEntries(
86
- Object.entries(blockContainer.properties || {}).filter(
87
- ([key]) =>
88
- key.startsWith("data") && key !== "dataId" && key !== "dataNodeType"
89
- )
90
- );
91
- // Saves the data attributes of the block content, excluding the block
92
- // content type as we're removing the block structure. This means that
93
- // only attributes for the block's props are saved.
94
- const blockContentDataAttributes = Object.fromEntries(
95
- Object.entries(blockContent?.properties || {}).filter(
96
- ([key]) =>
97
- key.startsWith("data") &&
98
- key !== "dataContentType" &&
99
- key !== "dataFileBlock" &&
100
- key !== "dataNodeViewWrapper" &&
101
- key !== "dataEditable"
102
- )
103
- );
104
- // All the block's props as data attributes.
105
- const blockPropsDataAttributes = {
106
- ...blockContainerDataAttributes,
107
- ...blockContentDataAttributes,
108
- };
109
-
110
- // When the selection starts in a nested block, the Fragment from it omits
111
- // the `blockContent` node of the parent `blockContainer` if it's not also
112
- // included in the selection. This is because ProseMirror preserves the
113
- // nesting hierarchy of the nested nodes, even if their ancestors aren't
114
- // fully selected. In this case, we just lift the child `blockContainer`
115
- // nodes up.
116
- // NOTE: This only happens for the first `blockContainer`, since to get to
117
- // any nested blocks later in the document, the selection must also
118
- // include their parents.
119
- if (!blockContent) {
120
- tree.children.splice(i, 1, ...blockGroup!.children);
121
- simplifyBlocksHelper(tree);
122
-
123
- return;
124
- }
125
-
126
- const isListItemBlock = listItemBlockTypes.has(
127
- blockContent.properties!["dataContentType"] as string
128
- );
129
-
130
- const listItemBlockType = isListItemBlock
131
- ? options.orderedListItemBlockTypes.has(
132
- blockContent.properties!["dataContentType"] as string
133
- )
134
- ? "ol"
135
- : "ul"
136
- : null;
137
-
138
- // Plugin runs recursively to process nested blocks.
139
- if (blockGroup) {
140
- simplifyBlocksHelper(blockGroup);
141
- }
142
-
143
- // Checks that there is an active list, but the block can't be added to it as it's of a different type.
144
- if (activeList && activeList.tagName !== listItemBlockType) {
145
- // Blocks that were copied into the list are removed and the list is inserted in their place.
146
- tree.children.splice(
147
- i - activeList.children.length,
148
- activeList.children.length,
149
- activeList
150
- );
151
-
152
- // Updates the current index and number of child elements.
153
- const numElementsRemoved = activeList.children.length - 1;
154
- i -= numElementsRemoved;
155
- numChildElements -= numElementsRemoved;
156
-
157
- activeList = undefined;
158
- }
159
-
160
- // Checks if the block represents a list item.
161
- if (isListItemBlock) {
162
- // Checks if a list isn't already active. We don't have to check if the block and the list are of the same
163
- // type as this was already done earlier.
164
- if (!activeList) {
165
- // Creates a new list element to represent an active list.
166
- activeList = deps.hastUtilFromDom.fromDom(
167
- document.createElement(listItemBlockType!)
168
- ) as HASTElement;
169
- }
170
-
171
- // Creates a new list item element to represent the block.
172
- const listItemElement = deps.hastUtilFromDom.fromDom(
173
- document.createElement("li")
174
- ) as HASTElement;
175
-
176
- // Adds only the content inside the block to the active list.
177
- listItemElement.children.push(...blockContent.children);
178
- // Nested blocks have already been processed in the recursive function call, so the resulting elements are
179
- // also added to the active list.
180
- if (blockGroup) {
181
- listItemElement.children.push(...blockGroup.children);
182
- }
183
-
184
- // Adds the list item representing the block to the active list.
185
- activeList.children.push(listItemElement);
186
- } else if (blockGroup) {
187
- // Lifts all children out of the current block, as only list items should allow nesting.
188
- tree.children.splice(i + 1, 0, ...blockGroup.children);
189
- // Replaces the block with only the content inside it.
190
- const content = blockContent.children[0] as HASTElement;
191
- addAttributesAndRemoveClasses(content, blockPropsDataAttributes);
192
- tree.children[i] = content;
193
-
194
- // Updates the current index and number of child elements.
195
- const numElementsAdded = blockGroup.children.length;
196
- i += numElementsAdded;
197
- numChildElements += numElementsAdded;
198
- } else {
199
- // Replaces the block with only the content inside it.
200
- const content = blockContent.children[0] as HASTElement;
201
- addAttributesAndRemoveClasses(content, blockPropsDataAttributes);
202
- tree.children[i] = content;
203
- }
204
- }
205
-
206
- // Since the active list is only inserted after encountering a block which can't be added to it, there are cases
207
- // where it remains un-inserted after processing all blocks, which are handled here.
208
- if (activeList) {
209
- tree.children.splice(
210
- numChildElements - activeList.children.length,
211
- activeList.children.length,
212
- activeList
213
- );
214
- }
215
- };
216
-
217
- return simplifyBlocksHelper;
218
- }
@@ -1,14 +0,0 @@
1
- import { Editor } from "@tiptap/core";
2
- import { getBlockInfoFromPos } from "./getBlockInfoFromPos";
3
-
4
- // Used to get the content type of the block that the text cursor is in. This is
5
- // a band-aid fix to prevent input rules and keyboard shortcuts from triggering
6
- // in tables, but really those should be extended to work with block selections.
7
- export const getCurrentBlockContentType = (editor: Editor) => {
8
- const { contentType } = getBlockInfoFromPos(
9
- editor.state.doc,
10
- editor.state.selection.from
11
- );
12
-
13
- return contentType.spec.content;
14
- };