@lexical/selection 0.30.1-nightly.20250409.0 → 0.30.1-nightly.20250410.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.
@@ -789,6 +789,27 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
789
789
  }
790
790
  }
791
791
 
792
+ /**
793
+ * Tests if the selection's parent element has vertical writing mode.
794
+ * @param selection - The selection whose parent to test.
795
+ * @returns true if the selection's parent has vertical writing mode (writing-mode: vertical-rl), false otherwise.
796
+ */
797
+ function $isEditorVerticalOrientation(selection) {
798
+ const anchorNode = selection.anchor.getNode();
799
+ const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
800
+ const editor = lexical.$getEditor();
801
+ const domElement = editor.getElementByKey(parent.getKey());
802
+ if (domElement === null) {
803
+ return false;
804
+ }
805
+ const view = domElement.ownerDocument.defaultView;
806
+ if (view === null) {
807
+ return false;
808
+ }
809
+ const computedStyle = view.getComputedStyle(domElement);
810
+ return computedStyle.writingMode === 'vertical-rl';
811
+ }
812
+
792
813
  /**
793
814
  * Determines if the default character selection should be overridden. Used with DecoratorNodes
794
815
  * @param selection - The selection whose default character selection may need to be overridden.
@@ -796,7 +817,11 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
796
817
  * @returns true if it should be overridden, false if not.
797
818
  */
798
819
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
799
- const focusCaret = lexical.$caretFromPoint(selection.focus, isBackward ? 'previous' : 'next');
820
+ const isVertical = $isEditorVerticalOrientation(selection);
821
+
822
+ // In vertical writing mode, we adjust the direction for correct caret movement
823
+ const adjustedIsBackward = isVertical ? !isBackward : isBackward;
824
+ const focusCaret = lexical.$caretFromPoint(selection.focus, adjustedIsBackward ? 'previous' : 'next');
800
825
  if (lexical.$isExtendableTextPointCaret(focusCaret)) {
801
826
  return false;
802
827
  }
@@ -843,7 +868,26 @@ function $isParentElementRTL(selection) {
843
868
  */
844
869
  function $moveCharacter(selection, isHoldingShift, isBackward) {
845
870
  const isRTL = $isParentElementRTL(selection);
846
- $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
871
+ const isVertical = $isEditorVerticalOrientation(selection);
872
+
873
+ // In vertical-rl writing mode, arrow key directions need to be flipped
874
+ // to match the visual flow of text (top to bottom, right to left)
875
+ let adjustedIsBackward;
876
+ if (isVertical) {
877
+ // In vertical-rl mode, we need to completely invert the direction
878
+ // Left arrow (backward) should move down (forward)
879
+ // Right arrow (forward) should move up (backward)
880
+ adjustedIsBackward = !isBackward;
881
+ } else if (isRTL) {
882
+ // In horizontal RTL mode, use the standard RTL behavior
883
+ adjustedIsBackward = !isBackward;
884
+ } else {
885
+ // Standard LTR horizontal text
886
+ adjustedIsBackward = isBackward;
887
+ }
888
+
889
+ // Apply the direction adjustment to move the caret
890
+ $moveCaretSelection(selection, isHoldingShift, adjustedIsBackward, 'character');
847
891
  }
848
892
 
849
893
  /**
@@ -6,7 +6,7 @@
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, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isChildCaret, $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, $getEditor } from 'lexical';
10
10
  export { $cloneWithProperties, $selectAll } from 'lexical';
11
11
 
12
12
  /**
@@ -788,6 +788,27 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
788
788
  }
789
789
  }
790
790
 
791
+ /**
792
+ * Tests if the selection's parent element has vertical writing mode.
793
+ * @param selection - The selection whose parent to test.
794
+ * @returns true if the selection's parent has vertical writing mode (writing-mode: vertical-rl), false otherwise.
795
+ */
796
+ function $isEditorVerticalOrientation(selection) {
797
+ const anchorNode = selection.anchor.getNode();
798
+ const parent = $isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
799
+ const editor = $getEditor();
800
+ const domElement = editor.getElementByKey(parent.getKey());
801
+ if (domElement === null) {
802
+ return false;
803
+ }
804
+ const view = domElement.ownerDocument.defaultView;
805
+ if (view === null) {
806
+ return false;
807
+ }
808
+ const computedStyle = view.getComputedStyle(domElement);
809
+ return computedStyle.writingMode === 'vertical-rl';
810
+ }
811
+
791
812
  /**
792
813
  * Determines if the default character selection should be overridden. Used with DecoratorNodes
793
814
  * @param selection - The selection whose default character selection may need to be overridden.
@@ -795,7 +816,11 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
795
816
  * @returns true if it should be overridden, false if not.
796
817
  */
797
818
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
798
- const focusCaret = $caretFromPoint(selection.focus, isBackward ? 'previous' : 'next');
819
+ const isVertical = $isEditorVerticalOrientation(selection);
820
+
821
+ // In vertical writing mode, we adjust the direction for correct caret movement
822
+ const adjustedIsBackward = isVertical ? !isBackward : isBackward;
823
+ const focusCaret = $caretFromPoint(selection.focus, adjustedIsBackward ? 'previous' : 'next');
799
824
  if ($isExtendableTextPointCaret(focusCaret)) {
800
825
  return false;
801
826
  }
@@ -842,7 +867,26 @@ function $isParentElementRTL(selection) {
842
867
  */
843
868
  function $moveCharacter(selection, isHoldingShift, isBackward) {
844
869
  const isRTL = $isParentElementRTL(selection);
845
- $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
870
+ const isVertical = $isEditorVerticalOrientation(selection);
871
+
872
+ // In vertical-rl writing mode, arrow key directions need to be flipped
873
+ // to match the visual flow of text (top to bottom, right to left)
874
+ let adjustedIsBackward;
875
+ if (isVertical) {
876
+ // In vertical-rl mode, we need to completely invert the direction
877
+ // Left arrow (backward) should move down (forward)
878
+ // Right arrow (forward) should move up (backward)
879
+ adjustedIsBackward = !isBackward;
880
+ } else if (isRTL) {
881
+ // In horizontal RTL mode, use the standard RTL behavior
882
+ adjustedIsBackward = !isBackward;
883
+ } else {
884
+ // Standard LTR horizontal text
885
+ adjustedIsBackward = isBackward;
886
+ }
887
+
888
+ // Apply the direction adjustment to move the caret
889
+ $moveCaretSelection(selection, isHoldingShift, adjustedIsBackward, 'character');
846
890
  }
847
891
 
848
892
  /**
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
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;
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 r(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function s(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 l(e){let t=n.get(e);return void 0===t&&(t=s(e),n.set(e,t)),t}function i(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function c(t,n,o){let r=n.getNode(),s=o;if(e.$isElementNode(r)){const e=r.getDescendantByIndex(n.offset);null!==e&&(r=e)}for(;s>0&&null!==r;){if(e.$isElementNode(r)){const e=r.getLastDescendant();null!==e&&(r=e)}let o=r.getPreviousSibling(),l=0;if(null===o){let e=r.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){o=null;break}t=e.getPreviousSibling()}null!==e&&(l=e.isInline()?0:2,o=t)}let i=r.getTextContent();""===i&&e.$isElementNode(r)&&!r.isInline()&&(i="\n\n");const c=i.length;if(!e.$isTextNode(r)||s>=c){const t=r.getParent();r.remove(),null==t||0!==t.getChildrenSize()||e.$isRootNode(t)||t.remove(),s-=c+l,r=o}else{const o=r.getKey(),l=t.getEditorState().read((()=>{const t=e.$getNodeByKey(o);return e.$isTextNode(t)&&t.isSimpleText()?t.getTextContent():null})),f=c-s,a=i.slice(0,f);if(null!==l&&l!==i){const t=e.$getPreviousSelection();let n=r;if(r.isSimpleText())r.setTextContent(l);else{const t=e.$createTextNode(l);r.replace(t),n=t}if(e.$isRangeSelection(t)&&t.isCollapsed()){const e=t.anchor.offset;n.select(e,e)}}else if(r.isSimpleText()){const e=n.key===o;let t=n.offset;t<s&&(t=c);const l=e?t-s:0,i=e?t:f;if(e&&0===l){const[e]=r.splitText(l,i);e.remove()}else{const[,e]=r.splitText(l,i);e.remove()}}else{const t=e.$createTextNode(a);r.replace(t)}s=0}}}function f(o,r){(e.$isRangeSelection(o)?o.isCollapsed():e.$isTextNode(o)||e.$isElementNode(o))||t(280);const s=l(e.$isRangeSelection(o)?o.style:e.$isTextNode(o)?o.getStyle():o.getTextStyle()),c=Object.entries(r).reduce(((e,[t,n])=>("function"==typeof n?e[t]=n(s[t],o):null===n?delete e[t]:e[t]=n,e)),{...s}),f=i(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 r=n.getNodes();for(const n of r){if(!e.$isTextNode(n)||!n.canHaveFormat())continue;const[r,l]=(s=n,o.get(s.getKey())||[0,s.getTextContentSize()]);if(l!==r)if(e.$isTokenOrSegmented(n)||0===r&&l===n.getTextContentSize())t(n);else{t(n.splitText(r,l)[0===r?0:1])}}var s;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:r,type:s}=t;t.set(n.key,n.offset,n.type),n.set(o,r,s)}}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,r,s,l=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<r;t++){const n=o[t];e.$isElementNode(n)&&0===n.getChildrenSize()&&g.add(n.getKey())}const h=new Set;for(let n=0;n<r;n++){const r=o[n];let l=r.getParent();if(null!==l&&l.isInline()&&(l=l.getParent()),null!==l&&e.$isLeafNode(r)&&!h.has(r.getKey())){const t=l.getKey();if(void 0===c.get(t)){const n=s();n.setFormat(l.getFormatType()),n.setIndent(l.getIndent()),f.push(n),c.set(t,n),l.getChildren().forEach((t=>{n.append(t),h.add(t.getKey()),e.$isElementNode(t)&&t.getChildrenKeys().forEach((e=>h.add(e)))})),p(l)}}else if(g.has(r.getKey())){e.$isElementNode(r)||t(179);const n=s();n.setFormat(r.getFormatType()),n.setIndent(r.getIndent()),f.push(n),r.remove(!0)}}if(null!==l)for(let e=0;e<f.length;e++){const t=f[e];l.append(t)}let $=null;if(e.$isRootOrShadowRoot(a))if(d)if(null!==l)a.insertAfter(l);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(l)a.append(l);else for(let e=0;e<f.length;e++){const t=f[e];a.append(t),$=t}else if(null!==l)t.insertBefore(l);else for(let e=0;e<f.length;e++){const n=f[e];t.insertBefore(n),$=n}}else if(l)a.insertAfter(l);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)&&u(y.anchor)&&u(y.focus)?e.$setSelection(y.clone()):null!==$?$.selectEnd():n.dirty=!0}function $(t){const n=t.anchor.getNode(),o=e.$isRootNode(n)?n:n.getParentOrThrow(),r=e.$getEditor().getElementByKey(o.getKey());if(null===r)return!1;const s=r.ownerDocument.defaultView;if(null===s)return!1;return"vertical-rl"===s.getComputedStyle(r).writingMode}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=l(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=c;exports.$cloneWithProperties=e.$cloneWithProperties,exports.$selectAll=e.$selectAll,exports.$addNodeStyle=function(e){const t=e.getStyle(),o=s(t);n.set(t,o)},exports.$copyBlockFormatIndent=g,exports.$ensureForwardRangeSelection=d,exports.$forEachSelectedTextNode=a,exports.$getSelectionStyleValueForProperty=function(t,n,o=""){let r=null;const s=t.getNodes(),i=t.anchor,c=t.focus,f=t.isBackward(),a=f?c.offset:i.offset,d=f?c.getNode():i.getNode();if(e.$isRangeSelection(t)&&t.isCollapsed()&&""!==t.style){const e=l(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<s.length;t++){const l=s[t];if((0===t||0!==a||!l.is(d))&&e.$isTextNode(l)){const e=m(l,n,o);if(null===r)r=e;else if(r!==e){r="";break}}}return null===r?o:r},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=y,exports.$moveCharacter=function(e,t,n){const o=S(e);let r;r=$(e)||o?!n:n,y(e,t,r,"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 r=t.getStartEndPoints(),s=new Map;let l=null;if(r){const[t,n]=r;l=e.$createRangeSelection(),l.anchor.set(t.key,t.offset,t.type),l.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)&&s.set(o.getKey(),o),e.$isElementNode(i)&&s.set(i.getKey(),i)}for(const n of t.getNodes())e.$isElementNode(n)&&e.INTERNAL_$isBlock(n)&&s.set(n.getKey(),n);for(const[e,t]of s){const r=n();o(t,r),t.replace(r,!0),l&&(e===l.anchor.key&&l.anchor.set(r.getKey(),l.anchor.offset,l.anchor.type),e===l.focus.key&&l.focus.set(r.getKey(),l.focus.offset,l.focus.type))}l&&t.is(e.$getSelection())&&e.$setSelection(l)},exports.$shouldOverrideDefaultCharacterSelection=function(t,n){const o=$(t)?!n:n,r=e.$caretFromPoint(t.focus,o?"previous":"next");if(e.$isExtendableTextPointCaret(r))return!1;for(const t of e.$extendCaretToRange(r)){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[r,s]=o,l=t.isBackward(),i=r.getNode(),c=s.getNode(),f=n.is(i),a=n.is(c);if(f||a){const[o,r]=e.$getCharacterOffsets(t),s=i.is(c),f=n.is(l?c:i),a=n.is(l?i:c);let d,g=0;if(s)g=o>r?r:o,d=o>r?o:r;else if(f){g=l?r:o,d=void 0}else if(a){g=0,d=l?o:r}return n.__text=n.__text.slice(g,d),n}}return n},exports.$trimTextContentFromAnchor=c,exports.$wrapNodes=function(t,n,o=null){const r=t.getStartEndPoints(),s=r?r[0]:null,l=t.getNodes(),i=l.length;if(null!==s&&(0===i||1===i&&"element"===s.type&&0===s.getNode().getChildrenSize())){const e="text"===s.type?s.getNode().getParentOrThrow():s.getNode(),t=e.getChildren();let r=n();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),t.forEach((e=>r.append(e))),o&&(r=o.append(r)),void e.replace(r)}let c=null,f=[];for(let r=0;r<i;r++){const s=l[r];e.$isRootOrShadowRoot(s)?(h(t,f,f.length,n,o),f=[],c=s):null===c||null!==c&&e.$hasAncestor(s,c)?f.push(s):(h(t,f,f.length,n,o),f=[s])}h(t,f,f.length,n,o)},exports.createDOMRange=function(t,n,s,l,i){const c=n.getKey(),f=l.getKey(),a=document.createRange();let d=t.getElementByKey(c),g=t.getElementByKey(f),u=s,p=i;if(e.$isTextNode(n)&&(d=o(d)),e.$isTextNode(l)&&(g=o(g)),void 0===n||void 0===l||null===d||null===g)return null;"BR"===d.nodeName&&([d,u]=r(d)),"BR"===g.nodeName&&([g,p]=r(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(),r=getComputedStyle(n),s=parseFloat(r.paddingLeft)+parseFloat(r.paddingRight),l=Array.from(t.getClientRects());let i,c=l.length;l.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=l[e],n=i&&i.top<=t.top&&i.top+i.height>t.top&&i.left+i.width>t.left,r=t.width+s===o.width;n||r?(l.splice(e--,1),c--):i=t}return l},exports.getCSSFromStyleObject=i,exports.getStyleObjectFromCSS=l,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 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};
9
+ import{$isTextNode as e,$getCharacterOffsets as t,$isElementNode as n,$isRootNode as o,$getNodeByKey as r,$getPreviousSelection as l,$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 T,$isChildCaret as x,$isDecoratorNode as w,$getEditor 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 C=new Map;function P(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function K(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function E(t,n,o,r,l){const s=n.getKey(),i=r.getKey(),c=document.createRange();let f=t.getElementByKey(s),u=t.getElementByKey(i),g=o,a=l;if(e(n)&&(f=P(f)),e(r)&&(u=P(u)),void 0===n||void 0===r||null===f||null===u)return null;"BR"===f.nodeName&&([f,g]=K(f)),"BR"===u.nodeName&&([u,a]=K(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 k(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),r=getComputedStyle(n),l=parseFloat(r.paddingLeft)+parseFloat(r.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,r=t.width+l===o.width;n||r?(s.splice(e--,1),c--):i=t}return s}function I(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 B(e){let t=C.get(e);return void 0===t&&(t=I(e),C.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[r,l]=o,s=e.isBackward(),i=r.getNode(),c=l.getNode(),f=n.is(i),u=n.is(c);if(f||u){const[o,r]=t(e),l=i.is(c),f=n.is(s?c:i),u=n.is(s?i:c);let g,a=0;if(l)a=o>r?r:o,g=o>r?o:r;else if(f){a=s?r:o,g=void 0}else if(u){a=0,g=s?o:r}return n.__text=n.__text.slice(a,g),n}}return n}function O(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 R(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=r(n);return e(t)&&t.isSimpleText()?t.getTextContent():null})),f=p-g,a=d.slice(0,f);if(null!==o&&o!==d){const e=l();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,r=e?t:f;if(e&&0===o){const[e]=u.splitText(o,r);e.remove()}else{const[,e]=u.splitText(o,r);e.remove()}}else{const e=s(a);u.replace(e)}g=0}}}function z(e){const t=e.getStyle(),n=I(t);C.set(t,n)}function A(t,o){(i(t)?t.isCollapsed():e(t)||n(t))||N(280);const r=B(i(t)?t.style:e(t)?t.getStyle():t.getTextStyle()),l=Object.entries(o).reduce(((e,[n,o])=>("function"==typeof o?e[n]=o(r[n],t):null===o?delete e[n]:e[n]=o,e)),{...r}),s=F(l);i(t)||e(t)?t.setStyle(s):t.setTextStyle(s),C.set(s,l)}function M(e,t){if(i(e)&&e.isCollapsed()){A(e,t);const o=e.anchor.getNode();n(o)&&o.isEmpty()&&A(o,t)}L((e=>{A(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 r=n.getNodes();for(const n of r){if(!e(n)||!n.canHaveFormat())continue;const[r,s]=(l=n,o.get(l.getKey())||[0,l.getTextContentSize()]);if(s!==r)if(u(n)||0===r&&s===n.getTextContentSize())t(n);else{t(n.splitText(r,s)[0===r?0:1])}}var l;i(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&$(n)}function $(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:o,offset:r,type:l}=t;t.set(n.key,n.offset,n.type),n.set(o,r,l)}}function D(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=D){if(null===e)return;const r=e.getStartEndPoints(),l=new Map;let s=null;if(r){const[e,t]=r;s=g(),s.anchor.set(e.key,e.offset,e.type),s.focus.set(t.key,t.offset,t.type);const o=Z(e.getNode(),a),i=Z(t.getNode(),a);n(o)&&l.set(o.getKey(),o),n(i)&&l.set(i.getKey(),i)}for(const t of e.getNodes())n(t)&&a(t)&&l.set(t.getKey(),t);for(const[e,n]of l){const r=t();o(n,r),n.replace(r,!0),s&&(e===s.anchor.key&&s.anchor.set(r.getKey(),s.anchor.offset,s.anchor.type),e===s.focus.key&&s.focus.set(r.getKey(),s.focus.offset,s.focus.type))}s&&e.is(c())&&d(s)}function U(e){return e.getNode().isAttached()}function j(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 H(e,t,n=null){const o=e.getStartEndPoints(),r=o?o[0]:null,l=e.getNodes(),s=l.length;if(null!==r&&(0===s||1===s&&"element"===r.type&&0===r.getNode().getChildrenSize())){const e="text"===r.type?r.getNode().getParentOrThrow():r.getNode(),o=e.getChildren();let l=t();return l.setFormat(e.getFormatType()),l.setIndent(e.getIndent()),o.forEach((e=>l.append(e))),n&&(l=n.append(l)),void e.replace(l)}let i=null,c=[];for(let o=0;o<s;o++){const r=l[o];p(r)?(V(e,c,c.length,t,n),c=[],i=r):null===i||null!==i&&h(r,i)?c.push(r):(V(e,c,c.length,t,n),c=[r])}V(e,c,c.length,t,n)}function V(e,t,o,r,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 l=o.getParent();if(null!==l&&l.isInline()&&(l=l.getParent()),null!==l&&y(o)&&!m.has(o.getKey())){const e=l.getKey();if(void 0===f.get(e)){const t=r();t.setFormat(l.getFormatType()),t.setIndent(l.getIndent()),u.push(t),f.set(e,t),l.getChildren().forEach((e=>{t.append(e),m.add(e.getKey()),n(e)&&e.getChildrenKeys().forEach((e=>m.add(e)))})),j(l)}}else if(h.has(o.getKey())){n(o)||N(179);const e=r();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 T=l();i(T)&&U(T.anchor)&&U(T.focus)?d(T.clone()):null!==S?S.selectEnd():e.dirty=!0}function W(e){const t=e.anchor.getNode(),n=o(t)?t:t.getParentOrThrow(),r=v().getElementByKey(n.getKey());if(null===r)return!1;const l=r.ownerDocument.defaultView;if(null===l)return!1;return"vertical-rl"===l.getComputedStyle(r).writingMode}function X(e,t){const o=W(e)?!t:t,r=m(e.focus,o?"previous":"next");if(S(r))return!1;for(const e of T(r)){if(x(e))return!e.origin.isInline();if(!n(e.origin)){if(w(e.origin))return!0;break}}return!1}function q(e,t,n,o){e.modify(t?"extend":"move",n,o)}function G(e){const t=e.anchor.getNode();return"rtl"===(o(t)?t:t.getParentOrThrow()).getDirection()}function J(e,t,n){const o=G(e);let r;r=W(e)||o?!n:n,q(e,t,r,"character")}function Q(e,t,n){const o=B(e.getStyle());return null!==o&&o[t]||n}function Y(t,n,o=""){let r=null;const l=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=B(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<l.length;t++){const s=l[t];if((0===t||0!==u||!s.is(g))&&e(s)){const e=Q(s,n,o);if(null===r)r=e;else if(r!==e){r="";break}}}return null===r?o:r}function Z(e,t){let n=e;for(;null!==n&&null!==n.getParent()&&!t(n);)n=n.getParentOrThrow();return t(n)?n:null}const ee=R;export{z as $addNodeStyle,D as $copyBlockFormatIndent,$ as $ensureForwardRangeSelection,L as $forEachSelectedTextNode,Y as $getSelectionStyleValueForProperty,O as $isAtNodeEnd,G as $isParentElementRTL,q as $moveCaretSelection,J as $moveCharacter,M as $patchStyleText,_ as $setBlocksType,X as $shouldOverrideDefaultCharacterSelection,b as $sliceSelectedTextNodeContent,R as $trimTextContentFromAnchor,H as $wrapNodes,E as createDOMRange,k as createRectsFromDOMRange,F as getCSSFromStyleObject,B as getStyleObjectFromCSS,ee as trimTextContentFromAnchor};
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "selection"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "0.30.1-nightly.20250409.0",
12
+ "version": "0.30.1-nightly.20250410.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.30.1-nightly.20250409.0"
40
+ "lexical": "0.30.1-nightly.20250410.0"
41
41
  }
42
42
  }
@@ -33,6 +33,12 @@ export declare function $wrapNodes(selection: BaseSelection, createElement: () =
33
33
  * @returns
34
34
  */
35
35
  export declare function $wrapNodesImpl(selection: BaseSelection, nodes: LexicalNode[], nodesLength: number, createElement: () => ElementNode, wrappingElement?: null | ElementNode): void;
36
+ /**
37
+ * Tests if the selection's parent element has vertical writing mode.
38
+ * @param selection - The selection whose parent to test.
39
+ * @returns true if the selection's parent has vertical writing mode (writing-mode: vertical-rl), false otherwise.
40
+ */
41
+ export declare function $isEditorVerticalOrientation(selection: RangeSelection): boolean;
36
42
  /**
37
43
  * Determines if the default character selection should be overridden. Used with DecoratorNodes
38
44
  * @param selection - The selection whose default character selection may need to be overridden.