@react-fabric/lexical 1.0.0-beta.8 → 1.0.1
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/{src/editor/Lexical.module.css → css/_lexical.css} +79 -13
- package/css/styles.css +24 -0
- package/dist/cjs/{packages/lexical/src/editor → editor}/LexicalEditor.js +98 -45
- package/dist/cjs/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +147 -140
- package/dist/cjs/i18n/ar/lexical.json.js +30 -0
- package/dist/cjs/i18n/en/lexical.json.js +30 -0
- package/{src/plugins/StickyPlugin.ts → dist/cjs/i18n/index.js} +10 -15
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/plugins/CommentPlugin.js +481 -0
- package/dist/cjs/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +17 -20
- package/dist/cjs/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +58 -37
- package/dist/esm/{packages/lexical/src/editor → editor}/LexicalEditor.js +101 -48
- package/dist/esm/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +95 -88
- package/dist/esm/i18n/ar/lexical.json.js +25 -0
- package/dist/esm/i18n/en/lexical.json.js +25 -0
- package/dist/esm/i18n/index.js +33 -0
- package/dist/esm/index.js +34 -0
- package/dist/esm/plugins/CommentPlugin.js +481 -0
- package/dist/esm/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +15 -18
- package/dist/esm/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +59 -38
- package/dist/types/editor/LexicalEditor.d.ts +33 -4
- package/dist/types/hooks/useFormatWatcher.d.ts +7 -4
- package/dist/types/i18n/index.d.ts +1 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/types/plugins/CommentPlugin.d.ts +5 -0
- package/dist/types/plugins/DraggableBlockPlugin.d.ts +3 -2
- package/dist/types/plugins/ToolbarPlugin.d.ts +1 -1
- package/dist/types/utils/index.d.ts +3 -6
- package/package.json +18 -18
- package/src/editor/LexicalEditor.tsx +95 -55
- package/src/hooks/useFormatWatcher.ts +50 -74
- package/src/i18n/ar/lexical.json +18 -0
- package/src/i18n/en/lexical.json +18 -0
- package/src/i18n/index.ts +28 -0
- package/src/index.ts +24 -17
- package/src/plugins/CommentPlugin.tsx +523 -0
- package/src/plugins/DraggableBlockPlugin.tsx +23 -68
- package/src/plugins/ToolbarPlugin.tsx +83 -131
- package/src/utils/index.ts +12 -108
- package/dist/cjs/_virtual/prism.js +0 -5
- package/dist/cjs/editor/Lexical.module.css +0 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -432
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -21
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -27
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +0 -1139
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +0 -25
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +0 -50
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +0 -245
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +0 -19
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +0 -18
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +0 -471
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +0 -17
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +0 -24
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +0 -1275
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +0 -29
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +0 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -789
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +0 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -26
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -976
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +0 -35
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -35
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +0 -2792
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +0 -23
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +0 -55
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -888
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +0 -35
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -66
- package/dist/cjs/node_modules/@mdi/js/mdi.js +0 -8
- package/dist/cjs/node_modules/prismjs/components/prism-c.js +0 -82
- package/dist/cjs/node_modules/prismjs/components/prism-clike.js +0 -33
- package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +0 -101
- package/dist/cjs/node_modules/prismjs/components/prism-css.js +0 -66
- package/dist/cjs/node_modules/prismjs/components/prism-java.js +0 -126
- package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +0 -174
- package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +0 -417
- package/dist/cjs/node_modules/prismjs/components/prism-markup.js +0 -188
- package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +0 -14
- package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +0 -60
- package/dist/cjs/node_modules/prismjs/components/prism-python.js +0 -67
- package/dist/cjs/node_modules/prismjs/components/prism-rust.js +0 -130
- package/dist/cjs/node_modules/prismjs/components/prism-sql.js +0 -34
- package/dist/cjs/node_modules/prismjs/components/prism-swift.js +0 -150
- package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +0 -62
- package/dist/cjs/node_modules/prismjs/prism.js +0 -1951
- package/dist/cjs/packages/lexical/src/components/StickyComponent.js +0 -221
- package/dist/cjs/packages/lexical/src/index.js +0 -7
- package/dist/cjs/packages/lexical/src/nodes/StickyNode.js +0 -218
- package/dist/cjs/packages/lexical/src/plugins/StickyPlugin.js +0 -20
- package/dist/esm/_virtual/prism.js +0 -5
- package/dist/esm/editor/Lexical.module.css +0 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -423
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -19
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -18
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +0 -1121
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +0 -21
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +0 -32
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +0 -244
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +0 -18
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +0 -463
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +0 -17
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +0 -1262
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +0 -23
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -781
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +0 -23
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -18
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -957
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +0 -26
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +0 -2754
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +0 -20
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -839
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +0 -26
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -17
- package/dist/esm/node_modules/@mdi/js/mdi.js +0 -7
- package/dist/esm/node_modules/prismjs/components/prism-c.js +0 -82
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -33
- package/dist/esm/node_modules/prismjs/components/prism-cpp.js +0 -101
- package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -66
- package/dist/esm/node_modules/prismjs/components/prism-java.js +0 -126
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -174
- package/dist/esm/node_modules/prismjs/components/prism-markdown.js +0 -417
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -188
- package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +0 -14
- package/dist/esm/node_modules/prismjs/components/prism-powershell.js +0 -60
- package/dist/esm/node_modules/prismjs/components/prism-python.js +0 -67
- package/dist/esm/node_modules/prismjs/components/prism-rust.js +0 -130
- package/dist/esm/node_modules/prismjs/components/prism-sql.js +0 -34
- package/dist/esm/node_modules/prismjs/components/prism-swift.js +0 -150
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -62
- package/dist/esm/node_modules/prismjs/prism.js +0 -1951
- package/dist/esm/packages/lexical/src/components/StickyComponent.js +0 -221
- package/dist/esm/packages/lexical/src/index.js +0 -3
- package/dist/esm/packages/lexical/src/nodes/StickyNode.js +0 -216
- package/dist/esm/packages/lexical/src/plugins/StickyPlugin.js +0 -20
- package/dist/types/components/StickyComponent.d.ts +0 -9
- package/dist/types/nodes/StickyNode.d.ts +0 -35
- package/dist/types/plugins/StickyPlugin.d.ts +0 -1
- package/src/components/StickyComponent.tsx +0 -271
- package/src/nodes/StickyNode.tsx +0 -249
- /package/dist/cjs/{packages/lexical/src/editor → editor}/theme.js +0 -0
- /package/dist/cjs/{packages/lexical/src/utils → utils}/index.js +0 -0
- /package/dist/esm/{packages/lexical/src/editor → editor}/theme.js +0 -0
- /package/dist/esm/{packages/lexical/src/utils → utils}/index.js +0 -0
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var LexicalUtils = require('../utils/LexicalUtils.js');
|
|
4
|
-
var lexical = require('lexical');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the MIT license found in the
|
|
10
|
-
* LICENSE file in the root directory of this source tree.
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
17
|
-
*
|
|
18
|
-
* This source code is licensed under the MIT license found in the
|
|
19
|
-
* LICENSE file in the root directory of this source tree.
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
|
|
24
|
-
|
|
25
|
-
/** @noInheritDoc */
|
|
26
|
-
class LinkNode extends lexical.ElementNode {
|
|
27
|
-
/** @internal */
|
|
28
|
-
|
|
29
|
-
/** @internal */
|
|
30
|
-
|
|
31
|
-
/** @internal */
|
|
32
|
-
|
|
33
|
-
/** @internal */
|
|
34
|
-
|
|
35
|
-
static getType() {
|
|
36
|
-
return 'link';
|
|
37
|
-
}
|
|
38
|
-
static clone(node) {
|
|
39
|
-
return new LinkNode(node.__url, {
|
|
40
|
-
rel: node.__rel,
|
|
41
|
-
target: node.__target,
|
|
42
|
-
title: node.__title
|
|
43
|
-
}, node.__key);
|
|
44
|
-
}
|
|
45
|
-
constructor(url, attributes = {}, key) {
|
|
46
|
-
super(key);
|
|
47
|
-
const {
|
|
48
|
-
target = null,
|
|
49
|
-
rel = null,
|
|
50
|
-
title = null
|
|
51
|
-
} = attributes;
|
|
52
|
-
this.__url = url;
|
|
53
|
-
this.__target = target;
|
|
54
|
-
this.__rel = rel;
|
|
55
|
-
this.__title = title;
|
|
56
|
-
}
|
|
57
|
-
createDOM(config) {
|
|
58
|
-
const element = document.createElement('a');
|
|
59
|
-
element.href = this.sanitizeUrl(this.__url);
|
|
60
|
-
if (this.__target !== null) {
|
|
61
|
-
element.target = this.__target;
|
|
62
|
-
}
|
|
63
|
-
if (this.__rel !== null) {
|
|
64
|
-
element.rel = this.__rel;
|
|
65
|
-
}
|
|
66
|
-
if (this.__title !== null) {
|
|
67
|
-
element.title = this.__title;
|
|
68
|
-
}
|
|
69
|
-
LexicalUtils.addClassNamesToElement(element, config.theme.link);
|
|
70
|
-
return element;
|
|
71
|
-
}
|
|
72
|
-
updateDOM(prevNode, anchor, config) {
|
|
73
|
-
if (anchor instanceof HTMLAnchorElement) {
|
|
74
|
-
const url = this.__url;
|
|
75
|
-
const target = this.__target;
|
|
76
|
-
const rel = this.__rel;
|
|
77
|
-
const title = this.__title;
|
|
78
|
-
if (url !== prevNode.__url) {
|
|
79
|
-
anchor.href = url;
|
|
80
|
-
}
|
|
81
|
-
if (target !== prevNode.__target) {
|
|
82
|
-
if (target) {
|
|
83
|
-
anchor.target = target;
|
|
84
|
-
} else {
|
|
85
|
-
anchor.removeAttribute('target');
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (rel !== prevNode.__rel) {
|
|
89
|
-
if (rel) {
|
|
90
|
-
anchor.rel = rel;
|
|
91
|
-
} else {
|
|
92
|
-
anchor.removeAttribute('rel');
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (title !== prevNode.__title) {
|
|
96
|
-
if (title) {
|
|
97
|
-
anchor.title = title;
|
|
98
|
-
} else {
|
|
99
|
-
anchor.removeAttribute('title');
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
static importDOM() {
|
|
106
|
-
return {
|
|
107
|
-
a: node => ({
|
|
108
|
-
conversion: $convertAnchorElement,
|
|
109
|
-
priority: 1
|
|
110
|
-
})
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
static importJSON(serializedNode) {
|
|
114
|
-
const node = $createLinkNode(serializedNode.url, {
|
|
115
|
-
rel: serializedNode.rel,
|
|
116
|
-
target: serializedNode.target,
|
|
117
|
-
title: serializedNode.title
|
|
118
|
-
});
|
|
119
|
-
node.setFormat(serializedNode.format);
|
|
120
|
-
node.setIndent(serializedNode.indent);
|
|
121
|
-
node.setDirection(serializedNode.direction);
|
|
122
|
-
return node;
|
|
123
|
-
}
|
|
124
|
-
sanitizeUrl(url) {
|
|
125
|
-
try {
|
|
126
|
-
const parsedUrl = new URL(url);
|
|
127
|
-
// eslint-disable-next-line no-script-url
|
|
128
|
-
if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {
|
|
129
|
-
return 'about:blank';
|
|
130
|
-
}
|
|
131
|
-
} catch (_unused) {
|
|
132
|
-
return url;
|
|
133
|
-
}
|
|
134
|
-
return url;
|
|
135
|
-
}
|
|
136
|
-
exportJSON() {
|
|
137
|
-
return {
|
|
138
|
-
...super.exportJSON(),
|
|
139
|
-
rel: this.getRel(),
|
|
140
|
-
target: this.getTarget(),
|
|
141
|
-
title: this.getTitle(),
|
|
142
|
-
type: 'link',
|
|
143
|
-
url: this.getURL(),
|
|
144
|
-
version: 1
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
getURL() {
|
|
148
|
-
return this.getLatest().__url;
|
|
149
|
-
}
|
|
150
|
-
setURL(url) {
|
|
151
|
-
const writable = this.getWritable();
|
|
152
|
-
writable.__url = url;
|
|
153
|
-
}
|
|
154
|
-
getTarget() {
|
|
155
|
-
return this.getLatest().__target;
|
|
156
|
-
}
|
|
157
|
-
setTarget(target) {
|
|
158
|
-
const writable = this.getWritable();
|
|
159
|
-
writable.__target = target;
|
|
160
|
-
}
|
|
161
|
-
getRel() {
|
|
162
|
-
return this.getLatest().__rel;
|
|
163
|
-
}
|
|
164
|
-
setRel(rel) {
|
|
165
|
-
const writable = this.getWritable();
|
|
166
|
-
writable.__rel = rel;
|
|
167
|
-
}
|
|
168
|
-
getTitle() {
|
|
169
|
-
return this.getLatest().__title;
|
|
170
|
-
}
|
|
171
|
-
setTitle(title) {
|
|
172
|
-
const writable = this.getWritable();
|
|
173
|
-
writable.__title = title;
|
|
174
|
-
}
|
|
175
|
-
insertNewAfter(_, restoreSelection = true) {
|
|
176
|
-
const linkNode = $createLinkNode(this.__url, {
|
|
177
|
-
rel: this.__rel,
|
|
178
|
-
target: this.__target,
|
|
179
|
-
title: this.__title
|
|
180
|
-
});
|
|
181
|
-
this.insertAfter(linkNode, restoreSelection);
|
|
182
|
-
return linkNode;
|
|
183
|
-
}
|
|
184
|
-
canInsertTextBefore() {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
canInsertTextAfter() {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
canBeEmpty() {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
isInline() {
|
|
194
|
-
return true;
|
|
195
|
-
}
|
|
196
|
-
extractWithChild(child, selection, destination) {
|
|
197
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
const anchorNode = selection.anchor.getNode();
|
|
201
|
-
const focusNode = selection.focus.getNode();
|
|
202
|
-
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && selection.getTextContent().length > 0;
|
|
203
|
-
}
|
|
204
|
-
isEmailURI() {
|
|
205
|
-
return this.__url.startsWith('mailto:');
|
|
206
|
-
}
|
|
207
|
-
isWebSiteURI() {
|
|
208
|
-
return this.__url.startsWith('https://') || this.__url.startsWith('http://');
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
function $convertAnchorElement(domNode) {
|
|
212
|
-
let node = null;
|
|
213
|
-
if (LexicalUtils.isHTMLAnchorElement(domNode)) {
|
|
214
|
-
const content = domNode.textContent;
|
|
215
|
-
if (content !== null && content !== '' || domNode.children.length > 0) {
|
|
216
|
-
node = $createLinkNode(domNode.getAttribute('href') || '', {
|
|
217
|
-
rel: domNode.getAttribute('rel'),
|
|
218
|
-
target: domNode.getAttribute('target'),
|
|
219
|
-
title: domNode.getAttribute('title')
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
node
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Takes a URL and creates a LinkNode.
|
|
230
|
-
* @param url - The URL the LinkNode should direct to.
|
|
231
|
-
* @param attributes - Optional HTML a tag attributes \\{ target, rel, title \\}
|
|
232
|
-
* @returns The LinkNode.
|
|
233
|
-
*/
|
|
234
|
-
function $createLinkNode(url, attributes) {
|
|
235
|
-
return lexical.$applyNodeReplacement(new LinkNode(url, attributes));
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Determines if node is a LinkNode.
|
|
240
|
-
* @param node - The node to be checked.
|
|
241
|
-
* @returns true if node is a LinkNode, false otherwise.
|
|
242
|
-
*/
|
|
243
|
-
function $isLinkNode(node) {
|
|
244
|
-
return node instanceof LinkNode;
|
|
245
|
-
}
|
|
246
|
-
// Custom node type to override `canInsertTextAfter` that will
|
|
247
|
-
// allow typing within the link
|
|
248
|
-
class AutoLinkNode extends LinkNode {
|
|
249
|
-
/** @internal */
|
|
250
|
-
/** Indicates whether the autolink was ever unlinked. **/
|
|
251
|
-
|
|
252
|
-
constructor(url, attributes = {}, key) {
|
|
253
|
-
super(url, attributes, key);
|
|
254
|
-
this.__isUnlinked = attributes.isUnlinked !== undefined && attributes.isUnlinked !== null ? attributes.isUnlinked : false;
|
|
255
|
-
}
|
|
256
|
-
static getType() {
|
|
257
|
-
return 'autolink';
|
|
258
|
-
}
|
|
259
|
-
static clone(node) {
|
|
260
|
-
return new AutoLinkNode(node.__url, {
|
|
261
|
-
isUnlinked: node.__isUnlinked,
|
|
262
|
-
rel: node.__rel,
|
|
263
|
-
target: node.__target,
|
|
264
|
-
title: node.__title
|
|
265
|
-
}, node.__key);
|
|
266
|
-
}
|
|
267
|
-
getIsUnlinked() {
|
|
268
|
-
return this.__isUnlinked;
|
|
269
|
-
}
|
|
270
|
-
setIsUnlinked(value) {
|
|
271
|
-
const self = this.getWritable();
|
|
272
|
-
self.__isUnlinked = value;
|
|
273
|
-
return self;
|
|
274
|
-
}
|
|
275
|
-
createDOM(config) {
|
|
276
|
-
if (this.__isUnlinked) {
|
|
277
|
-
return document.createElement('span');
|
|
278
|
-
} else {
|
|
279
|
-
return super.createDOM(config);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
updateDOM(prevNode, anchor, config) {
|
|
283
|
-
return super.updateDOM(prevNode, anchor, config) || prevNode.__isUnlinked !== this.__isUnlinked;
|
|
284
|
-
}
|
|
285
|
-
static importJSON(serializedNode) {
|
|
286
|
-
const node = $createAutoLinkNode(serializedNode.url, {
|
|
287
|
-
isUnlinked: serializedNode.isUnlinked,
|
|
288
|
-
rel: serializedNode.rel,
|
|
289
|
-
target: serializedNode.target,
|
|
290
|
-
title: serializedNode.title
|
|
291
|
-
});
|
|
292
|
-
node.setFormat(serializedNode.format);
|
|
293
|
-
node.setIndent(serializedNode.indent);
|
|
294
|
-
node.setDirection(serializedNode.direction);
|
|
295
|
-
return node;
|
|
296
|
-
}
|
|
297
|
-
static importDOM() {
|
|
298
|
-
// TODO: Should link node should handle the import over autolink?
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
301
|
-
exportJSON() {
|
|
302
|
-
return {
|
|
303
|
-
...super.exportJSON(),
|
|
304
|
-
isUnlinked: this.__isUnlinked,
|
|
305
|
-
type: 'autolink',
|
|
306
|
-
version: 1
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
insertNewAfter(selection, restoreSelection = true) {
|
|
310
|
-
const element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection);
|
|
311
|
-
if (lexical.$isElementNode(element)) {
|
|
312
|
-
const linkNode = $createAutoLinkNode(this.__url, {
|
|
313
|
-
isUnlinked: this.__isUnlinked,
|
|
314
|
-
rel: this.__rel,
|
|
315
|
-
target: this.__target,
|
|
316
|
-
title: this.__title
|
|
317
|
-
});
|
|
318
|
-
element.append(linkNode);
|
|
319
|
-
return linkNode;
|
|
320
|
-
}
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Takes a URL and creates an AutoLinkNode. AutoLinkNodes are generally automatically generated
|
|
327
|
-
* during typing, which is especially useful when a button to generate a LinkNode is not practical.
|
|
328
|
-
* @param url - The URL the LinkNode should direct to.
|
|
329
|
-
* @param attributes - Optional HTML a tag attributes. \\{ target, rel, title \\}
|
|
330
|
-
* @returns The LinkNode.
|
|
331
|
-
*/
|
|
332
|
-
function $createAutoLinkNode(url, attributes) {
|
|
333
|
-
return lexical.$applyNodeReplacement(new AutoLinkNode(url, attributes));
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Determines if node is an AutoLinkNode.
|
|
338
|
-
* @param node - The node to be checked.
|
|
339
|
-
* @returns true if node is an AutoLinkNode, false otherwise.
|
|
340
|
-
*/
|
|
341
|
-
function $isAutoLinkNode(node) {
|
|
342
|
-
return node instanceof AutoLinkNode;
|
|
343
|
-
}
|
|
344
|
-
const TOGGLE_LINK_COMMAND = lexical.createCommand('TOGGLE_LINK_COMMAND');
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
|
|
348
|
-
* but saves any children and brings them up to the parent node.
|
|
349
|
-
* @param url - The URL the link directs to.
|
|
350
|
-
* @param attributes - Optional HTML a tag attributes. \\{ target, rel, title \\}
|
|
351
|
-
*/
|
|
352
|
-
function $toggleLink(url, attributes = {}) {
|
|
353
|
-
const {
|
|
354
|
-
target,
|
|
355
|
-
title
|
|
356
|
-
} = attributes;
|
|
357
|
-
const rel = attributes.rel === undefined ? 'noreferrer' : attributes.rel;
|
|
358
|
-
const selection = lexical.$getSelection();
|
|
359
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
const nodes = selection.extract();
|
|
363
|
-
if (url === null) {
|
|
364
|
-
// Remove LinkNodes
|
|
365
|
-
nodes.forEach(node => {
|
|
366
|
-
const parent = node.getParent();
|
|
367
|
-
if (!$isAutoLinkNode(parent) && $isLinkNode(parent)) {
|
|
368
|
-
const children = parent.getChildren();
|
|
369
|
-
for (let i = 0; i < children.length; i++) {
|
|
370
|
-
parent.insertBefore(children[i]);
|
|
371
|
-
}
|
|
372
|
-
parent.remove();
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
} else {
|
|
376
|
-
// Add or merge LinkNodes
|
|
377
|
-
if (nodes.length === 1) {
|
|
378
|
-
const firstNode = nodes[0];
|
|
379
|
-
// if the first node is a LinkNode or if its
|
|
380
|
-
// parent is a LinkNode, we update the URL, target and rel.
|
|
381
|
-
const linkNode = $getAncestor(firstNode, $isLinkNode);
|
|
382
|
-
if (linkNode !== null) {
|
|
383
|
-
linkNode.setURL(url);
|
|
384
|
-
if (target !== undefined) {
|
|
385
|
-
linkNode.setTarget(target);
|
|
386
|
-
}
|
|
387
|
-
if (rel !== null) {
|
|
388
|
-
linkNode.setRel(rel);
|
|
389
|
-
}
|
|
390
|
-
if (title !== undefined) {
|
|
391
|
-
linkNode.setTitle(title);
|
|
392
|
-
}
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
let prevParent = null;
|
|
397
|
-
let linkNode = null;
|
|
398
|
-
nodes.forEach(node => {
|
|
399
|
-
const parent = node.getParent();
|
|
400
|
-
if (parent === linkNode || parent === null || lexical.$isElementNode(node) && !node.isInline()) {
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
if ($isLinkNode(parent)) {
|
|
404
|
-
linkNode = parent;
|
|
405
|
-
parent.setURL(url);
|
|
406
|
-
if (target !== undefined) {
|
|
407
|
-
parent.setTarget(target);
|
|
408
|
-
}
|
|
409
|
-
if (rel !== null) {
|
|
410
|
-
linkNode.setRel(rel);
|
|
411
|
-
}
|
|
412
|
-
if (title !== undefined) {
|
|
413
|
-
linkNode.setTitle(title);
|
|
414
|
-
}
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
if (!parent.is(prevParent)) {
|
|
418
|
-
prevParent = parent;
|
|
419
|
-
linkNode = $createLinkNode(url, {
|
|
420
|
-
rel,
|
|
421
|
-
target,
|
|
422
|
-
title
|
|
423
|
-
});
|
|
424
|
-
if ($isLinkNode(parent)) {
|
|
425
|
-
if (node.getPreviousSibling() === null) {
|
|
426
|
-
parent.insertBefore(linkNode);
|
|
427
|
-
} else {
|
|
428
|
-
parent.insertAfter(linkNode);
|
|
429
|
-
}
|
|
430
|
-
} else {
|
|
431
|
-
node.insertBefore(linkNode);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
if ($isLinkNode(node)) {
|
|
435
|
-
if (node.is(linkNode)) {
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
if (linkNode !== null) {
|
|
439
|
-
const children = node.getChildren();
|
|
440
|
-
for (let i = 0; i < children.length; i++) {
|
|
441
|
-
linkNode.append(children[i]);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
node.remove();
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
if (linkNode !== null) {
|
|
448
|
-
linkNode.append(node);
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
/** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
|
|
454
|
-
const toggleLink = $toggleLink;
|
|
455
|
-
function $getAncestor(node, predicate) {
|
|
456
|
-
let parent = node;
|
|
457
|
-
while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
|
|
458
|
-
parent = parent.getParentOrThrow();
|
|
459
|
-
}
|
|
460
|
-
return predicate(parent) ? parent : null;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
exports.$createAutoLinkNode = $createAutoLinkNode;
|
|
464
|
-
exports.$createLinkNode = $createLinkNode;
|
|
465
|
-
exports.$isAutoLinkNode = $isAutoLinkNode;
|
|
466
|
-
exports.$isLinkNode = $isLinkNode;
|
|
467
|
-
exports.$toggleLink = $toggleLink;
|
|
468
|
-
exports.AutoLinkNode = AutoLinkNode;
|
|
469
|
-
exports.LinkNode = LinkNode;
|
|
470
|
-
exports.TOGGLE_LINK_COMMAND = TOGGLE_LINK_COMMAND;
|
|
471
|
-
exports.toggleLink = toggleLink;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var LexicalLink_dev = require('./LexicalLink.dev.js');
|
|
4
|
-
var LexicalLink_prod = require('./LexicalLink.prod.js');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the MIT license found in the
|
|
10
|
-
* LICENSE file in the root directory of this source tree.
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const mod = process.env.NODE_ENV === 'development' ? LexicalLink_dev : LexicalLink_prod;
|
|
15
|
-
const $isLinkNode = mod.$isLinkNode;
|
|
16
|
-
|
|
17
|
-
exports.$isLinkNode = $isLinkNode;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var LexicalUtils = require('../utils/LexicalUtils.js');
|
|
4
|
-
var lexical = require('lexical');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the MIT license found in the
|
|
10
|
-
* LICENSE file in the root directory of this source tree.
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const _=new Set(["http:","https:","mailto:","sms:","tel:"]);class o extends lexical.ElementNode{static getType(){return "link"}static clone(t){return new o(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t,e={},r){super(r);const{target:i=null,rel:n=null,title:l=null}=e;this.__url=t,this.__target=i,this.__rel=n,this.__title=l;}createDOM(e){const r=document.createElement("a");return r.href=this.sanitizeUrl(this.__url),null!==this.__target&&(r.target=this.__target),null!==this.__rel&&(r.rel=this.__rel),null!==this.__title&&(r.title=this.__title),LexicalUtils.addClassNamesToElement(r,e.theme.link),r}updateDOM(t,e,r){if(e instanceof HTMLAnchorElement){const r=this.__url,i=this.__target,n=this.__rel,l=this.__title;r!==t.__url&&(e.href=r),i!==t.__target&&(i?e.target=i:e.removeAttribute("target")),n!==t.__rel&&(n?e.rel=n:e.removeAttribute("rel")),l!==t.__title&&(l?e.title=l:e.removeAttribute("title"));}return !1}static importDOM(){return {a:t=>({conversion:a,priority:1})}}static importJSON(t){const e=h(t.url,{rel:t.rel,target:t.target,title:t.title});return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}sanitizeUrl(t){try{const e=new URL(t);if(!_.has(e.protocol))return "about:blank"}catch(e){return t}return t}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(t){this.getWritable().__url=t;}getTarget(){return this.getLatest().__target}setTarget(t){this.getWritable().__target=t;}getRel(){return this.getLatest().__rel}setRel(t){this.getWritable().__rel=t;}getTitle(){return this.getLatest().__title}setTitle(t){this.getWritable().__title=t;}insertNewAfter(t,e=!0){const r=h(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(r,e),r}canInsertTextBefore(){return !1}canInsertTextAfter(){return !1}canBeEmpty(){return !1}isInline(){return !0}extractWithChild(t,e,r){if(!lexical.$isRangeSelection(e))return !1;const i=e.anchor.getNode(),l=e.focus.getNode();return this.isParentOf(i)&&this.isParentOf(l)&&e.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function a(t){let r=null;if(LexicalUtils.isHTMLAnchorElement(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(r=h(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}));}return {node:r}}function h(t,e){return lexical.$applyNodeReplacement(new o(t,e))}function c(t){return t instanceof o}class g extends o{constructor(t,e={},r){super(t,e,r),this.__isUnlinked=void 0!==e.isUnlinked&&null!==e.isUnlinked&&e.isUnlinked;}static getType(){return "autolink"}static clone(t){return new g(t.__url,{isUnlinked:t.__isUnlinked,rel:t.__rel,target:t.__target,title:t.__title},t.__key)}getIsUnlinked(){return this.__isUnlinked}setIsUnlinked(t){const e=this.getWritable();return e.__isUnlinked=t,e}createDOM(t){return this.__isUnlinked?document.createElement("span"):super.createDOM(t)}updateDOM(t,e,r){return super.updateDOM(t,e,r)||t.__isUnlinked!==this.__isUnlinked}static importJSON(t){const e=f(t.url,{isUnlinked:t.isUnlinked,rel:t.rel,target:t.target,title:t.title});return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}static importDOM(){return null}exportJSON(){return {...super.exportJSON(),isUnlinked:this.__isUnlinked,type:"autolink",version:1}}insertNewAfter(t,e=!0){const r=this.getParentOrThrow().insertNewAfter(t,e);if(lexical.$isElementNode(r)){const t=f(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return r.append(t),t}return null}}function f(t,e){return lexical.$applyNodeReplacement(new g(t,e))}function d(t){return t instanceof g}const p=lexical.createCommand("TOGGLE_LINK_COMMAND");function U(t,e={}){const{target:r,title:i}=e,l=void 0===e.rel?"noreferrer":e.rel,_=lexical.$getSelection();if(!lexical.$isRangeSelection(_))return;const o=_.extract();if(null===t)o.forEach((t=>{const e=t.getParent();if(!d(e)&&c(e)){const t=e.getChildren();for(let r=0;r<t.length;r++)e.insertBefore(t[r]);e.remove();}}));else {if(1===o.length){const e=function(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}(o[0],c);if(null!==e)return e.setURL(t),void 0!==r&&e.setTarget(r),null!==l&&e.setRel(l),void(void 0!==i&&e.setTitle(i))}let e=null,n=null;o.forEach((u=>{const _=u.getParent();if(_!==n&&null!==_&&(!lexical.$isElementNode(u)||u.isInline())){if(c(_))return n=_,_.setURL(t),void 0!==r&&_.setTarget(r),null!==l&&n.setRel(l),void(void 0!==i&&n.setTitle(i));if(_.is(e)||(e=_,n=h(t,{rel:l,target:r,title:i}),c(_)?null===u.getPreviousSibling()?_.insertBefore(n):_.insertAfter(n):u.insertBefore(n)),c(u)){if(u.is(n))return;if(null!==n){const t=u.getChildren();for(let e=0;e<t.length;e++)n.append(t[e]);}u.remove();}else null!==n&&n.append(u);}}));}}const m=U;
|
|
15
|
-
|
|
16
|
-
exports.$createAutoLinkNode = f;
|
|
17
|
-
exports.$createLinkNode = h;
|
|
18
|
-
exports.$isAutoLinkNode = d;
|
|
19
|
-
exports.$isLinkNode = c;
|
|
20
|
-
exports.$toggleLink = U;
|
|
21
|
-
exports.AutoLinkNode = g;
|
|
22
|
-
exports.LinkNode = o;
|
|
23
|
-
exports.TOGGLE_LINK_COMMAND = p;
|
|
24
|
-
exports.toggleLink = m;
|