@react-fabric/lexical 1.0.0-beta.47 → 1.0.0-beta.49
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/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +9 -9
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +142 -75
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +25 -21
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +10 -3
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +147 -103
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +254 -178
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +19 -16
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +53 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +176 -194
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +1 -1
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +25 -18
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +1925 -793
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +48 -40
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +426 -144
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +11 -1
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +46 -32
- package/dist/cjs/node_modules/prismjs/prism.js +1 -1
- package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +1 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +139 -76
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +11 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +149 -105
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +253 -180
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -30
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +171 -196
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +1 -1
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +1920 -796
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +413 -145
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +7 -2
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
- package/dist/esm/node_modules/prismjs/prism.js +1 -1
- package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +1 -1
- package/package.json +7 -8
- package/src/components/StickyComponent.tsx +1 -1
- package/src/editor/LexicalEditor.tsx +25 -21
- package/src/plugins/ToolbarPlugin.tsx +20 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { addClassNamesToElement, isHTMLAnchorElement } from '../utils/LexicalUtils.js';
|
|
4
|
-
import { ElementNode, $isRangeSelection, $applyNodeReplacement, $isElementNode, createCommand, $getSelection } from 'lexical';
|
|
3
|
+
import { addClassNamesToElement, isHTMLAnchorElement, $findMatchingParent } from '../utils/LexicalUtils.js';
|
|
4
|
+
import { ElementNode, $isRangeSelection, $applyNodeReplacement, $isElementNode, createCommand, $getSelection, $normalizeSelection__EXPERIMENTAL, $setSelection } from 'lexical';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -20,6 +20,12 @@ import { ElementNode, $isRangeSelection, $applyNodeReplacement, $isElementNode,
|
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
24
|
+
|
|
25
|
+
function formatDevErrorMessage(message) {
|
|
26
|
+
throw new Error(message);
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
|
|
24
30
|
|
|
25
31
|
/** @noInheritDoc */
|
|
@@ -42,7 +48,7 @@ class LinkNode extends ElementNode {
|
|
|
42
48
|
title: node.__title
|
|
43
49
|
}, node.__key);
|
|
44
50
|
}
|
|
45
|
-
constructor(url, attributes = {}, key) {
|
|
51
|
+
constructor(url = '', attributes = {}, key) {
|
|
46
52
|
super(key);
|
|
47
53
|
const {
|
|
48
54
|
target = null,
|
|
@@ -70,7 +76,7 @@ class LinkNode extends ElementNode {
|
|
|
70
76
|
return element;
|
|
71
77
|
}
|
|
72
78
|
updateDOM(prevNode, anchor, config) {
|
|
73
|
-
if (anchor
|
|
79
|
+
if (isHTMLAnchorElement(anchor)) {
|
|
74
80
|
const url = this.__url;
|
|
75
81
|
const target = this.__target;
|
|
76
82
|
const rel = this.__rel;
|
|
@@ -111,15 +117,10 @@ class LinkNode extends ElementNode {
|
|
|
111
117
|
};
|
|
112
118
|
}
|
|
113
119
|
static importJSON(serializedNode) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
node.setFormat(serializedNode.format);
|
|
120
|
-
node.setIndent(serializedNode.indent);
|
|
121
|
-
node.setDirection(serializedNode.direction);
|
|
122
|
-
return node;
|
|
120
|
+
return $createLinkNode().updateFromJSON(serializedNode);
|
|
121
|
+
}
|
|
122
|
+
updateFromJSON(serializedNode) {
|
|
123
|
+
return super.updateFromJSON(serializedNode).setURL(serializedNode.url).setRel(serializedNode.rel || null).setTarget(serializedNode.target || null).setTitle(serializedNode.title || null);
|
|
123
124
|
}
|
|
124
125
|
sanitizeUrl(url) {
|
|
125
126
|
try {
|
|
@@ -139,9 +140,7 @@ class LinkNode extends ElementNode {
|
|
|
139
140
|
rel: this.getRel(),
|
|
140
141
|
target: this.getTarget(),
|
|
141
142
|
title: this.getTitle(),
|
|
142
|
-
|
|
143
|
-
url: this.getURL(),
|
|
144
|
-
version: 1
|
|
143
|
+
url: this.getURL()
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
146
|
getURL() {
|
|
@@ -150,6 +149,7 @@ class LinkNode extends ElementNode {
|
|
|
150
149
|
setURL(url) {
|
|
151
150
|
const writable = this.getWritable();
|
|
152
151
|
writable.__url = url;
|
|
152
|
+
return writable;
|
|
153
153
|
}
|
|
154
154
|
getTarget() {
|
|
155
155
|
return this.getLatest().__target;
|
|
@@ -157,6 +157,7 @@ class LinkNode extends ElementNode {
|
|
|
157
157
|
setTarget(target) {
|
|
158
158
|
const writable = this.getWritable();
|
|
159
159
|
writable.__target = target;
|
|
160
|
+
return writable;
|
|
160
161
|
}
|
|
161
162
|
getRel() {
|
|
162
163
|
return this.getLatest().__rel;
|
|
@@ -164,6 +165,7 @@ class LinkNode extends ElementNode {
|
|
|
164
165
|
setRel(rel) {
|
|
165
166
|
const writable = this.getWritable();
|
|
166
167
|
writable.__rel = rel;
|
|
168
|
+
return writable;
|
|
167
169
|
}
|
|
168
170
|
getTitle() {
|
|
169
171
|
return this.getLatest().__title;
|
|
@@ -171,6 +173,7 @@ class LinkNode extends ElementNode {
|
|
|
171
173
|
setTitle(title) {
|
|
172
174
|
const writable = this.getWritable();
|
|
173
175
|
writable.__title = title;
|
|
176
|
+
return writable;
|
|
174
177
|
}
|
|
175
178
|
insertNewAfter(_, restoreSelection = true) {
|
|
176
179
|
const linkNode = $createLinkNode(this.__url, {
|
|
@@ -231,7 +234,7 @@ function $convertAnchorElement(domNode) {
|
|
|
231
234
|
* @param attributes - Optional HTML a tag attributes \\{ target, rel, title \\}
|
|
232
235
|
* @returns The LinkNode.
|
|
233
236
|
*/
|
|
234
|
-
function $createLinkNode(url, attributes) {
|
|
237
|
+
function $createLinkNode(url = '', attributes) {
|
|
235
238
|
return $applyNodeReplacement(new LinkNode(url, attributes));
|
|
236
239
|
}
|
|
237
240
|
|
|
@@ -249,7 +252,7 @@ class AutoLinkNode extends LinkNode {
|
|
|
249
252
|
/** @internal */
|
|
250
253
|
/** Indicates whether the autolink was ever unlinked. **/
|
|
251
254
|
|
|
252
|
-
constructor(url, attributes = {}, key) {
|
|
255
|
+
constructor(url = '', attributes = {}, key) {
|
|
253
256
|
super(url, attributes, key);
|
|
254
257
|
this.__isUnlinked = attributes.isUnlinked !== undefined && attributes.isUnlinked !== null ? attributes.isUnlinked : false;
|
|
255
258
|
}
|
|
@@ -283,16 +286,10 @@ class AutoLinkNode extends LinkNode {
|
|
|
283
286
|
return super.updateDOM(prevNode, anchor, config) || prevNode.__isUnlinked !== this.__isUnlinked;
|
|
284
287
|
}
|
|
285
288
|
static importJSON(serializedNode) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
title: serializedNode.title
|
|
291
|
-
});
|
|
292
|
-
node.setFormat(serializedNode.format);
|
|
293
|
-
node.setIndent(serializedNode.indent);
|
|
294
|
-
node.setDirection(serializedNode.direction);
|
|
295
|
-
return node;
|
|
289
|
+
return $createAutoLinkNode().updateFromJSON(serializedNode);
|
|
290
|
+
}
|
|
291
|
+
updateFromJSON(serializedNode) {
|
|
292
|
+
return super.updateFromJSON(serializedNode).setIsUnlinked(serializedNode.isUnlinked || false);
|
|
296
293
|
}
|
|
297
294
|
static importDOM() {
|
|
298
295
|
// TODO: Should link node should handle the import over autolink?
|
|
@@ -301,9 +298,7 @@ class AutoLinkNode extends LinkNode {
|
|
|
301
298
|
exportJSON() {
|
|
302
299
|
return {
|
|
303
300
|
...super.exportJSON(),
|
|
304
|
-
isUnlinked: this.__isUnlinked
|
|
305
|
-
type: 'autolink',
|
|
306
|
-
version: 1
|
|
301
|
+
isUnlinked: this.__isUnlinked
|
|
307
302
|
};
|
|
308
303
|
}
|
|
309
304
|
insertNewAfter(selection, restoreSelection = true) {
|
|
@@ -329,7 +324,7 @@ class AutoLinkNode extends LinkNode {
|
|
|
329
324
|
* @param attributes - Optional HTML a tag attributes. \\{ target, rel, title \\}
|
|
330
325
|
* @returns The LinkNode.
|
|
331
326
|
*/
|
|
332
|
-
function $createAutoLinkNode(url, attributes) {
|
|
327
|
+
function $createAutoLinkNode(url = '', attributes) {
|
|
333
328
|
return $applyNodeReplacement(new AutoLinkNode(url, attributes));
|
|
334
329
|
}
|
|
335
330
|
|
|
@@ -342,6 +337,56 @@ function $isAutoLinkNode(node) {
|
|
|
342
337
|
return node instanceof AutoLinkNode;
|
|
343
338
|
}
|
|
344
339
|
const TOGGLE_LINK_COMMAND = createCommand('TOGGLE_LINK_COMMAND');
|
|
340
|
+
function $getPointNode(point, offset) {
|
|
341
|
+
if (point.type === 'element') {
|
|
342
|
+
const node = point.getNode();
|
|
343
|
+
if (!$isElementNode(node)) {
|
|
344
|
+
formatDevErrorMessage(`$getPointNode: element point is not an ElementNode`);
|
|
345
|
+
}
|
|
346
|
+
const childNode = node.getChildren()[point.offset + offset];
|
|
347
|
+
return childNode || null;
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Preserve the logical start/end of a RangeSelection in situations where
|
|
354
|
+
* the point is an element that may be reparented in the callback.
|
|
355
|
+
*
|
|
356
|
+
* @param $fn The function to run
|
|
357
|
+
* @returns The result of the callback
|
|
358
|
+
*/
|
|
359
|
+
function $withSelectedNodes($fn) {
|
|
360
|
+
const initialSelection = $getSelection();
|
|
361
|
+
if (!$isRangeSelection(initialSelection)) {
|
|
362
|
+
return $fn();
|
|
363
|
+
}
|
|
364
|
+
const normalized = $normalizeSelection__EXPERIMENTAL(initialSelection);
|
|
365
|
+
const isBackwards = normalized.isBackward();
|
|
366
|
+
const anchorNode = $getPointNode(normalized.anchor, isBackwards ? -1 : 0);
|
|
367
|
+
const focusNode = $getPointNode(normalized.focus, isBackwards ? 0 : -1);
|
|
368
|
+
const rval = $fn();
|
|
369
|
+
if (anchorNode || focusNode) {
|
|
370
|
+
const updatedSelection = $getSelection();
|
|
371
|
+
if ($isRangeSelection(updatedSelection)) {
|
|
372
|
+
const finalSelection = updatedSelection.clone();
|
|
373
|
+
if (anchorNode) {
|
|
374
|
+
const anchorParent = anchorNode.getParent();
|
|
375
|
+
if (anchorParent) {
|
|
376
|
+
finalSelection.anchor.set(anchorParent.getKey(), anchorNode.getIndexWithinParent() + (isBackwards ? 1 : 0), 'element');
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (focusNode) {
|
|
380
|
+
const focusParent = focusNode.getParent();
|
|
381
|
+
if (focusParent) {
|
|
382
|
+
finalSelection.focus.set(focusParent.getKey(), focusNode.getIndexWithinParent() + (isBackwards ? 0 : 1), 'element');
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
$setSelection($normalizeSelection__EXPERIMENTAL(finalSelection));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return rval;
|
|
389
|
+
}
|
|
345
390
|
|
|
346
391
|
/**
|
|
347
392
|
* Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
|
|
@@ -363,92 +408,91 @@ function $toggleLink(url, attributes = {}) {
|
|
|
363
408
|
if (url === null) {
|
|
364
409
|
// Remove LinkNodes
|
|
365
410
|
nodes.forEach(node => {
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
368
|
-
const children =
|
|
411
|
+
const parentLink = $findMatchingParent(node, parent => !$isAutoLinkNode(parent) && $isLinkNode(parent));
|
|
412
|
+
if (parentLink) {
|
|
413
|
+
const children = parentLink.getChildren();
|
|
369
414
|
for (let i = 0; i < children.length; i++) {
|
|
370
|
-
|
|
415
|
+
parentLink.insertBefore(children[i]);
|
|
371
416
|
}
|
|
372
|
-
|
|
417
|
+
parentLink.remove();
|
|
373
418
|
}
|
|
374
419
|
});
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
if (title !== undefined) {
|
|
391
|
-
linkNode.setTitle(title);
|
|
392
|
-
}
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const updatedNodes = new Set();
|
|
423
|
+
const updateLinkNode = linkNode => {
|
|
424
|
+
if (updatedNodes.has(linkNode.getKey())) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
updatedNodes.add(linkNode.getKey());
|
|
428
|
+
linkNode.setURL(url);
|
|
429
|
+
if (target !== undefined) {
|
|
430
|
+
linkNode.setTarget(target);
|
|
431
|
+
}
|
|
432
|
+
if (rel !== undefined) {
|
|
433
|
+
linkNode.setRel(rel);
|
|
395
434
|
}
|
|
396
|
-
|
|
435
|
+
if (title !== undefined) {
|
|
436
|
+
linkNode.setTitle(title);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
// Add or merge LinkNodes
|
|
440
|
+
if (nodes.length === 1) {
|
|
441
|
+
const firstNode = nodes[0];
|
|
442
|
+
// if the first node is a LinkNode or if its
|
|
443
|
+
// parent is a LinkNode, we update the URL, target and rel.
|
|
444
|
+
const linkNode = $getAncestor(firstNode, $isLinkNode);
|
|
445
|
+
if (linkNode !== null) {
|
|
446
|
+
return updateLinkNode(linkNode);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
$withSelectedNodes(() => {
|
|
397
450
|
let linkNode = null;
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
return;
|
|
451
|
+
for (const node of nodes) {
|
|
452
|
+
if (!node.isAttached()) {
|
|
453
|
+
continue;
|
|
402
454
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
}
|
|
455
|
+
const parentLinkNode = $getAncestor(node, $isLinkNode);
|
|
456
|
+
if (parentLinkNode) {
|
|
457
|
+
updateLinkNode(parentLinkNode);
|
|
458
|
+
continue;
|
|
433
459
|
}
|
|
434
|
-
if ($
|
|
435
|
-
if (node.
|
|
436
|
-
|
|
460
|
+
if ($isElementNode(node)) {
|
|
461
|
+
if (!node.isInline()) {
|
|
462
|
+
// Ignore block nodes, if there are any children we will see them
|
|
463
|
+
// later and wrap in a new LinkNode
|
|
464
|
+
continue;
|
|
437
465
|
}
|
|
438
|
-
if (
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
466
|
+
if ($isLinkNode(node)) {
|
|
467
|
+
// If it's not an autolink node and we don't already have a LinkNode
|
|
468
|
+
// in this block then we can update it and re-use it
|
|
469
|
+
if (!$isAutoLinkNode(node) && (linkNode === null || !linkNode.getParentOrThrow().isParentOf(node))) {
|
|
470
|
+
updateLinkNode(node);
|
|
471
|
+
linkNode = node;
|
|
472
|
+
continue;
|
|
442
473
|
}
|
|
474
|
+
// Unwrap LinkNode, we already have one or it's an AutoLinkNode
|
|
475
|
+
for (const child of node.getChildren()) {
|
|
476
|
+
node.insertBefore(child);
|
|
477
|
+
}
|
|
478
|
+
node.remove();
|
|
479
|
+
continue;
|
|
443
480
|
}
|
|
444
|
-
node.remove();
|
|
445
|
-
return;
|
|
446
481
|
}
|
|
447
|
-
|
|
448
|
-
|
|
482
|
+
const prevLinkNode = node.getPreviousSibling();
|
|
483
|
+
if ($isLinkNode(prevLinkNode) && prevLinkNode.is(linkNode)) {
|
|
484
|
+
prevLinkNode.append(node);
|
|
485
|
+
continue;
|
|
449
486
|
}
|
|
450
|
-
|
|
451
|
-
|
|
487
|
+
linkNode = $createLinkNode(url, {
|
|
488
|
+
rel,
|
|
489
|
+
target,
|
|
490
|
+
title
|
|
491
|
+
});
|
|
492
|
+
node.insertAfter(linkNode);
|
|
493
|
+
linkNode.append(node);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
452
496
|
}
|
|
453
497
|
/** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
|
|
454
498
|
const toggleLink = $toggleLink;
|
|
@@ -11,7 +11,7 @@ import * as LexicalLink_prod from './LexicalLink.prod.js';
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const mod = process.env.NODE_ENV
|
|
14
|
+
const mod = process.env.NODE_ENV !== 'production' ? LexicalLink_dev : LexicalLink_prod;
|
|
15
15
|
const $isLinkNode = mod.$isLinkNode;
|
|
16
16
|
|
|
17
17
|
export { $isLinkNode };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { addClassNamesToElement, isHTMLAnchorElement } from '../utils/LexicalUtils.js';
|
|
4
|
-
import { ElementNode, $isRangeSelection, $applyNodeReplacement, $isElementNode, createCommand, $getSelection } from 'lexical';
|
|
3
|
+
import { addClassNamesToElement, isHTMLAnchorElement, $findMatchingParent } from '../utils/LexicalUtils.js';
|
|
4
|
+
import { ElementNode, $isRangeSelection, $applyNodeReplacement, $isElementNode, createCommand, $getSelection, $normalizeSelection__EXPERIMENTAL, $setSelection } from 'lexical';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -11,6 +11,6 @@ import { ElementNode, $isRangeSelection, $applyNodeReplacement, $isElementNode,
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const c=new Set(["http:","https:","mailto:","sms:","tel:"]);class h extends ElementNode{static getType(){return "link"}static clone(t){return new h(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t="",e={},r){super(r);const{target:n=null,rel:i=null,title:s=null}=e;this.__url=t,this.__target=n,this.__rel=i,this.__title=s;}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),addClassNamesToElement(r,e.theme.link),r}updateDOM(t,r,n){if(isHTMLAnchorElement(r)){const e=this.__url,n=this.__target,i=this.__rel,s=this.__title;e!==t.__url&&(r.href=e),n!==t.__target&&(n?r.target=n:r.removeAttribute("target")),i!==t.__rel&&(i?r.rel=i:r.removeAttribute("rel")),s!==t.__title&&(s?r.title=s:r.removeAttribute("title"));}return !1}static importDOM(){return {a:t=>({conversion:g,priority:1})}}static importJSON(t){return f().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setURL(t.url).setRel(t.rel||null).setTarget(t.target||null).setTitle(t.title||null)}sanitizeUrl(t){try{const e=new URL(t);if(!c.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(),url:this.getURL()}}getURL(){return this.getLatest().__url}setURL(t){const e=this.getWritable();return e.__url=t,e}getTarget(){return this.getLatest().__target}setTarget(t){const e=this.getWritable();return e.__target=t,e}getRel(){return this.getLatest().__rel}setRel(t){const e=this.getWritable();return e.__rel=t,e}getTitle(){return this.getLatest().__title}setTitle(t){const e=this.getWritable();return e.__title=t,e}insertNewAfter(t,e=!0){const r=f(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(!$isRangeSelection(e))return !1;const n=e.anchor.getNode(),i=e.focus.getNode();return this.isParentOf(n)&&this.isParentOf(i)&&e.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function g(t){let r=null;if(isHTMLAnchorElement(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(r=f(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}));}return {node:r}}function f(t="",e){return $applyNodeReplacement(new h(t,e))}function d(t){return t instanceof h}class p extends h{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 p(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){return m().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setIsUnlinked(t.isUnlinked||!1)}static importDOM(){return null}exportJSON(){return {...super.exportJSON(),isUnlinked:this.__isUnlinked}}insertNewAfter(t,e=!0){const r=this.getParentOrThrow().insertNewAfter(t,e);if($isElementNode(r)){const t=m(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return r.append(t),t}return null}}function m(t="",e){return $applyNodeReplacement(new p(t,e))}function U(t){return t instanceof p}const O=createCommand("TOGGLE_LINK_COMMAND");function k(t,e){if("element"===t.type){const r=t.getNode();$isElementNode(r)||function(t,...e){const r=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",t);for(const t of e)n.append("v",t);throw r.search=n.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(252);return r.getChildren()[t.offset+e]||null}return null}function N(t,e={}){const{target:n,title:i}=e,l=void 0===e.rel?"noreferrer":e.rel,c=$getSelection();if(!$isRangeSelection(c))return;const h=c.extract();if(null===t)return void h.forEach((t=>{const e=$findMatchingParent(t,(t=>!U(t)&&d(t)));if(e){const t=e.getChildren();for(let r=0;r<t.length;r++)e.insertBefore(t[r]);e.remove();}}));const g=new Set,p=e=>{g.has(e.getKey())||(g.add(e.getKey()),e.setURL(t),void 0!==n&&e.setTarget(n),void 0!==l&&e.setRel(l),void 0!==i&&e.setTitle(i));};if(1===h.length){const t=S(h[0],d);if(null!==t)return p(t)}!function(t){const e=$getSelection();if(!$isRangeSelection(e))return t();const r=$normalizeSelection__EXPERIMENTAL(e),n=r.isBackward(),i=k(r.anchor,n?-1:0),l=k(r.focus,n?0:-1);t();if(i||l){const t=$getSelection();if($isRangeSelection(t)){const e=t.clone();if(i){const t=i.getParent();t&&e.anchor.set(t.getKey(),i.getIndexWithinParent()+(n?1:0),"element");}if(l){const t=l.getParent();t&&e.focus.set(t.getKey(),l.getIndexWithinParent()+(n?0:1),"element");}$setSelection($normalizeSelection__EXPERIMENTAL(e));}}}((()=>{let e=null;for(const r of h){if(!r.isAttached())continue;const s=S(r,d);if(s){p(s);continue}if($isElementNode(r)){if(!r.isInline())continue;if(d(r)){if(!(U(r)||null!==e&&e.getParentOrThrow().isParentOf(r))){p(r),e=r;continue}for(const t of r.getChildren())r.insertBefore(t);r.remove();continue}}const u=r.getPreviousSibling();d(u)&&u.is(e)?u.append(r):(e=f(t,{rel:l,target:n,title:i}),r.insertAfter(e),e.append(r));}}));}const x=N;function S(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}
|
|
15
15
|
|
|
16
|
-
export {
|
|
16
|
+
export { m as $createAutoLinkNode, f as $createLinkNode, U as $isAutoLinkNode, d as $isLinkNode, N as $toggleLink, p as AutoLinkNode, h as LinkNode, O as TOGGLE_LINK_COMMAND, x as toggleLink };
|