@blocknote/core 0.20.0 → 0.21.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 (168) hide show
  1. package/dist/blocknote.js +1743 -1734
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +7 -7
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.js +1 -1
  6. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.js.map +1 -1
  7. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.js +3 -3
  8. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.js.map +1 -1
  9. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js +1 -1
  10. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js.map +1 -1
  11. package/dist/src/api/blockManipulation/selections/selection.js +4 -4
  12. package/dist/src/api/blockManipulation/selections/selection.js.map +1 -1
  13. package/dist/src/api/clipboard/clipboard.test.js +6 -3
  14. package/dist/src/api/clipboard/clipboard.test.js.map +1 -1
  15. package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js +1 -1
  16. package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js.map +1 -1
  17. package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js +2 -3
  18. package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js.map +1 -1
  19. package/dist/src/api/clipboard/fromClipboard/pasteExtension.js +5 -5
  20. package/dist/src/api/clipboard/fromClipboard/pasteExtension.js.map +1 -1
  21. package/dist/src/api/clipboard/toClipboard/copyExtension.js +4 -2
  22. package/dist/src/api/clipboard/toClipboard/copyExtension.js.map +1 -1
  23. package/dist/src/api/parsers/markdown/parseMarkdown.test.js +4 -1
  24. package/dist/src/api/parsers/markdown/parseMarkdown.test.js.map +1 -1
  25. package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js +14 -7
  26. package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js.map +1 -1
  27. package/dist/src/blocks/AudioBlockContent/{audioBlockHelpers.js → parseAudioElement.js} +1 -1
  28. package/dist/src/blocks/AudioBlockContent/parseAudioElement.js.map +1 -0
  29. package/dist/src/blocks/FileBlockContent/FileBlockContent.js +5 -4
  30. package/dist/src/blocks/FileBlockContent/FileBlockContent.js.map +1 -1
  31. package/dist/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.js +5 -0
  32. package/dist/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.js.map +1 -0
  33. package/dist/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.js +10 -0
  34. package/dist/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.js.map +1 -0
  35. package/dist/src/blocks/FileBlockContent/helpers/render/createAddFileButton.js +39 -0
  36. package/dist/src/blocks/FileBlockContent/helpers/render/createAddFileButton.js.map +1 -0
  37. package/dist/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js +51 -0
  38. package/dist/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js.map +1 -0
  39. package/dist/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js +17 -0
  40. package/dist/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js.map +1 -0
  41. package/dist/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js +147 -0
  42. package/dist/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js.map +1 -0
  43. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js +9 -0
  44. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js.map +1 -0
  45. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js +11 -0
  46. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js.map +1 -0
  47. package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js +17 -9
  48. package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js.map +1 -1
  49. package/dist/src/blocks/ImageBlockContent/{imageBlockHelpers.js → parseImageElement.js} +1 -1
  50. package/dist/src/blocks/ImageBlockContent/parseImageElement.js.map +1 -0
  51. package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js +18 -7
  52. package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js.map +1 -1
  53. package/dist/src/blocks/VideoBlockContent/{videoBlockHelpers.js → parseVideoElement.js} +1 -1
  54. package/dist/src/blocks/VideoBlockContent/parseVideoElement.js.map +1 -0
  55. package/dist/src/editor/BlockNoteEditor.js +8 -5
  56. package/dist/src/editor/BlockNoteEditor.js.map +1 -1
  57. package/dist/src/editor/BlockNoteExtensions.js +4 -8
  58. package/dist/src/editor/BlockNoteExtensions.js.map +1 -1
  59. package/dist/src/extensions/LinkToolbar/protocols.js +14 -0
  60. package/dist/src/extensions/LinkToolbar/protocols.js.map +1 -0
  61. package/dist/src/extensions/Placeholder/PlaceholderPlugin.js +6 -6
  62. package/dist/src/extensions/Placeholder/PlaceholderPlugin.js.map +1 -1
  63. package/dist/src/extensions/SideMenu/SideMenuPlugin.js +5 -1
  64. package/dist/src/extensions/SideMenu/SideMenuPlugin.js.map +1 -1
  65. package/dist/src/extensions/SideMenu/dragging.js +3 -0
  66. package/dist/src/extensions/SideMenu/dragging.js.map +1 -1
  67. package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js +3 -3
  68. package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js.map +1 -1
  69. package/dist/src/extensions/TableHandles/TableHandlesPlugin.js +12 -3
  70. package/dist/src/extensions/TableHandles/TableHandlesPlugin.js.map +1 -1
  71. package/dist/src/index.js +9 -2
  72. package/dist/src/index.js.map +1 -1
  73. package/dist/src/schema/inlineContent/createSpec.js +1 -1
  74. package/dist/src/schema/inlineContent/createSpec.js.map +1 -1
  75. package/dist/style.css +1 -1
  76. package/dist/tsconfig.tsbuildinfo +1 -1
  77. package/dist/webpack-stats.json +1 -1
  78. package/package.json +2 -2
  79. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +3 -3
  80. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +1 -3
  81. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +1 -1
  82. package/src/api/blockManipulation/selections/selection.ts +5 -5
  83. package/src/api/clipboard/__snapshots__/tableAllCells.html +1 -1
  84. package/src/api/clipboard/__snapshots__/tableCell.html +1 -1
  85. package/src/api/clipboard/__snapshots__/tableRow.html +1 -1
  86. package/src/api/clipboard/clipboard.test.ts +7 -3
  87. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +1 -1
  88. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +7 -14
  89. package/src/api/clipboard/fromClipboard/pasteExtension.ts +6 -6
  90. package/src/api/clipboard/toClipboard/copyExtension.ts +7 -2
  91. package/src/api/exporters/html/__snapshots__/file/basic/internal.html +1 -1
  92. package/src/api/exporters/html/__snapshots__/file/nested/internal.html +1 -1
  93. package/src/api/exporters/html/__snapshots__/file/noCaption/internal.html +1 -1
  94. package/src/api/exporters/html/__snapshots__/file/noName/internal.html +1 -1
  95. package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -1
  96. package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -1
  97. package/src/api/exporters/html/__snapshots__/image/noCaption/internal.html +1 -1
  98. package/src/api/exporters/html/__snapshots__/image/noName/internal.html +1 -1
  99. package/src/api/exporters/html/__snapshots__/image/noPreview/internal.html +1 -1
  100. package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -1
  101. package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -1
  102. package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -1
  103. package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -1
  104. package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +1 -1
  105. package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/internal.html +1 -1
  106. package/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +1 -1
  107. package/src/api/exporters/html/__snapshots__/simpleImage/noName/internal.html +1 -1
  108. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +1 -1
  109. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/internal.html +1 -1
  110. package/src/api/exporters/markdown/__snapshots__/simpleImage/basic/markdown.md +1 -1
  111. package/src/api/exporters/markdown/__snapshots__/simpleImage/nested/markdown.md +2 -2
  112. package/src/api/exporters/markdown/__snapshots__/simpleImage/noCaption/markdown.md +1 -1
  113. package/src/api/exporters/markdown/__snapshots__/simpleImage/noName/markdown.md +1 -1
  114. package/src/api/parsers/markdown/parseMarkdown.test.ts +5 -7
  115. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +13 -14
  116. package/src/blocks/FileBlockContent/FileBlockContent.ts +5 -12
  117. package/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.ts +5 -0
  118. package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +16 -0
  119. package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +63 -0
  120. package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +80 -0
  121. package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +24 -0
  122. package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +204 -0
  123. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +13 -0
  124. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +15 -0
  125. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +20 -28
  126. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +20 -27
  127. package/src/editor/Block.css +35 -51
  128. package/src/editor/BlockNoteEditor.ts +14 -7
  129. package/src/editor/BlockNoteExtensions.ts +7 -8
  130. package/src/editor/editor.css +1 -0
  131. package/src/extensions/LinkToolbar/protocols.ts +13 -0
  132. package/src/extensions/Placeholder/PlaceholderPlugin.ts +6 -6
  133. package/src/extensions/SideMenu/SideMenuPlugin.ts +5 -1
  134. package/src/extensions/SideMenu/dragging.ts +3 -0
  135. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +3 -6
  136. package/src/extensions/TableHandles/TableHandlesPlugin.ts +15 -3
  137. package/src/index.ts +9 -2
  138. package/src/schema/inlineContent/createSpec.ts +2 -2
  139. package/types/src/api/clipboard/fromClipboard/handleVSCodePaste.d.ts +2 -3
  140. package/types/src/api/clipboard/fromClipboard/pasteExtension.d.ts +1 -3
  141. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +2 -5
  142. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +2 -5
  143. package/types/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.d.ts +3 -0
  144. package/types/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.d.ts +4 -0
  145. package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +6 -0
  146. package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +9 -0
  147. package/types/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.d.ts +6 -0
  148. package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +9 -0
  149. package/types/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.d.ts +3 -0
  150. package/types/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.d.ts +3 -0
  151. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +2 -5
  152. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +2 -5
  153. package/types/src/editor/BlockNoteEditor.d.ts +6 -4
  154. package/types/src/extensions/LinkToolbar/protocols.d.ts +2 -0
  155. package/types/src/index.d.ts +9 -2
  156. package/dist/src/blocks/AudioBlockContent/audioBlockHelpers.js.map +0 -1
  157. package/dist/src/blocks/FileBlockContent/fileBlockHelpers.js +0 -317
  158. package/dist/src/blocks/FileBlockContent/fileBlockHelpers.js.map +0 -1
  159. package/dist/src/blocks/ImageBlockContent/imageBlockHelpers.js.map +0 -1
  160. package/dist/src/blocks/VideoBlockContent/videoBlockHelpers.js.map +0 -1
  161. package/src/blocks/FileBlockContent/fileBlockHelpers.ts +0 -456
  162. package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +0 -41
  163. /package/src/blocks/AudioBlockContent/{audioBlockHelpers.ts → parseAudioElement.ts} +0 -0
  164. /package/src/blocks/ImageBlockContent/{imageBlockHelpers.ts → parseImageElement.ts} +0 -0
  165. /package/src/blocks/VideoBlockContent/{videoBlockHelpers.ts → parseVideoElement.ts} +0 -0
  166. /package/types/src/blocks/AudioBlockContent/{audioBlockHelpers.d.ts → parseAudioElement.d.ts} +0 -0
  167. /package/types/src/blocks/ImageBlockContent/{imageBlockHelpers.d.ts → parseImageElement.d.ts} +0 -0
  168. /package/types/src/blocks/VideoBlockContent/{videoBlockHelpers.d.ts → parseVideoElement.d.ts} +0 -0
@@ -310,85 +310,66 @@ NESTED BLOCKS
310
310
 
311
311
  /* FILES */
312
312
 
313
- /* Add block button & default preview */
314
- [data-file-block] .bn-file-block-content-wrapper:has(.bn-add-file-button),
315
- [data-file-block] .bn-file-block-content-wrapper:has(.bn-file-default-preview) {
316
- width: 100%;
317
- }
318
-
313
+ /* Element that wraps content for all file blocks */
319
314
  [data-file-block] .bn-file-block-content-wrapper {
320
315
  cursor: pointer;
321
316
  display: flex;
322
317
  flex-direction: column;
323
- justify-content: stretch;
324
318
  user-select: none;
325
319
  }
326
320
 
321
+ /* Add block button & default element (name with icon) */
322
+ [data-file-block] .bn-file-block-content-wrapper:has(.bn-add-file-button),
323
+ [data-file-block] .bn-file-block-content-wrapper:has(.bn-file-name-with-icon) {
324
+ width: 100%;
325
+ }
326
+
327
327
  [data-file-block] .bn-add-file-button {
328
328
  align-items: center;
329
329
  background-color: rgb(242, 241, 238);
330
330
  border-radius: 4px;
331
331
  color: rgb(125, 121, 122);
332
332
  display: flex;
333
- flex-direction: row;
334
333
  gap: 10px;
335
334
  padding: 12px;
336
- width: 100%;
337
335
  }
338
336
 
339
- .bn-editor[contenteditable="true"] [data-file-block] .bn-add-file-button:hover {
337
+ .bn-editor[contenteditable="true"] [data-file-block] .bn-add-file-button:hover,
338
+ [data-file-block] .bn-file-name-with-icon:hover,
339
+ .ProseMirror-selectednode .bn-file-name-with-icon{
340
340
  background-color: rgb(225, 225, 225);
341
341
  }
342
342
 
343
- [data-file-block] .bn-add-file-button-icon {
343
+ [data-file-block] .bn-add-file-button-icon,
344
+ [data-file-block] .bn-file-icon {
344
345
  width: 24px;
345
346
  height: 24px;
346
347
  }
347
348
 
348
- [data-file-block] .bn-add-file-button .bn-add-file-button-text {
349
+ [data-file-block] .bn-add-file-button-text {
349
350
  font-size: 0.9rem;
350
351
  }
351
352
 
352
- [data-file-block] .bn-file-and-caption-wrapper {
353
- display: flex;
354
- flex-direction: column;
355
- border-radius: 4px;
356
- }
357
-
358
- [data-file-block] .bn-file-default-preview {
359
- align-items: center;
353
+ [data-file-block] .bn-file-name-with-icon {
360
354
  border-radius: 4px;
361
355
  display: flex;
362
- flex-direction: row;
363
356
  gap: 4px;
364
357
  padding: 4px;
365
- width: 100%;
366
- }
367
-
368
- [data-file-block] .bn-file-default-preview:hover,
369
- .ProseMirror-selectednode .bn-file-default-preview {
370
- background-color: rgb(225, 225, 225);
371
- }
372
-
373
- [data-file-block] .bn-file-default-preview-icon {
374
- width: 24px;
375
- height: 24px;
376
358
  }
377
359
 
378
- [data-file-block] .bn-visual-media-wrapper {
379
- display: flex;
380
- flex-direction: row;
381
- align-items: center;
382
- position: relative;
383
- width: fit-content;
360
+ /* File captions */
361
+ [data-file-block] .bn-file-caption {
362
+ font-size: 0.8em;
363
+ padding-block: 4px;
364
+ word-break: break-word;
384
365
  }
385
366
 
386
- [data-file-block] .bn-visual-media {
387
- border-radius: 4px;
388
- max-width: 100%;
367
+ [data-file-block] .bn-file-caption:empty {
368
+ padding-block: 0;
389
369
  }
390
370
 
391
- [data-file-block] .bn-visual-media-resize-handle {
371
+ /* Resize handles */
372
+ [data-file-block] .bn-resize-handle {
392
373
  position: absolute;
393
374
  width: 8px;
394
375
  height: 30px;
@@ -398,19 +379,22 @@ NESTED BLOCKS
398
379
  cursor: ew-resize;
399
380
  }
400
381
 
401
- [data-content-type="audio"] > .bn-file-block-content-wrapper,
402
- .bn-audio {
403
- width: 100%;
382
+ /* Visual media file blocks, e.g. images & videos */
383
+ [data-file-block] .bn-visual-media-wrapper {
384
+ display: flex;
385
+ align-items: center;
386
+ position: relative;
404
387
  }
405
388
 
406
- [data-file-block] .bn-file-caption {
407
- font-size: 0.8em;
408
- padding-block: 4px;
409
- word-break: break-word;
389
+ [data-file-block] .bn-visual-media {
390
+ border-radius: 4px;
391
+ width: 100%;
410
392
  }
411
393
 
412
- [data-file-block] .bn-file-caption:empty {
413
- padding-block: 0;
394
+ /* Block-specific styles */
395
+ [data-content-type="audio"] > .bn-file-block-content-wrapper,
396
+ .bn-audio {
397
+ width: 100%;
414
398
  }
415
399
 
416
400
  /* PLACEHOLDERS*/
@@ -93,6 +93,7 @@ import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTML
93
93
  import { inlineContentToNodes } from "../api/nodeConversions/blockToNode.js";
94
94
  import { nodeToBlock } from "../api/nodeConversions/nodeToBlock.js";
95
95
  import "../style.css";
96
+ import { EditorView } from "prosemirror-view";
96
97
 
97
98
  export type BlockNoteExtension =
98
99
  | AnyExtension
@@ -274,7 +275,8 @@ export class BlockNoteEditor<
274
275
  public readonly headless: boolean = false;
275
276
 
276
277
  public readonly _tiptapEditor:
277
- | BlockNoteTipTapEditor & {
278
+ | Omit<BlockNoteTipTapEditor, "view"> & {
279
+ view: EditorView | undefined;
278
280
  contentComponent: any;
279
281
  } = undefined as any; // TODO: Type should actually reflect that it can be `undefined` in headless mode
280
282
 
@@ -344,7 +346,7 @@ export class BlockNoteEditor<
344
346
  private onUploadStartCallbacks: ((blockId?: string) => void)[] = [];
345
347
  private onUploadEndCallbacks: ((blockId?: string) => void)[] = [];
346
348
 
347
- public readonly resolveFileUrl: (url: string) => Promise<string>;
349
+ public readonly resolveFileUrl?: (url: string) => Promise<string>;
348
350
 
349
351
  public get pmSchema() {
350
352
  return this._pmSchema;
@@ -456,7 +458,7 @@ export class BlockNoteEditor<
456
458
  };
457
459
  }
458
460
 
459
- this.resolveFileUrl = newOptions.resolveFileUrl || (async (url) => url);
461
+ this.resolveFileUrl = newOptions.resolveFileUrl;
460
462
  this.headless = newOptions._headless;
461
463
 
462
464
  if (newOptions.collaboration && newOptions.initialContent) {
@@ -542,6 +544,7 @@ export class BlockNoteEditor<
542
544
  tiptapOptions,
543
545
  this.schema.styleSchema
544
546
  ) as BlockNoteTipTapEditor & {
547
+ view: any;
545
548
  contentComponent: any;
546
549
  };
547
550
  this._pmSchema = this._tiptapEditor.schema;
@@ -570,15 +573,15 @@ export class BlockNoteEditor<
570
573
  }
571
574
 
572
575
  public get domElement() {
573
- return this._tiptapEditor.view.dom as HTMLDivElement;
576
+ return this.prosemirrorView?.dom as HTMLDivElement | undefined;
574
577
  }
575
578
 
576
579
  public isFocused() {
577
- return this._tiptapEditor.view.hasFocus();
580
+ return this.prosemirrorView?.hasFocus() || false;
578
581
  }
579
582
 
580
583
  public focus() {
581
- this._tiptapEditor.view.focus();
584
+ this.prosemirrorView?.focus();
582
585
  }
583
586
 
584
587
  public onUploadStart(callback: (blockId?: string) => void) {
@@ -1198,7 +1201,11 @@ export class BlockNoteEditor<
1198
1201
  ignoreQueryLength?: boolean;
1199
1202
  }
1200
1203
  ) {
1201
- const tr = this.prosemirrorView.state.tr;
1204
+ const tr = this.prosemirrorView?.state.tr;
1205
+ if (!tr) {
1206
+ return;
1207
+ }
1208
+
1202
1209
  const transaction =
1203
1210
  pluginState && pluginState.deleteTriggerCharacter
1204
1211
  ? tr.insertText(triggerCharacter)
@@ -19,6 +19,10 @@ import { FilePanelProsemirrorPlugin } from "../extensions/FilePanel/FilePanelPlu
19
19
  import { FormattingToolbarProsemirrorPlugin } from "../extensions/FormattingToolbar/FormattingToolbarPlugin.js";
20
20
  import { KeyboardShortcutsExtension } from "../extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js";
21
21
  import { LinkToolbarProsemirrorPlugin } from "../extensions/LinkToolbar/LinkToolbarPlugin.js";
22
+ import {
23
+ DEFAULT_LINK_PROTOCOL,
24
+ VALID_LINK_PROTOCOLS,
25
+ } from "../extensions/LinkToolbar/protocols.js";
22
26
  import { NodeSelectionKeyboardPlugin } from "../extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js";
23
27
  import { PlaceholderPlugin } from "../extensions/Placeholder/PlaceholderPlugin.js";
24
28
  import { PreviousBlockTypePlugin } from "../extensions/PreviousBlockType/PreviousBlockTypePlugin.js";
@@ -159,14 +163,9 @@ const getTipTapExtensions = <
159
163
  // marks:
160
164
  Link.extend({
161
165
  inclusive: false,
162
- addKeyboardShortcuts() {
163
- return {
164
- "Mod-k": () => {
165
- this.editor.commands.toggleLink({ href: "" });
166
- return true;
167
- },
168
- };
169
- },
166
+ }).configure({
167
+ defaultProtocol: DEFAULT_LINK_PROTOCOL,
168
+ protocols: VALID_LINK_PROTOCOLS,
170
169
  }),
171
170
  ...Object.values(opts.styleSpecs).map((styleSpec) => {
172
171
  return styleSpec.implementation.mark;
@@ -86,6 +86,7 @@ Tippy popups that are appended to document.body directly
86
86
  pointer-events: none;
87
87
  position: relative;
88
88
  word-break: normal;
89
+ white-space: nowrap !important;
89
90
  }
90
91
 
91
92
  /* Render the username above the caret */
@@ -0,0 +1,13 @@
1
+ export const VALID_LINK_PROTOCOLS = [
2
+ "http",
3
+ "https",
4
+ "ftp",
5
+ "ftps",
6
+ "mailto",
7
+ "tel",
8
+ "callto",
9
+ "sms",
10
+ "cid",
11
+ "xmpp",
12
+ ];
13
+ export const DEFAULT_LINK_PROTOCOL = "https";
@@ -18,10 +18,10 @@ export class PlaceholderPlugin {
18
18
  if (nonce) {
19
19
  styleEl.setAttribute("nonce", nonce);
20
20
  }
21
- if (editor._tiptapEditor.view.root instanceof ShadowRoot) {
22
- editor._tiptapEditor.view.root.append(styleEl);
21
+ if (editor.prosemirrorView?.root instanceof ShadowRoot) {
22
+ editor.prosemirrorView.root.append(styleEl);
23
23
  } else {
24
- editor._tiptapEditor.view.root.head.appendChild(styleEl);
24
+ editor.prosemirrorView?.root.head.appendChild(styleEl);
25
25
  }
26
26
 
27
27
  const styleSheet = styleEl.sheet!;
@@ -78,10 +78,10 @@ export class PlaceholderPlugin {
78
78
 
79
79
  return {
80
80
  destroy: () => {
81
- if (editor._tiptapEditor.view.root instanceof ShadowRoot) {
82
- editor._tiptapEditor.view.root.removeChild(styleEl);
81
+ if (editor.prosemirrorView?.root instanceof ShadowRoot) {
82
+ editor.prosemirrorView.root.removeChild(styleEl);
83
83
  } else {
84
- editor._tiptapEditor.view.root.head.removeChild(styleEl);
84
+ editor.prosemirrorView?.root.head.removeChild(styleEl);
85
85
  }
86
86
  },
87
87
  };
@@ -485,7 +485,11 @@ export class SideMenuProsemirrorPlugin<
485
485
  /**
486
486
  * Handles drag & drop events for blocks.
487
487
  */
488
- blockDragEnd = () => unsetDragImage(this.editor.prosemirrorView.root);
488
+ blockDragEnd = () => {
489
+ if (this.editor.prosemirrorView) {
490
+ unsetDragImage(this.editor.prosemirrorView.root);
491
+ }
492
+ };
489
493
  /**
490
494
  * Freezes the side menu. When frozen, the side menu will stay
491
495
  * attached to the same block regardless of which block is hovered by the
@@ -148,6 +148,9 @@ export function dragStart<
148
148
  }
149
149
 
150
150
  const view = editor.prosemirrorView;
151
+ if (!view) {
152
+ return;
153
+ }
151
154
 
152
155
  const posInfo = getNodeById(block.id, view.state.doc);
153
156
  if (!posInfo) {
@@ -45,12 +45,12 @@ class SuggestionMenuView<
45
45
  });
46
46
  };
47
47
 
48
- this.rootEl = this.editor._tiptapEditor.view.root;
48
+ this.rootEl = this.editor.prosemirrorView?.root;
49
49
 
50
50
  // Setting capture=true ensures that any parent container of the editor that
51
51
  // gets scrolled will trigger the scroll event. Scroll events do not bubble
52
52
  // and so won't propagate to the document by default.
53
- this.rootEl.addEventListener("scroll", this.handleScroll, true);
53
+ this.rootEl?.addEventListener("scroll", this.handleScroll, true);
54
54
  }
55
55
 
56
56
  handleScroll = () => {
@@ -113,10 +113,7 @@ class SuggestionMenuView<
113
113
 
114
114
  closeMenu = () => {
115
115
  this.editor.dispatch(
116
- this.editor._tiptapEditor.view.state.tr.setMeta(
117
- suggestionMenuPluginKey,
118
- null
119
- )
116
+ this.editor._tiptapEditor.state.tr.setMeta(suggestionMenuPluginKey, null)
120
117
  );
121
118
  };
122
119
 
@@ -742,7 +742,11 @@ export class TableHandlesProsemirrorPlugin<
742
742
  })
743
743
  );
744
744
 
745
- setHiddenDragImage(this.editor._tiptapEditor.view.root);
745
+ if (!this.editor.prosemirrorView) {
746
+ throw new Error("Editor view not initialized.");
747
+ }
748
+
749
+ setHiddenDragImage(this.editor.prosemirrorView.root);
746
750
  event.dataTransfer!.setDragImage(dragImageElement!, 0, 0);
747
751
  event.dataTransfer!.effectAllowed = "move";
748
752
  };
@@ -781,7 +785,11 @@ export class TableHandlesProsemirrorPlugin<
781
785
  })
782
786
  );
783
787
 
784
- setHiddenDragImage(this.editor._tiptapEditor.view.root);
788
+ if (!this.editor.prosemirrorView) {
789
+ throw new Error("Editor view not initialized.");
790
+ }
791
+
792
+ setHiddenDragImage(this.editor.prosemirrorView.root);
785
793
  event.dataTransfer!.setDragImage(dragImageElement!, 0, 0);
786
794
  event.dataTransfer!.effectAllowed = "copyMove";
787
795
  };
@@ -804,7 +812,11 @@ export class TableHandlesProsemirrorPlugin<
804
812
  this.editor._tiptapEditor.state.tr.setMeta(tableHandlesPluginKey, null)
805
813
  );
806
814
 
807
- unsetHiddenDragImage(this.editor._tiptapEditor.view.root);
815
+ if (!this.editor.prosemirrorView) {
816
+ throw new Error("Editor view not initialized.");
817
+ }
818
+
819
+ unsetHiddenDragImage(this.editor.prosemirrorView.root);
808
820
  };
809
821
 
810
822
  /**
package/src/index.ts CHANGED
@@ -7,10 +7,16 @@ export * from "./api/testUtil/index.js";
7
7
  export * from "./blocks/AudioBlockContent/AudioBlockContent.js";
8
8
  export * from "./blocks/CodeBlockContent/CodeBlockContent.js";
9
9
  export * from "./blocks/FileBlockContent/FileBlockContent.js";
10
- export * from "./blocks/FileBlockContent/fileBlockHelpers.js";
10
+ export * from "./blocks/FileBlockContent/helpers/parse/parseEmbedElement.js";
11
+ export * from "./blocks/FileBlockContent/helpers/parse/parseFigureElement.js";
12
+ export * from "./blocks/FileBlockContent/helpers/render/createAddFileButton.js";
13
+ export * from "./blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js";
14
+ export * from "./blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js";
15
+ export * from "./blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js";
16
+ export * from "./blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js";
17
+ export * from "./blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js";
11
18
  export * from "./blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js";
12
19
  export * from "./blocks/ImageBlockContent/ImageBlockContent.js";
13
- export { parseImageElement } from "./blocks/ImageBlockContent/imageBlockHelpers.js";
14
20
  export {
15
21
  EMPTY_CELL_HEIGHT,
16
22
  EMPTY_CELL_WIDTH,
@@ -30,6 +36,7 @@ export * from "./extensions-shared/UiElementPosition.js";
30
36
  export * from "./extensions/FilePanel/FilePanelPlugin.js";
31
37
  export * from "./extensions/FormattingToolbar/FormattingToolbarPlugin.js";
32
38
  export * from "./extensions/LinkToolbar/LinkToolbarPlugin.js";
39
+ export * from "./extensions/LinkToolbar/protocols.js";
33
40
  export * from "./extensions/SideMenu/SideMenuPlugin.js";
34
41
  export * from "./extensions/SuggestionMenu/DefaultGridSuggestionItem.js";
35
42
  export * from "./extensions/SuggestionMenu/DefaultSuggestionItem.js";
@@ -142,8 +142,8 @@ export function createInlineContentSpec<
142
142
  editor.schema.styleSchema
143
143
  );
144
144
 
145
- editor._tiptapEditor.view.dispatch(
146
- editor._tiptapEditor.view.state.tr.replaceWith(
145
+ editor.dispatch(
146
+ editor.prosemirrorView.state.tr.replaceWith(
147
147
  getPos(),
148
148
  getPos() + node.nodeSize,
149
149
  content
@@ -1,3 +1,2 @@
1
- import { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
2
- import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema/index.js";
3
- export declare function handleVSCodePaste<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(event: ClipboardEvent, editor: BlockNoteEditor<BSchema, I, S>): Promise<boolean>;
1
+ import { EditorView } from "prosemirror-view";
2
+ export declare function handleVSCodePaste(event: ClipboardEvent, view: EditorView): Promise<boolean>;
@@ -1,6 +1,4 @@
1
1
  import { Extension } from "@tiptap/core";
2
2
  import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
3
3
  import { InlineContentSchema, StyleSchema } from "../../../schema/index.js";
4
- export declare const createPasteFromClipboardExtension: <BSchema extends Record<string, import("../../../schema/index.js").BlockConfig>, I extends InlineContentSchema, S extends StyleSchema>(editor: BlockNoteEditor<BSchema, I, S>) => Extension<{
5
- editor: BlockNoteEditor<BSchema, I, S>;
6
- }, undefined>;
4
+ export declare const createPasteFromClipboardExtension: <BSchema extends Record<string, import("../../../schema/index.js").BlockConfig>, I extends InlineContentSchema, S extends StyleSchema>(editor: BlockNoteEditor<BSchema, I, S>) => Extension<any, any>;
@@ -42,11 +42,8 @@ export declare const audioBlockConfig: {
42
42
  fileBlockAccept: string[];
43
43
  };
44
44
  export declare const audioRender: (block: BlockFromConfig<typeof audioBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>) => {
45
- dom: HTMLDivElement;
46
- destroy?: undefined;
47
- } | {
48
- dom: HTMLDivElement;
49
- destroy: (() => void) | undefined;
45
+ dom: HTMLElement;
46
+ destroy?: (() => void) | undefined;
50
47
  };
51
48
  export declare const audioParse: (element: HTMLElement) => Partial<Props<typeof audioBlockConfig.propSchema>> | undefined;
52
49
  export declare const audioToExternalHTML: (block: BlockFromConfig<typeof audioBlockConfig, any, any>) => {
@@ -34,11 +34,8 @@ export declare const fileBlockConfig: {
34
34
  isFileBlock: true;
35
35
  };
36
36
  export declare const fileRender: (block: BlockFromConfig<typeof fileBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>) => {
37
- dom: HTMLDivElement;
38
- destroy?: undefined;
39
- } | {
40
- dom: HTMLDivElement;
41
- destroy: (() => void) | undefined;
37
+ dom: HTMLElement;
38
+ destroy?: (() => void) | undefined;
42
39
  };
43
40
  export declare const fileParse: (element: HTMLElement) => {
44
41
  url: string | undefined;
@@ -0,0 +1,3 @@
1
+ export declare const parseEmbedElement: (embedElement: HTMLEmbedElement) => {
2
+ url: string | undefined;
3
+ };
@@ -0,0 +1,4 @@
1
+ export declare const parseFigureElement: (figureElement: HTMLElement, targetTag: string) => {
2
+ targetElement: HTMLElement;
3
+ caption: string | undefined;
4
+ } | undefined;
@@ -0,0 +1,6 @@
1
+ import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
2
+ import { BlockFromConfig, FileBlockConfig } from "../../../../schema/index.js";
3
+ export declare const createAddFileButton: (block: BlockFromConfig<FileBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>, buttonText?: string, buttonIcon?: HTMLElement) => {
4
+ dom: HTMLDivElement;
5
+ destroy: () => void;
6
+ };
@@ -0,0 +1,9 @@
1
+ import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
2
+ import { BlockFromConfig, BlockSchemaWithBlock, FileBlockConfig } from "../../../../schema/index.js";
3
+ export declare const createFileBlockWrapper: (block: BlockFromConfig<FileBlockConfig, any, any>, editor: BlockNoteEditor<BlockSchemaWithBlock<FileBlockConfig["type"], FileBlockConfig>, any, any>, element?: {
4
+ dom: HTMLElement;
5
+ destroy?: () => void;
6
+ }, buttonText?: string, buttonIcon?: HTMLElement) => {
7
+ dom: HTMLElement;
8
+ destroy?: (() => void) | undefined;
9
+ };
@@ -0,0 +1,6 @@
1
+ import { BlockFromConfig, FileBlockConfig } from "../../../../schema/index.js";
2
+ export declare const FILE_ICON_SVG = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z\"></path></svg>";
3
+ export declare const createFileNameWithIcon: (block: BlockFromConfig<FileBlockConfig, any, any>) => {
4
+ dom: HTMLElement;
5
+ destroy?: () => void;
6
+ };
@@ -0,0 +1,9 @@
1
+ import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
2
+ import { BlockFromConfig, FileBlockConfig } from "../../../../schema/index.js";
3
+ export declare const createResizableFileBlockWrapper: (block: BlockFromConfig<FileBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>, element: {
4
+ dom: HTMLElement;
5
+ destroy?: () => void;
6
+ }, resizeHandlesContainerElement: HTMLElement, buttonText: string, buttonIcon: HTMLElement) => {
7
+ dom: HTMLElement;
8
+ destroy: () => void;
9
+ };
@@ -0,0 +1,3 @@
1
+ export declare const createFigureWithCaption: (element: HTMLElement, caption: string) => {
2
+ dom: HTMLElement;
3
+ };
@@ -0,0 +1,3 @@
1
+ export declare const createLinkWithCaption: (element: HTMLElement, caption: string) => {
2
+ dom: HTMLDivElement;
3
+ };
@@ -56,11 +56,8 @@ export declare const imageBlockConfig: {
56
56
  fileBlockAccept: string[];
57
57
  };
58
58
  export declare const imageRender: (block: BlockFromConfig<typeof imageBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>) => {
59
- dom: HTMLDivElement;
60
- destroy?: undefined;
61
- } | {
62
- dom: HTMLDivElement;
63
- destroy: (() => void) | undefined;
59
+ dom: HTMLElement;
60
+ destroy: () => void;
64
61
  };
65
62
  export declare const imageParse: (element: HTMLElement) => Partial<Props<typeof imageBlockConfig.propSchema>> | undefined;
66
63
  export declare const imageToExternalHTML: (block: BlockFromConfig<typeof imageBlockConfig, any, any>) => {
@@ -56,11 +56,8 @@ export declare const videoBlockConfig: {
56
56
  fileBlockAccept: string[];
57
57
  };
58
58
  export declare const videoRender: (block: BlockFromConfig<typeof videoBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>) => {
59
- dom: HTMLDivElement;
60
- destroy?: undefined;
61
- } | {
62
- dom: HTMLDivElement;
63
- destroy: (() => void) | undefined;
59
+ dom: HTMLElement;
60
+ destroy: () => void;
64
61
  };
65
62
  export declare const videoParse: (element: HTMLElement) => Partial<Props<typeof videoBlockConfig.propSchema>> | undefined;
66
63
  export declare const videoToExternalHTML: (block: BlockFromConfig<typeof videoBlockConfig, any, any>) => {
@@ -17,6 +17,7 @@ import { BlockNoteTipTapEditor } from "./BlockNoteTipTapEditor.js";
17
17
  import { Dictionary } from "../i18n/dictionary.js";
18
18
  import { Plugin, Transaction } from "@tiptap/pm/state";
19
19
  import "../style.css";
20
+ import { EditorView } from "prosemirror-view";
20
21
  export type BlockNoteExtension = AnyExtension | {
21
22
  plugin: Plugin;
22
23
  };
@@ -153,7 +154,8 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
153
154
  * You probably don't need to set this manually, but use the `server-util` package instead that uses this option internally
154
155
  */
155
156
  readonly headless: boolean;
156
- readonly _tiptapEditor: BlockNoteTipTapEditor & {
157
+ readonly _tiptapEditor: Omit<BlockNoteTipTapEditor, "view"> & {
158
+ view: EditorView | undefined;
157
159
  contentComponent: any;
158
160
  };
159
161
  /**
@@ -196,7 +198,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
196
198
  readonly uploadFile: ((file: File, blockId?: string) => Promise<string | Record<string, any>>) | undefined;
197
199
  private onUploadStartCallbacks;
198
200
  private onUploadEndCallbacks;
199
- readonly resolveFileUrl: (url: string) => Promise<string>;
201
+ readonly resolveFileUrl?: (url: string) => Promise<string>;
200
202
  get pmSchema(): Schema<any, any>;
201
203
  static create<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema>(options?: Partial<BlockNoteEditorOptions<BSchema, ISchema, SSchema>>): BlockNoteEditor<BSchema, ISchema, SSchema>;
202
204
  protected constructor(options: Partial<BlockNoteEditorOptions<any, any, any>>);
@@ -207,8 +209,8 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
207
209
  * @warning Not needed to call manually when using React, use BlockNoteView to take care of mounting
208
210
  */
209
211
  mount: (parentElement?: HTMLElement | null) => void;
210
- get prosemirrorView(): import("prosemirror-view").EditorView;
211
- get domElement(): HTMLDivElement;
212
+ get prosemirrorView(): EditorView | undefined;
213
+ get domElement(): HTMLDivElement | undefined;
212
214
  isFocused(): boolean;
213
215
  focus(): void;
214
216
  onUploadStart(callback: (blockId?: string) => void): () => void;
@@ -0,0 +1,2 @@
1
+ export declare const VALID_LINK_PROTOCOLS: string[];
2
+ export declare const DEFAULT_LINK_PROTOCOL = "https";
@@ -7,10 +7,16 @@ export * from "./api/testUtil/index.js";
7
7
  export * from "./blocks/AudioBlockContent/AudioBlockContent.js";
8
8
  export * from "./blocks/CodeBlockContent/CodeBlockContent.js";
9
9
  export * from "./blocks/FileBlockContent/FileBlockContent.js";
10
- export * from "./blocks/FileBlockContent/fileBlockHelpers.js";
10
+ export * from "./blocks/FileBlockContent/helpers/parse/parseEmbedElement.js";
11
+ export * from "./blocks/FileBlockContent/helpers/parse/parseFigureElement.js";
12
+ export * from "./blocks/FileBlockContent/helpers/render/createAddFileButton.js";
13
+ export * from "./blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js";
14
+ export * from "./blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js";
15
+ export * from "./blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js";
16
+ export * from "./blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js";
17
+ export * from "./blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js";
11
18
  export * from "./blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js";
12
19
  export * from "./blocks/ImageBlockContent/ImageBlockContent.js";
13
- export { parseImageElement } from "./blocks/ImageBlockContent/imageBlockHelpers.js";
14
20
  export { EMPTY_CELL_HEIGHT, EMPTY_CELL_WIDTH, } from "./blocks/TableBlockContent/TableExtension.js";
15
21
  export * from "./blocks/VideoBlockContent/VideoBlockContent.js";
16
22
  export * from "./blocks/defaultBlockHelpers.js";
@@ -27,6 +33,7 @@ export * from "./extensions-shared/UiElementPosition.js";
27
33
  export * from "./extensions/FilePanel/FilePanelPlugin.js";
28
34
  export * from "./extensions/FormattingToolbar/FormattingToolbarPlugin.js";
29
35
  export * from "./extensions/LinkToolbar/LinkToolbarPlugin.js";
36
+ export * from "./extensions/LinkToolbar/protocols.js";
30
37
  export * from "./extensions/SideMenu/SideMenuPlugin.js";
31
38
  export * from "./extensions/SuggestionMenu/DefaultGridSuggestionItem.js";
32
39
  export * from "./extensions/SuggestionMenu/DefaultSuggestionItem.js";
@@ -1 +0,0 @@
1
- {"version":3,"file":"audioBlockHelpers.js","sourceRoot":"","sources":["../../../../src/blocks/AudioBlockContent/audioBlockHelpers.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,YAA8B,EAAE,EAAE;IAClE,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,IAAI,SAAS,CAAC;IAE1C,OAAO,EAAE,GAAG,EAAE,CAAC;AACjB,CAAC,CAAC"}