@lexical/link 0.9.2 → 0.11.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.
- package/LexicalLink.dev.js +17 -2
- package/LexicalLink.prod.js +10 -10
- package/index.d.ts +1 -0
- package/package.json +3 -3
package/LexicalLink.dev.js
CHANGED
|
@@ -10,8 +10,9 @@ var utils = require('@lexical/utils');
|
|
|
10
10
|
var lexical = require('lexical');
|
|
11
11
|
|
|
12
12
|
/** @module @lexical/link */
|
|
13
|
-
|
|
13
|
+
const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
|
|
14
14
|
/** @noInheritDoc */
|
|
15
|
+
|
|
15
16
|
class LinkNode extends lexical.ElementNode {
|
|
16
17
|
/** @internal */
|
|
17
18
|
|
|
@@ -47,7 +48,7 @@ class LinkNode extends lexical.ElementNode {
|
|
|
47
48
|
|
|
48
49
|
createDOM(config) {
|
|
49
50
|
const element = document.createElement('a');
|
|
50
|
-
element.href = this.__url;
|
|
51
|
+
element.href = this.sanitizeUrl(this.__url);
|
|
51
52
|
|
|
52
53
|
if (this.__target !== null) {
|
|
53
54
|
element.target = this.__target;
|
|
@@ -123,6 +124,20 @@ class LinkNode extends lexical.ElementNode {
|
|
|
123
124
|
return node;
|
|
124
125
|
}
|
|
125
126
|
|
|
127
|
+
sanitizeUrl(url) {
|
|
128
|
+
try {
|
|
129
|
+
const parsedUrl = new URL(url); // eslint-disable-next-line no-script-url
|
|
130
|
+
|
|
131
|
+
if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {
|
|
132
|
+
return 'about:blank';
|
|
133
|
+
}
|
|
134
|
+
} catch {
|
|
135
|
+
return url;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return url;
|
|
139
|
+
}
|
|
140
|
+
|
|
126
141
|
exportJSON() {
|
|
127
142
|
return { ...super.exportJSON(),
|
|
128
143
|
rel: this.getRel(),
|
package/LexicalLink.prod.js
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
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 k=require("@lexical/utils"),n=require("lexical");
|
|
8
|
-
class
|
|
9
|
-
a.theme.link);return b}updateDOM(a,b){let d=this.__url,l=this.__target,h=this.__rel,e=this.__title;d!==a.__url&&(b.href=d);l!==a.__target&&(l?b.target=l:b.removeAttribute("target"));h!==a.__rel&&(h?b.rel=h:b.removeAttribute("rel"));e!==a.__title&&(e?b.title=e:b.removeAttribute("title"));return!1}static importDOM(){return{a:()=>({conversion:
|
|
10
|
-
return b}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(a){this.getWritable().__url=a}getTarget(){return this.getLatest().__target}setTarget(a){this.getWritable().__target=a}getRel(){return this.getLatest().__rel}setRel(a){this.getWritable().__rel=a}getTitle(){return this.getLatest().__title}setTitle(a){this.getWritable().__title=
|
|
11
|
-
this.getParentOrThrow().insertNewAfter(a,b);return n.$isElementNode(a)?(b=
|
|
12
|
-
function
|
|
13
|
-
class
|
|
14
|
-
(b=
|
|
15
|
-
exports.toggleLink=function(a,b={}){let {target:d,title:l}=b,h=void 0===b.rel?"noopener":b.rel;b=n.$getSelection();if(n.$isRangeSelection(b))if(b=b.extract(),null===a)b.forEach(m=>{m=m.getParent();if(
|
|
16
|
-
c&&null!==g&&(!n.$isElementNode(f)||f.isInline()))if(
|
|
7
|
+
'use strict';var k=require("@lexical/utils"),n=require("lexical");let p=new Set(["http:","https:","mailto:","sms:","tel:"]);
|
|
8
|
+
class q extends n.ElementNode{static getType(){return"link"}static clone(a){return new q(a.__url,{rel:a.__rel,target:a.__target,title:a.__title},a.__key)}constructor(a,b={},d){super(d);let {target:l=null,rel:h=null,title:e=null}=b;this.__url=a;this.__target=l;this.__rel=h;this.__title=e}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);k.addClassNamesToElement(b,
|
|
9
|
+
a.theme.link);return b}updateDOM(a,b){let d=this.__url,l=this.__target,h=this.__rel,e=this.__title;d!==a.__url&&(b.href=d);l!==a.__target&&(l?b.target=l:b.removeAttribute("target"));h!==a.__rel&&(h?b.rel=h:b.removeAttribute("rel"));e!==a.__title&&(e?b.title=e:b.removeAttribute("title"));return!1}static importDOM(){return{a:()=>({conversion:r,priority:1})}}static importJSON(a){let b=t(a.url,{rel:a.rel,target:a.target,title:a.title});b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);
|
|
10
|
+
return b}sanitizeUrl(a){try{let b=new URL(a);if(!p.has(b.protocol))return"about:blank"}catch{}return a}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(a){this.getWritable().__url=a}getTarget(){return this.getLatest().__target}setTarget(a){this.getWritable().__target=a}getRel(){return this.getLatest().__rel}setRel(a){this.getWritable().__rel=a}getTitle(){return this.getLatest().__title}setTitle(a){this.getWritable().__title=
|
|
11
|
+
a}insertNewAfter(a,b=!0){a=this.getParentOrThrow().insertNewAfter(a,b);return n.$isElementNode(a)?(b=t(this.__url,{rel:this.__rel,target:this.__target,title:this.__title}),a.append(b),b):null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,b){if(!n.$isRangeSelection(b))return!1;a=b.anchor.getNode();let d=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(d)&&0<b.getTextContent().length}}
|
|
12
|
+
function r(a){let b=null;if(k.isHTMLAnchorElement(a)){let d=a.textContent;null!==d&&""!==d&&(b=t(a.getAttribute("href")||"",{rel:a.getAttribute("rel"),target:a.getAttribute("target"),title:a.getAttribute("title")}))}return{node:b}}function t(a,b){return n.$applyNodeReplacement(new q(a,b))}function v(a){return a instanceof q}
|
|
13
|
+
class w extends q{static getType(){return"autolink"}static clone(a){return new w(a.__url,{rel:a.__rel,target:a.__target,title:a.__title},a.__key)}static importJSON(a){let b=x(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 n.$isElementNode(a)?
|
|
14
|
+
(b=x(this.__url,{rel:this._rel,target:this.__target,title:this.__title}),a.append(b),b):null}}function x(a,b){return n.$applyNodeReplacement(new w(a,b))}let y=n.createCommand("TOGGLE_LINK_COMMAND");function z(a,b){for(;null!==a&&null!==(a=a.getParent())&&!b(a););return a}exports.$createAutoLinkNode=x;exports.$createLinkNode=t;exports.$isAutoLinkNode=function(a){return a instanceof w};exports.$isLinkNode=v;exports.AutoLinkNode=w;exports.LinkNode=q;exports.TOGGLE_LINK_COMMAND=y;
|
|
15
|
+
exports.toggleLink=function(a,b={}){let {target:d,title:l}=b,h=void 0===b.rel?"noopener":b.rel;b=n.$getSelection();if(n.$isRangeSelection(b))if(b=b.extract(),null===a)b.forEach(m=>{m=m.getParent();if(v(m)){let c=m.getChildren();for(let f=0;f<c.length;f++)m.insertBefore(c[f]);m.remove()}});else{if(1===b.length){var e=b[0];e=v(e)?e:z(e,v);if(null!==e){e.setURL(a);void 0!==d&&e.setTarget(d);null!==h&&e.setRel(h);void 0!==l&&e.setTitle(l);return}}let m=null,c=null;b.forEach(f=>{var g=f.getParent();if(g!==
|
|
16
|
+
c&&null!==g&&(!n.$isElementNode(f)||f.isInline()))if(v(g))c=g,g.setURL(a),void 0!==d&&g.setTarget(d),null!==h&&c.setRel(h),void 0!==l&&c.setTitle(l);else if(g.is(m)||(m=g,c=t(a,{rel:h,target:d}),v(g)?null===f.getPreviousSibling()?g.insertBefore(c):g.insertAfter(c):f.insertBefore(c)),v(f)){if(!f.is(c)){if(null!==c){g=f.getChildren();for(let u=0;u<g.length;u++)c.append(g[u])}f.remove()}}else null!==c&&c.append(f)})}}
|
package/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export declare class LinkNode extends ElementNode {
|
|
|
33
33
|
updateDOM(prevNode: LinkNode, anchor: HTMLAnchorElement, config: EditorConfig): boolean;
|
|
34
34
|
static importDOM(): DOMConversionMap | null;
|
|
35
35
|
static importJSON(serializedNode: SerializedLinkNode | SerializedAutoLinkNode): LinkNode;
|
|
36
|
+
sanitizeUrl(url: string): string;
|
|
36
37
|
exportJSON(): SerializedLinkNode | SerializedAutoLinkNode;
|
|
37
38
|
getURL(): string;
|
|
38
39
|
setURL(url: string): void;
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"link"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.11.0",
|
|
12
12
|
"main": "LexicalLink.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.
|
|
14
|
+
"lexical": "0.11.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.
|
|
17
|
+
"@lexical/utils": "0.11.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|