@lexical/selection
Advanced tools
Comparing version 0.25.1-nightly.20250228.0 to 0.26.0
@@ -565,6 +565,6 @@ /** | ||
if (key === newSelection.anchor.key) { | ||
newSelection.anchor.key = element.getKey(); | ||
newSelection.anchor.set(element.getKey(), newSelection.anchor.offset, newSelection.anchor.type); | ||
} | ||
if (key === newSelection.focus.key) { | ||
newSelection.focus.key = element.getKey(); | ||
newSelection.focus.set(element.getKey(), newSelection.focus.offset, newSelection.focus.type); | ||
} | ||
@@ -571,0 +571,0 @@ } |
@@ -9,2 +9,2 @@ /** | ||
"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; | ||
"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.set(s.getKey(),r.anchor.offset,r.anchor.type),e===r.focus.key&&r.focus.set(s.getKey(),r.focus.offset,r.focus.type))}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; |
@@ -12,3 +12,3 @@ { | ||
"license": "MIT", | ||
"version": "0.25.1-nightly.20250228.0", | ||
"version": "0.26.0", | ||
"main": "LexicalSelection.js", | ||
@@ -41,4 +41,4 @@ "types": "index.d.ts", | ||
"dependencies": { | ||
"lexical": "0.25.1-nightly.20250228.0" | ||
"lexical": "0.26.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
111457
2150
+ Addedlexical@0.26.0(transitive)
- Removedlexical@0.25.1-nightly.20250228.0(transitive)
Updatedlexical@0.26.0