@lexical/link 0.37.1-nightly.20251024.0 → 0.38.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.
@@ -369,6 +369,48 @@ function $withSelectedNodes($fn) {
369
369
  return rval;
370
370
  }
371
371
 
372
+ /**
373
+ * Splits a LinkNode by removing selected children from it.
374
+ * Handles three cases: selection at start, end, or middle of the link.
375
+ * @param parentLink - The LinkNode to split
376
+ * @param extractedNodes - The nodes that were extracted from the selection
377
+ */
378
+ function $splitLinkAtSelection(parentLink, extractedNodes) {
379
+ const extractedKeys = new Set(extractedNodes.filter(n => parentLink.isParentOf(n)).map(n => n.getKey()));
380
+ const allChildren = parentLink.getChildren();
381
+ const extractedChildren = allChildren.filter(child => extractedKeys.has(child.getKey()));
382
+ if (extractedChildren.length === allChildren.length) {
383
+ allChildren.forEach(child => parentLink.insertBefore(child));
384
+ parentLink.remove();
385
+ return;
386
+ }
387
+ const firstExtractedIndex = allChildren.findIndex(child => extractedKeys.has(child.getKey()));
388
+ const lastExtractedIndex = allChildren.findLastIndex(child => extractedKeys.has(child.getKey()));
389
+ const isAtStart = firstExtractedIndex === 0;
390
+ const isAtEnd = lastExtractedIndex === allChildren.length - 1;
391
+ if (isAtStart) {
392
+ extractedChildren.forEach(child => parentLink.insertBefore(child));
393
+ } else if (isAtEnd) {
394
+ for (let i = extractedChildren.length - 1; i >= 0; i--) {
395
+ parentLink.insertAfter(extractedChildren[i]);
396
+ }
397
+ } else {
398
+ for (let i = extractedChildren.length - 1; i >= 0; i--) {
399
+ parentLink.insertAfter(extractedChildren[i]);
400
+ }
401
+ const trailingChildren = allChildren.slice(lastExtractedIndex + 1);
402
+ if (trailingChildren.length > 0) {
403
+ const newLink = $createLinkNode(parentLink.getURL(), {
404
+ rel: parentLink.getRel(),
405
+ target: parentLink.getTarget(),
406
+ title: parentLink.getTitle()
407
+ });
408
+ extractedChildren[extractedChildren.length - 1].insertAfter(newLink);
409
+ trailingChildren.forEach(child => newLink.append(child));
410
+ }
411
+ }
412
+ }
413
+
372
414
  /**
373
415
  * Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
374
416
  * but saves any children and brings them up to the parent node.
@@ -443,15 +485,16 @@ function $toggleLink(urlOrAttributes, attributes = {}) {
443
485
  // Handle RangeSelection
444
486
  const nodes = selection.extract();
445
487
  if (url === null) {
446
- // Remove LinkNodes
488
+ const processedLinks = new Set();
447
489
  nodes.forEach(node => {
448
- const parentLink = utils.$findMatchingParent(node, parent => !$isAutoLinkNode(parent) && $isLinkNode(parent));
449
- if (parentLink) {
450
- const children = parentLink.getChildren();
451
- for (let i = 0; i < children.length; i++) {
452
- parentLink.insertBefore(children[i]);
490
+ const parentLink = node.getParent();
491
+ if ($isLinkNode(parentLink) && !$isAutoLinkNode(parentLink)) {
492
+ const linkKey = parentLink.getKey();
493
+ if (processedLinks.has(linkKey)) {
494
+ return;
453
495
  }
454
- parentLink.remove();
496
+ $splitLinkAtSelection(parentLink, nodes);
497
+ processedLinks.add(linkKey);
455
498
  }
456
499
  });
457
500
  return;
@@ -367,6 +367,48 @@ function $withSelectedNodes($fn) {
367
367
  return rval;
368
368
  }
369
369
 
370
+ /**
371
+ * Splits a LinkNode by removing selected children from it.
372
+ * Handles three cases: selection at start, end, or middle of the link.
373
+ * @param parentLink - The LinkNode to split
374
+ * @param extractedNodes - The nodes that were extracted from the selection
375
+ */
376
+ function $splitLinkAtSelection(parentLink, extractedNodes) {
377
+ const extractedKeys = new Set(extractedNodes.filter(n => parentLink.isParentOf(n)).map(n => n.getKey()));
378
+ const allChildren = parentLink.getChildren();
379
+ const extractedChildren = allChildren.filter(child => extractedKeys.has(child.getKey()));
380
+ if (extractedChildren.length === allChildren.length) {
381
+ allChildren.forEach(child => parentLink.insertBefore(child));
382
+ parentLink.remove();
383
+ return;
384
+ }
385
+ const firstExtractedIndex = allChildren.findIndex(child => extractedKeys.has(child.getKey()));
386
+ const lastExtractedIndex = allChildren.findLastIndex(child => extractedKeys.has(child.getKey()));
387
+ const isAtStart = firstExtractedIndex === 0;
388
+ const isAtEnd = lastExtractedIndex === allChildren.length - 1;
389
+ if (isAtStart) {
390
+ extractedChildren.forEach(child => parentLink.insertBefore(child));
391
+ } else if (isAtEnd) {
392
+ for (let i = extractedChildren.length - 1; i >= 0; i--) {
393
+ parentLink.insertAfter(extractedChildren[i]);
394
+ }
395
+ } else {
396
+ for (let i = extractedChildren.length - 1; i >= 0; i--) {
397
+ parentLink.insertAfter(extractedChildren[i]);
398
+ }
399
+ const trailingChildren = allChildren.slice(lastExtractedIndex + 1);
400
+ if (trailingChildren.length > 0) {
401
+ const newLink = $createLinkNode(parentLink.getURL(), {
402
+ rel: parentLink.getRel(),
403
+ target: parentLink.getTarget(),
404
+ title: parentLink.getTitle()
405
+ });
406
+ extractedChildren[extractedChildren.length - 1].insertAfter(newLink);
407
+ trailingChildren.forEach(child => newLink.append(child));
408
+ }
409
+ }
410
+ }
411
+
370
412
  /**
371
413
  * Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
372
414
  * but saves any children and brings them up to the parent node.
@@ -441,15 +483,16 @@ function $toggleLink(urlOrAttributes, attributes = {}) {
441
483
  // Handle RangeSelection
442
484
  const nodes = selection.extract();
443
485
  if (url === null) {
444
- // Remove LinkNodes
486
+ const processedLinks = new Set();
445
487
  nodes.forEach(node => {
446
- const parentLink = $findMatchingParent(node, parent => !$isAutoLinkNode(parent) && $isLinkNode(parent));
447
- if (parentLink) {
448
- const children = parentLink.getChildren();
449
- for (let i = 0; i < children.length; i++) {
450
- parentLink.insertBefore(children[i]);
488
+ const parentLink = node.getParent();
489
+ if ($isLinkNode(parentLink) && !$isAutoLinkNode(parentLink)) {
490
+ const linkKey = parentLink.getKey();
491
+ if (processedLinks.has(linkKey)) {
492
+ return;
451
493
  }
452
- parentLink.remove();
494
+ $splitLinkAtSelection(parentLink, nodes);
495
+ processedLinks.add(linkKey);
453
496
  }
454
497
  });
455
498
  return;
@@ -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:_,mergeConfig(e,n){const r=t.shallowMergeConfig(e,n);return e.attributes&&(r.attributes=t.shallowMergeConfig(e.attributes,r.attributes)),r},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 b(e){return S(e[0])}function U(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)&&b(n.getTextContent())}function v(e,t,n,r){if(!(e>0?S(n[e-1]):U(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 C(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 E(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(!U(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())E(n,i,l);else if(!o(n)){if(e.isSimpleText()&&(b(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=C(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()||b(s)&&(l=s,!(r.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(l):/^\.[a-zA-Z0-9]{1,}/.test(l)))||(r.append(e),E(r,t,n),n(null,r.getURL())),!c(i)||i.getIsUnlinked()||$(s)||(M(i),E(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 a 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 a(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 u().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=u(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return r.append(e),e}return null}}function u(e="",n){return t.$applyNodeReplacement(new a(e,n))}function c(e){return e instanceof a}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:a}=r,u=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!==u&&n.setRel(u);else{const e=l(i,{rel:u,target:s});t.insertBefore(e),e.append(t)}}})}const f=g.extract();if(null===i){const e=new Set;return void f.forEach(t=>{const n=t.getParent();if(o(n)&&!c(n)){const t=n.getKey();if(e.has(t))return;!function(e,t){const n=new Set(t.filter(t=>e.isParentOf(t)).map(e=>e.getKey())),r=e.getChildren(),i=r.filter(e=>n.has(e.getKey()));if(i.length===r.length)return r.forEach(t=>e.insertBefore(t)),void e.remove();const s=r.findIndex(e=>n.has(e.getKey())),o=r.findLastIndex(e=>n.has(e.getKey())),a=0===s,u=o===r.length-1;if(a)i.forEach(t=>e.insertBefore(t));else if(u)for(let t=i.length-1;t>=0;t--)e.insertAfter(i[t]);else{for(let t=i.length-1;t>=0;t--)e.insertAfter(i[t]);const t=r.slice(o+1);if(t.length>0){const n=l(e.getURL(),{rel:e.getRel(),target:e.getTarget(),title:e.getTitle()});i[i.length-1].insertAfter(n),t.forEach(e=>n.append(e))}}}(n,f),e.add(t)}})}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!==u&&e.setRel(u),void 0!==a&&e.setTitle(a))};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:u,target:s,title:a}),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:_,mergeConfig(e,n){const r=t.shallowMergeConfig(e,n);return e.attributes&&(r.attributes=t.shallowMergeConfig(e.attributes,r.attributes)),r},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 a=null,u=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))a=i.sanitizeUrl(i.getURL()),u=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&&(a=t.href,u=t.target)}}}),null===a||""===a)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(a,r.newTab.peek()||g||i.metaKey||i.ctrlKey||"_blank"===u?"_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 b(e){return S(e[0])}function U(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)&&b(n.getTextContent())}function v(e,t,n,r){if(!(e>0?S(n[e-1]):U(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 a=[...e];for(;a.length>0;){const e=a[0],u=e.getTextContent().length,c=o;o+u<=t?(r.push(e),l+=u):c>=n?s.push(e):i.push(e),o+=u,a.shift()}return[l,r,i,s]}function E(e,n,r,i){const s=u(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 a=t.$createTextNode(i.text);return a.setFormat(l.getFormat()),a.setDetail(l.getDetail()),a.setStyle(l.getStyle()),s.append(a),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 a=[];let u;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)a.push(n);else{const[e,t]=n.splitText(r-s);a.push(e),u=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,...a),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),u}}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(!U(e)||!R(e))return M(e),void r(null,e.getURL());const a=e.getURL();if(a!==o.url&&(e.setURL(o.url),r(o.url,a)),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()&&(b(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,a]=O(r,o+e,o+t),u=E(l,o+e-i,o+t-i,s);r=u?[u,...a]:a,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()||b(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 y=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=u,exports.$createLinkNode=l,exports.$isAutoLinkNode=c,exports.$isLinkNode=o,exports.$toggleLink=f,exports.AutoLinkExtension=y,exports.AutoLinkNode=a,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,shallowMergeConfig as _,COMMAND_PRIORITY_LOW as p,PASTE_COMMAND as m,safeCast as x,isDOMNode as b,getNearestEditorFromDOMNode as k,$getNearestNodeFromDOMNode as U,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}},p)),C(()=>{const n=e.validateUrl.value;if(!n)return;const r=e.attributes.value;return t.registerCommand(m,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))},p)}))}const B=h({build:(t,e,n)=>O(e),config:{attributes:void 0,validateUrl:void 0},mergeConfig(t,e){const n=_(t,e);return t.attributes&&(n.attributes=_(t.attributes,n.attributes)),n},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(!b(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:x({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},p))}const st=h({config:it,dependencies:[B],mergeConfig(t,e){const n=_(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,shallowMergeConfig as p,COMMAND_PRIORITY_LOW as _,PASTE_COMMAND as m,safeCast as x,isDOMNode as b,getNearestEditorFromDOMNode as k,$getNearestNodeFromDOMNode as U,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 R=new Set(["http:","https:","mailto:","sms:","tel:"]);class y extends s{__url;__target;__rel;__title;static getType(){return"link"}static clone(t){return new y(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:N,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=W(t);try{const e=new URL(W(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 n=D(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 N(t){let n=null;if(e(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(n=D(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:n}}function D(t="",e){return u(new y(t,e))}function w(t){return t instanceof y}class A extends y{__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=D(r,{rel:s,target:i});t.insertBefore(e),e.append(t)}}})}const h=u.extract();if(null===r){const t=new Set;return void h.forEach(e=>{const n=e.getParent();if(w(n)&&!E(n)){const e=n.getKey();if(t.has(e))return;!function(t,e){const n=new Set(e.filter(e=>t.isParentOf(e)).map(t=>t.getKey())),r=t.getChildren(),i=r.filter(t=>n.has(t.getKey()));if(i.length===r.length)return r.forEach(e=>t.insertBefore(e)),void t.remove();const l=r.findIndex(t=>n.has(t.getKey())),s=r.findLastIndex(t=>n.has(t.getKey())),o=0===l,u=s===r.length-1;if(o)i.forEach(e=>t.insertBefore(e));else if(u)for(let e=i.length-1;e>=0;e--)t.insertAfter(i[e]);else{for(let e=i.length-1;e>=0;e--)t.insertAfter(i[e]);const e=r.slice(s+1);if(e.length>0){const n=D(t.getURL(),{rel:t.getRel(),target:t.getTarget(),title:t.getTitle()});i[i.length-1].insertAfter(n),e.forEach(t=>n.append(t))}}}(n,h),t.add(e)}})}const p=new Set,_=t=>{p.has(t.getKey())||(p.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 _(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){_(o);continue}if(a(e)){if(!e.isInline())continue;if(w(e)){if(!(E(e)||null!==t&&t.getParentOrThrow().isParentOf(e))){_(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=D(r,{rel:s,target:i,title:l}),e.insertAfter(t),t.append(e))}})}const K=/^\+?[0-9\s()-]{5,}$/;function W(t){return t.match(/^[a-z][a-z0-9+.-]*:/i)||t.match(/^[/#.]/)?t:t.includes("@")?`mailto:${t}`:K.test(t)?`tel:${t}`:`https://${t}`}function F(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(m,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},mergeConfig(t,e){const n=p(t,e);return t.attributes&&(n.attributes=p(t.attributes,n.attributes)),n},name:"@lexical/link/Link",nodes:[y],register:(t,e,n)=>F(t,n.getOutput())});function z(t,r,i={}){const l=i=>{const l=i.target;if(!b(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:x({disabled:!1,newTab:!1}),dependencies:[B],name:"@lexical/link/ClickableLink",register:(t,e,n)=>z(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=p(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,D as $createLinkNode,E as $isAutoLinkNode,w as $isLinkNode,J as $toggleLink,st as AutoLinkExtension,A as AutoLinkNode,$ as ClickableLinkExtension,B as LinkExtension,y as LinkNode,P as TOGGLE_LINK_COMMAND,H as createLinkMatcherWithRegExp,W as formatUrl,lt as registerAutoLink,z as registerClickableLink,F 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.37.1-nightly.20251024.0",
11
+ "version": "0.38.0",
12
12
  "main": "LexicalLink.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/extension": "0.37.1-nightly.20251024.0",
16
- "@lexical/utils": "0.37.1-nightly.20251024.0",
17
- "lexical": "0.37.1-nightly.20251024.0"
15
+ "@lexical/extension": "0.38.0",
16
+ "@lexical/utils": "0.38.0",
17
+ "lexical": "0.38.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",