Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/selection

Package Overview
Dependencies
Maintainers
6
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/selection - npm Package Compare versions

Comparing version 0.7.9 to 0.8.0

2

lexical-node.d.ts

@@ -14,2 +14,2 @@ /**

export declare function $addNodeStyle(node: TextNode): void;
export declare function $patchStyleText(selection: RangeSelection | GridSelection, patch: Record<string, string | null>): void;
export declare function $patchStyleText(selection: RangeSelection, patch: Record<string, string | null>): void;

@@ -349,2 +349,11 @@ /**

if (selection.isCollapsed()) {
const styles = getStyleObjectFromCSS(selection.style);
Object.entries(patch).forEach(([key, value]) => {
if (value !== null) {
styles[key] = value;
}
return styles;
});
const style = getCSSFromStyleObject(styles);
selection.setStyle(style);
return;

@@ -737,2 +746,19 @@ }

const endNode = isBackward ? focus.getNode() : anchor.getNode();
if (selection.style !== '') {
const css = selection.style;
const styleObject = getStyleObjectFromCSS(css);
let nodeStyleValue;
if (styleObject !== null) {
nodeStyleValue = styleObject[styleProperty] || defaultValue;
} else {
nodeStyleValue = defaultValue;
}
if (styleValue === null) {
styleValue = nodeStyleValue;
} else if (styleValue !== nodeStyleValue) {
// multiple text nodes are in the selection and they don't all
// have the same font size.
styleValue = '';
}
}
for (let i = 0; i < nodes.length; i++) {

@@ -739,0 +765,0 @@ const node = nodes[i];

@@ -7,23 +7,23 @@ /**

*/
'use strict';var l=require("lexical");let u=new Map;function v(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function x(a){let b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}function y(a){let b={};a=a.split(";");for(let c of a)if(""!==c){let [f,d]=c.split(/:([^]+)/);b[f.trim()]=d.trim()}return b}function z(a){let b=u.get(a);void 0===b&&(b=y(a),u.set(a,b));return b}
function A(a){let b="";for(let c in a)c&&(b+=`${c}: ${a[c]};`);return b}function B(a,b){var c=z(a.getStyle());b=Object.entries(b).reduce((f,[d,e])=>{null===e?delete f[d]:f[d]=e;return f},{...c});c=A(b);a.setStyle(c);u.set(c,b)}function C(a){for(;null!==a&&!l.$isRootOrShadowRoot(a);){let b=a.getLatest(),c=a.getParent();0===b.getChildrenSize()&&a.remove(!0);a=c}}
function D(a,b,c,f,d=null){if(0!==b.length){var e=b[0],k=new Map,g=[];e=l.$isElementNode(e)?e:e.getParentOrThrow();e.isInline()&&(e=e.getParentOrThrow());for(var h=!1;null!==e;){var p=e.getPreviousSibling();if(null!==p){e=p;h=!0;break}e=e.getParentOrThrow();if(l.$isRootOrShadowRoot(e))break}p=new Set;for(var q=0;q<c;q++){var m=b[q];l.$isElementNode(m)&&0===m.getChildrenSize()&&p.add(m.getKey())}var n=new Set;for(q=0;q<c;q++){m=b[q];var r=m.getParent();null!==r&&r.isInline()&&(r=r.getParent());if(null!==
r&&l.$isLeafNode(m)&&!n.has(m.getKey())){if(m=r.getKey(),void 0===k.get(m)){let t=f();t.setFormat(r.getFormatType());t.setIndent(r.getIndent());g.push(t);k.set(m,t);r.getChildren().forEach(w=>{t.append(w);n.add(w.getKey());l.$isElementNode(w)&&w.getChildrenKeys().forEach(G=>n.add(G))});C(r)}}else p.has(m.getKey())&&(r=f(),r.setFormat(m.getFormatType()),r.setIndent(m.getIndent()),g.push(r),m.remove(!0))}if(null!==d)for(b=0;b<g.length;b++)d.append(g[b]);b=null;if(l.$isRootOrShadowRoot(e))if(h)if(null!==
d)e.insertAfter(d);else for(d=g.length-1;0<=d;d--)e.insertAfter(g[d]);else if(h=e.getFirstChild(),l.$isElementNode(h)&&(e=h),null===h)if(d)e.append(d);else for(d=0;d<g.length;d++)h=g[d],e.append(h),b=h;else if(null!==d)h.insertBefore(d);else for(e=0;e<g.length;e++)d=g[e],h.insertBefore(d),b=d;else if(d)e.insertAfter(d);else for(d=g.length-1;0<=d;d--)h=g[d],e.insertAfter(h),b=h;g=l.$getPreviousSelection();l.$isRangeSelection(g)&&g.anchor.getNode().isAttached()&&g.focus.getNode().isAttached()?l.$setSelection(g.clone()):
null!==b?b.selectEnd():a.dirty=!0}}function E(a,b,c,f){a.modify(b?"extend":"move",c,f)}function F(a){a=a.anchor.getNode();return"rtl"===(l.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}exports.$addNodeStyle=function(a){a=a.getStyle();let b=y(a);u.set(a,b)};
'use strict';var l=require("lexical");let v=new Map;function w(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function x(a){let b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}function y(a){let b={};a=a.split(";");for(let c of a)if(""!==c){let [e,d]=c.split(/:([^]+)/);b[e.trim()]=d.trim()}return b}function A(a){let b=v.get(a);void 0===b&&(b=y(a),v.set(a,b));return b}
function B(a){let b="";for(let c in a)c&&(b+=`${c}: ${a[c]};`);return b}function C(a,b){var c=A(a.getStyle());b=Object.entries(b).reduce((e,[d,f])=>{null===f?delete e[d]:e[d]=f;return e},{...c});c=B(b);a.setStyle(c);v.set(c,b)}function D(a){for(;null!==a&&!l.$isRootOrShadowRoot(a);){let b=a.getLatest(),c=a.getParent();0===b.getChildrenSize()&&a.remove(!0);a=c}}
function E(a,b,c,e,d=null){if(0!==b.length){var f=b[0],h=new Map,g=[];f=l.$isElementNode(f)?f:f.getParentOrThrow();f.isInline()&&(f=f.getParentOrThrow());for(var k=!1;null!==f;){var n=f.getPreviousSibling();if(null!==n){f=n;k=!0;break}f=f.getParentOrThrow();if(l.$isRootOrShadowRoot(f))break}n=new Set;for(var q=0;q<c;q++){var p=b[q];l.$isElementNode(p)&&0===p.getChildrenSize()&&n.add(p.getKey())}var m=new Set;for(q=0;q<c;q++){p=b[q];var r=p.getParent();null!==r&&r.isInline()&&(r=r.getParent());if(null!==
r&&l.$isLeafNode(p)&&!m.has(p.getKey())){if(p=r.getKey(),void 0===h.get(p)){let u=e();u.setFormat(r.getFormatType());u.setIndent(r.getIndent());g.push(u);h.set(p,u);r.getChildren().forEach(t=>{u.append(t);m.add(t.getKey());l.$isElementNode(t)&&t.getChildrenKeys().forEach(z=>m.add(z))});D(r)}}else n.has(p.getKey())&&(r=e(),r.setFormat(p.getFormatType()),r.setIndent(p.getIndent()),g.push(r),p.remove(!0))}if(null!==d)for(b=0;b<g.length;b++)d.append(g[b]);b=null;if(l.$isRootOrShadowRoot(f))if(k)if(null!==
d)f.insertAfter(d);else for(d=g.length-1;0<=d;d--)f.insertAfter(g[d]);else if(k=f.getFirstChild(),l.$isElementNode(k)&&(f=k),null===k)if(d)f.append(d);else for(d=0;d<g.length;d++)k=g[d],f.append(k),b=k;else if(null!==d)k.insertBefore(d);else for(f=0;f<g.length;f++)d=g[f],k.insertBefore(d),b=d;else if(d)f.insertAfter(d);else for(d=g.length-1;0<=d;d--)k=g[d],f.insertAfter(k),b=k;g=l.$getPreviousSelection();l.$isRangeSelection(g)&&g.anchor.getNode().isAttached()&&g.focus.getNode().isAttached()?l.$setSelection(g.clone()):
null!==b?b.selectEnd():a.dirty=!0}}function F(a,b,c,e){a.modify(b?"extend":"move",c,e)}function H(a){a=a.anchor.getNode();return"rtl"===(l.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}exports.$addNodeStyle=function(a){a=a.getStyle();let b=y(a);v.set(a,b)};
exports.$cloneWithProperties=function(a){a=a.getLatest();let b=a.constructor.clone(a);b.__parent=a.__parent;b.__next=a.__next;b.__prev=a.__prev;if(l.$isElementNode(a)&&l.$isElementNode(b))return b.__first=a.__first,b.__last=a.__last,b.__size=a.__size,b.__format=a.__format,b.__indent=a.__indent,b.__dir=a.__dir,b;l.$isTextNode(a)&&l.$isTextNode(b)&&(b.__format=a.__format,b.__style=a.__style,b.__mode=a.__mode,b.__detail=a.__detail);return b};
exports.$getSelectionStyleValueForProperty=function(a,b,c=""){let f=null,d=a.getNodes();var e=a.anchor,k=a.focus,g=a.isBackward();a=g?k.offset:e.offset;e=g?k.getNode():e.getNode();for(k=0;k<d.length;k++){var h=d[k];if((0===k||0!==a||!h.is(e))&&l.$isTextNode(h)){g=b;var p=c;h=h.getStyle();h=z(h);g=null!==h?h[g]||p:p;if(null===f)f=g;else if(f!==g){f="";break}}}return null===f?c:f};exports.$isAtNodeEnd=function(a){return"text"===a.type?a.offset===a.getNode().getTextContentSize():a.offset===a.getNode().getChildrenSize()};
exports.$isParentElementRTL=F;exports.$moveCaretSelection=E;exports.$moveCharacter=function(a,b,c){let f=F(a);E(a,b,c?!f:f,"character")};
exports.$patchStyleText=function(a,b){var c=a.getNodes();let f=c.length-1,d=c[0],e=c[f];if(!a.isCollapsed()){var k=a.anchor,g=a.focus,h=d.getTextContent().length,p=g.offset,q=k.offset,m=k.isBefore(g),n=m?q:p;a=m?p:q;var r=m?k.type:g.type,t=m?g.type:k.type;k=m?g.key:k.key;l.$isTextNode(d)&&n===h&&(g=d.getNextSibling(),l.$isTextNode(g)&&(n=q=0,d=g));if(d.is(e))l.$isTextNode(d)&&(n="element"===r?0:q>p?p:q,a="element"===t?h:q>p?q:p,n!==a&&(0===n&&a===h?(B(d,b),d.select(n,a)):(c=d.splitText(n,a),c=0===
n?c[0]:c[1],B(c,b),c.select(0,a-n))));else for(l.$isTextNode(d)&&n<d.getTextContentSize()&&(0!==n&&(d=d.splitText(n)[1]),B(d,b)),l.$isTextNode(e)&&(n=e.getTextContent().length,e.__key!==k&&0!==a&&(a=n),a!==n&&([e]=e.splitText(a)),0!==a&&B(e,b)),a=1;a<f;a++)n=c[a],h=n.getKey(),l.$isTextNode(n)&&h!==d.getKey()&&h!==e.getKey()&&!n.isToken()&&B(n,b)}};
exports.$selectAll=function(a){let b=a.anchor;a=a.focus;var c=b.getNode().getTopLevelElementOrThrow().getParentOrThrow();let f=c.getFirstDescendant();c=c.getLastDescendant();let d="element",e="element",k=0;l.$isTextNode(f)?d="text":l.$isElementNode(f)||null===f||(f=f.getParentOrThrow());l.$isTextNode(c)?(e="text",k=c.getTextContentSize()):l.$isElementNode(c)||null===c||(c=c.getParentOrThrow());f&&c&&(b.set(f.getKey(),0,d),a.set(c.getKey(),k,e))};
exports.$setBlocksType_experimental=function(a,b){if("root"===a.anchor.key){b=b();var c=l.$getRoot();(a=c.getFirstChild())?a.replace(b,!0):c.append(b)}else for(c=a.getNodes(),"text"===a.anchor.type&&(a=a.anchor.getNode().getParent(),a=a.isInline()?a.getParent():a,-1===c.indexOf(a)&&c.push(a)),a=0;a<c.length;a++){let d=c[a];var f=d;!l.$isElementNode(f)||l.$isRootOrShadowRoot(f)||f.isInline()||(f=b(),f.setFormat(d.getFormatType()),f.setIndent(d.getIndent()),d.replace(f,!0))}};
exports.$getSelectionStyleValueForProperty=function(a,b,c=""){let e=null,d=a.getNodes();var f=a.anchor,h=a.focus,g=a.isBackward();let k=g?h.offset:f.offset;f=g?h.getNode():f.getNode();""!==a.style&&(a=A(a.style),a=null!==a?a[b]||c:c,null===e?e=a:e!==a&&(e=""));for(a=0;a<d.length;a++){var n=d[a];if((0===a||0!==k||!n.is(f))&&l.$isTextNode(n))if(h=b,g=c,n=n.getStyle(),n=A(n),h=null!==n?n[h]||g:g,null===e)e=h;else if(e!==h){e="";break}}return null===e?c:e};
exports.$isAtNodeEnd=function(a){return"text"===a.type?a.offset===a.getNode().getTextContentSize():a.offset===a.getNode().getChildrenSize()};exports.$isParentElementRTL=H;exports.$moveCaretSelection=F;exports.$moveCharacter=function(a,b,c){let e=H(a);F(a,b,c?!e:e,"character")};
exports.$patchStyleText=function(a,b){var c=a.getNodes();let e=c.length-1,d=c[0],f=c[e];if(a.isCollapsed()){let t=A(a.style);Object.entries(b).forEach(([z,G])=>{null!==G&&(t[z]=G);return t});b=B(t);a.setStyle(b)}else{var h=a.anchor,g=a.focus,k=d.getTextContent().length,n=g.offset,q=h.offset,p=h.isBefore(g),m=p?q:n;a=p?n:q;var r=p?h.type:g.type,u=p?g.type:h.type;h=p?g.key:h.key;l.$isTextNode(d)&&m===k&&(g=d.getNextSibling(),l.$isTextNode(g)&&(m=q=0,d=g));if(d.is(f))l.$isTextNode(d)&&(m="element"===
r?0:q>n?n:q,a="element"===u?k:q>n?q:n,m!==a&&(0===m&&a===k?(C(d,b),d.select(m,a)):(c=d.splitText(m,a),c=0===m?c[0]:c[1],C(c,b),c.select(0,a-m))));else for(l.$isTextNode(d)&&m<d.getTextContentSize()&&(0!==m&&(d=d.splitText(m)[1],m=0),C(d,b)),l.$isTextNode(f)&&(m=f.getTextContent().length,f.__key!==h&&0!==a&&(a=m),a!==m&&([f]=f.splitText(a)),0!==a&&C(f,b)),a=1;a<e;a++)m=c[a],k=m.getKey(),l.$isTextNode(m)&&k!==d.getKey()&&k!==f.getKey()&&!m.isToken()&&C(m,b)}};
exports.$selectAll=function(a){let b=a.anchor;a=a.focus;var c=b.getNode().getTopLevelElementOrThrow().getParentOrThrow();let e=c.getFirstDescendant();c=c.getLastDescendant();let d="element",f="element",h=0;l.$isTextNode(e)?d="text":l.$isElementNode(e)||null===e||(e=e.getParentOrThrow());l.$isTextNode(c)?(f="text",h=c.getTextContentSize()):l.$isElementNode(c)||null===c||(c=c.getParentOrThrow());e&&c&&(b.set(e.getKey(),0,d),a.set(c.getKey(),h,f))};
exports.$setBlocksType_experimental=function(a,b){if("root"===a.anchor.key){b=b();var c=l.$getRoot();(a=c.getFirstChild())?a.replace(b,!0):c.append(b)}else for(c=a.getNodes(),"text"===a.anchor.type&&(a=a.anchor.getNode().getParent(),a=a.isInline()?a.getParent():a,-1===c.indexOf(a)&&c.push(a)),a=0;a<c.length;a++){let d=c[a];var e=d;!l.$isElementNode(e)||l.$isRootOrShadowRoot(e)||e.isInline()||(e=b(),e.setFormat(d.getFormatType()),e.setIndent(d.getIndent()),d.replace(e,!0))}};
exports.$shouldOverrideDefaultCharacterSelection=function(a,b){a=l.$getAdjacentNode(a.focus,b);return l.$isDecoratorNode(a)&&!a.isIsolated()||l.$isElementNode(a)&&!a.isInline()&&!a.canBeEmpty()};
exports.$sliceSelectedTextNodeContent=function(a,b){if(b.isSelected()&&!b.isSegmented()&&!b.isToken()&&(l.$isRangeSelection(a)||l.DEPRECATED_$isGridSelection(a))){var c=a.anchor.getNode(),f=a.focus.getNode(),d=b.is(c),e=b.is(f);if(d||e){d=a.isBackward();let [k,g]=a.getCharacterOffsets();a=c.is(f);e=b.is(d?f:c);f=b.is(d?c:f);c=0;let h=void 0;a?(c=k>g?g:k,h=k>g?k:g):e?(c=d?g:k,h=void 0):f&&(d=d?k:g,c=0,h=d);b.__text=b.__text.slice(c,h)}}return b};
exports.$wrapNodes=function(a,b,c=null){var f=a.getNodes();let d=f.length;var e=a.anchor;if(0===d||1===d&&"element"===e.type&&0===e.getNode().getChildrenSize()){a="text"===e.type?e.getNode().getParentOrThrow():e.getNode();f=a.getChildren();let g=b();g.setFormat(a.getFormatType());g.setIndent(a.getIndent());f.forEach(h=>g.append(h));c&&(g=c.append(g));a.replace(g)}else{e=null;var k=[];for(let g=0;g<d;g++){let h=f[g];l.$isRootOrShadowRoot(h)?(D(a,k,k.length,b,c),k=[],e=h):null===e||null!==e&&l.$hasAncestor(h,
e)?k.push(h):(D(a,k,k.length,b,c),k=[h])}D(a,k,k.length,b,c)}};
exports.createDOMRange=function(a,b,c,f,d){let e=b.getKey(),k=f.getKey(),g=document.createRange(),h=a.getElementByKey(e);a=a.getElementByKey(k);l.$isTextNode(b)&&(h=v(h));l.$isTextNode(f)&&(a=v(a));if(void 0===b||void 0===f||null===h||null===a)return null;"BR"===h.nodeName&&([h,c]=x(h));"BR"===a.nodeName&&([a,d]=x(a));b=h.firstChild;h===a&&null!=b&&"BR"===b.nodeName&&0===c&&0===d&&(d=1);try{g.setStart(h,c),g.setEnd(a,d)}catch(p){return null}!g.collapsed||c===d&&e===k||(g.setStart(a,d),g.setEnd(h,
c));return g};exports.createRectsFromDOMRange=function(a,b){var c=a.getRootElement();if(null===c)return[];a=c.getBoundingClientRect();c=getComputedStyle(c);c=parseFloat(c.paddingLeft)+parseFloat(c.paddingRight);b=Array.from(b.getClientRects());let f=b.length,d;for(let e=0;e<f;e++){let k=b[e],g=k.width+c===a.width;d&&d.top===k.top&&d.left===k.left&&d.width===k.width&&d.height===k.height||g?(b.splice(e--,1),f--):d=k}return b};exports.getStyleObjectFromCSS=z;
exports.trimTextContentFromAnchor=function(a,b,c){let f=b.getNode();if(l.$isElementNode(f)){var d=f.getDescendantByIndex(b.offset);null!==d&&(f=d)}for(;0<c&&null!==f;){var e=f.getPreviousSibling(),k=0;if(null===e){d=f.getParentOrThrow();for(var g=d.getPreviousSibling();null===g;){d=d.getParent();if(null===d){e=null;break}g=d.getPreviousSibling()}null!==d&&(k=d.isInline()?0:2,e=l.$isElementNode(g)?g.getLastDescendant():g)}let h=f.getTextContent();""===h&&l.$isElementNode(f)&&!f.isInline()&&(h="\n\n");
d=h.length;g=d-c;let p=h.slice(0,g);if(!l.$isTextNode(f)||c>=d)g=f.getParent(),f.remove(),null!=g&&0===g.getChildrenSize()&&g.remove(),c-=d+k,f=e;else{let q=f.getKey();e=a.getEditorState().read(()=>{const m=l.$getNodeByKey(q);return l.$isTextNode(m)&&m.isSimpleText()?m.getTextContent():null});null!==e&&e!==h?(c=l.$getPreviousSelection(),d=f,f.isSimpleText()?f.setTextContent(e):(d=l.$createTextNode(e),f.replace(d)),l.$isRangeSelection(c)&&c.isCollapsed()&&(c=c.anchor.offset,d.select(c,c))):f.isSimpleText()?
(e=b.key===q,k=b.offset,k<c&&(k=d),c=e?k-c:0,d=e?k:g,e&&0===c?([c]=f.splitText(c,d),c.remove()):([,c]=f.splitText(c,d),c.remove())):(c=l.$createTextNode(p),f.replace(c));c=0}}}
exports.$sliceSelectedTextNodeContent=function(a,b){if(b.isSelected()&&!b.isSegmented()&&!b.isToken()&&(l.$isRangeSelection(a)||l.DEPRECATED_$isGridSelection(a))){var c=a.anchor.getNode(),e=a.focus.getNode(),d=b.is(c),f=b.is(e);if(d||f){d=a.isBackward();let [h,g]=a.getCharacterOffsets();a=c.is(e);f=b.is(d?e:c);e=b.is(d?c:e);c=0;let k=void 0;a?(c=h>g?g:h,k=h>g?h:g):f?(c=d?g:h,k=void 0):e&&(d=d?h:g,c=0,k=d);b.__text=b.__text.slice(c,k)}}return b};
exports.$wrapNodes=function(a,b,c=null){var e=a.getNodes();let d=e.length;var f=a.anchor;if(0===d||1===d&&"element"===f.type&&0===f.getNode().getChildrenSize()){a="text"===f.type?f.getNode().getParentOrThrow():f.getNode();e=a.getChildren();let g=b();g.setFormat(a.getFormatType());g.setIndent(a.getIndent());e.forEach(k=>g.append(k));c&&(g=c.append(g));a.replace(g)}else{f=null;var h=[];for(let g=0;g<d;g++){let k=e[g];l.$isRootOrShadowRoot(k)?(E(a,h,h.length,b,c),h=[],f=k):null===f||null!==f&&l.$hasAncestor(k,
f)?h.push(k):(E(a,h,h.length,b,c),h=[k])}E(a,h,h.length,b,c)}};
exports.createDOMRange=function(a,b,c,e,d){let f=b.getKey(),h=e.getKey(),g=document.createRange(),k=a.getElementByKey(f);a=a.getElementByKey(h);l.$isTextNode(b)&&(k=w(k));l.$isTextNode(e)&&(a=w(a));if(void 0===b||void 0===e||null===k||null===a)return null;"BR"===k.nodeName&&([k,c]=x(k));"BR"===a.nodeName&&([a,d]=x(a));b=k.firstChild;k===a&&null!=b&&"BR"===b.nodeName&&0===c&&0===d&&(d=1);try{g.setStart(k,c),g.setEnd(a,d)}catch(n){return null}!g.collapsed||c===d&&f===h||(g.setStart(a,d),g.setEnd(k,
c));return g};exports.createRectsFromDOMRange=function(a,b){var c=a.getRootElement();if(null===c)return[];a=c.getBoundingClientRect();c=getComputedStyle(c);c=parseFloat(c.paddingLeft)+parseFloat(c.paddingRight);b=Array.from(b.getClientRects());let e=b.length,d;for(let f=0;f<e;f++){let h=b[f],g=h.width+c===a.width;d&&d.top===h.top&&d.left===h.left&&d.width===h.width&&d.height===h.height||g?(b.splice(f--,1),e--):d=h}return b};exports.getStyleObjectFromCSS=A;
exports.trimTextContentFromAnchor=function(a,b,c){let e=b.getNode();if(l.$isElementNode(e)){var d=e.getDescendantByIndex(b.offset);null!==d&&(e=d)}for(;0<c&&null!==e;){var f=e.getPreviousSibling(),h=0;if(null===f){d=e.getParentOrThrow();for(var g=d.getPreviousSibling();null===g;){d=d.getParent();if(null===d){f=null;break}g=d.getPreviousSibling()}null!==d&&(h=d.isInline()?0:2,f=l.$isElementNode(g)?g.getLastDescendant():g)}let k=e.getTextContent();""===k&&l.$isElementNode(e)&&!e.isInline()&&(k="\n\n");
d=k.length;g=d-c;let n=k.slice(0,g);if(!l.$isTextNode(e)||c>=d)g=e.getParent(),e.remove(),null!=g&&0===g.getChildrenSize()&&g.remove(),c-=d+h,e=f;else{let q=e.getKey();f=a.getEditorState().read(()=>{const p=l.$getNodeByKey(q);return l.$isTextNode(p)&&p.isSimpleText()?p.getTextContent():null});null!==f&&f!==k?(c=l.$getPreviousSelection(),d=e,e.isSimpleText()?e.setTextContent(f):(d=l.$createTextNode(f),e.replace(d)),l.$isRangeSelection(c)&&c.isCollapsed()&&(c=c.anchor.offset,d.select(c,c))):e.isSimpleText()?
(f=b.key===q,h=b.offset,h<c&&(h=d),c=f?h-c:0,d=f?h:g,f&&0===c?([c]=e.splitText(c,d),c.remove()):([,c]=e.splitText(c,d),c.remove())):(c=l.$createTextNode(n),e.replace(c));c=0}}}

@@ -12,6 +12,6 @@ {

"license": "MIT",
"version": "0.7.9",
"version": "0.8.0",
"main": "LexicalSelection.js",
"peerDependencies": {
"lexical": "0.7.9"
"lexical": "0.8.0"
},

@@ -18,0 +18,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc