@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
@@ -99,17 +99,17 @@ export function getBlockFromPos<
99
99
  Config extends BlockConfig,
100
100
  BSchema extends BlockSchemaWithBlock<BType, Config>,
101
101
  I extends InlineContentSchema,
102
- S extends StyleSchema
102
+ S extends StyleSchema,
103
103
  >(
104
104
  getPos: (() => number) | boolean,
105
105
  editor: BlockNoteEditor<BSchema, I, S>,
106
106
  tipTapEditor: Editor,
107
- type: BType
107
+ type: BType,
108
108
  ) {
109
109
  // Gets position of the node
110
110
  if (typeof getPos === "boolean") {
111
111
  throw new Error(
112
- "Cannot find node position as getPos is a boolean, not a function."
112
+ "Cannot find node position as getPos is a boolean, not a function.",
113
113
  );
114
114
  }
115
115
  const pos = getPos();
@@ -142,7 +142,7 @@ export function getBlockFromPos<
142
142
  // an `inlineContent` class to it.
143
143
  export function wrapInBlockStructure<
144
144
  BType extends string,
145
- PSchema extends PropSchema
145
+ PSchema extends PropSchema,
146
146
  >(
147
147
  element: {
148
148
  dom: HTMLElement;
@@ -153,7 +153,7 @@ export function wrapInBlockStructure<
153
153
  blockProps: Props<PSchema>,
154
154
  propSchema: PSchema,
155
155
  isFileBlock = false,
156
- domAttributes?: Record<string, string>
156
+ domAttributes?: Record<string, string>,
157
157
  ): {
158
158
  dom: HTMLElement;
159
159
  contentDOM?: HTMLElement;
@@ -173,7 +173,7 @@ export function wrapInBlockStructure<
173
173
  // Sets blockContent class
174
174
  blockContent.className = mergeCSSClasses(
175
175
  "bn-block-content",
176
- domAttributes?.class || ""
176
+ domAttributes?.class || "",
177
177
  );
178
178
  // Sets content type attribute
179
179
  blockContent.setAttribute("data-content-type", blockType);
@@ -197,7 +197,7 @@ export function wrapInBlockStructure<
197
197
  if (element.contentDOM !== undefined) {
198
198
  element.contentDOM.className = mergeCSSClasses(
199
199
  "bn-inline-content",
200
- element.contentDOM.className
200
+ element.contentDOM.className,
201
201
  );
202
202
  }
203
203
 
@@ -215,7 +215,7 @@ type StronglyTypedTipTapNode<
215
215
  | "tableRow+"
216
216
  | "blockContainer+"
217
217
  | "column column+"
218
- | ""
218
+ | "",
219
219
  > = Node & { name: Name; config: { content: Content } };
220
220
 
221
221
  export function createStronglyTypedTiptapNode<
@@ -225,7 +225,7 @@ export function createStronglyTypedTiptapNode<
225
225
  | "tableRow+"
226
226
  | "blockContainer+"
227
227
  | "column column+"
228
- | ""
228
+ | "",
229
229
  >(config: NodeConfig & { name: Name; content: Content }) {
230
230
  return Node.create(config) as StronglyTypedTipTapNode<Name, Content>; // force re-typing (should be safe as it's type-checked from the config)
231
231
  }
@@ -239,7 +239,7 @@ export function createInternalBlockSpec<T extends BlockConfig>(
239
239
  any,
240
240
  InlineContentSchema,
241
241
  StyleSchema
242
- >
242
+ >,
243
243
  ) {
244
244
  return {
245
245
  config,
@@ -249,7 +249,7 @@ export function createInternalBlockSpec<T extends BlockConfig>(
249
249
 
250
250
  export function createBlockSpecFromStronglyTypedTiptapNode<
251
251
  T extends Node,
252
- P extends PropSchema
252
+ P extends PropSchema,
253
253
  >(node: T, propSchema: P, requiredExtensions?: Array<Extension | Node>) {
254
254
  return createInternalBlockSpec(
255
255
  {
@@ -257,12 +257,12 @@ export function createBlockSpecFromStronglyTypedTiptapNode<
257
257
  content: (node.config.content === "inline*"
258
258
  ? "inline"
259
259
  : node.config.content === "tableRow+"
260
- ? "table"
261
- : "none") as T["config"]["content"] extends "inline*"
260
+ ? "table"
261
+ : "none") as T["config"]["content"] extends "inline*"
262
262
  ? "inline"
263
263
  : T["config"]["content"] extends "tableRow+"
264
- ? "table"
265
- : "none",
264
+ ? "table"
265
+ : "none",
266
266
  propSchema,
267
267
  },
268
268
  {
@@ -271,12 +271,12 @@ export function createBlockSpecFromStronglyTypedTiptapNode<
271
271
  toInternalHTML: defaultBlockToHTML,
272
272
  toExternalHTML: defaultBlockToHTML,
273
273
  // parse: () => undefined, // parse rules are in node already
274
- }
274
+ },
275
275
  );
276
276
  }
277
277
 
278
278
  export function getBlockSchemaFromSpecs<T extends BlockSpecs>(specs: T) {
279
279
  return Object.fromEntries(
280
- Object.entries(specs).map(([key, value]) => [key, value.config])
280
+ Object.entries(specs).map(([key, value]) => [key, value.config]),
281
281
  ) as BlockSchemaFromSpecs<T>;
282
282
  }
@@ -74,7 +74,7 @@ export type TiptapBlockImplementation<
74
74
  T extends BlockConfig,
75
75
  B extends BlockSchema,
76
76
  I extends InlineContentSchema,
77
- S extends StyleSchema
77
+ S extends StyleSchema,
78
78
  > = {
79
79
  requiredExtensions?: Array<Extension | Node>;
80
80
  node: Node;
@@ -82,7 +82,7 @@ export type TiptapBlockImplementation<
82
82
  block: BlockFromConfigNoChildren<T, I, S> & {
83
83
  children: BlockNoDefaults<B, I, S>[];
84
84
  },
85
- editor: BlockNoteEditor<B, I, S>
85
+ editor: BlockNoteEditor<B, I, S>,
86
86
  ) => {
87
87
  dom: HTMLElement;
88
88
  contentDOM?: HTMLElement;
@@ -91,7 +91,7 @@ export type TiptapBlockImplementation<
91
91
  block: BlockFromConfigNoChildren<T, I, S> & {
92
92
  children: BlockNoDefaults<B, I, S>[];
93
93
  },
94
- editor: BlockNoteEditor<B, I, S>
94
+ editor: BlockNoteEditor<B, I, S>,
95
95
  ) => {
96
96
  dom: HTMLElement;
97
97
  contentDOM?: HTMLElement;
@@ -103,7 +103,7 @@ export type BlockSpec<
103
103
  T extends BlockConfig,
104
104
  B extends BlockSchema,
105
105
  I extends InlineContentSchema,
106
- S extends StyleSchema
106
+ S extends StyleSchema,
107
107
  > = {
108
108
  config: T;
109
109
  implementation: TiptapBlockImplementation<NoInfer<T>, B, I, S>;
@@ -141,7 +141,7 @@ export type BlockSchemaFromSpecs<T extends BlockSpecs> = {
141
141
 
142
142
  export type BlockSchemaWithBlock<
143
143
  BType extends string,
144
- C extends BlockConfig
144
+ C extends BlockConfig,
145
145
  > = {
146
146
  [k in BType]: C;
147
147
  };
@@ -156,7 +156,7 @@ export type TableCellProps = {
156
156
 
157
157
  export type TableCell<
158
158
  I extends InlineContentSchema,
159
- S extends StyleSchema = StyleSchema
159
+ S extends StyleSchema = StyleSchema,
160
160
  > = {
161
161
  type: "tableCell";
162
162
  props: TableCellProps;
@@ -165,7 +165,7 @@ export type TableCell<
165
165
 
166
166
  export type TableContent<
167
167
  I extends InlineContentSchema,
168
- S extends StyleSchema = StyleSchema
168
+ S extends StyleSchema = StyleSchema,
169
169
  > = {
170
170
  type: "tableContent";
171
171
  columnWidths: (number | undefined)[];
@@ -182,7 +182,7 @@ export type TableContent<
182
182
  export type BlockFromConfigNoChildren<
183
183
  B extends BlockConfig,
184
184
  I extends InlineContentSchema,
185
- S extends StyleSchema
185
+ S extends StyleSchema,
186
186
  > = {
187
187
  id: string;
188
188
  type: B["type"];
@@ -190,16 +190,16 @@ export type BlockFromConfigNoChildren<
190
190
  content: B["content"] extends "inline"
191
191
  ? InlineContent<I, S>[]
192
192
  : B["content"] extends "table"
193
- ? TableContent<I, S>
194
- : B["content"] extends "none"
195
- ? undefined
196
- : never;
193
+ ? TableContent<I, S>
194
+ : B["content"] extends "none"
195
+ ? undefined
196
+ : never;
197
197
  };
198
198
 
199
199
  export type BlockFromConfig<
200
200
  B extends BlockConfig,
201
201
  I extends InlineContentSchema,
202
- S extends StyleSchema
202
+ S extends StyleSchema,
203
203
  > = BlockFromConfigNoChildren<B, I, S> & {
204
204
  children: BlockNoDefaults<BlockSchema, I, S>[];
205
205
  };
@@ -210,7 +210,7 @@ export type BlockFromConfig<
210
210
  type BlocksWithoutChildren<
211
211
  BSchema extends BlockSchema,
212
212
  I extends InlineContentSchema,
213
- S extends StyleSchema
213
+ S extends StyleSchema,
214
214
  > = {
215
215
  [BType in keyof BSchema]: BlockFromConfigNoChildren<BSchema[BType], I, S>;
216
216
  };
@@ -220,7 +220,7 @@ type BlocksWithoutChildren<
220
220
  export type BlockNoDefaults<
221
221
  BSchema extends BlockSchema,
222
222
  I extends InlineContentSchema,
223
- S extends StyleSchema
223
+ S extends StyleSchema,
224
224
  > = BlocksWithoutChildren<BSchema, I, S>[keyof BSchema] & {
225
225
  children: BlockNoDefaults<BSchema, I, S>[];
226
226
  };
@@ -229,7 +229,7 @@ export type SpecificBlock<
229
229
  BSchema extends BlockSchema,
230
230
  BType extends keyof BSchema,
231
231
  I extends InlineContentSchema,
232
- S extends StyleSchema
232
+ S extends StyleSchema,
233
233
  > = BlocksWithoutChildren<BSchema, I, S>[BType] & {
234
234
  children: BlockNoDefaults<BSchema, I, S>[];
235
235
  };
@@ -243,7 +243,7 @@ export type SpecificBlock<
243
243
 
244
244
  export type PartialTableCell<
245
245
  I extends InlineContentSchema,
246
- S extends StyleSchema = StyleSchema
246
+ S extends StyleSchema = StyleSchema,
247
247
  > = {
248
248
  type: "tableCell";
249
249
  props?: Partial<TableCellProps>;
@@ -252,7 +252,7 @@ export type PartialTableCell<
252
252
 
253
253
  export type PartialTableContent<
254
254
  I extends InlineContentSchema,
255
- S extends StyleSchema = StyleSchema
255
+ S extends StyleSchema = StyleSchema,
256
256
  > = {
257
257
  type: "tableContent";
258
258
  columnWidths?: (number | undefined)[];
@@ -266,7 +266,7 @@ export type PartialTableContent<
266
266
  type PartialBlockFromConfigNoChildren<
267
267
  B extends BlockConfig,
268
268
  I extends InlineContentSchema,
269
- S extends StyleSchema
269
+ S extends StyleSchema,
270
270
  > = {
271
271
  id?: string;
272
272
  type?: B["type"];
@@ -274,14 +274,14 @@ type PartialBlockFromConfigNoChildren<
274
274
  content?: B["content"] extends "inline"
275
275
  ? PartialInlineContent<I, S>
276
276
  : B["content"] extends "table"
277
- ? PartialTableContent<I, S>
278
- : undefined;
277
+ ? PartialTableContent<I, S>
278
+ : undefined;
279
279
  };
280
280
 
281
281
  type PartialBlocksWithoutChildren<
282
282
  BSchema extends BlockSchema,
283
283
  I extends InlineContentSchema,
284
- S extends StyleSchema
284
+ S extends StyleSchema,
285
285
  > = {
286
286
  [BType in keyof BSchema]: PartialBlockFromConfigNoChildren<
287
287
  BSchema[BType],
@@ -293,7 +293,7 @@ type PartialBlocksWithoutChildren<
293
293
  export type PartialBlockNoDefaults<
294
294
  BSchema extends BlockSchema,
295
295
  I extends InlineContentSchema,
296
- S extends StyleSchema
296
+ S extends StyleSchema,
297
297
  > = PartialBlocksWithoutChildren<
298
298
  BSchema,
299
299
  I,
@@ -307,7 +307,7 @@ export type SpecificPartialBlock<
307
307
  BSchema extends BlockSchema,
308
308
  I extends InlineContentSchema,
309
309
  BType extends keyof BSchema,
310
- S extends StyleSchema
310
+ S extends StyleSchema,
311
311
  > = PartialBlocksWithoutChildren<BSchema, I, S>[BType] & {
312
312
  children?: BlockNoDefaults<BSchema, I, S>[];
313
313
  };
@@ -315,7 +315,7 @@ export type SpecificPartialBlock<
315
315
  export type PartialBlockFromConfig<
316
316
  B extends BlockConfig,
317
317
  I extends InlineContentSchema,
318
- S extends StyleSchema
318
+ S extends StyleSchema,
319
319
  > = PartialBlockFromConfigNoChildren<B, I, S> & {
320
320
  children?: BlockNoDefaults<BlockSchema, I, S>[];
321
321
  };
@@ -25,7 +25,7 @@ export type CustomInlineContentImplementation<
25
25
  T extends CustomInlineContentConfig,
26
26
  // B extends BlockSchema,
27
27
  // I extends InlineContentSchema,
28
- S extends StyleSchema
28
+ S extends StyleSchema,
29
29
  > = {
30
30
  render: (
31
31
  /**
@@ -33,14 +33,14 @@ export type CustomInlineContentImplementation<
33
33
  */
34
34
  inlineContent: InlineContentFromConfig<T, S>,
35
35
  updateInlineContent: (
36
- update: PartialCustomInlineContentFromConfig<T, S>
36
+ update: PartialCustomInlineContentFromConfig<T, S>,
37
37
  ) => void,
38
38
  /**
39
39
  * The BlockNote editor instance
40
40
  * This is typed generically. If you want an editor with your custom schema, you need to
41
41
  * cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
42
42
  */
43
- editor: BlockNoteEditor<any, any, S>
43
+ editor: BlockNoteEditor<any, any, S>,
44
44
  // (note) if we want to fix the manual cast, we need to prevent circular references and separate block definition and render implementations
45
45
  // or allow manually passing <BSchema>, but that's not possible without passing the other generics because Typescript doesn't support partial inferred generics
46
46
  ) => {
@@ -51,7 +51,7 @@ export type CustomInlineContentImplementation<
51
51
  };
52
52
 
53
53
  export function getInlineContentParseRules(
54
- config: CustomInlineContentConfig
54
+ config: CustomInlineContentConfig,
55
55
  ): TagParseRule[] {
56
56
  return [
57
57
  {
@@ -71,10 +71,10 @@ export function getInlineContentParseRules(
71
71
 
72
72
  export function createInlineContentSpec<
73
73
  T extends CustomInlineContentConfig,
74
- S extends StyleSchema
74
+ S extends StyleSchema,
75
75
  >(
76
76
  inlineContentConfig: T,
77
- inlineContentImplementation: CustomInlineContentImplementation<T, S>
77
+ inlineContentImplementation: CustomInlineContentImplementation<T, S>,
78
78
  ): InlineContentSpec<T> {
79
79
  const node = Node.create({
80
80
  name: inlineContentConfig.type,
@@ -105,31 +105,31 @@ export function createInlineContentSpec<
105
105
  nodeToCustomInlineContent(
106
106
  node,
107
107
  editor.schema.inlineContentSchema,
108
- editor.schema.styleSchema
108
+ editor.schema.styleSchema,
109
109
  ) as any as InlineContentFromConfig<T, S>, // TODO: fix cast
110
110
  () => {
111
111
  // No-op
112
112
  },
113
- editor
113
+ editor,
114
114
  );
115
115
 
116
116
  return addInlineContentAttributes(
117
117
  output,
118
118
  inlineContentConfig.type,
119
119
  node.attrs as Props<T["propSchema"]>,
120
- inlineContentConfig.propSchema
120
+ inlineContentConfig.propSchema,
121
121
  );
122
122
  },
123
123
 
124
124
  addNodeView() {
125
125
  return ({ node, getPos }) => {
126
- const editor = this.options.editor;
126
+ const editor = this.options.editor as BlockNoteEditor<any, any, S>;
127
127
 
128
128
  const output = inlineContentImplementation.render(
129
129
  nodeToCustomInlineContent(
130
130
  node,
131
131
  editor.schema.inlineContentSchema,
132
- editor.schema.styleSchema
132
+ editor.schema.styleSchema,
133
133
  ) as any as InlineContentFromConfig<T, S>, // TODO: fix cast
134
134
  (update) => {
135
135
  if (typeof getPos === "boolean") {
@@ -138,22 +138,18 @@ export function createInlineContentSpec<
138
138
 
139
139
  const content = inlineContentToNodes([update], editor.pmSchema);
140
140
 
141
- editor.dispatch(
142
- editor.prosemirrorView.state.tr.replaceWith(
143
- getPos(),
144
- getPos() + node.nodeSize,
145
- content
146
- )
141
+ editor.transact((tr) =>
142
+ tr.replaceWith(getPos(), getPos() + node.nodeSize, content),
147
143
  );
148
144
  },
149
- editor
145
+ editor,
150
146
  );
151
147
 
152
148
  return addInlineContentAttributes(
153
149
  output,
154
150
  inlineContentConfig.type,
155
151
  node.attrs as Props<T["propSchema"]>,
156
- inlineContentConfig.propSchema
152
+ inlineContentConfig.propSchema,
157
153
  );
158
154
  };
159
155
  },
@@ -161,6 +157,6 @@ export function createInlineContentSpec<
161
157
 
162
158
  return createInlineContentSpecFromTipTapNode(
163
159
  node,
164
- inlineContentConfig.propSchema
160
+ inlineContentConfig.propSchema,
165
161
  ) as InlineContentSpec<T>; // TODO: fix cast
166
162
  }
@@ -16,7 +16,7 @@ import {
16
16
  // is lost on internal copy & paste.
17
17
  export function addInlineContentAttributes<
18
18
  IType extends string,
19
- PSchema extends PropSchema
19
+ PSchema extends PropSchema,
20
20
  >(
21
21
  element: {
22
22
  dom: HTMLElement;
@@ -24,7 +24,7 @@ export function addInlineContentAttributes<
24
24
  },
25
25
  inlineContentType: IType,
26
26
  inlineContentProps: Props<PSchema>,
27
- propSchema: PSchema
27
+ propSchema: PSchema,
28
28
  ): {
29
29
  dom: HTMLElement;
30
30
  contentDOM?: HTMLElement;
@@ -52,9 +52,9 @@ export function addInlineContentAttributes<
52
52
 
53
53
  // see https://github.com/TypeCellOS/BlockNote/pull/435
54
54
  export function addInlineContentKeyboardShortcuts<
55
- T extends CustomInlineContentConfig
55
+ T extends CustomInlineContentConfig,
56
56
  >(
57
- config: T
57
+ config: T,
58
58
  ): {
59
59
  [p: string]: KeyboardShortcutCommand;
60
60
  } {
@@ -75,7 +75,7 @@ export function addInlineContentKeyboardShortcuts<
75
75
  // config and implementation that conform to the type of Config
76
76
  export function createInternalInlineContentSpec<T extends InlineContentConfig>(
77
77
  config: T,
78
- implementation: InlineContentImplementation<T>
78
+ implementation: InlineContentImplementation<T>,
79
79
  ) {
80
80
  return {
81
81
  config,
@@ -85,7 +85,7 @@ export function createInternalInlineContentSpec<T extends InlineContentConfig>(
85
85
 
86
86
  export function createInlineContentSpecFromTipTapNode<
87
87
  T extends Node,
88
- P extends PropSchema
88
+ P extends PropSchema,
89
89
  >(node: T, propSchema: P) {
90
90
  return createInternalInlineContentSpec(
91
91
  {
@@ -95,14 +95,14 @@ export function createInlineContentSpecFromTipTapNode<
95
95
  },
96
96
  {
97
97
  node,
98
- }
98
+ },
99
99
  );
100
100
  }
101
101
 
102
102
  export function getInlineContentSchemaFromSpecs<T extends InlineContentSpecs>(
103
- specs: T
103
+ specs: T,
104
104
  ) {
105
105
  return Object.fromEntries(
106
- Object.entries(specs).map(([key, value]) => [key, value.config])
106
+ Object.entries(specs).map(([key, value]) => [key, value.config]),
107
107
  ) as InlineContentSchemaFromSpecs<T>;
108
108
  }
@@ -44,55 +44,55 @@ export type InlineContentSchemaFromSpecs<T extends InlineContentSpecs> = {
44
44
 
45
45
  export type CustomInlineContentFromConfig<
46
46
  I extends CustomInlineContentConfig,
47
- S extends StyleSchema
47
+ S extends StyleSchema,
48
48
  > = {
49
49
  type: I["type"];
50
50
  props: Props<I["propSchema"]>;
51
51
  content: I["content"] extends "styled"
52
52
  ? StyledText<S>[]
53
53
  : I["content"] extends "plain"
54
- ? string
55
- : I["content"] extends "none"
56
- ? undefined
57
- : never;
54
+ ? string
55
+ : I["content"] extends "none"
56
+ ? undefined
57
+ : never;
58
58
  };
59
59
 
60
60
  export type InlineContentFromConfig<
61
61
  I extends InlineContentConfig,
62
- S extends StyleSchema
62
+ S extends StyleSchema,
63
63
  > = I extends "text"
64
64
  ? StyledText<S>
65
65
  : I extends "link"
66
- ? Link<S>
67
- : I extends CustomInlineContentConfig
68
- ? CustomInlineContentFromConfig<I, S>
69
- : never;
66
+ ? Link<S>
67
+ : I extends CustomInlineContentConfig
68
+ ? CustomInlineContentFromConfig<I, S>
69
+ : never;
70
70
 
71
71
  export type PartialCustomInlineContentFromConfig<
72
72
  I extends CustomInlineContentConfig,
73
- S extends StyleSchema
73
+ S extends StyleSchema,
74
74
  > = {
75
75
  type: I["type"];
76
76
  props?: Props<I["propSchema"]>;
77
77
  content?: I["content"] extends "styled"
78
78
  ? StyledText<S>[] | string
79
79
  : I["content"] extends "plain"
80
- ? string
81
- : I["content"] extends "none"
82
- ? undefined
83
- : never;
80
+ ? string
81
+ : I["content"] extends "none"
82
+ ? undefined
83
+ : never;
84
84
  };
85
85
 
86
86
  export type PartialInlineContentFromConfig<
87
87
  I extends InlineContentConfig,
88
- S extends StyleSchema
88
+ S extends StyleSchema,
89
89
  > = I extends "text"
90
90
  ? string | StyledText<S>
91
91
  : I extends "link"
92
- ? PartialLink<S>
93
- : I extends CustomInlineContentConfig
94
- ? PartialCustomInlineContentFromConfig<I, S>
95
- : never;
92
+ ? PartialLink<S>
93
+ : I extends CustomInlineContentConfig
94
+ ? PartialCustomInlineContentFromConfig<I, S>
95
+ : never;
96
96
 
97
97
  export type StyledText<T extends StyleSchema> = {
98
98
  type: "text";
@@ -112,33 +112,33 @@ export type PartialLink<T extends StyleSchema> = Omit<Link<T>, "content"> & {
112
112
 
113
113
  export type InlineContent<
114
114
  I extends InlineContentSchema,
115
- T extends StyleSchema
115
+ T extends StyleSchema,
116
116
  > = InlineContentFromConfig<I[keyof I], T>;
117
117
 
118
118
  type PartialInlineContentElement<
119
119
  I extends InlineContentSchema,
120
- T extends StyleSchema
120
+ T extends StyleSchema,
121
121
  > = PartialInlineContentFromConfig<I[keyof I], T>;
122
122
 
123
123
  export type PartialInlineContent<
124
124
  I extends InlineContentSchema,
125
- T extends StyleSchema
125
+ T extends StyleSchema,
126
126
  > = PartialInlineContentElement<I, T>[] | string;
127
127
 
128
128
  export function isLinkInlineContent<T extends StyleSchema>(
129
- content: InlineContent<any, T>
129
+ content: InlineContent<any, T>,
130
130
  ): content is Link<T> {
131
131
  return content.type === "link";
132
132
  }
133
133
 
134
134
  export function isPartialLinkInlineContent<T extends StyleSchema>(
135
- content: PartialInlineContentElement<any, T>
135
+ content: PartialInlineContentElement<any, T>,
136
136
  ): content is PartialLink<T> {
137
137
  return typeof content !== "string" && content.type === "link";
138
138
  }
139
139
 
140
140
  export function isStyledTextInlineContent<T extends StyleSchema>(
141
- content: PartialInlineContentElement<any, T>
141
+ content: PartialInlineContentElement<any, T>,
142
142
  ): content is StyledText<T> {
143
143
  return typeof content !== "string" && content.type === "text";
144
144
  }
@@ -39,14 +39,14 @@ export type Props<PSchema extends PropSchema> = {
39
39
  ? PSchema[PName]["values"][number]
40
40
  : boolean
41
41
  : PSchema[PName] extends { default: number } | { type: "number" }
42
- ? PSchema[PName]["values"] extends readonly number[]
43
- ? PSchema[PName]["values"][number]
44
- : number
45
- : PSchema[PName] extends { default: string } | { type: "string" }
46
- ? PSchema[PName]["values"] extends readonly string[]
47
- ? PSchema[PName]["values"][number]
48
- : string
49
- : never
42
+ ? PSchema[PName]["values"] extends readonly number[]
43
+ ? PSchema[PName]["values"][number]
44
+ : number
45
+ : PSchema[PName] extends { default: string } | { type: "string" }
46
+ ? PSchema[PName]["values"] extends readonly string[]
47
+ ? PSchema[PName]["values"][number]
48
+ : string
49
+ : never
50
50
  ) extends infer T
51
51
  ? PSchema[PName] extends { optional: true }
52
52
  ? T | undefined
@@ -42,7 +42,7 @@ export function getStyleParseRules(config: StyleConfig): ParseRule[] {
42
42
 
43
43
  export function createStyleSpec<T extends StyleConfig>(
44
44
  styleConfig: T,
45
- styleImplementation: CustomStyleImplementation<T>
45
+ styleImplementation: CustomStyleImplementation<T>,
46
46
  ): StyleSpec<T> {
47
47
  const mark = Mark.create({
48
48
  name: styleConfig.type,
@@ -75,7 +75,7 @@ export function createStyleSpec<T extends StyleConfig>(
75
75
  renderResult,
76
76
  styleConfig.type,
77
77
  mark.attrs.stringValue,
78
- styleConfig.propSchema
78
+ styleConfig.propSchema,
79
79
  );
80
80
  },
81
81
  });