@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
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
- import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $isTokenOrSegmented, $getRoot, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $setSelection, $getAdjacentNode, $isDecoratorNode, $isLineBreakNode } from 'lexical';
4
- export { $cloneWithProperties } from 'lexical';
3
+ import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $getSelection, $caretRangeFromSelection, $isTokenOrSegmented, $createRangeSelection, INTERNAL_$isBlock, $setSelection, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isChildCaret, $isDecoratorNode } from 'lexical';
4
+ export { $cloneWithProperties, $selectAll } from 'lexical';
5
5
 
6
6
  /**
7
7
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -12,6 +12,20 @@ export { $cloneWithProperties } from 'lexical';
12
12
  */
13
13
 
14
14
 
15
+ /**
16
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
17
+ *
18
+ * This source code is licensed under the MIT license found in the
19
+ * LICENSE file in the root directory of this source tree.
20
+ *
21
+ */
22
+
23
+ // Do not require this module directly! Use normal `invariant` calls.
24
+
25
+ function formatDevErrorMessage(message) {
26
+ throw new Error(message);
27
+ }
28
+
15
29
  /**
16
30
  * Copyright (c) Meta Platforms, Inc. and affiliates.
17
31
  *
@@ -147,6 +161,9 @@ function createRectsFromDOMRange(editor, range) {
147
161
  */
148
162
  function getStyleObjectFromRawCSS(css) {
149
163
  const styleObject = {};
164
+ if (!css) {
165
+ return styleObject;
166
+ }
150
167
  const styles = css.split(';');
151
168
  for (const style of styles) {
152
169
  if (style !== '') {
@@ -192,14 +209,6 @@ function getCSSFromStyleObject(styles) {
192
209
  return css;
193
210
  }
194
211
 
195
- /**
196
- * Copyright (c) Meta Platforms, Inc. and affiliates.
197
- *
198
- * This source code is licensed under the MIT license found in the
199
- * LICENSE file in the root directory of this source tree.
200
- *
201
- */
202
-
203
212
  /**
204
213
  * Generally used to append text content to HTML and JSON. Grabs the text content and "slices"
205
214
  * it to be generated into the new TextNode.
@@ -253,7 +262,7 @@ function $isAtNodeEnd(point) {
253
262
  }
254
263
  const node = point.getNode();
255
264
  if (!$isElementNode(node)) {
256
- throw Error(`isAtNodeEnd: node must be a TextNode or ElementNode`);
265
+ formatDevErrorMessage(`isAtNodeEnd: node must be a TextNode or ElementNode`);
257
266
  }
258
267
  return point.offset === node.getChildrenSize();
259
268
  }
@@ -379,8 +388,19 @@ function $addNodeStyle(node) {
379
388
  const styles = getStyleObjectFromRawCSS(CSSText);
380
389
  CSS_TO_STYLES.set(CSSText, styles);
381
390
  }
391
+
392
+ /**
393
+ * Applies the provided styles to the given TextNode, ElementNode, or
394
+ * collapsed RangeSelection.
395
+ *
396
+ * @param target - The TextNode, ElementNode, or collapsed RangeSelection to apply the styles to
397
+ * @param patch - The patch to apply, which can include multiple styles. \\{CSSProperty: value\\} . Can also accept a function that returns the new property value.
398
+ */
382
399
  function $patchStyle(target, patch) {
383
- const prevStyles = getStyleObjectFromCSS('getStyle' in target ? target.getStyle() : target.style);
400
+ if (!($isRangeSelection(target) ? target.isCollapsed() : $isTextNode(target) || $isElementNode(target))) {
401
+ formatDevErrorMessage(`$patchStyle must only be called with a TextNode, ElementNode, or collapsed RangeSelection`);
402
+ }
403
+ const prevStyles = getStyleObjectFromCSS($isRangeSelection(target) ? target.style : $isTextNode(target) ? target.getStyle() : target.getTextStyle());
384
404
  const newStyles = Object.entries(patch).reduce((styles, [key, value]) => {
385
405
  if (typeof value === 'function') {
386
406
  styles[key] = value(prevStyles[key], target);
@@ -392,9 +412,13 @@ function $patchStyle(target, patch) {
392
412
  return styles;
393
413
  }, {
394
414
  ...prevStyles
395
- } || {});
415
+ });
396
416
  const newCSSText = getCSSFromStyleObject(newStyles);
397
- target.setStyle(newCSSText);
417
+ if ($isRangeSelection(target) || $isTextNode(target)) {
418
+ target.setStyle(newCSSText);
419
+ } else {
420
+ target.setTextStyle(newCSSText);
421
+ }
398
422
  CSS_TO_STYLES.set(newCSSText, newStyles);
399
423
  }
400
424
 
@@ -406,161 +430,147 @@ function $patchStyle(target, patch) {
406
430
  * @param patch - The patch to apply, which can include multiple styles. \\{CSSProperty: value\\} . Can also accept a function that returns the new property value.
407
431
  */
408
432
  function $patchStyleText(selection, patch) {
409
- const selectedNodes = selection.getNodes();
410
- const selectedNodesLength = selectedNodes.length;
411
- const anchorAndFocus = selection.getStartEndPoints();
412
- if (anchorAndFocus === null) {
413
- return;
414
- }
415
- const [anchor, focus] = anchorAndFocus;
416
- const lastIndex = selectedNodesLength - 1;
417
- let firstNode = selectedNodes[0];
418
- let lastNode = selectedNodes[lastIndex];
419
- if (selection.isCollapsed() && $isRangeSelection(selection)) {
433
+ if ($isRangeSelection(selection) && selection.isCollapsed()) {
420
434
  $patchStyle(selection, patch);
435
+ const emptyNode = selection.anchor.getNode();
436
+ if ($isElementNode(emptyNode) && emptyNode.isEmpty()) {
437
+ $patchStyle(emptyNode, patch);
438
+ }
439
+ }
440
+ $forEachSelectedTextNode(textNode => {
441
+ $patchStyle(textNode, patch);
442
+ });
443
+ }
444
+ function $forEachSelectedTextNode(fn) {
445
+ const selection = $getSelection();
446
+ if (!selection) {
421
447
  return;
422
448
  }
423
- const firstNodeText = firstNode.getTextContent();
424
- const firstNodeTextLength = firstNodeText.length;
425
- const focusOffset = focus.offset;
426
- let anchorOffset = anchor.offset;
427
- const isBefore = anchor.isBefore(focus);
428
- let startOffset = isBefore ? anchorOffset : focusOffset;
429
- let endOffset = isBefore ? focusOffset : anchorOffset;
430
- const startType = isBefore ? anchor.type : focus.type;
431
- const endType = isBefore ? focus.type : anchor.type;
432
- const endKey = isBefore ? focus.key : anchor.key;
433
-
434
- // This is the case where the user only selected the very end of the
435
- // first node so we don't want to include it in the formatting change.
436
- if ($isTextNode(firstNode) && startOffset === firstNodeTextLength) {
437
- const nextSibling = firstNode.getNextSibling();
438
- if ($isTextNode(nextSibling)) {
439
- // we basically make the second node the firstNode, changing offsets accordingly
440
- anchorOffset = 0;
441
- startOffset = 0;
442
- firstNode = nextSibling;
443
- }
444
- }
445
-
446
- // This is the case where we only selected a single node
447
- if (selectedNodes.length === 1) {
448
- if ($isTextNode(firstNode) && firstNode.canHaveFormat()) {
449
- startOffset = startType === 'element' ? 0 : anchorOffset > focusOffset ? focusOffset : anchorOffset;
450
- endOffset = endType === 'element' ? firstNodeTextLength : anchorOffset > focusOffset ? anchorOffset : focusOffset;
451
-
452
- // No actual text is selected, so do nothing.
453
- if (startOffset === endOffset) {
454
- return;
455
- }
456
-
457
- // The entire node is selected or a token/segment, so just format it
458
- if ($isTokenOrSegmented(firstNode) || startOffset === 0 && endOffset === firstNodeTextLength) {
459
- $patchStyle(firstNode, patch);
460
- firstNode.select(startOffset, endOffset);
461
- } else {
462
- // The node is partially selected, so split it into two nodes
463
- // and style the selected one.
464
- const splitNodes = firstNode.splitText(startOffset, endOffset);
465
- const replacement = startOffset === 0 ? splitNodes[0] : splitNodes[1];
466
- $patchStyle(replacement, patch);
467
- replacement.select(0, endOffset - startOffset);
468
- }
469
- } // multiple nodes selected.
470
- } else {
471
- if ($isTextNode(firstNode) && startOffset < firstNode.getTextContentSize() && firstNode.canHaveFormat()) {
472
- if (startOffset !== 0 && !$isTokenOrSegmented(firstNode)) {
473
- // the entire first node isn't selected and it isn't a token or segmented, so split it
474
- firstNode = firstNode.splitText(startOffset)[1];
475
- startOffset = 0;
476
- if (isBefore) {
477
- anchor.set(firstNode.getKey(), startOffset, 'text');
478
- } else {
479
- focus.set(firstNode.getKey(), startOffset, 'text');
480
- }
481
- }
482
- $patchStyle(firstNode, patch);
483
- }
484
- if ($isTextNode(lastNode) && lastNode.canHaveFormat()) {
485
- const lastNodeText = lastNode.getTextContent();
486
- const lastNodeTextLength = lastNodeText.length;
487
-
488
- // The last node might not actually be the end node
489
- //
490
- // If not, assume the last node is fully-selected unless the end offset is
491
- // zero.
492
- if (lastNode.__key !== endKey && endOffset !== 0) {
493
- endOffset = lastNodeTextLength;
494
- }
495
-
496
- // if the entire last node isn't selected and it isn't a token or segmented, split it
497
- if (endOffset !== lastNodeTextLength && !$isTokenOrSegmented(lastNode)) {
498
- [lastNode] = lastNode.splitText(endOffset);
499
- }
500
- if (endOffset !== 0 || endType === 'element') {
501
- $patchStyle(lastNode, patch);
449
+ const slicedTextNodes = new Map();
450
+ const getSliceIndices = node => slicedTextNodes.get(node.getKey()) || [0, node.getTextContentSize()];
451
+ if ($isRangeSelection(selection)) {
452
+ for (const slice of $caretRangeFromSelection(selection).getTextSlices()) {
453
+ if (slice) {
454
+ slicedTextNodes.set(slice.caret.origin.getKey(), slice.getSliceIndices());
502
455
  }
503
456
  }
457
+ }
458
+ const selectedNodes = selection.getNodes();
459
+ for (const selectedNode of selectedNodes) {
460
+ if (!($isTextNode(selectedNode) && selectedNode.canHaveFormat())) {
461
+ continue;
462
+ }
463
+ const [startOffset, endOffset] = getSliceIndices(selectedNode);
464
+ // No actual text is selected, so do nothing.
465
+ if (endOffset === startOffset) {
466
+ continue;
467
+ }
504
468
 
505
- // style all the text nodes in between
506
- for (let i = 1; i < lastIndex; i++) {
507
- const selectedNode = selectedNodes[i];
508
- const selectedNodeKey = selectedNode.getKey();
509
- if ($isTextNode(selectedNode) && selectedNode.canHaveFormat() && selectedNodeKey !== firstNode.getKey() && selectedNodeKey !== lastNode.getKey() && !selectedNode.isToken()) {
510
- $patchStyle(selectedNode, patch);
511
- }
469
+ // The entire node is selected or a token/segment, so just format it
470
+ if ($isTokenOrSegmented(selectedNode) || startOffset === 0 && endOffset === selectedNode.getTextContentSize()) {
471
+ fn(selectedNode);
472
+ } else {
473
+ // The node is partially selected, so split it into two or three nodes
474
+ // and style the selected one.
475
+ const splitNodes = selectedNode.splitText(startOffset, endOffset);
476
+ const replacement = splitNodes[startOffset === 0 ? 0 : 1];
477
+ fn(replacement);
512
478
  }
513
479
  }
480
+ // Prior to NodeCaret #7046 this would have been a side-effect
481
+ // so we do this for test compatibility.
482
+ // TODO: we may want to consider simplifying by removing this
483
+ if ($isRangeSelection(selection) && selection.anchor.type === 'text' && selection.focus.type === 'text' && selection.anchor.key === selection.focus.key) {
484
+ $ensureForwardRangeSelection(selection);
485
+ }
514
486
  }
515
487
 
516
488
  /**
517
- * Copyright (c) Meta Platforms, Inc. and affiliates.
518
- *
519
- * This source code is licensed under the MIT license found in the
520
- * LICENSE file in the root directory of this source tree.
489
+ * Ensure that the given RangeSelection is not backwards. If it
490
+ * is backwards, then the anchor and focus points will be swapped
491
+ * in-place. Ensuring that the selection is a writable RangeSelection
492
+ * is the responsibility of the caller (e.g. in a read-only context
493
+ * you will want to clone $getSelection() before using this).
521
494
  *
495
+ * @param selection a writable RangeSelection
522
496
  */
497
+ function $ensureForwardRangeSelection(selection) {
498
+ if (selection.isBackward()) {
499
+ const {
500
+ anchor,
501
+ focus
502
+ } = selection;
503
+ // stash for the in-place swap
504
+ const {
505
+ key,
506
+ offset,
507
+ type
508
+ } = anchor;
509
+ anchor.set(focus.key, focus.offset, focus.type);
510
+ focus.set(key, offset, type);
511
+ }
512
+ }
523
513
 
514
+ function $copyBlockFormatIndent(srcNode, destNode) {
515
+ const format = srcNode.getFormatType();
516
+ const indent = srcNode.getIndent();
517
+ if (format !== destNode.getFormatType()) {
518
+ destNode.setFormat(format);
519
+ }
520
+ if (indent !== destNode.getIndent()) {
521
+ destNode.setIndent(indent);
522
+ }
523
+ }
524
524
 
525
525
  /**
526
526
  * Converts all nodes in the selection that are of one block type to another.
527
527
  * @param selection - The selected blocks to be converted.
528
- * @param createElement - The function that creates the node. eg. $createParagraphNode.
528
+ * @param $createElement - The function that creates the node. eg. $createParagraphNode.
529
+ * @param $afterCreateElement - The function that updates the new node based on the previous one ($copyBlockFormatIndent by default)
529
530
  */
530
- function $setBlocksType(selection, createElement) {
531
+ function $setBlocksType(selection, $createElement, $afterCreateElement = $copyBlockFormatIndent) {
531
532
  if (selection === null) {
532
533
  return;
533
534
  }
535
+ // Selections tend to not include their containing blocks so we effectively
536
+ // expand it here
534
537
  const anchorAndFocus = selection.getStartEndPoints();
535
- const anchor = anchorAndFocus ? anchorAndFocus[0] : null;
536
- if (anchor !== null && anchor.key === 'root') {
537
- const element = createElement();
538
- const root = $getRoot();
539
- const firstChild = root.getFirstChild();
540
- if (firstChild) {
541
- firstChild.replace(element, true);
542
- } else {
543
- root.append(element);
538
+ const blockMap = new Map();
539
+ let newSelection = null;
540
+ if (anchorAndFocus) {
541
+ const [anchor, focus] = anchorAndFocus;
542
+ newSelection = $createRangeSelection();
543
+ newSelection.anchor.set(anchor.key, anchor.offset, anchor.type);
544
+ newSelection.focus.set(focus.key, focus.offset, focus.type);
545
+ const anchorBlock = $getAncestor(anchor.getNode(), INTERNAL_$isBlock);
546
+ const focusBlock = $getAncestor(focus.getNode(), INTERNAL_$isBlock);
547
+ if ($isElementNode(anchorBlock)) {
548
+ blockMap.set(anchorBlock.getKey(), anchorBlock);
549
+ }
550
+ if ($isElementNode(focusBlock)) {
551
+ blockMap.set(focusBlock.getKey(), focusBlock);
552
+ }
553
+ }
554
+ for (const node of selection.getNodes()) {
555
+ if ($isElementNode(node) && INTERNAL_$isBlock(node)) {
556
+ blockMap.set(node.getKey(), node);
557
+ }
558
+ }
559
+ for (const [key, prevNode] of blockMap) {
560
+ const element = $createElement();
561
+ $afterCreateElement(prevNode, element);
562
+ prevNode.replace(element, true);
563
+ if (newSelection) {
564
+ if (key === newSelection.anchor.key) {
565
+ newSelection.anchor.set(element.getKey(), newSelection.anchor.offset, newSelection.anchor.type);
566
+ }
567
+ if (key === newSelection.focus.key) {
568
+ newSelection.focus.set(element.getKey(), newSelection.focus.offset, newSelection.focus.type);
569
+ }
544
570
  }
545
- return;
546
- }
547
- const nodes = selection.getNodes();
548
- const firstSelectedBlock = anchor !== null ? $getAncestor(anchor.getNode(), INTERNAL_$isBlock) : false;
549
- if (firstSelectedBlock && nodes.indexOf(firstSelectedBlock) === -1) {
550
- nodes.push(firstSelectedBlock);
551
571
  }
552
- for (let i = 0; i < nodes.length; i++) {
553
- const node = nodes[i];
554
- if (!INTERNAL_$isBlock(node)) {
555
- continue;
556
- }
557
- if (!$isElementNode(node)) {
558
- throw Error(`Expected block node to be an ElementNode`);
559
- }
560
- const targetElement = createElement();
561
- targetElement.setFormat(node.getFormatType());
562
- targetElement.setIndent(node.getIndent());
563
- node.replace(targetElement, true);
572
+ if (newSelection && selection.is($getSelection())) {
573
+ $setSelection(newSelection);
564
574
  }
565
575
  }
566
576
  function isPointAttached(point) {
@@ -704,7 +714,7 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
704
714
  }
705
715
  } else if (emptyElements.has(node.getKey())) {
706
716
  if (!$isElementNode(node)) {
707
- throw Error(`Expected node in emptyElements to be an ElementNode`);
717
+ formatDevErrorMessage(`Expected node in emptyElements to be an ElementNode`);
708
718
  }
709
719
  const targetElement = createElement();
710
720
  targetElement.setFormat(node.getFormatType());
@@ -788,8 +798,21 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
788
798
  * @returns true if it should be overridden, false if not.
789
799
  */
790
800
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
791
- const possibleNode = $getAdjacentNode(selection.focus, isBackward);
792
- return $isDecoratorNode(possibleNode) && !possibleNode.isIsolated() || $isElementNode(possibleNode) && !possibleNode.isInline() && !possibleNode.canBeEmpty();
801
+ const focusCaret = $caretFromPoint(selection.focus, isBackward ? 'previous' : 'next');
802
+ if ($isExtendableTextPointCaret(focusCaret)) {
803
+ return false;
804
+ }
805
+ for (const nextCaret of $extendCaretToRange(focusCaret)) {
806
+ if ($isChildCaret(nextCaret)) {
807
+ return !nextCaret.origin.isInline();
808
+ } else if ($isElementNode(nextCaret.origin)) {
809
+ continue;
810
+ } else if ($isDecoratorNode(nextCaret.origin)) {
811
+ return true;
812
+ }
813
+ break;
814
+ }
815
+ return false;
793
816
  }
794
817
 
795
818
  /**
@@ -825,38 +848,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
825
848
  $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
826
849
  }
827
850
 
828
- /**
829
- * Expands the current Selection to cover all of the content in the editor.
830
- * @param selection - The current selection.
831
- */
832
- function $selectAll(selection) {
833
- const anchor = selection.anchor;
834
- const focus = selection.focus;
835
- const anchorNode = anchor.getNode();
836
- const topParent = anchorNode.getTopLevelElementOrThrow();
837
- const root = topParent.getParentOrThrow();
838
- let firstNode = root.getFirstDescendant();
839
- let lastNode = root.getLastDescendant();
840
- let firstType = 'element';
841
- let lastType = 'element';
842
- let lastOffset = 0;
843
- if ($isTextNode(firstNode)) {
844
- firstType = 'text';
845
- } else if (!$isElementNode(firstNode) && firstNode !== null) {
846
- firstNode = firstNode.getParentOrThrow();
847
- }
848
- if ($isTextNode(lastNode)) {
849
- lastType = 'text';
850
- lastOffset = lastNode.getTextContentSize();
851
- } else if (!$isElementNode(lastNode) && lastNode !== null) {
852
- lastNode = lastNode.getParentOrThrow();
853
- }
854
- if (firstNode && lastNode) {
855
- anchor.set(firstNode.getKey(), 0, firstType);
856
- focus.set(lastNode.getKey(), lastOffset, lastType);
857
- }
858
- }
859
-
860
851
  /**
861
852
  * Returns the current value of a CSS property for Nodes, if set. If not set, it returns the defaultValue.
862
853
  * @param node - The node whose style value to get.
@@ -919,22 +910,6 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
919
910
  }
920
911
  return styleValue === null ? defaultValue : styleValue;
921
912
  }
922
-
923
- /**
924
- * This function is for internal use of the library.
925
- * Please do not use it as it may change in the future.
926
- */
927
- function INTERNAL_$isBlock(node) {
928
- if ($isDecoratorNode(node)) {
929
- return false;
930
- }
931
- if (!$isElementNode(node) || $isRootOrShadowRoot(node)) {
932
- return false;
933
- }
934
- const firstChild = node.getFirstChild();
935
- const isLeafElement = firstChild === null || $isLineBreakNode(firstChild) || $isTextNode(firstChild) || firstChild.isInline();
936
- return !node.isInline() && node.canBeEmpty() !== false && isLeafElement;
937
- }
938
913
  function $getAncestor(node, predicate) {
939
914
  let parent = node;
940
915
  while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
@@ -954,4 +929,4 @@ function $getAncestor(node, predicate) {
954
929
  /** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
955
930
  const trimTextContentFromAnchor = $trimTextContentFromAnchor;
956
931
 
957
- export { $addNodeStyle, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $patchStyleText, $selectAll, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, $wrapNodes, createDOMRange, createRectsFromDOMRange, getStyleObjectFromCSS, trimTextContentFromAnchor };
932
+ export { $addNodeStyle, $copyBlockFormatIndent, $ensureForwardRangeSelection, $forEachSelectedTextNode, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $patchStyleText, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, $wrapNodes, createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, getStyleObjectFromCSS, trimTextContentFromAnchor };
@@ -11,7 +11,7 @@ import * as LexicalSelection_prod from './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;
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
- import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $isTokenOrSegmented, $getRoot, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $setSelection, $getAdjacentNode, $isDecoratorNode, $isLineBreakNode } from 'lexical';
4
- export { $cloneWithProperties } from 'lexical';
3
+ import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $getSelection, $caretRangeFromSelection, $isTokenOrSegmented, $createRangeSelection, INTERNAL_$isBlock, $setSelection, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isChildCaret, $isDecoratorNode } from 'lexical';
4
+ export { $cloneWithProperties, $selectAll } from 'lexical';
5
5
 
6
6
  /**
7
7
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -11,6 +11,6 @@ export { $cloneWithProperties } from 'lexical';
11
11
  *
12
12
  */
13
13
 
14
- 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($isTextNode(n)&&(f=S(f)),$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]=$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 $isElementNode(t)||T(177),e.offset===t.getChildrenSize()}function K(t,c,f){let u=c.getNode(),g=f;if($isElementNode(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e);}for(;g>0&&null!==u;){if($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&&$isElementNode(u)&&!u.isInline()&&(d="\n\n");const p=d.length;if(!$isTextNode(u)||g>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||$isRootNode(e)||e.remove(),g-=p+a,u=f;}else {const n=u.getKey(),l=t.getEditorState().read((()=>{const t=$getNodeByKey(n);return $isTextNode(t)&&t.isSimpleText()?t.getTextContent():null})),f=p-g,a=d.slice(0,f);if(null!==l&&l!==d){const e=$getPreviousSelection();let t=u;if(u.isSimpleText())u.setTextContent(l);else {const e=$createTextNode(l);u.replace(e),t=e;}if($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=$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()&&$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($isTextNode(g)&&m===d){const t=g.getNextSibling();$isTextNode(t)&&(h=0,m=0,g=t);}if(1===l.length){if($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($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($isTextNode(g)&&m<g.getTextContentSize()&&g.canHaveFormat()&&(0===m||$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)),$isTextNode(a)&&a.canHaveFormat()){const e=a.getTextContent().length;a.__key!==v&&0!==T&&(T=e),T===e||$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();$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=$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;$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&&!$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];$isRootOrShadowRoot(o)?(z(e,c,c.length,t,n),c=[],i=o):null===i||null!==i&&$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=$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(),$isRootOrShadowRoot(p))break}const y=new Set;for(let e=0;e<l;e++){const l=t[e];$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&&$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()),$isElementNode(e)&&e.getChildrenKeys().forEach((e=>m.add(e)));})),R(r);}}else if(y.has(l.getKey())){$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($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($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=$getPreviousSelection();$isRangeSelection(S)&&b(S.anchor)&&b(S.focus)?$setSelection(S.clone()):null!==x?x.selectEnd():e.dirty=!0;}function A(e,t){const l=$getAdjacentNode(e.focus,t);return $isDecoratorNode(l)&&!l.isIsolated()||$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"===($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;$isTextNode(s)?c="text":$isElementNode(s)||null===s||(s=s.getParentOrThrow()),$isTextNode(i)?(f="text",u=i.getTextContentSize()):$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($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))&&$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($isDecoratorNode(t))return !1;if(!$isElementNode(t)||$isRootOrShadowRoot(t))return !1;const l=t.getFirstChild(),o=null===l||$isLineBreakNode(l)||$isTextNode(l)||l.isInline();return !t.isInline()&&!1!==t.canBeEmpty()&&o}const W=K;
14
+ 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($isTextNode(n)&&(f=C(f)),$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]=$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 $isElementNode(t)||N(177),e.offset===t.getChildrenSize()}function O(t,c,f){let u=c.getNode(),g=f;if($isElementNode(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e);}for(;g>0&&null!==u;){if($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&&$isElementNode(u)&&!u.isInline()&&(d="\n\n");const p=d.length;if(!$isTextNode(u)||g>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||$isRootNode(e)||e.remove(),g-=p+a,u=f;}else {const n=u.getKey(),o=t.getEditorState().read((()=>{const t=$getNodeByKey(n);return $isTextNode(t)&&t.isSimpleText()?t.getTextContent():null})),f=p-g,a=d.slice(0,f);if(null!==o&&o!==d){const e=$getPreviousSelection();let t=u;if(u.isSimpleText())u.setTextContent(o);else {const e=$createTextNode(o);u.replace(e),t=e;}if($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=$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){($isRangeSelection(t)?t.isCollapsed():$isTextNode(t)||$isElementNode(t))||N(280);const l=I($isRangeSelection(t)?t.style:$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);$isRangeSelection(t)||$isTextNode(t)?t.setStyle(s):t.setTextStyle(s),w.set(s,r);}function A(e,t){if($isRangeSelection(e)&&e.isCollapsed()){z(e,t);const o=e.anchor.getNode();$isElementNode(o)&&o.isEmpty()&&z(o,t);}L((e=>{z(e,t);}));}function L(t){const n=$getSelection();if(!n)return;const o=new Map;if($isRangeSelection(n))for(const e of $caretRangeFromSelection(n).getTextSlices())e&&o.set(e.caret.origin.getKey(),e.getSliceIndices());const l=n.getNodes();for(const n of l){if(!$isTextNode(n)||!n.canHaveFormat())continue;const[l,s]=(r=n,o.get(r.getKey())||[0,r.getTextContentSize()]);if(s!==l)if($isTokenOrSegmented(n)||0===l&&s===n.getTextContentSize())t(n);else {t(n.splitText(l,s)[0===l?0:1]);}}var r;$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=$createRangeSelection(),s.anchor.set(e.key,e.offset,e.type),s.focus.set(t.key,t.offset,t.type);const o=V(e.getNode(),INTERNAL_$isBlock),i=V(t.getNode(),INTERNAL_$isBlock);$isElementNode(o)&&r.set(o.getKey(),o),$isElementNode(i)&&r.set(i.getKey(),i);}for(const t of e.getNodes())$isElementNode(t)&&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($getSelection())&&$setSelection(s);}function D(e){return e.getNode().isAttached()}function U(e){let t=e;for(;null!==t&&!$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];$isRootOrShadowRoot(l)?(H(e,c,c.length,t,n),c=[],i=l):null===i||null!==i&&$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=$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(),$isRootOrShadowRoot(g))break}const h=new Set;for(let e=0;e<o;e++){const o=t[e];$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&&$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()),$isElementNode(e)&&e.getChildrenKeys().forEach((e=>m.add(e)));})),U(r);}}else if(h.has(o.getKey())){$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($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($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=$getPreviousSelection();$isRangeSelection(x)&&D(x.anchor)&&D(x.focus)?$setSelection(x.clone()):null!==S?S.selectEnd():e.dirty=!0;}function W(e,t){const o=$caretFromPoint(e.focus,t?"previous":"next");if($isExtendableTextPointCaret(o))return !1;for(const e of $extendCaretToRange(o)){if($isChildCaret(e))return !e.origin.isInline();if(!$isElementNode(e.origin)){if($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"===($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($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))&&$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;
15
15
 
16
- export { I as $addNodeStyle, j as $getSelectionStyleValueForProperty, F as $isAtNodeEnd, D as $isParentElementRTL, L as $moveCaretSelection, M as $moveCharacter, B as $patchStyleText, $ as $selectAll, k as $setBlocksType, A as $shouldOverrideDefaultCharacterSelection, E as $sliceSelectedTextNodeContent, K as $trimTextContentFromAnchor, _ as $wrapNodes, C as createDOMRange, P as createRectsFromDOMRange, N as getStyleObjectFromCSS, W as trimTextContentFromAnchor };
16
+ export { R as $addNodeStyle, $ as $copyBlockFormatIndent, M as $ensureForwardRangeSelection, L as $forEachSelectedTextNode, Q as $getSelectionStyleValueForProperty, b as $isAtNodeEnd, q as $isParentElementRTL, X as $moveCaretSelection, G as $moveCharacter, A as $patchStyleText, _ as $setBlocksType, W as $shouldOverrideDefaultCharacterSelection, B as $sliceSelectedTextNodeContent, O as $trimTextContentFromAnchor, j as $wrapNodes, k as createDOMRange, E as createRectsFromDOMRange, F as getCSSFromStyleObject, I as getStyleObjectFromCSS, Y as trimTextContentFromAnchor };