@lexical/link 0.1.17
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/LICENSE +21 -0
- package/LexicalLink.d.ts +50 -0
- package/LexicalLink.dev.js +159 -0
- package/LexicalLink.js +9 -0
- package/LexicalLink.js.flow +54 -0
- package/LexicalLink.prod.js +11 -0
- package/README.md +5 -0
- package/package.json +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/LexicalLink.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
import type {
|
|
10
|
+
DOMConversionMap,
|
|
11
|
+
DOMConversionOutput,
|
|
12
|
+
EditorConfig,
|
|
13
|
+
LexicalNode,
|
|
14
|
+
NodeKey,
|
|
15
|
+
RangeSelection,
|
|
16
|
+
LexicalCommand,
|
|
17
|
+
} from 'lexical';
|
|
18
|
+
|
|
19
|
+
export declare class LinkNode extends ElementNode {
|
|
20
|
+
__url: string;
|
|
21
|
+
static getType(): string;
|
|
22
|
+
static clone(node: LinkNode): LinkNode;
|
|
23
|
+
constructor(url: string, key?: NodeKey): void;
|
|
24
|
+
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
|
|
25
|
+
updateDOM<EditorContext>(
|
|
26
|
+
prevNode: LinkNode,
|
|
27
|
+
dom: HTMLElement,
|
|
28
|
+
config: EditorConfig<EditorContext>,
|
|
29
|
+
): boolean;
|
|
30
|
+
static convertDOM(): DOMConversionMap | null;
|
|
31
|
+
getURL(): string;
|
|
32
|
+
setURL(url: string): void;
|
|
33
|
+
insertNewAfter(selection: RangeSelection): null | ElementNode;
|
|
34
|
+
canInsertTextBefore(): false;
|
|
35
|
+
canInsertTextAfter(): boolean;
|
|
36
|
+
canBeEmpty(): false;
|
|
37
|
+
isInline(): true;
|
|
38
|
+
}
|
|
39
|
+
export function convertAnchorElement(domNode: Node): DOMConversionOutput;
|
|
40
|
+
export function $createLinkNode(url: string): LinkNode;
|
|
41
|
+
export function $isLinkNode(node: ?LexicalNode): boolean;
|
|
42
|
+
export declare class AutoLinkNode extends LinkNode {
|
|
43
|
+
static getType(): string;
|
|
44
|
+
static clone(node: AutoLinkNode): AutoLinkNode;
|
|
45
|
+
insertNewAfter(selection: RangeSelection): null | ElementNode;
|
|
46
|
+
}
|
|
47
|
+
export function $createAutoLinkNode(url: string): AutoLinkNode;
|
|
48
|
+
export function $isAutoLinkNode(node: ?LexicalNode): boolean;
|
|
49
|
+
|
|
50
|
+
export var TOGGLE_LINK_COMMAND: LexicalCommand<string | null>;
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var utils = require('@lexical/utils');
|
|
10
|
+
var lexical = require('lexical');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
class LinkNode extends lexical.ElementNode {
|
|
21
|
+
static getType() {
|
|
22
|
+
return 'link';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static clone(node) {
|
|
26
|
+
return new LinkNode(node.__url, node.__key);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor(url, key) {
|
|
30
|
+
super(key);
|
|
31
|
+
this.__url = url;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
createDOM(config) {
|
|
35
|
+
const element = document.createElement('a');
|
|
36
|
+
element.href = this.__url;
|
|
37
|
+
utils.addClassNamesToElement(element, config.theme.link);
|
|
38
|
+
return element;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
updateDOM( // $FlowFixMe: not sure how to fix this
|
|
42
|
+
prevNode, dom, config) {
|
|
43
|
+
// $FlowFixMe: not sure how to fix this
|
|
44
|
+
const anchor = dom;
|
|
45
|
+
const url = this.__url;
|
|
46
|
+
|
|
47
|
+
if (url !== prevNode.__url) {
|
|
48
|
+
anchor.href = url;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static convertDOM() {
|
|
55
|
+
return {
|
|
56
|
+
a: node => ({
|
|
57
|
+
conversion: convertAnchorElement,
|
|
58
|
+
priority: 1
|
|
59
|
+
})
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getURL() {
|
|
64
|
+
return this.getLatest().__url;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setURL(url) {
|
|
68
|
+
const writable = this.getWritable();
|
|
69
|
+
writable.__url = url;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
insertNewAfter(selection) {
|
|
73
|
+
const element = this.getParentOrThrow().insertNewAfter(selection);
|
|
74
|
+
|
|
75
|
+
if (lexical.$isElementNode(element)) {
|
|
76
|
+
const linkNode = $createLinkNode(this.__url);
|
|
77
|
+
element.append(linkNode);
|
|
78
|
+
return linkNode;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
canInsertTextBefore() {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
canInsertTextAfter() {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
canBeEmpty() {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
isInline() {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function convertAnchorElement(domNode) {
|
|
103
|
+
let node = null;
|
|
104
|
+
|
|
105
|
+
if (domNode instanceof HTMLAnchorElement) {
|
|
106
|
+
node = $createLinkNode(domNode.href);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
node
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function $createLinkNode(url) {
|
|
115
|
+
return new LinkNode(url);
|
|
116
|
+
}
|
|
117
|
+
function $isLinkNode(node) {
|
|
118
|
+
return node instanceof LinkNode;
|
|
119
|
+
} // Custom node type to override `canInsertTextAfter` that will
|
|
120
|
+
// allow typing within the link
|
|
121
|
+
|
|
122
|
+
class AutoLinkNode extends LinkNode {
|
|
123
|
+
static getType() {
|
|
124
|
+
return 'autolink';
|
|
125
|
+
} // $FlowFixMe[incompatible-extend]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
static clone(node) {
|
|
129
|
+
return new AutoLinkNode(node.__url, node.__key);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
insertNewAfter(selection) {
|
|
133
|
+
const element = this.getParentOrThrow().insertNewAfter(selection);
|
|
134
|
+
|
|
135
|
+
if (lexical.$isElementNode(element)) {
|
|
136
|
+
const linkNode = $createAutoLinkNode(this.__url);
|
|
137
|
+
element.append(linkNode);
|
|
138
|
+
return linkNode;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
function $createAutoLinkNode(url) {
|
|
146
|
+
return new AutoLinkNode(url);
|
|
147
|
+
}
|
|
148
|
+
function $isAutoLinkNode(node) {
|
|
149
|
+
return node instanceof AutoLinkNode;
|
|
150
|
+
}
|
|
151
|
+
const TOGGLE_LINK_COMMAND = lexical.createCommand();
|
|
152
|
+
|
|
153
|
+
exports.$createAutoLinkNode = $createAutoLinkNode;
|
|
154
|
+
exports.$createLinkNode = $createLinkNode;
|
|
155
|
+
exports.$isAutoLinkNode = $isAutoLinkNode;
|
|
156
|
+
exports.$isLinkNode = $isLinkNode;
|
|
157
|
+
exports.AutoLinkNode = AutoLinkNode;
|
|
158
|
+
exports.LinkNode = LinkNode;
|
|
159
|
+
exports.TOGGLE_LINK_COMMAND = TOGGLE_LINK_COMMAND;
|
package/LexicalLink.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
'use strict'
|
|
8
|
+
const LexicalLink = process.env.NODE_ENV === 'development' ? require('./LexicalLink.dev.js') : require('./LexicalLink.prod.js')
|
|
9
|
+
module.exports = LexicalLink;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
import type {
|
|
10
|
+
DOMConversionMap,
|
|
11
|
+
EditorConfig,
|
|
12
|
+
LexicalNode,
|
|
13
|
+
NodeKey,
|
|
14
|
+
RangeSelection,
|
|
15
|
+
LexicalCommand,
|
|
16
|
+
} from 'lexical';
|
|
17
|
+
import {addClassNamesToElement} from '@lexical/utils';
|
|
18
|
+
import {$isElementNode, ElementNode} from 'lexical';
|
|
19
|
+
declare export class LinkNode extends ElementNode {
|
|
20
|
+
__url: string;
|
|
21
|
+
static getType(): string;
|
|
22
|
+
static clone(node: LinkNode): LinkNode;
|
|
23
|
+
constructor(url: string, key?: NodeKey): void;
|
|
24
|
+
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
|
|
25
|
+
updateDOM<EditorContext>(
|
|
26
|
+
prevNode: LinkNode,
|
|
27
|
+
dom: HTMLElement,
|
|
28
|
+
config: EditorConfig<EditorContext>,
|
|
29
|
+
): boolean;
|
|
30
|
+
static convertDOM(): DOMConversionMap | null;
|
|
31
|
+
getURL(): string;
|
|
32
|
+
setURL(url: string): void;
|
|
33
|
+
insertNewAfter(selection: RangeSelection): null | ElementNode;
|
|
34
|
+
canInsertTextBefore(): false;
|
|
35
|
+
canInsertTextAfter(): boolean;
|
|
36
|
+
canBeEmpty(): false;
|
|
37
|
+
isInline(): true;
|
|
38
|
+
}
|
|
39
|
+
declare export function $createLinkNode(url: string): LinkNode;
|
|
40
|
+
declare export function $isLinkNode(
|
|
41
|
+
node: ?LexicalNode,
|
|
42
|
+
): boolean %checks(node instanceof LinkNode);
|
|
43
|
+
declare export class AutoLinkNode extends LinkNode {
|
|
44
|
+
static getType(): string;
|
|
45
|
+
// $FlowFixMe clone method inheritance
|
|
46
|
+
static clone(node: AutoLinkNode): AutoLinkNode;
|
|
47
|
+
insertNewAfter(selection: RangeSelection): null | ElementNode;
|
|
48
|
+
}
|
|
49
|
+
declare export function $createAutoLinkNode(url: string): AutoLinkNode;
|
|
50
|
+
declare export function $isAutoLinkNode(
|
|
51
|
+
node: ?LexicalNode,
|
|
52
|
+
): boolean %checks(node instanceof AutoLinkNode);
|
|
53
|
+
|
|
54
|
+
declare export var TOGGLE_LINK_COMMAND: LexicalCommand<string | null>;
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
var c=require("@lexical/utils"),d=require("lexical");
|
|
8
|
+
class e extends d.ElementNode{static getType(){return"link"}static clone(a){return new e(a.__url,a.__key)}constructor(a,b){super(b);this.__url=a}createDOM(a){const b=document.createElement("a");b.href=this.__url;c.addClassNamesToElement(b,a.theme.link);return b}updateDOM(a,b){const g=this.__url;g!==a.__url&&(b.href=g);return!1}static convertDOM(){return{a:()=>({conversion:f,priority:1})}}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=a}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);
|
|
9
|
+
if(d.$isElementNode(a)){const b=h(this.__url);a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}}function f(a){let b=null;a instanceof HTMLAnchorElement&&(b=h(a.href));return{node:b}}function h(a){return new e(a)}
|
|
10
|
+
class k extends e{static getType(){return"autolink"}static clone(a){return new k(a.__url,a.__key)}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(d.$isElementNode(a)){const b=l(this.__url);a.append(b);return b}return null}}function l(a){return new k(a)}const m=d.createCommand();exports.$createAutoLinkNode=l;exports.$createLinkNode=h;exports.$isAutoLinkNode=function(a){return a instanceof k};exports.$isLinkNode=function(a){return a instanceof e};exports.AutoLinkNode=k;
|
|
11
|
+
exports.LinkNode=e;exports.TOGGLE_LINK_COMMAND=m;
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lexical/link",
|
|
3
|
+
"description": "This package contains the functionality for Lexical links.",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"lexical",
|
|
6
|
+
"editor",
|
|
7
|
+
"rich-text",
|
|
8
|
+
"link"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"version": "0.1.17",
|
|
12
|
+
"main": "LexicalLink.js",
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"lexical": "0.1.17"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@lexical/utils": "0.1.17"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/facebook/lexical",
|
|
22
|
+
"directory": "packages/lexical-link"
|
|
23
|
+
}
|
|
24
|
+
}
|