@blocknote/core 0.37.0 → 0.39.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 (271) hide show
  1. package/dist/BlockNoteSchema-DmZ6UQfY.cjs +11 -0
  2. package/dist/BlockNoteSchema-DmZ6UQfY.cjs.map +1 -0
  3. package/dist/BlockNoteSchema-oR047ACf.js +4275 -0
  4. package/dist/BlockNoteSchema-oR047ACf.js.map +1 -0
  5. package/dist/blocknote.cjs +4 -12
  6. package/dist/blocknote.cjs.map +1 -1
  7. package/dist/blocknote.js +3311 -7230
  8. package/dist/blocknote.js.map +1 -1
  9. package/dist/blocks.cjs +2 -0
  10. package/dist/blocks.cjs.map +1 -0
  11. package/dist/blocks.js +71 -0
  12. package/dist/blocks.js.map +1 -0
  13. package/dist/{en-CvDoFvhc.js → en-Bq3Es3Np.js} +6 -12
  14. package/dist/en-Bq3Es3Np.js.map +1 -0
  15. package/dist/en-D3B48eJ7.cjs +2 -0
  16. package/dist/en-D3B48eJ7.cjs.map +1 -0
  17. package/dist/locales.cjs +1 -1
  18. package/dist/locales.cjs.map +1 -1
  19. package/dist/locales.js +109 -229
  20. package/dist/locales.js.map +1 -1
  21. package/dist/style.css +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -0
  23. package/dist/webpack-stats.json +1 -1
  24. package/package.json +25 -22
  25. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
  26. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +2 -2
  27. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +34 -25
  28. package/src/api/blockManipulation/setupTestEnv.ts +0 -1
  29. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +4 -8
  30. package/src/api/clipboard/toClipboard/copyExtension.ts +1 -3
  31. package/src/api/exporters/html/externalHTMLExporter.ts +0 -1
  32. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +128 -28
  33. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +101 -41
  34. package/src/api/exporters/markdown/markdownExporter.ts +13 -22
  35. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +2 -12
  36. package/src/api/parsers/html/parseHTML.ts +3 -2
  37. package/src/api/parsers/html/util/nestedLists.test.ts +8 -8
  38. package/src/api/parsers/markdown/parseMarkdown.ts +17 -14
  39. package/src/api/pmUtil.ts +1 -1
  40. package/src/api/positionMapping.test.ts +197 -33
  41. package/src/api/positionMapping.ts +4 -6
  42. package/src/blocks/Audio/block.ts +174 -0
  43. package/src/blocks/BlockNoteSchema.ts +59 -0
  44. package/src/blocks/Code/block.ts +303 -0
  45. package/src/blocks/Code/shiki.ts +73 -0
  46. package/src/blocks/File/block.ts +98 -0
  47. package/src/blocks/{FileBlockContent → File}/helpers/render/createAddFileButton.ts +8 -4
  48. package/src/blocks/{FileBlockContent → File}/helpers/render/createFileBlockWrapper.ts +16 -13
  49. package/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.ts +15 -2
  50. package/src/blocks/{FileBlockContent → File}/helpers/render/createResizableFileBlockWrapper.ts +63 -19
  51. package/src/blocks/Heading/block.ts +138 -0
  52. package/src/blocks/Image/block.ts +190 -0
  53. package/src/blocks/ListItem/BulletListItem/block.ts +116 -0
  54. package/src/blocks/ListItem/CheckListItem/block.ts +175 -0
  55. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +173 -0
  56. package/src/blocks/ListItem/NumberedListItem/block.ts +133 -0
  57. package/src/blocks/ListItem/ToggleListItem/block.ts +78 -0
  58. package/src/blocks/PageBreak/block.ts +72 -0
  59. package/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.ts +9 -7
  60. package/src/blocks/Paragraph/block.ts +80 -0
  61. package/src/blocks/Quote/block.ts +90 -0
  62. package/src/blocks/{TableBlockContent/TableBlockContent.ts → Table/block.ts} +169 -51
  63. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +1 -1
  64. package/src/blocks/Video/block.ts +143 -0
  65. package/src/blocks/defaultBlockHelpers.ts +2 -2
  66. package/src/blocks/defaultBlockTypeGuards.ts +143 -174
  67. package/src/blocks/defaultBlocks.ts +107 -35
  68. package/src/blocks/defaultProps.ts +145 -4
  69. package/src/blocks/index.ts +26 -0
  70. package/src/blocks/utils/listItemEnterHandler.ts +42 -0
  71. package/src/editor/Block.css +54 -18
  72. package/src/editor/BlockNoteEditor.ts +265 -230
  73. package/src/editor/BlockNoteExtension.ts +92 -0
  74. package/src/editor/BlockNoteExtensions.ts +20 -16
  75. package/src/editor/defaultColors.ts +2 -2
  76. package/src/exporter/Exporter.ts +1 -1
  77. package/src/exporter/mapping.ts +1 -1
  78. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +3 -20
  79. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +6 -8
  80. package/src/extensions/BlockChange/BlockChangePlugin.ts +2 -1
  81. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +2 -2
  82. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +2 -2
  83. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
  84. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
  85. package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +52 -0
  86. package/src/extensions/Collaboration/schemaMigration/migrationRules/index.ts +4 -0
  87. package/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.ts +4 -0
  88. package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.ts +78 -0
  89. package/src/extensions/Comments/CommentsPlugin.ts +2 -0
  90. package/src/extensions/FilePanel/FilePanelPlugin.ts +5 -10
  91. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -1
  92. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +4 -3
  93. package/src/extensions/Placeholder/PlaceholderPlugin.ts +2 -2
  94. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +1 -23
  95. package/src/extensions/SideMenu/SideMenuPlugin.ts +0 -2
  96. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +0 -5
  97. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +6 -2
  98. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +24 -17
  99. package/src/extensions/TableHandles/TableHandlesPlugin.ts +2 -2
  100. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +5 -11
  101. package/src/extensions/TextColor/TextColorExtension.ts +3 -17
  102. package/src/extensions/TextColor/TextColorMark.ts +4 -9
  103. package/src/extensions/UniqueID/UniqueID.ts +6 -13
  104. package/src/i18n/locales/ar.ts +6 -12
  105. package/src/i18n/locales/de.ts +6 -12
  106. package/src/i18n/locales/en.ts +6 -12
  107. package/src/i18n/locales/es.ts +6 -12
  108. package/src/i18n/locales/fr.ts +6 -12
  109. package/src/i18n/locales/he.ts +6 -12
  110. package/src/i18n/locales/hr.ts +6 -12
  111. package/src/i18n/locales/is.ts +6 -12
  112. package/src/i18n/locales/it.ts +6 -12
  113. package/src/i18n/locales/ja.ts +6 -12
  114. package/src/i18n/locales/ko.ts +6 -12
  115. package/src/i18n/locales/nl.ts +6 -12
  116. package/src/i18n/locales/no.ts +6 -12
  117. package/src/i18n/locales/pl.ts +6 -12
  118. package/src/i18n/locales/pt.ts +6 -12
  119. package/src/i18n/locales/ru.ts +6 -12
  120. package/src/i18n/locales/sk.ts +6 -12
  121. package/src/i18n/locales/uk.ts +6 -12
  122. package/src/i18n/locales/vi.ts +6 -12
  123. package/src/i18n/locales/zh-tw.ts +6 -12
  124. package/src/i18n/locales/zh.ts +6 -12
  125. package/src/index.ts +2 -29
  126. package/src/schema/blocks/createSpec.ts +342 -169
  127. package/src/schema/blocks/internal.ts +77 -138
  128. package/src/schema/blocks/types.ts +264 -94
  129. package/src/schema/index.ts +1 -0
  130. package/src/schema/inlineContent/createSpec.ts +99 -21
  131. package/src/schema/inlineContent/internal.ts +16 -7
  132. package/src/schema/inlineContent/types.ts +24 -2
  133. package/src/schema/propTypes.ts +15 -9
  134. package/src/schema/schema.ts +209 -0
  135. package/src/schema/styles/createSpec.ts +79 -31
  136. package/src/schema/styles/internal.ts +61 -2
  137. package/src/schema/styles/types.ts +17 -3
  138. package/src/util/topo-sort.test.ts +125 -0
  139. package/src/util/topo-sort.ts +160 -0
  140. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -1
  141. package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
  142. package/types/src/api/blockManipulation/setupTestEnv.d.ts +29 -543
  143. package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +1 -1
  144. package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +1 -1
  145. package/types/src/api/exporters/markdown/markdownExporter.d.ts +1 -1
  146. package/types/src/api/parsers/html/parseHTML.d.ts +1 -1
  147. package/types/src/api/parsers/markdown/parseMarkdown.d.ts +2 -2
  148. package/types/src/api/pmUtil.d.ts +1 -1
  149. package/types/src/blocks/Audio/block.d.ts +58 -0
  150. package/types/src/blocks/BlockNoteSchema.d.ts +18 -0
  151. package/types/src/blocks/{CodeBlockContent/CodeBlockContent.d.ts → Code/block.d.ts} +25 -26
  152. package/types/src/blocks/Code/shiki.d.ts +4 -0
  153. package/types/src/blocks/File/block.d.ts +37 -0
  154. package/types/src/blocks/File/helpers/render/createAddFileButton.d.ts +6 -0
  155. package/types/src/blocks/File/helpers/render/createFileBlockWrapper.d.ts +25 -0
  156. package/types/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.d.ts +6 -2
  157. package/types/src/blocks/File/helpers/render/createResizableFileBlockWrapper.d.ts +31 -0
  158. package/types/src/blocks/Heading/block.d.ts +71 -0
  159. package/types/src/blocks/Image/block.d.ts +102 -0
  160. package/types/src/blocks/ListItem/BulletListItem/block.d.ts +25 -0
  161. package/types/src/blocks/ListItem/CheckListItem/block.d.ts +33 -0
  162. package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.d.ts +8 -0
  163. package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +33 -0
  164. package/types/src/blocks/ListItem/ToggleListItem/block.d.ts +25 -0
  165. package/types/src/blocks/PageBreak/block.d.ts +11 -0
  166. package/types/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.d.ts +4 -2
  167. package/types/src/blocks/Paragraph/block.d.ts +25 -0
  168. package/types/src/blocks/Quote/block.d.ts +17 -0
  169. package/types/src/blocks/Table/block.d.ts +21 -0
  170. package/types/src/blocks/Video/block.d.ts +67 -0
  171. package/types/src/blocks/defaultBlockHelpers.d.ts +1 -1
  172. package/types/src/blocks/defaultBlockTypeGuards.d.ts +15 -36
  173. package/types/src/blocks/defaultBlocks.d.ts +221 -1060
  174. package/types/src/blocks/defaultProps.d.ts +17 -1
  175. package/types/src/blocks/index.d.ts +24 -0
  176. package/types/src/blocks/utils/listItemEnterHandler.d.ts +2 -0
  177. package/types/src/editor/BlockNoteEditor.d.ts +39 -75
  178. package/types/src/editor/BlockNoteExtension.d.ts +67 -0
  179. package/types/src/editor/BlockNoteExtensions.d.ts +2 -0
  180. package/types/src/editor/defaultColors.d.ts +8 -76
  181. package/types/src/exporter/Exporter.d.ts +1 -1
  182. package/types/src/exporter/mapping.d.ts +1 -1
  183. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +4 -1
  184. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +7 -0
  185. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/index.d.ts +3 -0
  186. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.d.ts +3 -0
  187. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.d.ts +2 -0
  188. package/types/src/extensions/Comments/CommentsPlugin.d.ts +3 -1
  189. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
  190. package/types/src/extensions/TextColor/TextColorMark.d.ts +4 -1
  191. package/types/src/i18n/locales/en.d.ts +1 -12
  192. package/types/src/i18n/locales/sk.d.ts +1 -12
  193. package/types/src/index.d.ts +2 -26
  194. package/types/src/schema/blocks/createSpec.d.ts +16 -36
  195. package/types/src/schema/blocks/internal.d.ts +11 -33
  196. package/types/src/schema/blocks/types.d.ts +181 -57
  197. package/types/src/schema/index.d.ts +1 -0
  198. package/types/src/schema/inlineContent/createSpec.d.ts +36 -2
  199. package/types/src/schema/inlineContent/internal.d.ts +7 -15
  200. package/types/src/schema/inlineContent/types.d.ts +15 -1
  201. package/types/src/schema/propTypes.d.ts +4 -4
  202. package/types/src/schema/schema.d.ts +40 -0
  203. package/types/src/schema/styles/createSpec.d.ts +6 -4
  204. package/types/src/schema/styles/internal.d.ts +6 -3
  205. package/types/src/schema/styles/types.d.ts +11 -2
  206. package/types/src/util/topo-sort.d.ts +18 -0
  207. package/types/src/util/topo-sort.test.d.ts +1 -0
  208. package/dist/en-CvDoFvhc.js.map +0 -1
  209. package/dist/en-ub2yVBX0.cjs +0 -2
  210. package/dist/en-ub2yVBX0.cjs.map +0 -1
  211. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +0 -145
  212. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +0 -445
  213. package/src/blocks/FileBlockContent/FileBlockContent.ts +0 -100
  214. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +0 -159
  215. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +0 -160
  216. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +0 -134
  217. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +0 -299
  218. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +0 -86
  219. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +0 -172
  220. package/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.ts +0 -104
  221. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +0 -49
  222. package/src/blocks/PageBreakBlockContent/schema.ts +0 -40
  223. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +0 -78
  224. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +0 -121
  225. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +0 -159
  226. package/src/editor/BlockNoteSchema.ts +0 -107
  227. package/src/editor/BlockNoteTipTapEditor.ts +0 -335
  228. package/src/util/esmDependencies.ts +0 -51
  229. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +0 -99
  230. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +0 -90
  231. package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +0 -6
  232. package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +0 -9
  233. package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +0 -9
  234. package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +0 -67
  235. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +0 -131
  236. package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -46
  237. package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +0 -55
  238. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -2
  239. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -58
  240. package/types/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.d.ts +0 -46
  241. package/types/src/blocks/PageBreakBlockContent/PageBreakBlockContent.d.ts +0 -31
  242. package/types/src/blocks/PageBreakBlockContent/schema.d.ts +0 -86
  243. package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -52
  244. package/types/src/blocks/QuoteBlockContent/QuoteBlockContent.d.ts +0 -52
  245. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -39
  246. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +0 -131
  247. package/types/src/editor/BlockNoteSchema.d.ts +0 -34
  248. package/types/src/editor/BlockNoteTipTapEditor.d.ts +0 -43
  249. package/types/src/util/esmDependencies.d.ts +0 -24
  250. /package/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.ts +0 -0
  251. /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.ts +0 -0
  252. /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.ts +0 -0
  253. /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.ts +0 -0
  254. /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.ts +0 -0
  255. /package/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
  256. /package/src/blocks/{ImageBlockContent → Image}/parseImageElement.ts +0 -0
  257. /package/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.ts +0 -0
  258. /package/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.ts +0 -0
  259. /package/src/blocks/{TableBlockContent → Table}/TableExtension.ts +0 -0
  260. /package/src/blocks/{VideoBlockContent → Video}/parseVideoElement.ts +0 -0
  261. /package/types/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.d.ts +0 -0
  262. /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.d.ts +0 -0
  263. /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.d.ts +0 -0
  264. /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.d.ts +0 -0
  265. /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.d.ts +0 -0
  266. /package/types/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
  267. /package/types/src/blocks/{ImageBlockContent → Image}/parseImageElement.d.ts +0 -0
  268. /package/types/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.d.ts +0 -0
  269. /package/types/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.d.ts +0 -0
  270. /package/types/src/blocks/{TableBlockContent → Table}/TableExtension.d.ts +0 -0
  271. /package/types/src/blocks/{VideoBlockContent → Video}/parseVideoElement.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- import { DOMSerializer, Fragment } from "prosemirror-model";
1
+ import { DOMSerializer, Fragment, Node } from "prosemirror-model";
2
2
 
3
3
  import { PartialBlock } from "../../../../blocks/defaultBlocks.js";
4
4
  import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
@@ -13,6 +13,7 @@ import {
13
13
  tableContentToNodes,
14
14
  } from "../../../nodeConversions/blockToNode.js";
15
15
 
16
+ import { nodeToCustomInlineContent } from "../../../nodeConversions/nodeToBlock.js";
16
17
  export function serializeInlineContentInternalHTML<
17
18
  BSchema extends BlockSchema,
18
19
  I extends InlineContentSchema,
@@ -24,7 +25,7 @@ export function serializeInlineContentInternalHTML<
24
25
  blockType?: string,
25
26
  options?: { document?: Document },
26
27
  ) {
27
- let nodes: any;
28
+ let nodes: Node[];
28
29
 
29
30
  // TODO: reuse function from nodeconversions?
30
31
  if (!blockContent) {
@@ -39,12 +40,90 @@ export function serializeInlineContentInternalHTML<
39
40
  throw new UnreachableCaseError(blockContent.type);
40
41
  }
41
42
 
42
- // We call the prosemirror serializer here because it handles Marks and Inline Content nodes nicely.
43
- // If we'd want to support custom serialization or externalHTML for Inline Content, we'd have to implement
44
- // a custom serializer here.
45
- const dom = serializer.serializeFragment(Fragment.from(nodes), options);
43
+ // Check if any of the nodes are custom inline content with toExternalHTML
44
+ const doc = options?.document ?? document;
45
+ const fragment = doc.createDocumentFragment();
46
+
47
+ for (const node of nodes) {
48
+ // Check if this is a custom inline content node with toExternalHTML
49
+ if (
50
+ node.type.name !== "text" &&
51
+ editor.schema.inlineContentSchema[node.type.name]
52
+ ) {
53
+ const inlineContentImplementation =
54
+ editor.schema.inlineContentSpecs[node.type.name].implementation;
55
+
56
+ if (inlineContentImplementation) {
57
+ // Convert the node to inline content format
58
+ const inlineContent = nodeToCustomInlineContent(
59
+ node,
60
+ editor.schema.inlineContentSchema,
61
+ editor.schema.styleSchema,
62
+ );
63
+
64
+ // Use the custom toExternalHTML method
65
+ const output = inlineContentImplementation.render.call(
66
+ {
67
+ renderType: "dom",
68
+ props: undefined,
69
+ },
70
+ inlineContent as any,
71
+ () => {
72
+ // No-op
73
+ },
74
+ editor as any,
75
+ );
76
+
77
+ if (output) {
78
+ fragment.appendChild(output.dom);
79
+
80
+ // If contentDOM exists, render the inline content into it
81
+ if (output.contentDOM) {
82
+ const contentFragment = serializer.serializeFragment(
83
+ node.content,
84
+ options,
85
+ );
86
+ output.contentDOM.dataset.editable = "";
87
+ output.contentDOM.appendChild(contentFragment);
88
+ }
89
+ continue;
90
+ }
91
+ }
92
+ } else if (node.type.name === "text") {
93
+ // We serialize text nodes manually as we need to serialize the styles/
94
+ // marks using `styleSpec.implementation.render`. When left up to
95
+ // ProseMirror, it'll use `toDOM` which is incorrect.
96
+ let dom: globalThis.Node | Text = document.createTextNode(
97
+ node.textContent,
98
+ );
99
+ // Reverse the order of marks to maintain the correct priority.
100
+ for (const mark of node.marks.toReversed()) {
101
+ if (mark.type.name in editor.schema.styleSpecs) {
102
+ const newDom = editor.schema.styleSpecs[
103
+ mark.type.name
104
+ ].implementation.render(mark.attrs["stringValue"], editor);
105
+ newDom.contentDOM!.appendChild(dom);
106
+ dom = newDom.dom;
107
+ } else {
108
+ const domOutputSpec = mark.type.spec.toDOM!(mark, true);
109
+ const newDom = DOMSerializer.renderSpec(document, domOutputSpec);
110
+ newDom.contentDOM!.appendChild(dom);
111
+ dom = newDom.dom;
112
+ }
113
+ }
46
114
 
47
- return dom;
115
+ fragment.appendChild(dom);
116
+ } else {
117
+ // Fall back to default serialization for this node
118
+ const nodeFragment = serializer.serializeFragment(
119
+ Fragment.from([node]),
120
+ options,
121
+ );
122
+ fragment.appendChild(nodeFragment);
123
+ }
124
+ }
125
+
126
+ return fragment;
48
127
  }
49
128
 
50
129
  function serializeBlock<
@@ -55,36 +134,29 @@ function serializeBlock<
55
134
  editor: BlockNoteEditor<BSchema, I, S>,
56
135
  block: PartialBlock<BSchema, I, S>,
57
136
  serializer: DOMSerializer,
58
- listIndex: number,
59
137
  options?: { document?: Document },
60
138
  ) {
61
139
  const BC_NODE = editor.pmSchema.nodes["blockContainer"];
62
140
 
63
- let props = block.props;
64
141
  // set default props in case we were passed a partial block
65
- if (!block.props) {
66
- props = {};
67
- for (const [name, spec] of Object.entries(
68
- editor.schema.blockSchema[block.type as any].propSchema,
69
- )) {
70
- if (spec.default !== undefined) {
71
- (props as any)[name] = spec.default;
72
- }
142
+ const props = block.props || {};
143
+ for (const [name, spec] of Object.entries(
144
+ editor.schema.blockSchema[block.type as any].propSchema,
145
+ )) {
146
+ if (!(name in props) && spec.default !== undefined) {
147
+ (props as any)[name] = spec.default;
73
148
  }
74
149
  }
75
150
 
76
151
  const impl = editor.blockImplementations[block.type as any].implementation;
77
- const ret = impl.toInternalHTML({ ...block, props } as any, editor as any);
78
-
79
- if (block.type === "numberedListItem") {
80
- // This is a workaround to make sure there's a list index set.
81
- // Normally, this is set on the internal prosemirror nodes by the NumberedListIndexingPlugin,
82
- // but:
83
- // - (a) this information is not available on the Blocks passed to the serializer. (we only have access to BlockNote Blocks)
84
- // - (b) the NumberedListIndexingPlugin might not even have run, because we can manually call blocksToFullHTML
85
- // with blocks that are not part of the active document
86
- ret.dom.setAttribute("data-index", listIndex.toString());
87
- }
152
+ const ret = impl.render.call(
153
+ {
154
+ renderType: "dom",
155
+ props: undefined,
156
+ },
157
+ { ...block, props } as any,
158
+ editor as any,
159
+ );
88
160
 
89
161
  if (ret.contentDOM && block.content) {
90
162
  const ic = serializeInlineContentInternalHTML(
@@ -147,20 +219,8 @@ function serializeBlocks<
147
219
  const doc = options?.document ?? document;
148
220
  const fragment = doc.createDocumentFragment();
149
221
 
150
- let listIndex = 0;
151
222
  for (const block of blocks) {
152
- if (block.type === "numberedListItem") {
153
- listIndex++;
154
- } else {
155
- listIndex = 0;
156
- }
157
- const blockDOM = serializeBlock(
158
- editor,
159
- block,
160
- serializer,
161
- listIndex,
162
- options,
163
- );
223
+ const blockDOM = serializeBlock(editor, block, serializer, options);
164
224
  fragment.appendChild(blockDOM);
165
225
  }
166
226
 
@@ -1,4 +1,10 @@
1
1
  import { Schema } from "prosemirror-model";
2
+ import rehypeParse from "rehype-parse";
3
+ import rehypeRemark from "rehype-remark";
4
+ import remarkGfm from "remark-gfm";
5
+ import remarkStringify from "remark-stringify";
6
+ import { unified } from "unified";
7
+
2
8
  import { PartialBlock } from "../../../blocks/defaultBlocks.js";
3
9
  import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
4
10
  import {
@@ -6,33 +12,19 @@ import {
6
12
  InlineContentSchema,
7
13
  StyleSchema,
8
14
  } from "../../../schema/index.js";
9
- import {
10
- esmDependencies,
11
- initializeESMDependencies,
12
- } from "../../../util/esmDependencies.js";
13
15
  import { createExternalHTMLExporter } from "../html/externalHTMLExporter.js";
14
16
  import { removeUnderlines } from "./removeUnderlinesRehypePlugin.js";
15
17
  import { addSpacesToCheckboxes } from "./util/addSpacesToCheckboxesRehypePlugin.js";
16
18
 
17
19
  // Needs to be sync because it's used in drag handler event (SideMenuPlugin)
18
- // Ideally, call `await initializeESMDependencies()` before calling this function
19
20
  export function cleanHTMLToMarkdown(cleanHTMLString: string) {
20
- const deps = esmDependencies;
21
-
22
- if (!deps) {
23
- throw new Error(
24
- "cleanHTMLToMarkdown requires ESM dependencies to be initialized",
25
- );
26
- }
27
-
28
- const markdownString = deps.unified
29
- .unified()
30
- .use(deps.rehypeParse.default, { fragment: true })
21
+ const markdownString = unified()
22
+ .use(rehypeParse, { fragment: true })
31
23
  .use(removeUnderlines)
32
24
  .use(addSpacesToCheckboxes)
33
- .use(deps.rehypeRemark.default)
34
- .use(deps.remarkGfm.default)
35
- .use(deps.remarkStringify.default, {
25
+ .use(rehypeRemark)
26
+ .use(remarkGfm)
27
+ .use(remarkStringify, {
36
28
  handlers: { text: (node) => node.value },
37
29
  })
38
30
  .processSync(cleanHTMLString);
@@ -40,7 +32,7 @@ export function cleanHTMLToMarkdown(cleanHTMLString: string) {
40
32
  return markdownString.value as string;
41
33
  }
42
34
 
43
- export async function blocksToMarkdown<
35
+ export function blocksToMarkdown<
44
36
  BSchema extends BlockSchema,
45
37
  I extends InlineContentSchema,
46
38
  S extends StyleSchema,
@@ -49,8 +41,7 @@ export async function blocksToMarkdown<
49
41
  schema: Schema,
50
42
  editor: BlockNoteEditor<BSchema, I, S>,
51
43
  options: { document?: Document },
52
- ): Promise<string> {
53
- await initializeESMDependencies();
44
+ ): string {
54
45
  const exporter = createExternalHTMLExporter(schema, editor);
55
46
  const externalHTML = exporter.exportBlocks(blocks, options);
56
47
 
@@ -1,5 +1,5 @@
1
1
  import { Element as HASTElement, Parent as HASTParent } from "hast";
2
- import { esmDependencies } from "../../../../util/esmDependencies.js";
2
+ import { fromDom } from "hast-util-from-dom";
3
3
 
4
4
  /**
5
5
  * Rehype plugin which adds a space after each checkbox input element. This is
@@ -7,14 +7,6 @@ import { esmDependencies } from "../../../../util/esmDependencies.js";
7
7
  * itself, but these are needed for correct Markdown syntax.
8
8
  */
9
9
  export function addSpacesToCheckboxes() {
10
- const deps = esmDependencies;
11
-
12
- if (!deps) {
13
- throw new Error(
14
- "addSpacesToCheckboxes requires ESM dependencies to be initialized",
15
- );
16
- }
17
-
18
10
  const helper = (tree: HASTParent) => {
19
11
  if (tree.children && "length" in tree.children && tree.children.length) {
20
12
  for (let i = tree.children.length - 1; i >= 0; i--) {
@@ -37,9 +29,7 @@ export function addSpacesToCheckboxes() {
37
29
  nextChild.children.splice(
38
30
  0,
39
31
  0,
40
- deps.hastUtilFromDom.fromDom(
41
- document.createTextNode(" "),
42
- ) as HASTElement,
32
+ fromDom(document.createTextNode(" ")) as HASTElement,
43
33
  );
44
34
  } else {
45
35
  helper(child as HASTParent);
@@ -8,11 +8,12 @@ import {
8
8
  import { Block } from "../../../blocks/defaultBlocks.js";
9
9
  import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
10
10
  import { nestedListsToBlockNoteStructure } from "./util/nestedLists.js";
11
- export async function HTMLToBlocks<
11
+
12
+ export function HTMLToBlocks<
12
13
  BSchema extends BlockSchema,
13
14
  I extends InlineContentSchema,
14
15
  S extends StyleSchema,
15
- >(html: string, pmSchema: Schema): Promise<Block<BSchema, I, S>[]> {
16
+ >(html: string, pmSchema: Schema): Block<BSchema, I, S>[] {
16
17
  const htmlNode = nestedListsToBlockNoteStructure(html);
17
18
  const parser = DOMParser.fromSchema(pmSchema);
18
19
 
@@ -1,17 +1,17 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { initializeESMDependencies } from "../../../../util/esmDependencies.js";
3
2
  import { nestedListsToBlockNoteStructure } from "./nestedLists.js";
3
+ import { unified } from "unified";
4
+ import rehypeParse from "rehype-parse";
5
+ import rehypeFormat from "rehype-format";
6
+ import rehypeStringify from "rehype-stringify";
4
7
 
5
8
  async function testHTML(html: string) {
6
- const deps = await initializeESMDependencies();
7
-
8
9
  const htmlNode = nestedListsToBlockNoteStructure(html);
9
10
 
10
- const pretty = await deps.unified
11
- .unified()
12
- .use(deps.rehypeParse.default, { fragment: true })
13
- .use(deps.rehypeFormat.default)
14
- .use(deps.rehypeStringify.default)
11
+ const pretty = await unified()
12
+ .use(rehypeParse, { fragment: true })
13
+ .use(rehypeFormat)
14
+ .use(rehypeStringify)
15
15
  .process(htmlNode.innerHTML);
16
16
 
17
17
  expect(pretty.value).toMatchSnapshot();
@@ -1,4 +1,11 @@
1
1
  import { Schema } from "prosemirror-model";
2
+ import remarkGfm from "remark-gfm";
3
+ import remarkParse from "remark-parse";
4
+ import remarkRehype, {
5
+ defaultHandlers as remarkRehypeDefaultHandlers,
6
+ } from "remark-rehype";
7
+ import rehypeStringify from "rehype-stringify";
8
+ import { unified } from "unified";
2
9
 
3
10
  import { Block } from "../../../blocks/defaultBlocks.js";
4
11
  import {
@@ -6,7 +13,6 @@ import {
6
13
  InlineContentSchema,
7
14
  StyleSchema,
8
15
  } from "../../../schema/index.js";
9
- import { initializeESMDependencies } from "../../../util/esmDependencies.js";
10
16
  import { HTMLToBlocks } from "../html/parseHTML.js";
11
17
 
12
18
  // modified version of https://github.com/syntax-tree/mdast-util-to-hast/blob/main/lib/handlers/code.js
@@ -48,31 +54,28 @@ function code(state: any, node: any) {
48
54
  return result;
49
55
  }
50
56
 
51
- export async function markdownToHTML(markdown: string): Promise<string> {
52
- const deps = await initializeESMDependencies();
53
-
54
- const htmlString = deps.unified
55
- .unified()
56
- .use(deps.remarkParse.default)
57
- .use(deps.remarkGfm.default)
58
- .use(deps.remarkRehype.default, {
57
+ export function markdownToHTML(markdown: string): string {
58
+ const htmlString = unified()
59
+ .use(remarkParse)
60
+ .use(remarkGfm)
61
+ .use(remarkRehype, {
59
62
  handlers: {
60
- ...(deps.remarkRehype.defaultHandlers as any),
63
+ ...(remarkRehypeDefaultHandlers as any),
61
64
  code,
62
65
  },
63
66
  })
64
- .use(deps.rehypeStringify.default)
67
+ .use(rehypeStringify)
65
68
  .processSync(markdown);
66
69
 
67
70
  return htmlString.value as string;
68
71
  }
69
72
 
70
- export async function markdownToBlocks<
73
+ export function markdownToBlocks<
71
74
  BSchema extends BlockSchema,
72
75
  I extends InlineContentSchema,
73
76
  S extends StyleSchema,
74
- >(markdown: string, pmSchema: Schema): Promise<Block<BSchema, I, S>[]> {
75
- const htmlString = await markdownToHTML(markdown);
77
+ >(markdown: string, pmSchema: Schema): Block<BSchema, I, S>[] {
78
+ const htmlString = markdownToHTML(markdown);
76
79
 
77
80
  return HTMLToBlocks(htmlString, pmSchema);
78
81
  }
package/src/api/pmUtil.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Node, Schema } from "prosemirror-model";
2
2
  import { Transform } from "prosemirror-transform";
3
3
  import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
4
- import { BlockNoteSchema } from "../editor/BlockNoteSchema.js";
4
+ import { BlockNoteSchema } from "../blocks/BlockNoteSchema.js";
5
5
  import type { BlockSchema } from "../schema/blocks/types.js";
6
6
  import type { InlineContentSchema } from "../schema/inlineContent/types.js";
7
7
  import type { StyleSchema } from "../schema/styles/types.js";