@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.
Files changed (62) hide show
  1. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
  2. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  3. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +9 -9
  4. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +142 -75
  5. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
  6. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +25 -21
  7. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +10 -3
  8. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
  9. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  10. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +147 -103
  11. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
  12. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +10 -10
  13. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +254 -178
  14. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
  15. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +19 -16
  16. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +53 -29
  17. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  18. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
  19. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +176 -194
  20. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +1 -1
  21. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +25 -18
  22. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +1925 -793
  23. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
  24. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +48 -40
  25. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +426 -144
  26. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +11 -1
  27. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +46 -32
  28. package/dist/cjs/node_modules/prismjs/prism.js +1 -1
  29. package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +1 -1
  30. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
  31. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  32. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
  33. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +139 -76
  34. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
  35. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
  36. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +11 -4
  37. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
  38. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  39. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +149 -105
  40. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
  41. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
  42. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +253 -180
  43. package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
  44. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +4 -4
  45. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -30
  46. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  47. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +3 -3
  48. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +171 -196
  49. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +1 -1
  50. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
  51. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +1920 -796
  52. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
  53. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
  54. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +413 -145
  55. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +7 -2
  56. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
  57. package/dist/esm/node_modules/prismjs/prism.js +1 -1
  58. package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +1 -1
  59. package/package.json +7 -8
  60. package/src/components/StickyComponent.tsx +1 -1
  61. package/src/editor/LexicalEditor.tsx +25 -21
  62. 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 instanceof HTMLAnchorElement) {
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
- 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;
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
- type: 'link',
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
- 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;
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 parent = node.getParent();
367
- if (!$isAutoLinkNode(parent) && $isLinkNode(parent)) {
368
- const children = parent.getChildren();
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
- parent.insertBefore(children[i]);
415
+ parentLink.insertBefore(children[i]);
371
416
  }
372
- parent.remove();
417
+ parentLink.remove();
373
418
  }
374
419
  });
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
- }
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
- let prevParent = null;
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
- nodes.forEach(node => {
399
- const parent = node.getParent();
400
- if (parent === linkNode || parent === null || $isElementNode(node) && !node.isInline()) {
401
- return;
451
+ for (const node of nodes) {
452
+ if (!node.isAttached()) {
453
+ continue;
402
454
  }
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
- }
455
+ const parentLinkNode = $getAncestor(node, $isLinkNode);
456
+ if (parentLinkNode) {
457
+ updateLinkNode(parentLinkNode);
458
+ continue;
433
459
  }
434
- if ($isLinkNode(node)) {
435
- if (node.is(linkNode)) {
436
- return;
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 (linkNode !== null) {
439
- const children = node.getChildren();
440
- for (let i = 0; i < children.length; i++) {
441
- linkNode.append(children[i]);
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
- if (linkNode !== null) {
448
- linkNode.append(node);
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 === 'development' ? LexicalLink_dev : LexicalLink_prod;
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 _=new Set(["http:","https:","mailto:","sms:","tel:"]);class o extends 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),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(!$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(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 $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($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 $applyNodeReplacement(new g(t,e))}function d(t){return t instanceof g}const p=createCommand("TOGGLE_LINK_COMMAND");function U(t,e={}){const{target:r,title:i}=e,l=void 0===e.rel?"noreferrer":e.rel,_=$getSelection();if(!$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!==_&&(!$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;
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 { f as $createAutoLinkNode, h as $createLinkNode, d as $isAutoLinkNode, c as $isLinkNode, U as $toggleLink, g as AutoLinkNode, o as LinkNode, p as TOGGLE_LINK_COMMAND, m as toggleLink };
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 };