@lexical/link 0.7.3 → 0.7.4
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.
- package/LexicalLink.dev.js +2 -2
- package/LexicalLink.prod.js +6 -6
- package/package.json +3 -3
package/LexicalLink.dev.js
CHANGED
|
@@ -204,7 +204,7 @@ function convertAnchorElement(domNode) {
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
function $createLinkNode(url, attributes) {
|
|
207
|
-
return new LinkNode(url, attributes);
|
|
207
|
+
return lexical.$applyNodeReplacement(new LinkNode(url, attributes));
|
|
208
208
|
}
|
|
209
209
|
function $isLinkNode(node) {
|
|
210
210
|
return node instanceof LinkNode;
|
|
@@ -263,7 +263,7 @@ class AutoLinkNode extends LinkNode {
|
|
|
263
263
|
|
|
264
264
|
}
|
|
265
265
|
function $createAutoLinkNode(url, attributes) {
|
|
266
|
-
return new AutoLinkNode(url, attributes);
|
|
266
|
+
return lexical.$applyNodeReplacement(new AutoLinkNode(url, attributes));
|
|
267
267
|
}
|
|
268
268
|
function $isAutoLinkNode(node) {
|
|
269
269
|
return node instanceof AutoLinkNode;
|
package/LexicalLink.prod.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
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
|
|
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);
|
|
7
|
+
'use strict';var k=require("@lexical/utils"),m=require("lexical");
|
|
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 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(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}
|
|
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
|
-
target:this.__target}),a.append(b),b):null}}function v(a,b){return 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
|
-
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(
|
|
15
|
-
f.isInline()))if(r(g))d=g,g.setURL(a),void 0!==c&&g.setTarget(c),null!==h&&d.setRel(h);else if(g.is(
|
|
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
|
+
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)||
|
|
15
|
+
f.isInline()))if(r(g))d=g,g.setURL(a),void 0!==c&&g.setTarget(c),null!==h&&d.setRel(h);else if(g.is(l)||(l=g,d=q(a,{rel:h,target:c}),r(g)?null===f.getPreviousSibling()?g.insertBefore(d):g.insertAfter(d):f.insertBefore(d)),r(f)){if(!f.is(d)){if(null!==d){g=f.getChildren();for(let t=0;t<g.length;t++)d.append(g[t])}f.remove()}}else null!==d&&d.append(f)})}}
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"link"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.7.
|
|
11
|
+
"version": "0.7.4",
|
|
12
12
|
"main": "LexicalLink.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.7.
|
|
14
|
+
"lexical": "0.7.4"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.7.
|
|
17
|
+
"@lexical/utils": "0.7.4"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|