@lexical/selection 0.53.0 → 0.53.1-nightly.20261030.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.
@@ -229,7 +229,10 @@ function $isParentRTL(node) {
229
229
  */
230
230
  function $sliceSelectedTextNodeContent(selection, textNode, mutates = 'self') {
231
231
  const points = selection.getStartEndPoints();
232
- if (points !== null && textNode.isSelected(selection) && !$isTokenOrSegmented(textNode)) {
232
+ // Only the node of a text point can be cut short; checking that first
233
+ // keeps a caller that slices every selected node from working out the
234
+ // selection for each of them.
235
+ if (points !== null && (points[0].key === textNode.__key || points[1].key === textNode.__key) && textNode.isSelected(selection) && !$isTokenOrSegmented(textNode)) {
233
236
  const [start, end] = selection.isBackward() ? [points[1], points[0]] : points;
234
237
  // Text endpoints can trim directly. Element endpoints need caret
235
238
  // normalization so equivalent mixed points produce an empty interval.
@@ -6,5 +6,5 @@
6
6
  *
7
7
  */
8
8
 
9
- import{getRootOwnerDocument as e,$getEditor as t,$isRootNode as n,$isTextNode as o,getDOMTextNode as l,$getElementAndOffsetForPoint as r,$getSelection as i,$isElementNode as s,$isRangeSelection as c,$isTokenOrSegmented as f,$getTextPointCaretSliceForNode as u,$caretRangeFromSelection as g,$cloneWithPropertiesEphemeral as a,$getNodeByKey as d,$getPreviousSelection as p,$createTextNode as h,$splitTextPointCaretSlice as y,getStyleObjectFromCSS as m,$caretFromPoint as S,$isExtendableTextPointCaret as x,$findMatchingParent as C,INTERNAL_$isBlock as N,flipDirection as v,$getSlotHost as T,$isTextPointCaret as w,$isTabNode as P,$extendCaretToRange as k,$isChildCaret as K,$isDecoratorNode as I,$getSlotFrame as b,$isRootOrShadowRoot as E,$hasAncestor as F,$isLeafNode as B,$setSelection as A}from"lexical";export{$cloneWithProperties,$selectAll}from"lexical";function z(e,...t){throw function(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);return n.search=o.toString(),new 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.`)}(e,...t)}
10
- /*@__INLINE__*/function R(e){return()=>{}}function _(e,t,n){const i=e.getElementByKey(t.getKey());if(null===i||o(t))return[l(i),n];const s=i.parentNode;return s&&"BR"===i.nodeName?[s,Array.from(s.childNodes).indexOf(i)]:e.read("latest",()=>r(e,t,n))}function O(t,n,o,l,r){const i=e(t.getRootElement()).createRange(),[s,c]=_(t,n,o),[f,u]=_(t,l,r);let g=u;if(null===s||null===f)return null;const a=s.firstChild;s===f&&null!=a&&"BR"===a.nodeName&&0===c&&0===g&&(g=1);try{i.setStart(s,c),i.setEnd(f,g)}catch(e){return null}return!i.collapsed||c===g&&n.is(l)||(i.setStart(f,g),i.setEnd(s,c)),i}function L(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),l=getComputedStyle(n),r=parseFloat(l.paddingLeft)+parseFloat(l.paddingRight),i=Array.from(t.getClientRects());let s,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=s&&s.top<=t.top&&s.bottom>=t.bottom&&s.left<=t.left&&s.right>=t.right,l=t.width+r===o.width;n||l?(i.splice(e--,1),c--):s=t}return i}function $(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function M(e){const n=t().getElementByKey(e.getKey());if(null===n)return null;const o=n.ownerDocument.defaultView;return null===o?null:o.getComputedStyle(n)}function D(e){const t=n(e)?e:e.getParent();return t&&M(t)}function U(e){const t=D(e);return null!==t&&"rtl"===t.direction}function j(e,t,n="self"){const o=e.getStartEndPoints();if(null!==o&&t.isSelected(e)&&!f(t)){const[l,r]=e.isBackward()?[o[1],o[0]]:o,i=!c(e)||"element"!==l.type&&"element"!==r.type?void 0:u(g(e).getTextSlices(),t),[s,f]=i?i.getSliceIndices():[t.__key===l.key?l.offset:0,t.__key===r.key?r.offset:void 0],d=t.__text.slice(s,f);d!==t.__text&&("clone"===n&&(t=a(t)),t.__text=d)}return t}function H(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return s(t)||z(177),e.offset===t.getChildrenSize()}function V(e,t,l){let r=t.getNode(),i=l;if(s(r)){const e=r.getDescendantByIndex(t.offset);null!==e&&(r=e)}for(;i>0&&null!==r;){if(s(r)){const e=r.getLastDescendant();null!==e&&(r=e)}let l=r.getPreviousSibling(),f=0;if(null===l){let e=r.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){l=null;break}t=e.getPreviousSibling()}null!==e&&(f=e.isInline()?0:2,l=t)}let u=r.getTextContent();""===u&&s(r)&&!r.isInline()&&(u="\n\n");const g=u.length;if(!o(r)||i>=g){const e=r.getParent();r.remove(),null==e||0!==e.getChildrenSize()||n(e)||e.remove(),i-=g+f,r=l}else{const n=r.getKey(),l=e.read("latest",()=>{const e=d(n);return o(e)&&e.isSimpleText()?e.getTextContent():null}),s=g-i,f=u.slice(0,s);if(null!==l&&l!==u){const e=p();let t=r;if(r.isSimpleText())r.setTextContent(l);else{const e=h(l);r.replace(e),t=e}if(c(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n)}}else if(r.isSimpleText()){const e=t.key===n;let o=t.offset;o<i&&(o=g);const l=e?o-i:0,c=e?o:s;if(e&&0===l){const[e]=r.splitText(l,c);e.remove()}else{const[,e]=r.splitText(l,c);e.remove()}}else{const e=h(f);r.replace(e)}i=0}}}const W=/* @__PURE__ */R();function q(e,t){(c(e)?e.isCollapsed():o(e)||s(e))||z(280);const n=m(c(e)?e.style:o(e)?e.getStyle():e.getTextStyle()),l=$(Object.entries(t).reduce((t,[o,l])=>("function"==typeof l?t[o]=l(n[o],e):null===l?delete t[o]:t[o]=l,t),{...n}));c(e)||o(e)?e.setStyle(l):e.setTextStyle(l)}function G(e,t){const n=new Set;if(c(e)&&e.isCollapsed()){q(e,t);const o=e.anchor.getNode();s(o)&&o.isEmpty()&&(n.add(o.getKey()),q(o,t))}Q(e,e=>{q(e,t)});const o=e.getNodes();if(o.length>0)for(const e of o){if(!s(e)||!e.canBeEmpty()||0!==e.getChildrenSize())continue;const o=e.getKey();n.has(o)||(n.add(o),q(e,t))}}function J(e){Q(i(),e)}function Q(e,t){if(!e)return;const n=c(e)?g(e).getTextSlices():[];for(const l of e.getNodes()){if(!o(l)||!l.canHaveFormat())continue;const r=u(n,l);(r?0!==r.distance:0!==l.getTextContentSize())&&t(r&&!f(l)?y(r,c(e)?e:null):l)}c(e)&&"text"===e.anchor.type&&"text"===e.focus.type&&e.anchor.key===e.focus.key&&X(e)}function X(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 Y(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function Z(e,t,n){let o=S(e,n);if(x(o))return!1;for(;o;o=o.getParentCaret()){const e=o.getParentAtCaret();if(!e||o.getNodeAtCaret())return!1;if(t.is(e))return!0}return!1}function ee(e,t,n=Y){if(!e)return;const o=e.getStartEndPoints();let l=!1,r=null;const i=new Map;if(o){const[t,n]=o,c=C(t.getNode(),N);r=C(n.getNode(),N);const f=e.isBackward()?"previous":"next";l=s(r)&&!r.is(c)&&function(e,t,n){const o=e.getNode();return(!s(o)||!o.isEmpty())&&Z(e,t,n)}(n,r,v(f)),s(c)&&i.set(c.getKey(),c),s(r)&&!l&&i.set(r.getKey(),r)}for(const t of e.getNodes())if(s(t)&&N(t)){if(l&&t.is(r))continue;i.set(t.getKey(),t)}else if(!o){const e=C(t,N);s(e)&&i.set(e.getKey(),e)}for(const e of i.values()){if(null!==T(e))continue;const o=t();n(e,o),e.replace(o,!0)}}function te(e){return e.getNode().isAttached()}function ne(e){let t=e;for(;null!==t&&!E(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function oe(e,t,n=null){const o=e.getStartEndPoints(),l=o?o[0]:null,r=e.getNodes(),i=r.length;if(null!==l){const e=b(l.getNode());if(null!==e&&!E(e))return}if(null!==l&&(0===i||1===i&&"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 s=null,c=[];for(let o=0;o<i;o++){const l=r[o];E(l)?(le(e,c,c.length,t,n),c=[],s=l):null===s||null!==s&&F(l,s)?c.push(l):(le(e,c,c.length,t,n),c=[l])}le(e,c,c.length,t,n)}function le(e,t,n,o,l=null){if(0===t.length)return;const r=t[0],i=new Map,f=[],u=s(r)?r:r.getParentOrThrow();let g=u.isInline()?u.getParentOrThrow():u,a=!1;for(;null!==g;){const e=g.getPreviousSibling();if(null!==e){g=e,a=!0;break}if(g=g.getParentOrThrow(),E(g))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];s(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const h=new Set;for(let e=0;e<n;e++){const n=t[e];let l=n.getParent();if(null!==l&&l.isInline()&&(l=l.getParent()),null!==l&&B(n)&&!h.has(n.getKey())){const e=l.getKey();if(void 0===i.get(e)){const t=o();t.setFormat(l.getFormatType()),t.setIndent(l.getIndent()),f.push(t),i.set(e,t);const n=l.getChildren();t.splice(t.getChildrenSize(),0,n);for(const e of n)if(h.add(e.getKey()),s(e))for(const t of e.getChildrenKeys())h.add(t);ne(l)}}else if(d.has(n.getKey())){s(n)||z(179);const e=o();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),f.push(e),n.remove(!0)}}if(null!==l)for(let e=0;e<f.length;e++){const t=f[e];l.append(t)}let y=null;if(E(g))if(a)if(null!==l)g.insertAfter(l);else for(let e=f.length-1;e>=0;e--){const t=f[e];g.insertAfter(t)}else{const e=g,t=e.getFirstChild();if(s(t)&&(g=t),null===t)if(l)e.append(l);else for(let t=0;t<f.length;t++){const n=f[t];e.append(n),y=n}else if(null!==l)t.insertBefore(l);else for(let e=0;e<f.length;e++){const n=f[e];t.insertBefore(n),y=n}}else if(l)g.insertAfter(l);else for(let e=f.length-1;e>=0;e--){const t=f[e];g.insertAfter(t),y=t}const m=p();c(m)&&te(m.anchor)&&te(m.focus)?A(m.clone()):null!==y?y.selectEnd():e.dirty=!0}function re(e){const t=ie(e);return null!==t&&"vertical-rl"===t.writingMode}function ie(e){const t=e.anchor.getNode();return s(t)?M(t):D(t)}function se(e,t){let n=re(e)?!t:t;fe(e)&&(n=!n);const l=S(e.focus,n?"previous":"next");if(x(l))return!1;if(w(l)&&!P(l.origin)&&l.origin.isUnmergeable()){const e=l.getNodeAtCaret();if(o(e)&&!P(e))return!0}for(const e of k(l)){if(K(e))return!e.origin.isInline();if(!s(e.origin)){if(I(e.origin))return!0;break}}return!1}function ce(e,t,n,o){e.modify(t?"extend":"move",n,o)}function fe(e){const t=ie(e);return null!==t&&"rtl"===t.direction}function ue(e,t,n){const o=fe(e);let l;l=re(e)||o?!n:n,ce(e,t,l,"character")}function ge(e,t,n){const o=e.getStyle(),l=m(o);return null!==l&&l[t]||n}function ae(e,t,n=""){let l=null;const r=e.getNodes();let i,s;if(c(e)){if(e.isCollapsed()&&""!==e.style){const n=m(e.style);if(null!==n&&t in n)return n[t]}const{anchor:n,focus:l}=e,r=e.isBackward(),c=r?l.getNode():n.getNode(),f=r?n.getNode():l.getNode(),u=r?l.offset:n.offset,g=r?n.offset:l.offset;o(c)&&u===c.getTextContentSize()&&(i=c),0===g&&(s=f)}for(let e=0;e<r.length;e++){const c=r[e];if(o(c)&&!c.is(0===e?i:s)){const e=ge(c,t,n);if(null===l)l=e;else if(l!==e){l="";break}}}return null===l?n:l}const de=m,pe=V;export{W as $addNodeStyle,Y as $copyBlockFormatIndent,X as $ensureForwardRangeSelection,J as $forEachSelectedTextNode,M as $getComputedStyleForElement,D as $getComputedStyleForParent,ae as $getSelectionStyleValueForProperty,Z as $isAtEdgeOfElement,H as $isAtNodeEnd,fe as $isParentElementRTL,U as $isParentRTL,ce as $moveCaretSelection,ue as $moveCharacter,G as $patchStyleText,ee as $setBlocksType,se as $shouldOverrideDefaultCharacterSelection,j as $sliceSelectedTextNodeContent,V as $trimTextContentFromAnchor,oe as $wrapNodes,O as createDOMRange,L as createRectsFromDOMRange,$ as getCSSFromStyleObject,de as getStyleObjectFromCSS,pe as trimTextContentFromAnchor};
9
+ import{getRootOwnerDocument as e,$getEditor as t,$isRootNode as n,$isTextNode as o,getDOMTextNode as l,$getElementAndOffsetForPoint as r,$getSelection as i,$isElementNode as s,$isRangeSelection as c,$isTokenOrSegmented as f,$getTextPointCaretSliceForNode as u,$caretRangeFromSelection as g,$cloneWithPropertiesEphemeral as a,$getNodeByKey as d,$getPreviousSelection as p,$createTextNode as y,$splitTextPointCaretSlice as h,getStyleObjectFromCSS as m,$caretFromPoint as S,$isExtendableTextPointCaret as x,$findMatchingParent as C,INTERNAL_$isBlock as N,flipDirection as v,$getSlotHost as T,$isTextPointCaret as w,$isTabNode as k,$extendCaretToRange as P,$isChildCaret as K,$isDecoratorNode as I,$getSlotFrame as b,$isRootOrShadowRoot as E,$hasAncestor as F,$isLeafNode as _,$setSelection as B}from"lexical";export{$cloneWithProperties,$selectAll}from"lexical";function A(e,...t){throw function(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);return n.search=o.toString(),new 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.`)}(e,...t)}
10
+ /*@__INLINE__*/function z(e){return()=>{}}function R(e,t,n){const i=e.getElementByKey(t.getKey());if(null===i||o(t))return[l(i),n];const s=i.parentNode;return s&&"BR"===i.nodeName?[s,Array.from(s.childNodes).indexOf(i)]:e.read("latest",()=>r(e,t,n))}function O(t,n,o,l,r){const i=e(t.getRootElement()).createRange(),[s,c]=R(t,n,o),[f,u]=R(t,l,r);let g=u;if(null===s||null===f)return null;const a=s.firstChild;s===f&&null!=a&&"BR"===a.nodeName&&0===c&&0===g&&(g=1);try{i.setStart(s,c),i.setEnd(f,g)}catch(e){return null}return!i.collapsed||c===g&&n.is(l)||(i.setStart(f,g),i.setEnd(s,c)),i}function L(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),l=getComputedStyle(n),r=parseFloat(l.paddingLeft)+parseFloat(l.paddingRight),i=Array.from(t.getClientRects());let s,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=s&&s.top<=t.top&&s.bottom>=t.bottom&&s.left<=t.left&&s.right>=t.right,l=t.width+r===o.width;n||l?(i.splice(e--,1),c--):s=t}return i}function $(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function M(e){const n=t().getElementByKey(e.getKey());if(null===n)return null;const o=n.ownerDocument.defaultView;return null===o?null:o.getComputedStyle(n)}function D(e){const t=n(e)?e:e.getParent();return t&&M(t)}function U(e){const t=D(e);return null!==t&&"rtl"===t.direction}function j(e,t,n="self"){const o=e.getStartEndPoints();if(null!==o&&(o[0].key===t.__key||o[1].key===t.__key)&&t.isSelected(e)&&!f(t)){const[l,r]=e.isBackward()?[o[1],o[0]]:o,i=!c(e)||"element"!==l.type&&"element"!==r.type?void 0:u(g(e).getTextSlices(),t),[s,f]=i?i.getSliceIndices():[t.__key===l.key?l.offset:0,t.__key===r.key?r.offset:void 0],d=t.__text.slice(s,f);d!==t.__text&&("clone"===n&&(t=a(t)),t.__text=d)}return t}function H(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return s(t)||A(177),e.offset===t.getChildrenSize()}function V(e,t,l){let r=t.getNode(),i=l;if(s(r)){const e=r.getDescendantByIndex(t.offset);null!==e&&(r=e)}for(;i>0&&null!==r;){if(s(r)){const e=r.getLastDescendant();null!==e&&(r=e)}let l=r.getPreviousSibling(),f=0;if(null===l){let e=r.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){l=null;break}t=e.getPreviousSibling()}null!==e&&(f=e.isInline()?0:2,l=t)}let u=r.getTextContent();""===u&&s(r)&&!r.isInline()&&(u="\n\n");const g=u.length;if(!o(r)||i>=g){const e=r.getParent();r.remove(),null==e||0!==e.getChildrenSize()||n(e)||e.remove(),i-=g+f,r=l}else{const n=r.getKey(),l=e.read("latest",()=>{const e=d(n);return o(e)&&e.isSimpleText()?e.getTextContent():null}),s=g-i,f=u.slice(0,s);if(null!==l&&l!==u){const e=p();let t=r;if(r.isSimpleText())r.setTextContent(l);else{const e=y(l);r.replace(e),t=e}if(c(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n)}}else if(r.isSimpleText()){const e=t.key===n;let o=t.offset;o<i&&(o=g);const l=e?o-i:0,c=e?o:s;if(e&&0===l){const[e]=r.splitText(l,c);e.remove()}else{const[,e]=r.splitText(l,c);e.remove()}}else{const e=y(f);r.replace(e)}i=0}}}const W=/* @__PURE__ */z();function q(e,t){(c(e)?e.isCollapsed():o(e)||s(e))||A(280);const n=m(c(e)?e.style:o(e)?e.getStyle():e.getTextStyle()),l=$(Object.entries(t).reduce((t,[o,l])=>("function"==typeof l?t[o]=l(n[o],e):null===l?delete t[o]:t[o]=l,t),{...n}));c(e)||o(e)?e.setStyle(l):e.setTextStyle(l)}function G(e,t){const n=new Set;if(c(e)&&e.isCollapsed()){q(e,t);const o=e.anchor.getNode();s(o)&&o.isEmpty()&&(n.add(o.getKey()),q(o,t))}Q(e,e=>{q(e,t)});const o=e.getNodes();if(o.length>0)for(const e of o){if(!s(e)||!e.canBeEmpty()||0!==e.getChildrenSize())continue;const o=e.getKey();n.has(o)||(n.add(o),q(e,t))}}function J(e){Q(i(),e)}function Q(e,t){if(!e)return;const n=c(e)?g(e).getTextSlices():[];for(const l of e.getNodes()){if(!o(l)||!l.canHaveFormat())continue;const r=u(n,l);(r?0!==r.distance:0!==l.getTextContentSize())&&t(r&&!f(l)?h(r,c(e)?e:null):l)}c(e)&&"text"===e.anchor.type&&"text"===e.focus.type&&e.anchor.key===e.focus.key&&X(e)}function X(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 Y(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function Z(e,t,n){let o=S(e,n);if(x(o))return!1;for(;o;o=o.getParentCaret()){const e=o.getParentAtCaret();if(!e||o.getNodeAtCaret())return!1;if(t.is(e))return!0}return!1}function ee(e,t,n=Y){if(!e)return;const o=e.getStartEndPoints();let l=!1,r=null;const i=new Map;if(o){const[t,n]=o,c=C(t.getNode(),N);r=C(n.getNode(),N);const f=e.isBackward()?"previous":"next";l=s(r)&&!r.is(c)&&function(e,t,n){const o=e.getNode();return(!s(o)||!o.isEmpty())&&Z(e,t,n)}(n,r,v(f)),s(c)&&i.set(c.getKey(),c),s(r)&&!l&&i.set(r.getKey(),r)}for(const t of e.getNodes())if(s(t)&&N(t)){if(l&&t.is(r))continue;i.set(t.getKey(),t)}else if(!o){const e=C(t,N);s(e)&&i.set(e.getKey(),e)}for(const e of i.values()){if(null!==T(e))continue;const o=t();n(e,o),e.replace(o,!0)}}function te(e){return e.getNode().isAttached()}function ne(e){let t=e;for(;null!==t&&!E(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function oe(e,t,n=null){const o=e.getStartEndPoints(),l=o?o[0]:null,r=e.getNodes(),i=r.length;if(null!==l){const e=b(l.getNode());if(null!==e&&!E(e))return}if(null!==l&&(0===i||1===i&&"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 s=null,c=[];for(let o=0;o<i;o++){const l=r[o];E(l)?(le(e,c,c.length,t,n),c=[],s=l):null===s||null!==s&&F(l,s)?c.push(l):(le(e,c,c.length,t,n),c=[l])}le(e,c,c.length,t,n)}function le(e,t,n,o,l=null){if(0===t.length)return;const r=t[0],i=new Map,f=[],u=s(r)?r:r.getParentOrThrow();let g=u.isInline()?u.getParentOrThrow():u,a=!1;for(;null!==g;){const e=g.getPreviousSibling();if(null!==e){g=e,a=!0;break}if(g=g.getParentOrThrow(),E(g))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];s(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const y=new Set;for(let e=0;e<n;e++){const n=t[e];let l=n.getParent();if(null!==l&&l.isInline()&&(l=l.getParent()),null!==l&&_(n)&&!y.has(n.getKey())){const e=l.getKey();if(void 0===i.get(e)){const t=o();t.setFormat(l.getFormatType()),t.setIndent(l.getIndent()),f.push(t),i.set(e,t);const n=l.getChildren();t.splice(t.getChildrenSize(),0,n);for(const e of n)if(y.add(e.getKey()),s(e))for(const t of e.getChildrenKeys())y.add(t);ne(l)}}else if(d.has(n.getKey())){s(n)||A(179);const e=o();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),f.push(e),n.remove(!0)}}if(null!==l)for(let e=0;e<f.length;e++){const t=f[e];l.append(t)}let h=null;if(E(g))if(a)if(null!==l)g.insertAfter(l);else for(let e=f.length-1;e>=0;e--){const t=f[e];g.insertAfter(t)}else{const e=g,t=e.getFirstChild();if(s(t)&&(g=t),null===t)if(l)e.append(l);else for(let t=0;t<f.length;t++){const n=f[t];e.append(n),h=n}else if(null!==l)t.insertBefore(l);else for(let e=0;e<f.length;e++){const n=f[e];t.insertBefore(n),h=n}}else if(l)g.insertAfter(l);else for(let e=f.length-1;e>=0;e--){const t=f[e];g.insertAfter(t),h=t}const m=p();c(m)&&te(m.anchor)&&te(m.focus)?B(m.clone()):null!==h?h.selectEnd():e.dirty=!0}function re(e){const t=ie(e);return null!==t&&"vertical-rl"===t.writingMode}function ie(e){const t=e.anchor.getNode();return s(t)?M(t):D(t)}function se(e,t){let n=re(e)?!t:t;fe(e)&&(n=!n);const l=S(e.focus,n?"previous":"next");if(x(l))return!1;if(w(l)&&!k(l.origin)&&l.origin.isUnmergeable()){const e=l.getNodeAtCaret();if(o(e)&&!k(e))return!0}for(const e of P(l)){if(K(e))return!e.origin.isInline();if(!s(e.origin)){if(I(e.origin))return!0;break}}return!1}function ce(e,t,n,o){e.modify(t?"extend":"move",n,o)}function fe(e){const t=ie(e);return null!==t&&"rtl"===t.direction}function ue(e,t,n){const o=fe(e);let l;l=re(e)||o?!n:n,ce(e,t,l,"character")}function ge(e,t,n){const o=e.getStyle(),l=m(o);return null!==l&&l[t]||n}function ae(e,t,n=""){let l=null;const r=e.getNodes();let i,s;if(c(e)){if(e.isCollapsed()&&""!==e.style){const n=m(e.style);if(null!==n&&t in n)return n[t]}const{anchor:n,focus:l}=e,r=e.isBackward(),c=r?l.getNode():n.getNode(),f=r?n.getNode():l.getNode(),u=r?l.offset:n.offset,g=r?n.offset:l.offset;o(c)&&u===c.getTextContentSize()&&(i=c),0===g&&(s=f)}for(let e=0;e<r.length;e++){const c=r[e];if(o(c)&&!c.is(0===e?i:s)){const e=ge(c,t,n);if(null===l)l=e;else if(l!==e){l="";break}}}return null===l?n:l}const de=m,pe=V;export{W as $addNodeStyle,Y as $copyBlockFormatIndent,X as $ensureForwardRangeSelection,J as $forEachSelectedTextNode,M as $getComputedStyleForElement,D as $getComputedStyleForParent,ae as $getSelectionStyleValueForProperty,Z as $isAtEdgeOfElement,H as $isAtNodeEnd,fe as $isParentElementRTL,U as $isParentRTL,ce as $moveCaretSelection,ue as $moveCharacter,G as $patchStyleText,ee as $setBlocksType,se as $shouldOverrideDefaultCharacterSelection,j as $sliceSelectedTextNodeContent,V as $trimTextContentFromAnchor,oe as $wrapNodes,O as createDOMRange,L as createRectsFromDOMRange,$ as getCSSFromStyleObject,de as getStyleObjectFromCSS,pe as trimTextContentFromAnchor};
package/package.json CHANGED
@@ -9,12 +9,12 @@
9
9
  "selection"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "0.53.0",
12
+ "version": "0.53.1-nightly.20261030.0",
13
13
  "main": "./dist/LexicalSelection.js",
14
14
  "types": "./dist/typescript-too-old.d.ts",
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git+https://github.com/facebook/lexical.git",
17
+ "url": "git+https://github.com/meta/lexical.git",
18
18
  "directory": "packages/lexical-selection"
19
19
  },
20
20
  "module": "./dist/LexicalSelection.js",
@@ -30,8 +30,8 @@
30
30
  }
31
31
  },
32
32
  "dependencies": {
33
- "@lexical/internal": "0.53.0",
34
- "lexical": "0.53.0"
33
+ "@lexical/internal": "0.53.1-nightly.20261030.0",
34
+ "lexical": "0.53.1-nightly.20261030.0"
35
35
  },
36
36
  "files": [
37
37
  "dist",
@@ -48,8 +48,12 @@ export function $sliceSelectedTextNodeContent<T extends TextNode>(
48
48
  mutates: 'clone' | 'self' = 'self',
49
49
  ): T {
50
50
  const points = selection.getStartEndPoints();
51
+ // Only the node of a text point can be cut short; checking that first
52
+ // keeps a caller that slices every selected node from working out the
53
+ // selection for each of them.
51
54
  if (
52
55
  points !== null &&
56
+ (points[0].key === textNode.__key || points[1].key === textNode.__key) &&
53
57
  textNode.isSelected(selection) &&
54
58
  !$isTokenOrSegmented(textNode)
55
59
  ) {