@blocknote/core 0.52.1 → 0.54.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 (221) hide show
  1. package/dist/BlockNoteExtension-BJCLnwrE.cjs +2 -0
  2. package/dist/BlockNoteExtension-BJCLnwrE.cjs.map +1 -0
  3. package/dist/BlockNoteExtension-CbvDA0F7.js +80 -0
  4. package/dist/BlockNoteExtension-CbvDA0F7.js.map +1 -0
  5. package/dist/{UserStore-QbbPFj0z.js → UserStore-C4TzkGEn.js} +3 -3
  6. package/dist/{UserStore-DCG6lsla.cjs.map → UserStore-C4TzkGEn.js.map} +1 -1
  7. package/dist/{UserStore-DCG6lsla.cjs → UserStore-mj3fXW4D.cjs} +2 -2
  8. package/dist/UserStore-mj3fXW4D.cjs.map +1 -0
  9. package/dist/blocknote.cjs +1 -1
  10. package/dist/blocknote.js +6 -6
  11. package/dist/{blocks-CiuUGa1E.js → blocks-CzQLehlc.js} +695 -652
  12. package/dist/blocks-CzQLehlc.js.map +1 -0
  13. package/dist/blocks-CzkqclGj.cjs +12 -0
  14. package/dist/blocks-CzkqclGj.cjs.map +1 -0
  15. package/dist/blocks.cjs +1 -1
  16. package/dist/blocks.js +2 -2
  17. package/dist/comments.cjs +1 -1
  18. package/dist/comments.cjs.map +1 -1
  19. package/dist/comments.js +7 -7
  20. package/dist/comments.js.map +1 -1
  21. package/dist/en-BuzSuuTq.cjs +2 -0
  22. package/dist/en-BuzSuuTq.cjs.map +1 -0
  23. package/dist/{en-CGKXfWma.js → en-uzHzj6eH.js} +10 -1
  24. package/dist/en-uzHzj6eH.js.map +1 -0
  25. package/dist/extensions-CSB9ZvuL.cjs +58 -0
  26. package/dist/extensions-CSB9ZvuL.cjs.map +1 -0
  27. package/dist/{extensions-CrUGDOks.js → extensions-DGuhtOgB.js} +717 -452
  28. package/dist/extensions-DGuhtOgB.js.map +1 -0
  29. package/dist/extensions.cjs +1 -1
  30. package/dist/extensions.js +4 -4
  31. package/dist/locales.cjs +1 -1
  32. package/dist/locales.cjs.map +1 -1
  33. package/dist/locales.js +199 -1
  34. package/dist/locales.js.map +1 -1
  35. package/dist/{src-DTF83Cl9.js → src-BkfZVfaO.js} +921 -835
  36. package/dist/src-BkfZVfaO.js.map +1 -0
  37. package/dist/src-DM3syMdf.cjs +23 -0
  38. package/dist/src-DM3syMdf.cjs.map +1 -0
  39. package/dist/style.css +1 -1
  40. package/dist/webpack-stats.json +1 -1
  41. package/dist/y.cjs +1 -1
  42. package/dist/y.cjs.map +1 -1
  43. package/dist/y.js +65 -62
  44. package/dist/y.js.map +1 -1
  45. package/dist/yjs.cjs +1 -1
  46. package/dist/yjs.cjs.map +1 -1
  47. package/dist/yjs.js +88 -76
  48. package/dist/yjs.js.map +1 -1
  49. package/package.json +29 -30
  50. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2505 -763
  51. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +42 -0
  52. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +16 -4
  53. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +10 -1
  54. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +42 -8
  55. package/src/api/exporters/markdown/htmlToMarkdown.ts +45 -10
  56. package/src/api/exporters/markdown/markdownExporter.ts +10 -1
  57. package/src/api/nodeConversions/blockToNode.ts +5 -1
  58. package/src/api/nodeConversions/nodeToBlock.ts +3 -0
  59. package/src/api/parsers/html/parseHTML.ts +43 -0
  60. package/src/api/pmUtil.ts +16 -8
  61. package/src/blocks/Code/CodeBlockOptions.ts +83 -0
  62. package/src/blocks/Code/block.test.ts +1 -1
  63. package/src/blocks/Code/block.ts +29 -281
  64. package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +120 -0
  65. package/src/blocks/Code/helpers/parse/parsePreCode.ts +45 -0
  66. package/src/blocks/Code/helpers/render/createCodeBlock.ts +98 -0
  67. package/src/blocks/Code/helpers/toExternalHTML/createPreCode.ts +14 -0
  68. package/src/blocks/Table/TableExtension.test.ts +102 -0
  69. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +16 -5
  70. package/src/blocks/defaultBlockTypeGuards.ts +6 -0
  71. package/src/blocks/index.ts +3 -0
  72. package/src/comments/extension.ts +2 -4
  73. package/src/editor/Block.css +324 -3
  74. package/src/editor/BlockNoteEditor.ts +25 -4
  75. package/src/editor/BlockNoteExtension.ts +1 -1
  76. package/src/editor/managers/ExtensionManager/extensions.ts +6 -0
  77. package/src/exporter/ExportImage.ts +50 -0
  78. package/src/exporter/Exporter.test.ts +48 -0
  79. package/src/exporter/Exporter.ts +46 -12
  80. package/src/exporter/index.ts +1 -0
  81. package/src/exporter/mapping.ts +4 -1
  82. package/src/extensions/FormattingToolbar/FormattingToolbar.ts +10 -8
  83. package/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.ts +109 -0
  84. package/src/extensions/SideMenu/SideMenu.ts +20 -3
  85. package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +192 -0
  86. package/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.ts +142 -0
  87. package/src/extensions/SuggestionMenu/SuggestionMenu.test.ts +118 -0
  88. package/src/extensions/SuggestionMenu/SuggestionMenu.ts +40 -27
  89. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +13 -3
  90. package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +120 -0
  91. package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +89 -0
  92. package/src/extensions/SyntaxHighlighting/inlineHighlight.test.ts +135 -0
  93. package/src/extensions/SyntaxHighlighting/shiki.ts +116 -0
  94. package/src/extensions/TableHandles/TableHandles.ts +25 -12
  95. package/src/extensions/TrailingNode/TrailingNode.ts +98 -32
  96. package/src/extensions/Versioning/inMemoryVersioning.ts +13 -3
  97. package/src/extensions/index.ts +4 -0
  98. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +51 -2
  99. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +22 -2
  100. package/src/i18n/locales/ar.ts +9 -0
  101. package/src/i18n/locales/de.ts +9 -0
  102. package/src/i18n/locales/en.ts +9 -0
  103. package/src/i18n/locales/es.ts +9 -0
  104. package/src/i18n/locales/fa.ts +9 -0
  105. package/src/i18n/locales/fr.ts +9 -0
  106. package/src/i18n/locales/he.ts +9 -0
  107. package/src/i18n/locales/hr.ts +9 -0
  108. package/src/i18n/locales/is.ts +9 -0
  109. package/src/i18n/locales/it.ts +9 -0
  110. package/src/i18n/locales/ja.ts +9 -0
  111. package/src/i18n/locales/ko.ts +9 -0
  112. package/src/i18n/locales/nl.ts +9 -0
  113. package/src/i18n/locales/no.ts +9 -0
  114. package/src/i18n/locales/pl.ts +9 -0
  115. package/src/i18n/locales/pt.ts +9 -0
  116. package/src/i18n/locales/ru.ts +9 -0
  117. package/src/i18n/locales/sk.ts +9 -0
  118. package/src/i18n/locales/uk.ts +9 -0
  119. package/src/i18n/locales/uz.ts +9 -0
  120. package/src/i18n/locales/vi.ts +9 -0
  121. package/src/i18n/locales/zh-tw.ts +9 -0
  122. package/src/i18n/locales/zh.ts +9 -0
  123. package/src/index.ts +6 -1
  124. package/src/schema/blocks/createSpec.ts +17 -5
  125. package/src/schema/blocks/internal.test.ts +86 -0
  126. package/src/schema/blocks/internal.ts +64 -0
  127. package/src/schema/blocks/types.ts +53 -3
  128. package/src/schema/contentTypePropagation.test.ts +1 -1
  129. package/src/schema/inlineContent/createSpec.test.ts +161 -0
  130. package/src/schema/inlineContent/createSpec.ts +180 -13
  131. package/src/schema/inlineContent/internal.ts +21 -2
  132. package/src/schema/inlineContent/types.ts +35 -5
  133. package/src/schema/nodeViewMutations.test.ts +121 -0
  134. package/src/schema/nodeViewMutations.ts +46 -0
  135. package/src/user/UserStore.ts +1 -1
  136. package/src/util/Store.test.ts +132 -0
  137. package/src/util/Store.ts +135 -0
  138. package/src/y/extensions/AttributionExtension.test.ts +10 -0
  139. package/src/y/extensions/Versioning.test.ts +20 -7
  140. package/src/yjs/comments/RESTYjsThreadStore.test.ts +85 -0
  141. package/src/yjs/comments/RESTYjsThreadStore.ts +7 -1
  142. package/src/yjs/extensions/ForkYDoc.test.ts +37 -0
  143. package/src/yjs/extensions/ForkYDoc.ts +26 -1
  144. package/src/yjs/extensions/RelativePositionMapping.ts +8 -2
  145. package/src/yjs/extensions/Versioning.test.ts +17 -5
  146. package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +13 -0
  147. package/types/src/api/pmUtil.d.ts +7 -7
  148. package/types/src/blocks/Code/CodeBlockOptions.d.ts +61 -0
  149. package/types/src/blocks/Code/block.d.ts +3 -53
  150. package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +35 -0
  151. package/types/src/blocks/Code/helpers/parse/parsePreCode.d.ts +8 -0
  152. package/types/src/blocks/Code/helpers/render/createCodeBlock.d.ts +18 -0
  153. package/types/src/blocks/Code/helpers/toExternalHTML/createPreCode.d.ts +5 -0
  154. package/types/src/blocks/defaultBlockTypeGuards.d.ts +2 -0
  155. package/types/src/blocks/index.d.ts +3 -0
  156. package/types/src/comments/extension.d.ts +1 -15
  157. package/types/src/editor/BlockNoteEditor.d.ts +3 -3
  158. package/types/src/editor/BlockNoteExtension.d.ts +1 -1
  159. package/types/src/exporter/ExportImage.d.ts +36 -0
  160. package/types/src/exporter/Exporter.d.ts +21 -0
  161. package/types/src/exporter/Exporter.test.d.ts +1 -0
  162. package/types/src/exporter/index.d.ts +1 -0
  163. package/types/src/exporter/mapping.d.ts +1 -1
  164. package/types/src/extensions/FilePanel/FilePanel.d.ts +1 -1
  165. package/types/src/extensions/FormattingToolbar/FormattingToolbar.d.ts +1 -1
  166. package/types/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.d.ts +5 -0
  167. package/types/src/extensions/ShowSelection/ShowSelection.d.ts +1 -5
  168. package/types/src/extensions/SideMenu/SideMenu.d.ts +6 -1
  169. package/types/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.d.ts +45 -0
  170. package/types/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.d.ts +49 -0
  171. package/types/src/extensions/SuggestionMenu/SuggestionMenu.d.ts +7 -11
  172. package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.d.ts +44 -0
  173. package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.d.ts +1 -0
  174. package/types/src/extensions/SyntaxHighlighting/inlineHighlight.test.d.ts +1 -0
  175. package/types/src/extensions/SyntaxHighlighting/shiki.d.ts +13 -0
  176. package/types/src/extensions/TableHandles/TableHandles.d.ts +1 -1
  177. package/types/src/extensions/TrailingNode/TrailingNode.d.ts +5 -4
  178. package/types/src/extensions/Versioning/Versioning.d.ts +1 -35
  179. package/types/src/extensions/index.d.ts +4 -0
  180. package/types/src/i18n/locales/en.d.ts +9 -0
  181. package/types/src/i18n/locales/fa.d.ts +9 -0
  182. package/types/src/i18n/locales/sk.d.ts +9 -0
  183. package/types/src/index.d.ts +3 -1
  184. package/types/src/schema/blocks/internal.d.ts +21 -0
  185. package/types/src/schema/blocks/internal.test.d.ts +1 -0
  186. package/types/src/schema/blocks/types.d.ts +36 -3
  187. package/types/src/schema/inlineContent/createSpec.d.ts +35 -3
  188. package/types/src/schema/inlineContent/createSpec.test.d.ts +1 -0
  189. package/types/src/schema/inlineContent/internal.d.ts +3 -2
  190. package/types/src/schema/inlineContent/types.d.ts +22 -3
  191. package/types/src/schema/nodeViewMutations.d.ts +3 -0
  192. package/types/src/schema/nodeViewMutations.test.d.ts +1 -0
  193. package/types/src/user/UserStore.d.ts +1 -1
  194. package/types/src/util/Store.d.ts +45 -0
  195. package/types/src/util/Store.test.d.ts +1 -0
  196. package/types/src/y/extensions/AttributionExtension.d.ts +1 -1
  197. package/types/src/y/extensions/DiffVersioningExtension.d.ts +1 -1
  198. package/types/src/y/extensions/ForkYDoc.d.ts +1 -5
  199. package/types/src/y/extensions/index.d.ts +2 -10
  200. package/types/src/yjs/comments/RESTYjsThreadStore.test.d.ts +1 -0
  201. package/types/src/yjs/extensions/ForkYDoc.d.ts +1 -5
  202. package/types/src/yjs/extensions/index.d.ts +1 -5
  203. package/dist/BlockNoteExtension-B_IEJHS8.js +0 -38
  204. package/dist/BlockNoteExtension-B_IEJHS8.js.map +0 -1
  205. package/dist/BlockNoteExtension-M0znTzxP.cjs +0 -2
  206. package/dist/BlockNoteExtension-M0znTzxP.cjs.map +0 -1
  207. package/dist/UserStore-QbbPFj0z.js.map +0 -1
  208. package/dist/blocks-BqHv0xhc.cjs +0 -12
  209. package/dist/blocks-BqHv0xhc.cjs.map +0 -1
  210. package/dist/blocks-CiuUGa1E.js.map +0 -1
  211. package/dist/en-C5Z4Ag9_.cjs +0 -2
  212. package/dist/en-C5Z4Ag9_.cjs.map +0 -1
  213. package/dist/en-CGKXfWma.js.map +0 -1
  214. package/dist/extensions-CrUGDOks.js.map +0 -1
  215. package/dist/extensions-Ghr9QqqR.cjs +0 -52
  216. package/dist/extensions-Ghr9QqqR.cjs.map +0 -1
  217. package/dist/src-DTF83Cl9.js.map +0 -1
  218. package/dist/src-OfbaVbMw.cjs +0 -21
  219. package/dist/src-OfbaVbMw.cjs.map +0 -1
  220. package/src/blocks/Code/shiki.ts +0 -73
  221. package/types/src/blocks/Code/shiki.d.ts +0 -4
@@ -1,5 +1,6 @@
1
- import { yUndoPluginKey } from "y-prosemirror";
1
+ import { ySyncPluginKey, yUndoPluginKey } from "y-prosemirror";
2
2
  import * as Y from "yjs";
3
+ import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
3
4
  import {
4
5
  createExtension,
5
6
  createStore,
@@ -11,6 +12,26 @@ import { YSyncExtension } from "./YSync.js";
11
12
  import { YUndoExtension } from "./YUndo.js";
12
13
  import { findTypeInOtherYdoc } from "../utils.js";
13
14
 
15
+ /**
16
+ * Point the `ySync` plugin state at `fragment`.
17
+ *
18
+ * Swapping the `ySync` plugin reconfigures the ProseMirror state, and
19
+ * ProseMirror carries over the state of plugins that share a key instead of
20
+ * re-initializing them. So the new plugin's `binding` (which is set from its
21
+ * view, via a transaction) ends up on the new fragment, while `type` and `doc`
22
+ * still point at the fragment the editor was bound to before. Anything reading
23
+ * those (e.g. `RelativePositionMappingExtension`) would then mix up the two
24
+ * Y.Docs, so we set them explicitly here.
25
+ */
26
+ function bindYSyncPluginStateTo(
27
+ editor: BlockNoteEditor<any, any, any>,
28
+ fragment: Y.XmlFragment,
29
+ ) {
30
+ editor.transact((tr) =>
31
+ tr.setMeta(ySyncPluginKey, { type: fragment, doc: fragment.doc }),
32
+ );
33
+ }
34
+
14
35
  export const ForkYDocExtension = createExtension(
15
36
  ({ editor, options }: ExtensionOptions<CollaborationOptions>) => {
16
37
  let forkedState:
@@ -84,6 +105,8 @@ export const ForkYDocExtension = createExtension(
84
105
  ],
85
106
  );
86
107
 
108
+ bindYSyncPluginStateTo(editor, forkedFragment);
109
+
87
110
  // Tell the store that the editor is now forked
88
111
  store.setState({ isForked: true });
89
112
  },
@@ -110,6 +133,8 @@ export const ForkYDocExtension = createExtension(
110
133
  ],
111
134
  );
112
135
 
136
+ bindYSyncPluginStateTo(editor, originalFragment);
137
+
113
138
  // Reset the undo stack to the original undo stack
114
139
  yUndoPluginKey.getState(
115
140
  editor.prosemirrorState,
@@ -51,9 +51,15 @@ export const RelativePositionMappingExtension = createExtension(
51
51
  const curYSyncPluginState = ySyncPluginKey.getState(
52
52
  editor.prosemirrorState,
53
53
  ) as typeof ySyncPluginState;
54
+ // Resolve against the doc that owns the currently bound type, and not
55
+ // against `curYSyncPluginState.doc`. Those can point at different
56
+ // Y.Docs (e.g. right after forking the doc, see `ForkYDocExtension`),
57
+ // in which case the resolved type wouldn't be part of the bound
58
+ // fragment and the position would be reported as "not found".
59
+ const boundType = curYSyncPluginState.binding.type;
54
60
  const pos = relativePositionToAbsolutePosition(
55
- curYSyncPluginState.doc,
56
- curYSyncPluginState.binding.type,
61
+ boundType.doc,
62
+ boundType,
57
63
  relativePosition,
58
64
  curYSyncPluginState.binding.mapping,
59
65
  );
@@ -304,15 +304,26 @@ function createInMemoryYjsEndpoints(): VersioningEndpoints<
304
304
  >();
305
305
  const contents = new Map<string, Uint8Array>();
306
306
 
307
+ // `Date.now()` only has millisecond resolution, so snapshots created in quick
308
+ // succession (as they are in these tests) can share a timestamp, which leaves
309
+ // the newest-first ordering of `list()` ambiguous. Hand out strictly
310
+ // increasing timestamps so creation order is always recoverable.
311
+ let lastTimestamp = 0;
312
+ function nextTimestamp() {
313
+ lastTimestamp = Math.max(Date.now(), lastTimestamp + 1);
314
+ return lastTimestamp;
315
+ }
316
+
307
317
  return {
308
318
  list: async () =>
309
319
  [...snapshots.values()].sort((a, b) => b.createdAt - a.createdAt),
310
320
  create: async (fragment, options) => {
321
+ const now = nextTimestamp();
311
322
  const snapshot = {
312
323
  id: crypto.randomUUID(),
313
324
  name: options?.name,
314
- createdAt: Date.now(),
315
- updatedAt: Date.now(),
325
+ createdAt: now,
326
+ updatedAt: now,
316
327
  restoredFromSnapshotId: options?.restoredFromSnapshot?.id
317
328
  ? String(options.restoredFromSnapshot.id)
318
329
  : undefined,
@@ -329,11 +340,12 @@ function createInMemoryYjsEndpoints(): VersioningEndpoints<
329
340
  return data;
330
341
  },
331
342
  restore: async (fragment, snapshot) => {
343
+ const backupTimestamp = nextTimestamp();
332
344
  const backup = {
333
345
  id: crypto.randomUUID(),
334
346
  name: "Backup",
335
- createdAt: Date.now(),
336
- updatedAt: Date.now(),
347
+ createdAt: backupTimestamp,
348
+ updatedAt: backupTimestamp,
337
349
  };
338
350
  contents.set(backup.id, Y.encodeStateAsUpdate(fragment.doc!));
339
351
  snapshots.set(backup.id, backup);
@@ -347,7 +359,7 @@ function createInMemoryYjsEndpoints(): VersioningEndpoints<
347
359
  throw new Error(`Snapshot ${String(snapshot.id)} not found`);
348
360
  }
349
361
  s.name = name;
350
- s.updatedAt = Date.now();
362
+ s.updatedAt = nextTimestamp();
351
363
  },
352
364
  };
353
365
  }
@@ -2,6 +2,19 @@ import { DOMSerializer } from "prosemirror-model";
2
2
  import { PartialBlock } from "../../../../blocks/defaultBlocks.js";
3
3
  import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
4
4
  import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../../schema/index.js";
5
+ /**
6
+ * Placeholder character inserted into empty inline-content blocks when
7
+ * exporting to external HTML. An empty block serializes to an element with no
8
+ * children (e.g. `<p></p>`), which is dropped when the HTML is parsed back into
9
+ * blocks. Filling it with this character keeps the block alive through the
10
+ * round trip, and the parser strips the character again so the block ends up
11
+ * empty (see `HTMLToBlocks`).
12
+ *
13
+ * The Unicode object replacement character (U+FFFC) is used because it's a
14
+ * reserved placeholder that users don't type, so it can be safely removed on
15
+ * import without discarding legitimate content (unlike a non-breaking space).
16
+ */
17
+ export declare const EMPTY_BLOCK_PLACEHOLDER = "\uFFFC";
5
18
  export declare function serializeInlineContentExternalHTML<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(editor: BlockNoteEditor<any, I, S>, blockContent: PartialBlock<BSchema, I, S>["content"], serializer: DOMSerializer, options?: {
6
19
  document?: Document;
7
20
  blockType?: string;
@@ -11,13 +11,13 @@ export declare function getInlineContentSchema<I extends InlineContentSchema>(sc
11
11
  export declare function getStyleSchema<S extends StyleSchema>(schema: Schema): S;
12
12
  export declare function getBlockCache(schema: Schema): import("../index.js").BlockCache<any, any, any>;
13
13
  /**
14
- * Whether `nodeType` is a BlockNote block whose content type is `"plain"` — i.e.
15
- * it holds unstyled text and only allows the non-formatting (`"annotation"`)
16
- * marks. Resolved semantically from the block schema (the source of truth),
17
- * reachable from `schema.cached.blockNoteEditor`.
14
+ * Whether `nodeType` is a BlockNote block or inline content whose content type
15
+ * is `"plain"` — i.e. it holds unstyled text and only allows the non-formatting
16
+ * (`"annotation"`) marks. Resolved semantically from the block / inline content
17
+ * schema (the source of truth), reachable from `schema.cached.blockNoteEditor`.
18
18
  *
19
- * Returns `false` for every non-block / structural node type (`doc`,
20
- * `blockGroup`, `text`, inline content, table sub-nodes), since those aren't
21
- * keys in the block schema.
19
+ * Returns `false` for every other node type (`doc`, `blockGroup`, `text`, table
20
+ * sub-nodes, and non-plain blocks / inline content), since those aren't plain
21
+ * content keys in either schema.
22
22
  */
23
23
  export declare function isPlainContentNodeType(schema: Schema, nodeType: NodeType): boolean;
@@ -0,0 +1,61 @@
1
+ import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
2
+ import type { BlockFromConfig } from "../../schema/index.js";
3
+ /**
4
+ * Renders a preview of a code block's content (e.g. rendered LaTeX). Takes the
5
+ * same parameters as a block's `render` function and returns the same type,
6
+ * minus `contentDOM` - as a preview never holds the block's editable content.
7
+ *
8
+ * A `renderPreview` function is only responsible for the preview itself. It has
9
+ * no opinion on when, where, or how the preview is displayed - that's up to the
10
+ * code block's `render` function.
11
+ */
12
+ export type CodeBlockPreview = (block: BlockFromConfig<any, any, any>, editor: BlockNoteEditor<any>) => {
13
+ dom: HTMLElement | DocumentFragment;
14
+ error?: string | null;
15
+ };
16
+ export type CodeBlockOptions = {
17
+ /**
18
+ * Whether to indent lines with a tab when the user presses `Tab` in a code block.
19
+ *
20
+ * @default true
21
+ */
22
+ indentLineWithTab?: boolean;
23
+ /**
24
+ * The default language to use for code blocks.
25
+ *
26
+ * @default "text"
27
+ */
28
+ defaultLanguage?: string;
29
+ /**
30
+ * The languages that are supported in the editor.
31
+ *
32
+ * @example
33
+ * {
34
+ * javascript: {
35
+ * name: "JavaScript",
36
+ * aliases: ["js"],
37
+ * },
38
+ * typescript: {
39
+ * name: "TypeScript",
40
+ * aliases: ["ts"],
41
+ * },
42
+ * }
43
+ */
44
+ supportedLanguages?: Record<string, {
45
+ /**
46
+ * The display name of the language.
47
+ */
48
+ name: string;
49
+ /**
50
+ * Aliases for this language.
51
+ */
52
+ aliases?: string[];
53
+ /**
54
+ * Renders a preview of the result of the code (e.g. rendered LaTeX). When
55
+ * defined, the code block displays this preview instead of the raw source
56
+ * by default, and shows the editable source in a popup when selected.
57
+ */
58
+ createPreview?: CodeBlockPreview;
59
+ }>;
60
+ };
61
+ export declare function getLanguageId(options: CodeBlockOptions, languageName: string): string | undefined;
@@ -1,70 +1,20 @@
1
- import type { HighlighterGeneric } from "@shikijs/types";
2
- export type CodeBlockOptions = {
3
- /**
4
- * Whether to indent lines with a tab when the user presses `Tab` in a code block.
5
- *
6
- * @default true
7
- */
8
- indentLineWithTab?: boolean;
9
- /**
10
- * The default language to use for code blocks.
11
- *
12
- * @default "text"
13
- */
14
- defaultLanguage?: string;
15
- /**
16
- * The languages that are supported in the editor.
17
- *
18
- * @example
19
- * {
20
- * javascript: {
21
- * name: "JavaScript",
22
- * aliases: ["js"],
23
- * },
24
- * typescript: {
25
- * name: "TypeScript",
26
- * aliases: ["ts"],
27
- * },
28
- * }
29
- */
30
- supportedLanguages?: Record<string, {
31
- /**
32
- * The display name of the language.
33
- */
34
- name: string;
35
- /**
36
- * Aliases for this language.
37
- */
38
- aliases?: string[];
39
- }>;
40
- /**
41
- * The highlighter to use for code blocks.
42
- */
43
- createHighlighter?: () => Promise<HighlighterGeneric<any, any>>;
44
- };
45
- export type CodeBlockConfig = ReturnType<typeof createCodeBlockConfig>;
1
+ import { CodeBlockOptions } from "./CodeBlockOptions.js";
46
2
  export declare const createCodeBlockConfig: (options: CodeBlockOptions) => import("../../index.js").BlockConfig<"codeBlock", {
47
3
  readonly language: {
48
4
  readonly default: string;
49
5
  };
50
6
  }, "plain">;
7
+ export type CodeBlockConfig = ReturnType<typeof createCodeBlockConfig>;
51
8
  export declare const createCodeBlockSpec: (options?: Partial<{
52
9
  indentLineWithTab: boolean;
53
10
  defaultLanguage: string;
54
11
  supportedLanguages: Record<string, {
55
- /**
56
- * The display name of the language.
57
- */
58
12
  name: string;
59
- /**
60
- * Aliases for this language.
61
- */
62
13
  aliases?: string[];
14
+ createPreview?: import("./CodeBlockOptions.js").CodeBlockPreview;
63
15
  }>;
64
- createHighlighter: () => Promise<HighlighterGeneric<any, any>>;
65
16
  }> | undefined) => import("../../index.js").BlockSpec<"codeBlock", {
66
17
  readonly language: {
67
18
  readonly default: string;
68
19
  };
69
20
  }, "plain">;
70
- export declare function getLanguageId(options: CodeBlockOptions, languageName: string): string | undefined;
@@ -0,0 +1,35 @@
1
+ import { CodeBlockOptions } from "../../CodeBlockOptions.js";
2
+ export declare const CodeKeyboardShortcutsExtension: (options: CodeBlockOptions) => (key: string, blockType: string) => import("../../../../index.js").ExtensionFactoryInstance<{
3
+ readonly key: string;
4
+ readonly keyboardShortcuts: {
5
+ readonly Delete: ({ editor }: {
6
+ editor: import("../../../../index.js").BlockNoteEditor<any, any, any>;
7
+ }) => boolean;
8
+ readonly Tab: ({ editor }: {
9
+ editor: import("../../../../index.js").BlockNoteEditor<any, any, any>;
10
+ }) => boolean;
11
+ readonly Enter: ({ editor }: {
12
+ editor: import("../../../../index.js").BlockNoteEditor<any, any, any>;
13
+ }) => boolean;
14
+ readonly "Shift-Enter": ({ editor }: {
15
+ editor: import("../../../../index.js").BlockNoteEditor<any, any, any>;
16
+ }) => boolean;
17
+ };
18
+ readonly inputRules: readonly [{
19
+ readonly find: RegExp;
20
+ readonly replace: ({ match }: {
21
+ match: RegExpMatchArray;
22
+ range: {
23
+ from: number;
24
+ to: number;
25
+ };
26
+ editor: import("../../../../index.js").BlockNoteEditor<any, any, any>;
27
+ }) => {
28
+ type: string;
29
+ props: {
30
+ language: string;
31
+ };
32
+ content: never[];
33
+ };
34
+ }];
35
+ }>;
@@ -0,0 +1,8 @@
1
+ import { Schema } from "@tiptap/pm/model";
2
+ export declare const parsePreCode: (el: HTMLElement) => {
3
+ language: string | undefined;
4
+ } | undefined;
5
+ export declare const parsePreCodeContent: ({ el, schema, }: {
6
+ el: HTMLElement;
7
+ schema: Schema;
8
+ }, blockType: string) => import("prosemirror-model").Fragment;
@@ -0,0 +1,18 @@
1
+ import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
2
+ import type { BlockFromConfig } from "../../../../schema/index.js";
3
+ export declare const createLanguageSelect: (block: BlockFromConfig<any, any, any>, editor: BlockNoteEditor<any>, selectedLanguage: string, supportedLanguages: Record<string, {
4
+ name: string;
5
+ }>) => {
6
+ dom: HTMLDivElement;
7
+ destroy: () => void;
8
+ };
9
+ export declare const createCodeBlock: (block: BlockFromConfig<any, any, any>, editor: BlockNoteEditor<any>, options?: {
10
+ selectedLanguage: string;
11
+ supportedLanguages: Record<string, {
12
+ name: string;
13
+ }>;
14
+ }) => {
15
+ dom: DocumentFragment;
16
+ contentDOM: HTMLElement;
17
+ destroy: () => void;
18
+ };
@@ -0,0 +1,5 @@
1
+ import type { BlockFromConfig } from "../../../../schema/index.js";
2
+ export declare const createPreCode: (block: BlockFromConfig<any, any, any>) => {
3
+ dom: HTMLPreElement;
4
+ contentDOM: HTMLElement;
5
+ };
@@ -1,3 +1,4 @@
1
+ import { Node } from "prosemirror-model";
1
2
  import { CellSelection } from "prosemirror-tables";
2
3
  import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
3
4
  import { BlockConfig, PropSchema, PropSpec } from "../schema/index.js";
@@ -18,3 +19,4 @@ export declare function blockHasType<BType extends string, Props extends PropSch
18
19
  }> : BlockConfig<BT, PropSchema>;
19
20
  }, any, any>;
20
21
  export declare function isTableCellSelection(selection: Selection): selection is CellSelection;
22
+ export declare function isTableCellNode(node: Node): boolean;
@@ -15,6 +15,9 @@ export * from "./Quote/block.js";
15
15
  export * from "./Table/block.js";
16
16
  export * from "./Video/block.js";
17
17
  export { EMPTY_CELL_HEIGHT, EMPTY_CELL_WIDTH } from "./Table/TableExtension.js";
18
+ export * from "./Code/helpers/parse/parsePreCode.js";
19
+ export * from "./Code/helpers/render/createCodeBlock.js";
20
+ export * from "./Code/helpers/toExternalHTML/createPreCode.js";
18
21
  export * from "./ToggleWrapper/createToggleWrapper.js";
19
22
  export * from "./File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.js";
20
23
  export * from "./PageBreak/getPageBreakSlashMenuItems.js";
@@ -40,21 +40,7 @@ export declare const CommentsExtension: (options: {
40
40
  confirmBeforeDiscard?: boolean;
41
41
  }) => import("../index.js").ExtensionFactoryInstance<{
42
42
  readonly key: "comments";
43
- readonly store: import("@tanstack/store").Store<{
44
- pendingComment: boolean;
45
- selectedThreadId: string | undefined;
46
- threadPositions: Map<string, {
47
- from: number;
48
- to: number;
49
- }>;
50
- }, (cb: {
51
- pendingComment: boolean;
52
- selectedThreadId: string | undefined;
53
- threadPositions: Map<string, {
54
- from: number;
55
- to: number;
56
- }>;
57
- }) => {
43
+ readonly store: import("../index.js").Store<{
58
44
  pendingComment: boolean;
59
45
  selectedThreadId: string | undefined;
60
46
  threadPositions: Map<string, {
@@ -9,7 +9,7 @@ import type { BlockIdentifier, BlockNoteDOMAttributes, BlockSchema, BlockSpecs,
9
9
  import "../style.css";
10
10
  import { EventEmitter } from "../util/EventEmitter.js";
11
11
  import type { NoInfer } from "../util/typescript.js";
12
- import { ExtensionFactoryInstance } from "./BlockNoteExtension.js";
12
+ import { Extension, ExtensionFactory, ExtensionFactoryInstance } from "./BlockNoteExtension.js";
13
13
  import type { TextCursorPosition } from "./cursorPositionTypes.js";
14
14
  import { ExtensionManager } from "./managers/index.js";
15
15
  import type { Selection } from "./selectionTypes.js";
@@ -320,7 +320,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
320
320
  /**
321
321
  * BlockNote extensions that are added to the editor, keyed by the extension key
322
322
  */
323
- get extensions(): Map<string, import("./BlockNoteExtension.js").Extension<any, string>>;
323
+ get extensions(): Map<string, Extension<any, string>>;
324
324
  /**
325
325
  * Execute a prosemirror command. This is mostly for backwards compatibility with older code.
326
326
  *
@@ -388,7 +388,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
388
388
  /**
389
389
  * Get an extension from the editor
390
390
  */
391
- getExtension: ExtensionManager["getExtension"];
391
+ getExtension: (<const Ext extends Extension | ExtensionFactory = Extension>(extension: string) => (Ext extends Extension ? Ext : Ext extends ExtensionFactory ? ReturnType<ReturnType<Ext>> : never) | undefined) & (<const T extends ExtensionFactory>(extension: T) => ReturnType<ReturnType<T>> | undefined);
392
392
  /**
393
393
  * Mount the editor to a DOM element.
394
394
  *
@@ -1,7 +1,7 @@
1
- import { Store, StoreOptions } from "@tanstack/store";
2
1
  import { type AnyExtension } from "@tiptap/core";
3
2
  import type { Plugin as ProsemirrorPlugin } from "prosemirror-state";
4
3
  import type { PartialBlockNoDefaults } from "../schema/index.js";
4
+ import { Store, StoreOptions } from "../util/Store.js";
5
5
  import type { BlockNoteEditor } from "./BlockNoteEditor.js";
6
6
  /**
7
7
  * This function is called when the extension is destroyed.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * An image generated during export (e.g. a rendered formula or diagram): the
3
+ * encoded image bytes plus the dimensions to display it at.
4
+ *
5
+ * The bytes (rather than e.g. a data URL string or a `Blob`) are the source
6
+ * of truth: they carry no encoding ambiguity, work in every environment, and
7
+ * are readable synchronously - each output format converts them at its own
8
+ * boundary (data URL for HTML-based targets, raw bytes for DOCX, base64 for
9
+ * email attachments).
10
+ */
11
+ export type ExportImage = {
12
+ /** MIME type of `data`, e.g. `"image/png"` or `"image/svg+xml"`. */
13
+ mimeType: string;
14
+ /** The encoded image bytes. */
15
+ data: Uint8Array;
16
+ /**
17
+ * Dimensions to display the image at, in the target format's units (CSS
18
+ * pixels, points, ...). For raster images, `data`'s own pixel dimensions
19
+ * may be larger - images are often rendered at 2-4x for sharpness.
20
+ */
21
+ width: number;
22
+ height: number;
23
+ };
24
+ /**
25
+ * Encodes bytes as base64. This papers over a platform gap: until
26
+ * `Uint8Array.prototype.toBase64()` (ES2026) is available in every runtime
27
+ * BlockNote supports, the only universal built-in is `btoa`, which takes
28
+ * binary *strings*. Uses `toBase64` when the runtime has it.
29
+ */
30
+ export declare function bytesToBase64(bytes: Uint8Array): string;
31
+ /**
32
+ * Encodes an {@link ExportImage}'s bytes as a base64 data URL, for targets
33
+ * that take image sources as URLs (HTML `src` attributes, react-pdf image
34
+ * sources, ...).
35
+ */
36
+ export declare function exportImageToDataURL(image: ExportImage): string;
@@ -1,5 +1,6 @@
1
1
  import { BlockNoteSchema } from "../blocks/BlockNoteSchema.js";
2
2
  import { COLORS_DEFAULT } from "../editor/defaultColors.js";
3
+ import type { Dictionary } from "../i18n/dictionary.js";
3
4
  import { BlockFromConfig, BlockSchema, InlineContent, InlineContentSchema, StyleSchema, StyledText, Styles } from "../schema/index.js";
4
5
  import type { BlockMapping, InlineContentMapping, StyleMapping } from "./mapping.js";
5
6
  export type ExporterOptions = {
@@ -20,6 +21,20 @@ export type ExporterOptions = {
20
21
  * Colors to use for background of blocks, font colors, and highlight colors
21
22
  */
22
23
  colors: typeof COLORS_DEFAULT;
24
+ /**
25
+ * The strings an exporter renders into the produced document (file link
26
+ * texts, error placeholders). Accepts a locale from
27
+ * `@blocknote/core/locales` or an editor dictionary; block packages that
28
+ * ship their own exporter strings (e.g. math, diagram) read their sections
29
+ * from this same object, exactly as they do from an editor dictionary.
30
+ *
31
+ * @default the English strings
32
+ */
33
+ dictionary?: {
34
+ exporter: Dictionary["exporter"];
35
+ } & {
36
+ [blockDictionary: string]: unknown;
37
+ };
23
38
  };
24
39
  export declare abstract class Exporter<B extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema, RB, RI, RS, TS> {
25
40
  protected readonly mappings: {
@@ -34,6 +49,12 @@ export declare abstract class Exporter<B extends BlockSchema, I extends InlineCo
34
49
  inlineContentMapping: InlineContentMapping<I, S, RI, TS>;
35
50
  styleMapping: StyleMapping<S, RS>;
36
51
  }, options: ExporterOptions);
52
+ /**
53
+ * The strings this exporter renders into the produced document - the
54
+ * `exporter` section of the configured dictionary (the `dictionary`
55
+ * option of {@link ExporterOptions}), or the English defaults.
56
+ */
57
+ get dictionary(): Dictionary["exporter"];
37
58
  resolveFile(url: string): Promise<Blob>;
38
59
  mapStyles(styles: Styles<S>): RS[];
39
60
  mapInlineContent(inlineContent: InlineContent<I, S>): RI;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,3 @@
1
1
  export * from "./Exporter.js";
2
+ export * from "./ExportImage.js";
2
3
  export * from "./mapping.js";
@@ -11,7 +11,7 @@ export type BlockMapping<B extends BlockSchema, I extends InlineContentSchema, S
11
11
  * Defines a mapping from all inline content types with a schema to a result type R.
12
12
  */
13
13
  export type InlineContentMapping<I extends InlineContentSchema, S extends StyleSchema, RI, TS> = {
14
- [K in keyof I]: (inlineContent: InlineContentFromConfig<I[K], S>, exporter: Exporter<any, I, S, any, RI, any, TS>) => RI;
14
+ [K in keyof I]: (inlineContent: InlineContentFromConfig<I[K], S>, exporter: Exporter<any, any, any, any, RI, any, TS>) => RI;
15
15
  };
16
16
  /**
17
17
  * Defines a mapping from all style types with a schema to a result type R.
@@ -1,6 +1,6 @@
1
1
  export declare const FilePanelExtension: (options?: any) => import("../../index.js").ExtensionFactoryInstance<{
2
2
  readonly key: "filePanel";
3
- readonly store: import("@tanstack/store").Store<string | undefined, (cb: string | undefined) => string | undefined>;
3
+ readonly store: import("../../index.js").Store<string | undefined>;
4
4
  readonly mount: ({ signal }: {
5
5
  dom: HTMLElement;
6
6
  root: Document | ShadowRoot;
@@ -1,6 +1,6 @@
1
1
  export declare const FormattingToolbarExtension: (options?: any) => import("../../index.js").ExtensionFactoryInstance<{
2
2
  readonly key: "formattingToolbar";
3
- readonly store: import("@tanstack/store").Store<boolean, (cb: boolean) => boolean>;
3
+ readonly store: import("../../index.js").Store<boolean>;
4
4
  readonly mount: ({ dom, signal }: {
5
5
  dom: HTMLElement;
6
6
  root: Document | ShadowRoot;
@@ -0,0 +1,5 @@
1
+ import { Plugin } from "prosemirror-state";
2
+ export declare const InlineContentBoundaryEditExtension: () => import("../../index.js").ExtensionFactoryInstance<{
3
+ readonly key: "inlineContentBoundaryEdit";
4
+ readonly prosemirrorPlugins: readonly [Plugin<any>];
5
+ }>;
@@ -6,11 +6,7 @@ import { Plugin } from "prosemirror-state";
6
6
  */
7
7
  export declare const ShowSelectionExtension: (options?: any) => import("../../index.js").ExtensionFactoryInstance<{
8
8
  readonly key: "showSelection";
9
- readonly store: import("@tanstack/store").Store<{
10
- enabledSet: Set<string>;
11
- }, (cb: {
12
- enabledSet: Set<string>;
13
- }) => {
9
+ readonly store: import("../../index.js").Store<{
14
10
  enabledSet: Set<string>;
15
11
  }>;
16
12
  readonly prosemirrorPlugins: readonly [Plugin<any>];
@@ -100,7 +100,7 @@ export declare class SideMenuView<BSchema extends BlockSchema, I extends InlineC
100
100
  export declare const sideMenuPluginKey: PluginKey<any>;
101
101
  export declare const SideMenuExtension: (options?: any) => import("../../index.js").ExtensionFactoryInstance<{
102
102
  readonly key: "sideMenu";
103
- readonly store: import("@tanstack/store").Store<SideMenuState<any, any, any> | undefined, (cb: SideMenuState<any, any, any> | undefined) => SideMenuState<any, any, any> | undefined>;
103
+ readonly store: import("../../index.js").Store<SideMenuState<any, any, any> | undefined>;
104
104
  readonly prosemirrorPlugins: readonly [Plugin<any>];
105
105
  /**
106
106
  * Handles drag & drop events for blocks.
@@ -113,6 +113,11 @@ export declare const SideMenuExtension: (options?: any) => import("../../index.j
113
113
  * Handles drag & drop events for blocks.
114
114
  */
115
115
  readonly blockDragEnd: () => void;
116
+ /**
117
+ * Whether the side menu is currently frozen (e.g. because the drag handle
118
+ * menu is open).
119
+ */
120
+ readonly menuFrozen: boolean;
116
121
  /**
117
122
  * Freezes the side menu. When frozen, the side menu will stay
118
123
  * attached to the same block regardless of which block is hovered by the