@react-fabric/lexical 1.0.0-beta.5 → 1.0.0-beta.52

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 (76) hide show
  1. package/{src/editor/Lexical.module.css → css/_lexical.css} +4 -4
  2. package/css/styles.css +24 -0
  3. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
  4. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  5. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +9 -9
  6. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +142 -75
  7. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
  8. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +25 -21
  9. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +10 -3
  10. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
  11. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  12. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +147 -103
  13. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
  14. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +10 -10
  15. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +254 -178
  16. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
  17. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +19 -16
  18. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +53 -29
  19. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  20. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
  21. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +176 -194
  22. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +1 -1
  23. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +25 -18
  24. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +1925 -793
  25. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
  26. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +48 -40
  27. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +426 -144
  28. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +11 -1
  29. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +46 -32
  30. package/dist/cjs/node_modules/prismjs/prism.js +1 -1
  31. package/dist/cjs/packages/lexical/src/components/StickyComponent.js +1 -1
  32. package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +29 -5
  33. package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +81 -76
  34. package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +4 -6
  35. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
  36. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  37. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
  38. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +139 -76
  39. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
  40. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
  41. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +11 -4
  42. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
  43. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  44. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +149 -105
  45. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
  46. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
  47. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +253 -180
  48. package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
  49. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +4 -4
  50. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -30
  51. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  52. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +3 -3
  53. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +171 -196
  54. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +1 -1
  55. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
  56. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +1920 -796
  57. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
  58. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
  59. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +413 -145
  60. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +7 -2
  61. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
  62. package/dist/esm/node_modules/prismjs/prism.js +1 -1
  63. package/dist/esm/packages/lexical/src/components/StickyComponent.js +1 -1
  64. package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +29 -5
  65. package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +82 -77
  66. package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +4 -6
  67. package/dist/types/editor/LexicalEditor.d.ts +25 -0
  68. package/dist/types/hooks/useFormatWatcher.d.ts +2 -2
  69. package/dist/types/nodes/StickyNode.d.ts +0 -1
  70. package/package.json +13 -12
  71. package/src/components/StickyComponent.tsx +2 -2
  72. package/src/editor/LexicalEditor.tsx +53 -25
  73. package/src/hooks/useFormatWatcher.ts +28 -27
  74. package/src/plugins/ToolbarPlugin.tsx +22 -6
  75. package/dist/cjs/editor/Lexical.module.css +0 -1
  76. package/dist/esm/editor/Lexical.module.css +0 -1
@@ -11,6 +11,20 @@ var lexical = require('lexical');
11
11
  */
12
12
 
13
13
 
14
+ /**
15
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ *
20
+ */
21
+
22
+ // Do not require this module directly! Use normal `invariant` calls.
23
+
24
+ function formatDevErrorMessage(message) {
25
+ throw new Error(message);
26
+ }
27
+
14
28
  /**
15
29
  * Copyright (c) Meta Platforms, Inc. and affiliates.
16
30
  *
@@ -146,6 +160,9 @@ function createRectsFromDOMRange(editor, range) {
146
160
  */
147
161
  function getStyleObjectFromRawCSS(css) {
148
162
  const styleObject = {};
163
+ if (!css) {
164
+ return styleObject;
165
+ }
149
166
  const styles = css.split(';');
150
167
  for (const style of styles) {
151
168
  if (style !== '') {
@@ -191,14 +208,6 @@ function getCSSFromStyleObject(styles) {
191
208
  return css;
192
209
  }
193
210
 
194
- /**
195
- * Copyright (c) Meta Platforms, Inc. and affiliates.
196
- *
197
- * This source code is licensed under the MIT license found in the
198
- * LICENSE file in the root directory of this source tree.
199
- *
200
- */
201
-
202
211
  /**
203
212
  * Generally used to append text content to HTML and JSON. Grabs the text content and "slices"
204
213
  * it to be generated into the new TextNode.
@@ -252,7 +261,7 @@ function $isAtNodeEnd(point) {
252
261
  }
253
262
  const node = point.getNode();
254
263
  if (!lexical.$isElementNode(node)) {
255
- throw Error(`isAtNodeEnd: node must be a TextNode or ElementNode`);
264
+ formatDevErrorMessage(`isAtNodeEnd: node must be a TextNode or ElementNode`);
256
265
  }
257
266
  return point.offset === node.getChildrenSize();
258
267
  }
@@ -378,8 +387,19 @@ function $addNodeStyle(node) {
378
387
  const styles = getStyleObjectFromRawCSS(CSSText);
379
388
  CSS_TO_STYLES.set(CSSText, styles);
380
389
  }
390
+
391
+ /**
392
+ * Applies the provided styles to the given TextNode, ElementNode, or
393
+ * collapsed RangeSelection.
394
+ *
395
+ * @param target - The TextNode, ElementNode, or collapsed RangeSelection to apply the styles to
396
+ * @param patch - The patch to apply, which can include multiple styles. \\{CSSProperty: value\\} . Can also accept a function that returns the new property value.
397
+ */
381
398
  function $patchStyle(target, patch) {
382
- const prevStyles = getStyleObjectFromCSS('getStyle' in target ? target.getStyle() : target.style);
399
+ if (!(lexical.$isRangeSelection(target) ? target.isCollapsed() : lexical.$isTextNode(target) || lexical.$isElementNode(target))) {
400
+ formatDevErrorMessage(`$patchStyle must only be called with a TextNode, ElementNode, or collapsed RangeSelection`);
401
+ }
402
+ const prevStyles = getStyleObjectFromCSS(lexical.$isRangeSelection(target) ? target.style : lexical.$isTextNode(target) ? target.getStyle() : target.getTextStyle());
383
403
  const newStyles = Object.entries(patch).reduce((styles, [key, value]) => {
384
404
  if (typeof value === 'function') {
385
405
  styles[key] = value(prevStyles[key], target);
@@ -391,9 +411,13 @@ function $patchStyle(target, patch) {
391
411
  return styles;
392
412
  }, {
393
413
  ...prevStyles
394
- } || {});
414
+ });
395
415
  const newCSSText = getCSSFromStyleObject(newStyles);
396
- target.setStyle(newCSSText);
416
+ if (lexical.$isRangeSelection(target) || lexical.$isTextNode(target)) {
417
+ target.setStyle(newCSSText);
418
+ } else {
419
+ target.setTextStyle(newCSSText);
420
+ }
397
421
  CSS_TO_STYLES.set(newCSSText, newStyles);
398
422
  }
399
423
 
@@ -405,161 +429,147 @@ function $patchStyle(target, patch) {
405
429
  * @param patch - The patch to apply, which can include multiple styles. \\{CSSProperty: value\\} . Can also accept a function that returns the new property value.
406
430
  */
407
431
  function $patchStyleText(selection, patch) {
408
- const selectedNodes = selection.getNodes();
409
- const selectedNodesLength = selectedNodes.length;
410
- const anchorAndFocus = selection.getStartEndPoints();
411
- if (anchorAndFocus === null) {
412
- return;
413
- }
414
- const [anchor, focus] = anchorAndFocus;
415
- const lastIndex = selectedNodesLength - 1;
416
- let firstNode = selectedNodes[0];
417
- let lastNode = selectedNodes[lastIndex];
418
- if (selection.isCollapsed() && lexical.$isRangeSelection(selection)) {
432
+ if (lexical.$isRangeSelection(selection) && selection.isCollapsed()) {
419
433
  $patchStyle(selection, patch);
434
+ const emptyNode = selection.anchor.getNode();
435
+ if (lexical.$isElementNode(emptyNode) && emptyNode.isEmpty()) {
436
+ $patchStyle(emptyNode, patch);
437
+ }
438
+ }
439
+ $forEachSelectedTextNode(textNode => {
440
+ $patchStyle(textNode, patch);
441
+ });
442
+ }
443
+ function $forEachSelectedTextNode(fn) {
444
+ const selection = lexical.$getSelection();
445
+ if (!selection) {
420
446
  return;
421
447
  }
422
- const firstNodeText = firstNode.getTextContent();
423
- const firstNodeTextLength = firstNodeText.length;
424
- const focusOffset = focus.offset;
425
- let anchorOffset = anchor.offset;
426
- const isBefore = anchor.isBefore(focus);
427
- let startOffset = isBefore ? anchorOffset : focusOffset;
428
- let endOffset = isBefore ? focusOffset : anchorOffset;
429
- const startType = isBefore ? anchor.type : focus.type;
430
- const endType = isBefore ? focus.type : anchor.type;
431
- const endKey = isBefore ? focus.key : anchor.key;
432
-
433
- // This is the case where the user only selected the very end of the
434
- // first node so we don't want to include it in the formatting change.
435
- if (lexical.$isTextNode(firstNode) && startOffset === firstNodeTextLength) {
436
- const nextSibling = firstNode.getNextSibling();
437
- if (lexical.$isTextNode(nextSibling)) {
438
- // we basically make the second node the firstNode, changing offsets accordingly
439
- anchorOffset = 0;
440
- startOffset = 0;
441
- firstNode = nextSibling;
442
- }
443
- }
444
-
445
- // This is the case where we only selected a single node
446
- if (selectedNodes.length === 1) {
447
- if (lexical.$isTextNode(firstNode) && firstNode.canHaveFormat()) {
448
- startOffset = startType === 'element' ? 0 : anchorOffset > focusOffset ? focusOffset : anchorOffset;
449
- endOffset = endType === 'element' ? firstNodeTextLength : anchorOffset > focusOffset ? anchorOffset : focusOffset;
450
-
451
- // No actual text is selected, so do nothing.
452
- if (startOffset === endOffset) {
453
- return;
454
- }
455
-
456
- // The entire node is selected or a token/segment, so just format it
457
- if (lexical.$isTokenOrSegmented(firstNode) || startOffset === 0 && endOffset === firstNodeTextLength) {
458
- $patchStyle(firstNode, patch);
459
- firstNode.select(startOffset, endOffset);
460
- } else {
461
- // The node is partially selected, so split it into two nodes
462
- // and style the selected one.
463
- const splitNodes = firstNode.splitText(startOffset, endOffset);
464
- const replacement = startOffset === 0 ? splitNodes[0] : splitNodes[1];
465
- $patchStyle(replacement, patch);
466
- replacement.select(0, endOffset - startOffset);
467
- }
468
- } // multiple nodes selected.
469
- } else {
470
- if (lexical.$isTextNode(firstNode) && startOffset < firstNode.getTextContentSize() && firstNode.canHaveFormat()) {
471
- if (startOffset !== 0 && !lexical.$isTokenOrSegmented(firstNode)) {
472
- // the entire first node isn't selected and it isn't a token or segmented, so split it
473
- firstNode = firstNode.splitText(startOffset)[1];
474
- startOffset = 0;
475
- if (isBefore) {
476
- anchor.set(firstNode.getKey(), startOffset, 'text');
477
- } else {
478
- focus.set(firstNode.getKey(), startOffset, 'text');
479
- }
480
- }
481
- $patchStyle(firstNode, patch);
482
- }
483
- if (lexical.$isTextNode(lastNode) && lastNode.canHaveFormat()) {
484
- const lastNodeText = lastNode.getTextContent();
485
- const lastNodeTextLength = lastNodeText.length;
486
-
487
- // The last node might not actually be the end node
488
- //
489
- // If not, assume the last node is fully-selected unless the end offset is
490
- // zero.
491
- if (lastNode.__key !== endKey && endOffset !== 0) {
492
- endOffset = lastNodeTextLength;
493
- }
494
-
495
- // if the entire last node isn't selected and it isn't a token or segmented, split it
496
- if (endOffset !== lastNodeTextLength && !lexical.$isTokenOrSegmented(lastNode)) {
497
- [lastNode] = lastNode.splitText(endOffset);
498
- }
499
- if (endOffset !== 0 || endType === 'element') {
500
- $patchStyle(lastNode, patch);
448
+ const slicedTextNodes = new Map();
449
+ const getSliceIndices = node => slicedTextNodes.get(node.getKey()) || [0, node.getTextContentSize()];
450
+ if (lexical.$isRangeSelection(selection)) {
451
+ for (const slice of lexical.$caretRangeFromSelection(selection).getTextSlices()) {
452
+ if (slice) {
453
+ slicedTextNodes.set(slice.caret.origin.getKey(), slice.getSliceIndices());
501
454
  }
502
455
  }
456
+ }
457
+ const selectedNodes = selection.getNodes();
458
+ for (const selectedNode of selectedNodes) {
459
+ if (!(lexical.$isTextNode(selectedNode) && selectedNode.canHaveFormat())) {
460
+ continue;
461
+ }
462
+ const [startOffset, endOffset] = getSliceIndices(selectedNode);
463
+ // No actual text is selected, so do nothing.
464
+ if (endOffset === startOffset) {
465
+ continue;
466
+ }
503
467
 
504
- // style all the text nodes in between
505
- for (let i = 1; i < lastIndex; i++) {
506
- const selectedNode = selectedNodes[i];
507
- const selectedNodeKey = selectedNode.getKey();
508
- if (lexical.$isTextNode(selectedNode) && selectedNode.canHaveFormat() && selectedNodeKey !== firstNode.getKey() && selectedNodeKey !== lastNode.getKey() && !selectedNode.isToken()) {
509
- $patchStyle(selectedNode, patch);
510
- }
468
+ // The entire node is selected or a token/segment, so just format it
469
+ if (lexical.$isTokenOrSegmented(selectedNode) || startOffset === 0 && endOffset === selectedNode.getTextContentSize()) {
470
+ fn(selectedNode);
471
+ } else {
472
+ // The node is partially selected, so split it into two or three nodes
473
+ // and style the selected one.
474
+ const splitNodes = selectedNode.splitText(startOffset, endOffset);
475
+ const replacement = splitNodes[startOffset === 0 ? 0 : 1];
476
+ fn(replacement);
511
477
  }
512
478
  }
479
+ // Prior to NodeCaret #7046 this would have been a side-effect
480
+ // so we do this for test compatibility.
481
+ // TODO: we may want to consider simplifying by removing this
482
+ if (lexical.$isRangeSelection(selection) && selection.anchor.type === 'text' && selection.focus.type === 'text' && selection.anchor.key === selection.focus.key) {
483
+ $ensureForwardRangeSelection(selection);
484
+ }
513
485
  }
514
486
 
515
487
  /**
516
- * Copyright (c) Meta Platforms, Inc. and affiliates.
517
- *
518
- * This source code is licensed under the MIT license found in the
519
- * LICENSE file in the root directory of this source tree.
488
+ * Ensure that the given RangeSelection is not backwards. If it
489
+ * is backwards, then the anchor and focus points will be swapped
490
+ * in-place. Ensuring that the selection is a writable RangeSelection
491
+ * is the responsibility of the caller (e.g. in a read-only context
492
+ * you will want to clone $getSelection() before using this).
520
493
  *
494
+ * @param selection a writable RangeSelection
521
495
  */
496
+ function $ensureForwardRangeSelection(selection) {
497
+ if (selection.isBackward()) {
498
+ const {
499
+ anchor,
500
+ focus
501
+ } = selection;
502
+ // stash for the in-place swap
503
+ const {
504
+ key,
505
+ offset,
506
+ type
507
+ } = anchor;
508
+ anchor.set(focus.key, focus.offset, focus.type);
509
+ focus.set(key, offset, type);
510
+ }
511
+ }
522
512
 
513
+ function $copyBlockFormatIndent(srcNode, destNode) {
514
+ const format = srcNode.getFormatType();
515
+ const indent = srcNode.getIndent();
516
+ if (format !== destNode.getFormatType()) {
517
+ destNode.setFormat(format);
518
+ }
519
+ if (indent !== destNode.getIndent()) {
520
+ destNode.setIndent(indent);
521
+ }
522
+ }
523
523
 
524
524
  /**
525
525
  * Converts all nodes in the selection that are of one block type to another.
526
526
  * @param selection - The selected blocks to be converted.
527
- * @param createElement - The function that creates the node. eg. $createParagraphNode.
527
+ * @param $createElement - The function that creates the node. eg. $createParagraphNode.
528
+ * @param $afterCreateElement - The function that updates the new node based on the previous one ($copyBlockFormatIndent by default)
528
529
  */
529
- function $setBlocksType(selection, createElement) {
530
+ function $setBlocksType(selection, $createElement, $afterCreateElement = $copyBlockFormatIndent) {
530
531
  if (selection === null) {
531
532
  return;
532
533
  }
534
+ // Selections tend to not include their containing blocks so we effectively
535
+ // expand it here
533
536
  const anchorAndFocus = selection.getStartEndPoints();
534
- const anchor = anchorAndFocus ? anchorAndFocus[0] : null;
535
- if (anchor !== null && anchor.key === 'root') {
536
- const element = createElement();
537
- const root = lexical.$getRoot();
538
- const firstChild = root.getFirstChild();
539
- if (firstChild) {
540
- firstChild.replace(element, true);
541
- } else {
542
- root.append(element);
537
+ const blockMap = new Map();
538
+ let newSelection = null;
539
+ if (anchorAndFocus) {
540
+ const [anchor, focus] = anchorAndFocus;
541
+ newSelection = lexical.$createRangeSelection();
542
+ newSelection.anchor.set(anchor.key, anchor.offset, anchor.type);
543
+ newSelection.focus.set(focus.key, focus.offset, focus.type);
544
+ const anchorBlock = $getAncestor(anchor.getNode(), lexical.INTERNAL_$isBlock);
545
+ const focusBlock = $getAncestor(focus.getNode(), lexical.INTERNAL_$isBlock);
546
+ if (lexical.$isElementNode(anchorBlock)) {
547
+ blockMap.set(anchorBlock.getKey(), anchorBlock);
548
+ }
549
+ if (lexical.$isElementNode(focusBlock)) {
550
+ blockMap.set(focusBlock.getKey(), focusBlock);
551
+ }
552
+ }
553
+ for (const node of selection.getNodes()) {
554
+ if (lexical.$isElementNode(node) && lexical.INTERNAL_$isBlock(node)) {
555
+ blockMap.set(node.getKey(), node);
556
+ }
557
+ }
558
+ for (const [key, prevNode] of blockMap) {
559
+ const element = $createElement();
560
+ $afterCreateElement(prevNode, element);
561
+ prevNode.replace(element, true);
562
+ if (newSelection) {
563
+ if (key === newSelection.anchor.key) {
564
+ newSelection.anchor.set(element.getKey(), newSelection.anchor.offset, newSelection.anchor.type);
565
+ }
566
+ if (key === newSelection.focus.key) {
567
+ newSelection.focus.set(element.getKey(), newSelection.focus.offset, newSelection.focus.type);
568
+ }
543
569
  }
544
- return;
545
570
  }
546
- const nodes = selection.getNodes();
547
- const firstSelectedBlock = anchor !== null ? $getAncestor(anchor.getNode(), INTERNAL_$isBlock) : false;
548
- if (firstSelectedBlock && nodes.indexOf(firstSelectedBlock) === -1) {
549
- nodes.push(firstSelectedBlock);
550
- }
551
- for (let i = 0; i < nodes.length; i++) {
552
- const node = nodes[i];
553
- if (!INTERNAL_$isBlock(node)) {
554
- continue;
555
- }
556
- if (!lexical.$isElementNode(node)) {
557
- throw Error(`Expected block node to be an ElementNode`);
558
- }
559
- const targetElement = createElement();
560
- targetElement.setFormat(node.getFormatType());
561
- targetElement.setIndent(node.getIndent());
562
- node.replace(targetElement, true);
571
+ if (newSelection && selection.is(lexical.$getSelection())) {
572
+ lexical.$setSelection(newSelection);
563
573
  }
564
574
  }
565
575
  function isPointAttached(point) {
@@ -703,7 +713,7 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
703
713
  }
704
714
  } else if (emptyElements.has(node.getKey())) {
705
715
  if (!lexical.$isElementNode(node)) {
706
- throw Error(`Expected node in emptyElements to be an ElementNode`);
716
+ formatDevErrorMessage(`Expected node in emptyElements to be an ElementNode`);
707
717
  }
708
718
  const targetElement = createElement();
709
719
  targetElement.setFormat(node.getFormatType());
@@ -787,8 +797,21 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
787
797
  * @returns true if it should be overridden, false if not.
788
798
  */
789
799
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
790
- const possibleNode = lexical.$getAdjacentNode(selection.focus, isBackward);
791
- return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated() || lexical.$isElementNode(possibleNode) && !possibleNode.isInline() && !possibleNode.canBeEmpty();
800
+ const focusCaret = lexical.$caretFromPoint(selection.focus, isBackward ? 'previous' : 'next');
801
+ if (lexical.$isExtendableTextPointCaret(focusCaret)) {
802
+ return false;
803
+ }
804
+ for (const nextCaret of lexical.$extendCaretToRange(focusCaret)) {
805
+ if (lexical.$isChildCaret(nextCaret)) {
806
+ return !nextCaret.origin.isInline();
807
+ } else if (lexical.$isElementNode(nextCaret.origin)) {
808
+ continue;
809
+ } else if (lexical.$isDecoratorNode(nextCaret.origin)) {
810
+ return true;
811
+ }
812
+ break;
813
+ }
814
+ return false;
792
815
  }
793
816
 
794
817
  /**
@@ -824,38 +847,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
824
847
  $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
825
848
  }
826
849
 
827
- /**
828
- * Expands the current Selection to cover all of the content in the editor.
829
- * @param selection - The current selection.
830
- */
831
- function $selectAll(selection) {
832
- const anchor = selection.anchor;
833
- const focus = selection.focus;
834
- const anchorNode = anchor.getNode();
835
- const topParent = anchorNode.getTopLevelElementOrThrow();
836
- const root = topParent.getParentOrThrow();
837
- let firstNode = root.getFirstDescendant();
838
- let lastNode = root.getLastDescendant();
839
- let firstType = 'element';
840
- let lastType = 'element';
841
- let lastOffset = 0;
842
- if (lexical.$isTextNode(firstNode)) {
843
- firstType = 'text';
844
- } else if (!lexical.$isElementNode(firstNode) && firstNode !== null) {
845
- firstNode = firstNode.getParentOrThrow();
846
- }
847
- if (lexical.$isTextNode(lastNode)) {
848
- lastType = 'text';
849
- lastOffset = lastNode.getTextContentSize();
850
- } else if (!lexical.$isElementNode(lastNode) && lastNode !== null) {
851
- lastNode = lastNode.getParentOrThrow();
852
- }
853
- if (firstNode && lastNode) {
854
- anchor.set(firstNode.getKey(), 0, firstType);
855
- focus.set(lastNode.getKey(), lastOffset, lastType);
856
- }
857
- }
858
-
859
850
  /**
860
851
  * Returns the current value of a CSS property for Nodes, if set. If not set, it returns the defaultValue.
861
852
  * @param node - The node whose style value to get.
@@ -918,22 +909,6 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
918
909
  }
919
910
  return styleValue === null ? defaultValue : styleValue;
920
911
  }
921
-
922
- /**
923
- * This function is for internal use of the library.
924
- * Please do not use it as it may change in the future.
925
- */
926
- function INTERNAL_$isBlock(node) {
927
- if (lexical.$isDecoratorNode(node)) {
928
- return false;
929
- }
930
- if (!lexical.$isElementNode(node) || lexical.$isRootOrShadowRoot(node)) {
931
- return false;
932
- }
933
- const firstChild = node.getFirstChild();
934
- const isLeafElement = firstChild === null || lexical.$isLineBreakNode(firstChild) || lexical.$isTextNode(firstChild) || firstChild.isInline();
935
- return !node.isInline() && node.canBeEmpty() !== false && isLeafElement;
936
- }
937
912
  function $getAncestor(node, predicate) {
938
913
  let parent = node;
939
914
  while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
@@ -957,14 +932,20 @@ Object.defineProperty(exports, "$cloneWithProperties", {
957
932
  enumerable: true,
958
933
  get: function () { return lexical.$cloneWithProperties; }
959
934
  });
935
+ Object.defineProperty(exports, "$selectAll", {
936
+ enumerable: true,
937
+ get: function () { return lexical.$selectAll; }
938
+ });
960
939
  exports.$addNodeStyle = $addNodeStyle;
940
+ exports.$copyBlockFormatIndent = $copyBlockFormatIndent;
941
+ exports.$ensureForwardRangeSelection = $ensureForwardRangeSelection;
942
+ exports.$forEachSelectedTextNode = $forEachSelectedTextNode;
961
943
  exports.$getSelectionStyleValueForProperty = $getSelectionStyleValueForProperty;
962
944
  exports.$isAtNodeEnd = $isAtNodeEnd;
963
945
  exports.$isParentElementRTL = $isParentElementRTL;
964
946
  exports.$moveCaretSelection = $moveCaretSelection;
965
947
  exports.$moveCharacter = $moveCharacter;
966
948
  exports.$patchStyleText = $patchStyleText;
967
- exports.$selectAll = $selectAll;
968
949
  exports.$setBlocksType = $setBlocksType;
969
950
  exports.$shouldOverrideDefaultCharacterSelection = $shouldOverrideDefaultCharacterSelection;
970
951
  exports.$sliceSelectedTextNodeContent = $sliceSelectedTextNodeContent;
@@ -972,5 +953,6 @@ exports.$trimTextContentFromAnchor = $trimTextContentFromAnchor;
972
953
  exports.$wrapNodes = $wrapNodes;
973
954
  exports.createDOMRange = createDOMRange;
974
955
  exports.createRectsFromDOMRange = createRectsFromDOMRange;
956
+ exports.getCSSFromStyleObject = getCSSFromStyleObject;
975
957
  exports.getStyleObjectFromCSS = getStyleObjectFromCSS;
976
958
  exports.trimTextContentFromAnchor = trimTextContentFromAnchor;
@@ -11,7 +11,7 @@ var LexicalSelection_prod = require('./LexicalSelection.prod.js');
11
11
  *
12
12
  */
13
13
 
14
- const mod = process.env.NODE_ENV === 'development' ? LexicalSelection_dev : LexicalSelection_prod;
14
+ const mod = process.env.NODE_ENV !== 'production' ? LexicalSelection_dev : LexicalSelection_prod;
15
15
  const $addNodeStyle = mod.$addNodeStyle;
16
16
  const $getSelectionStyleValueForProperty = mod.$getSelectionStyleValueForProperty;
17
17
  const $isAtNodeEnd = mod.$isAtNodeEnd;
@@ -10,26 +10,33 @@ var lexical = require('lexical');
10
10
  *
11
11
  */
12
12
 
13
- function m(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var T=m((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const x=new Map;function S(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild;}return null}function v(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return [t,Array.from(t.childNodes).indexOf(e)]}function C(t,n,l,o,r){const s=n.getKey(),i=o.getKey(),c=document.createRange();let f=t.getElementByKey(s),u=t.getElementByKey(i),g=l,a=r;if(lexical.$isTextNode(n)&&(f=S(f)),lexical.$isTextNode(o)&&(u=S(u)),void 0===n||void 0===o||null===f||null===u)return null;"BR"===f.nodeName&&([f,g]=v(f)),"BR"===u.nodeName&&([u,a]=v(u));const d=f.firstChild;f===u&&null!=d&&"BR"===d.nodeName&&0===g&&0===a&&(a=1);try{c.setStart(f,g),c.setEnd(u,a);}catch(e){return null}return !c.collapsed||g===a&&s===i||(c.setStart(u,a),c.setEnd(f,g)),c}function P(e,t){const n=e.getRootElement();if(null===n)return [];const l=n.getBoundingClientRect(),o=getComputedStyle(n),r=parseFloat(o.paddingLeft)+parseFloat(o.paddingRight),s=Array.from(t.getClientRects());let i,c=s.length;s.sort(((e,t)=>{const n=e.top-t.top;return Math.abs(n)<=3?e.left-t.left:n}));for(let e=0;e<c;e++){const t=s[e],n=i&&i.top<=t.top&&i.top+i.height>t.top&&i.left+i.width>t.left,o=t.width+r===l.width;n||o?(s.splice(e--,1),c--):i=t;}return s}function w(e){const t={},n=e.split(";");for(const e of n)if(""!==e){const[n,l]=e.split(/:([^]+)/);n&&l&&(t[n.trim()]=l.trim());}return t}function N(e){let t=x.get(e);return void 0===t&&(t=w(e),x.set(e,t)),t}function E(e,n){const l=e.getStartEndPoints();if(n.isSelected(e)&&!n.isSegmented()&&!n.isToken()&&null!==l){const[o,r]=l,s=e.isBackward(),i=o.getNode(),c=r.getNode(),f=n.is(i),u=n.is(c);if(f||u){const[l,o]=lexical.$getCharacterOffsets(e),r=i.is(c),f=n.is(s?c:i),u=n.is(s?i:c);let g,a=0;if(r)a=l>o?o:l,g=l>o?l:o;else if(f){a=s?o:l,g=void 0;}else if(u){a=0,g=s?l:o;}return n.__text=n.__text.slice(a,g),n}}return n}function F(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return lexical.$isElementNode(t)||T(177),e.offset===t.getChildrenSize()}function K(t,c,f){let u=c.getNode(),g=f;if(lexical.$isElementNode(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e);}for(;g>0&&null!==u;){if(lexical.$isElementNode(u)){const e=u.getLastDescendant();null!==e&&(u=e);}let f=u.getPreviousSibling(),a=0;if(null===f){let e=u.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){f=null;break}t=e.getPreviousSibling();}null!==e&&(a=e.isInline()?0:2,f=t);}let d=u.getTextContent();""===d&&lexical.$isElementNode(u)&&!u.isInline()&&(d="\n\n");const p=d.length;if(!lexical.$isTextNode(u)||g>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||lexical.$isRootNode(e)||e.remove(),g-=p+a,u=f;}else {const n=u.getKey(),l=t.getEditorState().read((()=>{const t=lexical.$getNodeByKey(n);return lexical.$isTextNode(t)&&t.isSimpleText()?t.getTextContent():null})),f=p-g,a=d.slice(0,f);if(null!==l&&l!==d){const e=lexical.$getPreviousSelection();let t=u;if(u.isSimpleText())u.setTextContent(l);else {const e=lexical.$createTextNode(l);u.replace(e),t=e;}if(lexical.$isRangeSelection(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n);}}else if(u.isSimpleText()){const e=c.key===n;let t=c.offset;t<g&&(t=p);const l=e?t-g:0,o=e?t:f;if(e&&0===l){const[e]=u.splitText(l,o);e.remove();}else {const[,e]=u.splitText(l,o);e.remove();}}else {const e=lexical.$createTextNode(a);u.replace(e);}g=0;}}}function I(e){const t=e.getStyle(),n=w(t);x.set(t,n);}function O(e,t){const n=N("getStyle"in e?e.getStyle():e.style),l=Object.entries(t).reduce(((t,[l,o])=>("function"==typeof o?t[l]=o(n[l],e):null===o?delete t[l]:t[l]=o,t)),{...n}||{}),o=function(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}(l);e.setStyle(o),x.set(o,l);}function B(t,n){const l=t.getNodes(),o=l.length,r=t.getStartEndPoints();if(null===r)return;const[s,f]=r,u=o-1;let g=l[0],a=l[u];if(t.isCollapsed()&&lexical.$isRangeSelection(t))return void O(t,n);const d=g.getTextContent().length,p=f.offset;let h=s.offset;const y=s.isBefore(f);let m=y?h:p,T=y?p:h;const x=y?s.type:f.type,S=y?f.type:s.type,v=y?f.key:s.key;if(lexical.$isTextNode(g)&&m===d){const t=g.getNextSibling();lexical.$isTextNode(t)&&(h=0,m=0,g=t);}if(1===l.length){if(lexical.$isTextNode(g)&&g.canHaveFormat()){if(m="element"===x?0:h>p?p:h,T="element"===S?d:h>p?h:p,m===T)return;if(lexical.$isTokenOrSegmented(g)||0===m&&T===d)O(g,n),g.select(m,T);else {const e=g.splitText(m,T),t=0===m?e[0]:e[1];O(t,n),t.select(0,T-m);}}}else {if(lexical.$isTextNode(g)&&m<g.getTextContentSize()&&g.canHaveFormat()&&(0===m||lexical.$isTokenOrSegmented(g)||(g=g.splitText(m)[1],m=0,y?s.set(g.getKey(),m,"text"):f.set(g.getKey(),m,"text")),O(g,n)),lexical.$isTextNode(a)&&a.canHaveFormat()){const e=a.getTextContent().length;a.__key!==v&&0!==T&&(T=e),T===e||lexical.$isTokenOrSegmented(a)||([a]=a.splitText(T)),0===T&&"element"!==S||O(a,n);}for(let t=1;t<u;t++){const o=l[t],r=o.getKey();lexical.$isTextNode(o)&&o.canHaveFormat()&&r!==g.getKey()&&r!==a.getKey()&&!o.isToken()&&O(o,n);}}}function k(e,t){if(null===e)return;const l=e.getStartEndPoints(),o=l?l[0]:null;if(null!==o&&"root"===o.key){const e=t(),n=lexical.$getRoot(),l=n.getFirstChild();return void(l?l.replace(e,!0):n.append(e))}const r=e.getNodes(),s=null!==o&&function(e,t){let n=e;for(;null!==n&&null!==n.getParent()&&!t(n);)n=n.getParentOrThrow();return t(n)?n:null}(o.getNode(),U);s&&-1===r.indexOf(s)&&r.push(s);for(let e=0;e<r.length;e++){const l=r[e];if(!U(l))continue;lexical.$isElementNode(l)||T(178);const o=t();o.setFormat(l.getFormatType()),o.setIndent(l.getIndent()),l.replace(o,!0);}}function b(e){return e.getNode().isAttached()}function R(e){let t=e;for(;null!==t&&!lexical.$isRootOrShadowRoot(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n;}}function _(e,t,n=null){const l=e.getStartEndPoints(),o=l?l[0]:null,r=e.getNodes(),s=r.length;if(null!==o&&(0===s||1===s&&"element"===o.type&&0===o.getNode().getChildrenSize())){const e="text"===o.type?o.getNode().getParentOrThrow():o.getNode(),l=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),l.forEach((e=>r.append(e))),n&&(r=n.append(r)),void e.replace(r)}let i=null,c=[];for(let l=0;l<s;l++){const o=r[l];lexical.$isRootOrShadowRoot(o)?(z(e,c,c.length,t,n),c=[],i=o):null===i||null!==i&&lexical.$hasAncestor(o,i)?c.push(o):(z(e,c,c.length,t,n),c=[o]);}z(e,c,c.length,t,n);}function z(e,t,l,o,s=null){if(0===t.length)return;const c=t[0],f=new Map,g=[];let p=lexical.$isElementNode(c)?c:c.getParentOrThrow();p.isInline()&&(p=p.getParentOrThrow());let h=!1;for(;null!==p;){const e=p.getPreviousSibling();if(null!==e){p=e,h=!0;break}if(p=p.getParentOrThrow(),lexical.$isRootOrShadowRoot(p))break}const y=new Set;for(let e=0;e<l;e++){const l=t[e];lexical.$isElementNode(l)&&0===l.getChildrenSize()&&y.add(l.getKey());}const m=new Set;for(let e=0;e<l;e++){const l=t[e];let r=l.getParent();if(null!==r&&r.isInline()&&(r=r.getParent()),null!==r&&lexical.$isLeafNode(l)&&!m.has(l.getKey())){const e=r.getKey();if(void 0===f.get(e)){const t=o();t.setFormat(r.getFormatType()),t.setIndent(r.getIndent()),g.push(t),f.set(e,t),r.getChildren().forEach((e=>{t.append(e),m.add(e.getKey()),lexical.$isElementNode(e)&&e.getChildrenKeys().forEach((e=>m.add(e)));})),R(r);}}else if(y.has(l.getKey())){lexical.$isElementNode(l)||T(179);const e=o();e.setFormat(l.getFormatType()),e.setIndent(l.getIndent()),g.push(e),l.remove(!0);}}if(null!==s)for(let e=0;e<g.length;e++){const t=g[e];s.append(t);}let x=null;if(lexical.$isRootOrShadowRoot(p))if(h)if(null!==s)p.insertAfter(s);else for(let e=g.length-1;e>=0;e--){const t=g[e];p.insertAfter(t);}else {const e=p.getFirstChild();if(lexical.$isElementNode(e)&&(p=e),null===e)if(s)p.append(s);else for(let e=0;e<g.length;e++){const t=g[e];p.append(t),x=t;}else if(null!==s)e.insertBefore(s);else for(let t=0;t<g.length;t++){const n=g[t];e.insertBefore(n),x=n;}}else if(s)p.insertAfter(s);else for(let e=g.length-1;e>=0;e--){const t=g[e];p.insertAfter(t),x=t;}const S=lexical.$getPreviousSelection();lexical.$isRangeSelection(S)&&b(S.anchor)&&b(S.focus)?lexical.$setSelection(S.clone()):null!==x?x.selectEnd():e.dirty=!0;}function A(e,t){const l=lexical.$getAdjacentNode(e.focus,t);return lexical.$isDecoratorNode(l)&&!l.isIsolated()||lexical.$isElementNode(l)&&!l.isInline()&&!l.canBeEmpty()}function L(e,t,n,l){e.modify(t?"extend":"move",n,l);}function D(e){const t=e.anchor.getNode();return "rtl"===(lexical.$isRootNode(t)?t:t.getParentOrThrow()).getDirection()}function M(e,t,n){const l=D(e);L(e,t,n?!l:l,"character");}function $(t){const l=t.anchor,o=t.focus,r=l.getNode().getTopLevelElementOrThrow().getParentOrThrow();let s=r.getFirstDescendant(),i=r.getLastDescendant(),c="element",f="element",u=0;lexical.$isTextNode(s)?c="text":lexical.$isElementNode(s)||null===s||(s=s.getParentOrThrow()),lexical.$isTextNode(i)?(f="text",u=i.getTextContentSize()):lexical.$isElementNode(i)||null===i||(i=i.getParentOrThrow()),s&&i&&(l.set(s.getKey(),0,c),o.set(i.getKey(),u,f));}function H(e,t,n){const l=N(e.getStyle());return null!==l&&l[t]||n}function j(t,n,l=""){let o=null;const r=t.getNodes(),s=t.anchor,c=t.focus,f=t.isBackward(),u=f?c.offset:s.offset,g=f?c.getNode():s.getNode();if(lexical.$isRangeSelection(t)&&t.isCollapsed()&&""!==t.style){const e=N(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<r.length;t++){const s=r[t];if((0===t||0!==u||!s.is(g))&&lexical.$isTextNode(s)){const e=H(s,n,l);if(null===o)o=e;else if(o!==e){o="";break}}}return null===o?l:o}function U(t){if(lexical.$isDecoratorNode(t))return !1;if(!lexical.$isElementNode(t)||lexical.$isRootOrShadowRoot(t))return !1;const l=t.getFirstChild(),o=null===l||lexical.$isLineBreakNode(l)||lexical.$isTextNode(l)||l.isInline();return !t.isInline()&&!1!==t.canBeEmpty()&&o}const W=K;
13
+ function N(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const w=new Map;function C(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild;}return null}function P(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return [t,Array.from(t.childNodes).indexOf(e)]}function k(t,n,o,l,r){const s=n.getKey(),i=l.getKey(),c=document.createRange();let f=t.getElementByKey(s),u=t.getElementByKey(i),g=o,a=r;if(lexical.$isTextNode(n)&&(f=C(f)),lexical.$isTextNode(l)&&(u=C(u)),void 0===n||void 0===l||null===f||null===u)return null;"BR"===f.nodeName&&([f,g]=P(f)),"BR"===u.nodeName&&([u,a]=P(u));const d=f.firstChild;f===u&&null!=d&&"BR"===d.nodeName&&0===g&&0===a&&(a=1);try{c.setStart(f,g),c.setEnd(u,a);}catch(e){return null}return !c.collapsed||g===a&&s===i||(c.setStart(u,a),c.setEnd(f,g)),c}function E(e,t){const n=e.getRootElement();if(null===n)return [];const o=n.getBoundingClientRect(),l=getComputedStyle(n),r=parseFloat(l.paddingLeft)+parseFloat(l.paddingRight),s=Array.from(t.getClientRects());let i,c=s.length;s.sort(((e,t)=>{const n=e.top-t.top;return Math.abs(n)<=3?e.left-t.left:n}));for(let e=0;e<c;e++){const t=s[e],n=i&&i.top<=t.top&&i.top+i.height>t.top&&i.left+i.width>t.left,l=t.width+r===o.width;n||l?(s.splice(e--,1),c--):i=t;}return s}function K(e){const t={};if(!e)return t;const n=e.split(";");for(const e of n)if(""!==e){const[n,o]=e.split(/:([^]+)/);n&&o&&(t[n.trim()]=o.trim());}return t}function I(e){let t=w.get(e);return void 0===t&&(t=K(e),w.set(e,t)),t}function F(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function B(e,n){const o=e.getStartEndPoints();if(n.isSelected(e)&&!n.isSegmented()&&!n.isToken()&&null!==o){const[l,r]=o,s=e.isBackward(),i=l.getNode(),c=r.getNode(),f=n.is(i),u=n.is(c);if(f||u){const[o,l]=lexical.$getCharacterOffsets(e),r=i.is(c),f=n.is(s?c:i),u=n.is(s?i:c);let g,a=0;if(r)a=o>l?l:o,g=o>l?o:l;else if(f){a=s?l:o,g=void 0;}else if(u){a=0,g=s?o:l;}return n.__text=n.__text.slice(a,g),n}}return n}function b(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return lexical.$isElementNode(t)||N(177),e.offset===t.getChildrenSize()}function O(t,c,f){let u=c.getNode(),g=f;if(lexical.$isElementNode(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e);}for(;g>0&&null!==u;){if(lexical.$isElementNode(u)){const e=u.getLastDescendant();null!==e&&(u=e);}let f=u.getPreviousSibling(),a=0;if(null===f){let e=u.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){f=null;break}t=e.getPreviousSibling();}null!==e&&(a=e.isInline()?0:2,f=t);}let d=u.getTextContent();""===d&&lexical.$isElementNode(u)&&!u.isInline()&&(d="\n\n");const p=d.length;if(!lexical.$isTextNode(u)||g>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||lexical.$isRootNode(e)||e.remove(),g-=p+a,u=f;}else {const n=u.getKey(),o=t.getEditorState().read((()=>{const t=lexical.$getNodeByKey(n);return lexical.$isTextNode(t)&&t.isSimpleText()?t.getTextContent():null})),f=p-g,a=d.slice(0,f);if(null!==o&&o!==d){const e=lexical.$getPreviousSelection();let t=u;if(u.isSimpleText())u.setTextContent(o);else {const e=lexical.$createTextNode(o);u.replace(e),t=e;}if(lexical.$isRangeSelection(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n);}}else if(u.isSimpleText()){const e=c.key===n;let t=c.offset;t<g&&(t=p);const o=e?t-g:0,l=e?t:f;if(e&&0===o){const[e]=u.splitText(o,l);e.remove();}else {const[,e]=u.splitText(o,l);e.remove();}}else {const e=lexical.$createTextNode(a);u.replace(e);}g=0;}}}function R(e){const t=e.getStyle(),n=K(t);w.set(t,n);}function z(t,o){(lexical.$isRangeSelection(t)?t.isCollapsed():lexical.$isTextNode(t)||lexical.$isElementNode(t))||N(280);const l=I(lexical.$isRangeSelection(t)?t.style:lexical.$isTextNode(t)?t.getStyle():t.getTextStyle()),r=Object.entries(o).reduce(((e,[n,o])=>("function"==typeof o?e[n]=o(l[n],t):null===o?delete e[n]:e[n]=o,e)),{...l}),s=F(r);lexical.$isRangeSelection(t)||lexical.$isTextNode(t)?t.setStyle(s):t.setTextStyle(s),w.set(s,r);}function A(e,t){if(lexical.$isRangeSelection(e)&&e.isCollapsed()){z(e,t);const o=e.anchor.getNode();lexical.$isElementNode(o)&&o.isEmpty()&&z(o,t);}L((e=>{z(e,t);}));}function L(t){const n=lexical.$getSelection();if(!n)return;const o=new Map;if(lexical.$isRangeSelection(n))for(const e of lexical.$caretRangeFromSelection(n).getTextSlices())e&&o.set(e.caret.origin.getKey(),e.getSliceIndices());const l=n.getNodes();for(const n of l){if(!lexical.$isTextNode(n)||!n.canHaveFormat())continue;const[l,s]=(r=n,o.get(r.getKey())||[0,r.getTextContentSize()]);if(s!==l)if(lexical.$isTokenOrSegmented(n)||0===l&&s===n.getTextContentSize())t(n);else {t(n.splitText(l,s)[0===l?0:1]);}}var r;lexical.$isRangeSelection(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&M(n);}function M(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:o,offset:l,type:r}=t;t.set(n.key,n.offset,n.type),n.set(o,l,r);}}function $(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o);}function _(e,t,o=$){if(null===e)return;const l=e.getStartEndPoints(),r=new Map;let s=null;if(l){const[e,t]=l;s=lexical.$createRangeSelection(),s.anchor.set(e.key,e.offset,e.type),s.focus.set(t.key,t.offset,t.type);const o=V(e.getNode(),lexical.INTERNAL_$isBlock),i=V(t.getNode(),lexical.INTERNAL_$isBlock);lexical.$isElementNode(o)&&r.set(o.getKey(),o),lexical.$isElementNode(i)&&r.set(i.getKey(),i);}for(const t of e.getNodes())lexical.$isElementNode(t)&&lexical.INTERNAL_$isBlock(t)&&r.set(t.getKey(),t);for(const[e,n]of r){const l=t();o(n,l),n.replace(l,!0),s&&(e===s.anchor.key&&s.anchor.set(l.getKey(),s.anchor.offset,s.anchor.type),e===s.focus.key&&s.focus.set(l.getKey(),s.focus.offset,s.focus.type));}s&&e.is(lexical.$getSelection())&&lexical.$setSelection(s);}function D(e){return e.getNode().isAttached()}function U(e){let t=e;for(;null!==t&&!lexical.$isRootOrShadowRoot(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n;}}function j(e,t,n=null){const o=e.getStartEndPoints(),l=o?o[0]:null,r=e.getNodes(),s=r.length;if(null!==l&&(0===s||1===s&&"element"===l.type&&0===l.getNode().getChildrenSize())){const e="text"===l.type?l.getNode().getParentOrThrow():l.getNode(),o=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),o.forEach((e=>r.append(e))),n&&(r=n.append(r)),void e.replace(r)}let i=null,c=[];for(let o=0;o<s;o++){const l=r[o];lexical.$isRootOrShadowRoot(l)?(H(e,c,c.length,t,n),c=[],i=l):null===i||null!==i&&lexical.$hasAncestor(l,i)?c.push(l):(H(e,c,c.length,t,n),c=[l]);}H(e,c,c.length,t,n);}function H(e,t,o,l,s=null){if(0===t.length)return;const c=t[0],f=new Map,u=[];let g=lexical.$isElementNode(c)?c:c.getParentOrThrow();g.isInline()&&(g=g.getParentOrThrow());let a=!1;for(;null!==g;){const e=g.getPreviousSibling();if(null!==e){g=e,a=!0;break}if(g=g.getParentOrThrow(),lexical.$isRootOrShadowRoot(g))break}const h=new Set;for(let e=0;e<o;e++){const o=t[e];lexical.$isElementNode(o)&&0===o.getChildrenSize()&&h.add(o.getKey());}const m=new Set;for(let e=0;e<o;e++){const o=t[e];let r=o.getParent();if(null!==r&&r.isInline()&&(r=r.getParent()),null!==r&&lexical.$isLeafNode(o)&&!m.has(o.getKey())){const e=r.getKey();if(void 0===f.get(e)){const t=l();t.setFormat(r.getFormatType()),t.setIndent(r.getIndent()),u.push(t),f.set(e,t),r.getChildren().forEach((e=>{t.append(e),m.add(e.getKey()),lexical.$isElementNode(e)&&e.getChildrenKeys().forEach((e=>m.add(e)));})),U(r);}}else if(h.has(o.getKey())){lexical.$isElementNode(o)||N(179);const e=l();e.setFormat(o.getFormatType()),e.setIndent(o.getIndent()),u.push(e),o.remove(!0);}}if(null!==s)for(let e=0;e<u.length;e++){const t=u[e];s.append(t);}let S=null;if(lexical.$isRootOrShadowRoot(g))if(a)if(null!==s)g.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];g.insertAfter(t);}else {const e=g.getFirstChild();if(lexical.$isElementNode(e)&&(g=e),null===e)if(s)g.append(s);else for(let e=0;e<u.length;e++){const t=u[e];g.append(t),S=t;}else if(null!==s)e.insertBefore(s);else for(let t=0;t<u.length;t++){const n=u[t];e.insertBefore(n),S=n;}}else if(s)g.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];g.insertAfter(t),S=t;}const x=lexical.$getPreviousSelection();lexical.$isRangeSelection(x)&&D(x.anchor)&&D(x.focus)?lexical.$setSelection(x.clone()):null!==S?S.selectEnd():e.dirty=!0;}function W(e,t){const o=lexical.$caretFromPoint(e.focus,t?"previous":"next");if(lexical.$isExtendableTextPointCaret(o))return !1;for(const e of lexical.$extendCaretToRange(o)){if(lexical.$isChildCaret(e))return !e.origin.isInline();if(!lexical.$isElementNode(e.origin)){if(lexical.$isDecoratorNode(e.origin))return !0;break}}return !1}function X(e,t,n,o){e.modify(t?"extend":"move",n,o);}function q(e){const t=e.anchor.getNode();return "rtl"===(lexical.$isRootNode(t)?t:t.getParentOrThrow()).getDirection()}function G(e,t,n){const o=q(e);X(e,t,n?!o:o,"character");}function J(e,t,n){const o=I(e.getStyle());return null!==o&&o[t]||n}function Q(t,n,o=""){let l=null;const r=t.getNodes(),s=t.anchor,c=t.focus,f=t.isBackward(),u=f?c.offset:s.offset,g=f?c.getNode():s.getNode();if(lexical.$isRangeSelection(t)&&t.isCollapsed()&&""!==t.style){const e=I(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<r.length;t++){const s=r[t];if((0===t||0!==u||!s.is(g))&&lexical.$isTextNode(s)){const e=J(s,n,o);if(null===l)l=e;else if(l!==e){l="";break}}}return null===l?o:l}function V(e,t){let n=e;for(;null!==n&&null!==n.getParent()&&!t(n);)n=n.getParentOrThrow();return t(n)?n:null}const Y=O;
14
14
 
15
15
  Object.defineProperty(exports, "$cloneWithProperties", {
16
16
  enumerable: true,
17
17
  get: function () { return lexical.$cloneWithProperties; }
18
18
  });
19
- exports.$addNodeStyle = I;
20
- exports.$getSelectionStyleValueForProperty = j;
21
- exports.$isAtNodeEnd = F;
22
- exports.$isParentElementRTL = D;
23
- exports.$moveCaretSelection = L;
24
- exports.$moveCharacter = M;
25
- exports.$patchStyleText = B;
26
- exports.$selectAll = $;
27
- exports.$setBlocksType = k;
28
- exports.$shouldOverrideDefaultCharacterSelection = A;
29
- exports.$sliceSelectedTextNodeContent = E;
30
- exports.$trimTextContentFromAnchor = K;
31
- exports.$wrapNodes = _;
32
- exports.createDOMRange = C;
33
- exports.createRectsFromDOMRange = P;
34
- exports.getStyleObjectFromCSS = N;
35
- exports.trimTextContentFromAnchor = W;
19
+ Object.defineProperty(exports, "$selectAll", {
20
+ enumerable: true,
21
+ get: function () { return lexical.$selectAll; }
22
+ });
23
+ exports.$addNodeStyle = R;
24
+ exports.$copyBlockFormatIndent = $;
25
+ exports.$ensureForwardRangeSelection = M;
26
+ exports.$forEachSelectedTextNode = L;
27
+ exports.$getSelectionStyleValueForProperty = Q;
28
+ exports.$isAtNodeEnd = b;
29
+ exports.$isParentElementRTL = q;
30
+ exports.$moveCaretSelection = X;
31
+ exports.$moveCharacter = G;
32
+ exports.$patchStyleText = A;
33
+ exports.$setBlocksType = _;
34
+ exports.$shouldOverrideDefaultCharacterSelection = W;
35
+ exports.$sliceSelectedTextNodeContent = B;
36
+ exports.$trimTextContentFromAnchor = O;
37
+ exports.$wrapNodes = j;
38
+ exports.createDOMRange = k;
39
+ exports.createRectsFromDOMRange = E;
40
+ exports.getCSSFromStyleObject = F;
41
+ exports.getStyleObjectFromCSS = I;
42
+ exports.trimTextContentFromAnchor = Y;