@lexical/link 0.3.5 → 0.3.6

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.
@@ -109,13 +109,23 @@ class LinkNode extends lexical.ElementNode {
109
109
  return true;
110
110
  }
111
111
 
112
+ extractWithChild(child, selection, destination) {
113
+ if (!lexical.$isRangeSelection(selection)) {
114
+ return false;
115
+ }
116
+
117
+ const anchorNode = selection.anchor.getNode();
118
+ const focusNode = selection.focus.getNode();
119
+ return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && selection.getTextContent().length > 0;
120
+ }
121
+
112
122
  }
113
123
 
114
124
  function convertAnchorElement(domNode) {
115
125
  let node = null;
116
126
 
117
127
  if (domNode instanceof HTMLAnchorElement) {
118
- node = $createLinkNode(domNode.getAttribute('href'));
128
+ node = $createLinkNode(domNode.getAttribute('href') || '');
119
129
  }
120
130
 
121
131
  return {
@@ -4,10 +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 h=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;h.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}}function m(a){let b=null;a instanceof HTMLAnchorElement&&(b=n(a.getAttribute("href")));return{node:b}}function n(a){return new l(a)}
10
- function p(a){return a instanceof l}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}}
11
- function t(a){return new r(a)}let u=k.createCommand();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;
12
- 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(g=>{g=g.getParent();if(p(g)){let c=g.getChildren();for(let d=0;d<c.length;d++)g.insertBefore(c[d]);g.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 g=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);
13
- else if(e.is(g)||(g=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)})}}
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)&&
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();
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)})}}
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { DOMConversionMap, EditorConfig, LexicalCommand, LexicalNode, NodeKey, RangeSelection, SerializedElementNode } from 'lexical';
8
+ import type { DOMConversionMap, EditorConfig, GridSelection, LexicalCommand, LexicalNode, NodeKey, NodeSelection, RangeSelection, SerializedElementNode } from 'lexical';
9
9
  import { ElementNode, Spread } from 'lexical';
10
10
  export declare type SerializedLinkNode = Spread<{
11
11
  type: 'link';
@@ -29,6 +29,7 @@ export declare class LinkNode extends ElementNode {
29
29
  canInsertTextAfter(): false;
30
30
  canBeEmpty(): false;
31
31
  isInline(): true;
32
+ extractWithChild(child: LexicalNode, selection: RangeSelection | NodeSelection | GridSelection, destination: 'clone' | 'html'): boolean;
32
33
  }
33
34
  export declare function $createLinkNode(url: string): LinkNode;
34
35
  export declare function $isLinkNode(node: LexicalNode | null | undefined): node is LinkNode;
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "link"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.3.5",
11
+ "version": "0.3.6",
12
12
  "main": "LexicalLink.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.3.5"
14
+ "lexical": "0.3.6"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.3.5"
17
+ "@lexical/utils": "0.3.6"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",