@lexical/link 0.35.1-nightly.20250924.0 → 0.36.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/ClickableLinkExtension.d.ts +22 -0
- package/LexicalAutoLinkExtension.d.ts +41 -0
- package/LexicalLink.dev.js +585 -9
- package/LexicalLink.dev.mjs +581 -12
- package/LexicalLink.js.flow +69 -0
- package/LexicalLink.mjs +7 -0
- package/LexicalLink.node.mjs +7 -0
- package/LexicalLink.prod.js +1 -1
- package/LexicalLink.prod.mjs +1 -1
- package/LexicalLinkExtension.d.ts +37 -0
- package/LexicalLinkNode.d.ts +126 -0
- package/index.d.ts +5 -117
- package/package.json +4 -3
package/LexicalLink.js.flow
CHANGED
|
@@ -14,9 +14,12 @@ import type {
|
|
|
14
14
|
RangeSelection,
|
|
15
15
|
LexicalCommand,
|
|
16
16
|
SerializedElementNode,
|
|
17
|
+
LexicalEditor,
|
|
17
18
|
} from 'lexical';
|
|
18
19
|
import {addClassNamesToElement} from '@lexical/utils';
|
|
19
20
|
import {$isElementNode, ElementNode} from 'lexical';
|
|
21
|
+
import type {LexicalExtension, NamedSignalsOutput} from '@lexical/extension';
|
|
22
|
+
|
|
20
23
|
export type LinkAttributes = $ReadOnly<{
|
|
21
24
|
rel?: null | string,
|
|
22
25
|
target?: null | string,
|
|
@@ -97,3 +100,69 @@ declare export function $toggleLink(
|
|
|
97
100
|
/** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
|
|
98
101
|
declare const toggleLink: typeof $toggleLink;
|
|
99
102
|
declare export function formatUrl(url: string): string;
|
|
103
|
+
|
|
104
|
+
export type ClickableLinkConfig = {
|
|
105
|
+
newTab: boolean;
|
|
106
|
+
disabled: boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type AddEventListenerOptions = Exclude<EventListenerOptionsOrUseCapture, boolean>;
|
|
110
|
+
|
|
111
|
+
declare export function registerClickableLink(
|
|
112
|
+
editor: LexicalEditor,
|
|
113
|
+
stores: NamedSignalsOutput<ClickableLinkConfig>,
|
|
114
|
+
eventOptions?: Pick<AddEventListenerOptions, 'signal'>,
|
|
115
|
+
): () => void;
|
|
116
|
+
|
|
117
|
+
declare export var ClickableLinkExtension: LexicalExtension<ClickableLinkConfig, "@lexical/link/ClickableLink", NamedSignalsOutput<ClickableLinkConfig>, void>;
|
|
118
|
+
declare export function registerClickableLink(
|
|
119
|
+
editor: LexicalEditor,
|
|
120
|
+
stores: NamedSignalsOutput<ClickableLinkConfig>,
|
|
121
|
+
eventOptions?: Pick<AddEventListenerOptions, 'signal'>,
|
|
122
|
+
): () => void;
|
|
123
|
+
|
|
124
|
+
export type AutoLinkConfig = {
|
|
125
|
+
matchers: LinkMatcher[];
|
|
126
|
+
changeHandlers: ChangeHandler[];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type ChangeHandler = (
|
|
130
|
+
url: string | null,
|
|
131
|
+
prevUrl: string | null,
|
|
132
|
+
) => void;
|
|
133
|
+
|
|
134
|
+
export type AutoLinkAttributes = Partial<
|
|
135
|
+
{...LinkAttributes, isUnlinked?: boolean}
|
|
136
|
+
>;
|
|
137
|
+
|
|
138
|
+
export type LinkMatcherResult = {
|
|
139
|
+
attributes?: AutoLinkAttributes;
|
|
140
|
+
index: number;
|
|
141
|
+
length: number;
|
|
142
|
+
text: string;
|
|
143
|
+
url: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type LinkMatcher = (text: string) => LinkMatcherResult | null;
|
|
147
|
+
|
|
148
|
+
declare export function createLinkMatcherWithRegExp(
|
|
149
|
+
regExp: RegExp,
|
|
150
|
+
urlTransformer?: (text: string) => string,
|
|
151
|
+
): LinkMatcher;
|
|
152
|
+
|
|
153
|
+
declare export var AutoLinkExtension: LexicalExtension<AutoLinkConfig, "@lexical/link/AutoLink", void, void>;
|
|
154
|
+
|
|
155
|
+
declare export function registerAutoLink(
|
|
156
|
+
editor: LexicalEditor,
|
|
157
|
+
config?: AutoLinkConfig,
|
|
158
|
+
): () => void;
|
|
159
|
+
|
|
160
|
+
export type LinkConfig = {
|
|
161
|
+
validateUrl: void | ((url: string) => boolean);
|
|
162
|
+
attributes: void | LinkAttributes;
|
|
163
|
+
}
|
|
164
|
+
declare export var LinkExtension: LexicalExtension<LinkConfig, "@lexical/link/Link", NamedSignalsOutput<LinkConfig>, void>;
|
|
165
|
+
declare export function registerLink(
|
|
166
|
+
editor: LexicalEditor,
|
|
167
|
+
stores: NamedSignalsOutput<LinkConfig>,
|
|
168
|
+
): () => void;
|
package/LexicalLink.mjs
CHANGED
|
@@ -14,8 +14,15 @@ export const $createLinkNode = mod.$createLinkNode;
|
|
|
14
14
|
export const $isAutoLinkNode = mod.$isAutoLinkNode;
|
|
15
15
|
export const $isLinkNode = mod.$isLinkNode;
|
|
16
16
|
export const $toggleLink = mod.$toggleLink;
|
|
17
|
+
export const AutoLinkExtension = mod.AutoLinkExtension;
|
|
17
18
|
export const AutoLinkNode = mod.AutoLinkNode;
|
|
19
|
+
export const ClickableLinkExtension = mod.ClickableLinkExtension;
|
|
20
|
+
export const LinkExtension = mod.LinkExtension;
|
|
18
21
|
export const LinkNode = mod.LinkNode;
|
|
19
22
|
export const TOGGLE_LINK_COMMAND = mod.TOGGLE_LINK_COMMAND;
|
|
23
|
+
export const createLinkMatcherWithRegExp = mod.createLinkMatcherWithRegExp;
|
|
20
24
|
export const formatUrl = mod.formatUrl;
|
|
25
|
+
export const registerAutoLink = mod.registerAutoLink;
|
|
26
|
+
export const registerClickableLink = mod.registerClickableLink;
|
|
27
|
+
export const registerLink = mod.registerLink;
|
|
21
28
|
export const toggleLink = mod.toggleLink;
|
package/LexicalLink.node.mjs
CHANGED
|
@@ -12,8 +12,15 @@ export const $createLinkNode = mod.$createLinkNode;
|
|
|
12
12
|
export const $isAutoLinkNode = mod.$isAutoLinkNode;
|
|
13
13
|
export const $isLinkNode = mod.$isLinkNode;
|
|
14
14
|
export const $toggleLink = mod.$toggleLink;
|
|
15
|
+
export const AutoLinkExtension = mod.AutoLinkExtension;
|
|
15
16
|
export const AutoLinkNode = mod.AutoLinkNode;
|
|
17
|
+
export const ClickableLinkExtension = mod.ClickableLinkExtension;
|
|
18
|
+
export const LinkExtension = mod.LinkExtension;
|
|
16
19
|
export const LinkNode = mod.LinkNode;
|
|
17
20
|
export const TOGGLE_LINK_COMMAND = mod.TOGGLE_LINK_COMMAND;
|
|
21
|
+
export const createLinkMatcherWithRegExp = mod.createLinkMatcherWithRegExp;
|
|
18
22
|
export const formatUrl = mod.formatUrl;
|
|
23
|
+
export const registerAutoLink = mod.registerAutoLink;
|
|
24
|
+
export const registerClickableLink = mod.registerClickableLink;
|
|
25
|
+
export const registerLink = mod.registerLink;
|
|
19
26
|
export const toggleLink = mod.toggleLink;
|
package/LexicalLink.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var t=require("@lexical/utils"),e=require("lexical");const n=new Set(["http:","https:","mailto:","sms:","tel:"]);class r extends e.ElementNode{static getType(){return"link"}static clone(t){return new r(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t="",e={},n){super(n);const{target:r=null,rel:i=null,title:s=null}=e;this.__url=t,this.__target=r,this.__rel=i,this.__title=s}createDOM(e){const n=document.createElement("a");return this.updateLinkDOM(null,n,e),t.addClassNamesToElement(n,e.theme.link),n}updateLinkDOM(e,n,r){if(t.isHTMLAnchorElement(n)){e&&e.__url===this.__url||(n.href=this.sanitizeUrl(this.__url));for(const t of["target","rel","title"]){const r=`__${t}`,i=this[r];e&&e[r]===i||(i?n[t]=i:n.removeAttribute(t))}}}updateDOM(t,e,n){return this.updateLinkDOM(t,e,n),!1}static importDOM(){return{a:t=>({conversion:i,priority:1})}}static importJSON(t){return s().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setURL(t.url).setRel(t.rel||null).setTarget(t.target||null).setTitle(t.title||null)}sanitizeUrl(t){t=f(t);try{const e=new URL(f(t));if(!n.has(e.protocol))return"about:blank"}catch(e){return t}return t}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),url:this.getURL()}}getURL(){return this.getLatest().__url}setURL(t){const e=this.getWritable();return e.__url=t,e}getTarget(){return this.getLatest().__target}setTarget(t){const e=this.getWritable();return e.__target=t,e}getRel(){return this.getLatest().__rel}setRel(t){const e=this.getWritable();return e.__rel=t,e}getTitle(){return this.getLatest().__title}setTitle(t){const e=this.getWritable();return e.__title=t,e}insertNewAfter(t,e=!0){const n=s(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(n,e),n}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,n,r){if(!e.$isRangeSelection(n))return!1;const i=n.anchor.getNode(),s=n.focus.getNode();return this.isParentOf(i)&&this.isParentOf(s)&&n.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function i(e){let n=null;if(t.isHTMLAnchorElement(e)){const t=e.textContent;(null!==t&&""!==t||e.children.length>0)&&(n=s(e.getAttribute("href")||"",{rel:e.getAttribute("rel"),target:e.getAttribute("target"),title:e.getAttribute("title")}))}return{node:n}}function s(t="",n){return e.$applyNodeReplacement(new r(t,n))}function l(t){return t instanceof r}class o extends r{constructor(t="",e={},n){super(t,e,n),this.__isUnlinked=void 0!==e.isUnlinked&&null!==e.isUnlinked&&e.isUnlinked}static getType(){return"autolink"}static clone(t){return new o(t.__url,{isUnlinked:t.__isUnlinked,rel:t.__rel,target:t.__target,title:t.__title},t.__key)}getIsUnlinked(){return this.__isUnlinked}setIsUnlinked(t){const e=this.getWritable();return e.__isUnlinked=t,e}createDOM(t){return this.__isUnlinked?document.createElement("span"):super.createDOM(t)}updateDOM(t,e,n){return super.updateDOM(t,e,n)||t.__isUnlinked!==this.__isUnlinked}static importJSON(t){return a().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setIsUnlinked(t.isUnlinked||!1)}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),isUnlinked:this.__isUnlinked}}insertNewAfter(t,n=!0){const r=this.getParentOrThrow().insertNewAfter(t,n);if(e.$isElementNode(r)){const t=a(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return r.append(t),t}return null}}function a(t="",n){return e.$applyNodeReplacement(new o(t,n))}function u(t){return t instanceof o}const c=e.createCommand("TOGGLE_LINK_COMMAND");function _(t,n){if("element"===t.type){const r=t.getNode();e.$isElementNode(r)||function(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(252);return r.getChildren()[t.offset+n]||null}return null}function d(n,r={}){const{target:i,title:o}=r,a=void 0===r.rel?"noreferrer":r.rel,c=e.$getSelection();if(null===c||!e.$isRangeSelection(c)&&!e.$isNodeSelection(c))return;if(e.$isNodeSelection(c)){const e=c.getNodes();if(0===e.length)return;return void e.forEach((e=>{if(null===n){const n=t.$findMatchingParent(e,(t=>!u(t)&&l(t)));n&&(n.insertBefore(e),0===n.getChildren().length&&n.remove())}else{const r=t.$findMatchingParent(e,(t=>!u(t)&&l(t)));if(r)r.setURL(n),void 0!==i&&r.setTarget(i),void 0!==a&&r.setRel(a);else{const t=s(n,{rel:a,target:i});e.insertBefore(t),t.append(e)}}}))}const d=c.extract();if(null===n)return void d.forEach((e=>{const n=t.$findMatchingParent(e,(t=>!u(t)&&l(t)));if(n){const t=n.getChildren();for(let e=0;e<t.length;e++)n.insertBefore(t[e]);n.remove()}}));const g=new Set,h=t=>{g.has(t.getKey())||(g.add(t.getKey()),t.setURL(n),void 0!==i&&t.setTarget(i),void 0!==a&&t.setRel(a),void 0!==o&&t.setTitle(o))};if(1===d.length){const e=d[0],n=t.$findMatchingParent(e,l);if(null!==n)return h(n)}!function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n))return t();const r=e.$normalizeSelection__EXPERIMENTAL(n),i=r.isBackward(),s=_(r.anchor,i?-1:0),l=_(r.focus,i?0:-1),o=t();if(s||l){const t=e.$getSelection();if(e.$isRangeSelection(t)){const n=t.clone();if(s){const t=s.getParent();t&&n.anchor.set(t.getKey(),s.getIndexWithinParent()+(i?1:0),"element")}if(l){const t=l.getParent();t&&n.focus.set(t.getKey(),l.getIndexWithinParent()+(i?0:1),"element")}e.$setSelection(e.$normalizeSelection__EXPERIMENTAL(n))}}}((()=>{let r=null;for(const c of d){if(!c.isAttached())continue;const _=t.$findMatchingParent(c,l);if(_){h(_);continue}if(e.$isElementNode(c)){if(!c.isInline())continue;if(l(c)){if(!(u(c)||null!==r&&r.getParentOrThrow().isParentOf(c))){h(c),r=c;continue}for(const t of c.getChildren())c.insertBefore(t);c.remove();continue}}const d=c.getPreviousSibling();l(d)&&d.is(r)?d.append(c):(r=s(n,{rel:a,target:i,title:o}),c.insertAfter(r),r.append(c))}}))}const g=d,h=/^\+?[0-9\s()-]{5,}$/;function f(t){return t.match(/^[a-z][a-z0-9+.-]*:/i)||t.match(/^[/#.]/)?t:t.includes("@")?`mailto:${t}`:h.test(t)?`tel:${t}`:`https://${t}`}exports.$createAutoLinkNode=a,exports.$createLinkNode=s,exports.$isAutoLinkNode=u,exports.$isLinkNode=l,exports.$toggleLink=d,exports.AutoLinkNode=o,exports.LinkNode=r,exports.TOGGLE_LINK_COMMAND=c,exports.formatUrl=f,exports.toggleLink=g;
|
|
9
|
+
"use strict";var e=require("@lexical/utils"),t=require("lexical"),n=require("@lexical/extension");const r=new Set(["http:","https:","mailto:","sms:","tel:"]);class i extends t.ElementNode{__url;__target;__rel;__title;static getType(){return"link"}static clone(e){return new i(e.__url,{rel:e.__rel,target:e.__target,title:e.__title},e.__key)}constructor(e="",t={},n){super(n);const{target:r=null,rel:i=null,title:s=null}=t;this.__url=e,this.__target=r,this.__rel=i,this.__title=s}createDOM(t){const n=document.createElement("a");return this.updateLinkDOM(null,n,t),e.addClassNamesToElement(n,t.theme.link),n}updateLinkDOM(t,n,r){if(e.isHTMLAnchorElement(n)){t&&t.__url===this.__url||(n.href=this.sanitizeUrl(this.__url));for(const e of["target","rel","title"]){const r=`__${e}`,i=this[r];t&&t[r]===i||(i?n[e]=i:n.removeAttribute(e))}}}updateDOM(e,t,n){return this.updateLinkDOM(e,t,n),!1}static importDOM(){return{a:e=>({conversion:s,priority:1})}}static importJSON(e){return l().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setURL(e.url).setRel(e.rel||null).setTarget(e.target||null).setTitle(e.title||null)}sanitizeUrl(e){e=p(e);try{const t=new URL(p(e));if(!r.has(t.protocol))return"about:blank"}catch(t){return e}return e}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),url:this.getURL()}}getURL(){return this.getLatest().__url}setURL(e){const t=this.getWritable();return t.__url=e,t}getTarget(){return this.getLatest().__target}setTarget(e){const t=this.getWritable();return t.__target=e,t}getRel(){return this.getLatest().__rel}setRel(e){const t=this.getWritable();return t.__rel=e,t}getTitle(){return this.getLatest().__title}setTitle(e){const t=this.getWritable();return t.__title=e,t}insertNewAfter(e,t=!0){const n=l(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(n,t),n}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(e,n,r){if(!t.$isRangeSelection(n))return!1;const i=n.anchor.getNode(),s=n.focus.getNode();return this.isParentOf(i)&&this.isParentOf(s)&&n.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function s(t){let n=null;if(e.isHTMLAnchorElement(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(n=l(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:n}}function l(e="",n){return t.$applyNodeReplacement(new i(e,n))}function o(e){return e instanceof i}class u extends i{__isUnlinked;constructor(e="",t={},n){super(e,t,n),this.__isUnlinked=void 0!==t.isUnlinked&&null!==t.isUnlinked&&t.isUnlinked}static getType(){return"autolink"}static clone(e){return new u(e.__url,{isUnlinked:e.__isUnlinked,rel:e.__rel,target:e.__target,title:e.__title},e.__key)}getIsUnlinked(){return this.__isUnlinked}setIsUnlinked(e){const t=this.getWritable();return t.__isUnlinked=e,t}createDOM(e){return this.__isUnlinked?document.createElement("span"):super.createDOM(e)}updateDOM(e,t,n){return super.updateDOM(e,t,n)||e.__isUnlinked!==this.__isUnlinked}static importJSON(e){return a().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setIsUnlinked(e.isUnlinked||!1)}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),isUnlinked:this.__isUnlinked}}insertNewAfter(e,n=!0){const r=this.getParentOrThrow().insertNewAfter(e,n);if(t.$isElementNode(r)){const e=a(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return r.append(e),e}return null}}function a(e="",n){return t.$applyNodeReplacement(new u(e,n))}function c(e){return e instanceof u}const g=t.createCommand("TOGGLE_LINK_COMMAND");function d(e,n){if("element"===e.type){const r=e.getNode();t.$isElementNode(r)||function(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(252);return r.getChildren()[e.offset+n]||null}return null}function f(n,r={}){let i;if(n&&"object"==typeof n){const{url:e,...t}=n;i=e,r={...t,...r}}else i=n;const{target:s,title:u}=r,a=void 0===r.rel?"noreferrer":r.rel,g=t.$getSelection();if(null===g||!t.$isRangeSelection(g)&&!t.$isNodeSelection(g))return;if(t.$isNodeSelection(g)){const t=g.getNodes();if(0===t.length)return;return void t.forEach((t=>{if(null===i){const n=e.$findMatchingParent(t,(e=>!c(e)&&o(e)));n&&(n.insertBefore(t),0===n.getChildren().length&&n.remove())}else{const n=e.$findMatchingParent(t,(e=>!c(e)&&o(e)));if(n)n.setURL(i),void 0!==s&&n.setTarget(s),void 0!==a&&n.setRel(a);else{const e=l(i,{rel:a,target:s});t.insertBefore(e),e.append(t)}}}))}const f=g.extract();if(null===i)return void f.forEach((t=>{const n=e.$findMatchingParent(t,(e=>!c(e)&&o(e)));if(n){const e=n.getChildren();for(let t=0;t<e.length;t++)n.insertBefore(e[t]);n.remove()}}));const h=new Set,p=e=>{h.has(e.getKey())||(h.add(e.getKey()),e.setURL(i),void 0!==s&&e.setTarget(s),void 0!==a&&e.setRel(a),void 0!==u&&e.setTitle(u))};if(1===f.length){const t=f[0],n=e.$findMatchingParent(t,o);if(null!==n)return p(n)}!function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n))return e();const r=t.$normalizeSelection__EXPERIMENTAL(n),i=r.isBackward(),s=d(r.anchor,i?-1:0),l=d(r.focus,i?0:-1),o=e();if(s||l){const e=t.$getSelection();if(t.$isRangeSelection(e)){const n=e.clone();if(s){const e=s.getParent();e&&n.anchor.set(e.getKey(),s.getIndexWithinParent()+(i?1:0),"element")}if(l){const e=l.getParent();e&&n.focus.set(e.getKey(),l.getIndexWithinParent()+(i?0:1),"element")}t.$setSelection(t.$normalizeSelection__EXPERIMENTAL(n))}}}((()=>{let n=null;for(const r of f){if(!r.isAttached())continue;const g=e.$findMatchingParent(r,o);if(g){p(g);continue}if(t.$isElementNode(r)){if(!r.isInline())continue;if(o(r)){if(!(c(r)||null!==n&&n.getParentOrThrow().isParentOf(r))){p(r),n=r;continue}for(const e of r.getChildren())r.insertBefore(e);r.remove();continue}}const d=r.getPreviousSibling();o(d)&&d.is(n)?d.append(r):(n=l(i,{rel:a,target:s,title:u}),r.insertAfter(n),n.append(r))}}))}const h=/^\+?[0-9\s()-]{5,}$/;function p(e){return e.match(/^[a-z][a-z0-9+.-]*:/i)||e.match(/^[/#.]/)?e:e.includes("@")?`mailto:${e}`:h.test(e)?`tel:${e}`:`https://${e}`}const _={attributes:void 0,validateUrl:void 0};function m(r,i){return e.mergeRegister(n.effect((()=>r.registerCommand(g,(e=>{const t=i.validateUrl.peek(),n=i.attributes.peek();if(null===e)return f(null),!0;if("string"==typeof e)return!(void 0!==t&&!t(e))&&(f(e,n),!0);{const{url:t,target:r,rel:i,title:s}=e;return f(t,{...n,rel:i,target:r,title:s}),!0}}),t.COMMAND_PRIORITY_LOW))),n.effect((()=>{const n=i.validateUrl.value;if(!n)return;const s=i.attributes.value;return r.registerCommand(t.PASTE_COMMAND,(i=>{const l=t.$getSelection();if(!t.$isRangeSelection(l)||l.isCollapsed()||!e.objectKlassEquals(i,ClipboardEvent))return!1;if(null===i.clipboardData)return!1;const o=i.clipboardData.getData("text");return!!n(o)&&(!l.getNodes().some((e=>t.$isElementNode(e)))&&(r.dispatchCommand(g,{...s,url:o}),i.preventDefault(),!0))}),t.COMMAND_PRIORITY_LOW)})))}const x=t.defineExtension({build:(e,t,r)=>n.namedSignals(t),config:_,name:"@lexical/link/Link",nodes:[i],register:(e,t,n)=>m(e,n.getOutput())});function N(n,r,i={}){const s=i=>{const s=i.target;if(!t.isDOMNode(s))return;const l=t.getNearestEditorFromDOMNode(s);if(null===l)return;let u=null,a=null;if(l.update((()=>{const n=t.$getNearestNodeFromDOMNode(s);if(null!==n){const i=e.$findMatchingParent(n,t.$isElementNode);if(!r.disabled.peek())if(o(i))u=i.sanitizeUrl(i.getURL()),a=i.getTarget();else{const t=function(e,t){let n=e;for(;null!=n;){if(t(n))return n;n=n.parentNode}return null}(s,e.isHTMLAnchorElement);null!==t&&(u=t.href,a=t.target)}}})),null===u||""===u)return;const c=n.getEditorState().read(t.$getSelection);if(t.$isRangeSelection(c)&&!c.isCollapsed())return void i.preventDefault();const g="auxclick"===i.type&&1===i.button;window.open(u,r.newTab.peek()||g||i.metaKey||i.ctrlKey||"_blank"===a?"_blank":"_self"),i.preventDefault()},l=e=>{1===e.button&&s(e)};return n.registerRootListener(((e,t)=>{null!==t&&(t.removeEventListener("click",s),t.removeEventListener("mouseup",l)),null!==e&&(e.addEventListener("click",s,i),e.addEventListener("mouseup",l,i))}))}const k=t.defineExtension({build:(e,t,r)=>n.namedSignals(t),config:t.safeCast({disabled:!1,newTab:!1}),dependencies:[x],name:"@lexical/link/ClickableLink",register:(e,t,n)=>N(e,n.getOutput())});function L(e,t){for(let n=0;n<t.length;n++){const r=t[n](e);if(r)return r}return null}const T=/[.,;\s]/;function S(e){return T.test(e)}function $(e){return S(e[e.length-1])}function U(e){return S(e[0])}function b(e){let n=e.getPreviousSibling();return t.$isElementNode(n)&&(n=n.getLastDescendant()),null===n||t.$isLineBreakNode(n)||t.$isTextNode(n)&&$(n.getTextContent())}function R(e){let n=e.getNextSibling();return t.$isElementNode(n)&&(n=n.getFirstDescendant()),null===n||t.$isLineBreakNode(n)||t.$isTextNode(n)&&U(n.getTextContent())}function v(e,t,n,r){if(!(e>0?S(n[e-1]):b(r[0])))return!1;return t<n.length?S(n[t]):R(r[r.length-1])}function O(e,t,n){const r=[],i=[],s=[];let l=0,o=0;const u=[...e];for(;u.length>0;){const e=u[0],a=e.getTextContent().length,c=o;o+a<=t?(r.push(e),l+=a):c>=n?s.push(e):i.push(e),o+=a,u.shift()}return[l,r,i,s]}function E(e,n,r,i){const s=a(i.url,i.attributes);if(1===e.length){let l,o=e[0];0===n?[l,o]=o.splitText(r):[,l,o]=o.splitText(n,r);const u=t.$createTextNode(i.text);return u.setFormat(l.getFormat()),u.setDetail(l.getDetail()),u.setStyle(l.getStyle()),s.append(u),l.replace(s),o}if(e.length>1){const i=e[0];let l,o=i.getTextContent().length;0===n?l=i:[,l]=i.splitText(n);const u=[];let a;for(let t=1;t<e.length;t++){const n=e[t],i=n.getTextContent().length,s=o;if(s<r)if(o+i<=r)u.push(n);else{const[e,t]=n.splitText(r-s);u.push(e),a=t}o+=i}const c=t.$getSelection(),g=c?c.getNodes().find(t.$isTextNode):void 0,d=t.$createTextNode(l.getTextContent());return d.setFormat(l.getFormat()),d.setDetail(l.getDetail()),d.setStyle(l.getStyle()),s.append(d,...u),g&&g===l&&(t.$isRangeSelection(c)?d.select(c.anchor.offset,c.focus.offset):t.$isNodeSelection(c)&&d.select(0,d.getTextContent().length)),l.replace(s),a}}function C(e,n,r){const i=e.getChildren(),s=i.length;for(let n=0;n<s;n++){const s=i[n];if(!t.$isTextNode(s)||!s.isSimpleText())return M(e),void r(null,e.getURL())}const l=e.getTextContent(),o=L(l,n);if(null===o||o.text!==l)return M(e),void r(null,e.getURL());if(!b(e)||!R(e))return M(e),void r(null,e.getURL());const u=e.getURL();if(u!==o.url&&(e.setURL(o.url),r(o.url,u)),o.attributes){const t=e.getRel();t!==o.attributes.rel&&(e.setRel(o.attributes.rel||null),r(o.attributes.rel||null,t));const n=e.getTarget();n!==o.attributes.target&&(e.setTarget(o.attributes.target||null),r(o.attributes.target||null,n))}}function M(e){const t=e.getChildren();for(let n=t.length-1;n>=0;n--)e.insertAfter(t[n]);return e.remove(),t.map((e=>e.getLatest()))}const A={changeHandlers:[],matchers:[]};function D(n,r=A){const{matchers:i,changeHandlers:s}=r,l=(e,t)=>{for(const n of s)n(e,t)};return e.mergeRegister(n.registerNodeTransform(t.TextNode,(e=>{const n=e.getParentOrThrow(),r=e.getPreviousSibling();if(c(n)&&!n.getIsUnlinked())C(n,i,l);else if(!o(n)){if(e.isSimpleText()&&(U(e.getTextContent())||!c(r))){const n=function(e){const n=[e];let r=e.getNextSibling();for(;null!==r&&t.$isTextNode(r)&&r.isSimpleText()&&(n.push(r),!/[\s]/.test(r.getTextContent()));)r=r.getNextSibling();return n}(e);!function(e,t,n){let r=[...e];const i=r.map((e=>e.getTextContent())).join("");let s,l=i,o=0;for(;(s=L(l,t))&&null!==s;){const e=s.index,t=e+s.length;if(v(o+e,o+t,i,r)){const[i,,l,u]=O(r,o+e,o+t),a=E(l,o+e-i,o+t-i,s);r=a?[a,...u]:u,n(s.url,null),o=0}else o+=t;l=l.substring(t)}}(n,i,l)}!function(e,t,n){const r=e.getPreviousSibling(),i=e.getNextSibling(),s=e.getTextContent();var l;!c(r)||r.getIsUnlinked()||U(s)&&(l=s,!(r.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(l):/^\.[a-zA-Z0-9]{1,}/.test(l)))||(r.append(e),C(r,t,n),n(null,r.getURL())),!c(i)||i.getIsUnlinked()||$(s)||(M(i),C(i,t,n),n(null,i.getURL()))}(e,i,l)}})),n.registerCommand(g,(e=>{const n=t.$getSelection();if(null!==e||!t.$isRangeSelection(n))return!1;return n.extract().forEach((e=>{const t=e.getParent();c(t)&&(t.setIsUnlinked(!t.getIsUnlinked()),t.markDirty())})),!1}),t.COMMAND_PRIORITY_LOW))}const P=t.defineExtension({config:A,dependencies:[x],mergeConfig(e,n){const r=t.shallowMergeConfig(e,n);for(const t of["matchers","changeHandlers"]){const i=n[t];Array.isArray(i)&&(r[t]=[...e[t],...i])}return r},name:"@lexical/link/AutoLink",register:D}),I=f;exports.$createAutoLinkNode=a,exports.$createLinkNode=l,exports.$isAutoLinkNode=c,exports.$isLinkNode=o,exports.$toggleLink=f,exports.AutoLinkExtension=P,exports.AutoLinkNode=u,exports.ClickableLinkExtension=k,exports.LinkExtension=x,exports.LinkNode=i,exports.TOGGLE_LINK_COMMAND=g,exports.createLinkMatcherWithRegExp=function(e,t=(e=>e)){return n=>{const r=e.exec(n);return null===r?null:{index:r.index,length:r[0].length,text:r[0],url:t(r[0])}}},exports.formatUrl=p,exports.registerAutoLink=D,exports.registerClickableLink=N,exports.registerLink=m,exports.toggleLink=I;
|
package/LexicalLink.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{addClassNamesToElement as t,isHTMLAnchorElement as e,$findMatchingParent as r}from"@lexical/utils";import{createCommand as n,ElementNode as i,$isRangeSelection as s,$applyNodeReplacement as l,$isElementNode as o,$getSelection as u,$isNodeSelection as a,$normalizeSelection__EXPERIMENTAL as c,$setSelection as _}from"lexical";const h=new Set(["http:","https:","mailto:","sms:","tel:"]);class g extends i{static getType(){return"link"}static clone(t){return new g(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t="",e={},r){super(r);const{target:n=null,rel:i=null,title:s=null}=e;this.__url=t,this.__target=n,this.__rel=i,this.__title=s}createDOM(e){const r=document.createElement("a");return this.updateLinkDOM(null,r,e),t(r,e.theme.link),r}updateLinkDOM(t,r,n){if(e(r)){t&&t.__url===this.__url||(r.href=this.sanitizeUrl(this.__url));for(const e of["target","rel","title"]){const n=`__${e}`,i=this[n];t&&t[n]===i||(i?r[e]=i:r.removeAttribute(e))}}}updateDOM(t,e,r){return this.updateLinkDOM(t,e,r),!1}static importDOM(){return{a:t=>({conversion:f,priority:1})}}static importJSON(t){return d().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setURL(t.url).setRel(t.rel||null).setTarget(t.target||null).setTitle(t.title||null)}sanitizeUrl(t){t=S(t);try{const e=new URL(S(t));if(!h.has(e.protocol))return"about:blank"}catch(e){return t}return t}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),url:this.getURL()}}getURL(){return this.getLatest().__url}setURL(t){const e=this.getWritable();return e.__url=t,e}getTarget(){return this.getLatest().__target}setTarget(t){const e=this.getWritable();return e.__target=t,e}getRel(){return this.getLatest().__rel}setRel(t){const e=this.getWritable();return e.__rel=t,e}getTitle(){return this.getLatest().__title}setTitle(t){const e=this.getWritable();return e.__title=t,e}insertNewAfter(t,e=!0){const r=d(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(r,e),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,e,r){if(!s(e))return!1;const n=e.anchor.getNode(),i=e.focus.getNode();return this.isParentOf(n)&&this.isParentOf(i)&&e.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function f(t){let r=null;if(e(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(r=d(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:r}}function d(t="",e){return l(new g(t,e))}function p(t){return t instanceof g}class m extends g{constructor(t="",e={},r){super(t,e,r),this.__isUnlinked=void 0!==e.isUnlinked&&null!==e.isUnlinked&&e.isUnlinked}static getType(){return"autolink"}static clone(t){return new m(t.__url,{isUnlinked:t.__isUnlinked,rel:t.__rel,target:t.__target,title:t.__title},t.__key)}getIsUnlinked(){return this.__isUnlinked}setIsUnlinked(t){const e=this.getWritable();return e.__isUnlinked=t,e}createDOM(t){return this.__isUnlinked?document.createElement("span"):super.createDOM(t)}updateDOM(t,e,r){return super.updateDOM(t,e,r)||t.__isUnlinked!==this.__isUnlinked}static importJSON(t){return U().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setIsUnlinked(t.isUnlinked||!1)}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),isUnlinked:this.__isUnlinked}}insertNewAfter(t,e=!0){const r=this.getParentOrThrow().insertNewAfter(t,e);if(o(r)){const t=U(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return r.append(t),t}return null}}function U(t="",e){return l(new m(t,e))}function O(t){return t instanceof m}const k=n("TOGGLE_LINK_COMMAND");function N(t,e){if("element"===t.type){const r=t.getNode();o(r)||function(t,...e){const r=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",t);for(const t of e)n.append("v",t);throw r.search=n.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(252);return r.getChildren()[t.offset+e]||null}return null}function v(t,e={}){const{target:n,title:i}=e,l=void 0===e.rel?"noreferrer":e.rel,h=u();if(null===h||!s(h)&&!a(h))return;if(a(h)){const e=h.getNodes();if(0===e.length)return;return void e.forEach((e=>{if(null===t){const t=r(e,(t=>!O(t)&&p(t)));t&&(t.insertBefore(e),0===t.getChildren().length&&t.remove())}else{const i=r(e,(t=>!O(t)&&p(t)));if(i)i.setURL(t),void 0!==n&&i.setTarget(n),void 0!==l&&i.setRel(l);else{const r=d(t,{rel:l,target:n});e.insertBefore(r),r.append(e)}}}))}const g=h.extract();if(null===t)return void g.forEach((t=>{const e=r(t,(t=>!O(t)&&p(t)));if(e){const t=e.getChildren();for(let r=0;r<t.length;r++)e.insertBefore(t[r]);e.remove()}}));const f=new Set,m=e=>{f.has(e.getKey())||(f.add(e.getKey()),e.setURL(t),void 0!==n&&e.setTarget(n),void 0!==l&&e.setRel(l),void 0!==i&&e.setTitle(i))};if(1===g.length){const t=g[0],e=r(t,p);if(null!==e)return m(e)}!function(t){const e=u();if(!s(e))return t();const r=c(e),n=r.isBackward(),i=N(r.anchor,n?-1:0),l=N(r.focus,n?0:-1),o=t();if(i||l){const t=u();if(s(t)){const e=t.clone();if(i){const t=i.getParent();t&&e.anchor.set(t.getKey(),i.getIndexWithinParent()+(n?1:0),"element")}if(l){const t=l.getParent();t&&e.focus.set(t.getKey(),l.getIndexWithinParent()+(n?0:1),"element")}_(c(e))}}}((()=>{let e=null;for(const s of g){if(!s.isAttached())continue;const u=r(s,p);if(u){m(u);continue}if(o(s)){if(!s.isInline())continue;if(p(s)){if(!(O(s)||null!==e&&e.getParentOrThrow().isParentOf(s))){m(s),e=s;continue}for(const t of s.getChildren())s.insertBefore(t);s.remove();continue}}const a=s.getPreviousSibling();p(a)&&a.is(e)?a.append(s):(e=d(t,{rel:l,target:n,title:i}),s.insertAfter(e),e.append(s))}}))}const x=v,L=/^\+?[0-9\s()-]{5,}$/;function S(t){return t.match(/^[a-z][a-z0-9+.-]*:/i)||t.match(/^[/#.]/)?t:t.includes("@")?`mailto:${t}`:L.test(t)?`tel:${t}`:`https://${t}`}export{U as $createAutoLinkNode,d as $createLinkNode,O as $isAutoLinkNode,p as $isLinkNode,v as $toggleLink,m as AutoLinkNode,g as LinkNode,k as TOGGLE_LINK_COMMAND,S as formatUrl,x as toggleLink};
|
|
9
|
+
import{addClassNamesToElement as t,isHTMLAnchorElement as e,$findMatchingParent as n,mergeRegister as r,objectKlassEquals as i}from"@lexical/utils";import{createCommand as l,ElementNode as s,$isRangeSelection as o,$applyNodeReplacement as u,$isElementNode as a,$getSelection as c,$isNodeSelection as g,$normalizeSelection__EXPERIMENTAL as f,$setSelection as d,defineExtension as h,COMMAND_PRIORITY_LOW as _,PASTE_COMMAND as p,safeCast as m,isDOMNode as x,getNearestEditorFromDOMNode as k,$getNearestNodeFromDOMNode as U,shallowMergeConfig as b,TextNode as v,$isTextNode as T,$isLineBreakNode as L,$createTextNode as S}from"lexical";import{namedSignals as O,effect as C}from"@lexical/extension";const N=new Set(["http:","https:","mailto:","sms:","tel:"]);class R extends s{__url;__target;__rel;__title;static getType(){return"link"}static clone(t){return new R(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t="",e={},n){super(n);const{target:r=null,rel:i=null,title:l=null}=e;this.__url=t,this.__target=r,this.__rel=i,this.__title=l}createDOM(e){const n=document.createElement("a");return this.updateLinkDOM(null,n,e),t(n,e.theme.link),n}updateLinkDOM(t,n,r){if(e(n)){t&&t.__url===this.__url||(n.href=this.sanitizeUrl(this.__url));for(const e of["target","rel","title"]){const r=`__${e}`,i=this[r];t&&t[r]===i||(i?n[e]=i:n.removeAttribute(e))}}}updateDOM(t,e,n){return this.updateLinkDOM(t,e,n),!1}static importDOM(){return{a:t=>({conversion:D,priority:1})}}static importJSON(t){return y().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setURL(t.url).setRel(t.rel||null).setTarget(t.target||null).setTitle(t.title||null)}sanitizeUrl(t){t=F(t);try{const e=new URL(F(t));if(!N.has(e.protocol))return"about:blank"}catch(e){return t}return t}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),url:this.getURL()}}getURL(){return this.getLatest().__url}setURL(t){const e=this.getWritable();return e.__url=t,e}getTarget(){return this.getLatest().__target}setTarget(t){const e=this.getWritable();return e.__target=t,e}getRel(){return this.getLatest().__rel}setRel(t){const e=this.getWritable();return e.__rel=t,e}getTitle(){return this.getLatest().__title}setTitle(t){const e=this.getWritable();return e.__title=t,e}insertNewAfter(t,e=!0){const n=y(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(n,e),n}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,e,n){if(!o(e))return!1;const r=e.anchor.getNode(),i=e.focus.getNode();return this.isParentOf(r)&&this.isParentOf(i)&&e.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function D(t){let n=null;if(e(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(n=y(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:n}}function y(t="",e){return u(new R(t,e))}function w(t){return t instanceof R}class A extends R{__isUnlinked;constructor(t="",e={},n){super(t,e,n),this.__isUnlinked=void 0!==e.isUnlinked&&null!==e.isUnlinked&&e.isUnlinked}static getType(){return"autolink"}static clone(t){return new A(t.__url,{isUnlinked:t.__isUnlinked,rel:t.__rel,target:t.__target,title:t.__title},t.__key)}getIsUnlinked(){return this.__isUnlinked}setIsUnlinked(t){const e=this.getWritable();return e.__isUnlinked=t,e}createDOM(t){return this.__isUnlinked?document.createElement("span"):super.createDOM(t)}updateDOM(t,e,n){return super.updateDOM(t,e,n)||t.__isUnlinked!==this.__isUnlinked}static importJSON(t){return I().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setIsUnlinked(t.isUnlinked||!1)}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),isUnlinked:this.__isUnlinked}}insertNewAfter(t,e=!0){const n=this.getParentOrThrow().insertNewAfter(t,e);if(a(n)){const t=I(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return n.append(t),t}return null}}function I(t="",e){return u(new A(t,e))}function E(t){return t instanceof A}const P=l("TOGGLE_LINK_COMMAND");function M(t,e){if("element"===t.type){const n=t.getNode();a(n)||function(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(252);return n.getChildren()[t.offset+e]||null}return null}function J(t,e={}){let r;if(t&&"object"==typeof t){const{url:n,...i}=t;r=n,e={...i,...e}}else r=t;const{target:i,title:l}=e,s=void 0===e.rel?"noreferrer":e.rel,u=c();if(null===u||!o(u)&&!g(u))return;if(g(u)){const t=u.getNodes();if(0===t.length)return;return void t.forEach((t=>{if(null===r){const e=n(t,(t=>!E(t)&&w(t)));e&&(e.insertBefore(t),0===e.getChildren().length&&e.remove())}else{const e=n(t,(t=>!E(t)&&w(t)));if(e)e.setURL(r),void 0!==i&&e.setTarget(i),void 0!==s&&e.setRel(s);else{const e=y(r,{rel:s,target:i});t.insertBefore(e),e.append(t)}}}))}const h=u.extract();if(null===r)return void h.forEach((t=>{const e=n(t,(t=>!E(t)&&w(t)));if(e){const t=e.getChildren();for(let n=0;n<t.length;n++)e.insertBefore(t[n]);e.remove()}}));const _=new Set,p=t=>{_.has(t.getKey())||(_.add(t.getKey()),t.setURL(r),void 0!==i&&t.setTarget(i),void 0!==s&&t.setRel(s),void 0!==l&&t.setTitle(l))};if(1===h.length){const t=h[0],e=n(t,w);if(null!==e)return p(e)}!function(t){const e=c();if(!o(e))return t();const n=f(e),r=n.isBackward(),i=M(n.anchor,r?-1:0),l=M(n.focus,r?0:-1),s=t();if(i||l){const t=c();if(o(t)){const e=t.clone();if(i){const t=i.getParent();t&&e.anchor.set(t.getKey(),i.getIndexWithinParent()+(r?1:0),"element")}if(l){const t=l.getParent();t&&e.focus.set(t.getKey(),l.getIndexWithinParent()+(r?0:1),"element")}d(f(e))}}}((()=>{let t=null;for(const e of h){if(!e.isAttached())continue;const o=n(e,w);if(o){p(o);continue}if(a(e)){if(!e.isInline())continue;if(w(e)){if(!(E(e)||null!==t&&t.getParentOrThrow().isParentOf(e))){p(e),t=e;continue}for(const t of e.getChildren())e.insertBefore(t);e.remove();continue}}const u=e.getPreviousSibling();w(u)&&u.is(t)?u.append(e):(t=y(r,{rel:s,target:i,title:l}),e.insertAfter(t),t.append(e))}}))}const W=/^\+?[0-9\s()-]{5,}$/;function F(t){return t.match(/^[a-z][a-z0-9+.-]*:/i)||t.match(/^[/#.]/)?t:t.includes("@")?`mailto:${t}`:W.test(t)?`tel:${t}`:`https://${t}`}function z(t,e){return r(C((()=>t.registerCommand(P,(t=>{const n=e.validateUrl.peek(),r=e.attributes.peek();if(null===t)return J(null),!0;if("string"==typeof t)return!(void 0!==n&&!n(t))&&(J(t,r),!0);{const{url:e,target:n,rel:i,title:l}=t;return J(e,{...r,rel:i,target:n,title:l}),!0}}),_))),C((()=>{const n=e.validateUrl.value;if(!n)return;const r=e.attributes.value;return t.registerCommand(p,(e=>{const l=c();if(!o(l)||l.isCollapsed()||!i(e,ClipboardEvent))return!1;if(null===e.clipboardData)return!1;const s=e.clipboardData.getData("text");return!!n(s)&&(!l.getNodes().some((t=>a(t)))&&(t.dispatchCommand(P,{...r,url:s}),e.preventDefault(),!0))}),_)})))}const B=h({build:(t,e,n)=>O(e),config:{attributes:void 0,validateUrl:void 0},name:"@lexical/link/Link",nodes:[R],register:(t,e,n)=>z(t,n.getOutput())});function K(t,r,i={}){const l=i=>{const l=i.target;if(!x(l))return;const s=k(l);if(null===s)return;let u=null,g=null;if(s.update((()=>{const t=U(l);if(null!==t){const i=n(t,a);if(!r.disabled.peek())if(w(i))u=i.sanitizeUrl(i.getURL()),g=i.getTarget();else{const t=function(t,e){let n=t;for(;null!=n;){if(e(n))return n;n=n.parentNode}return null}(l,e);null!==t&&(u=t.href,g=t.target)}}})),null===u||""===u)return;const f=t.getEditorState().read(c);if(o(f)&&!f.isCollapsed())return void i.preventDefault();const d="auxclick"===i.type&&1===i.button;window.open(u,r.newTab.peek()||d||i.metaKey||i.ctrlKey||"_blank"===g?"_blank":"_self"),i.preventDefault()},s=t=>{1===t.button&&l(t)};return t.registerRootListener(((t,e)=>{null!==e&&(e.removeEventListener("click",l),e.removeEventListener("mouseup",s)),null!==t&&(t.addEventListener("click",l,i),t.addEventListener("mouseup",s,i))}))}const $=h({build:(t,e,n)=>O(e),config:m({disabled:!1,newTab:!1}),dependencies:[B],name:"@lexical/link/ClickableLink",register:(t,e,n)=>K(t,n.getOutput())});function H(t,e=(t=>t)){return n=>{const r=t.exec(n);return null===r?null:{index:r.index,length:r[0].length,text:r[0],url:e(r[0])}}}function j(t,e){for(let n=0;n<e.length;n++){const r=e[n](t);if(r)return r}return null}const G=/[.,;\s]/;function Z(t){return G.test(t)}function q(t){return Z(t[t.length-1])}function Q(t){return Z(t[0])}function V(t){let e=t.getPreviousSibling();return a(e)&&(e=e.getLastDescendant()),null===e||L(e)||T(e)&&q(e.getTextContent())}function X(t){let e=t.getNextSibling();return a(e)&&(e=e.getFirstDescendant()),null===e||L(e)||T(e)&&Q(e.getTextContent())}function Y(t,e,n,r){if(!(t>0?Z(n[t-1]):V(r[0])))return!1;return e<n.length?Z(n[e]):X(r[r.length-1])}function tt(t,e,n){const r=[],i=[],l=[];let s=0,o=0;const u=[...t];for(;u.length>0;){const t=u[0],a=t.getTextContent().length,c=o;o+a<=e?(r.push(t),s+=a):c>=n?l.push(t):i.push(t),o+=a,u.shift()}return[s,r,i,l]}function et(t,e,n,r){const i=I(r.url,r.attributes);if(1===t.length){let l,s=t[0];0===e?[l,s]=s.splitText(n):[,l,s]=s.splitText(e,n);const o=S(r.text);return o.setFormat(l.getFormat()),o.setDetail(l.getDetail()),o.setStyle(l.getStyle()),i.append(o),l.replace(i),s}if(t.length>1){const r=t[0];let l,s=r.getTextContent().length;0===e?l=r:[,l]=r.splitText(e);const u=[];let a;for(let e=1;e<t.length;e++){const r=t[e],i=r.getTextContent().length,l=s;if(l<n)if(s+i<=n)u.push(r);else{const[t,e]=r.splitText(n-l);u.push(t),a=e}s+=i}const f=c(),d=f?f.getNodes().find(T):void 0,h=S(l.getTextContent());return h.setFormat(l.getFormat()),h.setDetail(l.getDetail()),h.setStyle(l.getStyle()),i.append(h,...u),d&&d===l&&(o(f)?h.select(f.anchor.offset,f.focus.offset):g(f)&&h.select(0,h.getTextContent().length)),l.replace(i),a}}function nt(t,e,n){const r=t.getChildren(),i=r.length;for(let e=0;e<i;e++){const i=r[e];if(!T(i)||!i.isSimpleText())return rt(t),void n(null,t.getURL())}const l=t.getTextContent(),s=j(l,e);if(null===s||s.text!==l)return rt(t),void n(null,t.getURL());if(!V(t)||!X(t))return rt(t),void n(null,t.getURL());const o=t.getURL();if(o!==s.url&&(t.setURL(s.url),n(s.url,o)),s.attributes){const e=t.getRel();e!==s.attributes.rel&&(t.setRel(s.attributes.rel||null),n(s.attributes.rel||null,e));const r=t.getTarget();r!==s.attributes.target&&(t.setTarget(s.attributes.target||null),n(s.attributes.target||null,r))}}function rt(t){const e=t.getChildren();for(let n=e.length-1;n>=0;n--)t.insertAfter(e[n]);return t.remove(),e.map((t=>t.getLatest()))}const it={changeHandlers:[],matchers:[]};function lt(t,e=it){const{matchers:n,changeHandlers:i}=e,l=(t,e)=>{for(const n of i)n(t,e)};return r(t.registerNodeTransform(v,(t=>{const e=t.getParentOrThrow(),r=t.getPreviousSibling();if(E(e)&&!e.getIsUnlinked())nt(e,n,l);else if(!w(e)){if(t.isSimpleText()&&(Q(t.getTextContent())||!E(r))){const e=function(t){const e=[t];let n=t.getNextSibling();for(;null!==n&&T(n)&&n.isSimpleText()&&(e.push(n),!/[\s]/.test(n.getTextContent()));)n=n.getNextSibling();return e}(t);!function(t,e,n){let r=[...t];const i=r.map((t=>t.getTextContent())).join("");let l,s=i,o=0;for(;(l=j(s,e))&&null!==l;){const t=l.index,e=t+l.length;if(Y(o+t,o+e,i,r)){const[i,,s,u]=tt(r,o+t,o+e),a=et(s,o+t-i,o+e-i,l);r=a?[a,...u]:u,n(l.url,null),o=0}else o+=e;s=s.substring(e)}}(e,n,l)}!function(t,e,n){const r=t.getPreviousSibling(),i=t.getNextSibling(),l=t.getTextContent();var s;!E(r)||r.getIsUnlinked()||Q(l)&&(s=l,!(r.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(s):/^\.[a-zA-Z0-9]{1,}/.test(s)))||(r.append(t),nt(r,e,n),n(null,r.getURL())),!E(i)||i.getIsUnlinked()||q(l)||(rt(i),nt(i,e,n),n(null,i.getURL()))}(t,n,l)}})),t.registerCommand(P,(t=>{const e=c();if(null!==t||!o(e))return!1;return e.extract().forEach((t=>{const e=t.getParent();E(e)&&(e.setIsUnlinked(!e.getIsUnlinked()),e.markDirty())})),!1}),_))}const st=h({config:it,dependencies:[B],mergeConfig(t,e){const n=b(t,e);for(const r of["matchers","changeHandlers"]){const i=e[r];Array.isArray(i)&&(n[r]=[...t[r],...i])}return n},name:"@lexical/link/AutoLink",register:lt}),ot=J;export{I as $createAutoLinkNode,y as $createLinkNode,E as $isAutoLinkNode,w as $isLinkNode,J as $toggleLink,st as AutoLinkExtension,A as AutoLinkNode,$ as ClickableLinkExtension,B as LinkExtension,R as LinkNode,P as TOGGLE_LINK_COMMAND,H as createLinkMatcherWithRegExp,F as formatUrl,lt as registerAutoLink,K as registerClickableLink,z as registerLink,ot as toggleLink};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { NamedSignalsOutput } from '@lexical/extension';
|
|
9
|
+
import { LexicalEditor } from 'lexical';
|
|
10
|
+
import { LinkAttributes } from './LexicalLinkNode';
|
|
11
|
+
export interface LinkConfig {
|
|
12
|
+
/**
|
|
13
|
+
* If this function is specified a {@link PASTE_COMMAND}
|
|
14
|
+
* listener will be registered to wrap selected nodes
|
|
15
|
+
* when a URL is pasted and `validateUrl(url)` returns true.
|
|
16
|
+
* The default of `undefined` will not register this listener.
|
|
17
|
+
*
|
|
18
|
+
* In the implementation of {@link TOGGLE_LINK_COMMAND}
|
|
19
|
+
* it will reject URLs that return false when specified.
|
|
20
|
+
* The default of `undefined` will always accept URLs.
|
|
21
|
+
*/
|
|
22
|
+
validateUrl: undefined | ((url: string) => boolean);
|
|
23
|
+
/**
|
|
24
|
+
* The default anchor tag attributes to use for
|
|
25
|
+
* {@link TOGGLE_LINK_COMMAND}
|
|
26
|
+
*/
|
|
27
|
+
attributes: undefined | LinkAttributes;
|
|
28
|
+
}
|
|
29
|
+
/** @internal */
|
|
30
|
+
export declare function registerLink(editor: LexicalEditor, stores: NamedSignalsOutput<LinkConfig>): () => void;
|
|
31
|
+
/**
|
|
32
|
+
* Provides {@link LinkNode}, an implementation of
|
|
33
|
+
* {@link TOGGLE_LINK_COMMAND}, and a {@link PASTE_COMMAND}
|
|
34
|
+
* listener to wrap selected nodes in a link when a
|
|
35
|
+
* URL is pasted and `validateUrl` is defined.
|
|
36
|
+
*/
|
|
37
|
+
export declare const LinkExtension: import("lexical").LexicalExtension<LinkConfig, "@lexical/link/Link", NamedSignalsOutput<LinkConfig>, unknown>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { BaseSelection, DOMConversionMap, EditorConfig, LexicalCommand, LexicalNode, LexicalUpdateJSON, NodeKey, RangeSelection, SerializedElementNode } from 'lexical';
|
|
9
|
+
import { ElementNode, Spread } from 'lexical';
|
|
10
|
+
export type LinkAttributes = {
|
|
11
|
+
rel?: null | string;
|
|
12
|
+
target?: null | string;
|
|
13
|
+
title?: null | string;
|
|
14
|
+
};
|
|
15
|
+
export type AutoLinkAttributes = Partial<Spread<LinkAttributes, {
|
|
16
|
+
isUnlinked?: boolean;
|
|
17
|
+
}>>;
|
|
18
|
+
export type SerializedLinkNode = Spread<{
|
|
19
|
+
url: string;
|
|
20
|
+
}, Spread<LinkAttributes, SerializedElementNode>>;
|
|
21
|
+
type LinkHTMLElementType = HTMLAnchorElement | HTMLSpanElement;
|
|
22
|
+
/** @noInheritDoc */
|
|
23
|
+
export declare class LinkNode extends ElementNode {
|
|
24
|
+
/** @internal */
|
|
25
|
+
__url: string;
|
|
26
|
+
/** @internal */
|
|
27
|
+
__target: null | string;
|
|
28
|
+
/** @internal */
|
|
29
|
+
__rel: null | string;
|
|
30
|
+
/** @internal */
|
|
31
|
+
__title: null | string;
|
|
32
|
+
static getType(): string;
|
|
33
|
+
static clone(node: LinkNode): LinkNode;
|
|
34
|
+
constructor(url?: string, attributes?: LinkAttributes, key?: NodeKey);
|
|
35
|
+
createDOM(config: EditorConfig): LinkHTMLElementType;
|
|
36
|
+
updateLinkDOM(prevNode: this | null, anchor: LinkHTMLElementType, config: EditorConfig): void;
|
|
37
|
+
updateDOM(prevNode: this, anchor: LinkHTMLElementType, config: EditorConfig): boolean;
|
|
38
|
+
static importDOM(): DOMConversionMap | null;
|
|
39
|
+
static importJSON(serializedNode: SerializedLinkNode): LinkNode;
|
|
40
|
+
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedLinkNode>): this;
|
|
41
|
+
sanitizeUrl(url: string): string;
|
|
42
|
+
exportJSON(): SerializedLinkNode | SerializedAutoLinkNode;
|
|
43
|
+
getURL(): string;
|
|
44
|
+
setURL(url: string): this;
|
|
45
|
+
getTarget(): null | string;
|
|
46
|
+
setTarget(target: null | string): this;
|
|
47
|
+
getRel(): null | string;
|
|
48
|
+
setRel(rel: null | string): this;
|
|
49
|
+
getTitle(): null | string;
|
|
50
|
+
setTitle(title: null | string): this;
|
|
51
|
+
insertNewAfter(_: RangeSelection, restoreSelection?: boolean): null | ElementNode;
|
|
52
|
+
canInsertTextBefore(): false;
|
|
53
|
+
canInsertTextAfter(): false;
|
|
54
|
+
canBeEmpty(): false;
|
|
55
|
+
isInline(): true;
|
|
56
|
+
extractWithChild(child: LexicalNode, selection: BaseSelection, destination: 'clone' | 'html'): boolean;
|
|
57
|
+
isEmailURI(): boolean;
|
|
58
|
+
isWebSiteURI(): boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Takes a URL and creates a LinkNode.
|
|
62
|
+
* @param url - The URL the LinkNode should direct to.
|
|
63
|
+
* @param attributes - Optional HTML a tag attributes \\{ target, rel, title \\}
|
|
64
|
+
* @returns The LinkNode.
|
|
65
|
+
*/
|
|
66
|
+
export declare function $createLinkNode(url?: string, attributes?: LinkAttributes): LinkNode;
|
|
67
|
+
/**
|
|
68
|
+
* Determines if node is a LinkNode.
|
|
69
|
+
* @param node - The node to be checked.
|
|
70
|
+
* @returns true if node is a LinkNode, false otherwise.
|
|
71
|
+
*/
|
|
72
|
+
export declare function $isLinkNode(node: LexicalNode | null | undefined): node is LinkNode;
|
|
73
|
+
export type SerializedAutoLinkNode = Spread<{
|
|
74
|
+
isUnlinked: boolean;
|
|
75
|
+
}, SerializedLinkNode>;
|
|
76
|
+
export declare class AutoLinkNode extends LinkNode {
|
|
77
|
+
/** @internal */
|
|
78
|
+
/** Indicates whether the autolink was ever unlinked. **/
|
|
79
|
+
__isUnlinked: boolean;
|
|
80
|
+
constructor(url?: string, attributes?: AutoLinkAttributes, key?: NodeKey);
|
|
81
|
+
static getType(): string;
|
|
82
|
+
static clone(node: AutoLinkNode): AutoLinkNode;
|
|
83
|
+
getIsUnlinked(): boolean;
|
|
84
|
+
setIsUnlinked(value: boolean): this;
|
|
85
|
+
createDOM(config: EditorConfig): LinkHTMLElementType;
|
|
86
|
+
updateDOM(prevNode: this, anchor: LinkHTMLElementType, config: EditorConfig): boolean;
|
|
87
|
+
static importJSON(serializedNode: SerializedAutoLinkNode): AutoLinkNode;
|
|
88
|
+
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedAutoLinkNode>): this;
|
|
89
|
+
static importDOM(): null;
|
|
90
|
+
exportJSON(): SerializedAutoLinkNode;
|
|
91
|
+
insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): null | ElementNode;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Takes a URL and creates an AutoLinkNode. AutoLinkNodes are generally automatically generated
|
|
95
|
+
* during typing, which is especially useful when a button to generate a LinkNode is not practical.
|
|
96
|
+
* @param url - The URL the LinkNode should direct to.
|
|
97
|
+
* @param attributes - Optional HTML a tag attributes. \\{ target, rel, title \\}
|
|
98
|
+
* @returns The LinkNode.
|
|
99
|
+
*/
|
|
100
|
+
export declare function $createAutoLinkNode(url?: string, attributes?: AutoLinkAttributes): AutoLinkNode;
|
|
101
|
+
/**
|
|
102
|
+
* Determines if node is an AutoLinkNode.
|
|
103
|
+
* @param node - The node to be checked.
|
|
104
|
+
* @returns true if node is an AutoLinkNode, false otherwise.
|
|
105
|
+
*/
|
|
106
|
+
export declare function $isAutoLinkNode(node: LexicalNode | null | undefined): node is AutoLinkNode;
|
|
107
|
+
export declare const TOGGLE_LINK_COMMAND: LexicalCommand<string | ({
|
|
108
|
+
url: string;
|
|
109
|
+
} & LinkAttributes) | null>;
|
|
110
|
+
/**
|
|
111
|
+
* Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
|
|
112
|
+
* but saves any children and brings them up to the parent node.
|
|
113
|
+
* @param urlOrAttributes - The URL the link directs to, or an attributes object with an url property
|
|
114
|
+
* @param attributes - Optional HTML a tag attributes. \\{ target, rel, title \\}
|
|
115
|
+
*/
|
|
116
|
+
export declare function $toggleLink(urlOrAttributes: null | string | (LinkAttributes & {
|
|
117
|
+
url: null | string;
|
|
118
|
+
}), attributes?: LinkAttributes): void;
|
|
119
|
+
/**
|
|
120
|
+
* Formats a URL string by adding appropriate protocol if missing
|
|
121
|
+
*
|
|
122
|
+
* @param url - URL to format
|
|
123
|
+
* @returns Formatted URL with appropriate protocol
|
|
124
|
+
*/
|
|
125
|
+
export declare function formatUrl(url: string): string;
|
|
126
|
+
export {};
|
package/index.d.ts
CHANGED
|
@@ -5,122 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
title?: null | string;
|
|
14
|
-
};
|
|
15
|
-
export type AutoLinkAttributes = Partial<Spread<LinkAttributes, {
|
|
16
|
-
isUnlinked?: boolean;
|
|
17
|
-
}>>;
|
|
18
|
-
export type SerializedLinkNode = Spread<{
|
|
19
|
-
url: string;
|
|
20
|
-
}, Spread<LinkAttributes, SerializedElementNode>>;
|
|
21
|
-
type LinkHTMLElementType = HTMLAnchorElement | HTMLSpanElement;
|
|
22
|
-
/** @noInheritDoc */
|
|
23
|
-
export declare class LinkNode extends ElementNode {
|
|
24
|
-
/** @internal */
|
|
25
|
-
__url: string;
|
|
26
|
-
/** @internal */
|
|
27
|
-
__target: null | string;
|
|
28
|
-
/** @internal */
|
|
29
|
-
__rel: null | string;
|
|
30
|
-
/** @internal */
|
|
31
|
-
__title: null | string;
|
|
32
|
-
static getType(): string;
|
|
33
|
-
static clone(node: LinkNode): LinkNode;
|
|
34
|
-
constructor(url?: string, attributes?: LinkAttributes, key?: NodeKey);
|
|
35
|
-
createDOM(config: EditorConfig): LinkHTMLElementType;
|
|
36
|
-
updateLinkDOM(prevNode: this | null, anchor: LinkHTMLElementType, config: EditorConfig): void;
|
|
37
|
-
updateDOM(prevNode: this, anchor: LinkHTMLElementType, config: EditorConfig): boolean;
|
|
38
|
-
static importDOM(): DOMConversionMap | null;
|
|
39
|
-
static importJSON(serializedNode: SerializedLinkNode): LinkNode;
|
|
40
|
-
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedLinkNode>): this;
|
|
41
|
-
sanitizeUrl(url: string): string;
|
|
42
|
-
exportJSON(): SerializedLinkNode | SerializedAutoLinkNode;
|
|
43
|
-
getURL(): string;
|
|
44
|
-
setURL(url: string): this;
|
|
45
|
-
getTarget(): null | string;
|
|
46
|
-
setTarget(target: null | string): this;
|
|
47
|
-
getRel(): null | string;
|
|
48
|
-
setRel(rel: null | string): this;
|
|
49
|
-
getTitle(): null | string;
|
|
50
|
-
setTitle(title: null | string): this;
|
|
51
|
-
insertNewAfter(_: RangeSelection, restoreSelection?: boolean): null | ElementNode;
|
|
52
|
-
canInsertTextBefore(): false;
|
|
53
|
-
canInsertTextAfter(): false;
|
|
54
|
-
canBeEmpty(): false;
|
|
55
|
-
isInline(): true;
|
|
56
|
-
extractWithChild(child: LexicalNode, selection: BaseSelection, destination: 'clone' | 'html'): boolean;
|
|
57
|
-
isEmailURI(): boolean;
|
|
58
|
-
isWebSiteURI(): boolean;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Takes a URL and creates a LinkNode.
|
|
62
|
-
* @param url - The URL the LinkNode should direct to.
|
|
63
|
-
* @param attributes - Optional HTML a tag attributes \\{ target, rel, title \\}
|
|
64
|
-
* @returns The LinkNode.
|
|
65
|
-
*/
|
|
66
|
-
export declare function $createLinkNode(url?: string, attributes?: LinkAttributes): LinkNode;
|
|
67
|
-
/**
|
|
68
|
-
* Determines if node is a LinkNode.
|
|
69
|
-
* @param node - The node to be checked.
|
|
70
|
-
* @returns true if node is a LinkNode, false otherwise.
|
|
71
|
-
*/
|
|
72
|
-
export declare function $isLinkNode(node: LexicalNode | null | undefined): node is LinkNode;
|
|
73
|
-
export type SerializedAutoLinkNode = Spread<{
|
|
74
|
-
isUnlinked: boolean;
|
|
75
|
-
}, SerializedLinkNode>;
|
|
76
|
-
export declare class AutoLinkNode extends LinkNode {
|
|
77
|
-
/** @internal */
|
|
78
|
-
/** Indicates whether the autolink was ever unlinked. **/
|
|
79
|
-
__isUnlinked: boolean;
|
|
80
|
-
constructor(url?: string, attributes?: AutoLinkAttributes, key?: NodeKey);
|
|
81
|
-
static getType(): string;
|
|
82
|
-
static clone(node: AutoLinkNode): AutoLinkNode;
|
|
83
|
-
getIsUnlinked(): boolean;
|
|
84
|
-
setIsUnlinked(value: boolean): this;
|
|
85
|
-
createDOM(config: EditorConfig): LinkHTMLElementType;
|
|
86
|
-
updateDOM(prevNode: this, anchor: LinkHTMLElementType, config: EditorConfig): boolean;
|
|
87
|
-
static importJSON(serializedNode: SerializedAutoLinkNode): AutoLinkNode;
|
|
88
|
-
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedAutoLinkNode>): this;
|
|
89
|
-
static importDOM(): null;
|
|
90
|
-
exportJSON(): SerializedAutoLinkNode;
|
|
91
|
-
insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): null | ElementNode;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Takes a URL and creates an AutoLinkNode. AutoLinkNodes are generally automatically generated
|
|
95
|
-
* during typing, which is especially useful when a button to generate a LinkNode is not practical.
|
|
96
|
-
* @param url - The URL the LinkNode should direct to.
|
|
97
|
-
* @param attributes - Optional HTML a tag attributes. \\{ target, rel, title \\}
|
|
98
|
-
* @returns The LinkNode.
|
|
99
|
-
*/
|
|
100
|
-
export declare function $createAutoLinkNode(url?: string, attributes?: AutoLinkAttributes): AutoLinkNode;
|
|
101
|
-
/**
|
|
102
|
-
* Determines if node is an AutoLinkNode.
|
|
103
|
-
* @param node - The node to be checked.
|
|
104
|
-
* @returns true if node is an AutoLinkNode, false otherwise.
|
|
105
|
-
*/
|
|
106
|
-
export declare function $isAutoLinkNode(node: LexicalNode | null | undefined): node is AutoLinkNode;
|
|
107
|
-
export declare const TOGGLE_LINK_COMMAND: LexicalCommand<string | ({
|
|
108
|
-
url: string;
|
|
109
|
-
} & LinkAttributes) | null>;
|
|
110
|
-
/**
|
|
111
|
-
* Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
|
|
112
|
-
* but saves any children and brings them up to the parent node.
|
|
113
|
-
* @param url - The URL the link directs to.
|
|
114
|
-
* @param attributes - Optional HTML a tag attributes. \\{ target, rel, title \\}
|
|
115
|
-
*/
|
|
116
|
-
export declare function $toggleLink(url: null | string, attributes?: LinkAttributes): void;
|
|
8
|
+
import { $toggleLink } from './LexicalLinkNode';
|
|
9
|
+
export { type ClickableLinkConfig, ClickableLinkExtension, registerClickableLink, } from './ClickableLinkExtension';
|
|
10
|
+
export { type AutoLinkConfig, AutoLinkExtension, type ChangeHandler, createLinkMatcherWithRegExp, type LinkMatcher, registerAutoLink, } from './LexicalAutoLinkExtension';
|
|
11
|
+
export { LinkExtension, registerLink } from './LexicalLinkExtension';
|
|
12
|
+
export { $createAutoLinkNode, $createLinkNode, $isAutoLinkNode, $isLinkNode, $toggleLink, type AutoLinkAttributes, AutoLinkNode, formatUrl, type LinkAttributes, LinkNode, type SerializedAutoLinkNode, type SerializedLinkNode, TOGGLE_LINK_COMMAND, } from './LexicalLinkNode';
|
|
117
13
|
/** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
|
|
118
14
|
export declare const toggleLink: typeof $toggleLink;
|
|
119
|
-
/**
|
|
120
|
-
* Formats a URL string by adding appropriate protocol if missing
|
|
121
|
-
*
|
|
122
|
-
* @param url - URL to format
|
|
123
|
-
* @returns Formatted URL with appropriate protocol
|
|
124
|
-
*/
|
|
125
|
-
export declare function formatUrl(url: string): string;
|
|
126
|
-
export {};
|
package/package.json
CHANGED
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
"link"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.36.0",
|
|
12
12
|
"main": "LexicalLink.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/
|
|
16
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/extension": "0.36.0",
|
|
16
|
+
"@lexical/utils": "0.36.0",
|
|
17
|
+
"lexical": "0.36.0"
|
|
17
18
|
},
|
|
18
19
|
"repository": {
|
|
19
20
|
"type": "git",
|