@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
@@ -168,6 +168,10 @@ export const fa = {
168
168
  toggle_blocks: {
169
169
  add_block_button: "تاشوی خالی. برای افزودن بلوک کلیک کنید.",
170
170
  },
171
+ code_block: {
172
+ add_source_button_text: "افزودن کد منبع",
173
+ ok_button_text: "تأیید",
174
+ },
171
175
  // from react package:
172
176
  side_menu: {
173
177
  add_block_label: "افزودن بلوک",
@@ -379,6 +383,11 @@ export const fa = {
379
383
  formatting_change_by: (formats: string, users: string) =>
380
384
  `تغییر قالب‌بندی (${formats}) توسط: ${users}`,
381
385
  },
386
+ exporter: {
387
+ open_file: "باز کردن فایل",
388
+ open_video_file: "باز کردن ویدیو",
389
+ open_audio_file: "باز کردن صدا",
390
+ },
382
391
  generic: {
383
392
  ctrl_shortcut: "Ctrl",
384
393
  },
@@ -246,6 +246,10 @@ export const fr: Dictionary = {
246
246
  toggle_blocks: {
247
247
  add_block_button: "Liste repliable vide. Cliquez pour ajouter un bloc.",
248
248
  },
249
+ code_block: {
250
+ add_source_button_text: "Ajouter le code source",
251
+ ok_button_text: "OK",
252
+ },
249
253
  // from react package:
250
254
  side_menu: {
251
255
  add_block_label: "Ajouter un bloc",
@@ -456,6 +460,11 @@ export const fr: Dictionary = {
456
460
  formatting_change_by: (formats: string, users: string) =>
457
461
  `Modification de mise en forme (${formats}) par : ${users}`,
458
462
  },
463
+ exporter: {
464
+ open_file: "Ouvrir le fichier",
465
+ open_video_file: "Ouvrir la vidéo",
466
+ open_audio_file: "Ouvrir l'audio",
467
+ },
459
468
  generic: {
460
469
  ctrl_shortcut: "Ctrl",
461
470
  },
@@ -202,6 +202,10 @@ export const he: Dictionary = {
202
202
  toggle_blocks: {
203
203
  add_block_button: "מתג ריק. לחץ כדי להוסיף בלוק.",
204
204
  },
205
+ code_block: {
206
+ add_source_button_text: "הוסף קוד מקור",
207
+ ok_button_text: "אישור",
208
+ },
205
209
  side_menu: {
206
210
  add_block_label: "הוסף בלוק",
207
211
  drag_handle_label: "פתח תפריט בלוק",
@@ -410,6 +414,11 @@ export const he: Dictionary = {
410
414
  formatting_change_by: (formats: string, users: string) =>
411
415
  `שינוי עיצוב (${formats}) על ידי: ${users}`,
412
416
  },
417
+ exporter: {
418
+ open_file: "פתח קובץ",
419
+ open_video_file: "פתח וידאו",
420
+ open_audio_file: "פתח שמע",
421
+ },
413
422
  generic: {
414
423
  ctrl_shortcut: "Ctrl",
415
424
  },
@@ -213,6 +213,10 @@ export const hr: Dictionary = {
213
213
  toggle_blocks: {
214
214
  add_block_button: "Prazan sklopivi blok. Klikni da dodaš sadržaj.",
215
215
  },
216
+ code_block: {
217
+ add_source_button_text: "Dodaj izvorni kôd",
218
+ ok_button_text: "U redu",
219
+ },
216
220
  // from react package:
217
221
  side_menu: {
218
222
  add_block_label: "Dodaj blok",
@@ -424,6 +428,11 @@ export const hr: Dictionary = {
424
428
  formatting_change_by: (formats: string, users: string) =>
425
429
  `Promjena oblikovanja (${formats}) od: ${users}`,
426
430
  },
431
+ exporter: {
432
+ open_file: "Otvori datoteku",
433
+ open_video_file: "Otvori videozapis",
434
+ open_audio_file: "Otvori audiozapis",
435
+ },
427
436
  generic: {
428
437
  ctrl_shortcut: "Ctrl",
429
438
  },
@@ -214,6 +214,10 @@ export const is: Dictionary = {
214
214
  toggle_blocks: {
215
215
  add_block_button: "Tóm fellilína. Smelltu til að bæta við blokk.",
216
216
  },
217
+ code_block: {
218
+ add_source_button_text: "Bæta við frumkóða",
219
+ ok_button_text: "Í lagi",
220
+ },
217
221
  side_menu: {
218
222
  add_block_label: "Bæta við blokki",
219
223
  drag_handle_label: "Opna blokkarvalmynd",
@@ -424,6 +428,11 @@ export const is: Dictionary = {
424
428
  formatting_change_by: (formats: string, users: string) =>
425
429
  `Sniðbreyting (${formats}) af: ${users}`,
426
430
  },
431
+ exporter: {
432
+ open_file: "Opna skrá",
433
+ open_video_file: "Opna myndband",
434
+ open_audio_file: "Opna hljóð",
435
+ },
427
436
  generic: {
428
437
  ctrl_shortcut: "Ctrl",
429
438
  },
@@ -222,6 +222,10 @@ export const it: Dictionary = {
222
222
  toggle_blocks: {
223
223
  add_block_button: "Toggle vuoto. Clicca per aggiungere un blocco.",
224
224
  },
225
+ code_block: {
226
+ add_source_button_text: "Aggiungi codice sorgente",
227
+ ok_button_text: "OK",
228
+ },
225
229
  // from react package:
226
230
  side_menu: {
227
231
  add_block_label: "Aggiungi blocco",
@@ -432,6 +436,11 @@ export const it: Dictionary = {
432
436
  formatting_change_by: (formats: string, users: string) =>
433
437
  `Modifica formattazione (${formats}) da: ${users}`,
434
438
  },
439
+ exporter: {
440
+ open_file: "Apri file",
441
+ open_video_file: "Apri video",
442
+ open_audio_file: "Apri audio",
443
+ },
435
444
  generic: {
436
445
  ctrl_shortcut: "Ctrl",
437
446
  },
@@ -240,6 +240,10 @@ export const ja: Dictionary = {
240
240
  toggle_blocks: {
241
241
  add_block_button: "空のトグルです。クリックしてブロックを追加。",
242
242
  },
243
+ code_block: {
244
+ add_source_button_text: "ソースコードを追加",
245
+ ok_button_text: "OK",
246
+ },
243
247
  // from react package:
244
248
  side_menu: {
245
249
  add_block_label: "ブロックを追加",
@@ -450,6 +454,11 @@ export const ja: Dictionary = {
450
454
  formatting_change_by: (formats: string, users: string) =>
451
455
  `書式の変更 (${formats}) 変更者: ${users}`,
452
456
  },
457
+ exporter: {
458
+ open_file: "ファイルを開く",
459
+ open_video_file: "動画を開く",
460
+ open_audio_file: "音声を開く",
461
+ },
453
462
  generic: {
454
463
  ctrl_shortcut: "Ctrl",
455
464
  },
@@ -213,6 +213,10 @@ export const ko: Dictionary = {
213
213
  toggle_blocks: {
214
214
  add_block_button: "비어 있는 토글입니다. 클릭하여 블록을 추가하세요.",
215
215
  },
216
+ code_block: {
217
+ add_source_button_text: "소스 코드 추가",
218
+ ok_button_text: "확인",
219
+ },
216
220
  // from react package:
217
221
  side_menu: {
218
222
  add_block_label: "블록 추가",
@@ -423,6 +427,11 @@ export const ko: Dictionary = {
423
427
  formatting_change_by: (formats: string, users: string) =>
424
428
  `서식 변경 (${formats}) 변경한 사람: ${users}`,
425
429
  },
430
+ exporter: {
431
+ open_file: "파일 열기",
432
+ open_video_file: "동영상 열기",
433
+ open_audio_file: "오디오 열기",
434
+ },
426
435
  generic: {
427
436
  ctrl_shortcut: "Ctrl",
428
437
  },
@@ -201,6 +201,10 @@ export const nl: Dictionary = {
201
201
  toggle_blocks: {
202
202
  add_block_button: "Lege uitklapper. Klik om een blok toe te voegen.",
203
203
  },
204
+ code_block: {
205
+ add_source_button_text: "Broncode toevoegen",
206
+ ok_button_text: "OK",
207
+ },
204
208
  // from react package:
205
209
  side_menu: {
206
210
  add_block_label: "Nieuw blok",
@@ -411,6 +415,11 @@ export const nl: Dictionary = {
411
415
  formatting_change_by: (formats: string, users: string) =>
412
416
  `Opmaakwijziging (${formats}) door: ${users}`,
413
417
  },
418
+ exporter: {
419
+ open_file: "Bestand openen",
420
+ open_video_file: "Video openen",
421
+ open_audio_file: "Audio openen",
422
+ },
414
423
  generic: {
415
424
  ctrl_shortcut: "Ctrl",
416
425
  },
@@ -219,6 +219,10 @@ export const no: Dictionary = {
219
219
  toggle_blocks: {
220
220
  add_block_button: "Tomt toggle. Klikk for å legge til en blokk.",
221
221
  },
222
+ code_block: {
223
+ add_source_button_text: "Legg til kildekode",
224
+ ok_button_text: "OK",
225
+ },
222
226
  side_menu: {
223
227
  add_block_label: "Legg til blokk",
224
228
  drag_handle_label: "Åpne blokkmeny",
@@ -428,6 +432,11 @@ export const no: Dictionary = {
428
432
  formatting_change_by: (formats: string, users: string) =>
429
433
  `Formateringsendring (${formats}) av: ${users}`,
430
434
  },
435
+ exporter: {
436
+ open_file: "Åpne fil",
437
+ open_video_file: "Åpne video",
438
+ open_audio_file: "Åpne lyd",
439
+ },
431
440
  generic: {
432
441
  ctrl_shortcut: "Ctrl",
433
442
  },
@@ -192,6 +192,10 @@ export const pl: Dictionary = {
192
192
  add_block_button:
193
193
  "Brak bloków do rozwinięcia. Kliknij, aby dodać pierwszego.",
194
194
  },
195
+ code_block: {
196
+ add_source_button_text: "Dodaj kod źródłowy",
197
+ ok_button_text: "OK",
198
+ },
195
199
  side_menu: {
196
200
  add_block_label: "Dodaj blok",
197
201
  drag_handle_label: "Otwórz menu bloków",
@@ -401,6 +405,11 @@ export const pl: Dictionary = {
401
405
  formatting_change_by: (formats: string, users: string) =>
402
406
  `Zmiana formatowania (${formats}) przez: ${users}`,
403
407
  },
408
+ exporter: {
409
+ open_file: "Otwórz plik",
410
+ open_video_file: "Otwórz wideo",
411
+ open_audio_file: "Otwórz audio",
412
+ },
404
413
  generic: {
405
414
  ctrl_shortcut: "Ctrl",
406
415
  },
@@ -192,6 +192,10 @@ export const pt: Dictionary = {
192
192
  toggle_blocks: {
193
193
  add_block_button: "Toggle vazio. Clique para adicionar um bloco.",
194
194
  },
195
+ code_block: {
196
+ add_source_button_text: "Adicionar código-fonte",
197
+ ok_button_text: "OK",
198
+ },
195
199
  // from react package:
196
200
  side_menu: {
197
201
  add_block_label: "Adicionar bloco",
@@ -403,6 +407,11 @@ export const pt: Dictionary = {
403
407
  formatting_change_by: (formats: string, users: string) =>
404
408
  `Alteração de formatação (${formats}) por: ${users}`,
405
409
  },
410
+ exporter: {
411
+ open_file: "Abrir arquivo",
412
+ open_video_file: "Abrir vídeo",
413
+ open_audio_file: "Abrir áudio",
414
+ },
406
415
  generic: {
407
416
  ctrl_shortcut: "Ctrl",
408
417
  },
@@ -243,6 +243,10 @@ export const ru: Dictionary = {
243
243
  toggle_blocks: {
244
244
  add_block_button: "Пустой переключатель. Нажмите, чтобы добавить блок.",
245
245
  },
246
+ code_block: {
247
+ add_source_button_text: "Добавить исходный код",
248
+ ok_button_text: "ОК",
249
+ },
246
250
  // from react package:
247
251
  side_menu: {
248
252
  add_block_label: "Добавить блок",
@@ -454,6 +458,11 @@ export const ru: Dictionary = {
454
458
  formatting_change_by: (formats: string, users: string) =>
455
459
  `Изменение форматирования (${formats}): ${users}`,
456
460
  },
461
+ exporter: {
462
+ open_file: "Открыть файл",
463
+ open_video_file: "Открыть видео",
464
+ open_audio_file: "Открыть аудио",
465
+ },
457
466
  generic: {
458
467
  ctrl_shortcut: "Ctrl",
459
468
  },
@@ -200,6 +200,10 @@ export const sk = {
200
200
  toggle_blocks: {
201
201
  add_block_button: "Prázdne prepínanie. Kliknite pre pridanie bloku.",
202
202
  },
203
+ code_block: {
204
+ add_source_button_text: "Pridať zdrojový kód",
205
+ ok_button_text: "OK",
206
+ },
203
207
  side_menu: {
204
208
  add_block_label: "Pridať blok",
205
209
  drag_handle_label: "Otvoriť menu bloku",
@@ -408,6 +412,11 @@ export const sk = {
408
412
  formatting_change_by: (formats: string, users: string) =>
409
413
  `Zmena formátovania (${formats}) od: ${users}`,
410
414
  },
415
+ exporter: {
416
+ open_file: "Otvoriť súbor",
417
+ open_video_file: "Otvoriť video",
418
+ open_audio_file: "Otvoriť zvuk",
419
+ },
411
420
  generic: {
412
421
  ctrl_shortcut: "Ctrl",
413
422
  },
@@ -225,6 +225,10 @@ export const uk: Dictionary = {
225
225
  toggle_blocks: {
226
226
  add_block_button: "Порожній перемикач. Натисніть, щоб додати блок.",
227
227
  },
228
+ code_block: {
229
+ add_source_button_text: "Додати вихідний код",
230
+ ok_button_text: "ОК",
231
+ },
228
232
  // from react package:
229
233
  side_menu: {
230
234
  add_block_label: "Додати блок",
@@ -434,6 +438,11 @@ export const uk: Dictionary = {
434
438
  formatting_change_by: (formats: string, users: string) =>
435
439
  `Зміна форматування (${formats}) користувачем: ${users}`,
436
440
  },
441
+ exporter: {
442
+ open_file: "Відкрити файл",
443
+ open_video_file: "Відкрити відео",
444
+ open_audio_file: "Відкрити аудіо",
445
+ },
437
446
  generic: {
438
447
  ctrl_shortcut: "Ctrl",
439
448
  },
@@ -262,6 +262,10 @@ export const uz: Dictionary = {
262
262
  add_block_button: "Bo‘sh toggle. Blok qo‘shish uchun bosing.",
263
263
  },
264
264
 
265
+ code_block: {
266
+ add_source_button_text: "Manba kodini qoʻshish",
267
+ ok_button_text: "OK",
268
+ },
265
269
  side_menu: {
266
270
  add_block_label: "Blok qo‘shish",
267
271
  drag_handle_label: "Blok menyusini ochish",
@@ -444,6 +448,11 @@ export const uz: Dictionary = {
444
448
  formatting_change_by: (formats: string, users: string) =>
445
449
  `Formatlash o'zgarishi (${formats}), o'zgartirgan: ${users}`,
446
450
  },
451
+ exporter: {
452
+ open_file: "Faylni ochish",
453
+ open_video_file: "Videoni ochish",
454
+ open_audio_file: "Audioni ochish",
455
+ },
447
456
  generic: {
448
457
  ctrl_shortcut: "Ctrl",
449
458
  },
@@ -199,6 +199,10 @@ export const vi: Dictionary = {
199
199
  toggle_blocks: {
200
200
  add_block_button: "Toggle trống. Nhấp để thêm khối.",
201
201
  },
202
+ code_block: {
203
+ add_source_button_text: "Thêm mã nguồn",
204
+ ok_button_text: "OK",
205
+ },
202
206
  // từ gói phản ứng:
203
207
  side_menu: {
204
208
  add_block_label: "Thêm khối",
@@ -409,6 +413,11 @@ export const vi: Dictionary = {
409
413
  formatting_change_by: (formats: string, users: string) =>
410
414
  `Thay đổi định dạng (${formats}) bởi: ${users}`,
411
415
  },
416
+ exporter: {
417
+ open_file: "Mở tệp",
418
+ open_video_file: "Mở video",
419
+ open_audio_file: "Mở âm thanh",
420
+ },
412
421
  generic: {
413
422
  ctrl_shortcut: "Ctrl",
414
423
  },
@@ -241,6 +241,10 @@ export const zhTW: Dictionary = {
241
241
  toggle_blocks: {
242
242
  add_block_button: "空的切換區。點擊新增區塊。",
243
243
  },
244
+ code_block: {
245
+ add_source_button_text: "新增原始碼",
246
+ ok_button_text: "確定",
247
+ },
244
248
  // from react package:
245
249
  side_menu: {
246
250
  add_block_label: "新增區塊",
@@ -451,6 +455,11 @@ export const zhTW: Dictionary = {
451
455
  formatting_change_by: (formats: string, users: string) =>
452
456
  `格式變更(${formats}),變更者:${users}`,
453
457
  },
458
+ exporter: {
459
+ open_file: "開啟檔案",
460
+ open_video_file: "開啟影片",
461
+ open_audio_file: "開啟音訊",
462
+ },
454
463
  generic: {
455
464
  ctrl_shortcut: "Ctrl",
456
465
  },
@@ -241,6 +241,10 @@ export const zh: Dictionary = {
241
241
  toggle_blocks: {
242
242
  add_block_button: "空的切换区。点击添加区块。",
243
243
  },
244
+ code_block: {
245
+ add_source_button_text: "添加源代码",
246
+ ok_button_text: "确定",
247
+ },
244
248
  // from react package:
245
249
  side_menu: {
246
250
  add_block_label: "添加块",
@@ -451,6 +455,11 @@ export const zh: Dictionary = {
451
455
  formatting_change_by: (formats: string, users: string) =>
452
456
  `格式更改(${formats}),更改者:${users}`,
453
457
  },
458
+ exporter: {
459
+ open_file: "打开文件",
460
+ open_video_file: "打开视频",
461
+ open_audio_file: "打开音频",
462
+ },
454
463
  generic: {
455
464
  ctrl_shortcut: "Ctrl",
456
465
  },
package/src/index.ts CHANGED
@@ -23,11 +23,15 @@ export * from "./user/index.js";
23
23
  export * from "./util/browser.js";
24
24
  export * from "./util/combineByGroup.js";
25
25
  export * from "./util/expandToWords.js";
26
+ export * from "./util/Store.js";
26
27
  export * from "./util/string.js";
27
28
  export * from "./util/table.js";
28
29
  export * from "./util/typescript.js";
29
30
 
30
- export type { CodeBlockOptions } from "./blocks/Code/block.js";
31
+ export type {
32
+ CodeBlockOptions,
33
+ CodeBlockPreview,
34
+ } from "./blocks/Code/CodeBlockOptions.js";
31
35
  export { assertEmpty, UnreachableCaseError } from "./util/typescript.js";
32
36
 
33
37
  export * from "./util/EventEmitter.js";
@@ -37,6 +41,7 @@ export { selectedFragmentToHTML } from "./api/clipboard/toClipboard/copyExtensio
37
41
 
38
42
  // Node conversions
39
43
  export * from "./api/nodeConversions/blockToNode.js";
44
+ export * from "./api/nodeConversions/fragmentToBlocks.js";
40
45
  export * from "./api/nodeConversions/nodeToBlock.js";
41
46
  export * from "./extensions/tiptap-extensions/UniqueID/UniqueID.js";
42
47
 
@@ -12,9 +12,10 @@ import {
12
12
  ExtensionFactoryInstance,
13
13
  } from "../../editor/BlockNoteExtension.js";
14
14
  import { nonFormattingMarks } from "../markGroups.js";
15
+ import { ignoreNonContentMutations } from "../nodeViewMutations.js";
15
16
  import { PropSchema } from "../propTypes.js";
16
17
  import {
17
- getBlockFromPos,
18
+ getBlockFromNodeView,
18
19
  propsToAttributes,
19
20
  wrapInBlockStructure,
20
21
  } from "./internal.js";
@@ -246,8 +247,15 @@ export function addNodeAndExtensionsToSpec<
246
247
  return (props) => {
247
248
  // Gets the BlockNote editor instance
248
249
  const editor = this.options.editor;
249
- // Gets the block
250
- const block = getBlockFromPos(props.getPos, props.view.state.doc);
250
+ // Gets the block. Resolving this can't rely on `getPos()` alone —
251
+ // node views are constructed part-way through ProseMirror's
252
+ // reconciliation, where positions don't always line up with
253
+ // `view.state.doc` yet (see `getBlockFromNodeView`).
254
+ const block = getBlockFromNodeView(
255
+ props.getPos,
256
+ props.node,
257
+ props.view.state.doc,
258
+ );
251
259
  // Gets the custom HTML attributes for `blockContent` nodes
252
260
  const blockContentDOMAttributes =
253
261
  this.options.domAttributes?.blockContent || {};
@@ -271,10 +279,14 @@ export function addNodeAndExtensionsToSpec<
271
279
  applyNonSelectableBlockFix(typedNodeView, this.editor);
272
280
  }
273
281
 
282
+ // Ignores DOM mutations that don't affect the block's content, so
283
+ // that browser extensions which rewrite the DOM (e.g. Dark Reader)
284
+ // can't trigger an infinite re-render loop that freezes the tab.
285
+ ignoreNonContentMutations(typedNodeView);
286
+
274
287
  // See explanation for why `update` is not implemented for NodeViews
275
288
  // https://github.com/TypeCellOS/BlockNote/pull/1904#discussion_r2313461464
276
- // TODO: in a future version, we might want to implement updates so that
277
- // vanilla blocks don't always re-render entirely (https://github.com/TypeCellOS/BlockNote/issues/220)
289
+ // https://github.com/TypeCellOS/BlockNote/issues/220
278
290
  return typedNodeView;
279
291
  };
280
292
  },
@@ -0,0 +1,86 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from "vite-plus/test";
2
+
3
+ import { getNodeById } from "../../api/nodeUtil.js";
4
+ import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
5
+ import { getBlockFromNodeView } from "./internal.js";
6
+
7
+ describe("getBlockFromNodeView", () => {
8
+ let editor: BlockNoteEditor;
9
+
10
+ beforeEach(() => {
11
+ editor = BlockNoteEditor.create({
12
+ trailingBlock: false,
13
+ initialContent: [
14
+ { type: "paragraph", content: "first" },
15
+ { type: "paragraph", content: "second" },
16
+ ],
17
+ });
18
+ });
19
+
20
+ afterEach(() => {
21
+ // Leaving the editor alive leaks a ProseMirror `DOMObserver`, whose
22
+ // `stop()` schedules a `flush()` 20ms later. That can outlive the test
23
+ // environment and then fail the run with `ReferenceError: document is not
24
+ // defined`, attributed to whichever test file happens to be running.
25
+ editor._tiptapEditor.destroy();
26
+ editor = undefined as any;
27
+ });
28
+
29
+ it("resolves from the position when it is valid", () => {
30
+ const doc = editor.prosemirrorState.doc;
31
+ const target = editor.document[1];
32
+ // `getBlockFromPos` resolves the *parent* of the position, so the position
33
+ // sits just inside the block container — which is what ProseMirror hands a
34
+ // node view.
35
+ const pos = getNodeById(target.id, doc)!.posBeforeNode + 1;
36
+ const block = getBlockFromNodeView(() => pos, doc.nodeAt(pos)!, doc) as any;
37
+
38
+ expect(block.id).toBe(target.id);
39
+ });
40
+
41
+ it("builds a standalone block when the node is no longer in the document", () => {
42
+ // The only way `getPos()` fails at node view construction is a re-entrant
43
+ // dispatch superseding `view.state.doc`, which takes the node with it — so
44
+ // the node genuinely isn't in the document any more. See #2937.
45
+ const doc = editor.prosemirrorState.doc;
46
+ const orphan = editor.pmSchema.nodes.paragraph.create(
47
+ { textAlignment: "right" },
48
+ editor.pmSchema.text("orphaned content"),
49
+ );
50
+ const block = getBlockFromNodeView(
51
+ () => doc.content.size + 1000,
52
+ orphan,
53
+ doc,
54
+ ) as any;
55
+
56
+ // Everything readable off the node is correct...
57
+ expect(block.type).toBe("paragraph");
58
+ expect(block.props.textAlignment).toBe("right");
59
+ expect(block.content[0].text).toBe("orphaned content");
60
+ // ...but the id belongs to no block in the document, so it must not
61
+ // collide with a real one.
62
+ expect(editor.document.map((b) => b.id)).not.toContain(block.id);
63
+ });
64
+
65
+ it("recovers from an in-range position that resolves to the wrong node", () => {
66
+ // Position 0 resolves to the doc rather than a block container — the shape
67
+ // a bounds check alone would not catch.
68
+ const doc = editor.prosemirrorState.doc;
69
+ const orphan = editor.pmSchema.nodes.paragraph.create(
70
+ null,
71
+ editor.pmSchema.text("orphaned content"),
72
+ );
73
+ expect(() => getBlockFromNodeView(() => 0, orphan, doc)).not.toThrow();
74
+ });
75
+
76
+ it("recovers when the position is undefined", () => {
77
+ const doc = editor.prosemirrorState.doc;
78
+ const orphan = editor.pmSchema.nodes.paragraph.create(
79
+ null,
80
+ editor.pmSchema.text("orphaned content"),
81
+ );
82
+ expect(() =>
83
+ getBlockFromNodeView(() => undefined, orphan, doc),
84
+ ).not.toThrow();
85
+ });
86
+ });
@@ -93,6 +93,70 @@ export function getBlockFromPos(getPos: () => number | undefined, doc: PMNode) {
93
93
  return block;
94
94
  }
95
95
 
96
+ /**
97
+ * Resolves the block a node view should render, tolerating a `getPos()` that
98
+ * can't be trusted.
99
+ *
100
+ * ProseMirror derives `getPos()` from its view-desc tree, but
101
+ * `EditorView.updateStateInner` assigns the new state *before* it reconciles
102
+ * that tree. Anything that runs partway through reconciliation - a re-entrant
103
+ * dispatch from a node view's effect, TipTap's `flushSync` while mounting a
104
+ * node view - therefore sees positions that no longer line up with
105
+ * `view.state.doc`. The position then either lands out of range or, just as
106
+ * bad, in range but pointing at the wrong node.
107
+ *
108
+ * Node views are constructed inside that same window, so this applies at
109
+ * construction just as much as on re-render. The state is always transient:
110
+ * ProseMirror finishes reconciling and rebuilds the node view against the
111
+ * current document immediately after. So we degrade instead of throwing,
112
+ * because a stale frame is invisible where a throw is not.
113
+ *
114
+ * See issues #2937, #2682 and #2621.
115
+ */
116
+ export function getBlockFromNodeView(
117
+ getPos: () => number | undefined,
118
+ node: PMNode,
119
+ doc: PMNode,
120
+ ) {
121
+ try {
122
+ return getBlockFromPos(getPos, doc);
123
+ } catch (e) {
124
+ // Failing here means the node is not in `doc` — a re-entrant dispatch
125
+ // superseded the document ProseMirror is building node views for, and the
126
+ // node went with it. So there is no container to read an id from, and the
127
+ // block has to be built from the node alone. Deliberately silent: this is
128
+ // expected and self-correcting, and there is nothing a consumer could do
129
+ // about it in the meantime.
130
+ //
131
+ // `type`, `props` and `content` are read off the node and are correct.
132
+ // `children` is empty and `id` is freshly generated, i.e. it belongs to no
133
+ // block in the document — callers must not treat it as addressable. (It
134
+ // can't collide with a real block: ids are uuids, and the deterministic
135
+ // test-mode generator shares one monotonic counter with real ids.) This is
136
+ // short-lived; ProseMirror rebuilds the node view against the real document
137
+ // right after.
138
+ //
139
+ // The alternatives are worse. Throwing is the crash this exists to prevent.
140
+ // Returning an empty placeholder node view can leave the block
141
+ // *permanently* blank, since vanilla node views don't implement `update()`
142
+ // and so are only rebuilt when something else changes the document.
143
+ //
144
+ // `createAndFill` rather than `create` so an unexpected node shape yields
145
+ // `null` instead of throwing over the top of the original failure.
146
+ const standalone = doc.type.schema.nodes["blockContainer"]?.createAndFill(
147
+ null,
148
+ node,
149
+ );
150
+ if (standalone) {
151
+ return nodeToBlock(standalone, doc);
152
+ }
153
+
154
+ // Nothing left to render from. Surface the original failure rather than
155
+ // inventing a block that isn't grounded in anything.
156
+ throw e;
157
+ }
158
+ }
159
+
96
160
  // Function that wraps the `dom` element returned from 'blockConfig.render' in a
97
161
  // `blockContent` div, which contains the block type and props as HTML
98
162
  // attributes. If `blockConfig.render` also returns a `contentDOM`, it also adds