@lexical/link 0.3.3 → 0.3.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 +4 -3
- package/LexicalLink.prod.js +2 -2
- package/index.d.ts +50 -0
- package/package.json +3 -3
- package/LexicalLink.d.ts +0 -57
package/LexicalLink.dev.js
CHANGED
|
@@ -15,7 +15,6 @@ var lexical = require('lexical');
|
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
17
|
*
|
|
18
|
-
|
|
19
18
|
*/
|
|
20
19
|
class LinkNode extends lexical.ElementNode {
|
|
21
20
|
static getType() {
|
|
@@ -68,7 +67,8 @@ class LinkNode extends lexical.ElementNode {
|
|
|
68
67
|
exportJSON() {
|
|
69
68
|
return { ...super.exportJSON(),
|
|
70
69
|
type: 'link',
|
|
71
|
-
url: this.getURL()
|
|
70
|
+
url: this.getURL(),
|
|
71
|
+
version: 1
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -155,7 +155,8 @@ class AutoLinkNode extends LinkNode {
|
|
|
155
155
|
|
|
156
156
|
exportJSON() {
|
|
157
157
|
return { ...super.exportJSON(),
|
|
158
|
-
type: 'autolink'
|
|
158
|
+
type: 'autolink',
|
|
159
|
+
version: 1
|
|
159
160
|
};
|
|
160
161
|
}
|
|
161
162
|
|
package/LexicalLink.prod.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var h=require("@lexical/utils"),k=require("lexical");
|
|
8
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()}}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"}}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(k.$isElementNode(a)){let b=t(this.__url);a.append(b);return b}return null}}
|
|
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
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
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
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)})}}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { DOMConversionMap, EditorConfig, LexicalCommand, LexicalNode, NodeKey, RangeSelection, SerializedElementNode } from 'lexical';
|
|
9
|
+
import { ElementNode, Spread } from 'lexical';
|
|
10
|
+
export declare type SerializedLinkNode = Spread<{
|
|
11
|
+
type: 'link';
|
|
12
|
+
url: string;
|
|
13
|
+
version: 1;
|
|
14
|
+
}, SerializedElementNode>;
|
|
15
|
+
export declare class LinkNode extends ElementNode {
|
|
16
|
+
__url: string;
|
|
17
|
+
static getType(): string;
|
|
18
|
+
static clone(node: LinkNode): LinkNode;
|
|
19
|
+
constructor(url: string, key?: NodeKey);
|
|
20
|
+
createDOM(config: EditorConfig): HTMLAnchorElement;
|
|
21
|
+
updateDOM(prevNode: LinkNode, anchor: HTMLAnchorElement, config: EditorConfig): boolean;
|
|
22
|
+
static importDOM(): DOMConversionMap | null;
|
|
23
|
+
static importJSON(serializedNode: SerializedLinkNode | SerializedAutoLinkNode): LinkNode;
|
|
24
|
+
exportJSON(): SerializedLinkNode | SerializedAutoLinkNode;
|
|
25
|
+
getURL(): string;
|
|
26
|
+
setURL(url: string): void;
|
|
27
|
+
insertNewAfter(selection: RangeSelection): null | ElementNode;
|
|
28
|
+
canInsertTextBefore(): false;
|
|
29
|
+
canInsertTextAfter(): false;
|
|
30
|
+
canBeEmpty(): false;
|
|
31
|
+
isInline(): true;
|
|
32
|
+
}
|
|
33
|
+
export declare function $createLinkNode(url: string): LinkNode;
|
|
34
|
+
export declare function $isLinkNode(node: LexicalNode | null | undefined): node is LinkNode;
|
|
35
|
+
export declare type SerializedAutoLinkNode = Spread<{
|
|
36
|
+
type: 'autolink';
|
|
37
|
+
version: 1;
|
|
38
|
+
}, SerializedLinkNode>;
|
|
39
|
+
export declare class AutoLinkNode extends LinkNode {
|
|
40
|
+
static getType(): string;
|
|
41
|
+
static clone(node: AutoLinkNode): AutoLinkNode;
|
|
42
|
+
static importJSON(serializedNode: SerializedAutoLinkNode): AutoLinkNode;
|
|
43
|
+
static importDOM(): null;
|
|
44
|
+
exportJSON(): SerializedAutoLinkNode;
|
|
45
|
+
insertNewAfter(selection: RangeSelection): null | ElementNode;
|
|
46
|
+
}
|
|
47
|
+
export declare function $createAutoLinkNode(url: string): AutoLinkNode;
|
|
48
|
+
export declare function $isAutoLinkNode(node: LexicalNode | null | undefined): node is AutoLinkNode;
|
|
49
|
+
export declare const TOGGLE_LINK_COMMAND: LexicalCommand<string | null>;
|
|
50
|
+
export declare function toggleLink(url: null | string): void;
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"link"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.3.
|
|
11
|
+
"version": "0.3.4",
|
|
12
12
|
"main": "LexicalLink.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.3.
|
|
14
|
+
"lexical": "0.3.4"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.3.
|
|
17
|
+
"@lexical/utils": "0.3.4"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
package/LexicalLink.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type {
|
|
11
|
-
DOMConversionMap,
|
|
12
|
-
DOMConversionOutput,
|
|
13
|
-
EditorConfig,
|
|
14
|
-
LexicalNode,
|
|
15
|
-
NodeKey,
|
|
16
|
-
RangeSelection,
|
|
17
|
-
LexicalCommand,
|
|
18
|
-
} from 'lexical';
|
|
19
|
-
import {ElementNode} from 'lexical';
|
|
20
|
-
|
|
21
|
-
export declare class LinkNode extends ElementNode {
|
|
22
|
-
__url: string;
|
|
23
|
-
static getType(): string;
|
|
24
|
-
static clone(node: LinkNode): LinkNode;
|
|
25
|
-
constructor(url: string, key?: NodeKey);
|
|
26
|
-
createDOM(config: EditorConfig): HTMLElement;
|
|
27
|
-
updateDOM(
|
|
28
|
-
prevNode: LinkNode,
|
|
29
|
-
dom: HTMLElement,
|
|
30
|
-
config: EditorConfig,
|
|
31
|
-
): boolean;
|
|
32
|
-
static importDOM(): DOMConversionMap | null;
|
|
33
|
-
getURL(): string;
|
|
34
|
-
setURL(url: string): void;
|
|
35
|
-
insertNewAfter(selection: RangeSelection): null | ElementNode;
|
|
36
|
-
canInsertTextBefore(): false;
|
|
37
|
-
canInsertTextAfter(): boolean;
|
|
38
|
-
canBeEmpty(): false;
|
|
39
|
-
isInline(): true;
|
|
40
|
-
}
|
|
41
|
-
export function convertAnchorElement(domNode: Node): DOMConversionOutput;
|
|
42
|
-
export function $createLinkNode(url: string): LinkNode;
|
|
43
|
-
export function $isLinkNode(
|
|
44
|
-
node: LinkNode | LexicalNode | null | undefined,
|
|
45
|
-
): node is LinkNode;
|
|
46
|
-
export declare class AutoLinkNode extends LinkNode {
|
|
47
|
-
static getType(): string;
|
|
48
|
-
static clone(node: AutoLinkNode): AutoLinkNode;
|
|
49
|
-
insertNewAfter(selection: RangeSelection): null | ElementNode;
|
|
50
|
-
}
|
|
51
|
-
export function $createAutoLinkNode(url: string): AutoLinkNode;
|
|
52
|
-
export function $isAutoLinkNode(
|
|
53
|
-
node: LinkNode | LexicalNode | null | undefined,
|
|
54
|
-
): node is AutoLinkNode;
|
|
55
|
-
|
|
56
|
-
export var TOGGLE_LINK_COMMAND: LexicalCommand<string | null>;
|
|
57
|
-
export function toggleLink(url: null | string): void;
|