@blocknote/core 0.30.0 → 0.31.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 (245) hide show
  1. package/dist/blocknote.cjs +9 -9
  2. package/dist/blocknote.cjs.map +1 -1
  3. package/dist/blocknote.js +2771 -2245
  4. package/dist/blocknote.js.map +1 -1
  5. package/dist/comments.cjs.map +1 -1
  6. package/dist/comments.js.map +1 -1
  7. package/dist/{en-D4taoCs4.cjs → en-BXVKCwYt.cjs} +2 -2
  8. package/dist/en-BXVKCwYt.cjs.map +1 -0
  9. package/dist/{en-B7ycW7c8.js → en-qGo6sk9V.js} +2 -3
  10. package/dist/en-qGo6sk9V.js.map +1 -0
  11. package/dist/locales.cjs +1 -1
  12. package/dist/locales.cjs.map +1 -1
  13. package/dist/locales.js +20 -39
  14. package/dist/locales.js.map +1 -1
  15. package/dist/style.css +1 -1
  16. package/dist/webpack-stats.json +1 -1
  17. package/package.json +8 -7
  18. package/src/api/README.md +1 -1
  19. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
  20. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +7 -8
  21. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
  22. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +12 -12
  23. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +14 -14
  24. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +16 -16
  25. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +8 -8
  26. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
  27. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +8 -8
  28. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +10 -10
  29. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +2 -2
  30. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2816 -0
  31. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +200 -42
  32. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +104 -34
  33. package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
  34. package/src/api/blockManipulation/insertContentAt.ts +1 -1
  35. package/src/api/blockManipulation/selections/selection.ts +59 -12
  36. package/src/api/blockManipulation/selections/{textCursorPosition/textCursorPosition.ts → textCursorPosition.ts} +13 -13
  37. package/src/api/blockManipulation/tables/tables.test.ts +106 -106
  38. package/src/api/blockManipulation/tables/tables.ts +35 -35
  39. package/src/api/clipboard/fromClipboard/fileDropExtension.ts +2 -2
  40. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +9 -9
  41. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +3 -3
  42. package/src/api/clipboard/fromClipboard/pasteExtension.ts +3 -3
  43. package/src/api/clipboard/toClipboard/copyExtension.ts +22 -22
  44. package/src/api/exporters/html/externalHTMLExporter.ts +6 -6
  45. package/src/api/exporters/html/internalHTMLSerializer.ts +3 -3
  46. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +16 -16
  47. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +14 -14
  48. package/src/api/exporters/markdown/markdownExporter.ts +3 -3
  49. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +3 -3
  50. package/src/api/getBlockInfoFromPos.ts +6 -6
  51. package/src/api/nodeConversions/blockToNode.ts +31 -28
  52. package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
  53. package/src/api/nodeConversions/nodeToBlock.ts +240 -41
  54. package/src/api/nodeUtil.test.ts +16 -16
  55. package/src/api/nodeUtil.ts +10 -10
  56. package/src/api/parsers/html/parseHTML.ts +1 -1
  57. package/src/api/parsers/html/util/nestedLists.ts +2 -2
  58. package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
  59. package/src/api/pmUtil.ts +7 -7
  60. package/src/api/positionMapping.test.ts +3 -3
  61. package/src/api/positionMapping.ts +5 -5
  62. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +4 -4
  63. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +18 -18
  64. package/src/blocks/FileBlockContent/FileBlockContent.ts +2 -2
  65. package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
  66. package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +6 -6
  67. package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +2 -2
  68. package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +1 -1
  69. package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +7 -7
  70. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +1 -1
  71. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +1 -1
  72. package/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +2 -2
  73. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +6 -6
  74. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +4 -4
  75. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +4 -4
  76. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +10 -10
  77. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
  78. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
  79. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +4 -4
  80. package/src/blocks/ListItemBlockContent/getListItemContent.ts +5 -5
  81. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +1 -1
  82. package/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.ts +3 -3
  83. package/src/blocks/PageBreakBlockContent/schema.ts +2 -2
  84. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +3 -3
  85. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +4 -4
  86. package/src/blocks/README.md +1 -1
  87. package/src/blocks/TableBlockContent/TableBlockContent.ts +37 -7
  88. package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
  89. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +4 -4
  90. package/src/blocks/defaultBlockHelpers.ts +8 -8
  91. package/src/blocks/defaultBlockTypeGuards.ts +16 -16
  92. package/src/blocks/defaultBlocks.ts +3 -3
  93. package/src/comments/threadstore/DefaultThreadStoreAuth.ts +3 -3
  94. package/src/comments/threadstore/ThreadStore.ts +1 -1
  95. package/src/comments/threadstore/TipTapThreadStore.ts +10 -10
  96. package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +4 -4
  97. package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +2 -2
  98. package/src/comments/threadstore/yjs/YjsThreadStore.ts +14 -14
  99. package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +1 -1
  100. package/src/comments/threadstore/yjs/yjsHelpers.ts +6 -6
  101. package/src/editor/Block.css +35 -1
  102. package/src/editor/BlockNoteEditor.test.ts +10 -3
  103. package/src/editor/BlockNoteEditor.ts +95 -38
  104. package/src/editor/BlockNoteExtension.ts +26 -0
  105. package/src/editor/BlockNoteExtensions.ts +38 -22
  106. package/src/editor/BlockNoteSchema.ts +4 -4
  107. package/src/editor/BlockNoteTipTapEditor.ts +33 -12
  108. package/src/editor/README.md +1 -1
  109. package/src/editor/cursorPositionTypes.ts +1 -1
  110. package/src/editor/editor.css +15 -3
  111. package/src/editor/selectionTypes.ts +1 -1
  112. package/src/editor/transformPasted.ts +2 -2
  113. package/src/exporter/Exporter.ts +5 -5
  114. package/src/exporter/mapping.ts +7 -7
  115. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
  116. package/src/extensions/Collaboration/CursorPlugin.ts +15 -9
  117. package/src/extensions/Collaboration/ForkYDocPlugin.test.ts +166 -0
  118. package/src/extensions/Collaboration/ForkYDocPlugin.ts +174 -0
  119. package/src/extensions/Collaboration/SyncPlugin.ts +7 -4
  120. package/src/extensions/Collaboration/UndoPlugin.ts +7 -4
  121. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +30 -0
  122. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +30 -0
  123. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -0
  124. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -0
  125. package/src/extensions/Comments/CommentsPlugin.ts +80 -75
  126. package/src/extensions/Comments/userstore/UserStore.ts +2 -2
  127. package/src/extensions/FilePanel/FilePanelPlugin.ts +56 -55
  128. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +60 -30
  129. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +26 -26
  130. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +33 -32
  131. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +45 -42
  132. package/src/extensions/Placeholder/PlaceholderPlugin.ts +113 -110
  133. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +179 -170
  134. package/src/extensions/README.md +1 -1
  135. package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +22 -19
  136. package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
  137. package/src/extensions/SideMenu/SideMenuPlugin.ts +49 -48
  138. package/src/extensions/SideMenu/dragging.ts +8 -8
  139. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +176 -176
  140. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
  141. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +16 -16
  142. package/src/extensions/Suggestions/SuggestionMarks.ts +175 -0
  143. package/src/extensions/TableHandles/TableHandlesPlugin.ts +199 -195
  144. package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
  145. package/src/extensions/UniqueID/UniqueID.ts +6 -6
  146. package/src/extensions/getDraggableBlockFromElement.ts +1 -1
  147. package/src/fonts/inter.css +18 -9
  148. package/src/i18n/locales/ar.ts +0 -1
  149. package/src/i18n/locales/de.ts +0 -1
  150. package/src/i18n/locales/en.ts +0 -1
  151. package/src/i18n/locales/es.ts +0 -1
  152. package/src/i18n/locales/fr.ts +0 -1
  153. package/src/i18n/locales/hr.ts +0 -1
  154. package/src/i18n/locales/is.ts +0 -1
  155. package/src/i18n/locales/it.ts +0 -1
  156. package/src/i18n/locales/ja.ts +0 -1
  157. package/src/i18n/locales/ko.ts +0 -1
  158. package/src/i18n/locales/nl.ts +0 -1
  159. package/src/i18n/locales/no.ts +0 -1
  160. package/src/i18n/locales/pl.ts +0 -1
  161. package/src/i18n/locales/pt.ts +0 -1
  162. package/src/i18n/locales/ru.ts +0 -1
  163. package/src/i18n/locales/sk.ts +0 -1
  164. package/src/i18n/locales/uk.ts +0 -1
  165. package/src/i18n/locales/vi.ts +0 -1
  166. package/src/i18n/locales/zh-tw.ts +0 -1
  167. package/src/i18n/locales/zh.ts +0 -1
  168. package/src/index.ts +18 -8
  169. package/src/locales.ts +1 -1
  170. package/src/pm-nodes/BlockContainer.ts +1 -1
  171. package/src/pm-nodes/BlockGroup.ts +2 -2
  172. package/src/pm-nodes/Doc.ts +5 -4
  173. package/src/schema/README.md +1 -1
  174. package/src/schema/blocks/createSpec.ts +14 -14
  175. package/src/schema/blocks/internal.ts +17 -17
  176. package/src/schema/blocks/types.ts +25 -25
  177. package/src/schema/inlineContent/createSpec.ts +16 -20
  178. package/src/schema/inlineContent/internal.ts +9 -9
  179. package/src/schema/inlineContent/types.ts +26 -26
  180. package/src/schema/propTypes.ts +8 -8
  181. package/src/schema/styles/createSpec.ts +2 -2
  182. package/src/schema/styles/internal.ts +7 -7
  183. package/src/schema/styles/types.ts +2 -2
  184. package/src/util/EventEmitter.ts +4 -4
  185. package/src/util/README.md +1 -1
  186. package/src/util/combineByGroup.ts +1 -1
  187. package/src/util/table.ts +33 -30
  188. package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +1 -1
  189. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +4 -0
  190. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
  191. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +3 -1
  192. package/types/src/api/blockManipulation/selections/selection.d.ts +10 -0
  193. package/types/src/api/blockManipulation/selections/textCursorPosition.d.ts +5 -0
  194. package/types/src/api/blockManipulation/transactions.test.d.ts +0 -0
  195. package/types/src/api/clipboard/clipboardExternal.test.d.ts +1 -0
  196. package/types/src/api/clipboard/clipboardInternal.test.d.ts +1 -0
  197. package/types/src/api/clipboard/testUtil.d.ts +541 -0
  198. package/types/src/api/exporters/html/htmlConversion.test.d.ts +1 -0
  199. package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +1 -0
  200. package/types/src/api/nodeConversions/nodeConversions.test.d.ts +1 -0
  201. package/types/src/api/nodeConversions/nodeToBlock.d.ts +39 -2
  202. package/types/src/api/parsers/html/parseHTML.test.d.ts +1 -0
  203. package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +1 -0
  204. package/types/src/api/pmUtil.d.ts +3 -3
  205. package/types/src/api/testUtil/cases/customBlocks.d.ts +670 -0
  206. package/types/src/api/testUtil/cases/customInlineContent.d.ts +558 -0
  207. package/types/src/api/testUtil/cases/customStyles.d.ts +552 -0
  208. package/types/src/api/testUtil/cases/defaultSchema.d.ts +4 -0
  209. package/types/src/api/testUtil/index.d.ts +14 -0
  210. package/types/src/api/testUtil/partialBlockTestUtil.d.ts +9 -0
  211. package/types/src/api/testUtil/paste.d.ts +2 -0
  212. package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +6 -0
  213. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +9 -1
  214. package/types/src/editor/BlockNoteEditor.d.ts +58 -10
  215. package/types/src/editor/BlockNoteExtension.d.ts +9 -0
  216. package/types/src/editor/BlockNoteExtensions.d.ts +2 -2
  217. package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
  218. package/types/src/extensions/Collaboration/CursorPlugin.d.ts +3 -3
  219. package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +41 -0
  220. package/types/src/extensions/Collaboration/ForkYDocPlugin.test.d.ts +1 -0
  221. package/types/src/extensions/Collaboration/SyncPlugin.d.ts +3 -3
  222. package/types/src/extensions/Collaboration/UndoPlugin.d.ts +3 -3
  223. package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +17 -0
  224. package/types/src/extensions/Comments/CommentsPlugin.d.ts +2 -4
  225. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +3 -4
  226. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +5 -5
  227. package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +3 -4
  228. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -3
  229. package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +2 -3
  230. package/types/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.d.ts +2 -3
  231. package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +2 -3
  232. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +3 -4
  233. package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +2 -4
  234. package/types/src/extensions/Suggestions/SuggestionMarks.d.ts +4 -0
  235. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +5 -6
  236. package/types/src/i18n/locales/en.d.ts +0 -1
  237. package/types/src/i18n/locales/sk.d.ts +0 -1
  238. package/types/src/index.d.ts +15 -8
  239. package/dist/en-B7ycW7c8.js.map +0 -1
  240. package/dist/en-D4taoCs4.cjs.map +0 -1
  241. package/dist/tsconfig.tsbuildinfo +0 -1
  242. package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +0 -844
  243. package/src/api/blockManipulation/selections/selection.test.ts +0 -72
  244. package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +0 -316
  245. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +0 -74
@@ -17,7 +17,7 @@ function addAttributesAndRemoveClasses(element: HTMLElement) {
17
17
  // Removes all BlockNote specific class names.
18
18
  const className =
19
19
  Array.from(element.classList).filter(
20
- (className) => !className.startsWith("bn-")
20
+ (className) => !className.startsWith("bn-"),
21
21
  ) || [];
22
22
 
23
23
  if (className.length > 0) {
@@ -30,12 +30,12 @@ function addAttributesAndRemoveClasses(element: HTMLElement) {
30
30
  export function serializeInlineContentExternalHTML<
31
31
  BSchema extends BlockSchema,
32
32
  I extends InlineContentSchema,
33
- S extends StyleSchema
33
+ S extends StyleSchema,
34
34
  >(
35
35
  editor: BlockNoteEditor<any, I, S>,
36
36
  blockContent: PartialBlock<BSchema, I, S>["content"],
37
37
  serializer: DOMSerializer,
38
- options?: { document?: Document }
38
+ options?: { document?: Document },
39
39
  ) {
40
40
  let nodes: any;
41
41
 
@@ -72,7 +72,7 @@ export function serializeInlineContentExternalHTML<
72
72
  function serializeBlock<
73
73
  BSchema extends BlockSchema,
74
74
  I extends InlineContentSchema,
75
- S extends StyleSchema
75
+ S extends StyleSchema,
76
76
  >(
77
77
  fragment: DocumentFragment,
78
78
  editor: BlockNoteEditor<BSchema, I, S>,
@@ -80,7 +80,7 @@ function serializeBlock<
80
80
  serializer: DOMSerializer,
81
81
  orderedListItemBlockTypes: Set<string>,
82
82
  unorderedListItemBlockTypes: Set<string>,
83
- options?: { document?: Document }
83
+ options?: { document?: Document },
84
84
  ) {
85
85
  const doc = options?.document ?? document;
86
86
  const BC_NODE = editor.pmSchema.nodes["blockContainer"];
@@ -90,7 +90,7 @@ function serializeBlock<
90
90
  if (!block.props) {
91
91
  props = {};
92
92
  for (const [name, spec] of Object.entries(
93
- editor.schema.blockSchema[block.type as any].propSchema
93
+ editor.schema.blockSchema[block.type as any].propSchema,
94
94
  )) {
95
95
  if (spec.default !== undefined) {
96
96
  (props as any)[name] = spec.default;
@@ -102,7 +102,7 @@ function serializeBlock<
102
102
  BC_NODE.create({
103
103
  id: block.id,
104
104
  ...props,
105
- })
105
+ }),
106
106
  ) as {
107
107
  dom: HTMLElement;
108
108
  contentDOM?: HTMLElement;
@@ -130,7 +130,7 @@ function serializeBlock<
130
130
  attr.name !== "data-node-type" &&
131
131
  attr.name !== "data-id" &&
132
132
  attr.name !== "data-index" &&
133
- attr.name !== "data-editable"
133
+ attr.name !== "data-editable",
134
134
  );
135
135
 
136
136
  // ret.dom = ret.dom.firstChild! as any;
@@ -149,7 +149,7 @@ function serializeBlock<
149
149
  editor,
150
150
  block.content as any, // TODO
151
151
  serializer,
152
- options
152
+ options,
153
153
  );
154
154
 
155
155
  ret.contentDOM.appendChild(ic);
@@ -187,7 +187,7 @@ function serializeBlock<
187
187
  serializer,
188
188
  orderedListItemBlockTypes,
189
189
  unorderedListItemBlockTypes,
190
- options
190
+ options,
191
191
  );
192
192
  if (
193
193
  fragment.lastChild?.nodeName === "UL" ||
@@ -215,7 +215,7 @@ function serializeBlock<
215
215
  const serializeBlocksToFragment = <
216
216
  BSchema extends BlockSchema,
217
217
  I extends InlineContentSchema,
218
- S extends StyleSchema
218
+ S extends StyleSchema,
219
219
  >(
220
220
  fragment: DocumentFragment,
221
221
  editor: BlockNoteEditor<BSchema, I, S>,
@@ -223,7 +223,7 @@ const serializeBlocksToFragment = <
223
223
  serializer: DOMSerializer,
224
224
  orderedListItemBlockTypes: Set<string>,
225
225
  unorderedListItemBlockTypes: Set<string>,
226
- options?: { document?: Document }
226
+ options?: { document?: Document },
227
227
  ) => {
228
228
  for (const block of blocks) {
229
229
  serializeBlock(
@@ -233,7 +233,7 @@ const serializeBlocksToFragment = <
233
233
  serializer,
234
234
  orderedListItemBlockTypes,
235
235
  unorderedListItemBlockTypes,
236
- options
236
+ options,
237
237
  );
238
238
  }
239
239
  };
@@ -241,14 +241,14 @@ const serializeBlocksToFragment = <
241
241
  export const serializeBlocksExternalHTML = <
242
242
  BSchema extends BlockSchema,
243
243
  I extends InlineContentSchema,
244
- S extends StyleSchema
244
+ S extends StyleSchema,
245
245
  >(
246
246
  editor: BlockNoteEditor<BSchema, I, S>,
247
247
  blocks: PartialBlock<BSchema, I, S>[],
248
248
  serializer: DOMSerializer,
249
249
  orderedListItemBlockTypes: Set<string>,
250
250
  unorderedListItemBlockTypes: Set<string>,
251
- options?: { document?: Document }
251
+ options?: { document?: Document },
252
252
  ) => {
253
253
  const doc = options?.document ?? document;
254
254
  const fragment = doc.createDocumentFragment();
@@ -260,7 +260,7 @@ export const serializeBlocksExternalHTML = <
260
260
  serializer,
261
261
  orderedListItemBlockTypes,
262
262
  unorderedListItemBlockTypes,
263
- options
263
+ options,
264
264
  );
265
265
  return fragment;
266
266
  };
@@ -16,13 +16,13 @@ import {
16
16
  export function serializeInlineContentInternalHTML<
17
17
  BSchema extends BlockSchema,
18
18
  I extends InlineContentSchema,
19
- S extends StyleSchema
19
+ S extends StyleSchema,
20
20
  >(
21
21
  editor: BlockNoteEditor<any, I, S>,
22
22
  blockContent: PartialBlock<BSchema, I, S>["content"],
23
23
  serializer: DOMSerializer,
24
24
  blockType?: string,
25
- options?: { document?: Document }
25
+ options?: { document?: Document },
26
26
  ) {
27
27
  let nodes: any;
28
28
 
@@ -50,13 +50,13 @@ export function serializeInlineContentInternalHTML<
50
50
  function serializeBlock<
51
51
  BSchema extends BlockSchema,
52
52
  I extends InlineContentSchema,
53
- S extends StyleSchema
53
+ S extends StyleSchema,
54
54
  >(
55
55
  editor: BlockNoteEditor<BSchema, I, S>,
56
56
  block: PartialBlock<BSchema, I, S>,
57
57
  serializer: DOMSerializer,
58
58
  listIndex: number,
59
- options?: { document?: Document }
59
+ options?: { document?: Document },
60
60
  ) {
61
61
  const BC_NODE = editor.pmSchema.nodes["blockContainer"];
62
62
 
@@ -65,7 +65,7 @@ function serializeBlock<
65
65
  if (!block.props) {
66
66
  props = {};
67
67
  for (const [name, spec] of Object.entries(
68
- editor.schema.blockSchema[block.type as any].propSchema
68
+ editor.schema.blockSchema[block.type as any].propSchema,
69
69
  )) {
70
70
  if (spec.default !== undefined) {
71
71
  (props as any)[name] = spec.default;
@@ -92,7 +92,7 @@ function serializeBlock<
92
92
  block.content as any, // TODO
93
93
  serializer,
94
94
  block.type,
95
- options
95
+ options,
96
96
  );
97
97
  ret.contentDOM.appendChild(ic);
98
98
  }
@@ -105,7 +105,7 @@ function serializeBlock<
105
105
  editor,
106
106
  block.children,
107
107
  serializer,
108
- options
108
+ options,
109
109
  );
110
110
 
111
111
  ret.contentDOM?.append(fragment);
@@ -118,7 +118,7 @@ function serializeBlock<
118
118
  BC_NODE.create({
119
119
  id: block.id,
120
120
  ...props,
121
- })
121
+ }),
122
122
  ) as {
123
123
  dom: HTMLElement;
124
124
  contentDOM?: HTMLElement;
@@ -128,7 +128,7 @@ function serializeBlock<
128
128
 
129
129
  if (block.children && block.children.length > 0) {
130
130
  bc.contentDOM?.appendChild(
131
- serializeBlocksInternalHTML(editor, block.children, serializer, options)
131
+ serializeBlocksInternalHTML(editor, block.children, serializer, options),
132
132
  );
133
133
  }
134
134
  return bc.dom;
@@ -137,12 +137,12 @@ function serializeBlock<
137
137
  function serializeBlocks<
138
138
  BSchema extends BlockSchema,
139
139
  I extends InlineContentSchema,
140
- S extends StyleSchema
140
+ S extends StyleSchema,
141
141
  >(
142
142
  editor: BlockNoteEditor<BSchema, I, S>,
143
143
  blocks: PartialBlock<BSchema, I, S>[],
144
144
  serializer: DOMSerializer,
145
- options?: { document?: Document }
145
+ options?: { document?: Document },
146
146
  ) {
147
147
  const doc = options?.document ?? document;
148
148
  const fragment = doc.createDocumentFragment();
@@ -159,7 +159,7 @@ function serializeBlocks<
159
159
  block,
160
160
  serializer,
161
161
  listIndex,
162
- options
162
+ options,
163
163
  );
164
164
  fragment.appendChild(blockDOM);
165
165
  }
@@ -170,12 +170,12 @@ function serializeBlocks<
170
170
  export const serializeBlocksInternalHTML = <
171
171
  BSchema extends BlockSchema,
172
172
  I extends InlineContentSchema,
173
- S extends StyleSchema
173
+ S extends StyleSchema,
174
174
  >(
175
175
  editor: BlockNoteEditor<BSchema, I, S>,
176
176
  blocks: PartialBlock<BSchema, I, S>[],
177
177
  serializer: DOMSerializer,
178
- options?: { document?: Document }
178
+ options?: { document?: Document },
179
179
  ) => {
180
180
  const BG_NODE = editor.pmSchema.nodes["blockGroup"];
181
181
 
@@ -21,7 +21,7 @@ export function cleanHTMLToMarkdown(cleanHTMLString: string) {
21
21
 
22
22
  if (!deps) {
23
23
  throw new Error(
24
- "cleanHTMLToMarkdown requires ESM dependencies to be initialized"
24
+ "cleanHTMLToMarkdown requires ESM dependencies to be initialized",
25
25
  );
26
26
  }
27
27
 
@@ -43,12 +43,12 @@ export function cleanHTMLToMarkdown(cleanHTMLString: string) {
43
43
  export async function blocksToMarkdown<
44
44
  BSchema extends BlockSchema,
45
45
  I extends InlineContentSchema,
46
- S extends StyleSchema
46
+ S extends StyleSchema,
47
47
  >(
48
48
  blocks: PartialBlock<BSchema, I, S>[],
49
49
  schema: Schema,
50
50
  editor: BlockNoteEditor<BSchema, I, S>,
51
- options: { document?: Document }
51
+ options: { document?: Document },
52
52
  ): Promise<string> {
53
53
  await initializeESMDependencies();
54
54
  const exporter = createExternalHTMLExporter(schema, editor);
@@ -11,7 +11,7 @@ export function addSpacesToCheckboxes() {
11
11
 
12
12
  if (!deps) {
13
13
  throw new Error(
14
- "addSpacesToCheckboxes requires ESM dependencies to be initialized"
14
+ "addSpacesToCheckboxes requires ESM dependencies to be initialized",
15
15
  );
16
16
  }
17
17
 
@@ -38,8 +38,8 @@ export function addSpacesToCheckboxes() {
38
38
  0,
39
39
  0,
40
40
  deps.hastUtilFromDom.fromDom(
41
- document.createTextNode(" ")
42
- ) as HASTElement
41
+ document.createTextNode(" "),
42
+ ) as HASTElement,
43
43
  );
44
44
  } else {
45
45
  helper(child as HASTParent);
@@ -101,7 +101,7 @@ export function getNearestBlockPos(doc: Node, pos: number) {
101
101
 
102
102
  const resolvedPos = doc.resolve(
103
103
  allBlockContainerPositions.find((position) => position >= pos) ||
104
- allBlockContainerPositions[allBlockContainerPositions.length - 1]
104
+ allBlockContainerPositions[allBlockContainerPositions.length - 1],
105
105
  );
106
106
  return {
107
107
  posBeforeNode: resolvedPos.pos,
@@ -122,11 +122,11 @@ export function getNearestBlockPos(doc: Node, pos: number) {
122
122
  */
123
123
  export function getBlockInfoWithManualOffset(
124
124
  node: Node,
125
- bnBlockBeforePosOffset: number
125
+ bnBlockBeforePosOffset: number,
126
126
  ): BlockInfo {
127
127
  if (!node.type.isInGroup("bnBlock")) {
128
128
  throw new Error(
129
- `Attempted to get bnBlock node at position but found node of different type ${node.type}`
129
+ `Attempted to get bnBlock node at position but found node of different type ${node.type.name}`,
130
130
  );
131
131
  }
132
132
 
@@ -171,7 +171,7 @@ export function getBlockInfoWithManualOffset(
171
171
 
172
172
  if (!blockContent) {
173
173
  throw new Error(
174
- `blockContainer node does not contain a blockContent node in its children: ${bnBlockNode}`
174
+ `blockContainer node does not contain a blockContent node in its children: ${bnBlockNode}`,
175
175
  );
176
176
  }
177
177
 
@@ -185,7 +185,7 @@ export function getBlockInfoWithManualOffset(
185
185
  } else {
186
186
  if (!bnBlock.node.type.isInGroup("childContainer")) {
187
187
  throw new Error(
188
- `bnBlock node is not in the childContainer group: ${bnBlock.node}`
188
+ `bnBlock node is not in the childContainer group: ${bnBlock.node}`,
189
189
  );
190
190
  }
191
191
 
@@ -222,7 +222,7 @@ export function getBlockInfo(posInfo: { posBeforeNode: number; node: Node }) {
222
222
  export function getBlockInfoFromResolvedPos(resolvedPos: ResolvedPos) {
223
223
  if (!resolvedPos.nodeAfter) {
224
224
  throw new Error(
225
- `Attempted to get blockContainer node at position ${resolvedPos.pos} but a node at this position does not exist`
225
+ `Attempted to get blockContainer node at position ${resolvedPos.pos} but a node at this position does not exist`,
226
226
  );
227
227
  }
228
228
  return getBlockInfoWithManualOffset(resolvedPos.nodeAfter, resolvedPos.pos);
@@ -29,11 +29,11 @@ function styledTextToNodes<T extends StyleSchema>(
29
29
  styledText: StyledText<T>,
30
30
  schema: Schema,
31
31
  styleSchema: T,
32
- blockType?: string
32
+ blockType?: string,
33
33
  ): Node[] {
34
34
  const marks: Mark[] = [];
35
35
 
36
- for (const [style, value] of Object.entries(styledText.styles)) {
36
+ for (const [style, value] of Object.entries(styledText.styles || {})) {
37
37
  const config = styleSchema[style];
38
38
  if (!config) {
39
39
  throw new Error(`style ${style} not found in styleSchema`);
@@ -51,7 +51,9 @@ function styledTextToNodes<T extends StyleSchema>(
51
51
  const parseHardBreaks = !blockType || !schema.nodes[blockType].spec.code;
52
52
 
53
53
  if (!parseHardBreaks) {
54
- return [schema.text(styledText.text, marks)];
54
+ return styledText.text.length > 0
55
+ ? [schema.text(styledText.text, marks)]
56
+ : [];
55
57
  }
56
58
 
57
59
  return (
@@ -79,7 +81,7 @@ function styledTextToNodes<T extends StyleSchema>(
79
81
  function linkToNodes(
80
82
  link: PartialLink<StyleSchema>,
81
83
  schema: Schema,
82
- styleSchema: StyleSchema
84
+ styleSchema: StyleSchema,
83
85
  ): Node[] {
84
86
  const linkMark = schema.marks.link.create({
85
87
  href: link.href,
@@ -95,7 +97,7 @@ function linkToNodes(
95
97
  return node;
96
98
  }
97
99
  throw new Error("unexpected node type");
98
- }
100
+ },
99
101
  );
100
102
  }
101
103
 
@@ -107,7 +109,7 @@ function styledTextArrayToNodes<S extends StyleSchema>(
107
109
  content: string | StyledText<S>[],
108
110
  schema: Schema,
109
111
  styleSchema: S,
110
- blockType?: string
112
+ blockType?: string,
111
113
  ): Node[] {
112
114
  const nodes: Node[] = [];
113
115
 
@@ -117,15 +119,15 @@ function styledTextArrayToNodes<S extends StyleSchema>(
117
119
  { type: "text", text: content, styles: {} },
118
120
  schema,
119
121
  styleSchema,
120
- blockType
121
- )
122
+ blockType,
123
+ ),
122
124
  );
123
125
  return nodes;
124
126
  }
125
127
 
126
128
  for (const styledText of content) {
127
129
  nodes.push(
128
- ...styledTextToNodes(styledText, schema, styleSchema, blockType)
130
+ ...styledTextToNodes(styledText, schema, styleSchema, blockType),
129
131
  );
130
132
  }
131
133
  return nodes;
@@ -136,29 +138,29 @@ function styledTextArrayToNodes<S extends StyleSchema>(
136
138
  */
137
139
  export function inlineContentToNodes<
138
140
  I extends InlineContentSchema,
139
- S extends StyleSchema
141
+ S extends StyleSchema,
140
142
  >(
141
143
  blockContent: PartialInlineContent<I, S>,
142
144
  schema: Schema,
143
145
  blockType?: string,
144
- styleSchema: S = getStyleSchema(schema)
146
+ styleSchema: S = getStyleSchema(schema),
145
147
  ): Node[] {
146
148
  const nodes: Node[] = [];
147
149
 
148
150
  for (const content of blockContent) {
149
151
  if (typeof content === "string") {
150
152
  nodes.push(
151
- ...styledTextArrayToNodes(content, schema, styleSchema, blockType)
153
+ ...styledTextArrayToNodes(content, schema, styleSchema, blockType),
152
154
  );
153
155
  } else if (isPartialLinkInlineContent(content)) {
154
156
  nodes.push(...linkToNodes(content, schema, styleSchema));
155
157
  } else if (isStyledTextInlineContent(content)) {
156
158
  nodes.push(
157
- ...styledTextArrayToNodes([content], schema, styleSchema, blockType)
159
+ ...styledTextArrayToNodes([content], schema, styleSchema, blockType),
158
160
  );
159
161
  } else {
160
162
  nodes.push(
161
- blockOrInlineContentToContentNode(content, schema, styleSchema)
163
+ blockOrInlineContentToContentNode(content, schema, styleSchema),
162
164
  );
163
165
  }
164
166
  }
@@ -170,11 +172,11 @@ export function inlineContentToNodes<
170
172
  */
171
173
  export function tableContentToNodes<
172
174
  I extends InlineContentSchema,
173
- S extends StyleSchema
175
+ S extends StyleSchema,
174
176
  >(
175
177
  tableContent: PartialTableContent<I, S>,
176
178
  schema: Schema,
177
- styleSchema: StyleSchema = getStyleSchema(schema)
179
+ styleSchema: StyleSchema = getStyleSchema(schema),
178
180
  ): Node[] {
179
181
  const rowNodes: Node[] = [];
180
182
  // Header rows and columns are used to determine the type of the cell
@@ -207,7 +209,7 @@ export function tableContentToNodes<
207
209
  row: rowIndex,
208
210
  col: cellIndex,
209
211
  },
210
- { type: "table", content: tableContent } as any
212
+ { type: "table", content: tableContent } as any,
211
213
  );
212
214
 
213
215
  // Assume the column width is the width of the cell at the absolute cell index
@@ -227,7 +229,7 @@ export function tableContentToNodes<
227
229
  cell.content,
228
230
  schema,
229
231
  "tableParagraph",
230
- styleSchema
232
+ styleSchema,
231
233
  );
232
234
  }
233
235
  const colspan = getColspan(cell);
@@ -244,7 +246,7 @@ export function tableContentToNodes<
244
246
  cell,
245
247
  schema,
246
248
  "tableParagraph",
247
- styleSchema
249
+ styleSchema,
248
250
  );
249
251
  }
250
252
 
@@ -255,10 +257,11 @@ export function tableContentToNodes<
255
257
  ...(isPartialTableCell(cell) ? cell.props : {}),
256
258
  colwidth,
257
259
  },
258
- schema.nodes["tableParagraph"].createChecked(attrs, content)
260
+ schema.nodes["tableParagraph"].createChecked(attrs, content),
259
261
  );
260
262
  columnNodes.push(cellNode);
261
263
  }
264
+
262
265
  const rowNode = schema.nodes["tableRow"].createChecked({}, columnNodes);
263
266
  rowNodes.push(rowNode);
264
267
  }
@@ -270,7 +273,7 @@ function blockOrInlineContentToContentNode(
270
273
  | PartialBlock<any, any, any>
271
274
  | PartialCustomInlineContentFromConfig<any, any>,
272
275
  schema: Schema,
273
- styleSchema: StyleSchema
276
+ styleSchema: StyleSchema,
274
277
  ) {
275
278
  let contentNode: Node;
276
279
  let type = block.type;
@@ -291,7 +294,7 @@ function blockOrInlineContentToContentNode(
291
294
  [block.content],
292
295
  schema,
293
296
  type,
294
- styleSchema
297
+ styleSchema,
295
298
  );
296
299
  contentNode = schema.nodes[type].createChecked(block.props, nodes);
297
300
  } else if (Array.isArray(block.content)) {
@@ -299,7 +302,7 @@ function blockOrInlineContentToContentNode(
299
302
  block.content,
300
303
  schema,
301
304
  type,
302
- styleSchema
305
+ styleSchema,
303
306
  );
304
307
  contentNode = schema.nodes[type].createChecked(block.props, nodes);
305
308
  } else if (block.content.type === "tableContent") {
@@ -317,7 +320,7 @@ function blockOrInlineContentToContentNode(
317
320
  export function blockToNode(
318
321
  block: PartialBlock<any, any, any>,
319
322
  schema: Schema,
320
- styleSchema: StyleSchema = getStyleSchema(schema)
323
+ styleSchema: StyleSchema = getStyleSchema(schema),
321
324
  ) {
322
325
  let id = block.id;
323
326
 
@@ -343,7 +346,7 @@ export function blockToNode(
343
346
  const contentNode = blockOrInlineContentToContentNode(
344
347
  block,
345
348
  schema,
346
- styleSchema
349
+ styleSchema,
347
350
  );
348
351
 
349
352
  const groupNode =
@@ -356,7 +359,7 @@ export function blockToNode(
356
359
  id: id,
357
360
  ...block.props,
358
361
  },
359
- groupNode ? [contentNode, groupNode] : contentNode
362
+ groupNode ? [contentNode, groupNode] : contentNode,
360
363
  );
361
364
  } else if (schema.nodes[block.type].isInGroup("bnBlock")) {
362
365
  // this is a bnBlock node like Column or ColumnList that directly translates to a prosemirror node
@@ -365,11 +368,11 @@ export function blockToNode(
365
368
  id: id,
366
369
  ...block.props,
367
370
  },
368
- children
371
+ children,
369
372
  );
370
373
  } else {
371
374
  throw new Error(
372
- `block type ${block.type} doesn't match blockContent or bnBlock group`
375
+ `block type ${block.type} doesn't match blockContent or bnBlock group`,
373
376
  );
374
377
  }
375
378
  }
@@ -14,7 +14,7 @@ import { nodeToBlock } from "./nodeToBlock.js";
14
14
  export function fragmentToBlocks<
15
15
  B extends BlockSchema,
16
16
  I extends InlineContentSchema,
17
- S extends StyleSchema
17
+ S extends StyleSchema,
18
18
  >(fragment: Fragment) {
19
19
  // first convert selection to blocknote-style blocks, and then
20
20
  // pass these to the exporter