@lexical/link 0.14.5 → 0.15.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.
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  'use strict';
8
10
 
9
11
  var utils = require('@lexical/utils');
@@ -16,6 +18,7 @@ var lexical = require('lexical');
16
18
  * LICENSE file in the root directory of this source tree.
17
19
  *
18
20
  */
21
+
19
22
  const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
20
23
 
21
24
  /** @noInheritDoc */
@@ -99,7 +102,7 @@ class LinkNode extends lexical.ElementNode {
99
102
  static importDOM() {
100
103
  return {
101
104
  a: node => ({
102
- conversion: convertAnchorElement,
105
+ conversion: $convertAnchorElement,
103
106
  priority: 1
104
107
  })
105
108
  };
@@ -196,7 +199,7 @@ class LinkNode extends lexical.ElementNode {
196
199
  return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && selection.getTextContent().length > 0;
197
200
  }
198
201
  }
199
- function convertAnchorElement(domNode) {
202
+ function $convertAnchorElement(domNode) {
200
203
  let node = null;
201
204
  if (utils.isHTMLAnchorElement(domNode)) {
202
205
  const content = domNode.textContent;
@@ -308,7 +311,7 @@ const TOGGLE_LINK_COMMAND = lexical.createCommand('TOGGLE_LINK_COMMAND');
308
311
  * @param url - The URL the link directs to.
309
312
  * @param attributes - Optional HTML a tag attributes. { target, rel, title }
310
313
  */
311
- function toggleLink(url, attributes = {}) {
314
+ function $toggleLink(url, attributes = {}) {
312
315
  const {
313
316
  target,
314
317
  title
@@ -409,6 +412,8 @@ function toggleLink(url, attributes = {}) {
409
412
  });
410
413
  }
411
414
  }
415
+ /** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
416
+ const toggleLink = $toggleLink;
412
417
  function $getAncestor(node, predicate) {
413
418
  let parent = node;
414
419
  while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
@@ -421,6 +426,7 @@ exports.$createAutoLinkNode = $createAutoLinkNode;
421
426
  exports.$createLinkNode = $createLinkNode;
422
427
  exports.$isAutoLinkNode = $isAutoLinkNode;
423
428
  exports.$isLinkNode = $isLinkNode;
429
+ exports.$toggleLink = $toggleLink;
424
430
  exports.AutoLinkNode = AutoLinkNode;
425
431
  exports.LinkNode = LinkNode;
426
432
  exports.TOGGLE_LINK_COMMAND = TOGGLE_LINK_COMMAND;
@@ -3,9 +3,11 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  import { addClassNamesToElement, isHTMLAnchorElement } from '@lexical/utils';
8
- import { createCommand, ElementNode, $applyNodeReplacement, $isRangeSelection, $isElementNode, $getSelection } from 'lexical';
10
+ import { createCommand, ElementNode, $isRangeSelection, $applyNodeReplacement, $isElementNode, $getSelection } from 'lexical';
9
11
 
10
12
  /**
11
13
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -14,6 +16,7 @@ import { createCommand, ElementNode, $applyNodeReplacement, $isRangeSelection, $
14
16
  * LICENSE file in the root directory of this source tree.
15
17
  *
16
18
  */
19
+
17
20
  const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
18
21
 
19
22
  /** @noInheritDoc */
@@ -97,7 +100,7 @@ class LinkNode extends ElementNode {
97
100
  static importDOM() {
98
101
  return {
99
102
  a: node => ({
100
- conversion: convertAnchorElement,
103
+ conversion: $convertAnchorElement,
101
104
  priority: 1
102
105
  })
103
106
  };
@@ -194,7 +197,7 @@ class LinkNode extends ElementNode {
194
197
  return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && selection.getTextContent().length > 0;
195
198
  }
196
199
  }
197
- function convertAnchorElement(domNode) {
200
+ function $convertAnchorElement(domNode) {
198
201
  let node = null;
199
202
  if (isHTMLAnchorElement(domNode)) {
200
203
  const content = domNode.textContent;
@@ -306,7 +309,7 @@ const TOGGLE_LINK_COMMAND = createCommand('TOGGLE_LINK_COMMAND');
306
309
  * @param url - The URL the link directs to.
307
310
  * @param attributes - Optional HTML a tag attributes. { target, rel, title }
308
311
  */
309
- function toggleLink(url, attributes = {}) {
312
+ function $toggleLink(url, attributes = {}) {
310
313
  const {
311
314
  target,
312
315
  title
@@ -407,6 +410,8 @@ function toggleLink(url, attributes = {}) {
407
410
  });
408
411
  }
409
412
  }
413
+ /** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
414
+ const toggleLink = $toggleLink;
410
415
  function $getAncestor(node, predicate) {
411
416
  let parent = node;
412
417
  while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
@@ -415,4 +420,4 @@ function $getAncestor(node, predicate) {
415
420
  return predicate(parent) ? parent : null;
416
421
  }
417
422
 
418
- export { $createAutoLinkNode, $createLinkNode, $isAutoLinkNode, $isLinkNode, AutoLinkNode, LinkNode, TOGGLE_LINK_COMMAND, toggleLink };
423
+ export { $createAutoLinkNode, $createLinkNode, $isAutoLinkNode, $isLinkNode, $toggleLink, AutoLinkNode, LinkNode, TOGGLE_LINK_COMMAND, toggleLink };
package/LexicalLink.js CHANGED
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  'use strict'
8
10
  const LexicalLink = process.env.NODE_ENV === 'development' ? require('./LexicalLink.dev.js') : require('./LexicalLink.prod.js');
9
11
  module.exports = LexicalLink;
@@ -80,7 +80,9 @@ declare export function $isAutoLinkNode(
80
80
  declare export var TOGGLE_LINK_COMMAND: LexicalCommand<
81
81
  string | {url: string, ...LinkAttributes} | null,
82
82
  >;
83
- declare export function toggleLink(
83
+ declare export function $toggleLink(
84
84
  url: null | string,
85
85
  attributes: LinkAttributes,
86
86
  ): void;
87
+ /** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
88
+ declare const toggleLink: typeof $toggleLink;
package/LexicalLink.mjs CHANGED
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  import * as modDev from './LexicalLink.dev.mjs';
8
10
  import * as modProd from './LexicalLink.prod.mjs';
9
11
  const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
@@ -11,6 +13,7 @@ export const $createAutoLinkNode = mod.$createAutoLinkNode;
11
13
  export const $createLinkNode = mod.$createLinkNode;
12
14
  export const $isAutoLinkNode = mod.$isAutoLinkNode;
13
15
  export const $isLinkNode = mod.$isLinkNode;
16
+ export const $toggleLink = mod.$toggleLink;
14
17
  export const AutoLinkNode = mod.AutoLinkNode;
15
18
  export const LinkNode = mod.LinkNode;
16
19
  export const TOGGLE_LINK_COMMAND = mod.TOGGLE_LINK_COMMAND;
@@ -3,12 +3,15 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalLink.dev.mjs') : import('./LexicalLink.prod.mjs'));
8
10
  export const $createAutoLinkNode = mod.$createAutoLinkNode;
9
11
  export const $createLinkNode = mod.$createLinkNode;
10
12
  export const $isAutoLinkNode = mod.$isAutoLinkNode;
11
13
  export const $isLinkNode = mod.$isLinkNode;
14
+ export const $toggleLink = mod.$toggleLink;
12
15
  export const AutoLinkNode = mod.AutoLinkNode;
13
16
  export const LinkNode = mod.LinkNode;
14
17
  export const TOGGLE_LINK_COMMAND = mod.TOGGLE_LINK_COMMAND;
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  'use strict';var l=require("@lexical/utils"),m=require("lexical");let n=new Set(["http:","https:","mailto:","sms:","tel:"]);
8
10
  class p extends m.ElementNode{static getType(){return"link"}static clone(a){return new p(a.__url,{rel:a.__rel,target:a.__target,title:a.__title},a.__key)}constructor(a,b={},e){super(e);let {target:h=null,rel:k=null,title:f=null}=b;this.__url=a;this.__target=h;this.__rel=k;this.__title=f}createDOM(a){let b=document.createElement("a");b.href=this.sanitizeUrl(this.__url);null!==this.__target&&(b.target=this.__target);null!==this.__rel&&(b.rel=this.__rel);null!==this.__title&&(b.title=this.__title);l.addClassNamesToElement(b,
9
11
  a.theme.link);return b}updateDOM(a,b){let e=this.__url,h=this.__target,k=this.__rel,f=this.__title;e!==a.__url&&(b.href=e);h!==a.__target&&(h?b.target=h:b.removeAttribute("target"));k!==a.__rel&&(k?b.rel=k:b.removeAttribute("rel"));f!==a.__title&&(f?b.title=f:b.removeAttribute("title"));return!1}static importDOM(){return{a:()=>({conversion:q,priority:1})}}static importJSON(a){let b=r(a.url,{rel:a.rel,target:a.target,title:a.title});b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);
@@ -11,7 +13,7 @@ return b}sanitizeUrl(a){try{let b=new URL(a);if(!n.has(b.protocol))return"about:
11
13
  a}insertNewAfter(a,b=!0){a=r(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});this.insertAfter(a,b);return a}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,b){if(!m.$isRangeSelection(b))return!1;a=b.anchor.getNode();let e=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(e)&&0<b.getTextContent().length}}
12
14
  function q(a){let b=null;if(l.isHTMLAnchorElement(a)){let e=a.textContent;if(null!==e&&""!==e||0<a.children.length)b=r(a.getAttribute("href")||"",{rel:a.getAttribute("rel"),target:a.getAttribute("target"),title:a.getAttribute("title")})}return{node:b}}function r(a,b){return m.$applyNodeReplacement(new p(a,b))}function u(a){return a instanceof p}
13
15
  class v extends p{static getType(){return"autolink"}static clone(a){return new v(a.__url,{rel:a.__rel,target:a.__target,title:a.__title},a.__key)}static importJSON(a){let b=w(a.url,{rel:a.rel,target:a.target,title:a.title});b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),type:"autolink",version:1}}insertNewAfter(a,b=!0){a=this.getParentOrThrow().insertNewAfter(a,b);return m.$isElementNode(a)?
14
- (b=w(this.__url,{rel:this.__rel,target:this.__target,title:this.__title}),a.append(b),b):null}}function w(a,b){return m.$applyNodeReplacement(new v(a,b))}let x=m.createCommand("TOGGLE_LINK_COMMAND");function y(a,b){for(;null!==a&&null!==a.getParent()&&!b(a);)a=a.getParentOrThrow();return b(a)?a:null}exports.$createAutoLinkNode=w;exports.$createLinkNode=r;exports.$isAutoLinkNode=function(a){return a instanceof v};exports.$isLinkNode=u;exports.AutoLinkNode=v;exports.LinkNode=p;
15
- exports.TOGGLE_LINK_COMMAND=x;
16
- exports.toggleLink=function(a,b={}){let {target:e,title:h}=b,k=void 0===b.rel?"noreferrer":b.rel;b=m.$getSelection();if(m.$isRangeSelection(b))if(b=b.extract(),null===a)b.forEach(f=>{f=f.getParent();if(u(f)){let d=f.getChildren();for(let c=0;c<d.length;c++)f.insertBefore(d[c]);f.remove()}});else{if(1===b.length){let c=y(b[0],u);if(null!==c){c.setURL(a);void 0!==e&&c.setTarget(e);null!==k&&c.setRel(k);void 0!==h&&c.setTitle(h);return}}let f=null,d=null;b.forEach(c=>{var g=c.getParent();if(g!==d&&null!==
17
- g&&(!m.$isElementNode(c)||c.isInline()))if(u(g))d=g,g.setURL(a),void 0!==e&&g.setTarget(e),null!==k&&d.setRel(k),void 0!==h&&d.setTitle(h);else if(g.is(f)||(f=g,d=r(a,{rel:k,target:e,title:h}),u(g)?null===c.getPreviousSibling()?g.insertBefore(d):g.insertAfter(d):c.insertBefore(d)),u(c)){if(!c.is(d)){if(null!==d){g=c.getChildren();for(let t=0;t<g.length;t++)d.append(g[t])}c.remove()}}else null!==d&&d.append(c)})}}
16
+ (b=w(this.__url,{rel:this.__rel,target:this.__target,title:this.__title}),a.append(b),b):null}}function w(a,b){return m.$applyNodeReplacement(new v(a,b))}let x=m.createCommand("TOGGLE_LINK_COMMAND");
17
+ function y(a,b={}){let {target:e,title:h}=b,k=void 0===b.rel?"noreferrer":b.rel;b=m.$getSelection();if(m.$isRangeSelection(b))if(b=b.extract(),null===a)b.forEach(f=>{f=f.getParent();if(u(f)){let d=f.getChildren();for(let c=0;c<d.length;c++)f.insertBefore(d[c]);f.remove()}});else{if(1===b.length){let c=z(b[0],u);if(null!==c){c.setURL(a);void 0!==e&&c.setTarget(e);null!==k&&c.setRel(k);void 0!==h&&c.setTitle(h);return}}let f=null,d=null;b.forEach(c=>{var g=c.getParent();if(g!==d&&null!==g&&(!m.$isElementNode(c)||
18
+ c.isInline()))if(u(g))d=g,g.setURL(a),void 0!==e&&g.setTarget(e),null!==k&&d.setRel(k),void 0!==h&&d.setTitle(h);else if(g.is(f)||(f=g,d=r(a,{rel:k,target:e,title:h}),u(g)?null===c.getPreviousSibling()?g.insertBefore(d):g.insertAfter(d):c.insertBefore(d)),u(c)){if(!c.is(d)){if(null!==d){g=c.getChildren();for(let t=0;t<g.length;t++)d.append(g[t])}c.remove()}}else null!==d&&d.append(c)})}}function z(a,b){for(;null!==a&&null!==a.getParent()&&!b(a);)a=a.getParentOrThrow();return b(a)?a:null}
19
+ exports.$createAutoLinkNode=w;exports.$createLinkNode=r;exports.$isAutoLinkNode=function(a){return a instanceof v};exports.$isLinkNode=u;exports.$toggleLink=y;exports.AutoLinkNode=v;exports.LinkNode=p;exports.TOGGLE_LINK_COMMAND=x;exports.toggleLink=y
@@ -3,5 +3,7 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
7
- import{addClassNamesToElement as t,isHTMLAnchorElement as e}from"@lexical/utils";import{createCommand as r,ElementNode as i,$applyNodeReplacement as n,$isRangeSelection as l,$isElementNode as s,$getSelection as u}from"lexical";const o=new Set(["http:","https:","mailto:","sms:","tel:"]);class _ extends i{static getType(){return"link"}static clone(t){return new _(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t,e={},r){super(r);const{target:i=null,rel:n=null,title:l=null}=e;this.__url=t,this.__target=i,this.__rel=n,this.__title=l}createDOM(e){const r=document.createElement("a");return r.href=this.sanitizeUrl(this.__url),null!==this.__target&&(r.target=this.__target),null!==this.__rel&&(r.rel=this.__rel),null!==this.__title&&(r.title=this.__title),t(r,e.theme.link),r}updateDOM(t,e,r){const i=this.__url,n=this.__target,l=this.__rel,s=this.__title;return i!==t.__url&&(e.href=i),n!==t.__target&&(n?e.target=n:e.removeAttribute("target")),l!==t.__rel&&(l?e.rel=l:e.removeAttribute("rel")),s!==t.__title&&(s?e.title=s:e.removeAttribute("title")),!1}static importDOM(){return{a:t=>({conversion:a,priority:1})}}static importJSON(t){const e=g(t.url,{rel:t.rel,target:t.target,title:t.title});return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}sanitizeUrl(t){try{const e=new URL(t);if(!o.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(),type:"link",url:this.getURL(),version:1}}getURL(){return this.getLatest().__url}setURL(t){this.getWritable().__url=t}getTarget(){return this.getLatest().__target}setTarget(t){this.getWritable().__target=t}getRel(){return this.getLatest().__rel}setRel(t){this.getWritable().__rel=t}getTitle(){return this.getLatest().__title}setTitle(t){this.getWritable().__title=t}insertNewAfter(t,e=!0){const r=g(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(r,e),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,e,r){if(!l(e))return!1;const i=e.anchor.getNode(),n=e.focus.getNode();return this.isParentOf(i)&&this.isParentOf(n)&&e.getTextContent().length>0}}function a(t){let r=null;if(e(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(r=g(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:r}}function g(t,e){return n(new _(t,e))}function c(t){return t instanceof _}class h extends _{static getType(){return"autolink"}static clone(t){return new h(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}static importJSON(t){const e=f(t.url,{rel:t.rel,target:t.target,title:t.title});return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),type:"autolink",version:1}}insertNewAfter(t,e=!0){const r=this.getParentOrThrow().insertNewAfter(t,e);if(s(r)){const t=f(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return r.append(t),t}return null}}function f(t,e){return n(new h(t,e))}function p(t){return t instanceof h}const d=r("TOGGLE_LINK_COMMAND");function m(t,e={}){const{target:r,title:i}=e,n=void 0===e.rel?"noreferrer":e.rel,o=u();if(!l(o))return;const _=o.extract();if(null===t)_.forEach((t=>{const e=t.getParent();if(c(e)){const t=e.getChildren();for(let r=0;r<t.length;r++)e.insertBefore(t[r]);e.remove()}}));else{if(1===_.length){const e=function(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}(_[0],c);if(null!==e)return e.setURL(t),void 0!==r&&e.setTarget(r),null!==n&&e.setRel(n),void(void 0!==i&&e.setTitle(i))}let e=null,l=null;_.forEach((u=>{const o=u.getParent();if(o!==l&&null!==o&&(!s(u)||u.isInline())){if(c(o))return l=o,o.setURL(t),void 0!==r&&o.setTarget(r),null!==n&&l.setRel(n),void(void 0!==i&&l.setTitle(i));if(o.is(e)||(e=o,l=g(t,{rel:n,target:r,title:i}),c(o)?null===u.getPreviousSibling()?o.insertBefore(l):o.insertAfter(l):u.insertBefore(l)),c(u)){if(u.is(l))return;if(null!==l){const t=u.getChildren();for(let e=0;e<t.length;e++)l.append(t[e])}u.remove()}else null!==l&&l.append(u)}}))}}export{f as $createAutoLinkNode,g as $createLinkNode,p as $isAutoLinkNode,c as $isLinkNode,h as AutoLinkNode,_ as LinkNode,d as TOGGLE_LINK_COMMAND,m as toggleLink};
8
+
9
+ import{addClassNamesToElement as t,isHTMLAnchorElement as e}from"@lexical/utils";import{createCommand as r,ElementNode as i,$isRangeSelection as n,$applyNodeReplacement as l,$isElementNode as s,$getSelection as o}from"lexical";const u=new Set(["http:","https:","mailto:","sms:","tel:"]);class _ extends i{static getType(){return"link"}static clone(t){return new _(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t,e={},r){super(r);const{target:i=null,rel:n=null,title:l=null}=e;this.__url=t,this.__target=i,this.__rel=n,this.__title=l}createDOM(e){const r=document.createElement("a");return r.href=this.sanitizeUrl(this.__url),null!==this.__target&&(r.target=this.__target),null!==this.__rel&&(r.rel=this.__rel),null!==this.__title&&(r.title=this.__title),t(r,e.theme.link),r}updateDOM(t,e,r){const i=this.__url,n=this.__target,l=this.__rel,s=this.__title;return i!==t.__url&&(e.href=i),n!==t.__target&&(n?e.target=n:e.removeAttribute("target")),l!==t.__rel&&(l?e.rel=l:e.removeAttribute("rel")),s!==t.__title&&(s?e.title=s:e.removeAttribute("title")),!1}static importDOM(){return{a:t=>({conversion:a,priority:1})}}static importJSON(t){const e=g(t.url,{rel:t.rel,target:t.target,title:t.title});return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}sanitizeUrl(t){try{const e=new URL(t);if(!u.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(),type:"link",url:this.getURL(),version:1}}getURL(){return this.getLatest().__url}setURL(t){this.getWritable().__url=t}getTarget(){return this.getLatest().__target}setTarget(t){this.getWritable().__target=t}getRel(){return this.getLatest().__rel}setRel(t){this.getWritable().__rel=t}getTitle(){return this.getLatest().__title}setTitle(t){this.getWritable().__title=t}insertNewAfter(t,e=!0){const r=g(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(r,e),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,e,r){if(!n(e))return!1;const i=e.anchor.getNode(),l=e.focus.getNode();return this.isParentOf(i)&&this.isParentOf(l)&&e.getTextContent().length>0}}function a(t){let r=null;if(e(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(r=g(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:r}}function g(t,e){return l(new _(t,e))}function c(t){return t instanceof _}class h extends _{static getType(){return"autolink"}static clone(t){return new h(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}static importJSON(t){const e=f(t.url,{rel:t.rel,target:t.target,title:t.title});return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),type:"autolink",version:1}}insertNewAfter(t,e=!0){const r=this.getParentOrThrow().insertNewAfter(t,e);if(s(r)){const t=f(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return r.append(t),t}return null}}function f(t,e){return l(new h(t,e))}function p(t){return t instanceof h}const d=r("TOGGLE_LINK_COMMAND");function m(t,e={}){const{target:r,title:i}=e,l=void 0===e.rel?"noreferrer":e.rel,u=o();if(!n(u))return;const _=u.extract();if(null===t)_.forEach((t=>{const e=t.getParent();if(c(e)){const t=e.getChildren();for(let r=0;r<t.length;r++)e.insertBefore(t[r]);e.remove()}}));else{if(1===_.length){const e=function(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}(_[0],c);if(null!==e)return e.setURL(t),void 0!==r&&e.setTarget(r),null!==l&&e.setRel(l),void(void 0!==i&&e.setTitle(i))}let e=null,n=null;_.forEach((o=>{const u=o.getParent();if(u!==n&&null!==u&&(!s(o)||o.isInline())){if(c(u))return n=u,u.setURL(t),void 0!==r&&u.setTarget(r),null!==l&&n.setRel(l),void(void 0!==i&&n.setTitle(i));if(u.is(e)||(e=u,n=g(t,{rel:l,target:r,title:i}),c(u)?null===o.getPreviousSibling()?u.insertBefore(n):u.insertAfter(n):o.insertBefore(n)),c(o)){if(o.is(n))return;if(null!==n){const t=o.getChildren();for(let e=0;e<t.length;e++)n.append(t[e])}o.remove()}else null!==n&&n.append(o)}}))}}const T=m;export{f as $createAutoLinkNode,g as $createLinkNode,p as $isAutoLinkNode,c as $isLinkNode,m as $toggleLink,h as AutoLinkNode,_ as LinkNode,d as TOGGLE_LINK_COMMAND,T as toggleLink};
package/index.d.ts CHANGED
@@ -94,4 +94,6 @@ export declare const TOGGLE_LINK_COMMAND: LexicalCommand<string | ({
94
94
  * @param url - The URL the link directs to.
95
95
  * @param attributes - Optional HTML a tag attributes. { target, rel, title }
96
96
  */
97
- export declare function toggleLink(url: null | string, attributes?: LinkAttributes): void;
97
+ export declare function $toggleLink(url: null | string, attributes?: LinkAttributes): void;
98
+ /** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
99
+ export declare const toggleLink: typeof $toggleLink;
package/package.json CHANGED
@@ -8,12 +8,12 @@
8
8
  "link"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.14.5",
11
+ "version": "0.15.0",
12
12
  "main": "LexicalLink.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/utils": "0.14.5",
16
- "lexical": "0.14.5"
15
+ "@lexical/utils": "0.15.0",
16
+ "lexical": "0.15.0"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",