@blocknote/core 0.48.1 → 0.50.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 (115) hide show
  1. package/dist/blocknote.cjs +1 -1
  2. package/dist/blocknote.js +3 -3
  3. package/dist/{blocks-BEvIOzln.cjs → blocks-BFnTypT-.cjs} +3 -3
  4. package/dist/blocks-BFnTypT-.cjs.map +1 -0
  5. package/dist/{blocks-DYl7UTS4.js → blocks-UU7EM-QM.js} +601 -570
  6. package/dist/blocks-UU7EM-QM.js.map +1 -0
  7. package/dist/blocks.cjs +1 -1
  8. package/dist/blocks.js +1 -1
  9. package/dist/comments.cjs +1 -1
  10. package/dist/comments.cjs.map +1 -1
  11. package/dist/comments.js +19 -16
  12. package/dist/comments.js.map +1 -1
  13. package/dist/{en-QsSI16s5.js → en-B9hMApn4.js} +4 -2
  14. package/dist/en-B9hMApn4.js.map +1 -0
  15. package/dist/{en-C4ykW581.cjs → en-Cj5r8sW_.cjs} +2 -2
  16. package/dist/en-Cj5r8sW_.cjs.map +1 -0
  17. package/dist/extensions-CYsFi5Is.cjs +2 -0
  18. package/dist/extensions-CYsFi5Is.cjs.map +1 -0
  19. package/dist/{extensions-3nf9PPhA.js → extensions-CkLT--Nc.js} +244 -250
  20. package/dist/extensions-CkLT--Nc.js.map +1 -0
  21. package/dist/extensions.cjs +1 -1
  22. package/dist/extensions.js +2 -2
  23. package/dist/locales.cjs +1 -1
  24. package/dist/locales.cjs.map +1 -1
  25. package/dist/locales.js +67 -23
  26. package/dist/locales.js.map +1 -1
  27. package/dist/src-DsJ6yzs9.cjs +5 -0
  28. package/dist/src-DsJ6yzs9.cjs.map +1 -0
  29. package/dist/{src-Hjv1f5lc.js → src-SVFpMAWE.js} +754 -366
  30. package/dist/src-SVFpMAWE.js.map +1 -0
  31. package/dist/style.css +1 -1
  32. package/dist/webpack-stats.json +1 -1
  33. package/dist/yjs.cjs +1 -1
  34. package/dist/yjs.js +1 -1
  35. package/package.json +6 -8
  36. package/src/api/clipboard/toClipboard/copyExtension.ts +21 -16
  37. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +14 -1
  38. package/src/blocks/Quote/block.ts +9 -0
  39. package/src/blocks/Table/TableExtension.ts +38 -9
  40. package/src/blocks/Table/block.ts +26 -0
  41. package/src/blocks/defaultBlocks.ts +34 -1
  42. package/src/comments/extension.ts +35 -11
  43. package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +3 -2
  44. package/src/comments/threadstore/yjs/YjsThreadStore.ts +4 -4
  45. package/src/editor/Block.css +14 -18
  46. package/src/editor/BlockNoteEditor.ts +84 -5
  47. package/src/editor/editor.css +5 -0
  48. package/src/editor/managers/ExtensionManager/extensions.ts +8 -27
  49. package/src/editor/managers/StyleManager.ts +90 -10
  50. package/src/extensions/FormattingToolbar/FormattingToolbar.ts +23 -16
  51. package/src/extensions/LinkToolbar/LinkToolbar.ts +30 -75
  52. package/src/extensions/Placeholder/Placeholder.ts +2 -2
  53. package/src/extensions/SideMenu/SideMenu.ts +2 -2
  54. package/src/extensions/TableHandles/TableHandles.ts +2 -0
  55. package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +179 -0
  56. package/src/extensions/tiptap-extensions/Link/helpers/clickHandler.ts +82 -0
  57. package/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts +414 -0
  58. package/src/extensions/tiptap-extensions/Link/helpers/pasteHandler.ts +53 -0
  59. package/src/extensions/tiptap-extensions/Link/helpers/tlds.ts +7 -0
  60. package/src/extensions/tiptap-extensions/Link/helpers/whitespace.ts +13 -0
  61. package/src/extensions/tiptap-extensions/Link/index.ts +2 -0
  62. package/src/extensions/tiptap-extensions/Link/link.test.ts +941 -0
  63. package/src/extensions/tiptap-extensions/Link/link.ts +238 -0
  64. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +3 -5
  65. package/src/i18n/locales/ar.ts +3 -1
  66. package/src/i18n/locales/de.ts +3 -1
  67. package/src/i18n/locales/en.ts +3 -1
  68. package/src/i18n/locales/es.ts +3 -1
  69. package/src/i18n/locales/fa.ts +3 -1
  70. package/src/i18n/locales/fr.ts +3 -1
  71. package/src/i18n/locales/he.ts +3 -1
  72. package/src/i18n/locales/hr.ts +3 -1
  73. package/src/i18n/locales/is.ts +3 -1
  74. package/src/i18n/locales/it.ts +3 -1
  75. package/src/i18n/locales/ja.ts +3 -1
  76. package/src/i18n/locales/ko.ts +3 -1
  77. package/src/i18n/locales/nl.ts +3 -1
  78. package/src/i18n/locales/no.ts +3 -1
  79. package/src/i18n/locales/pl.ts +3 -1
  80. package/src/i18n/locales/pt.ts +3 -1
  81. package/src/i18n/locales/ru.ts +3 -1
  82. package/src/i18n/locales/sk.ts +3 -1
  83. package/src/i18n/locales/uk.ts +3 -1
  84. package/src/i18n/locales/uz.ts +3 -1
  85. package/src/i18n/locales/vi.ts +3 -1
  86. package/src/i18n/locales/zh-tw.ts +3 -1
  87. package/src/i18n/locales/zh.ts +3 -1
  88. package/src/schema/inlineContent/types.ts +1 -1
  89. package/types/src/comments/extension.d.ts +2 -1
  90. package/types/src/editor/BlockNoteEditor.d.ts +69 -3
  91. package/types/src/editor/managers/StyleManager.d.ts +22 -0
  92. package/types/src/extensions/LinkToolbar/LinkToolbar.d.ts +28 -7
  93. package/types/src/extensions/tiptap-extensions/Link/helpers/autolink.d.ts +13 -0
  94. package/types/src/extensions/tiptap-extensions/Link/helpers/clickHandler.d.ts +12 -0
  95. package/types/src/extensions/tiptap-extensions/Link/helpers/linkDetector.d.ts +32 -0
  96. package/types/src/extensions/tiptap-extensions/Link/helpers/pasteHandler.d.ts +12 -0
  97. package/types/src/extensions/tiptap-extensions/Link/helpers/tlds.d.ts +1 -0
  98. package/types/src/extensions/tiptap-extensions/Link/helpers/whitespace.d.ts +4 -0
  99. package/types/src/extensions/tiptap-extensions/Link/index.d.ts +2 -0
  100. package/types/src/extensions/tiptap-extensions/Link/link.d.ts +25 -0
  101. package/types/src/extensions/tiptap-extensions/Link/link.test.d.ts +1 -0
  102. package/types/src/i18n/locales/en.d.ts +2 -0
  103. package/types/src/i18n/locales/fa.d.ts +2 -0
  104. package/types/src/i18n/locales/sk.d.ts +2 -0
  105. package/types/src/schema/inlineContent/types.d.ts +1 -2
  106. package/dist/blocks-BEvIOzln.cjs.map +0 -1
  107. package/dist/blocks-DYl7UTS4.js.map +0 -1
  108. package/dist/en-C4ykW581.cjs.map +0 -1
  109. package/dist/en-QsSI16s5.js.map +0 -1
  110. package/dist/extensions-3nf9PPhA.js.map +0 -1
  111. package/dist/extensions-D9y6evn6.cjs +0 -2
  112. package/dist/extensions-D9y6evn6.cjs.map +0 -1
  113. package/dist/src-BKJH7Jla.cjs +0 -5
  114. package/dist/src-BKJH7Jla.cjs.map +0 -1
  115. package/dist/src-Hjv1f5lc.js.map +0 -1
@@ -158,6 +158,8 @@ export const CommentsExtension = createExtension(
158
158
  return {
159
159
  key: "comments",
160
160
  store,
161
+ runsBefore: ["link"],
162
+ tiptapExtensions: [CommentMark],
161
163
  prosemirrorPlugins: [
162
164
  new Plugin<CommentsPluginState>({
163
165
  key: PLUGIN_KEY,
@@ -224,7 +226,7 @@ export const CommentsExtension = createExtension(
224
226
  },
225
227
  handleClick: (view, pos, event) => {
226
228
  if (event.button !== 0) {
227
- return;
229
+ return false;
228
230
  }
229
231
 
230
232
  const node = view.state.doc.nodeAt(pos);
@@ -235,7 +237,7 @@ export const CommentsExtension = createExtension(
235
237
  ...prev,
236
238
  selectedThreadId: undefined,
237
239
  }));
238
- return;
240
+ return false;
239
241
  }
240
242
 
241
243
  const commentMark = node.marks.find(
@@ -243,15 +245,33 @@ export const CommentsExtension = createExtension(
243
245
  mark.type.name === markType && mark.attrs.orphan !== true,
244
246
  );
245
247
 
246
- const threadId = commentMark?.attrs.threadId as
247
- | string
248
- | undefined;
249
- if (threadId !== store.state.selectedThreadId) {
250
- store.setState((prev) => ({
251
- ...prev,
252
- selectedThreadId: threadId,
253
- }));
248
+ if (!commentMark) {
249
+ // Clicked outside any comment thread. Deselect if needed but
250
+ // don't consume the event so other handlers (e.g. link
251
+ // navigation) can process it.
252
+ if (store.state.selectedThreadId !== undefined) {
253
+ store.setState((prev) => ({
254
+ ...prev,
255
+ selectedThreadId: undefined,
256
+ }));
257
+ }
258
+ return false;
259
+ }
260
+
261
+ const threadId = commentMark.attrs.threadId as string;
262
+
263
+ // If the clicked thread is already selected, do nothing and let
264
+ // other handlers process the event (e.g. navigating a link).
265
+ if (threadId === store.state.selectedThreadId) {
266
+ return false;
254
267
  }
268
+
269
+ store.setState((prev) => ({
270
+ ...prev,
271
+ selectedThreadId: threadId,
272
+ }));
273
+
274
+ return true;
255
275
  },
256
276
  },
257
277
  }),
@@ -306,6 +326,11 @@ export const CommentsExtension = createExtension(
306
326
  selectedThreadId: undefined,
307
327
  pendingComment: true,
308
328
  }));
329
+ // Use `editor.domElement` as `editor.focus()` doesn't do anything if
330
+ // the editor is non-editable. Editor needs to be focused as
331
+ // `showSelection` will otherwise trigger a selection update which
332
+ // triggers `stopPendingComment`.
333
+ editor.domElement?.focus();
309
334
  editor
310
335
  .getExtension(ShowSelectionExtension)
311
336
  ?.showSelection(true, "comments");
@@ -351,7 +376,6 @@ export const CommentsExtension = createExtension(
351
376
  },
352
377
  userStore,
353
378
  commentEditorSchema,
354
- tiptapExtensions: [CommentMark],
355
379
  } as const;
356
380
  },
357
381
  );
@@ -6,8 +6,9 @@ import { YjsThreadStore } from "./YjsThreadStore.js";
6
6
 
7
7
  // Mock UUID to generate sequential IDs
8
8
  let mockUuidCounter = 0;
9
- vi.mock("uuid", () => ({
10
- v4: () => `mocked-uuid-${++mockUuidCounter}`,
9
+ vi.mock("lib0/random", async (importOriginal) => ({
10
+ ...(await importOriginal<typeof import("lib0/random")>()),
11
+ uuidv4: () => `mocked-uuid-${++mockUuidCounter}`,
11
12
  }));
12
13
 
13
14
  describe("YjsThreadStore", () => {
@@ -1,4 +1,4 @@
1
- import { v4 } from "uuid";
1
+ import { uuidv4 } from "lib0/random";
2
2
  import * as Y from "yjs";
3
3
  import { CommentBody, CommentData, ThreadData } from "../../types.js";
4
4
  import { ThreadStoreAuth } from "../ThreadStoreAuth.js";
@@ -57,7 +57,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
57
57
 
58
58
  const comment: CommentData = {
59
59
  type: "comment",
60
- id: v4(),
60
+ id: uuidv4(),
61
61
  userId: this.userId,
62
62
  createdAt: date,
63
63
  updatedAt: date,
@@ -68,7 +68,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
68
68
 
69
69
  const thread: ThreadData = {
70
70
  type: "thread",
71
- id: v4(),
71
+ id: uuidv4(),
72
72
  createdAt: date,
73
73
  updatedAt: date,
74
74
  comments: [comment],
@@ -105,7 +105,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
105
105
  const date = new Date();
106
106
  const comment: CommentData = {
107
107
  type: "comment",
108
- id: v4(),
108
+ id: uuidv4(),
109
109
  userId: this.userId,
110
110
  createdAt: date,
111
111
  updatedAt: date,
@@ -127,6 +127,7 @@ NESTED BLOCKS
127
127
 
128
128
  /* HEADINGS*/
129
129
  [data-content-type="heading"] {
130
+ padding-top: 18px;
130
131
  --level: 3em;
131
132
  }
132
133
  [data-content-type="heading"][data-level="2"] {
@@ -486,12 +487,25 @@ NESTED BLOCKS
486
487
  padding: 12px;
487
488
  }
488
489
 
490
+ [data-file-block] .bn-add-file-button:where(.dark, .dark *) {
491
+ background-color: rgb(70, 70, 70);
492
+ color: rgb(190, 190, 190);
493
+ }
494
+
489
495
  .bn-editor[contenteditable="true"] [data-file-block] .bn-add-file-button:hover,
490
496
  [data-file-block] .bn-file-name-with-icon:hover,
491
497
  .ProseMirror-selectednode .bn-file-name-with-icon {
492
498
  background-color: rgb(225, 225, 225);
493
499
  }
494
500
 
501
+ .bn-editor[contenteditable="true"]
502
+ [data-file-block]
503
+ .bn-add-file-button:hover:where(.dark, .dark *),
504
+ [data-file-block] .bn-file-name-with-icon:hover:where(.dark, .dark *),
505
+ .ProseMirror-selectednode .bn-file-name-with-icon:where(.dark, .dark *) {
506
+ background-color: rgb(90, 90, 90);
507
+ }
508
+
495
509
  [data-file-block] .bn-add-file-button-icon,
496
510
  [data-file-block] .bn-file-icon {
497
511
  width: 24px;
@@ -561,110 +575,92 @@ NESTED BLOCKS
561
575
 
562
576
  /* TEXT COLORS */
563
577
  [data-style-type="textColor"][data-value="gray"],
564
- [data-text-color="gray"],
565
578
  .bn-block:has(> .bn-block-content[data-text-color="gray"]) {
566
579
  color: #9b9a97;
567
580
  }
568
581
 
569
582
  [data-style-type="textColor"][data-value="brown"],
570
- [data-text-color="brown"],
571
583
  .bn-block:has(> .bn-block-content[data-text-color="brown"]) {
572
584
  color: #64473a;
573
585
  }
574
586
 
575
587
  [data-style-type="textColor"][data-value="red"],
576
- [data-text-color="red"],
577
588
  .bn-block:has(> .bn-block-content[data-text-color="red"]) {
578
589
  color: #e03e3e;
579
590
  }
580
591
 
581
592
  [data-style-type="textColor"][data-value="orange"],
582
- [data-text-color="orange"],
583
593
  .bn-block:has(> .bn-block-content[data-text-color="orange"]) {
584
594
  color: #d9730d;
585
595
  }
586
596
 
587
597
  [data-style-type="textColor"][data-value="yellow"],
588
- [data-text-color="yellow"],
589
598
  .bn-block:has(> .bn-block-content[data-text-color="yellow"]) {
590
599
  color: #dfab01;
591
600
  }
592
601
 
593
602
  [data-style-type="textColor"][data-value="green"],
594
- [data-text-color="green"],
595
603
  .bn-block:has(> .bn-block-content[data-text-color="green"]) {
596
604
  color: #4d6461;
597
605
  }
598
606
 
599
607
  [data-style-type="textColor"][data-value="blue"],
600
- [data-text-color="blue"],
601
608
  .bn-block:has(> .bn-block-content[data-text-color="blue"]) {
602
609
  color: #0b6e99;
603
610
  }
604
611
 
605
612
  [data-style-type="textColor"][data-value="purple"],
606
- [data-text-color="purple"],
607
613
  .bn-block:has(> .bn-block-content[data-text-color="purple"]) {
608
614
  color: #6940a5;
609
615
  }
610
616
 
611
617
  [data-style-type="textColor"][data-value="pink"],
612
- [data-text-color="pink"],
613
618
  .bn-block:has(> .bn-block-content[data-text-color="pink"]) {
614
619
  color: #ad1a72;
615
620
  }
616
621
 
617
622
  /* BACKGROUND COLORS */
618
623
  [data-style-type="backgroundColor"][data-value="gray"],
619
- [data-background-color="gray"],
620
624
  .bn-block:has(> .bn-block-content[data-background-color="gray"]) {
621
625
  background-color: #ebeced;
622
626
  }
623
627
 
624
628
  [data-style-type="backgroundColor"][data-value="brown"],
625
- [data-background-color="brown"],
626
629
  .bn-block:has(> .bn-block-content[data-background-color="brown"]) {
627
630
  background-color: #e9e5e3;
628
631
  }
629
632
 
630
633
  [data-style-type="backgroundColor"][data-value="red"],
631
- [data-background-color="red"],
632
634
  .bn-block:has(> .bn-block-content[data-background-color="red"]) {
633
635
  background-color: #fbe4e4;
634
636
  }
635
637
 
636
638
  [data-style-type="backgroundColor"][data-value="orange"],
637
- [data-background-color="orange"],
638
639
  .bn-block:has(> .bn-block-content[data-background-color="orange"]) {
639
640
  background-color: #f6e9d9;
640
641
  }
641
642
 
642
643
  [data-style-type="backgroundColor"][data-value="yellow"],
643
- [data-background-color="yellow"],
644
644
  .bn-block:has(> .bn-block-content[data-background-color="yellow"]) {
645
645
  background-color: #fbf3db;
646
646
  }
647
647
 
648
648
  [data-style-type="backgroundColor"][data-value="green"],
649
- [data-background-color="green"],
650
649
  .bn-block:has(> .bn-block-content[data-background-color="green"]) {
651
650
  background-color: #ddedea;
652
651
  }
653
652
 
654
653
  [data-style-type="backgroundColor"][data-value="blue"],
655
- [data-background-color="blue"],
656
654
  .bn-block:has(> .bn-block-content[data-background-color="blue"]) {
657
655
  background-color: #ddebf1;
658
656
  }
659
657
 
660
658
  [data-style-type="backgroundColor"][data-value="purple"],
661
- [data-background-color="purple"],
662
659
  .bn-block:has(> .bn-block-content[data-background-color="purple"]) {
663
660
  background-color: #eae4f2;
664
661
  }
665
662
 
666
663
  [data-style-type="backgroundColor"][data-value="pink"],
667
- [data-background-color="pink"],
668
664
  .bn-block:has(> .bn-block-content[data-background-color="pink"]) {
669
665
  background-color: #f4dfeb;
670
666
  }
@@ -140,6 +140,54 @@ export interface BlockNoteEditorOptions<
140
140
  NoInfer<SSchema>
141
141
  >[];
142
142
 
143
+ /**
144
+ * Options for configuring how links behave in the editor.
145
+ */
146
+ links?: {
147
+ /**
148
+ * HTML attributes to add to rendered link elements.
149
+ *
150
+ * @default {}
151
+ * @example { class: "my-link-class", target: "_blank" }
152
+ */
153
+ HTMLAttributes?: Record<string, any>;
154
+ /**
155
+ * Custom handler invoked when a link is clicked. If left `undefined`,
156
+ * links are opened in a new window on click. If provided, the default
157
+ * open-on-click behavior is disabled and this function is called instead.
158
+ *
159
+ * Return `false` to let ProseMirror continue handling the click event.
160
+ * Returning `true` or nothing (the default) marks the event as handled.
161
+ */
162
+ onClick?: (
163
+ event: MouseEvent,
164
+ editor: BlockNoteEditor<any, any, any>,
165
+ ) => boolean | void;
166
+ /**
167
+ * Callback that decides whether a given `href` is a valid link. Applied at
168
+ * every gate where a link enters the document: HTML import, HTML export,
169
+ * paste, and autolink. Useful for supporting additional URI schemes (e.g.
170
+ * `vscode:`, `myapp:`) or tightening the default allowlist.
171
+ *
172
+ * Defaults to `isAllowedUri`, which allows
173
+ * `http|https|ftp|ftps|mailto|tel|callto|sms|cid|xmpp`. Import
174
+ * `isAllowedUri` from `@blocknote/core` to layer on top of the default.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * import { isAllowedUri } from "@blocknote/core";
179
+ *
180
+ * BlockNoteEditor.create({
181
+ * links: {
182
+ * isValidLink: (href) =>
183
+ * isAllowedUri(href) || href.startsWith("myapp:"),
184
+ * },
185
+ * });
186
+ * ```
187
+ */
188
+ isValidLink?: (href: string) => boolean;
189
+ };
190
+
143
191
  /**
144
192
  * @deprecated, provide placeholders via dictionary instead
145
193
  * @internal
@@ -562,6 +610,13 @@ export class BlockNoteEditor<
562
610
  };
563
611
  this.pmSchema.cached.blockNoteEditor = this;
564
612
 
613
+ this._tiptapEditor.on("mount", () => {
614
+ this.headless = false;
615
+ });
616
+ this._tiptapEditor.on("unmount", () => {
617
+ this.headless = true;
618
+ });
619
+
565
620
  // Initialize managers
566
621
  this._blockManager = new BlockManager(this as any);
567
622
 
@@ -758,9 +813,7 @@ export class BlockNoteEditor<
758
813
  return this.prosemirrorView?.hasFocus() || false;
759
814
  }
760
815
 
761
- public get headless() {
762
- return !this._tiptapEditor.isInitialized;
763
- }
816
+ public headless = true;
764
817
 
765
818
  /**
766
819
  * Focus on the editor
@@ -1130,6 +1183,32 @@ export class BlockNoteEditor<
1130
1183
  this._styleManager.createLink(url, text);
1131
1184
  }
1132
1185
 
1186
+ /**
1187
+ * Find the link mark and its range at the given position.
1188
+ * Returns undefined if there is no link at that position.
1189
+ */
1190
+ public getLinkMarkAtPos(pos: number) {
1191
+ return this._styleManager.getLinkMarkAtPos(pos);
1192
+ }
1193
+
1194
+ /**
1195
+ * Updates the link at the given position with a new URL and text.
1196
+ * @param url The new link URL.
1197
+ * @param text The new text to display.
1198
+ * @param position The position inside the link to edit. Defaults to the current selection anchor.
1199
+ */
1200
+ public editLink(url: string, text: string, position?: number) {
1201
+ this._styleManager.editLink(url, text, position);
1202
+ }
1203
+
1204
+ /**
1205
+ * Removes the link at the given position, keeping the text.
1206
+ * @param position The position inside the link to remove. Defaults to the current selection anchor.
1207
+ */
1208
+ public deleteLink(position?: number) {
1209
+ this._styleManager.deleteLink(position);
1210
+ }
1211
+
1133
1212
  /**
1134
1213
  * Checks if the block containing the text cursor can be nested.
1135
1214
  */
@@ -1296,7 +1375,7 @@ export class BlockNoteEditor<
1296
1375
  editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
1297
1376
  }) => void,
1298
1377
  ) {
1299
- this._eventManager.onMount(callback);
1378
+ return this._eventManager.onMount(callback);
1300
1379
  }
1301
1380
 
1302
1381
  /**
@@ -1312,7 +1391,7 @@ export class BlockNoteEditor<
1312
1391
  editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
1313
1392
  }) => void,
1314
1393
  ) {
1315
- this._eventManager.onUnmount(callback);
1394
+ return this._eventManager.onUnmount(callback);
1316
1395
  }
1317
1396
 
1318
1397
  /**
@@ -80,6 +80,11 @@
80
80
  hidden. So setting it to an extremely low value instead makes the element
81
81
  functionally invisible while not affecting the drag preview itself. */
82
82
  opacity: 0.001;
83
+ /* The element is kept in the DOM after setDragImage captures its snapshot,
84
+ so it can overlap the editor and block drops in that area. Disabling
85
+ pointer-events lets drag/drop events pass through to the editor while
86
+ leaving the captured preview unaffected. */
87
+ pointer-events: none;
83
88
  }
84
89
 
85
90
  .bn-editor .bn-collaboration-cursor__base {
@@ -5,7 +5,7 @@ import {
5
5
  Extension as TiptapExtension,
6
6
  } from "@tiptap/core";
7
7
  import { Gapcursor } from "@tiptap/extensions/gap-cursor";
8
- import { Link } from "@tiptap/extension-link";
8
+ import { LinkExtension } from "../../../extensions/tiptap-extensions/Link/link.js";
9
9
  import { Text } from "@tiptap/extension-text";
10
10
  import { createDropFileExtension } from "../../../api/clipboard/fromClipboard/fileDropExtension.js";
11
11
  import { createPasteFromClipboardExtension } from "../../../api/clipboard/fromClipboard/pasteExtension.js";
@@ -26,10 +26,6 @@ import {
26
26
  TableHandlesExtension,
27
27
  TrailingNodeExtension,
28
28
  } from "../../../extensions/index.js";
29
- import {
30
- DEFAULT_LINK_PROTOCOL,
31
- VALID_LINK_PROTOCOLS,
32
- } from "../../../extensions/LinkToolbar/protocols.js";
33
29
  import {
34
30
  BackgroundColorExtension,
35
31
  HardBreak,
@@ -49,9 +45,6 @@ import {
49
45
  import { ExtensionFactoryInstance } from "../../BlockNoteExtension.js";
50
46
  import { CollaborationExtension } from "../../../extensions/Collaboration/Collaboration.js";
51
47
 
52
- // TODO remove linkify completely by vendoring the link extension & dropping linkifyjs as a dependency
53
- let LINKIFY_INITIALIZED = false;
54
-
55
48
  /**
56
49
  * Get all the Tiptap extensions BlockNote is configured with by default
57
50
  */
@@ -80,23 +73,6 @@ export function getDefaultTiptapExtensions(
80
73
  SuggestionAddMark,
81
74
  SuggestionDeleteMark,
82
75
  SuggestionModificationMark,
83
- Link.extend({
84
- inclusive: false,
85
- })
86
- .extend({
87
- // Remove the title attribute added in newer versions of @tiptap/extension-link
88
- // to avoid unnecessary null attributes in serialized output
89
- addAttributes() {
90
- const attrs = this.parent?.() || {};
91
- delete (attrs as Record<string, unknown>).title;
92
- return attrs;
93
- },
94
- })
95
- .configure({
96
- defaultProtocol: DEFAULT_LINK_PROTOCOL,
97
- // only call this once if we have multiple editors installed. Or fix https://github.com/ueberdosis/tiptap/issues/5450
98
- protocols: LINKIFY_INITIALIZED ? [] : VALID_LINK_PROTOCOLS,
99
- }),
100
76
  ...(Object.values(editor.schema.styleSpecs).map((styleSpec) => {
101
77
  return styleSpec.implementation.mark.configure({
102
78
  editor: editor,
@@ -173,8 +149,6 @@ export function getDefaultTiptapExtensions(
173
149
  createDropFileExtension(editor),
174
150
  ];
175
151
 
176
- LINKIFY_INITIALIZED = true;
177
-
178
152
  return tiptapExtensions;
179
153
  }
180
154
 
@@ -187,6 +161,13 @@ export function getDefaultExtensions(
187
161
  DropCursorExtension(options),
188
162
  FilePanelExtension(options),
189
163
  FormattingToolbarExtension(options),
164
+ LinkExtension({
165
+ HTMLAttributes: options.links?.HTMLAttributes ?? {},
166
+ onClick: options.links?.onClick,
167
+ ...(options.links?.isValidLink
168
+ ? { isValidLink: options.links.isValidLink }
169
+ : {}),
170
+ }),
190
171
  LinkToolbarExtension(options),
191
172
  NodeSelectionKeyboardExtension(),
192
173
  PlaceholderExtension(options),
@@ -1,3 +1,4 @@
1
+ import { getMarkRange } from "@tiptap/core";
1
2
  import { insertContentAt } from "../../api/blockManipulation/insertContentAt.js";
2
3
  import { inlineContentToNodes } from "../../api/nodeConversions/blockToNode.js";
3
4
  import {
@@ -12,7 +13,6 @@ import {
12
13
  DefaultInlineContentSchema,
13
14
  DefaultStyleSchema,
14
15
  } from "../../blocks/defaultBlocks.js";
15
- import { TextSelection } from "@tiptap/pm/state";
16
16
  import { UnreachableCaseError } from "../../util/typescript.js";
17
17
  import { BlockNoteEditor } from "../BlockNoteEditor.js";
18
18
 
@@ -146,13 +146,42 @@ export class StyleManager<
146
146
  });
147
147
  }
148
148
 
149
+ /**
150
+ * Find the link mark and its range at the given position.
151
+ * Returns undefined if there is no link at that position.
152
+ */
153
+ public getLinkMarkAtPos(pos: number) {
154
+ return this.editor.transact((tr) => {
155
+ const resolvedPos = tr.doc.resolve(pos);
156
+ const linkMark = resolvedPos
157
+ .marks()
158
+ .find((mark) => mark.type.name === "link");
159
+
160
+ if (!linkMark) {
161
+ return undefined;
162
+ }
163
+
164
+ const range = getMarkRange(resolvedPos, linkMark.type);
165
+ if (!range) {
166
+ return undefined;
167
+ }
168
+
169
+ return {
170
+ href: linkMark.attrs.href as string,
171
+ from: range.from,
172
+ to: range.to,
173
+ text: tr.doc.textBetween(range.from, range.to),
174
+ };
175
+ });
176
+ }
177
+
149
178
  /**
150
179
  * Gets the URL of the last link in the current selection, or `undefined` if there are no links in the selection.
151
180
  */
152
181
  public getSelectedLinkUrl() {
153
- return this.editor._tiptapEditor.getAttributes("link").href as
154
- | string
155
- | undefined;
182
+ return this.editor.transact((tr) => {
183
+ return this.getLinkMarkAtPos(tr.selection.from)?.href;
184
+ });
156
185
  }
157
186
 
158
187
  /**
@@ -164,19 +193,70 @@ export class StyleManager<
164
193
  if (url === "") {
165
194
  return;
166
195
  }
167
- const mark = this.editor.pmSchema.mark("link", { href: url });
196
+
168
197
  this.editor.transact((tr) => {
169
198
  const { from, to } = tr.selection;
199
+ const linkMark = this.editor.pmSchema.mark("link", { href: url });
170
200
 
171
201
  if (text) {
172
- tr.insertText(text, from, to).addMark(from, from + text.length, mark);
173
- } else {
174
- tr.setSelection(TextSelection.create(tr.doc, to)).addMark(
202
+ tr.insertText(text, from, to).addMark(
175
203
  from,
176
- to,
177
- mark,
204
+ from + text.length,
205
+ linkMark,
178
206
  );
207
+ } else {
208
+ tr.addMark(from, to, linkMark);
209
+ }
210
+ });
211
+ }
212
+
213
+ /**
214
+ * Updates the link at the given position with a new URL and text.
215
+ * @param url The new link URL.
216
+ * @param text The new text to display.
217
+ * @param position The position inside the link to edit. Defaults to the current selection anchor.
218
+ */
219
+ public editLink(
220
+ url: string,
221
+ text: string,
222
+ position = this.editor.transact((tr) => tr.selection.anchor),
223
+ ) {
224
+ this.editor.transact((tr) => {
225
+ const linkData = this.getLinkMarkAtPos(position + 1);
226
+ const { from, to } = linkData || {
227
+ from: tr.selection.from,
228
+ to: tr.selection.to,
229
+ };
230
+
231
+ const linkMark = this.editor.pmSchema.mark("link", { href: url });
232
+ const existingText = tr.doc.textBetween(from, to);
233
+ if (text !== existingText) {
234
+ tr.insertText(text, from, to);
179
235
  }
236
+ tr.addMark(from, from + text.length, linkMark);
237
+ });
238
+ this.editor.prosemirrorView.focus();
239
+ }
240
+
241
+ /**
242
+ * Removes the link at the given position, keeping the text.
243
+ * @param position The position inside the link to remove. Defaults to the current selection anchor.
244
+ */
245
+ public deleteLink(
246
+ position = this.editor.transact((tr) => tr.selection.anchor),
247
+ ) {
248
+ this.editor.transact((tr) => {
249
+ const linkData = this.getLinkMarkAtPos(position + 1);
250
+ const { from, to } = linkData || {
251
+ from: tr.selection.from,
252
+ to: tr.selection.to,
253
+ };
254
+
255
+ tr.removeMark(from, to, this.editor.pmSchema.marks["link"]).setMeta(
256
+ "preventAutolink",
257
+ true,
258
+ );
180
259
  });
260
+ this.editor.prosemirrorView.focus();
181
261
  }
182
262
  }