@lexical/link 0.35.1-nightly.20250915.0 → 0.35.1-nightly.20250916.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.
@@ -463,7 +463,7 @@ function $toggleLink(url, attributes = {}) {
463
463
  const firstNode = nodes[0];
464
464
  // if the first node is a LinkNode or if its
465
465
  // parent is a LinkNode, we update the URL, target and rel.
466
- const linkNode = $getAncestor(firstNode, $isLinkNode);
466
+ const linkNode = utils.$findMatchingParent(firstNode, $isLinkNode);
467
467
  if (linkNode !== null) {
468
468
  return updateLinkNode(linkNode);
469
469
  }
@@ -474,7 +474,7 @@ function $toggleLink(url, attributes = {}) {
474
474
  if (!node.isAttached()) {
475
475
  continue;
476
476
  }
477
- const parentLinkNode = $getAncestor(node, $isLinkNode);
477
+ const parentLinkNode = utils.$findMatchingParent(node, $isLinkNode);
478
478
  if (parentLinkNode) {
479
479
  updateLinkNode(parentLinkNode);
480
480
  continue;
@@ -518,13 +518,6 @@ function $toggleLink(url, attributes = {}) {
518
518
  }
519
519
  /** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
520
520
  const toggleLink = $toggleLink;
521
- function $getAncestor(node, predicate) {
522
- let parent = node;
523
- while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
524
- parent = parent.getParentOrThrow();
525
- }
526
- return predicate(parent) ? parent : null;
527
- }
528
521
  const PHONE_NUMBER_REGEX = /^\+?[0-9\s()-]{5,}$/;
529
522
 
530
523
  /**
@@ -461,7 +461,7 @@ function $toggleLink(url, attributes = {}) {
461
461
  const firstNode = nodes[0];
462
462
  // if the first node is a LinkNode or if its
463
463
  // parent is a LinkNode, we update the URL, target and rel.
464
- const linkNode = $getAncestor(firstNode, $isLinkNode);
464
+ const linkNode = $findMatchingParent(firstNode, $isLinkNode);
465
465
  if (linkNode !== null) {
466
466
  return updateLinkNode(linkNode);
467
467
  }
@@ -472,7 +472,7 @@ function $toggleLink(url, attributes = {}) {
472
472
  if (!node.isAttached()) {
473
473
  continue;
474
474
  }
475
- const parentLinkNode = $getAncestor(node, $isLinkNode);
475
+ const parentLinkNode = $findMatchingParent(node, $isLinkNode);
476
476
  if (parentLinkNode) {
477
477
  updateLinkNode(parentLinkNode);
478
478
  continue;
@@ -516,13 +516,6 @@ function $toggleLink(url, attributes = {}) {
516
516
  }
517
517
  /** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
518
518
  const toggleLink = $toggleLink;
519
- function $getAncestor(node, predicate) {
520
- let parent = node;
521
- while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
522
- parent = parent.getParentOrThrow();
523
- }
524
- return predicate(parent) ? parent : null;
525
- }
526
519
  const PHONE_NUMBER_REGEX = /^\+?[0-9\s()-]{5,}$/;
527
520
 
528
521
  /**
@@ -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=p(t);try{const e=new URL(p(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 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,n=!0){const r=this.getParentOrThrow().insertNewAfter(t,n);if(e.$isElementNode(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="",n){return e.$applyNodeReplacement(new o(t,n))}function a(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,u=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=>!a(t)&&l(t)));n&&(n.insertBefore(e),0===n.getChildren().length&&n.remove())}else{const r=t.$findMatchingParent(e,(t=>!a(t)&&l(t)));if(r)r.setURL(n),void 0!==i&&r.setTarget(i),void 0!==u&&r.setRel(u);else{const t=s(n,{rel:u,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=>!a(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,f=t=>{g.has(t.getKey())||(g.add(t.getKey()),t.setURL(n),void 0!==i&&t.setTarget(i),void 0!==u&&t.setRel(u),void 0!==o&&t.setTitle(o))};if(1===d.length){const t=h(d[0],l);if(null!==t)return f(t)}!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 t=null;for(const r of d){if(!r.isAttached())continue;const c=h(r,l);if(c){f(c);continue}if(e.$isElementNode(r)){if(!r.isInline())continue;if(l(r)){if(!(a(r)||null!==t&&t.getParentOrThrow().isParentOf(r))){f(r),t=r;continue}for(const t of r.getChildren())r.insertBefore(t);r.remove();continue}}const _=r.getPreviousSibling();l(_)&&_.is(t)?_.append(r):(t=s(n,{rel:u,target:i,title:o}),r.insertAfter(t),t.append(r))}}))}const g=d;function h(t,e){let n=t;for(;null!==n&&null!==n.getParent()&&!e(n);)n=n.getParentOrThrow();return e(n)?n:null}const f=/^\+?[0-9\s()-]{5,}$/;function p(t){return t.match(/^[a-z][a-z0-9+.-]*:/i)||t.match(/^[/#.]/)?t:t.includes("@")?`mailto:${t}`:f.test(t)?`tel:${t}`:`https://${t}`}exports.$createAutoLinkNode=u,exports.$createLinkNode=s,exports.$isAutoLinkNode=a,exports.$isLinkNode=l,exports.$toggleLink=d,exports.AutoLinkNode=o,exports.LinkNode=r,exports.TOGGLE_LINK_COMMAND=c,exports.formatUrl=p,exports.toggleLink=g;
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;
@@ -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=x(g[0],p);if(null!==t)return m(t)}!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 r of g){if(!r.isAttached())continue;const s=x(r,p);if(s){m(s);continue}if(o(r)){if(!r.isInline())continue;if(p(r)){if(!(O(r)||null!==e&&e.getParentOrThrow().isParentOf(r))){m(r),e=r;continue}for(const t of r.getChildren())r.insertBefore(t);r.remove();continue}}const u=r.getPreviousSibling();p(u)&&u.is(e)?u.append(r):(e=d(t,{rel:l,target:n,title:i}),r.insertAfter(e),e.append(r))}}))}const T=v;function x(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}const 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,T as toggleLink};
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};
package/package.json CHANGED
@@ -8,12 +8,12 @@
8
8
  "link"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.35.1-nightly.20250915.0",
11
+ "version": "0.35.1-nightly.20250916.0",
12
12
  "main": "LexicalLink.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/utils": "0.35.1-nightly.20250915.0",
16
- "lexical": "0.35.1-nightly.20250915.0"
15
+ "@lexical/utils": "0.35.1-nightly.20250916.0",
16
+ "lexical": "0.35.1-nightly.20250916.0"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",