@blocknote/core 0.53.0 → 0.54.1

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 (219) 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-CTB_5Vyj.cjs +12 -0
  12. package/dist/blocks-CTB_5Vyj.cjs.map +1 -0
  13. package/dist/{blocks-BEJW9OM_.js → blocks-Dol85hpH.js} +680 -670
  14. package/dist/blocks-Dol85hpH.js.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-B7Rsp_Ft.cjs +58 -0
  26. package/dist/extensions-B7Rsp_Ft.cjs.map +1 -0
  27. package/dist/{extensions-BR5hkAio.js → extensions-D6JcJCwd.js} +735 -457
  28. package/dist/extensions-D6JcJCwd.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-BUXut68d.js → src-Buuo5l7X.js} +924 -851
  36. package/dist/src-Buuo5l7X.js.map +1 -0
  37. package/dist/src-C54Ok9E0.cjs +23 -0
  38. package/dist/src-C54Ok9E0.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 +245 -242
  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 +79 -67
  48. package/dist/yjs.js.map +1 -1
  49. package/package.json +17 -18
  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/exporters/markdown/htmlToMarkdown.ts +45 -10
  54. package/src/api/getBlocksChangedByTransaction.test.ts +211 -0
  55. package/src/api/getBlocksChangedByTransaction.ts +48 -12
  56. package/src/api/getChangedRange.ts +54 -0
  57. package/src/api/nodeConversions/blockToNode.ts +5 -1
  58. package/src/api/nodeConversions/nodeToBlock.ts +3 -0
  59. package/src/api/pmUtil.ts +16 -8
  60. package/src/blocks/Code/CodeBlockOptions.ts +83 -0
  61. package/src/blocks/Code/block.test.ts +1 -1
  62. package/src/blocks/Code/block.ts +29 -281
  63. package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +120 -0
  64. package/src/blocks/Code/helpers/parse/parsePreCode.ts +45 -0
  65. package/src/blocks/Code/helpers/render/createCodeBlock.ts +98 -0
  66. package/src/blocks/Code/helpers/toExternalHTML/createPreCode.ts +14 -0
  67. package/src/blocks/index.ts +3 -1
  68. package/src/comments/extension.ts +2 -4
  69. package/src/editor/Block.css +273 -2
  70. package/src/editor/BlockNoteEditor.ts +25 -4
  71. package/src/editor/BlockNoteExtension.ts +1 -1
  72. package/src/editor/managers/ExtensionManager/extensions.ts +6 -0
  73. package/src/editor/performance.test.ts +45 -0
  74. package/src/exporter/ExportImage.ts +50 -0
  75. package/src/exporter/Exporter.test.ts +186 -0
  76. package/src/exporter/Exporter.ts +66 -14
  77. package/src/exporter/index.ts +1 -0
  78. package/src/exporter/mapping.ts +4 -1
  79. package/src/extensions/FormattingToolbar/FormattingToolbar.ts +10 -8
  80. package/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.ts +109 -0
  81. package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +21 -0
  82. package/src/extensions/PreviousBlockType/PreviousBlockType.ts +5 -3
  83. package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +192 -0
  84. package/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.ts +142 -0
  85. package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +120 -0
  86. package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +89 -0
  87. package/src/extensions/SyntaxHighlighting/inlineHighlight.test.ts +135 -0
  88. package/src/extensions/SyntaxHighlighting/shiki.ts +116 -0
  89. package/src/extensions/TableHandles/TableHandles.browser.test.ts +305 -0
  90. package/src/extensions/TableHandles/TableHandles.ts +82 -41
  91. package/src/extensions/Versioning/inMemoryVersioning.ts +13 -3
  92. package/src/extensions/index.ts +4 -0
  93. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +51 -2
  94. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +22 -2
  95. package/src/fonts/inter.css +9 -9
  96. package/src/i18n/locales/ar.ts +9 -0
  97. package/src/i18n/locales/de.ts +9 -0
  98. package/src/i18n/locales/en.ts +9 -0
  99. package/src/i18n/locales/es.ts +9 -0
  100. package/src/i18n/locales/fa.ts +9 -0
  101. package/src/i18n/locales/fr.ts +9 -0
  102. package/src/i18n/locales/he.ts +9 -0
  103. package/src/i18n/locales/hr.ts +9 -0
  104. package/src/i18n/locales/is.ts +9 -0
  105. package/src/i18n/locales/it.ts +9 -0
  106. package/src/i18n/locales/ja.ts +9 -0
  107. package/src/i18n/locales/ko.ts +9 -0
  108. package/src/i18n/locales/nl.ts +9 -0
  109. package/src/i18n/locales/no.ts +9 -0
  110. package/src/i18n/locales/pl.ts +9 -0
  111. package/src/i18n/locales/pt.ts +9 -0
  112. package/src/i18n/locales/ru.ts +9 -0
  113. package/src/i18n/locales/sk.ts +9 -0
  114. package/src/i18n/locales/uk.ts +9 -0
  115. package/src/i18n/locales/uz.ts +9 -0
  116. package/src/i18n/locales/vi.ts +9 -0
  117. package/src/i18n/locales/zh-tw.ts +9 -0
  118. package/src/i18n/locales/zh.ts +9 -0
  119. package/src/index.ts +5 -1
  120. package/src/schema/blocks/createSpec.ts +5 -7
  121. package/src/schema/blocks/types.ts +53 -3
  122. package/src/schema/contentTypePropagation.test.ts +1 -1
  123. package/src/schema/inlineContent/createSpec.test.ts +161 -0
  124. package/src/schema/inlineContent/createSpec.ts +175 -17
  125. package/src/schema/inlineContent/internal.ts +21 -2
  126. package/src/schema/inlineContent/types.ts +35 -5
  127. package/src/schema/nodeViewMutations.test.ts +81 -56
  128. package/src/schema/nodeViewMutations.ts +30 -27
  129. package/src/schema/schema.test.ts +110 -0
  130. package/src/schema/schema.ts +13 -4
  131. package/src/user/UserStore.ts +1 -1
  132. package/src/util/Store.test.ts +132 -0
  133. package/src/util/Store.ts +135 -0
  134. package/src/y/extensions/AttributionExtension.test.ts +18 -9
  135. package/src/y/extensions/Versioning.test.ts +20 -7
  136. package/src/y/versioning/__test__/yhub.test.ts +92 -59
  137. package/src/y/versioning/yhub.ts +35 -29
  138. package/src/yjs/comments/RESTYjsThreadStore.test.ts +85 -0
  139. package/src/yjs/comments/RESTYjsThreadStore.ts +7 -1
  140. package/src/yjs/extensions/ForkYDoc.test.ts +37 -0
  141. package/src/yjs/extensions/ForkYDoc.ts +26 -1
  142. package/src/yjs/extensions/RelativePositionMapping.ts +8 -2
  143. package/src/yjs/extensions/Versioning.test.ts +17 -5
  144. package/types/src/api/getChangedRange.d.ts +14 -0
  145. package/types/src/api/pmUtil.d.ts +7 -7
  146. package/types/src/blocks/Code/CodeBlockOptions.d.ts +61 -0
  147. package/types/src/blocks/Code/block.d.ts +3 -53
  148. package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +35 -0
  149. package/types/src/blocks/Code/helpers/parse/parsePreCode.d.ts +8 -0
  150. package/types/src/blocks/Code/helpers/render/createCodeBlock.d.ts +18 -0
  151. package/types/src/blocks/Code/helpers/toExternalHTML/createPreCode.d.ts +5 -0
  152. package/types/src/blocks/index.d.ts +3 -1
  153. package/types/src/comments/extension.d.ts +1 -15
  154. package/types/src/editor/BlockNoteEditor.d.ts +3 -3
  155. package/types/src/editor/BlockNoteExtension.d.ts +1 -1
  156. package/types/src/exporter/ExportImage.d.ts +36 -0
  157. package/types/src/exporter/Exporter.d.ts +30 -0
  158. package/types/src/exporter/Exporter.test.d.ts +1 -0
  159. package/types/src/exporter/index.d.ts +1 -0
  160. package/types/src/exporter/mapping.d.ts +1 -1
  161. package/types/src/extensions/FilePanel/FilePanel.d.ts +1 -1
  162. package/types/src/extensions/FormattingToolbar/FormattingToolbar.d.ts +1 -1
  163. package/types/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.d.ts +5 -0
  164. package/types/src/extensions/ShowSelection/ShowSelection.d.ts +1 -5
  165. package/types/src/extensions/SideMenu/SideMenu.d.ts +1 -1
  166. package/types/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.d.ts +45 -0
  167. package/types/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.d.ts +49 -0
  168. package/types/src/extensions/SuggestionMenu/SuggestionMenu.d.ts +1 -11
  169. package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.d.ts +44 -0
  170. package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.d.ts +1 -0
  171. package/types/src/extensions/SyntaxHighlighting/inlineHighlight.test.d.ts +1 -0
  172. package/types/src/extensions/SyntaxHighlighting/shiki.d.ts +13 -0
  173. package/types/src/extensions/TableHandles/TableHandles.browser.test.d.ts +1 -0
  174. package/types/src/extensions/TableHandles/TableHandles.d.ts +4 -1
  175. package/types/src/extensions/Versioning/Versioning.d.ts +1 -35
  176. package/types/src/extensions/index.d.ts +4 -0
  177. package/types/src/i18n/locales/en.d.ts +9 -0
  178. package/types/src/i18n/locales/fa.d.ts +9 -0
  179. package/types/src/i18n/locales/sk.d.ts +9 -0
  180. package/types/src/index.d.ts +2 -1
  181. package/types/src/schema/blocks/types.d.ts +36 -3
  182. package/types/src/schema/inlineContent/createSpec.d.ts +35 -3
  183. package/types/src/schema/inlineContent/createSpec.test.d.ts +1 -0
  184. package/types/src/schema/inlineContent/internal.d.ts +3 -2
  185. package/types/src/schema/inlineContent/types.d.ts +22 -3
  186. package/types/src/schema/nodeViewMutations.d.ts +2 -2
  187. package/types/src/schema/schema.test.d.ts +1 -0
  188. package/types/src/user/UserStore.d.ts +1 -1
  189. package/types/src/util/Store.d.ts +45 -0
  190. package/types/src/util/Store.test.d.ts +1 -0
  191. package/types/src/y/extensions/AttributionExtension.d.ts +1 -1
  192. package/types/src/y/extensions/DiffVersioningExtension.d.ts +1 -1
  193. package/types/src/y/extensions/ForkYDoc.d.ts +1 -5
  194. package/types/src/y/extensions/index.d.ts +2 -10
  195. package/types/src/y/versioning/yhub.d.ts +3 -2
  196. package/types/src/yjs/comments/RESTYjsThreadStore.test.d.ts +1 -0
  197. package/types/src/yjs/extensions/ForkYDoc.d.ts +1 -5
  198. package/types/src/yjs/extensions/index.d.ts +1 -5
  199. package/dist/BlockNoteExtension-B_IEJHS8.js +0 -38
  200. package/dist/BlockNoteExtension-B_IEJHS8.js.map +0 -1
  201. package/dist/BlockNoteExtension-M0znTzxP.cjs +0 -2
  202. package/dist/BlockNoteExtension-M0znTzxP.cjs.map +0 -1
  203. package/dist/UserStore-QbbPFj0z.js.map +0 -1
  204. package/dist/blocks-BEJW9OM_.js.map +0 -1
  205. package/dist/blocks-BPmJglFo.cjs +0 -12
  206. package/dist/blocks-BPmJglFo.cjs.map +0 -1
  207. package/dist/en-C5Z4Ag9_.cjs +0 -2
  208. package/dist/en-C5Z4Ag9_.cjs.map +0 -1
  209. package/dist/en-CGKXfWma.js.map +0 -1
  210. package/dist/extensions-AitWbYdJ.cjs +0 -52
  211. package/dist/extensions-AitWbYdJ.cjs.map +0 -1
  212. package/dist/extensions-BR5hkAio.js.map +0 -1
  213. package/dist/src-BHPuOo7W.cjs +0 -21
  214. package/dist/src-BHPuOo7W.cjs.map +0 -1
  215. package/dist/src-BUXut68d.js.map +0 -1
  216. package/src/blocks/Code/shiki.ts +0 -73
  217. package/src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -20
  218. package/types/src/blocks/Code/shiki.d.ts +0 -4
  219. package/types/src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -6
@@ -16,8 +16,10 @@ export * from "./Table/block.js";
16
16
  export * from "./Video/block.js";
17
17
 
18
18
  export { EMPTY_CELL_HEIGHT, EMPTY_CELL_WIDTH } from "./Table/TableExtension.js";
19
+ export * from "./Code/helpers/parse/parsePreCode.js";
20
+ export * from "./Code/helpers/render/createCodeBlock.js";
21
+ export * from "./Code/helpers/toExternalHTML/createPreCode.js";
19
22
  export * from "./ToggleWrapper/createToggleWrapper.js";
20
- export * from "./File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.js";
21
23
  export * from "./PageBreak/getPageBreakSlashMenuItems.js";
22
24
 
23
25
  export * from "./BlockNoteSchema.js";
@@ -117,11 +117,9 @@ export const CommentsExtension = createExtension(
117
117
  threadPositions: new Map<string, { from: number; to: number }>(),
118
118
  },
119
119
  {
120
- onUpdate() {
120
+ onUpdate(state, prevState) {
121
121
  // If the selected thread id changed, we need to update the decorations
122
- if (
123
- store.state.selectedThreadId !== store.prevState.selectedThreadId
124
- ) {
122
+ if (state.selectedThreadId !== prevState.selectedThreadId) {
125
123
  // So, we issue a transaction to update the decorations
126
124
  editor.transact((tr) => tr.setMeta(PLUGIN_KEY, true));
127
125
  }
@@ -22,9 +22,27 @@ BASIC STYLES
22
22
 
23
23
  .bn-block-content.ProseMirror-selectednode > *,
24
24
  /* Case for node view renderers */
25
- .ProseMirror-selectednode > .bn-block-content > * {
25
+ .ProseMirror-selectednode > .bn-block-content > *,
26
+ /* Case for blocks/inline content where class is set manually */
27
+ .bn-block-content .ProseMirror-selectednode,
28
+ .bn-inline-content .ProseMirror-selectednode {
29
+ /* Anchor for the `::after` highlight overlay below. */
30
+ position: relative;
31
+ }
32
+
33
+ /* Draws the selection highlight (border + translucent fill) as an overlay on
34
+ top of the element's content */
35
+ .bn-block-content.ProseMirror-selectednode > *::after,
36
+ .ProseMirror-selectednode > .bn-block-content > *::after,
37
+ .bn-block-content .ProseMirror-selectednode::after,
38
+ .bn-inline-content .ProseMirror-selectednode::after {
39
+ content: "";
40
+ position: absolute;
41
+ inset: 0;
26
42
  border-radius: 4px;
27
- outline: 4px solid rgb(100, 160, 255);
43
+ background-color: rgba(100, 160, 255, 0.08);
44
+ box-shadow: inset 0 0 0 4px rgba(100, 160, 255, 0.3);
45
+ pointer-events: none;
28
46
  }
29
47
 
30
48
  .bn-block-content::before {
@@ -468,6 +486,259 @@ NESTED BLOCKS
468
486
  transition-delay: 0.1s;
469
487
  }
470
488
 
489
+ /* CODE BLOCK PREVIEW */
490
+ .bn-block-content[data-content-type="codeBlock"]:has(
491
+ .bn-preview-with-source-popup
492
+ ) {
493
+ background-color: transparent;
494
+ color: inherit;
495
+ }
496
+
497
+ /* Default to dark theme as the code block has a dark background regardless of theme. */
498
+ .shiki {
499
+ color: var(--shiki-dark);
500
+ }
501
+ .bn-source-block-popup .shiki {
502
+ color: var(--shiki-light);
503
+ }
504
+ .bn-root[data-color-scheme="dark"] .bn-source-block-popup .shiki {
505
+ color: var(--shiki-dark);
506
+ }
507
+
508
+ .bn-preview-with-source-popup {
509
+ position: relative;
510
+ }
511
+
512
+ .bn-block-content .bn-preview-with-source-popup {
513
+ display: flex;
514
+ padding: 12px;
515
+ width: 100%;
516
+ }
517
+
518
+ .bn-inline-content-section .bn-preview-with-source-popup {
519
+ display: inline-block;
520
+ padding: 0;
521
+ width: fit-content;
522
+ }
523
+
524
+ .bn-preview-container {
525
+ anchor-name: --bn-source-popup-anchor;
526
+ cursor: pointer;
527
+ }
528
+
529
+ .bn-block-content .bn-preview-container {
530
+ overflow: auto;
531
+ width: 100%;
532
+ }
533
+
534
+ .bn-inline-content-section .bn-preview-container {
535
+ overflow: visible;
536
+ width: fit-content;
537
+ }
538
+
539
+ /* Additional right padding for equation numbers. */
540
+ .bn-block-content .bn-preview-container .katex-html:has(> .tag) {
541
+ box-sizing: border-box;
542
+ width: max-content;
543
+ min-width: 100%;
544
+ padding-right: 2.5em;
545
+ }
546
+
547
+ .bn-source-block-popup {
548
+ background-color: transparent;
549
+ border: none;
550
+ border-radius: 0;
551
+ box-shadow: none;
552
+ color: transparent;
553
+ height: 0;
554
+ left: 0;
555
+ margin-top: 4px;
556
+ overflow: clip;
557
+ position: absolute;
558
+ top: 100%;
559
+ width: 0;
560
+ z-index: 0;
561
+ }
562
+
563
+ .bn-preview-with-source-popup[data-open="true"] .bn-source-block-popup {
564
+ background-color: var(--bn-colors-menu-background);
565
+ border: var(--bn-border);
566
+ border-radius: var(--bn-border-radius-medium);
567
+ box-shadow: var(--bn-shadow-medium);
568
+ color: var(--bn-colors-menu-text);
569
+ height: unset;
570
+ z-index: 1;
571
+ }
572
+
573
+ .bn-block-content
574
+ .bn-preview-with-source-popup[data-open="true"]
575
+ .bn-source-block-popup {
576
+ width: 100%;
577
+ }
578
+
579
+ .bn-inline-content-section
580
+ .bn-preview-with-source-popup[data-open="true"]
581
+ .bn-source-block-popup {
582
+ width: 300px;
583
+ }
584
+
585
+ .bn-code-block-source-popup-body {
586
+ align-items: flex-end;
587
+ display: flex;
588
+ }
589
+
590
+ .bn-code-block-source-popup-body > pre {
591
+ align-self: center;
592
+ flex: 1;
593
+ margin: 0;
594
+ max-height: 200px;
595
+ overflow: auto;
596
+ padding: 16px;
597
+ position: relative;
598
+ tab-size: 2;
599
+ white-space: pre;
600
+ width: 0;
601
+ }
602
+
603
+ .bn-code-block-source-popup-input-empty::before {
604
+ color: currentColor;
605
+ content: attr(data-placeholder);
606
+ left: 16px;
607
+ opacity: 0.5;
608
+ overflow: hidden;
609
+ pointer-events: none;
610
+ position: absolute;
611
+ right: 16px;
612
+ text-overflow: ellipsis;
613
+ top: 16px;
614
+ white-space: nowrap;
615
+ }
616
+
617
+ .bn-code-block-source-error {
618
+ border-top: var(--bn-border);
619
+ color: var(--bn-colors-highlights-red-text);
620
+ font-size: 0.8em;
621
+ padding: 8px 16px;
622
+ white-space: pre-wrap !important;
623
+ font-family: monospace;
624
+ }
625
+
626
+ .bn-code-block-source-popup-ok-button-wrapper {
627
+ align-items: flex-end;
628
+ justify-content: flex-end;
629
+ padding: 14px 16px;
630
+ }
631
+
632
+ .bn-code-block-source-popup-ok-button {
633
+ align-items: center;
634
+ appearance: none;
635
+ background-color: rgb(37, 99, 235);
636
+ border: none;
637
+ border-radius: var(--bn-border-radius-small);
638
+ color: white;
639
+ cursor: pointer;
640
+ display: flex;
641
+ font-size: 0.8em;
642
+ font-weight: 500;
643
+ gap: 4px;
644
+ padding: 4px 8px;
645
+ }
646
+
647
+ .bn-code-block-source-popup-ok-button-icon {
648
+ height: 1.2em;
649
+ width: 1.2em;
650
+ }
651
+
652
+ .bn-code-block-source-popup-ok-button:hover {
653
+ background-color: rgb(29, 78, 216);
654
+ }
655
+
656
+ .bn-preview-with-source-popup:has(.bn-preview-placeholder) {
657
+ padding: 0;
658
+ }
659
+
660
+ .bn-preview-placeholder {
661
+ align-items: center;
662
+ background-color: rgb(242, 241, 238);
663
+ border-radius: 4px;
664
+ color: rgb(95, 91, 92);
665
+ display: flex;
666
+ }
667
+
668
+ .bn-block-content .bn-preview-placeholder {
669
+ gap: 10px;
670
+ padding: 12px;
671
+ }
672
+
673
+ .bn-inline-content-section .bn-preview-placeholder {
674
+ gap: 4px;
675
+ padding: 0 4px;
676
+ }
677
+
678
+ .bn-preview-placeholder:where(.dark, .dark *) {
679
+ background-color: rgb(70, 70, 70);
680
+ color: rgb(190, 190, 190);
681
+ }
682
+
683
+ .bn-editor[contenteditable="true"]
684
+ .bn-preview-placeholder:not(.bn-preview-placeholder-error):hover {
685
+ background-color: rgb(225, 225, 225);
686
+ }
687
+
688
+ .bn-editor[contenteditable="true"]
689
+ .bn-preview-placeholder:not(.bn-preview-placeholder-error):hover:where(
690
+ .dark,
691
+ .dark *
692
+ ) {
693
+ background-color: rgb(90, 90, 90);
694
+ }
695
+
696
+ .bn-preview-placeholder-error {
697
+ background-color: var(--bn-colors-highlights-red-background);
698
+ color: var(--bn-colors-highlights-red-text);
699
+ }
700
+
701
+ .bn-preview-placeholder-icon {
702
+ align-items: center;
703
+ display: flex;
704
+ }
705
+
706
+ .bn-block-content .bn-preview-placeholder-icon {
707
+ height: 24px;
708
+ width: 24px;
709
+ }
710
+
711
+ .bn-inline-content-section .bn-preview-placeholder-icon {
712
+ height: 14px;
713
+ width: 14px;
714
+ }
715
+
716
+ .bn-preview-placeholder-icon > svg {
717
+ height: 100%;
718
+ width: 100%;
719
+ }
720
+
721
+ .bn-preview-placeholder-text {
722
+ margin: 0;
723
+ }
724
+
725
+ .bn-block-content .bn-preview-placeholder-text {
726
+ font-size: 0.9rem;
727
+ }
728
+
729
+ .bn-inline-content-section .bn-preview-placeholder-text {
730
+ font-size: 0.7rem;
731
+ }
732
+
733
+ /* Toggled for a single frame while an up/down arrow press is handled, so the
734
+ browser's geometry-based vertical caret movement skips the popup. */
735
+ .bn-suppress-source-popup-caret
736
+ .bn-inline-content-section
737
+ .bn-preview-with-source-popup:not([data-open="true"])
738
+ .bn-source-block-popup {
739
+ visibility: hidden;
740
+ }
741
+
471
742
  /* PAGE BREAK */
472
743
  .bn-block-content[data-content-type="pageBreak"] > div {
473
744
  width: 100%;
@@ -41,7 +41,11 @@ import "../style.css";
41
41
  import { mergeCSSClasses } from "../util/browser.js";
42
42
  import { EventEmitter } from "../util/EventEmitter.js";
43
43
  import type { NoInfer } from "../util/typescript.js";
44
- import { ExtensionFactoryInstance } from "./BlockNoteExtension.js";
44
+ import {
45
+ Extension,
46
+ ExtensionFactory,
47
+ ExtensionFactoryInstance,
48
+ } from "./BlockNoteExtension.js";
45
49
  import type { TextCursorPosition } from "./cursorPositionTypes.js";
46
50
  import {
47
51
  BlockManager,
@@ -690,9 +694,26 @@ export class BlockNoteEditor<
690
694
  /**
691
695
  * Get an extension from the editor
692
696
  */
693
- public getExtension: ExtensionManager["getExtension"] = ((
694
- ...args: Parameters<ExtensionManager["getExtension"]>
695
- ) => this._extensionManager.getExtension(...args)) as any;
697
+ // Declared as an explicit intersection of the two `ExtensionManager`
698
+ // overloads rather than `ExtensionManager["getExtension"]`: indexed access on
699
+ // an overloaded method collapses the signatures, which widened the factory
700
+ // overload's `ReturnType<ReturnType<T>>` result to `any` (losing e.g. a
701
+ // returned extension's `store` type).
702
+ public getExtension: (<
703
+ const Ext extends Extension | ExtensionFactory = Extension,
704
+ >(
705
+ extension: string,
706
+ ) =>
707
+ | (Ext extends Extension
708
+ ? Ext
709
+ : Ext extends ExtensionFactory
710
+ ? ReturnType<ReturnType<Ext>>
711
+ : never)
712
+ | undefined) &
713
+ (<const T extends ExtensionFactory>(
714
+ extension: T,
715
+ ) => ReturnType<ReturnType<T>> | undefined) = ((extension: any) =>
716
+ this._extensionManager.getExtension(extension)) as any;
696
717
 
697
718
  /**
698
719
  * Mount the editor to a DOM element.
@@ -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
  import { originalFactorySymbol } from "./managers/ExtensionManager/symbol.js";
7
7
 
@@ -15,6 +15,7 @@ import {
15
15
  FilePanelExtension,
16
16
  FormattingToolbarExtension,
17
17
  HistoryExtension,
18
+ InlineContentBoundaryEditExtension,
18
19
  LinkToolbarExtension,
19
20
  NodeSelectionKeyboardExtension,
20
21
  PlaceholderExtension,
@@ -22,6 +23,8 @@ import {
22
23
  PreviousBlockTypeExtension,
23
24
  ShowSelectionExtension,
24
25
  SideMenuExtension,
26
+ SourceBlockWithPreviewExtension,
27
+ SourceInlineContentWithPreviewExtension,
25
28
  SuggestionMenu,
26
29
  TableHandlesExtension,
27
30
  TrailingNodeExtension,
@@ -167,8 +170,11 @@ export function getDefaultExtensions(
167
170
  PlaceholderExtension(options),
168
171
  ShowSelectionExtension(options),
169
172
  SideMenuExtension(options),
173
+ SourceBlockWithPreviewExtension(),
174
+ SourceInlineContentWithPreviewExtension(),
170
175
  SuggestionMenu(options),
171
176
  HistoryExtension(),
177
+ InlineContentBoundaryEditExtension(),
172
178
  PositionMappingExtension(),
173
179
  ...(options.trailingBlock !== false ? [TrailingNodeExtension()] : []),
174
180
  ] as ExtensionFactoryInstance[];
@@ -144,4 +144,49 @@ describe("Performance: transaction processing scales sub-linearly (#2595)", () =
144
144
  // Absolute time (~40ms) is comparable to begin (~32ms).
145
145
  expect(ratio).toBeLessThan(250);
146
146
  });
147
+
148
+ // getChanges() is lazy — it only diffs when a subscriber calls it, so the tests
149
+ // above don't cover getBlocksChangedByTransaction. This locks in that the diff
150
+ // scopes to the changed range, not the whole document.
151
+ it(
152
+ "getChanges() in onChange scales sub-linearly",
153
+ { timeout: 30_000 },
154
+ () => {
155
+ function measureWithGetChanges(
156
+ editor: BlockNoteEditor<any, any, any>,
157
+ pos: number,
158
+ ) {
159
+ // Run the diff every transaction, like an app reading changed blocks per keystroke.
160
+ // eslint-disable-next-line @typescript-eslint/unbound-method -- getChanges is destructured from callback parameter, not a class
161
+ const unsubscribe = editor.onChange((_editor, { getChanges }) => {
162
+ getChanges();
163
+ });
164
+ const avg = measureAvgInsertTime(editor, pos);
165
+ unsubscribe();
166
+ return avg;
167
+ }
168
+
169
+ const smallEditor = createEditorWithBlocks(SMALL, "paragraph");
170
+ const largeEditor = createEditorWithBlocks(LARGE, "paragraph");
171
+
172
+ const smallAvg = measureWithGetChanges(
173
+ smallEditor,
174
+ smallEditor._tiptapEditor.view.state.doc.content.size - 2,
175
+ );
176
+ const largeAvg = measureWithGetChanges(
177
+ largeEditor,
178
+ largeEditor._tiptapEditor.view.state.doc.content.size - 2,
179
+ );
180
+ const ratio = largeAvg / smallAvg;
181
+
182
+ // eslint-disable-next-line no-console
183
+ console.log(
184
+ `getChanges (end): ${SMALL}=${smallAvg.toFixed(3)}ms, ${LARGE}=${largeAvg.toFixed(3)}ms, ratio=${ratio.toFixed(2)}x`,
185
+ );
186
+
187
+ // The full-document snapshot made getChanges O(blocks) per keystroke, pushing
188
+ // this toward the block-count ratio (~50x); the ranged diff stays well below.
189
+ expect(ratio).toBeLessThan(50);
190
+ },
191
+ );
147
192
  });
@@ -0,0 +1,50 @@
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
+ /**
26
+ * Encodes bytes as base64. This papers over a platform gap: until
27
+ * `Uint8Array.prototype.toBase64()` (ES2026) is available in every runtime
28
+ * BlockNote supports, the only universal built-in is `btoa`, which takes
29
+ * binary *strings*. Uses `toBase64` when the runtime has it.
30
+ */
31
+ export function bytesToBase64(bytes: Uint8Array): string {
32
+ if ("toBase64" in bytes && typeof bytes.toBase64 === "function") {
33
+ return (bytes as Uint8Array & { toBase64(): string }).toBase64();
34
+ }
35
+
36
+ let binary = "";
37
+ for (const byte of bytes) {
38
+ binary += String.fromCharCode(byte);
39
+ }
40
+ return btoa(binary);
41
+ }
42
+
43
+ /**
44
+ * Encodes an {@link ExportImage}'s bytes as a base64 data URL, for targets
45
+ * that take image sources as URLs (HTML `src` attributes, react-pdf image
46
+ * sources, ...).
47
+ */
48
+ export function exportImageToDataURL(image: ExportImage): string {
49
+ return `data:${image.mimeType};base64,${bytesToBase64(image.data)}`;
50
+ }
@@ -0,0 +1,186 @@
1
+ import { describe, expect, it } from "vite-plus/test";
2
+ import {
3
+ BlockNoteSchema,
4
+ BlockSchema,
5
+ COLORS_DEFAULT,
6
+ createBlockSpec,
7
+ createInlineContentSpec,
8
+ createStyleSpec,
9
+ defaultBlockSpecs,
10
+ defaultInlineContentSpecs,
11
+ defaultStyleSpecs,
12
+ InlineContentSchema,
13
+ StyledText,
14
+ StyleSchema,
15
+ } from "../index.js";
16
+ import { Exporter } from "./Exporter.js";
17
+ import { BlockMapping, InlineContentMapping, StyleMapping } from "./mapping.js";
18
+
19
+ /**
20
+ * Type-level tests for the base `Exporter`: the constructor's `mappings`
21
+ * argument must cover every block / inline-content / style type in the schema.
22
+ * This enforcement lives entirely in the generic base class, so the tests live
23
+ * here rather than being duplicated in each concrete exporter.
24
+ *
25
+ * A minimal concrete exporter with `string` result types exercises the typing;
26
+ * the tests pass as long as the file type-checks (the `@ts-expect-error`
27
+ * directives assert that the omissions are compile errors).
28
+ */
29
+ class TestExporter<
30
+ B extends BlockSchema,
31
+ I extends InlineContentSchema,
32
+ S extends StyleSchema,
33
+ > extends Exporter<B, I, S, string, string, string, string> {
34
+ public constructor(
35
+ schema: BlockNoteSchema<B, I, S>,
36
+ // NoInfer so B/I/S come from the schema only (matching the real exporters);
37
+ // the mappings are then type-checked against it.
38
+ mappings: Exporter<
39
+ NoInfer<B>,
40
+ NoInfer<I>,
41
+ NoInfer<S>,
42
+ string,
43
+ string,
44
+ string,
45
+ string
46
+ >["mappings"],
47
+ ) {
48
+ super(schema, mappings, { colors: COLORS_DEFAULT });
49
+ }
50
+
51
+ public transformStyledText(_styledText: StyledText<S>): string {
52
+ return "";
53
+ }
54
+ }
55
+
56
+ // Mappings covering the default schema, used as the baseline. These tests are
57
+ // purely type-level (nothing is ever invoked), so only the declared types
58
+ // matter - plain casts, no runtime construction.
59
+ const defaultSchema = BlockNoteSchema.create();
60
+ const blockMapping = {} as BlockMapping<
61
+ typeof defaultSchema.blockSchema,
62
+ typeof defaultSchema.inlineContentSchema,
63
+ typeof defaultSchema.styleSchema,
64
+ string,
65
+ string
66
+ >;
67
+ const inlineContentMapping = {} as InlineContentMapping<
68
+ typeof defaultSchema.inlineContentSchema,
69
+ typeof defaultSchema.styleSchema,
70
+ string,
71
+ string
72
+ >;
73
+ const styleMapping = {} as StyleMapping<
74
+ typeof defaultSchema.styleSchema,
75
+ string
76
+ >;
77
+ const defaultMappings = { blockMapping, inlineContentMapping, styleMapping };
78
+
79
+ describe("Exporter mapping typing", () => {
80
+ it("typescript: a schema with an extra block requires a mapping for it", () => {
81
+ const schema = BlockNoteSchema.create({
82
+ blockSpecs: {
83
+ ...defaultBlockSpecs,
84
+ extraBlock: createBlockSpec(
85
+ { content: "none", type: "extraBlock", propSchema: {} },
86
+ {} as any,
87
+ )(),
88
+ },
89
+ });
90
+
91
+ // @ts-expect-error - extraBlock has no mapping
92
+ new TestExporter(schema, defaultMappings);
93
+ });
94
+
95
+ it("typescript: a schema with extra inline content requires a mapping for it", () => {
96
+ const schema = BlockNoteSchema.create({
97
+ inlineContentSpecs: {
98
+ ...defaultInlineContentSpecs,
99
+ extraInlineContent: createInlineContentSpec(
100
+ { type: "extraInlineContent", content: "styled", propSchema: {} },
101
+ {} as any,
102
+ ),
103
+ },
104
+ });
105
+
106
+ // @ts-expect-error - extraInlineContent has no mapping
107
+ new TestExporter(schema, defaultMappings);
108
+ });
109
+
110
+ it("typescript: a schema with an extra style requires a mapping for it", () => {
111
+ const schema = BlockNoteSchema.create({
112
+ styleSpecs: {
113
+ ...defaultStyleSpecs,
114
+ extraStyle: createStyleSpec(
115
+ { type: "extraStyle", propSchema: "boolean" },
116
+ {} as any,
117
+ ),
118
+ },
119
+ });
120
+
121
+ // @ts-expect-error - extraStyle has no mapping
122
+ new TestExporter(schema, defaultMappings);
123
+ });
124
+
125
+ it("typescript: a mapping covering more block types than the schema is allowed", () => {
126
+ // Only a subset of the default blocks; the default mappings are a superset.
127
+ const schema = BlockNoteSchema.create({
128
+ blockSpecs: { paragraph: defaultBlockSpecs.paragraph },
129
+ });
130
+
131
+ // no error — extra mappings are fine
132
+ new TestExporter(schema, defaultMappings);
133
+ });
134
+ });
135
+
136
+ // A minimal concrete exporter with empty mappings, to exercise the
137
+ // missing-mapping errors thrown when a document contains block types the
138
+ // mappings don't cover (e.g. blocks from separate packages, like math,
139
+ // without their exporter mappings spread in).
140
+ class EmptyMappingsExporter extends Exporter<
141
+ any,
142
+ any,
143
+ any,
144
+ void,
145
+ void,
146
+ void,
147
+ void
148
+ > {
149
+ constructor() {
150
+ super(
151
+ BlockNoteSchema.create(),
152
+ { blockMapping: {}, inlineContentMapping: {}, styleMapping: {} } as any,
153
+ { colors: COLORS_DEFAULT },
154
+ );
155
+ }
156
+
157
+ public transformStyledText(_styledText: StyledText<any>) {
158
+ return undefined;
159
+ }
160
+ }
161
+
162
+ describe("Exporter missing mappings", () => {
163
+ it("throws a descriptive error for an unmapped block type", async () => {
164
+ await expect(
165
+ new EmptyMappingsExporter().mapBlock({ type: "math" } as any, 0, 0),
166
+ ).rejects.toThrow(
167
+ 'missing a block mapping for block type "math". If this block comes from a separate package, spread that package\'s exporter mappings',
168
+ );
169
+ });
170
+
171
+ it("throws a descriptive error for an unmapped inline content type", () => {
172
+ expect(() =>
173
+ new EmptyMappingsExporter().mapInlineContent({
174
+ type: "inlineMath",
175
+ } as any),
176
+ ).toThrow(
177
+ 'missing an inline content mapping for inline content type "inlineMath"',
178
+ );
179
+ });
180
+
181
+ it("throws a descriptive error for an unmapped style", () => {
182
+ expect(() =>
183
+ new EmptyMappingsExporter().mapStyles({ bold: true } as any),
184
+ ).toThrow('missing a style mapping for style "bold"');
185
+ });
186
+ });