@lexical/selection 0.25.1-nightly.20250228.0 → 0.26.1-nightly.20250303.0

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.
@@ -10,6 +10,20 @@
10
10
 
11
11
  var lexical = require('lexical');
12
12
 
13
+ /**
14
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ */
20
+
21
+ // Do not require this module directly! Use normal `invariant` calls.
22
+
23
+ function formatDevErrorMessage(message) {
24
+ throw new Error(message);
25
+ }
26
+
13
27
  /**
14
28
  * Copyright (c) Meta Platforms, Inc. and affiliates.
15
29
  *
@@ -193,14 +207,6 @@ function getCSSFromStyleObject(styles) {
193
207
  return css;
194
208
  }
195
209
 
196
- /**
197
- * Copyright (c) Meta Platforms, Inc. and affiliates.
198
- *
199
- * This source code is licensed under the MIT license found in the
200
- * LICENSE file in the root directory of this source tree.
201
- *
202
- */
203
-
204
210
  /**
205
211
  * Generally used to append text content to HTML and JSON. Grabs the text content and "slices"
206
212
  * it to be generated into the new TextNode.
@@ -254,7 +260,7 @@ function $isAtNodeEnd(point) {
254
260
  }
255
261
  const node = point.getNode();
256
262
  if (!lexical.$isElementNode(node)) {
257
- throw Error(`isAtNodeEnd: node must be a TextNode or ElementNode`);
263
+ formatDevErrorMessage(`isAtNodeEnd: node must be a TextNode or ElementNode`);
258
264
  }
259
265
  return point.offset === node.getChildrenSize();
260
266
  }
@@ -390,7 +396,7 @@ function $addNodeStyle(node) {
390
396
  */
391
397
  function $patchStyle(target, patch) {
392
398
  if (!(lexical.$isRangeSelection(target) ? target.isCollapsed() : lexical.$isTextNode(target) || lexical.$isElementNode(target))) {
393
- throw Error(`$patchStyle must only be called with a TextNode, ElementNode, or collapsed RangeSelection`);
399
+ formatDevErrorMessage(`$patchStyle must only be called with a TextNode, ElementNode, or collapsed RangeSelection`);
394
400
  }
395
401
  const prevStyles = getStyleObjectFromCSS(lexical.$isRangeSelection(target) ? target.style : lexical.$isTextNode(target) ? target.getStyle() : target.getTextStyle());
396
402
  const newStyles = Object.entries(patch).reduce((styles, [key, value]) => {
@@ -503,14 +509,6 @@ function $ensureForwardRangeSelection(selection) {
503
509
  }
504
510
  }
505
511
 
506
- /**
507
- * Copyright (c) Meta Platforms, Inc. and affiliates.
508
- *
509
- * This source code is licensed under the MIT license found in the
510
- * LICENSE file in the root directory of this source tree.
511
- *
512
- */
513
-
514
512
  function $copyBlockFormatIndent(srcNode, destNode) {
515
513
  const format = srcNode.getFormatType();
516
514
  const indent = srcNode.getIndent();
@@ -562,10 +560,10 @@ function $setBlocksType(selection, $createElement, $afterCreateElement = $copyBl
562
560
  prevNode.replace(element, true);
563
561
  if (newSelection) {
564
562
  if (key === newSelection.anchor.key) {
565
- newSelection.anchor.key = element.getKey();
563
+ newSelection.anchor.set(element.getKey(), newSelection.anchor.offset, newSelection.anchor.type);
566
564
  }
567
565
  if (key === newSelection.focus.key) {
568
- newSelection.focus.key = element.getKey();
566
+ newSelection.focus.set(element.getKey(), newSelection.focus.offset, newSelection.focus.type);
569
567
  }
570
568
  }
571
569
  }
@@ -714,7 +712,7 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
714
712
  }
715
713
  } else if (emptyElements.has(node.getKey())) {
716
714
  if (!lexical.$isElementNode(node)) {
717
- throw Error(`Expected node in emptyElements to be an ElementNode`);
715
+ formatDevErrorMessage(`Expected node in emptyElements to be an ElementNode`);
718
716
  }
719
717
  const targetElement = createElement();
720
718
  targetElement.setFormat(node.getFormatType());
@@ -798,8 +796,21 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
798
796
  * @returns true if it should be overridden, false if not.
799
797
  */
800
798
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
801
- const possibleNode = lexical.$getAdjacentNode(selection.focus, isBackward);
802
- return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated() || lexical.$isElementNode(possibleNode) && !possibleNode.isInline() && !possibleNode.canBeEmpty();
799
+ const focusCaret = lexical.$caretFromPoint(selection.focus, isBackward ? 'previous' : 'next');
800
+ if (lexical.$isExtendableTextPointCaret(focusCaret)) {
801
+ return false;
802
+ }
803
+ for (const nextCaret of lexical.$extendCaretToRange(focusCaret)) {
804
+ if (lexical.$isChildCaret(nextCaret)) {
805
+ return !nextCaret.origin.isInline();
806
+ } else if (lexical.$isElementNode(nextCaret.origin)) {
807
+ continue;
808
+ } else if (lexical.$isDecoratorNode(nextCaret.origin)) {
809
+ return true;
810
+ }
811
+ break;
812
+ }
813
+ return false;
803
814
  }
804
815
 
805
816
  /**
@@ -6,9 +6,23 @@
6
6
  *
7
7
  */
8
8
 
9
- import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $getSelection, $caretRangeFromSelection, $isTokenOrSegmented, $createRangeSelection, INTERNAL_$isBlock, $setSelection, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $getAdjacentNode, $isDecoratorNode } from 'lexical';
9
+ 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';
10
10
  export { $cloneWithProperties, $selectAll } from 'lexical';
11
11
 
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ */
19
+
20
+ // Do not require this module directly! Use normal `invariant` calls.
21
+
22
+ function formatDevErrorMessage(message) {
23
+ throw new Error(message);
24
+ }
25
+
12
26
  /**
13
27
  * Copyright (c) Meta Platforms, Inc. and affiliates.
14
28
  *
@@ -192,14 +206,6 @@ function getCSSFromStyleObject(styles) {
192
206
  return css;
193
207
  }
194
208
 
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
209
  /**
204
210
  * Generally used to append text content to HTML and JSON. Grabs the text content and "slices"
205
211
  * it to be generated into the new TextNode.
@@ -253,7 +259,7 @@ function $isAtNodeEnd(point) {
253
259
  }
254
260
  const node = point.getNode();
255
261
  if (!$isElementNode(node)) {
256
- throw Error(`isAtNodeEnd: node must be a TextNode or ElementNode`);
262
+ formatDevErrorMessage(`isAtNodeEnd: node must be a TextNode or ElementNode`);
257
263
  }
258
264
  return point.offset === node.getChildrenSize();
259
265
  }
@@ -389,7 +395,7 @@ function $addNodeStyle(node) {
389
395
  */
390
396
  function $patchStyle(target, patch) {
391
397
  if (!($isRangeSelection(target) ? target.isCollapsed() : $isTextNode(target) || $isElementNode(target))) {
392
- throw Error(`$patchStyle must only be called with a TextNode, ElementNode, or collapsed RangeSelection`);
398
+ formatDevErrorMessage(`$patchStyle must only be called with a TextNode, ElementNode, or collapsed RangeSelection`);
393
399
  }
394
400
  const prevStyles = getStyleObjectFromCSS($isRangeSelection(target) ? target.style : $isTextNode(target) ? target.getStyle() : target.getTextStyle());
395
401
  const newStyles = Object.entries(patch).reduce((styles, [key, value]) => {
@@ -502,14 +508,6 @@ function $ensureForwardRangeSelection(selection) {
502
508
  }
503
509
  }
504
510
 
505
- /**
506
- * Copyright (c) Meta Platforms, Inc. and affiliates.
507
- *
508
- * This source code is licensed under the MIT license found in the
509
- * LICENSE file in the root directory of this source tree.
510
- *
511
- */
512
-
513
511
  function $copyBlockFormatIndent(srcNode, destNode) {
514
512
  const format = srcNode.getFormatType();
515
513
  const indent = srcNode.getIndent();
@@ -561,10 +559,10 @@ function $setBlocksType(selection, $createElement, $afterCreateElement = $copyBl
561
559
  prevNode.replace(element, true);
562
560
  if (newSelection) {
563
561
  if (key === newSelection.anchor.key) {
564
- newSelection.anchor.key = element.getKey();
562
+ newSelection.anchor.set(element.getKey(), newSelection.anchor.offset, newSelection.anchor.type);
565
563
  }
566
564
  if (key === newSelection.focus.key) {
567
- newSelection.focus.key = element.getKey();
565
+ newSelection.focus.set(element.getKey(), newSelection.focus.offset, newSelection.focus.type);
568
566
  }
569
567
  }
570
568
  }
@@ -713,7 +711,7 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
713
711
  }
714
712
  } else if (emptyElements.has(node.getKey())) {
715
713
  if (!$isElementNode(node)) {
716
- throw Error(`Expected node in emptyElements to be an ElementNode`);
714
+ formatDevErrorMessage(`Expected node in emptyElements to be an ElementNode`);
717
715
  }
718
716
  const targetElement = createElement();
719
717
  targetElement.setFormat(node.getFormatType());
@@ -797,8 +795,21 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
797
795
  * @returns true if it should be overridden, false if not.
798
796
  */
799
797
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
800
- const possibleNode = $getAdjacentNode(selection.focus, isBackward);
801
- return $isDecoratorNode(possibleNode) && !possibleNode.isIsolated() || $isElementNode(possibleNode) && !possibleNode.isInline() && !possibleNode.canBeEmpty();
798
+ const focusCaret = $caretFromPoint(selection.focus, isBackward ? 'previous' : 'next');
799
+ if ($isExtendableTextPointCaret(focusCaret)) {
800
+ return false;
801
+ }
802
+ for (const nextCaret of $extendCaretToRange(focusCaret)) {
803
+ if ($isChildCaret(nextCaret)) {
804
+ return !nextCaret.origin.isInline();
805
+ } else if ($isElementNode(nextCaret.origin)) {
806
+ continue;
807
+ } else if ($isDecoratorNode(nextCaret.origin)) {
808
+ return true;
809
+ }
810
+ break;
811
+ }
812
+ return false;
802
813
  }
803
814
 
804
815
  /**
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("lexical");function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n=t((function(e){const t=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(let e=1;e<arguments.length;e++)n.append("v",arguments[e]);throw t.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const o=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 l(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function r(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=o.get(e);return void 0===t&&(t=r(e),o.set(e,t)),t}function c(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function f(t,n,o){let s=n.getNode(),l=o;if(e.$isElementNode(s)){const e=s.getDescendantByIndex(n.offset);null!==e&&(s=e)}for(;l>0&&null!==s;){if(e.$isElementNode(s)){const e=s.getLastDescendant();null!==e&&(s=e)}let o=s.getPreviousSibling(),r=0;if(null===o){let e=s.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){o=null;break}t=e.getPreviousSibling()}null!==e&&(r=e.isInline()?0:2,o=t)}let i=s.getTextContent();""===i&&e.$isElementNode(s)&&!s.isInline()&&(i="\n\n");const c=i.length;if(!e.$isTextNode(s)||l>=c){const t=s.getParent();s.remove(),null==t||0!==t.getChildrenSize()||e.$isRootNode(t)||t.remove(),l-=c+r,s=o}else{const o=s.getKey(),r=t.getEditorState().read((()=>{const t=e.$getNodeByKey(o);return e.$isTextNode(t)&&t.isSimpleText()?t.getTextContent():null})),f=c-l,a=i.slice(0,f);if(null!==r&&r!==i){const t=e.$getPreviousSelection();let n=s;if(s.isSimpleText())s.setTextContent(r);else{const t=e.$createTextNode(r);s.replace(t),n=t}if(e.$isRangeSelection(t)&&t.isCollapsed()){const e=t.anchor.offset;n.select(e,e)}}else if(s.isSimpleText()){const e=n.key===o;let t=n.offset;t<l&&(t=c);const r=e?t-l:0,i=e?t:f;if(e&&0===r){const[e]=s.splitText(r,i);e.remove()}else{const[,e]=s.splitText(r,i);e.remove()}}else{const t=e.$createTextNode(a);s.replace(t)}l=0}}}function a(t,s){(e.$isRangeSelection(t)?t.isCollapsed():e.$isTextNode(t)||e.$isElementNode(t))||n(280);const l=i(e.$isRangeSelection(t)?t.style:e.$isTextNode(t)?t.getStyle():t.getTextStyle()),r=Object.entries(s).reduce(((e,[n,o])=>("function"==typeof o?e[n]=o(l[n],t):null===o?delete e[n]:e[n]=o,e)),{...l}),f=c(r);e.$isRangeSelection(t)||e.$isTextNode(t)?t.setStyle(f):t.setTextStyle(f),o.set(f,r)}function d(t){const n=e.$getSelection();if(!n)return;const o=new Map;if(e.$isRangeSelection(n))for(const t of e.$caretRangeFromSelection(n).getTextSlices())t&&o.set(t.caret.origin.getKey(),t.getSliceIndices());const s=n.getNodes();for(const n of s){if(!e.$isTextNode(n)||!n.canHaveFormat())continue;const[s,r]=(l=n,o.get(l.getKey())||[0,l.getTextContentSize()]);if(r!==s)if(e.$isTokenOrSegmented(n)||0===s&&r===n.getTextContentSize())t(n);else{t(n.splitText(s,r)[0===s?0:1])}}var l;e.$isRangeSelection(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&g(n)}function g(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:o,offset:s,type:l}=t;t.set(n.key,n.offset,n.type),n.set(o,s,l)}}function u(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function p(e){return e.getNode().isAttached()}function h(t){let n=t;for(;null!==n&&!e.$isRootOrShadowRoot(n);){const e=n.getLatest(),t=n.getParent();0===e.getChildrenSize()&&n.remove(!0),n=t}}function $(t,o,s,l,r=null){if(0===o.length)return;const i=o[0],c=new Map,f=[];let a=e.$isElementNode(i)?i:i.getParentOrThrow();a.isInline()&&(a=a.getParentOrThrow());let d=!1;for(;null!==a;){const t=a.getPreviousSibling();if(null!==t){a=t,d=!0;break}if(a=a.getParentOrThrow(),e.$isRootOrShadowRoot(a))break}const g=new Set;for(let t=0;t<s;t++){const n=o[t];e.$isElementNode(n)&&0===n.getChildrenSize()&&g.add(n.getKey())}const u=new Set;for(let t=0;t<s;t++){const s=o[t];let r=s.getParent();if(null!==r&&r.isInline()&&(r=r.getParent()),null!==r&&e.$isLeafNode(s)&&!u.has(s.getKey())){const t=r.getKey();if(void 0===c.get(t)){const n=l();n.setFormat(r.getFormatType()),n.setIndent(r.getIndent()),f.push(n),c.set(t,n),r.getChildren().forEach((t=>{n.append(t),u.add(t.getKey()),e.$isElementNode(t)&&t.getChildrenKeys().forEach((e=>u.add(e)))})),h(r)}}else if(g.has(s.getKey())){e.$isElementNode(s)||n(179);const t=l();t.setFormat(s.getFormatType()),t.setIndent(s.getIndent()),f.push(t),s.remove(!0)}}if(null!==r)for(let e=0;e<f.length;e++){const t=f[e];r.append(t)}let $=null;if(e.$isRootOrShadowRoot(a))if(d)if(null!==r)a.insertAfter(r);else for(let e=f.length-1;e>=0;e--){const t=f[e];a.insertAfter(t)}else{const t=a.getFirstChild();if(e.$isElementNode(t)&&(a=t),null===t)if(r)a.append(r);else for(let e=0;e<f.length;e++){const t=f[e];a.append(t),$=t}else if(null!==r)t.insertBefore(r);else for(let e=0;e<f.length;e++){const n=f[e];t.insertBefore(n),$=n}}else if(r)a.insertAfter(r);else for(let e=f.length-1;e>=0;e--){const t=f[e];a.insertAfter(t),$=t}const y=e.$getPreviousSelection();e.$isRangeSelection(y)&&p(y.anchor)&&p(y.focus)?e.$setSelection(y.clone()):null!==$?$.selectEnd():t.dirty=!0}function y(e,t,n,o){e.modify(t?"extend":"move",n,o)}function S(t){const n=t.anchor.getNode();return"rtl"===(e.$isRootNode(n)?n:n.getParentOrThrow()).getDirection()}function m(e,t,n){const o=i(e.getStyle());return null!==o&&o[t]||n}function N(e,t){let n=e;for(;null!==n&&null!==n.getParent()&&!t(n);)n=n.getParentOrThrow();return t(n)?n:null}const x=f;exports.$cloneWithProperties=e.$cloneWithProperties,exports.$selectAll=e.$selectAll,exports.$addNodeStyle=function(e){const t=e.getStyle(),n=r(t);o.set(t,n)},exports.$copyBlockFormatIndent=u,exports.$ensureForwardRangeSelection=g,exports.$forEachSelectedTextNode=d,exports.$getSelectionStyleValueForProperty=function(t,n,o=""){let s=null;const l=t.getNodes(),r=t.anchor,c=t.focus,f=t.isBackward(),a=f?c.offset:r.offset,d=f?c.getNode():r.getNode();if(e.$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<l.length;t++){const r=l[t];if((0===t||0!==a||!r.is(d))&&e.$isTextNode(r)){const e=m(r,n,o);if(null===s)s=e;else if(s!==e){s="";break}}}return null===s?o:s},exports.$isAtNodeEnd=function(t){if("text"===t.type)return t.offset===t.getNode().getTextContentSize();const o=t.getNode();return e.$isElementNode(o)||n(177),t.offset===o.getChildrenSize()},exports.$isParentElementRTL=S,exports.$moveCaretSelection=y,exports.$moveCharacter=function(e,t,n){const o=S(e);y(e,t,n?!o:o,"character")},exports.$patchStyleText=function(t,n){if(e.$isRangeSelection(t)&&t.isCollapsed()){a(t,n);const o=t.anchor.getNode();e.$isElementNode(o)&&o.isEmpty()&&a(o,n)}d((e=>{a(e,n)}))},exports.$setBlocksType=function(t,n,o=u){if(null===t)return;const s=t.getStartEndPoints(),l=new Map;let r=null;if(s){const[t,n]=s;r=e.$createRangeSelection(),r.anchor.set(t.key,t.offset,t.type),r.focus.set(n.key,n.offset,n.type);const o=N(t.getNode(),e.INTERNAL_$isBlock),i=N(n.getNode(),e.INTERNAL_$isBlock);e.$isElementNode(o)&&l.set(o.getKey(),o),e.$isElementNode(i)&&l.set(i.getKey(),i)}for(const n of t.getNodes())e.$isElementNode(n)&&e.INTERNAL_$isBlock(n)&&l.set(n.getKey(),n);for(const[e,t]of l){const s=n();o(t,s),t.replace(s,!0),r&&(e===r.anchor.key&&(r.anchor.key=s.getKey()),e===r.focus.key&&(r.focus.key=s.getKey()))}r&&t.is(e.$getSelection())&&e.$setSelection(r)},exports.$shouldOverrideDefaultCharacterSelection=function(t,n){const o=e.$getAdjacentNode(t.focus,n);return e.$isDecoratorNode(o)&&!o.isIsolated()||e.$isElementNode(o)&&!o.isInline()&&!o.canBeEmpty()},exports.$sliceSelectedTextNodeContent=function(t,n){const o=t.getStartEndPoints();if(n.isSelected(t)&&!n.isSegmented()&&!n.isToken()&&null!==o){const[s,l]=o,r=t.isBackward(),i=s.getNode(),c=l.getNode(),f=n.is(i),a=n.is(c);if(f||a){const[o,s]=e.$getCharacterOffsets(t),l=i.is(c),f=n.is(r?c:i),a=n.is(r?i:c);let d,g=0;if(l)g=o>s?s:o,d=o>s?o:s;else if(f){g=r?s:o,d=void 0}else if(a){g=0,d=r?o:s}return n.__text=n.__text.slice(g,d),n}}return n},exports.$trimTextContentFromAnchor=f,exports.$wrapNodes=function(t,n,o=null){const s=t.getStartEndPoints(),l=s?s[0]:null,r=t.getNodes(),i=r.length;if(null!==l&&(0===i||1===i&&"element"===l.type&&0===l.getNode().getChildrenSize())){const e="text"===l.type?l.getNode().getParentOrThrow():l.getNode(),t=e.getChildren();let s=n();return s.setFormat(e.getFormatType()),s.setIndent(e.getIndent()),t.forEach((e=>s.append(e))),o&&(s=o.append(s)),void e.replace(s)}let c=null,f=[];for(let s=0;s<i;s++){const l=r[s];e.$isRootOrShadowRoot(l)?($(t,f,f.length,n,o),f=[],c=l):null===c||null!==c&&e.$hasAncestor(l,c)?f.push(l):($(t,f,f.length,n,o),f=[l])}$(t,f,f.length,n,o)},exports.createDOMRange=function(t,n,o,r,i){const c=n.getKey(),f=r.getKey(),a=document.createRange();let d=t.getElementByKey(c),g=t.getElementByKey(f),u=o,p=i;if(e.$isTextNode(n)&&(d=s(d)),e.$isTextNode(r)&&(g=s(g)),void 0===n||void 0===r||null===d||null===g)return null;"BR"===d.nodeName&&([d,u]=l(d)),"BR"===g.nodeName&&([g,p]=l(g));const h=d.firstChild;d===g&&null!=h&&"BR"===h.nodeName&&0===u&&0===p&&(p=1);try{a.setStart(d,u),a.setEnd(g,p)}catch(e){return null}return!a.collapsed||u===p&&c===f||(a.setStart(g,p),a.setEnd(d,u)),a},exports.createRectsFromDOMRange=function(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),s=getComputedStyle(n),l=parseFloat(s.paddingLeft)+parseFloat(s.paddingRight),r=Array.from(t.getClientRects());let i,c=r.length;r.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=r[e],n=i&&i.top<=t.top&&i.top+i.height>t.top&&i.left+i.width>t.left,s=t.width+l===o.width;n||s?(r.splice(e--,1),c--):i=t}return r},exports.getCSSFromStyleObject=c,exports.getStyleObjectFromCSS=i,exports.trimTextContentFromAnchor=x;
9
+ "use strict";var e=require("lexical");function t(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 n=new Map;function o(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function s(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function r(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=n.get(e);return void 0===t&&(t=r(e),n.set(e,t)),t}function l(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function c(t,n,o){let s=n.getNode(),r=o;if(e.$isElementNode(s)){const e=s.getDescendantByIndex(n.offset);null!==e&&(s=e)}for(;r>0&&null!==s;){if(e.$isElementNode(s)){const e=s.getLastDescendant();null!==e&&(s=e)}let o=s.getPreviousSibling(),i=0;if(null===o){let e=s.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){o=null;break}t=e.getPreviousSibling()}null!==e&&(i=e.isInline()?0:2,o=t)}let l=s.getTextContent();""===l&&e.$isElementNode(s)&&!s.isInline()&&(l="\n\n");const c=l.length;if(!e.$isTextNode(s)||r>=c){const t=s.getParent();s.remove(),null==t||0!==t.getChildrenSize()||e.$isRootNode(t)||t.remove(),r-=c+i,s=o}else{const o=s.getKey(),i=t.getEditorState().read((()=>{const t=e.$getNodeByKey(o);return e.$isTextNode(t)&&t.isSimpleText()?t.getTextContent():null})),f=c-r,a=l.slice(0,f);if(null!==i&&i!==l){const t=e.$getPreviousSelection();let n=s;if(s.isSimpleText())s.setTextContent(i);else{const t=e.$createTextNode(i);s.replace(t),n=t}if(e.$isRangeSelection(t)&&t.isCollapsed()){const e=t.anchor.offset;n.select(e,e)}}else if(s.isSimpleText()){const e=n.key===o;let t=n.offset;t<r&&(t=c);const i=e?t-r:0,l=e?t:f;if(e&&0===i){const[e]=s.splitText(i,l);e.remove()}else{const[,e]=s.splitText(i,l);e.remove()}}else{const t=e.$createTextNode(a);s.replace(t)}r=0}}}function f(o,s){(e.$isRangeSelection(o)?o.isCollapsed():e.$isTextNode(o)||e.$isElementNode(o))||t(280);const r=i(e.$isRangeSelection(o)?o.style:e.$isTextNode(o)?o.getStyle():o.getTextStyle()),c=Object.entries(s).reduce(((e,[t,n])=>("function"==typeof n?e[t]=n(r[t],o):null===n?delete e[t]:e[t]=n,e)),{...r}),f=l(c);e.$isRangeSelection(o)||e.$isTextNode(o)?o.setStyle(f):o.setTextStyle(f),n.set(f,c)}function a(t){const n=e.$getSelection();if(!n)return;const o=new Map;if(e.$isRangeSelection(n))for(const t of e.$caretRangeFromSelection(n).getTextSlices())t&&o.set(t.caret.origin.getKey(),t.getSliceIndices());const s=n.getNodes();for(const n of s){if(!e.$isTextNode(n)||!n.canHaveFormat())continue;const[s,i]=(r=n,o.get(r.getKey())||[0,r.getTextContentSize()]);if(i!==s)if(e.$isTokenOrSegmented(n)||0===s&&i===n.getTextContentSize())t(n);else{t(n.splitText(s,i)[0===s?0:1])}}var r;e.$isRangeSelection(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&d(n)}function d(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:o,offset:s,type:r}=t;t.set(n.key,n.offset,n.type),n.set(o,s,r)}}function g(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function u(e){return e.getNode().isAttached()}function p(t){let n=t;for(;null!==n&&!e.$isRootOrShadowRoot(n);){const e=n.getLatest(),t=n.getParent();0===e.getChildrenSize()&&n.remove(!0),n=t}}function h(n,o,s,r,i=null){if(0===o.length)return;const l=o[0],c=new Map,f=[];let a=e.$isElementNode(l)?l:l.getParentOrThrow();a.isInline()&&(a=a.getParentOrThrow());let d=!1;for(;null!==a;){const t=a.getPreviousSibling();if(null!==t){a=t,d=!0;break}if(a=a.getParentOrThrow(),e.$isRootOrShadowRoot(a))break}const g=new Set;for(let t=0;t<s;t++){const n=o[t];e.$isElementNode(n)&&0===n.getChildrenSize()&&g.add(n.getKey())}const h=new Set;for(let n=0;n<s;n++){const s=o[n];let i=s.getParent();if(null!==i&&i.isInline()&&(i=i.getParent()),null!==i&&e.$isLeafNode(s)&&!h.has(s.getKey())){const t=i.getKey();if(void 0===c.get(t)){const n=r();n.setFormat(i.getFormatType()),n.setIndent(i.getIndent()),f.push(n),c.set(t,n),i.getChildren().forEach((t=>{n.append(t),h.add(t.getKey()),e.$isElementNode(t)&&t.getChildrenKeys().forEach((e=>h.add(e)))})),p(i)}}else if(g.has(s.getKey())){e.$isElementNode(s)||t(179);const n=r();n.setFormat(s.getFormatType()),n.setIndent(s.getIndent()),f.push(n),s.remove(!0)}}if(null!==i)for(let e=0;e<f.length;e++){const t=f[e];i.append(t)}let $=null;if(e.$isRootOrShadowRoot(a))if(d)if(null!==i)a.insertAfter(i);else for(let e=f.length-1;e>=0;e--){const t=f[e];a.insertAfter(t)}else{const t=a.getFirstChild();if(e.$isElementNode(t)&&(a=t),null===t)if(i)a.append(i);else for(let e=0;e<f.length;e++){const t=f[e];a.append(t),$=t}else if(null!==i)t.insertBefore(i);else for(let e=0;e<f.length;e++){const n=f[e];t.insertBefore(n),$=n}}else if(i)a.insertAfter(i);else for(let e=f.length-1;e>=0;e--){const t=f[e];a.insertAfter(t),$=t}const S=e.$getPreviousSelection();e.$isRangeSelection(S)&&u(S.anchor)&&u(S.focus)?e.$setSelection(S.clone()):null!==$?$.selectEnd():n.dirty=!0}function $(e,t,n,o){e.modify(t?"extend":"move",n,o)}function S(t){const n=t.anchor.getNode();return"rtl"===(e.$isRootNode(n)?n:n.getParentOrThrow()).getDirection()}function y(e,t,n){const o=i(e.getStyle());return null!==o&&o[t]||n}function m(e,t){let n=e;for(;null!==n&&null!==n.getParent()&&!t(n);)n=n.getParentOrThrow();return t(n)?n:null}const x=c;exports.$cloneWithProperties=e.$cloneWithProperties,exports.$selectAll=e.$selectAll,exports.$addNodeStyle=function(e){const t=e.getStyle(),o=r(t);n.set(t,o)},exports.$copyBlockFormatIndent=g,exports.$ensureForwardRangeSelection=d,exports.$forEachSelectedTextNode=a,exports.$getSelectionStyleValueForProperty=function(t,n,o=""){let s=null;const r=t.getNodes(),l=t.anchor,c=t.focus,f=t.isBackward(),a=f?c.offset:l.offset,d=f?c.getNode():l.getNode();if(e.$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 i=r[t];if((0===t||0!==a||!i.is(d))&&e.$isTextNode(i)){const e=y(i,n,o);if(null===s)s=e;else if(s!==e){s="";break}}}return null===s?o:s},exports.$isAtNodeEnd=function(n){if("text"===n.type)return n.offset===n.getNode().getTextContentSize();const o=n.getNode();return e.$isElementNode(o)||t(177),n.offset===o.getChildrenSize()},exports.$isParentElementRTL=S,exports.$moveCaretSelection=$,exports.$moveCharacter=function(e,t,n){const o=S(e);$(e,t,n?!o:o,"character")},exports.$patchStyleText=function(t,n){if(e.$isRangeSelection(t)&&t.isCollapsed()){f(t,n);const o=t.anchor.getNode();e.$isElementNode(o)&&o.isEmpty()&&f(o,n)}a((e=>{f(e,n)}))},exports.$setBlocksType=function(t,n,o=g){if(null===t)return;const s=t.getStartEndPoints(),r=new Map;let i=null;if(s){const[t,n]=s;i=e.$createRangeSelection(),i.anchor.set(t.key,t.offset,t.type),i.focus.set(n.key,n.offset,n.type);const o=m(t.getNode(),e.INTERNAL_$isBlock),l=m(n.getNode(),e.INTERNAL_$isBlock);e.$isElementNode(o)&&r.set(o.getKey(),o),e.$isElementNode(l)&&r.set(l.getKey(),l)}for(const n of t.getNodes())e.$isElementNode(n)&&e.INTERNAL_$isBlock(n)&&r.set(n.getKey(),n);for(const[e,t]of r){const s=n();o(t,s),t.replace(s,!0),i&&(e===i.anchor.key&&i.anchor.set(s.getKey(),i.anchor.offset,i.anchor.type),e===i.focus.key&&i.focus.set(s.getKey(),i.focus.offset,i.focus.type))}i&&t.is(e.$getSelection())&&e.$setSelection(i)},exports.$shouldOverrideDefaultCharacterSelection=function(t,n){const o=e.$caretFromPoint(t.focus,n?"previous":"next");if(e.$isExtendableTextPointCaret(o))return!1;for(const t of e.$extendCaretToRange(o)){if(e.$isChildCaret(t))return!t.origin.isInline();if(!e.$isElementNode(t.origin)){if(e.$isDecoratorNode(t.origin))return!0;break}}return!1},exports.$sliceSelectedTextNodeContent=function(t,n){const o=t.getStartEndPoints();if(n.isSelected(t)&&!n.isSegmented()&&!n.isToken()&&null!==o){const[s,r]=o,i=t.isBackward(),l=s.getNode(),c=r.getNode(),f=n.is(l),a=n.is(c);if(f||a){const[o,s]=e.$getCharacterOffsets(t),r=l.is(c),f=n.is(i?c:l),a=n.is(i?l:c);let d,g=0;if(r)g=o>s?s:o,d=o>s?o:s;else if(f){g=i?s:o,d=void 0}else if(a){g=0,d=i?o:s}return n.__text=n.__text.slice(g,d),n}}return n},exports.$trimTextContentFromAnchor=c,exports.$wrapNodes=function(t,n,o=null){const s=t.getStartEndPoints(),r=s?s[0]:null,i=t.getNodes(),l=i.length;if(null!==r&&(0===l||1===l&&"element"===r.type&&0===r.getNode().getChildrenSize())){const e="text"===r.type?r.getNode().getParentOrThrow():r.getNode(),t=e.getChildren();let s=n();return s.setFormat(e.getFormatType()),s.setIndent(e.getIndent()),t.forEach((e=>s.append(e))),o&&(s=o.append(s)),void e.replace(s)}let c=null,f=[];for(let s=0;s<l;s++){const r=i[s];e.$isRootOrShadowRoot(r)?(h(t,f,f.length,n,o),f=[],c=r):null===c||null!==c&&e.$hasAncestor(r,c)?f.push(r):(h(t,f,f.length,n,o),f=[r])}h(t,f,f.length,n,o)},exports.createDOMRange=function(t,n,r,i,l){const c=n.getKey(),f=i.getKey(),a=document.createRange();let d=t.getElementByKey(c),g=t.getElementByKey(f),u=r,p=l;if(e.$isTextNode(n)&&(d=o(d)),e.$isTextNode(i)&&(g=o(g)),void 0===n||void 0===i||null===d||null===g)return null;"BR"===d.nodeName&&([d,u]=s(d)),"BR"===g.nodeName&&([g,p]=s(g));const h=d.firstChild;d===g&&null!=h&&"BR"===h.nodeName&&0===u&&0===p&&(p=1);try{a.setStart(d,u),a.setEnd(g,p)}catch(e){return null}return!a.collapsed||u===p&&c===f||(a.setStart(g,p),a.setEnd(d,u)),a},exports.createRectsFromDOMRange=function(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),s=getComputedStyle(n),r=parseFloat(s.paddingLeft)+parseFloat(s.paddingRight),i=Array.from(t.getClientRects());let l,c=i.length;i.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=i[e],n=l&&l.top<=t.top&&l.top+l.height>t.top&&l.left+l.width>t.left,s=t.width+r===o.width;n||s?(i.splice(e--,1),c--):l=t}return i},exports.getCSSFromStyleObject=l,exports.getStyleObjectFromCSS=i,exports.trimTextContentFromAnchor=x;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{$isTextNode as e,$getCharacterOffsets as t,$isElementNode as n,$isRootNode as o,$getNodeByKey as l,$getPreviousSelection as r,$createTextNode as s,$isRangeSelection as i,$getSelection as c,$caretRangeFromSelection as f,$isTokenOrSegmented as u,$createRangeSelection as a,INTERNAL_$isBlock as g,$setSelection as d,$isRootOrShadowRoot as p,$hasAncestor as h,$isLeafNode as y,$getAdjacentNode as m,$isDecoratorNode as S}from"lexical";export{$cloneWithProperties,$selectAll}from"lexical";function T(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var x=T((function(e){const t=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(let e=1;e<arguments.length;e++)n.append("v",arguments[e]);throw t.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const v=new Map;function w(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function N(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,o,l,r){const s=n.getKey(),i=l.getKey(),c=document.createRange();let f=t.getElementByKey(s),u=t.getElementByKey(i),a=o,g=r;if(e(n)&&(f=w(f)),e(l)&&(u=w(u)),void 0===n||void 0===l||null===f||null===u)return null;"BR"===f.nodeName&&([f,a]=N(f)),"BR"===u.nodeName&&([u,g]=N(u));const d=f.firstChild;f===u&&null!=d&&"BR"===d.nodeName&&0===a&&0===g&&(g=1);try{c.setStart(f,a),c.setEnd(u,g)}catch(e){return null}return!c.collapsed||a===g&&s===i||(c.setStart(u,g),c.setEnd(f,a)),c}function P(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 E(e){let t=v.get(e);return void 0===t&&(t=k(e),v.set(e,t)),t}function K(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function I(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]=t(e),r=i.is(c),f=n.is(s?c:i),u=n.is(s?i:c);let a,g=0;if(r)g=o>l?l:o,a=o>l?o:l;else if(f){g=s?l:o,a=void 0}else if(u){g=0,a=s?o:l}return n.__text=n.__text.slice(g,a),n}}return n}function B(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return n(t)||x(177),e.offset===t.getChildrenSize()}function F(t,c,f){let u=c.getNode(),a=f;if(n(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e)}for(;a>0&&null!==u;){if(n(u)){const e=u.getLastDescendant();null!==e&&(u=e)}let f=u.getPreviousSibling(),g=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&&(g=e.isInline()?0:2,f=t)}let d=u.getTextContent();""===d&&n(u)&&!u.isInline()&&(d="\n\n");const p=d.length;if(!e(u)||a>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||o(e)||e.remove(),a-=p+g,u=f}else{const n=u.getKey(),o=t.getEditorState().read((()=>{const t=l(n);return e(t)&&t.isSimpleText()?t.getTextContent():null})),f=p-a,g=d.slice(0,f);if(null!==o&&o!==d){const e=r();let t=u;if(u.isSimpleText())u.setTextContent(o);else{const e=s(o);u.replace(e),t=e}if(i(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<a&&(t=p);const o=e?t-a: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=s(g);u.replace(e)}a=0}}}function O(e){const t=e.getStyle(),n=k(t);v.set(t,n)}function b(t,o){(i(t)?t.isCollapsed():e(t)||n(t))||x(280);const l=E(i(t)?t.style:e(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=K(r);i(t)||e(t)?t.setStyle(s):t.setTextStyle(s),v.set(s,r)}function R(e,t){if(i(e)&&e.isCollapsed()){b(e,t);const o=e.anchor.getNode();n(o)&&o.isEmpty()&&b(o,t)}z((e=>{b(e,t)}))}function z(t){const n=c();if(!n)return;const o=new Map;if(i(n))for(const e of f(n).getTextSlices())e&&o.set(e.caret.origin.getKey(),e.getSliceIndices());const l=n.getNodes();for(const n of l){if(!e(n)||!n.canHaveFormat())continue;const[l,s]=(r=n,o.get(r.getKey())||[0,r.getTextContentSize()]);if(s!==l)if(u(n)||0===l&&s===n.getTextContentSize())t(n);else{t(n.splitText(l,s)[0===l?0:1])}}var r;i(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&A(n)}function A(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 M(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=M){if(null===e)return;const l=e.getStartEndPoints(),r=new Map;let s=null;if(l){const[e,t]=l;s=a(),s.anchor.set(e.key,e.offset,e.type),s.focus.set(t.key,t.offset,t.type);const o=J(e.getNode(),g),i=J(t.getNode(),g);n(o)&&r.set(o.getKey(),o),n(i)&&r.set(i.getKey(),i)}for(const t of e.getNodes())n(t)&&g(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.key=l.getKey()),e===s.focus.key&&(s.focus.key=l.getKey()))}s&&e.is(c())&&d(s)}function L(e){return e.getNode().isAttached()}function $(e){let t=e;for(;null!==t&&!p(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function D(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];p(l)?(j(e,c,c.length,t,n),c=[],i=l):null===i||null!==i&&h(l,i)?c.push(l):(j(e,c,c.length,t,n),c=[l])}j(e,c,c.length,t,n)}function j(e,t,o,l,s=null){if(0===t.length)return;const c=t[0],f=new Map,u=[];let a=n(c)?c:c.getParentOrThrow();a.isInline()&&(a=a.getParentOrThrow());let g=!1;for(;null!==a;){const e=a.getPreviousSibling();if(null!==e){a=e,g=!0;break}if(a=a.getParentOrThrow(),p(a))break}const h=new Set;for(let e=0;e<o;e++){const o=t[e];n(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&&y(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()),n(e)&&e.getChildrenKeys().forEach((e=>m.add(e)))})),$(r)}}else if(h.has(o.getKey())){n(o)||x(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(p(a))if(g)if(null!==s)a.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];a.insertAfter(t)}else{const e=a.getFirstChild();if(n(e)&&(a=e),null===e)if(s)a.append(s);else for(let e=0;e<u.length;e++){const t=u[e];a.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)a.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];a.insertAfter(t),S=t}const T=r();i(T)&&L(T.anchor)&&L(T.focus)?d(T.clone()):null!==S?S.selectEnd():e.dirty=!0}function U(e,t){const o=m(e.focus,t);return S(o)&&!o.isIsolated()||n(o)&&!o.isInline()&&!o.canBeEmpty()}function H(e,t,n,o){e.modify(t?"extend":"move",n,o)}function W(e){const t=e.anchor.getNode();return"rtl"===(o(t)?t:t.getParentOrThrow()).getDirection()}function X(e,t,n){const o=W(e);H(e,t,n?!o:o,"character")}function q(e,t,n){const o=E(e.getStyle());return null!==o&&o[t]||n}function G(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,a=f?c.getNode():s.getNode();if(i(t)&&t.isCollapsed()&&""!==t.style){const e=E(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(a))&&e(s)){const e=q(s,n,o);if(null===l)l=e;else if(l!==e){l="";break}}}return null===l?o:l}function J(e,t){let n=e;for(;null!==n&&null!==n.getParent()&&!t(n);)n=n.getParentOrThrow();return t(n)?n:null}const Q=F;export{O as $addNodeStyle,M as $copyBlockFormatIndent,A as $ensureForwardRangeSelection,z as $forEachSelectedTextNode,G as $getSelectionStyleValueForProperty,B as $isAtNodeEnd,W as $isParentElementRTL,H as $moveCaretSelection,X as $moveCharacter,R as $patchStyleText,_ as $setBlocksType,U as $shouldOverrideDefaultCharacterSelection,I as $sliceSelectedTextNodeContent,F as $trimTextContentFromAnchor,D as $wrapNodes,C as createDOMRange,P as createRectsFromDOMRange,K as getCSSFromStyleObject,E as getStyleObjectFromCSS,Q as trimTextContentFromAnchor};
9
+ import{$isTextNode as e,$getCharacterOffsets as t,$isElementNode as n,$isRootNode as o,$getNodeByKey as l,$getPreviousSelection as r,$createTextNode as s,$isRangeSelection as i,$getSelection as c,$caretRangeFromSelection as f,$isTokenOrSegmented as u,$createRangeSelection as g,INTERNAL_$isBlock as a,$setSelection as d,$isRootOrShadowRoot as p,$hasAncestor as h,$isLeafNode as y,$caretFromPoint as m,$isExtendableTextPointCaret as S,$extendCaretToRange as x,$isChildCaret as T,$isDecoratorNode as v}from"lexical";export{$cloneWithProperties,$selectAll}from"lexical";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(e(n)&&(f=C(f)),e(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]=t(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 n(t)||N(177),e.offset===t.getChildrenSize()}function O(t,c,f){let u=c.getNode(),g=f;if(n(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e)}for(;g>0&&null!==u;){if(n(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&&n(u)&&!u.isInline()&&(d="\n\n");const p=d.length;if(!e(u)||g>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||o(e)||e.remove(),g-=p+a,u=f}else{const n=u.getKey(),o=t.getEditorState().read((()=>{const t=l(n);return e(t)&&t.isSimpleText()?t.getTextContent():null})),f=p-g,a=d.slice(0,f);if(null!==o&&o!==d){const e=r();let t=u;if(u.isSimpleText())u.setTextContent(o);else{const e=s(o);u.replace(e),t=e}if(i(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=s(a);u.replace(e)}g=0}}}function R(e){const t=e.getStyle(),n=K(t);w.set(t,n)}function z(t,o){(i(t)?t.isCollapsed():e(t)||n(t))||N(280);const l=I(i(t)?t.style:e(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);i(t)||e(t)?t.setStyle(s):t.setTextStyle(s),w.set(s,r)}function A(e,t){if(i(e)&&e.isCollapsed()){z(e,t);const o=e.anchor.getNode();n(o)&&o.isEmpty()&&z(o,t)}L((e=>{z(e,t)}))}function L(t){const n=c();if(!n)return;const o=new Map;if(i(n))for(const e of f(n).getTextSlices())e&&o.set(e.caret.origin.getKey(),e.getSliceIndices());const l=n.getNodes();for(const n of l){if(!e(n)||!n.canHaveFormat())continue;const[l,s]=(r=n,o.get(r.getKey())||[0,r.getTextContentSize()]);if(s!==l)if(u(n)||0===l&&s===n.getTextContentSize())t(n);else{t(n.splitText(l,s)[0===l?0:1])}}var r;i(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=g(),s.anchor.set(e.key,e.offset,e.type),s.focus.set(t.key,t.offset,t.type);const o=V(e.getNode(),a),i=V(t.getNode(),a);n(o)&&r.set(o.getKey(),o),n(i)&&r.set(i.getKey(),i)}for(const t of e.getNodes())n(t)&&a(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(c())&&d(s)}function D(e){return e.getNode().isAttached()}function U(e){let t=e;for(;null!==t&&!p(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];p(l)?(H(e,c,c.length,t,n),c=[],i=l):null===i||null!==i&&h(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=n(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(),p(g))break}const h=new Set;for(let e=0;e<o;e++){const o=t[e];n(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&&y(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()),n(e)&&e.getChildrenKeys().forEach((e=>m.add(e)))})),U(r)}}else if(h.has(o.getKey())){n(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(p(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(n(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=r();i(x)&&D(x.anchor)&&D(x.focus)?d(x.clone()):null!==S?S.selectEnd():e.dirty=!0}function W(e,t){const o=m(e.focus,t?"previous":"next");if(S(o))return!1;for(const e of x(o)){if(T(e))return!e.origin.isInline();if(!n(e.origin)){if(v(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"===(o(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(i(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))&&e(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;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};
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "selection"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "0.25.1-nightly.20250228.0",
12
+ "version": "0.26.1-nightly.20250303.0",
13
13
  "main": "LexicalSelection.js",
14
14
  "types": "index.d.ts",
15
15
  "repository": {
@@ -37,6 +37,6 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
- "lexical": "0.25.1-nightly.20250228.0"
40
+ "lexical": "0.26.1-nightly.20250303.0"
41
41
  }
42
42
  }