@lexical/link 0.3.7 → 0.3.8

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.
@@ -219,6 +219,10 @@ function toggleLink(url) {
219
219
  });
220
220
  } else {
221
221
  // Add or merge LinkNodes
222
+ if (lexical.$isRangeSelection(sel) && sel.isCollapsed()) {
223
+ return;
224
+ }
225
+
222
226
  if (nodes.length === 1) {
223
227
  const firstNode = nodes[0]; // if the first node is a LinkNode or if its
224
228
  // parent is a LinkNode, we update the URL.
@@ -4,11 +4,11 @@
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
- 'use strict';var g=require("@lexical/utils"),k=require("lexical");
8
- class l extends k.ElementNode{static getType(){return"link"}static clone(a){return new l(a.__url,a.__key)}constructor(a,b){super(b);this.__url=a}createDOM(a){let b=document.createElement("a");b.href=this.__url;g.addClassNamesToElement(b,a.theme.link);return b}updateDOM(a,b){let f=this.__url;f!==a.__url&&(b.href=f);return!1}static importDOM(){return{a:()=>({conversion:m,priority:1})}}static importJSON(a){let b=n(a.url);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),
9
- type:"link",url:this.getURL(),version:1}}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=a}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(k.$isElementNode(a)){let b=n(this.__url);a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,b){if(!k.$isRangeSelection(b))return!1;a=b.anchor.getNode();let f=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(f)&&
7
+ 'use strict';var g=require("@lexical/utils"),h=require("lexical");
8
+ class l extends h.ElementNode{static getType(){return"link"}static clone(a){return new l(a.__url,a.__key)}constructor(a,b){super(b);this.__url=a}createDOM(a){let b=document.createElement("a");b.href=this.__url;g.addClassNamesToElement(b,a.theme.link);return b}updateDOM(a,b){let d=this.__url;d!==a.__url&&(b.href=d);return!1}static importDOM(){return{a:()=>({conversion:m,priority:1})}}static importJSON(a){let b=n(a.url);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),
9
+ type:"link",url:this.getURL(),version:1}}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=a}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(h.$isElementNode(a)){let b=n(this.__url);a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,b){if(!h.$isRangeSelection(b))return!1;a=b.anchor.getNode();let d=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(d)&&
10
10
  0<b.getTextContent().length}}function m(a){let b=null;a instanceof HTMLAnchorElement&&(b=n(a.getAttribute("href")||""));return{node:b}}function n(a){return new l(a)}function p(a){return a instanceof l}
11
- class r extends l{static getType(){return"autolink"}static clone(a){return new r(a.__url,a.__key)}static importJSON(a){let b=t(a.url);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){a=this.getParentOrThrow().insertNewAfter(a);if(k.$isElementNode(a)){let b=t(this.__url);a.append(b);return b}return null}}function t(a){return new r(a)}let u=k.createCommand();
11
+ class r extends l{static getType(){return"autolink"}static clone(a){return new r(a.__url,a.__key)}static importJSON(a){let b=t(a.url);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){a=this.getParentOrThrow().insertNewAfter(a);if(h.$isElementNode(a)){let b=t(this.__url);a.append(b);return b}return null}}function t(a){return new r(a)}let u=h.createCommand();
12
12
  exports.$createAutoLinkNode=t;exports.$createLinkNode=n;exports.$isAutoLinkNode=function(a){return a instanceof r};exports.$isLinkNode=p;exports.AutoLinkNode=r;exports.LinkNode=l;exports.TOGGLE_LINK_COMMAND=u;
13
- exports.toggleLink=function(a){var b=k.$getSelection();null!==b&&k.$setSelection(b);b=k.$getSelection();if(null!==b)if(b=b.extract(),null===a)b.forEach(h=>{h=h.getParent();if(p(h)){let c=h.getChildren();for(let d=0;d<c.length;d++)h.insertBefore(c[d]);h.remove()}});else{if(1===b.length){var f=b[0];if(p(f)){f.setURL(a);return}f=f.getParent();if(p(f)){f.setURL(a);return}}let h=null,c=null;b.forEach(d=>{var e=d.getParent();if(e!==c&&null!==e&&(!k.$isElementNode(d)||d.isInline()))if(p(e))c=e,e.setURL(a);
14
- else if(e.is(h)||(h=e,c=n(a),p(e)?null===d.getPreviousSibling()?e.insertBefore(c):e.insertAfter(c):d.insertBefore(c)),p(d)){if(!d.is(c)){if(null!==c){e=d.getChildren();for(let q=0;q<e.length;q++)c.append(e[q])}d.remove()}}else null!==c&&c.append(d)})}}
13
+ exports.toggleLink=function(a){var b=h.$getSelection();null!==b&&h.$setSelection(b);var d=h.$getSelection();if(null!==d)if(b=d.extract(),null===a)b.forEach(c=>{c=c.getParent();if(p(c)){let e=c.getChildren();for(let k=0;k<e.length;k++)c.insertBefore(e[k]);c.remove()}});else if(!h.$isRangeSelection(d)||!d.isCollapsed()){if(1===b.length){d=b[0];if(p(d)){d.setURL(a);return}d=d.getParent();if(p(d)){d.setURL(a);return}}var q=null,f=null;b.forEach(c=>{var e=c.getParent();if(e!==f&&null!==e&&(!h.$isElementNode(c)||
14
+ c.isInline()))if(p(e))f=e,e.setURL(a);else if(e.is(q)||(q=e,f=n(a),p(e)?null===c.getPreviousSibling()?e.insertBefore(f):e.insertAfter(f):c.insertBefore(f)),p(c)){if(!c.is(f)){if(null!==f){e=c.getChildren();for(let k=0;k<e.length;k++)f.append(e[k])}c.remove()}}else null!==f&&f.append(c)})}}
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "link"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.3.7",
11
+ "version": "0.3.8",
12
12
  "main": "LexicalLink.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.3.7"
14
+ "lexical": "0.3.8"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.3.7"
17
+ "@lexical/utils": "0.3.8"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",