@blocknote/core 0.16.0 → 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 (248) hide show
  1. package/dist/blocknote.js +3287 -2755
  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__/tableAllCells.html +1 -1
  34. package/src/api/clipboard/clipboard.test.ts +5 -6
  35. package/src/api/clipboard/fromClipboard/fileDropExtension.ts +8 -4
  36. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +11 -6
  37. package/src/api/clipboard/fromClipboard/pasteExtension.ts +8 -4
  38. package/src/api/clipboard/toClipboard/copyExtension.ts +113 -61
  39. package/src/api/exporters/html/__snapshots__/complex/misc/external.html +1 -1
  40. package/src/api/exporters/html/__snapshots__/lists/basic/external.html +1 -1
  41. package/src/api/exporters/html/__snapshots__/lists/nested/external.html +1 -1
  42. package/src/api/exporters/html/externalHTMLExporter.ts +42 -94
  43. package/src/api/exporters/html/htmlConversion.test.ts +19 -13
  44. package/src/api/exporters/html/internalHTMLSerializer.ts +21 -72
  45. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +263 -0
  46. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +158 -0
  47. package/src/api/exporters/markdown/markdownExporter.test.ts +10 -10
  48. package/src/api/exporters/markdown/markdownExporter.ts +11 -7
  49. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +2 -2
  50. package/src/api/getBlockInfoFromPos.ts +172 -90
  51. package/src/api/nodeConversions/blockToNode.ts +257 -0
  52. package/src/api/nodeConversions/fragmentToBlocks.ts +60 -0
  53. package/src/api/nodeConversions/nodeConversions.test.ts +9 -8
  54. package/src/api/nodeConversions/{nodeConversions.ts → nodeToBlock.ts} +20 -262
  55. package/src/api/parsers/html/parseHTML.test.ts +2 -2
  56. package/src/api/parsers/html/parseHTML.ts +8 -4
  57. package/src/api/parsers/html/util/nestedLists.test.ts +2 -2
  58. package/src/api/parsers/markdown/parseMarkdown.test.ts +2 -2
  59. package/src/api/parsers/markdown/parseMarkdown.ts +8 -4
  60. package/src/api/testUtil/cases/customBlocks.ts +11 -11
  61. package/src/api/testUtil/cases/customInlineContent.ts +6 -6
  62. package/src/api/testUtil/cases/customStyles.ts +6 -6
  63. package/src/api/testUtil/cases/defaultSchema.ts +4 -4
  64. package/src/api/testUtil/index.ts +6 -6
  65. package/src/api/testUtil/partialBlockTestUtil.ts +5 -5
  66. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +5 -5
  67. package/src/blocks/FileBlockContent/FileBlockContent.ts +4 -4
  68. package/src/blocks/FileBlockContent/fileBlockHelpers.ts +2 -2
  69. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +61 -39
  70. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +5 -5
  71. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +30 -18
  72. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +67 -33
  73. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +23 -19
  74. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +22 -24
  75. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +31 -19
  76. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +16 -11
  77. package/src/blocks/TableBlockContent/TableBlockContent.ts +4 -4
  78. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +5 -5
  79. package/src/blocks/defaultBlockHelpers.ts +4 -4
  80. package/src/blocks/defaultBlockTypeGuards.ts +5 -5
  81. package/src/blocks/defaultBlocks.ts +13 -13
  82. package/src/blocks/defaultProps.ts +1 -1
  83. package/src/editor/BlockNoteEditor.test.ts +14 -7
  84. package/src/editor/BlockNoteEditor.ts +82 -149
  85. package/src/editor/BlockNoteExtensions.ts +15 -11
  86. package/src/editor/BlockNoteSchema.ts +7 -7
  87. package/src/editor/BlockNoteTipTapEditor.ts +5 -3
  88. package/src/editor/cursorPositionTypes.ts +7 -2
  89. package/src/editor/selectionTypes.ts +6 -2
  90. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -1
  91. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
  92. package/src/extensions/FilePanel/FilePanelPlugin.ts +4 -4
  93. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +8 -4
  94. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +333 -0
  95. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +9 -4
  96. package/src/extensions/{NonEditableBlocks/NonEditableBlockPlugin.ts → NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts} +2 -2
  97. package/src/extensions/Placeholder/PlaceholderPlugin.ts +1 -1
  98. package/src/extensions/SideMenu/SideMenuPlugin.ts +72 -401
  99. package/src/extensions/SideMenu/dragging.ts +251 -0
  100. package/src/extensions/SuggestionMenu/DefaultSuggestionItem.ts +1 -1
  101. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +8 -4
  102. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +8 -4
  103. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +19 -15
  104. package/src/extensions/TableHandles/TableHandlesPlugin.ts +11 -7
  105. package/src/extensions/TextColor/TextColorExtension.ts +1 -1
  106. package/src/extensions/TextColor/TextColorMark.ts +1 -1
  107. package/src/i18n/dictionary.ts +1 -1
  108. package/src/i18n/locales/ar.ts +1 -1
  109. package/src/i18n/locales/fr.ts +1 -1
  110. package/src/i18n/locales/hr.ts +308 -0
  111. package/src/i18n/locales/index.ts +15 -14
  112. package/src/i18n/locales/is.ts +1 -1
  113. package/src/i18n/locales/ja.ts +1 -1
  114. package/src/i18n/locales/ko.ts +1 -1
  115. package/src/i18n/locales/nl.ts +1 -1
  116. package/src/i18n/locales/pl.ts +1 -1
  117. package/src/i18n/locales/pt.ts +1 -1
  118. package/src/i18n/locales/ru.ts +1 -1
  119. package/src/i18n/locales/vi.ts +1 -1
  120. package/src/i18n/locales/zh.ts +1 -1
  121. package/src/index.ts +45 -44
  122. package/src/pm-nodes/BlockContainer.ts +3 -647
  123. package/src/pm-nodes/BlockGroup.ts +2 -2
  124. package/src/pm-nodes/index.ts +3 -3
  125. package/src/schema/blocks/createSpec.ts +8 -7
  126. package/src/schema/blocks/internal.ts +9 -9
  127. package/src/schema/blocks/types.ts +4 -4
  128. package/src/schema/index.ts +10 -10
  129. package/src/schema/inlineContent/createSpec.ts +9 -10
  130. package/src/schema/inlineContent/internal.ts +3 -3
  131. package/src/schema/inlineContent/types.ts +2 -2
  132. package/src/schema/styles/createSpec.ts +4 -3
  133. package/src/schema/styles/internal.ts +1 -1
  134. package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +4 -0
  135. package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +7 -0
  136. package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.d.ts +1 -0
  137. package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.d.ts +5 -0
  138. package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.test.d.ts +1 -0
  139. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +7 -0
  140. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
  141. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +7 -0
  142. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.d.ts +1 -0
  143. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +5 -0
  144. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.test.d.ts +1 -0
  145. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +11 -0
  146. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.test.d.ts +1 -0
  147. package/types/src/api/blockManipulation/insertContentAt.d.ts +6 -0
  148. package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.d.ts +5 -0
  149. package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.d.ts +1 -0
  150. package/types/src/api/blockManipulation/setupTestEnv.d.ts +492 -0
  151. package/types/src/api/clipboard/fromClipboard/fileDropExtension.d.ts +3 -3
  152. package/types/src/api/clipboard/fromClipboard/handleFileInsertion.d.ts +1 -1
  153. package/types/src/api/clipboard/fromClipboard/pasteExtension.d.ts +2 -2
  154. package/types/src/api/clipboard/toClipboard/copyExtension.d.ts +5 -5
  155. package/types/src/api/exporters/html/externalHTMLExporter.d.ts +7 -9
  156. package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +6 -10
  157. package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +10 -0
  158. package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +11 -0
  159. package/types/src/api/exporters/markdown/markdownExporter.d.ts +3 -3
  160. package/types/src/api/getBlockInfoFromPos.d.ts +63 -20
  161. package/types/src/api/nodeConversions/blockToNode.d.ts +15 -0
  162. package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +7 -0
  163. package/types/src/api/nodeConversions/nodeToBlock.d.ts +16 -0
  164. package/types/src/api/parsers/html/parseHTML.d.ts +2 -2
  165. package/types/src/api/parsers/markdown/parseMarkdown.d.ts +2 -2
  166. package/types/src/api/testUtil/cases/customBlocks.d.ts +39 -39
  167. package/types/src/api/testUtil/cases/customInlineContent.d.ts +35 -35
  168. package/types/src/api/testUtil/cases/customStyles.d.ts +35 -35
  169. package/types/src/api/testUtil/cases/defaultSchema.d.ts +2 -2
  170. package/types/src/api/testUtil/index.d.ts +6 -6
  171. package/types/src/api/testUtil/partialBlockTestUtil.d.ts +4 -4
  172. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +4 -4
  173. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +4 -4
  174. package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +2 -2
  175. package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +2 -2
  176. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +4 -4
  177. package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +2 -2
  178. package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +2 -2
  179. package/types/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +2 -2
  180. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +2 -2
  181. package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +2 -2
  182. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +2 -2
  183. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +4 -4
  184. package/types/src/blocks/defaultBlockHelpers.d.ts +3 -3
  185. package/types/src/blocks/defaultBlockTypeGuards.d.ts +4 -4
  186. package/types/src/blocks/defaultBlocks.d.ts +38 -38
  187. package/types/src/blocks/defaultProps.d.ts +1 -1
  188. package/types/src/editor/BlockNoteEditor.d.ts +28 -16
  189. package/types/src/editor/BlockNoteExtensions.d.ts +3 -3
  190. package/types/src/editor/BlockNoteSchema.d.ts +4 -4
  191. package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
  192. package/types/src/editor/cursorPositionTypes.d.ts +3 -2
  193. package/types/src/editor/selectionTypes.d.ts +2 -2
  194. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +1 -1
  195. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
  196. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +4 -4
  197. package/types/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +5 -0
  198. package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +4 -4
  199. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -0
  200. package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +1 -1
  201. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +12 -28
  202. package/types/src/extensions/SideMenu/dragging.d.ts +17 -0
  203. package/types/src/extensions/SuggestionMenu/DefaultSuggestionItem.d.ts +1 -1
  204. package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +4 -4
  205. package/types/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.d.ts +3 -3
  206. package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +4 -4
  207. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +4 -4
  208. package/types/src/extensions/TextColor/TextColorMark.d.ts +1 -1
  209. package/types/src/i18n/dictionary.d.ts +1 -1
  210. package/types/src/i18n/locales/ar.d.ts +1 -1
  211. package/types/src/i18n/locales/fr.d.ts +1 -1
  212. package/types/src/i18n/locales/hr.d.ts +239 -0
  213. package/types/src/i18n/locales/index.d.ts +15 -14
  214. package/types/src/i18n/locales/is.d.ts +1 -1
  215. package/types/src/i18n/locales/ja.d.ts +1 -1
  216. package/types/src/i18n/locales/ko.d.ts +1 -1
  217. package/types/src/i18n/locales/nl.d.ts +1 -1
  218. package/types/src/i18n/locales/pl.d.ts +1 -1
  219. package/types/src/i18n/locales/pt.d.ts +1 -1
  220. package/types/src/i18n/locales/ru.d.ts +1 -1
  221. package/types/src/i18n/locales/vi.d.ts +1 -1
  222. package/types/src/i18n/locales/zh.d.ts +1 -1
  223. package/types/src/index.d.ts +45 -44
  224. package/types/src/pm-nodes/BlockContainer.d.ts +2 -16
  225. package/types/src/pm-nodes/BlockGroup.d.ts +1 -1
  226. package/types/src/pm-nodes/index.d.ts +3 -3
  227. package/types/src/schema/blocks/createSpec.d.ts +5 -5
  228. package/types/src/schema/blocks/internal.d.ts +5 -5
  229. package/types/src/schema/blocks/types.d.ts +4 -4
  230. package/types/src/schema/index.d.ts +10 -10
  231. package/types/src/schema/inlineContent/createSpec.d.ts +3 -3
  232. package/types/src/schema/inlineContent/internal.d.ts +2 -2
  233. package/types/src/schema/inlineContent/types.d.ts +2 -2
  234. package/types/src/schema/styles/createSpec.d.ts +1 -1
  235. package/types/src/schema/styles/internal.d.ts +1 -1
  236. package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +0 -714
  237. package/src/api/blockManipulation/blockManipulation.test.ts +0 -292
  238. package/src/api/blockManipulation/blockManipulation.ts +0 -350
  239. package/src/api/exporters/html/util/sharedHTMLConversion.ts +0 -130
  240. package/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts +0 -218
  241. package/src/api/getCurrentBlockContentType.ts +0 -14
  242. package/types/src/api/blockManipulation/blockManipulation.d.ts +0 -14
  243. package/types/src/api/exporters/html/util/sharedHTMLConversion.d.ts +0 -9
  244. package/types/src/api/exporters/html/util/simplifyBlocksRehypePlugin.d.ts +0 -16
  245. package/types/src/api/getCurrentBlockContentType.d.ts +0 -2
  246. package/types/src/api/nodeConversions/nodeConversions.d.ts +0 -24
  247. package/types/src/extensions/NonEditableBlocks/NonEditableBlockPlugin.d.ts +0 -2
  248. /package/types/src/api/blockManipulation/{blockManipulation.test.d.ts → commands/insertBlocks/insertBlocks.test.d.ts} +0 -0
@@ -1,10 +1,14 @@
1
1
  import { Extension } from "@tiptap/core";
2
2
  import { Plugin } from "prosemirror-state";
3
3
 
4
- import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
5
- import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
6
- import { handleFileInsertion } from "./handleFileInsertion";
7
- import { acceptedMIMETypes } from "./acceptedMIMETypes";
4
+ import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
5
+ import {
6
+ BlockSchema,
7
+ InlineContentSchema,
8
+ StyleSchema,
9
+ } from "../../../schema/index.js";
10
+ import { acceptedMIMETypes } from "./acceptedMIMETypes.js";
11
+ import { handleFileInsertion } from "./handleFileInsertion.js";
8
12
 
9
13
  export const createDropFileExtension = <
10
14
  BSchema extends BlockSchema,
@@ -1,13 +1,16 @@
1
+ import { PartialBlock } from "../../../blocks/defaultBlocks.js";
1
2
  import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
2
- import { PartialBlock } from "../../../blocks/defaultBlocks";
3
3
  import {
4
4
  BlockSchema,
5
5
  FileBlockConfig,
6
6
  InlineContentSchema,
7
7
  StyleSchema,
8
- } from "../../../schema";
9
- import { getBlockInfoFromPos } from "../../getBlockInfoFromPos";
10
- import { acceptedMIMETypes } from "./acceptedMIMETypes";
8
+ } from "../../../schema/index.js";
9
+ import {
10
+ getBlockInfo,
11
+ getNearestBlockContainerPos,
12
+ } from "../../getBlockInfoFromPos.js";
13
+ import { acceptedMIMETypes } from "./acceptedMIMETypes.js";
11
14
 
12
15
  function checkFileExtensionsMatch(
13
16
  fileExtension1: string,
@@ -132,14 +135,16 @@ export async function handleFileInsertion<
132
135
  return;
133
136
  }
134
137
 
135
- const blockInfo = getBlockInfoFromPos(
138
+ const posInfo = getNearestBlockContainerPos(
136
139
  editor._tiptapEditor.state.doc,
137
140
  pos.pos
138
141
  );
139
142
 
143
+ const blockInfo = getBlockInfo(posInfo);
144
+
140
145
  insertedBlockId = editor.insertBlocks(
141
146
  [fileBlock],
142
- blockInfo.id,
147
+ blockInfo.blockContainer.node.attrs.id,
143
148
  "after"
144
149
  )[0].id;
145
150
  } else {
@@ -2,10 +2,14 @@ import { Extension } from "@tiptap/core";
2
2
  import { Plugin } from "prosemirror-state";
3
3
 
4
4
  import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
5
- import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
6
- import { nestedListsToBlockNoteStructure } from "../../parsers/html/util/nestedLists";
7
- import { acceptedMIMETypes } from "./acceptedMIMETypes";
8
- import { handleFileInsertion } from "./handleFileInsertion";
5
+ import {
6
+ BlockSchema,
7
+ InlineContentSchema,
8
+ StyleSchema,
9
+ } from "../../../schema/index.js";
10
+ import { nestedListsToBlockNoteStructure } from "../../parsers/html/util/nestedLists.js";
11
+ import { acceptedMIMETypes } from "./acceptedMIMETypes.js";
12
+ import { handleFileInsertion } from "./handleFileInsertion.js";
9
13
 
10
14
  export const createPasteFromClipboardExtension = <
11
15
  BSchema extends BlockSchema,
@@ -1,57 +1,40 @@
1
1
  import { Extension } from "@tiptap/core";
2
- import { Node } from "prosemirror-model";
2
+ import { Fragment, Node } from "prosemirror-model";
3
3
  import { NodeSelection, Plugin } from "prosemirror-state";
4
4
  import { CellSelection } from "prosemirror-tables";
5
5
  import * as pmView from "prosemirror-view";
6
6
 
7
7
  import { EditorView } from "prosemirror-view";
8
- import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
9
- import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
10
- import { initializeESMDependencies } from "../../../util/esmDependencies";
11
- import { createExternalHTMLExporter } from "../../exporters/html/externalHTMLExporter";
12
- import { cleanHTMLToMarkdown } from "../../exporters/markdown/markdownExporter";
13
-
14
- export async function selectedFragmentToHTML<
8
+ import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
9
+ import {
10
+ BlockSchema,
11
+ InlineContentSchema,
12
+ StyleSchema,
13
+ } from "../../../schema/index.js";
14
+ import { createExternalHTMLExporter } from "../../exporters/html/externalHTMLExporter.js";
15
+ import { cleanHTMLToMarkdown } from "../../exporters/markdown/markdownExporter.js";
16
+ import { fragmentToBlocks } from "../../nodeConversions/fragmentToBlocks.js";
17
+ import {
18
+ contentNodeToInlineContent,
19
+ contentNodeToTableContent,
20
+ } from "../../nodeConversions/nodeToBlock.js";
21
+
22
+ function fragmentToExternalHTML<
15
23
  BSchema extends BlockSchema,
16
24
  I extends InlineContentSchema,
17
25
  S extends StyleSchema
18
26
  >(
19
- view: EditorView,
27
+ view: pmView.EditorView,
28
+ selectedFragment: Fragment,
20
29
  editor: BlockNoteEditor<BSchema, I, S>
21
- ): Promise<{
22
- clipboardHTML: string;
23
- externalHTML: string;
24
- markdown: string;
25
- }> {
26
- // Checks if a `blockContent` node is being copied and expands
27
- // the selection to the parent `blockContainer` node. This is
28
- // for the use-case in which only a block without content is
29
- // selected, e.g. an image block.
30
- if (
31
- "node" in view.state.selection &&
32
- (view.state.selection.node as Node).type.spec.group === "blockContent"
33
- ) {
34
- editor.dispatch(
35
- editor._tiptapEditor.state.tr.setSelection(
36
- new NodeSelection(view.state.doc.resolve(view.state.selection.from - 1))
37
- )
38
- );
39
- }
40
-
41
- // Uses default ProseMirror clipboard serialization.
42
- const clipboardHTML: string = (pmView as any).__serializeForClipboard(
43
- view,
44
- view.state.selection.content()
45
- ).dom.innerHTML;
46
-
47
- let selectedFragment = view.state.selection.content().content;
48
-
49
- // Checks whether block ancestry should be included when creating external
50
- // HTML. If the selection is within a block content node, the block ancestry
51
- // is excluded as we only care about the inline content.
30
+ ) {
52
31
  let isWithinBlockContent = false;
53
32
  const isWithinTable = view.state.selection instanceof CellSelection;
33
+
54
34
  if (!isWithinTable) {
35
+ // Checks whether block ancestry should be included when creating external
36
+ // HTML. If the selection is within a block content node, the block ancestry
37
+ // is excluded as we only care about the inline content.
55
38
  const fragmentWithoutParents = view.state.doc.slice(
56
39
  view.state.selection.from,
57
40
  view.state.selection.to,
@@ -75,14 +58,84 @@ export async function selectedFragmentToHTML<
75
58
  }
76
59
  }
77
60
 
78
- await initializeESMDependencies();
61
+ let externalHTML: string;
62
+
79
63
  const externalHTMLExporter = createExternalHTMLExporter(
80
64
  view.state.schema,
81
65
  editor
82
66
  );
83
- const externalHTML = externalHTMLExporter.exportProseMirrorFragment(
67
+
68
+ if (isWithinTable) {
69
+ if (selectedFragment.firstChild?.type.name === "table") {
70
+ // contentNodeToTableContent expects the fragment of the content of a table, not the table node itself
71
+ // but cellselection.content() returns the table node itself if all cells and columns are selected
72
+ selectedFragment = selectedFragment.firstChild.content;
73
+ }
74
+
75
+ // first convert selection to blocknote-style table content, and then
76
+ // pass this to the exporter
77
+ const ic = contentNodeToTableContent(
78
+ selectedFragment as any,
79
+ editor.schema.inlineContentSchema,
80
+ editor.schema.styleSchema
81
+ );
82
+
83
+ externalHTML = externalHTMLExporter.exportInlineContent(ic as any, {});
84
+ } else if (isWithinBlockContent) {
85
+ // first convert selection to blocknote-style inline content, and then
86
+ // pass this to the exporter
87
+ const ic = contentNodeToInlineContent(
88
+ selectedFragment as any,
89
+ editor.schema.inlineContentSchema,
90
+ editor.schema.styleSchema
91
+ );
92
+ externalHTML = externalHTMLExporter.exportInlineContent(ic, {});
93
+ } else {
94
+ const blocks = fragmentToBlocks(selectedFragment, editor.schema);
95
+ externalHTML = externalHTMLExporter.exportBlocks(blocks, {});
96
+ }
97
+ return externalHTML;
98
+ }
99
+
100
+ export function selectedFragmentToHTML<
101
+ BSchema extends BlockSchema,
102
+ I extends InlineContentSchema,
103
+ S extends StyleSchema
104
+ >(
105
+ view: EditorView,
106
+ editor: BlockNoteEditor<BSchema, I, S>
107
+ ): {
108
+ clipboardHTML: string;
109
+ externalHTML: string;
110
+ markdown: string;
111
+ } {
112
+ // Checks if a `blockContent` node is being copied and expands
113
+ // the selection to the parent `blockContainer` node. This is
114
+ // for the use-case in which only a block without content is
115
+ // selected, e.g. an image block.
116
+ if (
117
+ "node" in view.state.selection &&
118
+ (view.state.selection.node as Node).type.spec.group === "blockContent"
119
+ ) {
120
+ editor.dispatch(
121
+ editor._tiptapEditor.state.tr.setSelection(
122
+ new NodeSelection(view.state.doc.resolve(view.state.selection.from - 1))
123
+ )
124
+ );
125
+ }
126
+
127
+ // Uses default ProseMirror clipboard serialization.
128
+ const clipboardHTML: string = (pmView as any).__serializeForClipboard(
129
+ view,
130
+ view.state.selection.content()
131
+ ).dom.innerHTML;
132
+
133
+ const selectedFragment = view.state.selection.content().content;
134
+
135
+ const externalHTML = fragmentToExternalHTML<BSchema, I, S>(
136
+ view,
84
137
  selectedFragment,
85
- { simplifyBlocks: !isWithinBlockContent && !isWithinTable }
138
+ editor
86
139
  );
87
140
 
88
141
  const markdown = cleanHTMLToMarkdown(externalHTML);
@@ -103,16 +156,16 @@ const copyToClipboard = <
103
156
  event.preventDefault();
104
157
  event.clipboardData!.clearData();
105
158
 
106
- (async () => {
107
- const { clipboardHTML, externalHTML, markdown } =
108
- await selectedFragmentToHTML(view, editor);
159
+ const { clipboardHTML, externalHTML, markdown } = selectedFragmentToHTML(
160
+ view,
161
+ editor
162
+ );
109
163
 
110
- // TODO: Writing to other MIME types not working in Safari for
111
- // some reason.
112
- event.clipboardData!.setData("blocknote/html", clipboardHTML);
113
- event.clipboardData!.setData("text/html", externalHTML);
114
- event.clipboardData!.setData("text/plain", markdown);
115
- })();
164
+ // TODO: Writing to other MIME types not working in Safari for
165
+ // some reason.
166
+ event.clipboardData!.setData("blocknote/html", clipboardHTML);
167
+ event.clipboardData!.setData("text/html", externalHTML);
168
+ event.clipboardData!.setData("text/plain", markdown);
116
169
  };
117
170
 
118
171
  export const createCopyToClipboardExtension = <
@@ -170,16 +223,15 @@ export const createCopyToClipboardExtension = <
170
223
  event.preventDefault();
171
224
  event.dataTransfer!.clearData();
172
225
 
173
- (async () => {
174
- const { clipboardHTML, externalHTML, markdown } =
175
- await selectedFragmentToHTML(view, editor);
226
+ const { clipboardHTML, externalHTML, markdown } =
227
+ selectedFragmentToHTML(view, editor);
228
+
229
+ // TODO: Writing to other MIME types not working in Safari for
230
+ // some reason.
231
+ event.dataTransfer!.setData("blocknote/html", clipboardHTML);
232
+ event.dataTransfer!.setData("text/html", externalHTML);
233
+ event.dataTransfer!.setData("text/plain", markdown);
176
234
 
177
- // TODO: Writing to other MIME types not working in Safari for
178
- // some reason.
179
- event.dataTransfer!.setData("blocknote/html", clipboardHTML);
180
- event.dataTransfer!.setData("text/html", externalHTML);
181
- event.dataTransfer!.setData("text/plain", markdown);
182
- })();
183
235
  // Prevent default PM handler to be called
184
236
  return true;
185
237
  },
@@ -1 +1 @@
1
- <h2 data-text-color="yellow" data-background-color="blue" data-text-alignment="right" data-level="2"><strong><u>Heading </u></strong><em><s>2</s></em></h2><p data-background-color="red">Paragraph</p><ul><li><p class="bn-inline-content"></p></li></ul>
1
+ <h2 data-text-color="yellow" data-background-color="blue" data-text-alignment="right" data-level="2"><strong><u>Heading </u></strong><em><s>2</s></em></h2><p data-background-color="red">Paragraph</p><ul><li><p></p></li></ul>
@@ -1 +1 @@
1
- <ul><li><p class="bn-inline-content">Bullet List Item 1</p></li><li><p class="bn-inline-content">Bullet List Item 2</p></li></ul><ol><li><p class="bn-inline-content">Numbered List Item 1</p></li><li><p class="bn-inline-content">Numbered List Item 2</p></li></ol><ul><li><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></li><li><input type="checkbox" checked><p class="bn-inline-content">Check List Item 2</p></li></ul>
1
+ <ul><li><p>Bullet List Item 1</p></li><li><p>Bullet List Item 2</p></li></ul><ol><li><p>Numbered List Item 1</p></li><li><p>Numbered List Item 2</p></li></ol><ul><li><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></li><li><input type="checkbox" checked="" data-checked="true"><p class="bn-inline-content">Check List Item 2</p></li></ul>
@@ -1 +1 @@
1
- <ul><li><p class="bn-inline-content">Bullet List Item 1</p></li><li><p class="bn-inline-content">Bullet List Item 2</p><ol><li><p class="bn-inline-content">Numbered List Item 1</p></li><li><p class="bn-inline-content">Numbered List Item 2</p><ul><li><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></li><li><input type="checkbox" checked><p class="bn-inline-content">Check List Item 2</p></li></ul></li></ol></li></ul>
1
+ <ul><li><p>Bullet List Item 1</p></li><li><p>Bullet List Item 2</p><ol><li><p>Numbered List Item 1</p></li><li><p>Numbered List Item 2</p><ul><li><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></li><li><input type="checkbox" checked="" data-checked="true"><p class="bn-inline-content">Check List Item 2</p></li></ul></li></ol></li></ul>
@@ -1,15 +1,17 @@
1
- import { DOMSerializer, Fragment, Node, Schema } from "prosemirror-model";
1
+ import { DOMSerializer, Schema } from "prosemirror-model";
2
2
 
3
- import { PartialBlock } from "../../../blocks/defaultBlocks";
4
- import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
5
- import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
6
- import { esmDependencies } from "../../../util/esmDependencies";
7
- import { blockToNode } from "../../nodeConversions/nodeConversions";
3
+ import { PartialBlock } from "../../../blocks/defaultBlocks.js";
4
+ import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
8
5
  import {
9
- serializeNodeInner,
10
- serializeProseMirrorFragment,
11
- } from "./util/sharedHTMLConversion";
12
- import { simplifyBlocks } from "./util/simplifyBlocksRehypePlugin";
6
+ BlockSchema,
7
+ InlineContent,
8
+ InlineContentSchema,
9
+ StyleSchema,
10
+ } from "../../../schema/index.js";
11
+ import {
12
+ serializeBlocksExternalHTML,
13
+ serializeInlineContentExternalHTML,
14
+ } from "./util/serializeBlocksExternalHTML.js";
13
15
 
14
16
  // Used to export BlockNote blocks and ProseMirror nodes to HTML for use outside
15
17
  // the editor. Blocks are exported using the `toExternalHTML` method in their
@@ -24,26 +26,6 @@ import { simplifyBlocks } from "./util/simplifyBlocksRehypePlugin";
24
26
  // 3. While nesting for list items is preserved, other types of blocks nested
25
27
  // inside a list are un-nested and a new list is created after them.
26
28
  // 4. The HTML is wrapped in a single `div` element.
27
- //
28
- // The serializer has 2 main methods:
29
- // `exportBlocks`: Exports an array of blocks to HTML.
30
- // `exportFragment`: Exports a ProseMirror fragment to HTML. This is mostly
31
- // useful if you want to export a selection which may not start/end at the
32
- // start/end of a block.
33
- export interface ExternalHTMLExporter<
34
- BSchema extends BlockSchema,
35
- I extends InlineContentSchema,
36
- S extends StyleSchema
37
- > {
38
- exportBlocks: (
39
- blocks: PartialBlock<BSchema, I, S>[],
40
- options: { document?: Document }
41
- ) => string;
42
- exportProseMirrorFragment: (
43
- fragment: Fragment,
44
- options: { document?: Document; simplifyBlocks?: boolean }
45
- ) => string;
46
- }
47
29
 
48
30
  // Needs to be sync because it's used in drag handler event (SideMenuPlugin)
49
31
  // Ideally, call `await initializeESMDependencies()` before calling this function
@@ -54,76 +36,42 @@ export const createExternalHTMLExporter = <
54
36
  >(
55
37
  schema: Schema,
56
38
  editor: BlockNoteEditor<BSchema, I, S>
57
- ): ExternalHTMLExporter<BSchema, I, S> => {
58
- const deps = esmDependencies;
59
-
60
- if (!deps) {
61
- throw new Error(
62
- "External HTML exporter requires ESM dependencies to be initialized"
63
- );
64
- }
39
+ ) => {
40
+ const serializer = DOMSerializer.fromSchema(schema);
65
41
 
66
- // TODO: maybe cache this serializer (default prosemirror serializer is cached)?
67
- const serializer = new DOMSerializer(
68
- DOMSerializer.nodesFromSchema(schema),
69
- DOMSerializer.marksFromSchema(schema)
70
- ) as DOMSerializer & {
71
- serializeNodeInner: (
72
- node: Node,
73
- options: { document?: Document }
74
- ) => HTMLElement;
75
- exportProseMirrorFragment: (
76
- fragment: Fragment,
77
- options: { document?: Document; simplifyBlocks?: boolean }
78
- ) => string;
42
+ return {
79
43
  exportBlocks: (
80
44
  blocks: PartialBlock<BSchema, I, S>[],
81
45
  options: { document?: Document }
82
- ) => string;
83
- };
84
-
85
- serializer.serializeNodeInner = (
86
- node: Node,
87
- options: { document?: Document }
88
- ) => serializeNodeInner(node, options, serializer, editor, true);
89
-
90
- // Like the `internalHTMLSerializer`, also uses `serializeProseMirrorFragment`
91
- // but additionally runs it through the `simplifyBlocks` rehype plugin to
92
- // convert the internal HTML to external.
93
- serializer.exportProseMirrorFragment = (fragment, options) => {
94
- let externalHTML: any = deps.unified
95
- .unified()
96
- .use(deps.rehypeParse.default, { fragment: true });
97
- if (options.simplifyBlocks !== false) {
98
- externalHTML = externalHTML.use(simplifyBlocks, {
99
- orderedListItemBlockTypes: new Set<string>(["numberedListItem"]),
100
- unorderedListItemBlockTypes: new Set<string>([
101
- "bulletListItem",
102
- "checkListItem",
103
- ]),
104
- });
105
- }
106
- externalHTML = externalHTML
107
- .use(deps.rehypeStringify.default)
108
- .processSync(serializeProseMirrorFragment(fragment, serializer, options));
46
+ ) => {
47
+ const html = serializeBlocksExternalHTML(
48
+ editor,
49
+ blocks,
50
+ serializer,
51
+ new Set<string>(["numberedListItem"]),
52
+ new Set<string>(["bulletListItem", "checkListItem"]),
53
+ options
54
+ );
55
+ const div = document.createElement("div");
56
+ div.append(html);
57
+ return div.innerHTML;
58
+ },
109
59
 
110
- return externalHTML.value as string;
111
- };
60
+ exportInlineContent: (
61
+ inlineContent: InlineContent<I, S>[],
62
+ options: { document?: Document }
63
+ ) => {
64
+ const domFragment = serializeInlineContentExternalHTML(
65
+ editor,
66
+ inlineContent as any,
67
+ serializer,
68
+ options
69
+ );
112
70
 
113
- serializer.exportBlocks = (
114
- blocks: PartialBlock<BSchema, I, S>[],
115
- options
116
- ) => {
117
- const nodes = blocks.map((block) =>
118
- blockToNode(block, schema, editor.schema.styleSchema)
119
- );
120
- const blockGroup = schema.nodes["blockGroup"].create(null, nodes);
71
+ const parent = document.createElement("div");
72
+ parent.append(domFragment.cloneNode(true));
121
73
 
122
- return serializer.exportProseMirrorFragment(
123
- Fragment.from(blockGroup),
124
- options
125
- );
74
+ return parent.innerHTML;
75
+ },
126
76
  };
127
-
128
- return serializer;
129
77
  };
@@ -1,18 +1,23 @@
1
1
  import { afterEach, beforeEach, describe, expect, it } from "vitest";
2
2
 
3
- import { addIdsToBlocks, partialBlocksToBlocksForTesting } from "../../..";
4
- import { PartialBlock } from "../../../blocks/defaultBlocks";
5
- import { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
6
- import { BlockSchema } from "../../../schema";
7
- import { InlineContentSchema } from "../../../schema";
8
- import { StyleSchema } from "../../../schema";
9
- import { initializeESMDependencies } from "../../../util/esmDependencies";
10
- import { customBlocksTestCases } from "../../testUtil/cases/customBlocks";
11
- import { customInlineContentTestCases } from "../../testUtil/cases/customInlineContent";
12
- import { customStylesTestCases } from "../../testUtil/cases/customStyles";
13
- import { defaultSchemaTestCases } from "../../testUtil/cases/defaultSchema";
14
- import { createExternalHTMLExporter } from "./externalHTMLExporter";
15
- import { createInternalHTMLSerializer } from "./internalHTMLSerializer";
3
+ import { PartialBlock } from "../../../blocks/defaultBlocks.js";
4
+ import { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
5
+ import {
6
+ addIdsToBlocks,
7
+ partialBlocksToBlocksForTesting,
8
+ } from "../../../index.js";
9
+ import {
10
+ BlockSchema,
11
+ InlineContentSchema,
12
+ StyleSchema,
13
+ } from "../../../schema/index.js";
14
+ import { initializeESMDependencies } from "../../../util/esmDependencies.js";
15
+ import { customBlocksTestCases } from "../../testUtil/cases/customBlocks.js";
16
+ import { customInlineContentTestCases } from "../../testUtil/cases/customInlineContent.js";
17
+ import { customStylesTestCases } from "../../testUtil/cases/customStyles.js";
18
+ import { defaultSchemaTestCases } from "../../testUtil/cases/defaultSchema.js";
19
+ import { createExternalHTMLExporter } from "./externalHTMLExporter.js";
20
+ import { createInternalHTMLSerializer } from "./internalHTMLSerializer.js";
16
21
 
17
22
  async function convertToHTMLAndCompareSnapshots<
18
23
  B extends BlockSchema,
@@ -25,6 +30,7 @@ async function convertToHTMLAndCompareSnapshots<
25
30
  snapshotName: string
26
31
  ) {
27
32
  addIdsToBlocks(blocks);
33
+
28
34
  const serializer = createInternalHTMLSerializer(editor.pmSchema, editor);
29
35
  const internalHTML = serializer.serializeBlocks(blocks, {});
30
36
  const internalHTMLSnapshotPath =
@@ -1,12 +1,12 @@
1
- import { DOMSerializer, Fragment, Node, Schema } from "prosemirror-model";
2
- import { PartialBlock } from "../../../blocks/defaultBlocks";
3
- import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
4
- import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
5
- import { blockToNode } from "../../nodeConversions/nodeConversions";
1
+ import { DOMSerializer, Schema } from "prosemirror-model";
2
+ import { PartialBlock } from "../../../blocks/defaultBlocks.js";
3
+ import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
6
4
  import {
7
- serializeNodeInner,
8
- serializeProseMirrorFragment,
9
- } from "./util/sharedHTMLConversion";
5
+ BlockSchema,
6
+ InlineContentSchema,
7
+ StyleSchema,
8
+ } from "../../../schema/index.js";
9
+ import { serializeBlocksInternalHTML } from "./util/serializeBlocksInternalHTML.js";
10
10
  // Used to serialize BlockNote blocks and ProseMirror nodes to HTML without
11
11
  // losing data. Blocks are exported using the `toInternalHTML` method in their
12
12
  // `blockSpec`.
@@ -16,29 +16,6 @@ import {
16
16
  // editor, including the `blockGroup` and `blockContainer` wrappers. This also
17
17
  // means that it can be converted back to the original blocks without any data
18
18
  // loss.
19
- //
20
- // The serializer has 2 main methods:
21
- // `serializeFragment`: Serializes a ProseMirror fragment to HTML. This is
22
- // mostly useful if you want to serialize a selection which may not start/end at
23
- // the start/end of a block.
24
- // `serializeBlocks`: Serializes an array of blocks to HTML.
25
- export interface InternalHTMLSerializer<
26
- BSchema extends BlockSchema,
27
- I extends InlineContentSchema,
28
- S extends StyleSchema
29
- > {
30
- // TODO: Ideally we would expand the BlockNote API to support partial
31
- // selections so we don't need this.
32
- serializeProseMirrorFragment: (
33
- fragment: Fragment,
34
- options: { document?: Document }
35
- ) => string;
36
- serializeBlocks: (
37
- blocks: PartialBlock<BSchema, I, S>[],
38
- options: { document?: Document }
39
- ) => string;
40
- }
41
-
42
19
  export const createInternalHTMLSerializer = <
43
20
  BSchema extends BlockSchema,
44
21
  I extends InlineContentSchema,
@@ -46,49 +23,21 @@ export const createInternalHTMLSerializer = <
46
23
  >(
47
24
  schema: Schema,
48
25
  editor: BlockNoteEditor<BSchema, I, S>
49
- ): InternalHTMLSerializer<BSchema, I, S> => {
50
- // TODO: maybe cache this serializer (default prosemirror serializer is cached)?
51
- const serializer = new DOMSerializer(
52
- DOMSerializer.nodesFromSchema(schema),
53
- DOMSerializer.marksFromSchema(schema)
54
- ) as DOMSerializer & {
55
- serializeNodeInner: (
56
- node: Node,
57
- options: { document?: Document }
58
- ) => HTMLElement;
26
+ ) => {
27
+ const serializer = DOMSerializer.fromSchema(schema);
28
+
29
+ return {
59
30
  serializeBlocks: (
60
31
  blocks: PartialBlock<BSchema, I, S>[],
61
32
  options: { document?: Document }
62
- ) => string;
63
- serializeProseMirrorFragment: (
64
- fragment: Fragment,
65
- options?: { document?: Document | undefined } | undefined,
66
- target?: HTMLElement | DocumentFragment | undefined
67
- ) => string;
33
+ ) => {
34
+ return serializeBlocksInternalHTML(
35
+ editor,
36
+ blocks,
37
+ serializer,
38
+ false,
39
+ options
40
+ ).outerHTML;
41
+ },
68
42
  };
69
-
70
- serializer.serializeNodeInner = (
71
- node: Node,
72
- options: { document?: Document }
73
- ) => serializeNodeInner(node, options, serializer, editor, false);
74
-
75
- serializer.serializeProseMirrorFragment = (fragment: Fragment, options) =>
76
- serializeProseMirrorFragment(fragment, serializer, options);
77
-
78
- serializer.serializeBlocks = (
79
- blocks: PartialBlock<BSchema, I, S>[],
80
- options
81
- ) => {
82
- const nodes = blocks.map((block) =>
83
- blockToNode(block, schema, editor.schema.styleSchema)
84
- );
85
- const blockGroup = schema.nodes["blockGroup"].create(null, nodes);
86
-
87
- return serializer.serializeProseMirrorFragment(
88
- Fragment.from(blockGroup),
89
- options
90
- );
91
- };
92
-
93
- return serializer;
94
43
  };