@lexical/link 0.42.1-nightly.20260408.0 → 0.43.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.
@@ -247,9 +247,28 @@ function $linkNodeTransform(link) {
247
247
  });
248
248
  }
249
249
  }
250
+ // Fix a caret pair that points to the end of the absorbing link,
251
+ // which would shift when new children are appended during merge.
252
+ function $fixMergeBoundaryCaret(pair, absorbingLink, mergingLink) {
253
+ const [next, prev] = pair;
254
+ const $isAffected = caret => lexical.$isSiblingCaret(caret) && caret.origin.is(absorbingLink);
255
+ if (!$isAffected(next) && !$isAffected(prev)) {
256
+ return pair;
257
+ }
258
+ // Resolve the merge boundary from the merging link's start, since
259
+ // those children survive the move and represent the boundary position.
260
+ const fixed = lexical.$normalizeCaret(lexical.$getChildCaret(mergingLink, 'next'));
261
+ return [fixed, fixed.getFlipped()];
262
+ }
250
263
  if (link.isAttached()) {
251
264
  const prevSibling = link.getPreviousSibling();
252
265
  if ($isLinkNode(prevSibling) && prevSibling.shouldMergeAdjacentLink(link)) {
266
+ if (anchorPair) {
267
+ anchorPair = $fixMergeBoundaryCaret(anchorPair, prevSibling, link);
268
+ }
269
+ if (focusPair) {
270
+ focusPair = $fixMergeBoundaryCaret(focusPair, prevSibling, link);
271
+ }
253
272
  prevSibling.append(...link.getChildren());
254
273
  link.remove();
255
274
  $restoreSelection();
@@ -257,6 +276,12 @@ function $linkNodeTransform(link) {
257
276
  }
258
277
  const nextSibling = link.getNextSibling();
259
278
  if ($isLinkNode(nextSibling) && link.shouldMergeAdjacentLink(nextSibling)) {
279
+ if (anchorPair) {
280
+ anchorPair = $fixMergeBoundaryCaret(anchorPair, link, nextSibling);
281
+ }
282
+ if (focusPair) {
283
+ focusPair = $fixMergeBoundaryCaret(focusPair, link, nextSibling);
284
+ }
260
285
  link.append(...nextSibling.getChildren());
261
286
  nextSibling.remove();
262
287
  transformed = true;
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import { addClassNamesToElement, isHTMLAnchorElement, $findMatchingParent, $insertNodeToNearestRootAtCaret, mergeRegister, objectKlassEquals } from '@lexical/utils';
10
- import { ElementNode, $copyNode, $isRangeSelection, $applyNodeReplacement, createCommand, $getSelection, $isNodeSelection, $normalizeSelection__EXPERIMENTAL, $setSelection, $getChildCaret, $isElementNode, $rewindSiblingCaret, $caretFromPoint, $normalizeCaret, $setPointFromCaret, defineExtension, shallowMergeConfig, COMMAND_PRIORITY_EDITOR, PASTE_COMMAND, COMMAND_PRIORITY_LOW, safeCast, isDOMNode, getNearestEditorFromDOMNode, $getNearestNodeFromDOMNode, TextNode, $isTextNode, $isLineBreakNode, $createTextNode } from 'lexical';
10
+ import { ElementNode, $copyNode, $isRangeSelection, $applyNodeReplacement, createCommand, $getSelection, $isNodeSelection, $normalizeSelection__EXPERIMENTAL, $setSelection, $getChildCaret, $isElementNode, $rewindSiblingCaret, $caretFromPoint, $normalizeCaret, $isSiblingCaret, $setPointFromCaret, defineExtension, shallowMergeConfig, COMMAND_PRIORITY_EDITOR, PASTE_COMMAND, COMMAND_PRIORITY_LOW, safeCast, isDOMNode, getNearestEditorFromDOMNode, $getNearestNodeFromDOMNode, TextNode, $isTextNode, $isLineBreakNode, $createTextNode } from 'lexical';
11
11
  import { namedSignals, effect } from '@lexical/extension';
12
12
 
13
13
  /**
@@ -245,9 +245,28 @@ function $linkNodeTransform(link) {
245
245
  });
246
246
  }
247
247
  }
248
+ // Fix a caret pair that points to the end of the absorbing link,
249
+ // which would shift when new children are appended during merge.
250
+ function $fixMergeBoundaryCaret(pair, absorbingLink, mergingLink) {
251
+ const [next, prev] = pair;
252
+ const $isAffected = caret => $isSiblingCaret(caret) && caret.origin.is(absorbingLink);
253
+ if (!$isAffected(next) && !$isAffected(prev)) {
254
+ return pair;
255
+ }
256
+ // Resolve the merge boundary from the merging link's start, since
257
+ // those children survive the move and represent the boundary position.
258
+ const fixed = $normalizeCaret($getChildCaret(mergingLink, 'next'));
259
+ return [fixed, fixed.getFlipped()];
260
+ }
248
261
  if (link.isAttached()) {
249
262
  const prevSibling = link.getPreviousSibling();
250
263
  if ($isLinkNode(prevSibling) && prevSibling.shouldMergeAdjacentLink(link)) {
264
+ if (anchorPair) {
265
+ anchorPair = $fixMergeBoundaryCaret(anchorPair, prevSibling, link);
266
+ }
267
+ if (focusPair) {
268
+ focusPair = $fixMergeBoundaryCaret(focusPair, prevSibling, link);
269
+ }
251
270
  prevSibling.append(...link.getChildren());
252
271
  link.remove();
253
272
  $restoreSelection();
@@ -255,6 +274,12 @@ function $linkNodeTransform(link) {
255
274
  }
256
275
  const nextSibling = link.getNextSibling();
257
276
  if ($isLinkNode(nextSibling) && link.shouldMergeAdjacentLink(nextSibling)) {
277
+ if (anchorPair) {
278
+ anchorPair = $fixMergeBoundaryCaret(anchorPair, link, nextSibling);
279
+ }
280
+ if (focusPair) {
281
+ focusPair = $fixMergeBoundaryCaret(focusPair, link, nextSibling);
282
+ }
258
283
  link.append(...nextSibling.getChildren());
259
284
  nextSibling.remove();
260
285
  transformed = true;
@@ -20,7 +20,7 @@ import {addClassNamesToElement} from '@lexical/utils';
20
20
  import {$isElementNode, ElementNode} from 'lexical';
21
21
  import type {LexicalExtension, NamedSignalsOutput} from '@lexical/extension';
22
22
 
23
- export type LinkAttributes = $ReadOnly<{
23
+ export type LinkAttributes = Readonly<{
24
24
  rel?: null | string,
25
25
  target?: null | string,
26
26
  title?: null | string,
@@ -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}afterCloneFrom(e){super.afterCloneFrom(e),this.__url=e.__url,this.__rel=e.__rel,this.__target=e.__target,this.__title=e.__title}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:a,priority:1})}}static importJSON(e){return u().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=x(e);try{const t=new URL(x(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,n=!0){const r=t.$copyNode(this);return this.insertAfter(r,n),r}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://")}shouldMergeAdjacentLink(e){return this.getType()===e.getType()&&this.__url===e.__url&&this.__target===e.__target&&this.__rel===e.__rel&&this.__title===e.__title}}function s(e){const n=t.$caretFromPoint(e,"next");return[n,n.getFlipped()]}function l(e,n){for(const r of n)if(r.origin.isAttached()){const n=t.$normalizeCaret(r);return void t.$setPointFromCaret(e,n)}}function o(n){const r=t.$getSelection();let i=null,o=null;function a(){t.$isRangeSelection(r)&&(l(r.anchor,i),l(r.focus,o),t.$normalizeSelection__EXPERIMENTAL(r))}t.$isRangeSelection(r)&&(i=s(r.anchor),o=s(r.focus));let u=!1;for(const r of t.$getChildCaret(n,"next")){const i=r.origin;if(t.$isElementNode(i)&&!i.isInline()){const s=i.getChildren();if(s.length>0){const e=t.$copyNode(n);e.append(...s),i.append(e),u=!0}e.$insertNodeToNearestRootAtCaret(i,t.$rewindSiblingCaret(r),{$shouldSplit:()=>!1})}}if(n.isAttached()){const e=n.getPreviousSibling();if(c(e)&&e.shouldMergeAdjacentLink(n))return e.append(...n.getChildren()),n.remove(),void a();const t=n.getNextSibling();c(t)&&n.shouldMergeAdjacentLink(t)&&(n.append(...t.getChildren()),t.remove(),u=!0)}if(u){if(!n.canBeEmpty()&&n.isEmpty()){const e=n.getParent();n.remove(),e&&e.isEmpty()&&e.remove()}a()}}function a(t){let n=null;if(e.isHTMLAnchorElement(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(n=u(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:n}}function u(e="",n){return t.$applyNodeReplacement(new i(e,n))}function c(e){return e instanceof i}class g extends i{__isUnlinked;constructor(e="",t={},n){super(e,t,n),this.__isUnlinked=void 0!==t.isUnlinked&&null!==t.isUnlinked&&t.isUnlinked}afterCloneFrom(e){super.afterCloneFrom(e),this.__isUnlinked=e.__isUnlinked}static getType(){return"autolink"}static clone(e){return new g(e.__url,{isUnlinked:e.__isUnlinked,rel:e.__rel,target:e.__target,title:e.__title},e.__key)}shouldMergeAdjacentLink(e){return!1}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 d().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,t=!0){const n=d(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(n,t),n}}function d(e="",n){return t.$applyNodeReplacement(new g(e,n))}function f(e){return e instanceof g}const h=t.createCommand("TOGGLE_LINK_COMMAND");function _(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 p(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:l}=r,o=void 0===r.rel?"noreferrer":r.rel,a=t.$getSelection();if(null===a||!t.$isRangeSelection(a)&&!t.$isNodeSelection(a))return;if(t.$isNodeSelection(a)){const t=a.getNodes();if(0===t.length)return;return void t.forEach(t=>{if(null===i){const n=e.$findMatchingParent(t,e=>!f(e)&&c(e));n&&(n.insertBefore(t),0===n.getChildren().length&&n.remove())}else{const n=e.$findMatchingParent(t,e=>!f(e)&&c(e));if(n)n.setURL(i),void 0!==s&&n.setTarget(s),void 0!==o&&n.setRel(o);else{const e=u(i,{rel:o,target:s});t.insertBefore(e),e.append(t)}}})}if(a.isCollapsed()&&null===i)for(const t of a.getNodes()){const n=e.$findMatchingParent(t,e=>!f(e)&&c(e));return void(null!==n&&(n.getChildren().forEach(e=>{n.insertBefore(e)}),n.remove()))}const g=a.extract();if(null===i){const n=new Set;return void g.forEach(r=>{const i=e.$findMatchingParent(r,e=>!f(e)&&c(e));if(null!==i){const e=i.getKey();if(n.has(e))return;!function(e,n){const r=new Set(n.filter(t=>e.isParentOf(t)).map(e=>e.getKey())),i=e.getChildren(),s=i=>r.has(i.getKey())||t.$isElementNode(i)&&n.some(t=>e.isParentOf(t)&&i.isParentOf(t)),l=i.filter(s);if(l.length===i.length)return i.forEach(t=>e.insertBefore(t)),void e.remove();const o=i.findIndex(s),a=i.findLastIndex(s),u=0===o,c=a===i.length-1;if(u)l.forEach(t=>e.insertBefore(t));else if(c)for(let t=l.length-1;t>=0;t--)e.insertAfter(l[t]);else{for(let t=l.length-1;t>=0;t--)e.insertAfter(l[t]);const n=i.slice(a+1);if(n.length>0){const r=t.$copyNode(e);l[l.length-1].insertAfter(r),n.forEach(e=>r.append(e))}}}(i,g),n.add(e)}})}const d=new Set,h=e=>{d.has(e.getKey())||(d.add(e.getKey()),e.setURL(i),void 0!==s&&e.setTarget(s),void 0!==o&&e.setRel(o),void 0!==l&&e.setTitle(l))};if(1===g.length){const t=g[0],n=e.$findMatchingParent(t,c);if(null!==n)return h(n)}!function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n))return e();const r=t.$normalizeSelection__EXPERIMENTAL(n),i=r.isBackward(),s=_(r.anchor,i?-1:0),l=_(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 g){if(!r.isAttached())continue;const a=e.$findMatchingParent(r,c);if(a){h(a);continue}if(t.$isElementNode(r)){if(!r.isInline())continue;if(c(r)){if(!(f(r)||null!==n&&n.getParentOrThrow().isParentOf(r))){h(r),n=r;continue}for(const e of r.getChildren())r.insertBefore(e);r.remove();continue}}const g=r.getPreviousSibling();c(g)&&g.is(n)?g.append(r):(n=u(i,{rel:o,target:s,title:l}),r.insertAfter(n),n.append(r))}})}const m=/^\+?[0-9\s()-]{5,}$/;function x(e){return e.match(/^[a-z][a-z0-9+.-]*:/i)||e.match(/^[/#.]/)?e:e.includes("@")?`mailto:${e}`:m.test(e)?`tel:${e}`:`https://${e}`}const N={attributes:void 0,validateUrl:void 0};function k(r,s){return e.mergeRegister(r.registerNodeTransform(i,o),r.registerCommand(h,e=>{const t=s.validateUrl.peek(),n=s.attributes.peek();if(null===e)return p(null),!0;if("string"==typeof e)return!(void 0!==t&&!t(e))&&(p(e,n),!0);{const{url:t,target:r,rel:i,title:s}=e;return p(t,{...n,rel:i,target:r,title:s}),!0}},t.COMMAND_PRIORITY_EDITOR),n.effect(()=>{const n=s.validateUrl.value;if(!n)return;const i=s.attributes.value;return r.registerCommand(t.PASTE_COMMAND,s=>{const l=t.$getSelection();if(!t.$isRangeSelection(l)||l.isCollapsed()||!e.objectKlassEquals(s,ClipboardEvent))return!1;if(null===s.clipboardData)return!1;const o=s.clipboardData.getData("text");return!!n(o)&&(!l.getNodes().some(e=>t.$isElementNode(e))&&(r.dispatchCommand(h,{...i,url:o}),s.preventDefault(),!0))},t.COMMAND_PRIORITY_LOW)}))}const $=t.defineExtension({build:(e,t,r)=>n.namedSignals(t),config:N,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)=>k(e,n.getOutput())});function L(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 o=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(c(i))o=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&&(o=t.href,a=t.target)}}}),null===o||""===o)return;const u=n.getEditorState().read(t.$getSelection);if(t.$isRangeSelection(u)&&!u.isCollapsed())return void i.preventDefault();const g="auxclick"===i.type&&1===i.button;window.open(o,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=>{if(e)return e.addEventListener("click",s,i),e.addEventListener("mouseup",l,i),()=>{e.removeEventListener("click",s),e.removeEventListener("mouseup",l)}})}const S=t.defineExtension({build:(e,t,r)=>n.namedSignals(t),config:t.safeCast({disabled:!1,newTab:!1}),dependencies:[$],name:"@lexical/link/ClickableLink",register:(e,t,n)=>L(e,n.getOutput())});function T(e,t){for(let n=0;n<t.length;n++){const r=t[n](e);if(r)return r}return null}const b=/[.,;\s]/;function v(e){return b.test(e)}function C(e){return v(e[e.length-1])}function E(e){return v(e[0])}function U(e){let n=e.getPreviousSibling();return t.$isElementNode(n)&&(n=n.getLastDescendant()),null===n||t.$isLineBreakNode(n)||t.$isTextNode(n)&&C(n.getTextContent())}function R(e){let n=e.getNextSibling();return t.$isElementNode(n)&&(n=n.getFirstDescendant()),null===n||t.$isLineBreakNode(n)||t.$isTextNode(n)&&E(n.getTextContent())}function O(e,t,n,r){if(!(e>0?v(n[e-1]):U(r[0])))return!1;return t<n.length?v(n[t]):R(r[r.length-1])}function M(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 P(e,n,r,i){const s=d(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 A(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 y(e),void r(null,e.getURL())}const l=e.getTextContent(),o=T(l,n);if(null===o||o.text!==l)return y(e),void r(null,e.getURL());if(!U(e)||!R(e))return y(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 y(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 D={changeHandlers:[],excludeParents:[],matchers:[]};function I(n,r=D){const{matchers:i,changeHandlers:s,excludeParents:l}=r,o=(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(f(n))A(n,i,o);else if(!c(n)&&!l.some(e=>e(n))){if(e.isSimpleText()&&(E(e.getTextContent())||!f(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){for(const t of e){const e=t.getParent();if(f(e)&&!e.getIsUnlinked())return}let r=[...e];const i=r.map(e=>e.getTextContent()).join("");let s,l=i,o=0;for(;(s=T(l,t))&&null!==s;){const e=s.index,t=e+s.length;if(O(o+e,o+t,i,r)){const[i,,a,u]=M(r,o+e,o+t);let c=!1;for(const e of a){const t=e.getParent();if(f(t)&&!t.getIsUnlinked()){c=!0;break}}if(c){o+=t,l=l.substring(t);continue}const g=P(a,o+e-i,o+t-i,s);r=g?[g,...u]:u,n(s.url,null),o=0}else o+=t;l=l.substring(t)}}(n,i,o)}!function(e,t,n){const r=e.getParent(),i=e.getPreviousSibling(),s=e.getNextSibling(),l=e.getTextContent();if(!f(r)||r.getIsUnlinked()){if(f(i)&&!i.getIsUnlinked()&&i.is(e.getPreviousSibling())&&e.getParent()===i.getParent()){if(!E(l))return y(i),void n(null,i.getURL());if(o=l,i.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(o):/^\.[a-zA-Z0-9]{1,}/.test(o)){const r=i.getTextContent()+l,s=T(r,t);null!==s&&s.text===r&&(i.append(e),A(i,t,n),n(null,i.getURL()))}}var o;!f(s)||s.getIsUnlinked()||C(l)||s.is(e.getNextSibling())&&e.getParent()===s.getParent()&&(y(s),n(null,s.getURL()))}}(e,i,o)}}),n.registerCommand(h,e=>{const n=t.$getSelection();if(null!==e||!t.$isRangeSelection(n))return!1;return n.extract().forEach(e=>{const t=e.getParent();f(t)&&(t.setIsUnlinked(!t.getIsUnlinked()),t.markDirty())}),!1},t.COMMAND_PRIORITY_LOW))}const w=t.defineExtension({config:D,dependencies:[$],mergeConfig(e,n){const r=t.shallowMergeConfig(e,n);for(const t of["matchers","changeHandlers","excludeParents"]){const i=n[t];Array.isArray(i)&&(r[t]=[...e[t],...i])}return r},name:"@lexical/link/AutoLink",nodes:[g],register:I}),F=p;exports.$createAutoLinkNode=d,exports.$createLinkNode=u,exports.$isAutoLinkNode=f,exports.$isLinkNode=c,exports.$toggleLink=p,exports.AutoLinkExtension=w,exports.AutoLinkNode=g,exports.ClickableLinkExtension=S,exports.LinkExtension=$,exports.LinkNode=i,exports.TOGGLE_LINK_COMMAND=h,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=x,exports.registerAutoLink=I,exports.registerClickableLink=L,exports.registerLink=k,exports.toggleLink=F;
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}afterCloneFrom(e){super.afterCloneFrom(e),this.__url=e.__url,this.__rel=e.__rel,this.__target=e.__target,this.__title=e.__title}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:a,priority:1})}}static importJSON(e){return u().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=x(e);try{const t=new URL(x(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,n=!0){const r=t.$copyNode(this);return this.insertAfter(r,n),r}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://")}shouldMergeAdjacentLink(e){return this.getType()===e.getType()&&this.__url===e.__url&&this.__target===e.__target&&this.__rel===e.__rel&&this.__title===e.__title}}function s(e){const n=t.$caretFromPoint(e,"next");return[n,n.getFlipped()]}function o(e,n){for(const r of n)if(r.origin.isAttached()){const n=t.$normalizeCaret(r);return void t.$setPointFromCaret(e,n)}}function l(n){const r=t.$getSelection();let i=null,l=null;function a(){t.$isRangeSelection(r)&&(o(r.anchor,i),o(r.focus,l),t.$normalizeSelection__EXPERIMENTAL(r))}t.$isRangeSelection(r)&&(i=s(r.anchor),l=s(r.focus));let u=!1;for(const r of t.$getChildCaret(n,"next")){const i=r.origin;if(t.$isElementNode(i)&&!i.isInline()){const s=i.getChildren();if(s.length>0){const e=t.$copyNode(n);e.append(...s),i.append(e),u=!0}e.$insertNodeToNearestRootAtCaret(i,t.$rewindSiblingCaret(r),{$shouldSplit:()=>!1})}}function g(e,n,r){const[i,s]=e,o=e=>t.$isSiblingCaret(e)&&e.origin.is(n);if(!o(i)&&!o(s))return e;const l=t.$normalizeCaret(t.$getChildCaret(r,"next"));return[l,l.getFlipped()]}if(n.isAttached()){const e=n.getPreviousSibling();if(c(e)&&e.shouldMergeAdjacentLink(n))return i&&(i=g(i,e,n)),l&&(l=g(l,e,n)),e.append(...n.getChildren()),n.remove(),void a();const t=n.getNextSibling();c(t)&&n.shouldMergeAdjacentLink(t)&&(i&&(i=g(i,n,t)),l&&(l=g(l,n,t)),n.append(...t.getChildren()),t.remove(),u=!0)}if(u){if(!n.canBeEmpty()&&n.isEmpty()){const e=n.getParent();n.remove(),e&&e.isEmpty()&&e.remove()}a()}}function a(t){let n=null;if(e.isHTMLAnchorElement(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(n=u(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:n}}function u(e="",n){return t.$applyNodeReplacement(new i(e,n))}function c(e){return e instanceof i}class g extends i{__isUnlinked;constructor(e="",t={},n){super(e,t,n),this.__isUnlinked=void 0!==t.isUnlinked&&null!==t.isUnlinked&&t.isUnlinked}afterCloneFrom(e){super.afterCloneFrom(e),this.__isUnlinked=e.__isUnlinked}static getType(){return"autolink"}static clone(e){return new g(e.__url,{isUnlinked:e.__isUnlinked,rel:e.__rel,target:e.__target,title:e.__title},e.__key)}shouldMergeAdjacentLink(e){return!1}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 d().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,t=!0){const n=d(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(n,t),n}}function d(e="",n){return t.$applyNodeReplacement(new g(e,n))}function f(e){return e instanceof g}const h=t.createCommand("TOGGLE_LINK_COMMAND");function p(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 _(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:o}=r,l=void 0===r.rel?"noreferrer":r.rel,a=t.$getSelection();if(null===a||!t.$isRangeSelection(a)&&!t.$isNodeSelection(a))return;if(t.$isNodeSelection(a)){const t=a.getNodes();if(0===t.length)return;return void t.forEach(t=>{if(null===i){const n=e.$findMatchingParent(t,e=>!f(e)&&c(e));n&&(n.insertBefore(t),0===n.getChildren().length&&n.remove())}else{const n=e.$findMatchingParent(t,e=>!f(e)&&c(e));if(n)n.setURL(i),void 0!==s&&n.setTarget(s),void 0!==l&&n.setRel(l);else{const e=u(i,{rel:l,target:s});t.insertBefore(e),e.append(t)}}})}if(a.isCollapsed()&&null===i)for(const t of a.getNodes()){const n=e.$findMatchingParent(t,e=>!f(e)&&c(e));return void(null!==n&&(n.getChildren().forEach(e=>{n.insertBefore(e)}),n.remove()))}const g=a.extract();if(null===i){const n=new Set;return void g.forEach(r=>{const i=e.$findMatchingParent(r,e=>!f(e)&&c(e));if(null!==i){const e=i.getKey();if(n.has(e))return;!function(e,n){const r=new Set(n.filter(t=>e.isParentOf(t)).map(e=>e.getKey())),i=e.getChildren(),s=i=>r.has(i.getKey())||t.$isElementNode(i)&&n.some(t=>e.isParentOf(t)&&i.isParentOf(t)),o=i.filter(s);if(o.length===i.length)return i.forEach(t=>e.insertBefore(t)),void e.remove();const l=i.findIndex(s),a=i.findLastIndex(s),u=0===l,c=a===i.length-1;if(u)o.forEach(t=>e.insertBefore(t));else if(c)for(let t=o.length-1;t>=0;t--)e.insertAfter(o[t]);else{for(let t=o.length-1;t>=0;t--)e.insertAfter(o[t]);const n=i.slice(a+1);if(n.length>0){const r=t.$copyNode(e);o[o.length-1].insertAfter(r),n.forEach(e=>r.append(e))}}}(i,g),n.add(e)}})}const d=new Set,h=e=>{d.has(e.getKey())||(d.add(e.getKey()),e.setURL(i),void 0!==s&&e.setTarget(s),void 0!==l&&e.setRel(l),void 0!==o&&e.setTitle(o))};if(1===g.length){const t=g[0],n=e.$findMatchingParent(t,c);if(null!==n)return h(n)}!function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n))return e();const r=t.$normalizeSelection__EXPERIMENTAL(n),i=r.isBackward(),s=p(r.anchor,i?-1:0),o=p(r.focus,i?0:-1),l=e();if(s||o){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(o){const e=o.getParent();e&&n.focus.set(e.getKey(),o.getIndexWithinParent()+(i?0:1),"element")}t.$setSelection(t.$normalizeSelection__EXPERIMENTAL(n))}}}(()=>{let n=null;for(const r of g){if(!r.isAttached())continue;const a=e.$findMatchingParent(r,c);if(a){h(a);continue}if(t.$isElementNode(r)){if(!r.isInline())continue;if(c(r)){if(!(f(r)||null!==n&&n.getParentOrThrow().isParentOf(r))){h(r),n=r;continue}for(const e of r.getChildren())r.insertBefore(e);r.remove();continue}}const g=r.getPreviousSibling();c(g)&&g.is(n)?g.append(r):(n=u(i,{rel:l,target:s,title:o}),r.insertAfter(n),n.append(r))}})}const m=/^\+?[0-9\s()-]{5,}$/;function x(e){return e.match(/^[a-z][a-z0-9+.-]*:/i)||e.match(/^[/#.]/)?e:e.includes("@")?`mailto:${e}`:m.test(e)?`tel:${e}`:`https://${e}`}const N={attributes:void 0,validateUrl:void 0};function k(r,s){return e.mergeRegister(r.registerNodeTransform(i,l),r.registerCommand(h,e=>{const t=s.validateUrl.peek(),n=s.attributes.peek();if(null===e)return _(null),!0;if("string"==typeof e)return!(void 0!==t&&!t(e))&&(_(e,n),!0);{const{url:t,target:r,rel:i,title:s}=e;return _(t,{...n,rel:i,target:r,title:s}),!0}},t.COMMAND_PRIORITY_EDITOR),n.effect(()=>{const n=s.validateUrl.value;if(!n)return;const i=s.attributes.value;return r.registerCommand(t.PASTE_COMMAND,s=>{const o=t.$getSelection();if(!t.$isRangeSelection(o)||o.isCollapsed()||!e.objectKlassEquals(s,ClipboardEvent))return!1;if(null===s.clipboardData)return!1;const l=s.clipboardData.getData("text");return!!n(l)&&(!o.getNodes().some(e=>t.$isElementNode(e))&&(r.dispatchCommand(h,{...i,url:l}),s.preventDefault(),!0))},t.COMMAND_PRIORITY_LOW)}))}const $=t.defineExtension({build:(e,t,r)=>n.namedSignals(t),config:N,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)=>k(e,n.getOutput())});function S(n,r,i={}){const s=i=>{const s=i.target;if(!t.isDOMNode(s))return;const o=t.getNearestEditorFromDOMNode(s);if(null===o)return;let l=null,a=null;if(o.update(()=>{const n=t.$getNearestNodeFromDOMNode(s);if(null!==n){const i=e.$findMatchingParent(n,t.$isElementNode);if(!r.disabled.peek())if(c(i))l=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&&(l=t.href,a=t.target)}}}),null===l||""===l)return;const u=n.getEditorState().read(t.$getSelection);if(t.$isRangeSelection(u)&&!u.isCollapsed())return void i.preventDefault();const g="auxclick"===i.type&&1===i.button;window.open(l,r.newTab.peek()||g||i.metaKey||i.ctrlKey||"_blank"===a?"_blank":"_self"),i.preventDefault()},o=e=>{1===e.button&&s(e)};return n.registerRootListener(e=>{if(e)return e.addEventListener("click",s,i),e.addEventListener("mouseup",o,i),()=>{e.removeEventListener("click",s),e.removeEventListener("mouseup",o)}})}const L=t.defineExtension({build:(e,t,r)=>n.namedSignals(t),config:t.safeCast({disabled:!1,newTab:!1}),dependencies:[$],name:"@lexical/link/ClickableLink",register:(e,t,n)=>S(e,n.getOutput())});function T(e,t){for(let n=0;n<t.length;n++){const r=t[n](e);if(r)return r}return null}const C=/[.,;\s]/;function b(e){return C.test(e)}function v(e){return b(e[e.length-1])}function E(e){return b(e[0])}function U(e){let n=e.getPreviousSibling();return t.$isElementNode(n)&&(n=n.getLastDescendant()),null===n||t.$isLineBreakNode(n)||t.$isTextNode(n)&&v(n.getTextContent())}function R(e){let n=e.getNextSibling();return t.$isElementNode(n)&&(n=n.getFirstDescendant()),null===n||t.$isLineBreakNode(n)||t.$isTextNode(n)&&E(n.getTextContent())}function O(e,t,n,r){if(!(e>0?b(n[e-1]):U(r[0])))return!1;return t<n.length?b(n[t]):R(r[r.length-1])}function M(e,t,n){const r=[],i=[],s=[];let o=0,l=0;const a=[...e];for(;a.length>0;){const e=a[0],u=e.getTextContent().length,c=l;l+u<=t?(r.push(e),o+=u):c>=n?s.push(e):i.push(e),l+=u,a.shift()}return[o,r,i,s]}function P(e,n,r,i){const s=d(i.url,i.attributes);if(1===e.length){let o,l=e[0];0===n?[o,l]=l.splitText(r):[,o,l]=l.splitText(n,r);const a=t.$createTextNode(i.text);return a.setFormat(o.getFormat()),a.setDetail(o.getDetail()),a.setStyle(o.getStyle()),s.append(a),o.replace(s),l}if(e.length>1){const i=e[0];let o,l=i.getTextContent().length;0===n?o=i:[,o]=i.splitText(n);const a=[];let u;for(let t=1;t<e.length;t++){const n=e[t],i=n.getTextContent().length,s=l;if(s<r)if(l+i<=r)a.push(n);else{const[e,t]=n.splitText(r-s);a.push(e),u=t}l+=i}const c=t.$getSelection(),g=c?c.getNodes().find(t.$isTextNode):void 0,d=t.$createTextNode(o.getTextContent());return d.setFormat(o.getFormat()),d.setDetail(o.getDetail()),d.setStyle(o.getStyle()),s.append(d,...a),g&&g===o&&(t.$isRangeSelection(c)?d.select(c.anchor.offset,c.focus.offset):t.$isNodeSelection(c)&&d.select(0,d.getTextContent().length)),o.replace(s),u}}function A(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 y(e),void r(null,e.getURL())}const o=e.getTextContent(),l=T(o,n);if(null===l||l.text!==o)return y(e),void r(null,e.getURL());if(!U(e)||!R(e))return y(e),void r(null,e.getURL());const a=e.getURL();if(a!==l.url&&(e.setURL(l.url),r(l.url,a)),l.attributes){const t=e.getRel();t!==l.attributes.rel&&(e.setRel(l.attributes.rel||null),r(l.attributes.rel||null,t));const n=e.getTarget();n!==l.attributes.target&&(e.setTarget(l.attributes.target||null),r(l.attributes.target||null,n))}}function y(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 D={changeHandlers:[],excludeParents:[],matchers:[]};function I(n,r=D){const{matchers:i,changeHandlers:s,excludeParents:o}=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(f(n))A(n,i,l);else if(!c(n)&&!o.some(e=>e(n))){if(e.isSimpleText()&&(E(e.getTextContent())||!f(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){for(const t of e){const e=t.getParent();if(f(e)&&!e.getIsUnlinked())return}let r=[...e];const i=r.map(e=>e.getTextContent()).join("");let s,o=i,l=0;for(;(s=T(o,t))&&null!==s;){const e=s.index,t=e+s.length;if(O(l+e,l+t,i,r)){const[i,,a,u]=M(r,l+e,l+t);let c=!1;for(const e of a){const t=e.getParent();if(f(t)&&!t.getIsUnlinked()){c=!0;break}}if(c){l+=t,o=o.substring(t);continue}const g=P(a,l+e-i,l+t-i,s);r=g?[g,...u]:u,n(s.url,null),l=0}else l+=t;o=o.substring(t)}}(n,i,l)}!function(e,t,n){const r=e.getParent(),i=e.getPreviousSibling(),s=e.getNextSibling(),o=e.getTextContent();if(!f(r)||r.getIsUnlinked()){if(f(i)&&!i.getIsUnlinked()&&i.is(e.getPreviousSibling())&&e.getParent()===i.getParent()){if(!E(o))return y(i),void n(null,i.getURL());if(l=o,i.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(l):/^\.[a-zA-Z0-9]{1,}/.test(l)){const r=i.getTextContent()+o,s=T(r,t);null!==s&&s.text===r&&(i.append(e),A(i,t,n),n(null,i.getURL()))}}var l;!f(s)||s.getIsUnlinked()||v(o)||s.is(e.getNextSibling())&&e.getParent()===s.getParent()&&(y(s),n(null,s.getURL()))}}(e,i,l)}}),n.registerCommand(h,e=>{const n=t.$getSelection();if(null!==e||!t.$isRangeSelection(n))return!1;return n.extract().forEach(e=>{const t=e.getParent();f(t)&&(t.setIsUnlinked(!t.getIsUnlinked()),t.markDirty())}),!1},t.COMMAND_PRIORITY_LOW))}const w=t.defineExtension({config:D,dependencies:[$],mergeConfig(e,n){const r=t.shallowMergeConfig(e,n);for(const t of["matchers","changeHandlers","excludeParents"]){const i=n[t];Array.isArray(i)&&(r[t]=[...e[t],...i])}return r},name:"@lexical/link/AutoLink",nodes:[g],register:I}),F=_;exports.$createAutoLinkNode=d,exports.$createLinkNode=u,exports.$isAutoLinkNode=f,exports.$isLinkNode=c,exports.$toggleLink=_,exports.AutoLinkExtension=w,exports.AutoLinkNode=g,exports.ClickableLinkExtension=L,exports.LinkExtension=$,exports.LinkNode=i,exports.TOGGLE_LINK_COMMAND=h,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=x,exports.registerAutoLink=I,exports.registerClickableLink=S,exports.registerLink=k,exports.toggleLink=F;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{addClassNamesToElement as t,isHTMLAnchorElement as e,$findMatchingParent as n,$insertNodeToNearestRootAtCaret as r,mergeRegister as i,objectKlassEquals as s}from"@lexical/utils";import{ElementNode as l,$copyNode as o,$isRangeSelection as u,$applyNodeReplacement as a,createCommand as c,$getSelection as g,$isNodeSelection as f,$normalizeSelection__EXPERIMENTAL as d,$setSelection as h,$getChildCaret as _,$isElementNode as p,$rewindSiblingCaret as m,$caretFromPoint as x,$normalizeCaret as k,$setPointFromCaret as v,defineExtension as b,shallowMergeConfig as U,COMMAND_PRIORITY_EDITOR as T,PASTE_COMMAND as L,COMMAND_PRIORITY_LOW as C,safeCast as S,isDOMNode as O,getNearestEditorFromDOMNode as y,$getNearestNodeFromDOMNode as N,TextNode as P,$isTextNode as R,$isLineBreakNode as A,$createTextNode as D}from"lexical";import{namedSignals as E,effect as I}from"@lexical/extension";const w=new Set(["http:","https:","mailto:","sms:","tel:"]);class M extends l{__url;__target;__rel;__title;static getType(){return"link"}static clone(t){return new M(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t="",e={},n){super(n);const{target:r=null,rel:i=null,title:s=null}=e;this.__url=t,this.__target=r,this.__rel=i,this.__title=s}afterCloneFrom(t){super.afterCloneFrom(t),this.__url=t.__url,this.__rel=t.__rel,this.__target=t.__target,this.__title=t.__title}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:B,priority:1})}}static importJSON(t){return K().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=V(t);try{const e=new URL(V(t));if(!w.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=o(this);return this.insertAfter(n,e),n}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,e,n){if(!u(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://")}shouldMergeAdjacentLink(t){return this.getType()===t.getType()&&this.__url===t.__url&&this.__target===t.__target&&this.__rel===t.__rel&&this.__title===t.__title}}function F(t){const e=x(t,"next");return[e,e.getFlipped()]}function J(t,e){for(const n of e)if(n.origin.isAttached()){const e=k(n);return void v(t,e)}}function W(t){const e=g();let n=null,i=null;function s(){u(e)&&(J(e.anchor,n),J(e.focus,i),d(e))}u(e)&&(n=F(e.anchor),i=F(e.focus));let l=!1;for(const e of _(t,"next")){const n=e.origin;if(p(n)&&!n.isInline()){const i=n.getChildren();if(i.length>0){const e=o(t);e.append(...i),n.append(e),l=!0}r(n,m(e),{$shouldSplit:()=>!1})}}if(t.isAttached()){const e=t.getPreviousSibling();if($(e)&&e.shouldMergeAdjacentLink(t))return e.append(...t.getChildren()),t.remove(),void s();const n=t.getNextSibling();$(n)&&t.shouldMergeAdjacentLink(n)&&(t.append(...n.getChildren()),n.remove(),l=!0)}if(l){if(!t.canBeEmpty()&&t.isEmpty()){const e=t.getParent();t.remove(),e&&e.isEmpty()&&e.remove()}s()}}function B(t){let n=null;if(e(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(n=K(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:n}}function K(t="",e){return a(new M(t,e))}function $(t){return t instanceof M}class z extends M{__isUnlinked;constructor(t="",e={},n){super(t,e,n),this.__isUnlinked=void 0!==e.isUnlinked&&null!==e.isUnlinked&&e.isUnlinked}afterCloneFrom(t){super.afterCloneFrom(t),this.__isUnlinked=t.__isUnlinked}static getType(){return"autolink"}static clone(t){return new z(t.__url,{isUnlinked:t.__isUnlinked,rel:t.__rel,target:t.__target,title:t.__title},t.__key)}shouldMergeAdjacentLink(t){return!1}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 j().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=j(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(n,e),n}}function j(t="",e){return a(new z(t,e))}function H(t){return t instanceof z}const G=c("TOGGLE_LINK_COMMAND");function Z(t,e){if("element"===t.type){const n=t.getNode();p(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 q(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:s}=e,l=void 0===e.rel?"noreferrer":e.rel,a=g();if(null===a||!u(a)&&!f(a))return;if(f(a)){const t=a.getNodes();if(0===t.length)return;return void t.forEach(t=>{if(null===r){const e=n(t,t=>!H(t)&&$(t));e&&(e.insertBefore(t),0===e.getChildren().length&&e.remove())}else{const e=n(t,t=>!H(t)&&$(t));if(e)e.setURL(r),void 0!==i&&e.setTarget(i),void 0!==l&&e.setRel(l);else{const e=K(r,{rel:l,target:i});t.insertBefore(e),e.append(t)}}})}if(a.isCollapsed()&&null===r)for(const t of a.getNodes()){const e=n(t,t=>!H(t)&&$(t));return void(null!==e&&(e.getChildren().forEach(t=>{e.insertBefore(t)}),e.remove()))}const c=a.extract();if(null===r){const t=new Set;return void c.forEach(e=>{const r=n(e,t=>!H(t)&&$(t));if(null!==r){const e=r.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=>n.has(r.getKey())||p(r)&&e.some(e=>t.isParentOf(e)&&r.isParentOf(e)),s=r.filter(i);if(s.length===r.length)return r.forEach(e=>t.insertBefore(e)),void t.remove();const l=r.findIndex(i),u=r.findLastIndex(i),a=0===l,c=u===r.length-1;if(a)s.forEach(e=>t.insertBefore(e));else if(c)for(let e=s.length-1;e>=0;e--)t.insertAfter(s[e]);else{for(let e=s.length-1;e>=0;e--)t.insertAfter(s[e]);const e=r.slice(u+1);if(e.length>0){const n=o(t);s[s.length-1].insertAfter(n),e.forEach(t=>n.append(t))}}}(r,c),t.add(e)}})}const _=new Set,m=t=>{_.has(t.getKey())||(_.add(t.getKey()),t.setURL(r),void 0!==i&&t.setTarget(i),void 0!==l&&t.setRel(l),void 0!==s&&t.setTitle(s))};if(1===c.length){const t=c[0],e=n(t,$);if(null!==e)return m(e)}!function(t){const e=g();if(!u(e))return t();const n=d(e),r=n.isBackward(),i=Z(n.anchor,r?-1:0),s=Z(n.focus,r?0:-1),l=t();if(i||s){const t=g();if(u(t)){const e=t.clone();if(i){const t=i.getParent();t&&e.anchor.set(t.getKey(),i.getIndexWithinParent()+(r?1:0),"element")}if(s){const t=s.getParent();t&&e.focus.set(t.getKey(),s.getIndexWithinParent()+(r?0:1),"element")}h(d(e))}}}(()=>{let t=null;for(const e of c){if(!e.isAttached())continue;const o=n(e,$);if(o){m(o);continue}if(p(e)){if(!e.isInline())continue;if($(e)){if(!(H(e)||null!==t&&t.getParentOrThrow().isParentOf(e))){m(e),t=e;continue}for(const t of e.getChildren())e.insertBefore(t);e.remove();continue}}const u=e.getPreviousSibling();$(u)&&u.is(t)?u.append(e):(t=K(r,{rel:l,target:i,title:s}),e.insertAfter(t),t.append(e))}})}const Q=/^\+?[0-9\s()-]{5,}$/;function V(t){return t.match(/^[a-z][a-z0-9+.-]*:/i)||t.match(/^[/#.]/)?t:t.includes("@")?`mailto:${t}`:Q.test(t)?`tel:${t}`:`https://${t}`}function X(t,e){return i(t.registerNodeTransform(M,W),t.registerCommand(G,t=>{const n=e.validateUrl.peek(),r=e.attributes.peek();if(null===t)return q(null),!0;if("string"==typeof t)return!(void 0!==n&&!n(t))&&(q(t,r),!0);{const{url:e,target:n,rel:i,title:s}=t;return q(e,{...r,rel:i,target:n,title:s}),!0}},T),I(()=>{const n=e.validateUrl.value;if(!n)return;const r=e.attributes.value;return t.registerCommand(L,e=>{const i=g();if(!u(i)||i.isCollapsed()||!s(e,ClipboardEvent))return!1;if(null===e.clipboardData)return!1;const l=e.clipboardData.getData("text");return!!n(l)&&(!i.getNodes().some(t=>p(t))&&(t.dispatchCommand(G,{...r,url:l}),e.preventDefault(),!0))},C)}))}const Y=b({build:(t,e,n)=>E(e),config:{attributes:void 0,validateUrl:void 0},mergeConfig(t,e){const n=U(t,e);return t.attributes&&(n.attributes=U(t.attributes,n.attributes)),n},name:"@lexical/link/Link",nodes:()=>[M],register:(t,e,n)=>X(t,n.getOutput())});function tt(t,r,i={}){const s=i=>{const s=i.target;if(!O(s))return;const l=y(s);if(null===l)return;let o=null,a=null;if(l.update(()=>{const t=N(s);if(null!==t){const i=n(t,p);if(!r.disabled.peek())if($(i))o=i.sanitizeUrl(i.getURL()),a=i.getTarget();else{const t=function(t,e){let n=t;for(;null!=n;){if(e(n))return n;n=n.parentNode}return null}(s,e);null!==t&&(o=t.href,a=t.target)}}}),null===o||""===o)return;const c=t.getEditorState().read(g);if(u(c)&&!c.isCollapsed())return void i.preventDefault();const f="auxclick"===i.type&&1===i.button;window.open(o,r.newTab.peek()||f||i.metaKey||i.ctrlKey||"_blank"===a?"_blank":"_self"),i.preventDefault()},l=t=>{1===t.button&&s(t)};return t.registerRootListener(t=>{if(t)return t.addEventListener("click",s,i),t.addEventListener("mouseup",l,i),()=>{t.removeEventListener("click",s),t.removeEventListener("mouseup",l)}})}const et=b({build:(t,e,n)=>E(e),config:S({disabled:!1,newTab:!1}),dependencies:[Y],name:"@lexical/link/ClickableLink",register:(t,e,n)=>tt(t,n.getOutput())});function nt(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 rt(t,e){for(let n=0;n<e.length;n++){const r=e[n](t);if(r)return r}return null}const it=/[.,;\s]/;function st(t){return it.test(t)}function lt(t){return st(t[t.length-1])}function ot(t){return st(t[0])}function ut(t){let e=t.getPreviousSibling();return p(e)&&(e=e.getLastDescendant()),null===e||A(e)||R(e)&&lt(e.getTextContent())}function at(t){let e=t.getNextSibling();return p(e)&&(e=e.getFirstDescendant()),null===e||A(e)||R(e)&&ot(e.getTextContent())}function ct(t,e,n,r){if(!(t>0?st(n[t-1]):ut(r[0])))return!1;return e<n.length?st(n[e]):at(r[r.length-1])}function gt(t,e,n){const r=[],i=[],s=[];let l=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),l+=a):c>=n?s.push(t):i.push(t),o+=a,u.shift()}return[l,r,i,s]}function ft(t,e,n,r){const i=j(r.url,r.attributes);if(1===t.length){let s,l=t[0];0===e?[s,l]=l.splitText(n):[,s,l]=l.splitText(e,n);const o=D(r.text);return o.setFormat(s.getFormat()),o.setDetail(s.getDetail()),o.setStyle(s.getStyle()),i.append(o),s.replace(i),l}if(t.length>1){const r=t[0];let s,l=r.getTextContent().length;0===e?s=r:[,s]=r.splitText(e);const o=[];let a;for(let e=1;e<t.length;e++){const r=t[e],i=r.getTextContent().length,s=l;if(s<n)if(l+i<=n)o.push(r);else{const[t,e]=r.splitText(n-s);o.push(t),a=e}l+=i}const c=g(),d=c?c.getNodes().find(R):void 0,h=D(s.getTextContent());return h.setFormat(s.getFormat()),h.setDetail(s.getDetail()),h.setStyle(s.getStyle()),i.append(h,...o),d&&d===s&&(u(c)?h.select(c.anchor.offset,c.focus.offset):f(c)&&h.select(0,h.getTextContent().length)),s.replace(i),a}}function dt(t,e,n){const r=t.getChildren(),i=r.length;for(let e=0;e<i;e++){const i=r[e];if(!R(i)||!i.isSimpleText())return ht(t),void n(null,t.getURL())}const s=t.getTextContent(),l=rt(s,e);if(null===l||l.text!==s)return ht(t),void n(null,t.getURL());if(!ut(t)||!at(t))return ht(t),void n(null,t.getURL());const o=t.getURL();if(o!==l.url&&(t.setURL(l.url),n(l.url,o)),l.attributes){const e=t.getRel();e!==l.attributes.rel&&(t.setRel(l.attributes.rel||null),n(l.attributes.rel||null,e));const r=t.getTarget();r!==l.attributes.target&&(t.setTarget(l.attributes.target||null),n(l.attributes.target||null,r))}}function ht(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 _t={changeHandlers:[],excludeParents:[],matchers:[]};function pt(t,e=_t){const{matchers:n,changeHandlers:r,excludeParents:s}=e,l=(t,e)=>{for(const n of r)n(t,e)};return i(t.registerNodeTransform(P,t=>{const e=t.getParentOrThrow(),r=t.getPreviousSibling();if(H(e))dt(e,n,l);else if(!$(e)&&!s.some(t=>t(e))){if(t.isSimpleText()&&(ot(t.getTextContent())||!H(r))){const e=function(t){const e=[t];let n=t.getNextSibling();for(;null!==n&&R(n)&&n.isSimpleText()&&(e.push(n),!/[\s]/.test(n.getTextContent()));)n=n.getNextSibling();return e}(t);!function(t,e,n){for(const e of t){const t=e.getParent();if(H(t)&&!t.getIsUnlinked())return}let r=[...t];const i=r.map(t=>t.getTextContent()).join("");let s,l=i,o=0;for(;(s=rt(l,e))&&null!==s;){const t=s.index,e=t+s.length;if(ct(o+t,o+e,i,r)){const[i,,u,a]=gt(r,o+t,o+e);let c=!1;for(const t of u){const e=t.getParent();if(H(e)&&!e.getIsUnlinked()){c=!0;break}}if(c){o+=e,l=l.substring(e);continue}const g=ft(u,o+t-i,o+e-i,s);r=g?[g,...a]:a,n(s.url,null),o=0}else o+=e;l=l.substring(e)}}(e,n,l)}!function(t,e,n){const r=t.getParent(),i=t.getPreviousSibling(),s=t.getNextSibling(),l=t.getTextContent();if(!H(r)||r.getIsUnlinked()){if(H(i)&&!i.getIsUnlinked()&&i.is(t.getPreviousSibling())&&t.getParent()===i.getParent()){if(!ot(l))return ht(i),void n(null,i.getURL());if(o=l,i.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(o):/^\.[a-zA-Z0-9]{1,}/.test(o)){const r=i.getTextContent()+l,s=rt(r,e);null!==s&&s.text===r&&(i.append(t),dt(i,e,n),n(null,i.getURL()))}}var o;!H(s)||s.getIsUnlinked()||lt(l)||s.is(t.getNextSibling())&&t.getParent()===s.getParent()&&(ht(s),n(null,s.getURL()))}}(t,n,l)}}),t.registerCommand(G,t=>{const e=g();if(null!==t||!u(e))return!1;return e.extract().forEach(t=>{const e=t.getParent();H(e)&&(e.setIsUnlinked(!e.getIsUnlinked()),e.markDirty())}),!1},C))}const mt=b({config:_t,dependencies:[Y],mergeConfig(t,e){const n=U(t,e);for(const r of["matchers","changeHandlers","excludeParents"]){const i=e[r];Array.isArray(i)&&(n[r]=[...t[r],...i])}return n},name:"@lexical/link/AutoLink",nodes:[z],register:pt}),xt=q;export{j as $createAutoLinkNode,K as $createLinkNode,H as $isAutoLinkNode,$ as $isLinkNode,q as $toggleLink,mt as AutoLinkExtension,z as AutoLinkNode,et as ClickableLinkExtension,Y as LinkExtension,M as LinkNode,G as TOGGLE_LINK_COMMAND,nt as createLinkMatcherWithRegExp,V as formatUrl,pt as registerAutoLink,tt as registerClickableLink,X as registerLink,xt as toggleLink};
9
+ import{addClassNamesToElement as t,isHTMLAnchorElement as e,$findMatchingParent as n,$insertNodeToNearestRootAtCaret as r,mergeRegister as i,objectKlassEquals as s}from"@lexical/utils";import{ElementNode as l,$copyNode as o,$isRangeSelection as u,$applyNodeReplacement as a,createCommand as c,$getSelection as g,$isNodeSelection as f,$normalizeSelection__EXPERIMENTAL as d,$setSelection as h,$getChildCaret as _,$isElementNode as p,$rewindSiblingCaret as m,$caretFromPoint as x,$normalizeCaret as k,$isSiblingCaret as v,$setPointFromCaret as b,defineExtension as U,shallowMergeConfig as T,COMMAND_PRIORITY_EDITOR as L,PASTE_COMMAND as C,COMMAND_PRIORITY_LOW as S,safeCast as O,isDOMNode as y,getNearestEditorFromDOMNode as N,$getNearestNodeFromDOMNode as P,TextNode as R,$isTextNode as A,$isLineBreakNode as D,$createTextNode as E}from"lexical";import{namedSignals as I,effect as w}from"@lexical/extension";const M=new Set(["http:","https:","mailto:","sms:","tel:"]);class F extends l{__url;__target;__rel;__title;static getType(){return"link"}static clone(t){return new F(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t="",e={},n){super(n);const{target:r=null,rel:i=null,title:s=null}=e;this.__url=t,this.__target=r,this.__rel=i,this.__title=s}afterCloneFrom(t){super.afterCloneFrom(t),this.__url=t.__url,this.__rel=t.__rel,this.__target=t.__target,this.__title=t.__title}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:K,priority:1})}}static importJSON(t){return $().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=X(t);try{const e=new URL(X(t));if(!M.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=o(this);return this.insertAfter(n,e),n}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,e,n){if(!u(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://")}shouldMergeAdjacentLink(t){return this.getType()===t.getType()&&this.__url===t.__url&&this.__target===t.__target&&this.__rel===t.__rel&&this.__title===t.__title}}function J(t){const e=x(t,"next");return[e,e.getFlipped()]}function W(t,e){for(const n of e)if(n.origin.isAttached()){const e=k(n);return void b(t,e)}}function B(t){const e=g();let n=null,i=null;function s(){u(e)&&(W(e.anchor,n),W(e.focus,i),d(e))}u(e)&&(n=J(e.anchor),i=J(e.focus));let l=!1;for(const e of _(t,"next")){const n=e.origin;if(p(n)&&!n.isInline()){const i=n.getChildren();if(i.length>0){const e=o(t);e.append(...i),n.append(e),l=!0}r(n,m(e),{$shouldSplit:()=>!1})}}function a(t,e,n){const[r,i]=t,s=t=>v(t)&&t.origin.is(e);if(!s(r)&&!s(i))return t;const l=k(_(n,"next"));return[l,l.getFlipped()]}if(t.isAttached()){const e=t.getPreviousSibling();if(z(e)&&e.shouldMergeAdjacentLink(t))return n&&(n=a(n,e,t)),i&&(i=a(i,e,t)),e.append(...t.getChildren()),t.remove(),void s();const r=t.getNextSibling();z(r)&&t.shouldMergeAdjacentLink(r)&&(n&&(n=a(n,t,r)),i&&(i=a(i,t,r)),t.append(...r.getChildren()),r.remove(),l=!0)}if(l){if(!t.canBeEmpty()&&t.isEmpty()){const e=t.getParent();t.remove(),e&&e.isEmpty()&&e.remove()}s()}}function K(t){let n=null;if(e(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(n=$(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:n}}function $(t="",e){return a(new F(t,e))}function z(t){return t instanceof F}class j extends F{__isUnlinked;constructor(t="",e={},n){super(t,e,n),this.__isUnlinked=void 0!==e.isUnlinked&&null!==e.isUnlinked&&e.isUnlinked}afterCloneFrom(t){super.afterCloneFrom(t),this.__isUnlinked=t.__isUnlinked}static getType(){return"autolink"}static clone(t){return new j(t.__url,{isUnlinked:t.__isUnlinked,rel:t.__rel,target:t.__target,title:t.__title},t.__key)}shouldMergeAdjacentLink(t){return!1}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 H().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=H(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(n,e),n}}function H(t="",e){return a(new j(t,e))}function G(t){return t instanceof j}const Z=c("TOGGLE_LINK_COMMAND");function q(t,e){if("element"===t.type){const n=t.getNode();p(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 Q(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:s}=e,l=void 0===e.rel?"noreferrer":e.rel,a=g();if(null===a||!u(a)&&!f(a))return;if(f(a)){const t=a.getNodes();if(0===t.length)return;return void t.forEach(t=>{if(null===r){const e=n(t,t=>!G(t)&&z(t));e&&(e.insertBefore(t),0===e.getChildren().length&&e.remove())}else{const e=n(t,t=>!G(t)&&z(t));if(e)e.setURL(r),void 0!==i&&e.setTarget(i),void 0!==l&&e.setRel(l);else{const e=$(r,{rel:l,target:i});t.insertBefore(e),e.append(t)}}})}if(a.isCollapsed()&&null===r)for(const t of a.getNodes()){const e=n(t,t=>!G(t)&&z(t));return void(null!==e&&(e.getChildren().forEach(t=>{e.insertBefore(t)}),e.remove()))}const c=a.extract();if(null===r){const t=new Set;return void c.forEach(e=>{const r=n(e,t=>!G(t)&&z(t));if(null!==r){const e=r.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=>n.has(r.getKey())||p(r)&&e.some(e=>t.isParentOf(e)&&r.isParentOf(e)),s=r.filter(i);if(s.length===r.length)return r.forEach(e=>t.insertBefore(e)),void t.remove();const l=r.findIndex(i),u=r.findLastIndex(i),a=0===l,c=u===r.length-1;if(a)s.forEach(e=>t.insertBefore(e));else if(c)for(let e=s.length-1;e>=0;e--)t.insertAfter(s[e]);else{for(let e=s.length-1;e>=0;e--)t.insertAfter(s[e]);const e=r.slice(u+1);if(e.length>0){const n=o(t);s[s.length-1].insertAfter(n),e.forEach(t=>n.append(t))}}}(r,c),t.add(e)}})}const _=new Set,m=t=>{_.has(t.getKey())||(_.add(t.getKey()),t.setURL(r),void 0!==i&&t.setTarget(i),void 0!==l&&t.setRel(l),void 0!==s&&t.setTitle(s))};if(1===c.length){const t=c[0],e=n(t,z);if(null!==e)return m(e)}!function(t){const e=g();if(!u(e))return t();const n=d(e),r=n.isBackward(),i=q(n.anchor,r?-1:0),s=q(n.focus,r?0:-1),l=t();if(i||s){const t=g();if(u(t)){const e=t.clone();if(i){const t=i.getParent();t&&e.anchor.set(t.getKey(),i.getIndexWithinParent()+(r?1:0),"element")}if(s){const t=s.getParent();t&&e.focus.set(t.getKey(),s.getIndexWithinParent()+(r?0:1),"element")}h(d(e))}}}(()=>{let t=null;for(const e of c){if(!e.isAttached())continue;const o=n(e,z);if(o){m(o);continue}if(p(e)){if(!e.isInline())continue;if(z(e)){if(!(G(e)||null!==t&&t.getParentOrThrow().isParentOf(e))){m(e),t=e;continue}for(const t of e.getChildren())e.insertBefore(t);e.remove();continue}}const u=e.getPreviousSibling();z(u)&&u.is(t)?u.append(e):(t=$(r,{rel:l,target:i,title:s}),e.insertAfter(t),t.append(e))}})}const V=/^\+?[0-9\s()-]{5,}$/;function X(t){return t.match(/^[a-z][a-z0-9+.-]*:/i)||t.match(/^[/#.]/)?t:t.includes("@")?`mailto:${t}`:V.test(t)?`tel:${t}`:`https://${t}`}function Y(t,e){return i(t.registerNodeTransform(F,B),t.registerCommand(Z,t=>{const n=e.validateUrl.peek(),r=e.attributes.peek();if(null===t)return Q(null),!0;if("string"==typeof t)return!(void 0!==n&&!n(t))&&(Q(t,r),!0);{const{url:e,target:n,rel:i,title:s}=t;return Q(e,{...r,rel:i,target:n,title:s}),!0}},L),w(()=>{const n=e.validateUrl.value;if(!n)return;const r=e.attributes.value;return t.registerCommand(C,e=>{const i=g();if(!u(i)||i.isCollapsed()||!s(e,ClipboardEvent))return!1;if(null===e.clipboardData)return!1;const l=e.clipboardData.getData("text");return!!n(l)&&(!i.getNodes().some(t=>p(t))&&(t.dispatchCommand(Z,{...r,url:l}),e.preventDefault(),!0))},S)}))}const tt=U({build:(t,e,n)=>I(e),config:{attributes:void 0,validateUrl:void 0},mergeConfig(t,e){const n=T(t,e);return t.attributes&&(n.attributes=T(t.attributes,n.attributes)),n},name:"@lexical/link/Link",nodes:()=>[F],register:(t,e,n)=>Y(t,n.getOutput())});function et(t,r,i={}){const s=i=>{const s=i.target;if(!y(s))return;const l=N(s);if(null===l)return;let o=null,a=null;if(l.update(()=>{const t=P(s);if(null!==t){const i=n(t,p);if(!r.disabled.peek())if(z(i))o=i.sanitizeUrl(i.getURL()),a=i.getTarget();else{const t=function(t,e){let n=t;for(;null!=n;){if(e(n))return n;n=n.parentNode}return null}(s,e);null!==t&&(o=t.href,a=t.target)}}}),null===o||""===o)return;const c=t.getEditorState().read(g);if(u(c)&&!c.isCollapsed())return void i.preventDefault();const f="auxclick"===i.type&&1===i.button;window.open(o,r.newTab.peek()||f||i.metaKey||i.ctrlKey||"_blank"===a?"_blank":"_self"),i.preventDefault()},l=t=>{1===t.button&&s(t)};return t.registerRootListener(t=>{if(t)return t.addEventListener("click",s,i),t.addEventListener("mouseup",l,i),()=>{t.removeEventListener("click",s),t.removeEventListener("mouseup",l)}})}const nt=U({build:(t,e,n)=>I(e),config:O({disabled:!1,newTab:!1}),dependencies:[tt],name:"@lexical/link/ClickableLink",register:(t,e,n)=>et(t,n.getOutput())});function rt(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 it(t,e){for(let n=0;n<e.length;n++){const r=e[n](t);if(r)return r}return null}const st=/[.,;\s]/;function lt(t){return st.test(t)}function ot(t){return lt(t[t.length-1])}function ut(t){return lt(t[0])}function at(t){let e=t.getPreviousSibling();return p(e)&&(e=e.getLastDescendant()),null===e||D(e)||A(e)&&ot(e.getTextContent())}function ct(t){let e=t.getNextSibling();return p(e)&&(e=e.getFirstDescendant()),null===e||D(e)||A(e)&&ut(e.getTextContent())}function gt(t,e,n,r){if(!(t>0?lt(n[t-1]):at(r[0])))return!1;return e<n.length?lt(n[e]):ct(r[r.length-1])}function ft(t,e,n){const r=[],i=[],s=[];let l=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),l+=a):c>=n?s.push(t):i.push(t),o+=a,u.shift()}return[l,r,i,s]}function dt(t,e,n,r){const i=H(r.url,r.attributes);if(1===t.length){let s,l=t[0];0===e?[s,l]=l.splitText(n):[,s,l]=l.splitText(e,n);const o=E(r.text);return o.setFormat(s.getFormat()),o.setDetail(s.getDetail()),o.setStyle(s.getStyle()),i.append(o),s.replace(i),l}if(t.length>1){const r=t[0];let s,l=r.getTextContent().length;0===e?s=r:[,s]=r.splitText(e);const o=[];let a;for(let e=1;e<t.length;e++){const r=t[e],i=r.getTextContent().length,s=l;if(s<n)if(l+i<=n)o.push(r);else{const[t,e]=r.splitText(n-s);o.push(t),a=e}l+=i}const c=g(),d=c?c.getNodes().find(A):void 0,h=E(s.getTextContent());return h.setFormat(s.getFormat()),h.setDetail(s.getDetail()),h.setStyle(s.getStyle()),i.append(h,...o),d&&d===s&&(u(c)?h.select(c.anchor.offset,c.focus.offset):f(c)&&h.select(0,h.getTextContent().length)),s.replace(i),a}}function ht(t,e,n){const r=t.getChildren(),i=r.length;for(let e=0;e<i;e++){const i=r[e];if(!A(i)||!i.isSimpleText())return _t(t),void n(null,t.getURL())}const s=t.getTextContent(),l=it(s,e);if(null===l||l.text!==s)return _t(t),void n(null,t.getURL());if(!at(t)||!ct(t))return _t(t),void n(null,t.getURL());const o=t.getURL();if(o!==l.url&&(t.setURL(l.url),n(l.url,o)),l.attributes){const e=t.getRel();e!==l.attributes.rel&&(t.setRel(l.attributes.rel||null),n(l.attributes.rel||null,e));const r=t.getTarget();r!==l.attributes.target&&(t.setTarget(l.attributes.target||null),n(l.attributes.target||null,r))}}function _t(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 pt={changeHandlers:[],excludeParents:[],matchers:[]};function mt(t,e=pt){const{matchers:n,changeHandlers:r,excludeParents:s}=e,l=(t,e)=>{for(const n of r)n(t,e)};return i(t.registerNodeTransform(R,t=>{const e=t.getParentOrThrow(),r=t.getPreviousSibling();if(G(e))ht(e,n,l);else if(!z(e)&&!s.some(t=>t(e))){if(t.isSimpleText()&&(ut(t.getTextContent())||!G(r))){const e=function(t){const e=[t];let n=t.getNextSibling();for(;null!==n&&A(n)&&n.isSimpleText()&&(e.push(n),!/[\s]/.test(n.getTextContent()));)n=n.getNextSibling();return e}(t);!function(t,e,n){for(const e of t){const t=e.getParent();if(G(t)&&!t.getIsUnlinked())return}let r=[...t];const i=r.map(t=>t.getTextContent()).join("");let s,l=i,o=0;for(;(s=it(l,e))&&null!==s;){const t=s.index,e=t+s.length;if(gt(o+t,o+e,i,r)){const[i,,u,a]=ft(r,o+t,o+e);let c=!1;for(const t of u){const e=t.getParent();if(G(e)&&!e.getIsUnlinked()){c=!0;break}}if(c){o+=e,l=l.substring(e);continue}const g=dt(u,o+t-i,o+e-i,s);r=g?[g,...a]:a,n(s.url,null),o=0}else o+=e;l=l.substring(e)}}(e,n,l)}!function(t,e,n){const r=t.getParent(),i=t.getPreviousSibling(),s=t.getNextSibling(),l=t.getTextContent();if(!G(r)||r.getIsUnlinked()){if(G(i)&&!i.getIsUnlinked()&&i.is(t.getPreviousSibling())&&t.getParent()===i.getParent()){if(!ut(l))return _t(i),void n(null,i.getURL());if(o=l,i.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(o):/^\.[a-zA-Z0-9]{1,}/.test(o)){const r=i.getTextContent()+l,s=it(r,e);null!==s&&s.text===r&&(i.append(t),ht(i,e,n),n(null,i.getURL()))}}var o;!G(s)||s.getIsUnlinked()||ot(l)||s.is(t.getNextSibling())&&t.getParent()===s.getParent()&&(_t(s),n(null,s.getURL()))}}(t,n,l)}}),t.registerCommand(Z,t=>{const e=g();if(null!==t||!u(e))return!1;return e.extract().forEach(t=>{const e=t.getParent();G(e)&&(e.setIsUnlinked(!e.getIsUnlinked()),e.markDirty())}),!1},S))}const xt=U({config:pt,dependencies:[tt],mergeConfig(t,e){const n=T(t,e);for(const r of["matchers","changeHandlers","excludeParents"]){const i=e[r];Array.isArray(i)&&(n[r]=[...t[r],...i])}return n},name:"@lexical/link/AutoLink",nodes:[j],register:mt}),kt=Q;export{H as $createAutoLinkNode,$ as $createLinkNode,G as $isAutoLinkNode,z as $isLinkNode,Q as $toggleLink,xt as AutoLinkExtension,j as AutoLinkNode,nt as ClickableLinkExtension,tt as LinkExtension,F as LinkNode,Z as TOGGLE_LINK_COMMAND,rt as createLinkMatcherWithRegExp,X as formatUrl,mt as registerAutoLink,et as registerClickableLink,Y as registerLink,kt as toggleLink};
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "link"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.42.1-nightly.20260408.0",
11
+ "version": "0.43.0",
12
12
  "main": "LexicalLink.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/extension": "0.42.1-nightly.20260408.0",
16
- "@lexical/utils": "0.42.1-nightly.20260408.0",
17
- "lexical": "0.42.1-nightly.20260408.0"
15
+ "@lexical/extension": "0.43.0",
16
+ "@lexical/utils": "0.43.0",
17
+ "lexical": "0.43.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",