@lexical/link 0.7.9 → 0.8.1

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.
@@ -156,7 +156,7 @@ class LinkNode extends lexical.ElementNode {
156
156
  }
157
157
  function convertAnchorElement(domNode) {
158
158
  let node = null;
159
- if (domNode instanceof HTMLAnchorElement) {
159
+ if (utils.isHTMLAnchorElement(domNode)) {
160
160
  const content = domNode.textContent;
161
161
  if (content !== null && content !== '') {
162
162
  node = $createLinkNode(domNode.getAttribute('href') || '', {
@@ -8,7 +8,7 @@
8
8
  class n extends m.ElementNode{static getType(){return"link"}static clone(a){return new n(a.__url,{rel:a.__rel,target:a.__target},a.__key)}constructor(a,b={},c){super(c);let {target:h=null,rel:e=null}=b;this.__url=a;this.__target=h;this.__rel=e}createDOM(a){let b=document.createElement("a");b.href=this.__url;null!==this.__target&&(b.target=this.__target);null!==this.__rel&&(b.rel=this.__rel);k.addClassNamesToElement(b,a.theme.link);return b}updateDOM(a,b){let c=this.__url,h=this.__target,e=this.__rel;
9
9
  c!==a.__url&&(b.href=c);h!==a.__target&&(h?b.target=h:b.removeAttribute("target"));e!==a.__rel&&(e?b.rel=e:b.removeAttribute("rel"));return!1}static importDOM(){return{a:()=>({conversion:p,priority:1})}}static importJSON(a){let b=q(a.url,{rel:a.rel,target:a.target});b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),type:"link",url:this.getURL(),version:1}}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=
10
10
  a}getTarget(){return this.getLatest().__target}setTarget(a){this.getWritable().__target=a}getRel(){return this.getLatest().__rel}setRel(a){this.getWritable().__rel=a}insertNewAfter(a,b=!0){a=this.getParentOrThrow().insertNewAfter(a,b);return m.$isElementNode(a)?(b=q(this.__url,{rel:this.__rel,target:this.__target}),a.append(b),b):null}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();
11
- let c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&0<b.getTextContent().length}}function p(a){let b=null;if(a instanceof HTMLAnchorElement){let c=a.textContent;null!==c&&""!==c&&(b=q(a.getAttribute("href")||"",{rel:a.getAttribute("rel"),target:a.getAttribute("target")}))}return{node:b}}function q(a,b){return m.$applyNodeReplacement(new n(a,b))}function r(a){return a instanceof n}
11
+ let c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&0<b.getTextContent().length}}function p(a){let b=null;if(k.isHTMLAnchorElement(a)){let c=a.textContent;null!==c&&""!==c&&(b=q(a.getAttribute("href")||"",{rel:a.getAttribute("rel"),target:a.getAttribute("target")}))}return{node:b}}function q(a,b){return m.$applyNodeReplacement(new n(a,b))}function r(a){return a instanceof n}
12
12
  class u extends n{static getType(){return"autolink"}static clone(a){return new u(a.__url,{rel:a.__rel,target:a.__target},a.__key)}static importJSON(a){let b=v(a.url,{rel:a.rel,target:a.target});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)?(b=v(this.__url,{rel:this._rel,
13
13
  target:this.__target}),a.append(b),b):null}}function v(a,b){return m.$applyNodeReplacement(new u(a,b))}let w=m.createCommand("TOGGLE_LINK_COMMAND");function x(a){return y(a,b=>r(b))}function y(a,b){for(;null!==a&&null!==(a=a.getParent())&&!b(a););return a}exports.$createAutoLinkNode=v;exports.$createLinkNode=q;exports.$isAutoLinkNode=function(a){return a instanceof u};exports.$isLinkNode=r;exports.AutoLinkNode=u;exports.LinkNode=n;exports.TOGGLE_LINK_COMMAND=w;
14
14
  exports.toggleLink=function(a,b={}){let {target:c}=b,h=void 0===b.rel?"noopener":b.rel;b=m.$getSelection();if(m.$isRangeSelection(b))if(b=b.extract(),null===a)b.forEach(l=>{l=l.getParent();if(r(l)){let d=l.getChildren();for(let f=0;f<d.length;f++)l.insertBefore(d[f]);l.remove()}});else{if(1===b.length){var e=b[0];e=r(e)?e:x(e);if(null!==e){e.setURL(a);void 0!==c&&e.setTarget(c);null!==h&&e.setRel(h);return}}let l=null,d=null;b.forEach(f=>{var g=f.getParent();if(g!==d&&null!==g&&(!m.$isElementNode(f)||
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "link"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.7.9",
11
+ "version": "0.8.1",
12
12
  "main": "LexicalLink.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.7.9"
14
+ "lexical": "0.8.1"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.7.9"
17
+ "@lexical/utils": "0.8.1"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",