@blocknote/core 0.48.0 → 0.49.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.
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +3 -3
- package/dist/{blocks-DYl7UTS4.js → blocks-CSfJen16.js} +18 -2
- package/dist/blocks-CSfJen16.js.map +1 -0
- package/dist/{blocks-BEvIOzln.cjs → blocks-_lpGWKOa.cjs} +3 -3
- package/dist/blocks-_lpGWKOa.cjs.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +1 -1
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +2 -2
- package/dist/comments.js.map +1 -1
- package/dist/extensions-BfYaEv6F.cjs +2 -0
- package/dist/extensions-BfYaEv6F.cjs.map +1 -0
- package/dist/{extensions-3nf9PPhA.js → extensions-C3nguvVr.js} +240 -248
- package/dist/extensions-C3nguvVr.js.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +2 -2
- package/dist/src-ChTwrMcE.cjs +5 -0
- package/dist/src-ChTwrMcE.cjs.map +1 -0
- package/dist/{src-Hjv1f5lc.js → src-DQfz4zLM.js} +757 -373
- package/dist/src-DQfz4zLM.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.js +1 -1
- package/package.json +6 -8
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +14 -1
- package/src/blocks/Quote/block.ts +9 -0
- package/src/blocks/Table/block.ts +26 -0
- package/src/comments/extension.ts +5 -0
- package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +3 -2
- package/src/comments/threadstore/yjs/YjsThreadStore.ts +4 -4
- package/src/editor/BlockNoteEditor.ts +84 -5
- package/src/editor/editor.css +5 -0
- package/src/editor/managers/ExtensionManager/extensions.ts +8 -26
- package/src/editor/managers/StyleManager.ts +90 -10
- package/src/extensions/FormattingToolbar/FormattingToolbar.ts +23 -16
- package/src/extensions/LinkToolbar/LinkToolbar.ts +30 -75
- package/src/extensions/Placeholder/Placeholder.ts +2 -2
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +179 -0
- package/src/extensions/tiptap-extensions/Link/helpers/clickHandler.ts +82 -0
- package/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts +414 -0
- package/src/extensions/tiptap-extensions/Link/helpers/pasteHandler.ts +53 -0
- package/src/extensions/tiptap-extensions/Link/helpers/tlds.ts +7 -0
- package/src/extensions/tiptap-extensions/Link/helpers/whitespace.ts +13 -0
- package/src/extensions/tiptap-extensions/Link/index.ts +2 -0
- package/src/extensions/tiptap-extensions/Link/link.test.ts +941 -0
- package/src/extensions/tiptap-extensions/Link/link.ts +207 -0
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +3 -5
- package/src/schema/inlineContent/types.ts +1 -1
- package/types/src/editor/BlockNoteEditor.d.ts +69 -3
- package/types/src/editor/managers/StyleManager.d.ts +22 -0
- package/types/src/extensions/LinkToolbar/LinkToolbar.d.ts +28 -7
- package/types/src/extensions/tiptap-extensions/Link/helpers/autolink.d.ts +13 -0
- package/types/src/extensions/tiptap-extensions/Link/helpers/clickHandler.d.ts +12 -0
- package/types/src/extensions/tiptap-extensions/Link/helpers/linkDetector.d.ts +32 -0
- package/types/src/extensions/tiptap-extensions/Link/helpers/pasteHandler.d.ts +12 -0
- package/types/src/extensions/tiptap-extensions/Link/helpers/tlds.d.ts +1 -0
- package/types/src/extensions/tiptap-extensions/Link/helpers/whitespace.d.ts +4 -0
- package/types/src/extensions/tiptap-extensions/Link/index.d.ts +2 -0
- package/types/src/extensions/tiptap-extensions/Link/link.d.ts +13 -0
- package/types/src/extensions/tiptap-extensions/Link/link.test.d.ts +1 -0
- package/types/src/schema/inlineContent/types.d.ts +1 -2
- package/dist/blocks-BEvIOzln.cjs.map +0 -1
- package/dist/blocks-DYl7UTS4.js.map +0 -1
- package/dist/extensions-3nf9PPhA.js.map +0 -1
- package/dist/extensions-D9y6evn6.cjs +0 -2
- package/dist/extensions-D9y6evn6.cjs.map +0 -1
- package/dist/src-BKJH7Jla.cjs +0 -5
- package/dist/src-BKJH7Jla.cjs.map +0 -1
- package/dist/src-Hjv1f5lc.js.map +0 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { PasteRuleMatch } from "@tiptap/core";
|
|
2
|
+
import { Mark, markPasteRule, mergeAttributes } from "@tiptap/core";
|
|
3
|
+
import type { Plugin } from "@tiptap/pm/state";
|
|
4
|
+
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
|
|
5
|
+
import { autolink } from "./helpers/autolink.js";
|
|
6
|
+
import { findLinks } from "./helpers/linkDetector.js";
|
|
7
|
+
import { clickHandler } from "./helpers/clickHandler.js";
|
|
8
|
+
import { pasteHandler } from "./helpers/pasteHandler.js";
|
|
9
|
+
import { UNICODE_WHITESPACE_REGEX_GLOBAL } from "./helpers/whitespace.js";
|
|
10
|
+
|
|
11
|
+
const DEFAULT_PROTOCOL = "https";
|
|
12
|
+
|
|
13
|
+
const HTML_ATTRIBUTES = {
|
|
14
|
+
target: "_blank",
|
|
15
|
+
rel: "noopener noreferrer nofollow",
|
|
16
|
+
className: "bn-inline-content-section",
|
|
17
|
+
"data-inline-content-type": "link",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Pre-compiled regex for URI protocol validation.
|
|
21
|
+
// Allows: http, https, ftp, ftps, mailto, tel, callto, sms, cid, xmpp
|
|
22
|
+
const ALLOWED_URI_REGEX =
|
|
23
|
+
// eslint-disable-next-line no-useless-escape
|
|
24
|
+
/^(?:(?:http|https|ftp|ftps|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z0-9+.\-]+(?:[^a-z+.\-:]|$))/i;
|
|
25
|
+
|
|
26
|
+
export function isAllowedUri(uri: string | undefined): boolean {
|
|
27
|
+
if (!uri) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const cleaned = uri.replace(UNICODE_WHITESPACE_REGEX_GLOBAL, "");
|
|
31
|
+
return ALLOWED_URI_REGEX.test(cleaned);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Determine whether a detected URL should be auto-linked.
|
|
36
|
+
* URLs with explicit protocols are always auto-linked.
|
|
37
|
+
* Bare hostnames must have a TLD (no IP addresses or single words).
|
|
38
|
+
*/
|
|
39
|
+
function shouldAutoLink(url: string): boolean {
|
|
40
|
+
const hasProtocol = /^[a-z][a-z0-9+.-]*:\/\//i.test(url);
|
|
41
|
+
const hasMaybeProtocol = /^[a-z][a-z0-9+.-]*:/i.test(url);
|
|
42
|
+
|
|
43
|
+
if (hasProtocol || (hasMaybeProtocol && !url.includes("@"))) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
// Strip userinfo (user:pass@) if present, then extract hostname
|
|
47
|
+
const urlWithoutUserinfo = url.includes("@") ? url.split("@").pop()! : url;
|
|
48
|
+
const hostname = urlWithoutUserinfo.split(/[/?#:]/)[0];
|
|
49
|
+
|
|
50
|
+
// Don't auto-link IP addresses without protocol
|
|
51
|
+
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(hostname)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
// Don't auto-link single-word hostnames without TLD (e.g., "localhost")
|
|
55
|
+
if (!/\./.test(hostname)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type LinkOptions = {
|
|
62
|
+
HTMLAttributes: Record<string, any>;
|
|
63
|
+
editor?: BlockNoteEditor<any, any, any>;
|
|
64
|
+
onClick?: (
|
|
65
|
+
event: MouseEvent,
|
|
66
|
+
editor: BlockNoteEditor<any, any, any>,
|
|
67
|
+
) => boolean | void;
|
|
68
|
+
isValidLink: (href: string) => boolean;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* BlockNote Link mark extension.
|
|
73
|
+
*/
|
|
74
|
+
export const Link = Mark.create<LinkOptions>({
|
|
75
|
+
name: "link",
|
|
76
|
+
|
|
77
|
+
priority: 1000,
|
|
78
|
+
|
|
79
|
+
keepOnSplit: false,
|
|
80
|
+
|
|
81
|
+
exitable: true,
|
|
82
|
+
|
|
83
|
+
inclusive: false,
|
|
84
|
+
|
|
85
|
+
addOptions() {
|
|
86
|
+
return {
|
|
87
|
+
HTMLAttributes: {},
|
|
88
|
+
editor: undefined,
|
|
89
|
+
onClick: undefined,
|
|
90
|
+
isValidLink: isAllowedUri,
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
addAttributes() {
|
|
95
|
+
return {
|
|
96
|
+
href: {
|
|
97
|
+
default: null,
|
|
98
|
+
parseHTML(element) {
|
|
99
|
+
return element.getAttribute("href");
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
target: {
|
|
103
|
+
default: HTML_ATTRIBUTES.target,
|
|
104
|
+
},
|
|
105
|
+
rel: {
|
|
106
|
+
default: HTML_ATTRIBUTES.rel,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
parseHTML() {
|
|
112
|
+
const isValidLink = this.options.isValidLink;
|
|
113
|
+
return [
|
|
114
|
+
{
|
|
115
|
+
tag: "a[href]",
|
|
116
|
+
getAttrs: (dom) => {
|
|
117
|
+
const href = (dom as HTMLElement).getAttribute("href");
|
|
118
|
+
if (!href || !isValidLink(href)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
renderHTML({ HTMLAttributes }) {
|
|
128
|
+
if (!this.options.isValidLink(HTMLAttributes.href)) {
|
|
129
|
+
return [
|
|
130
|
+
"a",
|
|
131
|
+
mergeAttributes(HTML_ATTRIBUTES, { ...HTMLAttributes, href: "" }),
|
|
132
|
+
0,
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return ["a", mergeAttributes(HTML_ATTRIBUTES, HTMLAttributes), 0];
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
addPasteRules() {
|
|
140
|
+
const isValidLink = this.options.isValidLink;
|
|
141
|
+
return [
|
|
142
|
+
markPasteRule({
|
|
143
|
+
find: (text) => {
|
|
144
|
+
const foundLinks: PasteRuleMatch[] = [];
|
|
145
|
+
|
|
146
|
+
if (text) {
|
|
147
|
+
const links = findLinks(text, {
|
|
148
|
+
defaultProtocol: DEFAULT_PROTOCOL,
|
|
149
|
+
}).filter((item) => item.isLink && isValidLink(item.value));
|
|
150
|
+
|
|
151
|
+
for (const link of links) {
|
|
152
|
+
if (!shouldAutoLink(link.value)) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
foundLinks.push({
|
|
157
|
+
text: link.value,
|
|
158
|
+
data: { href: link.href },
|
|
159
|
+
index: link.start,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return foundLinks;
|
|
165
|
+
},
|
|
166
|
+
type: this.type,
|
|
167
|
+
getAttributes: (match) => ({
|
|
168
|
+
href: match.data?.href,
|
|
169
|
+
}),
|
|
170
|
+
}),
|
|
171
|
+
];
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
addProseMirrorPlugins() {
|
|
175
|
+
const plugins: Plugin[] = [];
|
|
176
|
+
|
|
177
|
+
plugins.push(
|
|
178
|
+
autolink({
|
|
179
|
+
type: this.type,
|
|
180
|
+
defaultProtocol: DEFAULT_PROTOCOL,
|
|
181
|
+
validate: this.options.isValidLink,
|
|
182
|
+
shouldAutoLink,
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
plugins.push(
|
|
187
|
+
clickHandler({
|
|
188
|
+
type: this.type,
|
|
189
|
+
tiptapEditor: this.editor,
|
|
190
|
+
editor: this.options.editor,
|
|
191
|
+
onClick: this.options.onClick,
|
|
192
|
+
}),
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
plugins.push(
|
|
196
|
+
pasteHandler({
|
|
197
|
+
editor: this.editor,
|
|
198
|
+
defaultProtocol: DEFAULT_PROTOCOL,
|
|
199
|
+
type: this.type,
|
|
200
|
+
shouldAutoLink,
|
|
201
|
+
isValidLink: this.options.isValidLink,
|
|
202
|
+
}),
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
return plugins;
|
|
206
|
+
},
|
|
207
|
+
});
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "@tiptap/core";
|
|
7
7
|
import { Fragment, Slice } from "prosemirror-model";
|
|
8
8
|
import { Plugin, PluginKey } from "prosemirror-state";
|
|
9
|
-
import {
|
|
9
|
+
import { uuidv4 } from "lib0/random";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Code from Tiptap UniqueID extension (https://tiptap.dev/api/extensions/unique-id)
|
|
@@ -51,9 +51,7 @@ const UniqueID = Extension.create({
|
|
|
51
51
|
attributeName: "id",
|
|
52
52
|
types: [],
|
|
53
53
|
setIdAttribute: false,
|
|
54
|
-
isWithinEditor: undefined as
|
|
55
|
-
| ((element: Element) => boolean)
|
|
56
|
-
| undefined,
|
|
54
|
+
isWithinEditor: undefined as ((element: Element) => boolean) | undefined,
|
|
57
55
|
generateID: () => {
|
|
58
56
|
// Use mock ID if tests are running.
|
|
59
57
|
if (typeof window !== "undefined" && (window as any).__TEST_OPTIONS) {
|
|
@@ -67,7 +65,7 @@ const UniqueID = Extension.create({
|
|
|
67
65
|
return testOptions.mockID.toString() as string;
|
|
68
66
|
}
|
|
69
67
|
|
|
70
|
-
return
|
|
68
|
+
return uuidv4();
|
|
71
69
|
},
|
|
72
70
|
filterTransaction: null,
|
|
73
71
|
};
|
|
@@ -145,7 +145,7 @@ export type InlineContent<
|
|
|
145
145
|
T extends StyleSchema,
|
|
146
146
|
> = InlineContentFromConfig<I[keyof I], T>;
|
|
147
147
|
|
|
148
|
-
type PartialInlineContentElement<
|
|
148
|
+
export type PartialInlineContentElement<
|
|
149
149
|
I extends InlineContentSchema,
|
|
150
150
|
T extends StyleSchema,
|
|
151
151
|
> = PartialInlineContentFromConfig<I[keyof I], T>;
|
|
@@ -76,6 +76,50 @@ export interface BlockNoteEditorOptions<BSchema extends BlockSchema, ISchema ext
|
|
|
76
76
|
* @remarks `PartialBlock[]`
|
|
77
77
|
*/
|
|
78
78
|
initialContent?: PartialBlock<NoInfer<BSchema>, NoInfer<ISchema>, NoInfer<SSchema>>[];
|
|
79
|
+
/**
|
|
80
|
+
* Options for configuring how links behave in the editor.
|
|
81
|
+
*/
|
|
82
|
+
links?: {
|
|
83
|
+
/**
|
|
84
|
+
* HTML attributes to add to rendered link elements.
|
|
85
|
+
*
|
|
86
|
+
* @default {}
|
|
87
|
+
* @example { class: "my-link-class", target: "_blank" }
|
|
88
|
+
*/
|
|
89
|
+
HTMLAttributes?: Record<string, any>;
|
|
90
|
+
/**
|
|
91
|
+
* Custom handler invoked when a link is clicked. If left `undefined`,
|
|
92
|
+
* links are opened in a new window on click. If provided, the default
|
|
93
|
+
* open-on-click behavior is disabled and this function is called instead.
|
|
94
|
+
*
|
|
95
|
+
* Return `false` to let ProseMirror continue handling the click event.
|
|
96
|
+
* Returning `true` or nothing (the default) marks the event as handled.
|
|
97
|
+
*/
|
|
98
|
+
onClick?: (event: MouseEvent, editor: BlockNoteEditor<any, any, any>) => boolean | void;
|
|
99
|
+
/**
|
|
100
|
+
* Callback that decides whether a given `href` is a valid link. Applied at
|
|
101
|
+
* every gate where a link enters the document: HTML import, HTML export,
|
|
102
|
+
* paste, and autolink. Useful for supporting additional URI schemes (e.g.
|
|
103
|
+
* `vscode:`, `myapp:`) or tightening the default allowlist.
|
|
104
|
+
*
|
|
105
|
+
* Defaults to `isAllowedUri`, which allows
|
|
106
|
+
* `http|https|ftp|ftps|mailto|tel|callto|sms|cid|xmpp`. Import
|
|
107
|
+
* `isAllowedUri` from `@blocknote/core` to layer on top of the default.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { isAllowedUri } from "@blocknote/core";
|
|
112
|
+
*
|
|
113
|
+
* BlockNoteEditor.create({
|
|
114
|
+
* links: {
|
|
115
|
+
* isValidLink: (href) =>
|
|
116
|
+
* isAllowedUri(href) || href.startsWith("myapp:"),
|
|
117
|
+
* },
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
isValidLink?: (href: string) => boolean;
|
|
122
|
+
};
|
|
79
123
|
/**
|
|
80
124
|
* @deprecated, provide placeholders via dictionary instead
|
|
81
125
|
* @internal
|
|
@@ -381,7 +425,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
|
|
|
381
425
|
*/
|
|
382
426
|
isWithinEditor: (element: Element) => boolean;
|
|
383
427
|
isFocused(): boolean;
|
|
384
|
-
|
|
428
|
+
headless: boolean;
|
|
385
429
|
/**
|
|
386
430
|
* Focus on the editor
|
|
387
431
|
*/
|
|
@@ -598,6 +642,28 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
|
|
|
598
642
|
* @param text The text to display the link with.
|
|
599
643
|
*/
|
|
600
644
|
createLink(url: string, text?: string): void;
|
|
645
|
+
/**
|
|
646
|
+
* Find the link mark and its range at the given position.
|
|
647
|
+
* Returns undefined if there is no link at that position.
|
|
648
|
+
*/
|
|
649
|
+
getLinkMarkAtPos(pos: number): {
|
|
650
|
+
href: string;
|
|
651
|
+
from: number;
|
|
652
|
+
to: number;
|
|
653
|
+
text: string;
|
|
654
|
+
} | undefined;
|
|
655
|
+
/**
|
|
656
|
+
* Updates the link at the given position with a new URL and text.
|
|
657
|
+
* @param url The new link URL.
|
|
658
|
+
* @param text The new text to display.
|
|
659
|
+
* @param position The position inside the link to edit. Defaults to the current selection anchor.
|
|
660
|
+
*/
|
|
661
|
+
editLink(url: string, text: string, position?: number): void;
|
|
662
|
+
/**
|
|
663
|
+
* Removes the link at the given position, keeping the text.
|
|
664
|
+
* @param position The position inside the link to remove. Defaults to the current selection anchor.
|
|
665
|
+
*/
|
|
666
|
+
deleteLink(position?: number): void;
|
|
601
667
|
/**
|
|
602
668
|
* Checks if the block containing the text cursor can be nested.
|
|
603
669
|
*/
|
|
@@ -701,7 +767,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
|
|
|
701
767
|
*/
|
|
702
768
|
onMount(callback: (ctx: {
|
|
703
769
|
editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
|
|
704
|
-
}) => void):
|
|
770
|
+
}) => void): import("./managers/EventManager.js").Unsubscribe;
|
|
705
771
|
/**
|
|
706
772
|
* A callback function that runs when the editor has been unmounted.
|
|
707
773
|
*
|
|
@@ -712,7 +778,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
|
|
|
712
778
|
*/
|
|
713
779
|
onUnmount(callback: (ctx: {
|
|
714
780
|
editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
|
|
715
|
-
}) => void):
|
|
781
|
+
}) => void): import("./managers/EventManager.js").Unsubscribe;
|
|
716
782
|
/**
|
|
717
783
|
* Gets the bounding box of the current selection.
|
|
718
784
|
* @returns The bounding box of the current selection.
|
|
@@ -35,6 +35,16 @@ export declare class StyleManager<BSchema extends BlockSchema = DefaultBlockSche
|
|
|
35
35
|
* Gets the currently selected text.
|
|
36
36
|
*/
|
|
37
37
|
getSelectedText(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Find the link mark and its range at the given position.
|
|
40
|
+
* Returns undefined if there is no link at that position.
|
|
41
|
+
*/
|
|
42
|
+
getLinkMarkAtPos(pos: number): {
|
|
43
|
+
href: string;
|
|
44
|
+
from: number;
|
|
45
|
+
to: number;
|
|
46
|
+
text: string;
|
|
47
|
+
} | undefined;
|
|
38
48
|
/**
|
|
39
49
|
* Gets the URL of the last link in the current selection, or `undefined` if there are no links in the selection.
|
|
40
50
|
*/
|
|
@@ -45,4 +55,16 @@ export declare class StyleManager<BSchema extends BlockSchema = DefaultBlockSche
|
|
|
45
55
|
* @param text The text to display the link with.
|
|
46
56
|
*/
|
|
47
57
|
createLink(url: string, text?: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Updates the link at the given position with a new URL and text.
|
|
60
|
+
* @param url The new link URL.
|
|
61
|
+
* @param text The new text to display.
|
|
62
|
+
* @param position The position inside the link to edit. Defaults to the current selection anchor.
|
|
63
|
+
*/
|
|
64
|
+
editLink(url: string, text: string, position?: number): void;
|
|
65
|
+
/**
|
|
66
|
+
* Removes the link at the given position, keeping the text.
|
|
67
|
+
* @param position The position inside the link to remove. Defaults to the current selection anchor.
|
|
68
|
+
*/
|
|
69
|
+
deleteLink(position?: number): void;
|
|
48
70
|
}
|
|
@@ -1,21 +1,42 @@
|
|
|
1
1
|
export declare const LinkToolbarExtension: (options?: any) => import("../../index.js").ExtensionFactoryInstance<{
|
|
2
2
|
readonly key: "linkToolbar";
|
|
3
3
|
readonly getLinkAtSelection: () => {
|
|
4
|
-
range:
|
|
5
|
-
|
|
4
|
+
range: {
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
};
|
|
8
|
+
mark: {
|
|
9
|
+
attrs: {
|
|
10
|
+
href: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
6
13
|
readonly text: string;
|
|
7
14
|
readonly position: DOMRect;
|
|
8
15
|
} | undefined;
|
|
9
16
|
readonly getLinkElementAtPos: (pos: number) => HTMLAnchorElement | null;
|
|
10
|
-
readonly getMarkAtPos: (pos: number,
|
|
11
|
-
range:
|
|
12
|
-
|
|
17
|
+
readonly getMarkAtPos: (pos: number, _markType: string) => {
|
|
18
|
+
range: {
|
|
19
|
+
from: number;
|
|
20
|
+
to: number;
|
|
21
|
+
};
|
|
22
|
+
mark: {
|
|
23
|
+
attrs: {
|
|
24
|
+
href: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
13
27
|
readonly text: string;
|
|
14
28
|
readonly position: DOMRect;
|
|
15
29
|
} | undefined;
|
|
16
30
|
readonly getLinkAtElement: (element: HTMLElement) => {
|
|
17
|
-
range:
|
|
18
|
-
|
|
31
|
+
range: {
|
|
32
|
+
from: number;
|
|
33
|
+
to: number;
|
|
34
|
+
};
|
|
35
|
+
mark: {
|
|
36
|
+
attrs: {
|
|
37
|
+
href: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
19
40
|
readonly text: string;
|
|
20
41
|
readonly position: DOMRect;
|
|
21
42
|
} | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MarkType } from "@tiptap/pm/model";
|
|
2
|
+
import { Plugin } from "@tiptap/pm/state";
|
|
3
|
+
type AutolinkOptions = {
|
|
4
|
+
type: MarkType;
|
|
5
|
+
defaultProtocol: string;
|
|
6
|
+
validate: (url: string) => boolean;
|
|
7
|
+
shouldAutoLink: (url: string) => boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Plugin that automatically adds link marks when typing URLs.
|
|
11
|
+
*/
|
|
12
|
+
export declare function autolink(options: AutolinkOptions): Plugin;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Editor } from "@tiptap/core";
|
|
2
|
+
import type { MarkType } from "@tiptap/pm/model";
|
|
3
|
+
import { Plugin } from "@tiptap/pm/state";
|
|
4
|
+
import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
|
|
5
|
+
type ClickHandlerOptions = {
|
|
6
|
+
type: MarkType;
|
|
7
|
+
tiptapEditor: Editor;
|
|
8
|
+
editor?: BlockNoteEditor<any, any, any>;
|
|
9
|
+
onClick?: (event: MouseEvent, editor: BlockNoteEditor<any, any, any>) => boolean | void;
|
|
10
|
+
};
|
|
11
|
+
export declare function clickHandler(options: ClickHandlerOptions): Plugin;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight URL detection module replacing linkifyjs.
|
|
3
|
+
*
|
|
4
|
+
* Provides two functions:
|
|
5
|
+
* - findLinks(): find all URLs/emails in arbitrary text (replaces linkifyjs find())
|
|
6
|
+
* - tokenizeLink(): tokenize a single word for autolink validation (replaces linkifyjs tokenize())
|
|
7
|
+
*/
|
|
8
|
+
export interface LinkMatch {
|
|
9
|
+
type: string;
|
|
10
|
+
value: string;
|
|
11
|
+
isLink: boolean;
|
|
12
|
+
href: string;
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
}
|
|
16
|
+
export interface FindOptions {
|
|
17
|
+
defaultProtocol?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Find all URLs and email addresses in the given text.
|
|
21
|
+
* Drop-in replacement for linkifyjs find().
|
|
22
|
+
*/
|
|
23
|
+
export declare function findLinks(text: string, options?: FindOptions): LinkMatch[];
|
|
24
|
+
/**
|
|
25
|
+
* Tokenize a single word for autolink validation.
|
|
26
|
+
* Drop-in replacement for: tokenize(word).map(t => t.toObject(defaultProtocol))
|
|
27
|
+
*
|
|
28
|
+
* Returns an array of LinkMatch tokens. The autolink code checks:
|
|
29
|
+
* - 1 token with isLink=true → valid single link
|
|
30
|
+
* - 3 tokens with middle isLink=true and outer brackets → valid wrapped link
|
|
31
|
+
*/
|
|
32
|
+
export declare function tokenizeLink(text: string, defaultProtocol?: string): LinkMatch[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Editor } from "@tiptap/core";
|
|
2
|
+
import type { MarkType } from "@tiptap/pm/model";
|
|
3
|
+
import { Plugin } from "@tiptap/pm/state";
|
|
4
|
+
type PasteHandlerOptions = {
|
|
5
|
+
editor: Editor;
|
|
6
|
+
defaultProtocol: string;
|
|
7
|
+
type: MarkType;
|
|
8
|
+
shouldAutoLink?: (url: string) => boolean;
|
|
9
|
+
isValidLink: (href: string) => boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function pasteHandler(options: PasteHandlerOptions): Plugin;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ENCODED_TLDS = "aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2odyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rck0msd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2oodside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const UNICODE_WHITESPACE_PATTERN = "[\0- \u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]";
|
|
2
|
+
export declare const UNICODE_WHITESPACE_REGEX: RegExp;
|
|
3
|
+
export declare const UNICODE_WHITESPACE_REGEX_END: RegExp;
|
|
4
|
+
export declare const UNICODE_WHITESPACE_REGEX_GLOBAL: RegExp;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Mark } from "@tiptap/core";
|
|
2
|
+
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
|
|
3
|
+
export declare function isAllowedUri(uri: string | undefined): boolean;
|
|
4
|
+
export type LinkOptions = {
|
|
5
|
+
HTMLAttributes: Record<string, any>;
|
|
6
|
+
editor?: BlockNoteEditor<any, any, any>;
|
|
7
|
+
onClick?: (event: MouseEvent, editor: BlockNoteEditor<any, any, any>) => boolean | void;
|
|
8
|
+
isValidLink: (href: string) => boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* BlockNote Link mark extension.
|
|
12
|
+
*/
|
|
13
|
+
export declare const Link: Mark<LinkOptions, any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -73,9 +73,8 @@ export type PartialLink<T extends StyleSchema> = Omit<Link<T>, "content"> & {
|
|
|
73
73
|
content: string | Link<T>["content"];
|
|
74
74
|
};
|
|
75
75
|
export type InlineContent<I extends InlineContentSchema, T extends StyleSchema> = InlineContentFromConfig<I[keyof I], T>;
|
|
76
|
-
type PartialInlineContentElement<I extends InlineContentSchema, T extends StyleSchema> = PartialInlineContentFromConfig<I[keyof I], T>;
|
|
76
|
+
export type PartialInlineContentElement<I extends InlineContentSchema, T extends StyleSchema> = PartialInlineContentFromConfig<I[keyof I], T>;
|
|
77
77
|
export type PartialInlineContent<I extends InlineContentSchema, T extends StyleSchema> = PartialInlineContentElement<I, T>[] | string;
|
|
78
78
|
export declare function isLinkInlineContent<T extends StyleSchema>(content: InlineContent<any, T>): content is Link<T>;
|
|
79
79
|
export declare function isPartialLinkInlineContent<T extends StyleSchema>(content: PartialInlineContentElement<any, T>): content is PartialLink<T>;
|
|
80
80
|
export declare function isStyledTextInlineContent<T extends StyleSchema>(content: PartialInlineContentElement<any, T>): content is StyledText<T>;
|
|
81
|
-
export {};
|