@lexical/link 0.36.2-nightly.20250930.0 → 0.36.2

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.
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
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;
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;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
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};
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};
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "link"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.36.2-nightly.20250930.0",
11
+ "version": "0.36.2",
12
12
  "main": "LexicalLink.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/extension": "0.36.2-nightly.20250930.0",
16
- "@lexical/utils": "0.36.2-nightly.20250930.0",
17
- "lexical": "0.36.2-nightly.20250930.0"
15
+ "@lexical/extension": "0.36.2",
16
+ "@lexical/utils": "0.36.2",
17
+ "lexical": "0.36.2"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",