@lexical/link 0.6.1-next.0 → 0.6.3
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 +5 -5
- package/LexicalLink.js.flow +11 -14
- package/LexicalLink.prod.js +2 -2
- package/index.d.ts +11 -23
- package/package.json +3 -3
package/LexicalLink.dev.js
CHANGED
|
@@ -271,9 +271,9 @@ function $isAutoLinkNode(node) {
|
|
|
271
271
|
const TOGGLE_LINK_COMMAND = lexical.createCommand('TOGGLE_LINK_COMMAND');
|
|
272
272
|
function toggleLink(url, attributes = {}) {
|
|
273
273
|
const {
|
|
274
|
-
target
|
|
275
|
-
rel
|
|
274
|
+
target
|
|
276
275
|
} = attributes;
|
|
276
|
+
const rel = attributes.rel === undefined ? 'noopener' : attributes.rel;
|
|
277
277
|
const selection = lexical.$getSelection();
|
|
278
278
|
|
|
279
279
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -312,7 +312,7 @@ function toggleLink(url, attributes = {}) {
|
|
|
312
312
|
linkNode.setTarget(target);
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
if (rel !==
|
|
315
|
+
if (rel !== null) {
|
|
316
316
|
linkNode.setRel(rel);
|
|
317
317
|
}
|
|
318
318
|
|
|
@@ -337,8 +337,8 @@ function toggleLink(url, attributes = {}) {
|
|
|
337
337
|
parent.setTarget(target);
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
-
if (rel !==
|
|
341
|
-
|
|
340
|
+
if (rel !== null) {
|
|
341
|
+
linkNode.setRel(rel);
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
return;
|
package/LexicalLink.js.flow
CHANGED
|
@@ -16,6 +16,10 @@ import type {
|
|
|
16
16
|
} from 'lexical';
|
|
17
17
|
import {addClassNamesToElement} from '@lexical/utils';
|
|
18
18
|
import {$isElementNode, ElementNode} from 'lexical';
|
|
19
|
+
export type LinkAttributes = {
|
|
20
|
+
rel?: null | string,
|
|
21
|
+
target?: null | string,
|
|
22
|
+
};
|
|
19
23
|
declare export class LinkNode extends ElementNode {
|
|
20
24
|
__url: string;
|
|
21
25
|
__target: null | string;
|
|
@@ -51,10 +55,7 @@ declare export class LinkNode extends ElementNode {
|
|
|
51
55
|
}
|
|
52
56
|
declare export function $createLinkNode(
|
|
53
57
|
url: string,
|
|
54
|
-
attributes?:
|
|
55
|
-
rel?: null | string,
|
|
56
|
-
target?: null | string,
|
|
57
|
-
},
|
|
58
|
+
attributes?: LinkAttributes,
|
|
58
59
|
): LinkNode;
|
|
59
60
|
declare export function $isLinkNode(
|
|
60
61
|
node: ?LexicalNode,
|
|
@@ -65,22 +66,18 @@ declare export class AutoLinkNode extends LinkNode {
|
|
|
65
66
|
static clone(node: AutoLinkNode): AutoLinkNode;
|
|
66
67
|
insertNewAfter(selection: RangeSelection): null | ElementNode;
|
|
67
68
|
}
|
|
68
|
-
declare export function $createAutoLinkNode(
|
|
69
|
+
declare export function $createAutoLinkNode(
|
|
70
|
+
url: string,
|
|
71
|
+
attributes?: LinkAttributes,
|
|
72
|
+
): AutoLinkNode;
|
|
69
73
|
declare export function $isAutoLinkNode(
|
|
70
74
|
node: ?LexicalNode,
|
|
71
75
|
): boolean %checks(node instanceof AutoLinkNode);
|
|
72
76
|
|
|
73
77
|
declare export var TOGGLE_LINK_COMMAND: LexicalCommand<
|
|
74
|
-
| string
|
|
75
|
-
| {
|
|
76
|
-
url: string,
|
|
77
|
-
target?: null | string,
|
|
78
|
-
rel?: null | string,
|
|
79
|
-
}
|
|
80
|
-
| null,
|
|
78
|
+
string | {url: string, ...LinkAttributes} | null,
|
|
81
79
|
>;
|
|
82
80
|
declare export function toggleLink(
|
|
83
81
|
url: null | string,
|
|
84
|
-
target?: null | string,
|
|
85
|
-
rel?: null | string,
|
|
82
|
+
attributes: {target?: null | string, rel?: null | string},
|
|
86
83
|
): void;
|
package/LexicalLink.prod.js
CHANGED
|
@@ -11,5 +11,5 @@ a}getTarget(){return this.getLatest().__target}setTarget(a){this.getWritable()._
|
|
|
11
11
|
a=b.anchor.getNode();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}
|
|
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){a=this.getParentOrThrow().insertNewAfter(a);if(m.$isElementNode(a)){let b=v(this.__url,{rel:this._rel,target:this.__target});
|
|
13
13
|
a.append(b);return b}return 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,
|
|
15
|
-
d,
|
|
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(k=>{k=k.getParent();if(r(k)){let d=k.getChildren();for(let f=0;f<d.length;f++)k.insertBefore(d[f]);k.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 k=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(k)||(k=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/index.d.ts
CHANGED
|
@@ -8,13 +8,15 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { DOMConversionMap, EditorConfig, GridSelection, LexicalCommand, LexicalNode, NodeKey, NodeSelection, RangeSelection, SerializedElementNode } from 'lexical';
|
|
10
10
|
import { ElementNode, Spread } from 'lexical';
|
|
11
|
+
export declare type LinkAttributes = {
|
|
12
|
+
rel?: null | string;
|
|
13
|
+
target?: null | string;
|
|
14
|
+
};
|
|
11
15
|
export declare type SerializedLinkNode = Spread<{
|
|
12
16
|
type: 'link';
|
|
13
17
|
url: string;
|
|
14
|
-
target?: null | string;
|
|
15
|
-
rel?: null | string;
|
|
16
18
|
version: 1;
|
|
17
|
-
}, SerializedElementNode
|
|
19
|
+
}, Spread<LinkAttributes, SerializedElementNode>>;
|
|
18
20
|
/** @noInheritDoc */
|
|
19
21
|
export declare class LinkNode extends ElementNode {
|
|
20
22
|
/** @internal */
|
|
@@ -25,10 +27,7 @@ export declare class LinkNode extends ElementNode {
|
|
|
25
27
|
__rel: null | string;
|
|
26
28
|
static getType(): string;
|
|
27
29
|
static clone(node: LinkNode): LinkNode;
|
|
28
|
-
constructor(url: string, attributes?:
|
|
29
|
-
target?: null | string;
|
|
30
|
-
rel?: null | string;
|
|
31
|
-
}, key?: NodeKey);
|
|
30
|
+
constructor(url: string, attributes?: LinkAttributes, key?: NodeKey);
|
|
32
31
|
createDOM(config: EditorConfig): HTMLAnchorElement;
|
|
33
32
|
updateDOM(prevNode: LinkNode, anchor: HTMLAnchorElement, config: EditorConfig): boolean;
|
|
34
33
|
static importDOM(): DOMConversionMap | null;
|
|
@@ -47,10 +46,7 @@ export declare class LinkNode extends ElementNode {
|
|
|
47
46
|
isInline(): true;
|
|
48
47
|
extractWithChild(child: LexicalNode, selection: RangeSelection | NodeSelection | GridSelection, destination: 'clone' | 'html'): boolean;
|
|
49
48
|
}
|
|
50
|
-
export declare function $createLinkNode(url: string, attributes?:
|
|
51
|
-
target?: null | string;
|
|
52
|
-
rel?: null | string;
|
|
53
|
-
}): LinkNode;
|
|
49
|
+
export declare function $createLinkNode(url: string, attributes?: LinkAttributes): LinkNode;
|
|
54
50
|
export declare function $isLinkNode(node: LexicalNode | null | undefined): node is LinkNode;
|
|
55
51
|
export declare type SerializedAutoLinkNode = Spread<{
|
|
56
52
|
type: 'autolink';
|
|
@@ -64,17 +60,9 @@ export declare class AutoLinkNode extends LinkNode {
|
|
|
64
60
|
exportJSON(): SerializedAutoLinkNode;
|
|
65
61
|
insertNewAfter(selection: RangeSelection): null | ElementNode;
|
|
66
62
|
}
|
|
67
|
-
export declare function $createAutoLinkNode(url: string, attributes?:
|
|
68
|
-
target?: null | string;
|
|
69
|
-
rel?: null | string;
|
|
70
|
-
}): AutoLinkNode;
|
|
63
|
+
export declare function $createAutoLinkNode(url: string, attributes?: LinkAttributes): AutoLinkNode;
|
|
71
64
|
export declare function $isAutoLinkNode(node: LexicalNode | null | undefined): node is AutoLinkNode;
|
|
72
|
-
export declare const TOGGLE_LINK_COMMAND: LexicalCommand<string | {
|
|
65
|
+
export declare const TOGGLE_LINK_COMMAND: LexicalCommand<string | ({
|
|
73
66
|
url: string;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} | null>;
|
|
77
|
-
export declare function toggleLink(url: null | string, attributes?: {
|
|
78
|
-
target?: null | string;
|
|
79
|
-
rel?: null | string;
|
|
80
|
-
}): void;
|
|
67
|
+
} & LinkAttributes) | null>;
|
|
68
|
+
export declare function toggleLink(url: null | string, attributes?: LinkAttributes): void;
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"link"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.6.
|
|
11
|
+
"version": "0.6.3",
|
|
12
12
|
"main": "LexicalLink.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.6.
|
|
14
|
+
"lexical": "0.6.3"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.6.
|
|
17
|
+
"@lexical/utils": "0.6.3"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|