@thomasjahoda-forks/tiptap-extension-link 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,150 @@
1
+ import { Mark } from '@tiptap/core';
2
+
3
+ interface LinkProtocolOptions {
4
+ /**
5
+ * The protocol scheme to be registered.
6
+ * @default '''
7
+ * @example 'ftp'
8
+ * @example 'git'
9
+ */
10
+ scheme: string;
11
+ /**
12
+ * If enabled, it allows optional slashes after the protocol.
13
+ * @default false
14
+ * @example true
15
+ */
16
+ optionalSlashes?: boolean;
17
+ }
18
+ declare const pasteRegex: RegExp;
19
+ /**
20
+ * @deprecated The default behavior is now to open links when the editor is not editable.
21
+ */
22
+ type DeprecatedOpenWhenNotEditable = 'whenNotEditable';
23
+ interface LinkOptions {
24
+ /**
25
+ * If enabled, the extension will automatically add links as you type.
26
+ * @default true
27
+ * @example false
28
+ */
29
+ autolink: boolean;
30
+ /**
31
+ * An array of custom protocols to be registered with linkifyjs.
32
+ * @default []
33
+ * @example ['ftp', 'git']
34
+ */
35
+ protocols: Array<LinkProtocolOptions | string>;
36
+ /**
37
+ * Default protocol to use when no protocol is specified.
38
+ * @default 'http'
39
+ */
40
+ defaultProtocol: string;
41
+ /**
42
+ * If enabled, links will be opened on click.
43
+ * @default true
44
+ * @example false
45
+ */
46
+ openOnClick: boolean | DeprecatedOpenWhenNotEditable;
47
+ /**
48
+ * If enabled, the link will be selected when clicked.
49
+ * @default false
50
+ * @example true
51
+ */
52
+ enableClickSelection: boolean;
53
+ /**
54
+ * Adds a link to the current selection if the pasted content only contains an url.
55
+ * @default true
56
+ * @example false
57
+ */
58
+ linkOnPaste: boolean;
59
+ /**
60
+ * HTML attributes to add to the link element.
61
+ * @default {}
62
+ * @example { class: 'foo' }
63
+ */
64
+ HTMLAttributes: Record<string, any>;
65
+ /**
66
+ * @deprecated Use the `shouldAutoLink` option instead.
67
+ * A validation function that modifies link verification for the auto linker.
68
+ * @param url - The url to be validated.
69
+ * @returns - True if the url is valid, false otherwise.
70
+ */
71
+ validate: (url: string) => boolean;
72
+ /**
73
+ * A validation function which is used for configuring link verification for preventing XSS attacks.
74
+ * Only modify this if you know what you're doing.
75
+ *
76
+ * @returns {boolean} `true` if the URL is valid, `false` otherwise.
77
+ *
78
+ * @example
79
+ * isAllowedUri: (url, { defaultValidate, protocols, defaultProtocol }) => {
80
+ * return url.startsWith('./') || defaultValidate(url)
81
+ * }
82
+ */
83
+ isAllowedUri: (
84
+ /**
85
+ * The URL to be validated.
86
+ */
87
+ url: string, ctx: {
88
+ /**
89
+ * The default validation function.
90
+ */
91
+ defaultValidate: (url: string) => boolean;
92
+ /**
93
+ * An array of allowed protocols for the URL (e.g., "http", "https"). As defined in the `protocols` option.
94
+ */
95
+ protocols: Array<LinkProtocolOptions | string>;
96
+ /**
97
+ * A string that represents the default protocol (e.g., 'http'). As defined in the `defaultProtocol` option.
98
+ */
99
+ defaultProtocol: string;
100
+ }) => boolean;
101
+ /**
102
+ * Determines whether a valid link should be automatically linked in the content.
103
+ *
104
+ * @param {string} url - The URL that has already been validated.
105
+ * @returns {boolean} - True if the link should be auto-linked; false if it should not be auto-linked.
106
+ */
107
+ shouldAutoLink: (url: string) => boolean;
108
+ }
109
+ declare module '@tiptap/core' {
110
+ interface Commands<ReturnType> {
111
+ link: {
112
+ /**
113
+ * Set a link mark
114
+ * @param attributes The link attributes
115
+ * @example editor.commands.setLink({ href: 'https://tiptap.dev' })
116
+ */
117
+ setLink: (attributes: {
118
+ href: string;
119
+ target?: string | null;
120
+ rel?: string | null;
121
+ class?: string | null;
122
+ }) => ReturnType;
123
+ /**
124
+ * Toggle a link mark
125
+ * @param attributes The link attributes
126
+ * @example editor.commands.toggleLink({ href: 'https://tiptap.dev' })
127
+ */
128
+ toggleLink: (attributes?: {
129
+ href: string;
130
+ target?: string | null;
131
+ rel?: string | null;
132
+ class?: string | null;
133
+ }) => ReturnType;
134
+ /**
135
+ * Unset a link mark
136
+ * @example editor.commands.unsetLink()
137
+ */
138
+ unsetLink: () => ReturnType;
139
+ };
140
+ }
141
+ }
142
+ declare function isAllowedUri(uri: string | undefined, protocols?: LinkOptions['protocols']): true | RegExpMatchArray | null;
143
+ declare function getEffectiveLinkHref(href: string | null | undefined, opts: LinkOptions): string | null;
144
+ /**
145
+ * This extension allows you to create links.
146
+ * @see https://www.tiptap.dev/api/marks/link
147
+ */
148
+ declare const Link: Mark<LinkOptions, any>;
149
+
150
+ export { Link, type LinkOptions, type LinkProtocolOptions, Link as default, getEffectiveLinkHref, isAllowedUri, pasteRegex };
@@ -0,0 +1,150 @@
1
+ import { Mark } from '@tiptap/core';
2
+
3
+ interface LinkProtocolOptions {
4
+ /**
5
+ * The protocol scheme to be registered.
6
+ * @default '''
7
+ * @example 'ftp'
8
+ * @example 'git'
9
+ */
10
+ scheme: string;
11
+ /**
12
+ * If enabled, it allows optional slashes after the protocol.
13
+ * @default false
14
+ * @example true
15
+ */
16
+ optionalSlashes?: boolean;
17
+ }
18
+ declare const pasteRegex: RegExp;
19
+ /**
20
+ * @deprecated The default behavior is now to open links when the editor is not editable.
21
+ */
22
+ type DeprecatedOpenWhenNotEditable = 'whenNotEditable';
23
+ interface LinkOptions {
24
+ /**
25
+ * If enabled, the extension will automatically add links as you type.
26
+ * @default true
27
+ * @example false
28
+ */
29
+ autolink: boolean;
30
+ /**
31
+ * An array of custom protocols to be registered with linkifyjs.
32
+ * @default []
33
+ * @example ['ftp', 'git']
34
+ */
35
+ protocols: Array<LinkProtocolOptions | string>;
36
+ /**
37
+ * Default protocol to use when no protocol is specified.
38
+ * @default 'http'
39
+ */
40
+ defaultProtocol: string;
41
+ /**
42
+ * If enabled, links will be opened on click.
43
+ * @default true
44
+ * @example false
45
+ */
46
+ openOnClick: boolean | DeprecatedOpenWhenNotEditable;
47
+ /**
48
+ * If enabled, the link will be selected when clicked.
49
+ * @default false
50
+ * @example true
51
+ */
52
+ enableClickSelection: boolean;
53
+ /**
54
+ * Adds a link to the current selection if the pasted content only contains an url.
55
+ * @default true
56
+ * @example false
57
+ */
58
+ linkOnPaste: boolean;
59
+ /**
60
+ * HTML attributes to add to the link element.
61
+ * @default {}
62
+ * @example { class: 'foo' }
63
+ */
64
+ HTMLAttributes: Record<string, any>;
65
+ /**
66
+ * @deprecated Use the `shouldAutoLink` option instead.
67
+ * A validation function that modifies link verification for the auto linker.
68
+ * @param url - The url to be validated.
69
+ * @returns - True if the url is valid, false otherwise.
70
+ */
71
+ validate: (url: string) => boolean;
72
+ /**
73
+ * A validation function which is used for configuring link verification for preventing XSS attacks.
74
+ * Only modify this if you know what you're doing.
75
+ *
76
+ * @returns {boolean} `true` if the URL is valid, `false` otherwise.
77
+ *
78
+ * @example
79
+ * isAllowedUri: (url, { defaultValidate, protocols, defaultProtocol }) => {
80
+ * return url.startsWith('./') || defaultValidate(url)
81
+ * }
82
+ */
83
+ isAllowedUri: (
84
+ /**
85
+ * The URL to be validated.
86
+ */
87
+ url: string, ctx: {
88
+ /**
89
+ * The default validation function.
90
+ */
91
+ defaultValidate: (url: string) => boolean;
92
+ /**
93
+ * An array of allowed protocols for the URL (e.g., "http", "https"). As defined in the `protocols` option.
94
+ */
95
+ protocols: Array<LinkProtocolOptions | string>;
96
+ /**
97
+ * A string that represents the default protocol (e.g., 'http'). As defined in the `defaultProtocol` option.
98
+ */
99
+ defaultProtocol: string;
100
+ }) => boolean;
101
+ /**
102
+ * Determines whether a valid link should be automatically linked in the content.
103
+ *
104
+ * @param {string} url - The URL that has already been validated.
105
+ * @returns {boolean} - True if the link should be auto-linked; false if it should not be auto-linked.
106
+ */
107
+ shouldAutoLink: (url: string) => boolean;
108
+ }
109
+ declare module '@tiptap/core' {
110
+ interface Commands<ReturnType> {
111
+ link: {
112
+ /**
113
+ * Set a link mark
114
+ * @param attributes The link attributes
115
+ * @example editor.commands.setLink({ href: 'https://tiptap.dev' })
116
+ */
117
+ setLink: (attributes: {
118
+ href: string;
119
+ target?: string | null;
120
+ rel?: string | null;
121
+ class?: string | null;
122
+ }) => ReturnType;
123
+ /**
124
+ * Toggle a link mark
125
+ * @param attributes The link attributes
126
+ * @example editor.commands.toggleLink({ href: 'https://tiptap.dev' })
127
+ */
128
+ toggleLink: (attributes?: {
129
+ href: string;
130
+ target?: string | null;
131
+ rel?: string | null;
132
+ class?: string | null;
133
+ }) => ReturnType;
134
+ /**
135
+ * Unset a link mark
136
+ * @example editor.commands.unsetLink()
137
+ */
138
+ unsetLink: () => ReturnType;
139
+ };
140
+ }
141
+ }
142
+ declare function isAllowedUri(uri: string | undefined, protocols?: LinkOptions['protocols']): true | RegExpMatchArray | null;
143
+ declare function getEffectiveLinkHref(href: string | null | undefined, opts: LinkOptions): string | null;
144
+ /**
145
+ * This extension allows you to create links.
146
+ * @see https://www.tiptap.dev/api/marks/link
147
+ */
148
+ declare const Link: Mark<LinkOptions, any>;
149
+
150
+ export { Link, type LinkOptions, type LinkProtocolOptions, Link as default, getEffectiveLinkHref, isAllowedUri, pasteRegex };