@lexical/link 0.26.0 → 0.27.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.
@@ -19,6 +19,12 @@ var lexical = require('lexical');
19
19
  *
20
20
  */
21
21
 
22
+ // Do not require this module directly! Use normal `invariant` calls.
23
+
24
+ function formatDevErrorMessage(message) {
25
+ throw new Error(message);
26
+ }
27
+
22
28
  const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
23
29
 
24
30
  /** @noInheritDoc */
@@ -334,7 +340,7 @@ function $getPointNode(point, offset) {
334
340
  if (point.type === 'element') {
335
341
  const node = point.getNode();
336
342
  if (!lexical.$isElementNode(node)) {
337
- throw Error(`$getPointNode: element point is not an ElementNode`);
343
+ formatDevErrorMessage(`$getPointNode: element point is not an ElementNode`);
338
344
  }
339
345
  const childNode = node.getChildren()[point.offset + offset];
340
346
  return childNode || null;
@@ -17,6 +17,12 @@ import { createCommand, ElementNode, $isRangeSelection, $applyNodeReplacement, $
17
17
  *
18
18
  */
19
19
 
20
+ // Do not require this module directly! Use normal `invariant` calls.
21
+
22
+ function formatDevErrorMessage(message) {
23
+ throw new Error(message);
24
+ }
25
+
20
26
  const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
21
27
 
22
28
  /** @noInheritDoc */
@@ -332,7 +338,7 @@ function $getPointNode(point, offset) {
332
338
  if (point.type === 'element') {
333
339
  const node = point.getNode();
334
340
  if (!$isElementNode(node)) {
335
- throw Error(`$getPointNode: element point is not an ElementNode`);
341
+ formatDevErrorMessage(`$getPointNode: element point is not an ElementNode`);
336
342
  }
337
343
  const childNode = node.getChildren()[point.offset + offset];
338
344
  return childNode || null;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var t=require("@lexical/utils"),e=require("lexical");function r(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var n=r((function(t){const e=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(let t=1;t<arguments.length;t++)r.append("v",arguments[t]);throw e.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${e.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const i=new Set(["http:","https:","mailto:","sms:","tel:"]);class l extends e.ElementNode{static getType(){return"link"}static clone(t){return new l(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:l=null}=e;this.__url=t,this.__target=n,this.__rel=i,this.__title=l}createDOM(e){const r=document.createElement("a");return r.href=this.sanitizeUrl(this.__url),null!==this.__target&&(r.target=this.__target),null!==this.__rel&&(r.rel=this.__rel),null!==this.__title&&(r.title=this.__title),t.addClassNamesToElement(r,e.theme.link),r}updateDOM(e,r,n){if(t.isHTMLAnchorElement(r)){const t=this.__url,n=this.__target,i=this.__rel,l=this.__title;t!==e.__url&&(r.href=t),n!==e.__target&&(n?r.target=n:r.removeAttribute("target")),i!==e.__rel&&(i?r.rel=i:r.removeAttribute("rel")),l!==e.__title&&(l?r.title=l:r.removeAttribute("title"))}return!1}static importDOM(){return{a:t=>({conversion:s,priority:1})}}static importJSON(t){return o().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){try{const e=new URL(t);if(!i.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=o(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,r,n){if(!e.$isRangeSelection(r))return!1;const i=r.anchor.getNode(),l=r.focus.getNode();return this.isParentOf(i)&&this.isParentOf(l)&&r.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function s(e){let r=null;if(t.isHTMLAnchorElement(e)){const t=e.textContent;(null!==t&&""!==t||e.children.length>0)&&(r=o(e.getAttribute("href")||"",{rel:e.getAttribute("rel"),target:e.getAttribute("target"),title:e.getAttribute("title")}))}return{node:r}}function o(t="",r){return e.$applyNodeReplacement(new l(t,r))}function u(t){return t instanceof l}class a extends l{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 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,r){return super.updateDOM(t,e,r)||t.__isUnlinked!==this.__isUnlinked}static importJSON(t){return c().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,r=!0){const n=this.getParentOrThrow().insertNewAfter(t,r);if(e.$isElementNode(n)){const t=c(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return n.append(t),t}return null}}function c(t="",r){return e.$applyNodeReplacement(new a(t,r))}function _(t){return t instanceof a}const g=e.createCommand("TOGGLE_LINK_COMMAND");function h(t,r){if("element"===t.type){const i=t.getNode();e.$isElementNode(i)||n(252);return i.getChildren()[t.offset+r]||null}return null}function d(r,n={}){const{target:i,title:l}=n,s=void 0===n.rel?"noreferrer":n.rel,a=e.$getSelection();if(!e.$isRangeSelection(a))return;const c=a.extract();if(null===r)return void c.forEach((e=>{const r=t.$findMatchingParent(e,(t=>!_(t)&&u(t)));if(r){const t=r.getChildren();for(let e=0;e<t.length;e++)r.insertBefore(t[e]);r.remove()}}));const g=new Set,d=t=>{g.has(t.getKey())||(g.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===c.length){const t=p(c[0],u);if(null!==t)return d(t)}!function(t){const r=e.$getSelection();if(!e.$isRangeSelection(r))return t();const n=e.$normalizeSelection__EXPERIMENTAL(r),i=n.isBackward(),l=h(n.anchor,i?-1:0),s=h(n.focus,i?0:-1),o=t();if(l||s){const t=e.$getSelection();if(e.$isRangeSelection(t)){const r=t.clone();if(l){const t=l.getParent();t&&r.anchor.set(t.getKey(),l.getIndexWithinParent()+(i?1:0),"element")}if(s){const t=s.getParent();t&&r.focus.set(t.getKey(),s.getIndexWithinParent()+(i?0:1),"element")}e.$setSelection(e.$normalizeSelection__EXPERIMENTAL(r))}}}((()=>{let t=null;for(const n of c){if(!n.isAttached())continue;const a=p(n,u);if(a){d(a);continue}if(e.$isElementNode(n)){if(!n.isInline())continue;if(u(n)){if(!(_(n)||null!==t&&t.getParentOrThrow().isParentOf(n))){d(n),t=n;continue}for(const t of n.getChildren())n.insertBefore(t);n.remove();continue}}const c=n.getPreviousSibling();u(c)&&c.is(t)?c.append(n):(t=o(r,{rel:s,target:i,title:l}),n.insertAfter(t),t.append(n))}}))}const f=d;function p(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}exports.$createAutoLinkNode=c,exports.$createLinkNode=o,exports.$isAutoLinkNode=_,exports.$isLinkNode=u,exports.$toggleLink=d,exports.AutoLinkNode=a,exports.LinkNode=l,exports.TOGGLE_LINK_COMMAND=g,exports.toggleLink=f;
9
+ "use strict";var t=require("@lexical/utils"),e=require("lexical");const r=new Set(["http:","https:","mailto:","sms:","tel:"]);class n extends e.ElementNode{static getType(){return"link"}static clone(t){return new n(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 r.href=this.sanitizeUrl(this.__url),null!==this.__target&&(r.target=this.__target),null!==this.__rel&&(r.rel=this.__rel),null!==this.__title&&(r.title=this.__title),t.addClassNamesToElement(r,e.theme.link),r}updateDOM(e,r,n){if(t.isHTMLAnchorElement(r)){const t=this.__url,n=this.__target,i=this.__rel,s=this.__title;t!==e.__url&&(r.href=t),n!==e.__target&&(n?r.target=n:r.removeAttribute("target")),i!==e.__rel&&(i?r.rel=i:r.removeAttribute("rel")),s!==e.__title&&(s?r.title=s:r.removeAttribute("title"))}return!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){try{const e=new URL(t);if(!r.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=s(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,r,n){if(!e.$isRangeSelection(r))return!1;const i=r.anchor.getNode(),s=r.focus.getNode();return this.isParentOf(i)&&this.isParentOf(s)&&r.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function i(e){let r=null;if(t.isHTMLAnchorElement(e)){const t=e.textContent;(null!==t&&""!==t||e.children.length>0)&&(r=s(e.getAttribute("href")||"",{rel:e.getAttribute("rel"),target:e.getAttribute("target"),title:e.getAttribute("title")}))}return{node:r}}function s(t="",r){return e.$applyNodeReplacement(new n(t,r))}function l(t){return t instanceof n}class o extends n{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 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,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,r=!0){const n=this.getParentOrThrow().insertNewAfter(t,r);if(e.$isElementNode(n)){const t=u(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return n.append(t),t}return null}}function u(t="",r){return e.$applyNodeReplacement(new o(t,r))}function a(t){return t instanceof o}const c=e.createCommand("TOGGLE_LINK_COMMAND");function _(t,r){if("element"===t.type){const n=t.getNode();e.$isElementNode(n)||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 n.getChildren()[t.offset+r]||null}return null}function g(r,n={}){const{target:i,title:o}=n,u=void 0===n.rel?"noreferrer":n.rel,c=e.$getSelection();if(!e.$isRangeSelection(c))return;const g=c.extract();if(null===r)return void g.forEach((e=>{const r=t.$findMatchingParent(e,(t=>!a(t)&&l(t)));if(r){const t=r.getChildren();for(let e=0;e<t.length;e++)r.insertBefore(t[e]);r.remove()}}));const h=new Set,f=t=>{h.has(t.getKey())||(h.add(t.getKey()),t.setURL(r),void 0!==i&&t.setTarget(i),void 0!==u&&t.setRel(u),void 0!==o&&t.setTitle(o))};if(1===g.length){const t=d(g[0],l);if(null!==t)return f(t)}!function(t){const r=e.$getSelection();if(!e.$isRangeSelection(r))return t();const n=e.$normalizeSelection__EXPERIMENTAL(r),i=n.isBackward(),s=_(n.anchor,i?-1:0),l=_(n.focus,i?0:-1),o=t();if(s||l){const t=e.$getSelection();if(e.$isRangeSelection(t)){const r=t.clone();if(s){const t=s.getParent();t&&r.anchor.set(t.getKey(),s.getIndexWithinParent()+(i?1:0),"element")}if(l){const t=l.getParent();t&&r.focus.set(t.getKey(),l.getIndexWithinParent()+(i?0:1),"element")}e.$setSelection(e.$normalizeSelection__EXPERIMENTAL(r))}}}((()=>{let t=null;for(const n of g){if(!n.isAttached())continue;const c=d(n,l);if(c){f(c);continue}if(e.$isElementNode(n)){if(!n.isInline())continue;if(l(n)){if(!(a(n)||null!==t&&t.getParentOrThrow().isParentOf(n))){f(n),t=n;continue}for(const t of n.getChildren())n.insertBefore(t);n.remove();continue}}const _=n.getPreviousSibling();l(_)&&_.is(t)?_.append(n):(t=s(r,{rel:u,target:i,title:o}),n.insertAfter(t),t.append(n))}}))}const h=g;function d(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}exports.$createAutoLinkNode=u,exports.$createLinkNode=s,exports.$isAutoLinkNode=a,exports.$isLinkNode=l,exports.$toggleLink=g,exports.AutoLinkNode=o,exports.LinkNode=n,exports.TOGGLE_LINK_COMMAND=c,exports.toggleLink=h;
@@ -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 l,$applyNodeReplacement as s,$isElementNode as o,$getSelection as u,$normalizeSelection__EXPERIMENTAL as a,$setSelection as _}from"lexical";function c(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var h=c((function(t){const e=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(let t=1;t<arguments.length;t++)r.append("v",arguments[t]);throw e.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${e.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const g=new Set(["http:","https:","mailto:","sms:","tel:"]);class f extends i{static getType(){return"link"}static clone(t){return new f(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:l=null}=e;this.__url=t,this.__target=n,this.__rel=i,this.__title=l}createDOM(e){const r=document.createElement("a");return r.href=this.sanitizeUrl(this.__url),null!==this.__target&&(r.target=this.__target),null!==this.__rel&&(r.rel=this.__rel),null!==this.__title&&(r.title=this.__title),t(r,e.theme.link),r}updateDOM(t,r,n){if(e(r)){const e=this.__url,n=this.__target,i=this.__rel,l=this.__title;e!==t.__url&&(r.href=e),n!==t.__target&&(n?r.target=n:r.removeAttribute("target")),i!==t.__rel&&(i?r.rel=i:r.removeAttribute("rel")),l!==t.__title&&(l?r.title=l:r.removeAttribute("title"))}return!1}static importDOM(){return{a:t=>({conversion:d,priority:1})}}static importJSON(t){return p().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){try{const e=new URL(t);if(!g.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=p(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(!l(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 d(t){let r=null;if(e(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(r=p(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:r}}function p(t="",e){return s(new f(t,e))}function m(t){return t instanceof f}class U extends f{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 U(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 O().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=O(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return r.append(t),t}return null}}function O(t="",e){return s(new U(t,e))}function k(t){return t instanceof U}const N=n("TOGGLE_LINK_COMMAND");function v(t,e){if("element"===t.type){const r=t.getNode();o(r)||h(252);return r.getChildren()[t.offset+e]||null}return null}function w(t,e={}){const{target:n,title:i}=e,s=void 0===e.rel?"noreferrer":e.rel,c=u();if(!l(c))return;const h=c.extract();if(null===t)return void h.forEach((t=>{const e=r(t,(t=>!k(t)&&m(t)));if(e){const t=e.getChildren();for(let r=0;r<t.length;r++)e.insertBefore(t[r]);e.remove()}}));const g=new Set,f=e=>{g.has(e.getKey())||(g.add(e.getKey()),e.setURL(t),void 0!==n&&e.setTarget(n),void 0!==s&&e.setRel(s),void 0!==i&&e.setTitle(i))};if(1===h.length){const t=S(h[0],m);if(null!==t)return f(t)}!function(t){const e=u();if(!l(e))return t();const r=a(e),n=r.isBackward(),i=v(r.anchor,n?-1:0),s=v(r.focus,n?0:-1),o=t();if(i||s){const t=u();if(l(t)){const e=t.clone();if(i){const t=i.getParent();t&&e.anchor.set(t.getKey(),i.getIndexWithinParent()+(n?1:0),"element")}if(s){const t=s.getParent();t&&e.focus.set(t.getKey(),s.getIndexWithinParent()+(n?0:1),"element")}_(a(e))}}}((()=>{let e=null;for(const r of h){if(!r.isAttached())continue;const l=S(r,m);if(l){f(l);continue}if(o(r)){if(!r.isInline())continue;if(m(r)){if(!(k(r)||null!==e&&e.getParentOrThrow().isParentOf(r))){f(r),e=r;continue}for(const t of r.getChildren())r.insertBefore(t);r.remove();continue}}const u=r.getPreviousSibling();m(u)&&u.is(e)?u.append(r):(e=p(t,{rel:s,target:n,title:i}),r.insertAfter(e),e.append(r))}}))}const x=w;function S(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}export{O as $createAutoLinkNode,p as $createLinkNode,k as $isAutoLinkNode,m as $isLinkNode,w as $toggleLink,U as AutoLinkNode,f as LinkNode,N as TOGGLE_LINK_COMMAND,x 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,$normalizeSelection__EXPERIMENTAL as a,$setSelection as _}from"lexical";const c=new Set(["http:","https:","mailto:","sms:","tel:"]);class h extends i{static getType(){return"link"}static clone(t){return new h(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 r.href=this.sanitizeUrl(this.__url),null!==this.__target&&(r.target=this.__target),null!==this.__rel&&(r.rel=this.__rel),null!==this.__title&&(r.title=this.__title),t(r,e.theme.link),r}updateDOM(t,r,n){if(e(r)){const e=this.__url,n=this.__target,i=this.__rel,s=this.__title;e!==t.__url&&(r.href=e),n!==t.__target&&(n?r.target=n:r.removeAttribute("target")),i!==t.__rel&&(i?r.rel=i:r.removeAttribute("rel")),s!==t.__title&&(s?r.title=s:r.removeAttribute("title"))}return!1}static importDOM(){return{a:t=>({conversion:g,priority:1})}}static importJSON(t){return f().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){try{const e=new URL(t);if(!c.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=f(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 g(t){let r=null;if(e(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(r=f(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:r}}function f(t="",e){return l(new h(t,e))}function d(t){return t instanceof h}class p extends h{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 p(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 m().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=m(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return r.append(t),t}return null}}function m(t="",e){return l(new p(t,e))}function U(t){return t instanceof p}const O=n("TOGGLE_LINK_COMMAND");function k(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 N(t,e={}){const{target:n,title:i}=e,l=void 0===e.rel?"noreferrer":e.rel,c=u();if(!s(c))return;const h=c.extract();if(null===t)return void h.forEach((t=>{const e=r(t,(t=>!U(t)&&d(t)));if(e){const t=e.getChildren();for(let r=0;r<t.length;r++)e.insertBefore(t[r]);e.remove()}}));const g=new Set,p=e=>{g.has(e.getKey())||(g.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===h.length){const t=S(h[0],d);if(null!==t)return p(t)}!function(t){const e=u();if(!s(e))return t();const r=a(e),n=r.isBackward(),i=k(r.anchor,n?-1:0),l=k(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")}_(a(e))}}}((()=>{let e=null;for(const r of h){if(!r.isAttached())continue;const s=S(r,d);if(s){p(s);continue}if(o(r)){if(!r.isInline())continue;if(d(r)){if(!(U(r)||null!==e&&e.getParentOrThrow().isParentOf(r))){p(r),e=r;continue}for(const t of r.getChildren())r.insertBefore(t);r.remove();continue}}const u=r.getPreviousSibling();d(u)&&u.is(e)?u.append(r):(e=f(t,{rel:l,target:n,title:i}),r.insertAfter(e),e.append(r))}}))}const x=N;function S(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}export{m as $createAutoLinkNode,f as $createLinkNode,U as $isAutoLinkNode,d as $isLinkNode,N as $toggleLink,p as AutoLinkNode,h as LinkNode,O as TOGGLE_LINK_COMMAND,x as toggleLink};
package/package.json CHANGED
@@ -8,12 +8,12 @@
8
8
  "link"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.26.0",
11
+ "version": "0.27.0",
12
12
  "main": "LexicalLink.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/utils": "0.26.0",
16
- "lexical": "0.26.0"
15
+ "@lexical/utils": "0.27.0",
16
+ "lexical": "0.27.0"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",