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
192
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.3.3 to 0.3.4

index.d.ts

33

LexicalSelection.dev.js

@@ -111,3 +111,3 @@ /**

function $cloneContents(selection) {
const clone = $cloneContentsImpl(selection); // @ts-ignore
const clone = $cloneContentsImpl(selection);

@@ -232,2 +232,14 @@ {

function getStyleObjectFromRawCSS(css) {
const styleObject = {};
const styles = css.split(';').slice(0, -1);
for (const style of styles) {
const patch = style.split(': ');
styleObject[patch[0]] = patch[1];
}
return styleObject;
}
function getCSSFromStyleObject(styles) {

@@ -245,2 +257,8 @@ let css = '';

function $addNodeStyle(node) {
const CSSText = node.getStyle();
const styles = getStyleObjectFromRawCSS(CSSText);
cssToStyles.set(CSSText, styles);
}
function $patchNodeStyle(node, patch) {

@@ -724,7 +742,2 @@ const prevStyles = getStyleObjectFromCSS(node.getStyle());

}
function doesContainGrapheme(str) {
return /[\uD800-\uDBFF][\uDC00-\uDFFF]/g.test(str);
}
function trimTextContentFromAnchor(editor, anchor, delCount) {

@@ -783,8 +796,5 @@ // Work from the current selection anchor point

const offset = textNodeSize - remaining;
const slicedText = text.slice(0, offset); // Sometimes the text we're putting in might be a partial grapheme.
// So we just remove the entire thing, rather than show a partial unicode grapheme.
const slicedText = text.slice(0, offset);
const containsPartialGraphemeHeuristic = doesContainGrapheme(text) && !doesContainGrapheme(slicedText);
if (!lexical.$isTextNode(currentNode) || remaining >= textNodeSize || containsPartialGraphemeHeuristic) {
if (!lexical.$isTextNode(currentNode) || remaining >= textNodeSize) {
const parent = currentNode.getParent();

@@ -894,2 +904,3 @@ currentNode.remove();

exports.$addNodeStyle = $addNodeStyle;
exports.$cloneContents = $cloneContents;

@@ -896,0 +907,0 @@ exports.$cloneWithProperties = $cloneWithProperties;

@@ -8,22 +8,22 @@ /**

'use strict';var l=require("lexical");let t=new Map;function u(a){a=a.getLatest();let c=a.constructor.clone(a);c.__parent=a.__parent;l.$isElementNode(a)&&l.$isElementNode(c)?(c.__children=Array.from(a.__children),c.__format=a.__format,c.__indent=a.__indent,c.__dir=a.__dir):l.$isTextNode(a)&&l.$isTextNode(c)&&(c.__format=a.__format,c.__style=a.__style,c.__mode=a.__mode,c.__detail=a.__detail);return c}
function w(a,c,b,e,f,g){for(var d=c;null!==a;){for(c=a.getParent();null!==c&&c.excludeFromCopy("clone");)c=c.getParent();if(null===c)break;if(!l.$isElementNode(a)||!a.excludeFromCopy("clone")){let k=a.getKey(),h=g.get(k),m=void 0===h;m&&(h=u(a),g.set(k,h));!l.$isTextNode(h)||h.isSegmented()||h.isToken()?l.$isElementNode(h)&&(h.__children=h.__children.slice(e?d:0,e?void 0:(d||0)+1)):h.__text=h.__text.slice(e?d:0,e?b:d);if(l.$isRootNode(c)){m&&f.push(k);break}}d=g.get(c.getKey());d=l.$isElementNode(d)?
d.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}}
function x(a){if(l.$isRangeSelection(a)){var c=a.anchor,b=a.focus;let [h,m]=a.getCharacterOffsets();a=a.getNodes();if(0===a.length)return{nodeMap:[],range:[]};let n=a.length;var e=a[0],f=e.getParent();if(null!==f&&(!f.canBeEmpty()||l.$isRootNode(f))){var g=f.__children;if(g.length===n){var d=!0;for(var k=0;k<g.length;k++)if(g[k]!==a[k].__key){d=!1;break}d&&(n++,a.push(f))}}f=a[n-1];c=c.isBefore(b);b=new Map;g=[];d=l.$isTextNode(e)&&1===n;w(e,c?h:m,d?c?m:h:void 0,!0,g,b);for(e=0;e<n;e++){k=a[e];let q=
k.getKey();if(!(b.has(q)||l.$isElementNode(k)&&k.excludeFromCopy("clone"))){let p=u(k);l.$isRootNode(k.getParent())&&g.push(k.getKey());"root"!==q&&b.set(q,p)}}w(f,d?void 0:c?m:h,void 0,!1,g,b);return{nodeMap:Array.from(b.entries()),range:g}}if(l.$isGridSelection(a))return{nodeMap:a.getNodes().map(h=>{const m=h.getKey();h=u(h);return[m,h]}),range:[a.gridKey]};throw Error("Minified Lexical error #1; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
}function y(a){return t.get(a)||null}function z(a,c){var b=y(a.getStyle());c=b?{...b,...c}:c;b="";for(e in c)e&&(b+=`${e}: ${c[e]};`);var e=b;a.setStyle(e);t.set(e,c)}function A(a,c,b,e){a.modify(c?"extend":"move",b,e)}function B(a){a=a.anchor.getNode();return"rtl"===(l.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function C(a){for(;null!==a&&!l.$isRootNode(a);){let c=a.getLatest(),b=a.getParent();0===c.__children.length&&a.remove(!0);a=b}}
function D(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function E(a){let c=a.parentNode;if(null==c)throw Error("Should never happen");return[c,Array.from(c.childNodes).indexOf(a)]}function F(a){return/[\uD800-\uDBFF][\uDC00-\uDFFF]/g.test(a)}exports.$cloneContents=function(a){return x(a)};exports.$cloneWithProperties=u;
exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let e=null,f=a.getNodes();var g=a.anchor,d=a.focus,k=a.isBackward();a=k?d.offset:g.offset;g=k?d.getNode():g.getNode();for(d=0;d<f.length;d++){var h=f[d];if((0===d||0!==a||!h.is(g))&&l.$isTextNode(h)){k=c;var m=b;h=h.getStyle();h=y(h);k=null!==h?h[k]||m:m;if(null===e)e=k;else if(e!==k){e="";break}}}return null===e?b:e};exports.$isAtNodeEnd=function(a){return"text"===a.type?a.offset===a.getNode().getTextContentSize():a.offset===a.getNode().getChildrenSize()};
exports.$isParentElementRTL=B;exports.$moveCaretSelection=A;exports.$moveCharacter=function(a,c,b){let e=B(a);A(a,c,b?!e:e,"character")};
exports.$patchStyleText=function(a,c){var b=a.getNodes();let e=b.length-1,f=b[0],g=b[e];if(!a.isCollapsed()){var d=a.anchor,k=a.focus;a=f.getTextContent().length;var h=k.offset,m=d.offset;d=(k=d.isBefore(k))?m:h;k=k?h:m;if(d===f.getTextContentSize()){let n=f.getNextSibling();l.$isTextNode(n)&&(d=m=0,f=n)}if(f.is(g))l.$isTextNode(f)&&(d=m>h?h:m,k=m>h?m:h,d!==k&&(0===d&&k===a?(z(f,c),f.select(d,k)):(b=f.splitText(d,k),b=0===d?b[0]:b[1],z(b,c),b.select(0,k-d))));else for(l.$isTextNode(f)&&(0!==d&&(f=
f.splitText(d)[1]),z(f,c)),l.$isTextNode(g)&&(a=g.getTextContent().length,k!==a&&([g]=g.splitText(k)),0!==k&&z(g,c)),a=1;a<e;a++)h=b[a],m=h.getKey(),l.$isTextNode(h)&&m!==f.getKey()&&m!==g.getKey()&&!h.isToken()&&z(h,c)}};
exports.$selectAll=function(a){let c=a.anchor;a=a.focus;var b=c.getNode().getTopLevelElementOrThrow().getParentOrThrow();let e=b.getFirstDescendant();b=b.getLastDescendant();let f="element",g="element",d=0;l.$isTextNode(e)?f="text":l.$isElementNode(e)||null===e||(e=e.getParentOrThrow());l.$isTextNode(b)?(g="text",d=b.getTextContentSize()):l.$isElementNode(b)||null===b||(b=b.getParentOrThrow());e&&b&&(c.set(e.getKey(),0,f),a.set(b.getKey(),d,g))};
function w(a,c,b,d,f,g){for(var e=c;null!==a;){for(c=a.getParent();null!==c&&c.excludeFromCopy("clone");)c=c.getParent();if(null===c)break;if(!l.$isElementNode(a)||!a.excludeFromCopy("clone")){let h=a.getKey(),k=g.get(h),m=void 0===k;m&&(k=u(a),g.set(h,k));!l.$isTextNode(k)||k.isSegmented()||k.isToken()?l.$isElementNode(k)&&(k.__children=k.__children.slice(d?e:0,d?void 0:(e||0)+1)):k.__text=k.__text.slice(d?e:0,d?b:e);if(l.$isRootNode(c)){m&&f.push(h);break}}e=g.get(c.getKey());e=l.$isElementNode(e)?
e.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}}
function x(a){if(l.$isRangeSelection(a)){var c=a.anchor,b=a.focus;let [k,m]=a.getCharacterOffsets();a=a.getNodes();if(0===a.length)return{nodeMap:[],range:[]};let n=a.length;var d=a[0],f=d.getParent();if(null!==f&&(!f.canBeEmpty()||l.$isRootNode(f))){var g=f.__children;if(g.length===n){var e=!0;for(var h=0;h<g.length;h++)if(g[h]!==a[h].__key){e=!1;break}e&&(n++,a.push(f))}}f=a[n-1];c=c.isBefore(b);b=new Map;g=[];e=l.$isTextNode(d)&&1===n;w(d,c?k:m,e?c?m:k:void 0,!0,g,b);for(d=0;d<n;d++){h=a[d];let p=
h.getKey();if(!(b.has(p)||l.$isElementNode(h)&&h.excludeFromCopy("clone"))){let q=u(h);l.$isRootNode(h.getParent())&&g.push(h.getKey());"root"!==p&&b.set(p,q)}}w(f,e?void 0:c?m:k,void 0,!1,g,b);return{nodeMap:Array.from(b.entries()),range:g}}if(l.$isGridSelection(a))return{nodeMap:a.getNodes().map(k=>{const m=k.getKey();k=u(k);return[m,k]}),range:[a.gridKey]};throw Error("Minified Lexical error #1; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
}function y(a){return t.get(a)||null}function z(a,c){var b=y(a.getStyle());c=b?{...b,...c}:c;b="";for(d in c)d&&(b+=`${d}: ${c[d]};`);var d=b;a.setStyle(d);t.set(d,c)}function A(a,c,b,d){a.modify(c?"extend":"move",b,d)}function B(a){a=a.anchor.getNode();return"rtl"===(l.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function C(a){for(;null!==a&&!l.$isRootNode(a);){let c=a.getLatest(),b=a.getParent();0===c.__children.length&&a.remove(!0);a=b}}
function D(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function E(a){let c=a.parentNode;if(null==c)throw Error("Should never happen");return[c,Array.from(c.childNodes).indexOf(a)]}exports.$addNodeStyle=function(a){a=a.getStyle();let c={};var b=a.split(";").slice(0,-1);for(let d of b)b=d.split(": "),c[b[0]]=b[1];t.set(a,c)};exports.$cloneContents=function(a){return x(a)};exports.$cloneWithProperties=u;
exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let d=null,f=a.getNodes();var g=a.anchor,e=a.focus,h=a.isBackward();a=h?e.offset:g.offset;g=h?e.getNode():g.getNode();for(e=0;e<f.length;e++){var k=f[e];if((0===e||0!==a||!k.is(g))&&l.$isTextNode(k)){h=c;var m=b;k=k.getStyle();k=y(k);h=null!==k?k[h]||m:m;if(null===d)d=h;else if(d!==h){d="";break}}}return null===d?b:d};exports.$isAtNodeEnd=function(a){return"text"===a.type?a.offset===a.getNode().getTextContentSize():a.offset===a.getNode().getChildrenSize()};
exports.$isParentElementRTL=B;exports.$moveCaretSelection=A;exports.$moveCharacter=function(a,c,b){let d=B(a);A(a,c,b?!d:d,"character")};
exports.$patchStyleText=function(a,c){var b=a.getNodes();let d=b.length-1,f=b[0],g=b[d];if(!a.isCollapsed()){var e=a.anchor,h=a.focus;a=f.getTextContent().length;var k=h.offset,m=e.offset;e=(h=e.isBefore(h))?m:k;h=h?k:m;if(e===f.getTextContentSize()){let n=f.getNextSibling();l.$isTextNode(n)&&(e=m=0,f=n)}if(f.is(g))l.$isTextNode(f)&&(e=m>k?k:m,h=m>k?m:k,e!==h&&(0===e&&h===a?(z(f,c),f.select(e,h)):(b=f.splitText(e,h),b=0===e?b[0]:b[1],z(b,c),b.select(0,h-e))));else for(l.$isTextNode(f)&&(0!==e&&(f=
f.splitText(e)[1]),z(f,c)),l.$isTextNode(g)&&(a=g.getTextContent().length,h!==a&&([g]=g.splitText(h)),0!==h&&z(g,c)),a=1;a<d;a++)k=b[a],m=k.getKey(),l.$isTextNode(k)&&m!==f.getKey()&&m!==g.getKey()&&!k.isToken()&&z(k,c)}};
exports.$selectAll=function(a){let c=a.anchor;a=a.focus;var b=c.getNode().getTopLevelElementOrThrow().getParentOrThrow();let d=b.getFirstDescendant();b=b.getLastDescendant();let f="element",g="element",e=0;l.$isTextNode(d)?f="text":l.$isElementNode(d)||null===d||(d=d.getParentOrThrow());l.$isTextNode(b)?(g="text",e=b.getTextContentSize()):l.$isElementNode(b)||null===b||(b=b.getParentOrThrow());d&&b&&(c.set(d.getKey(),0,f),a.set(b.getKey(),e,g))};
exports.$shouldOverrideDefaultCharacterSelection=function(a,c){a=l.$getDecoratorNode(a.focus,c);return l.$isDecoratorNode(a)&&!a.isIsolated()};
exports.$sliceSelectedTextNodeContent=function(a,c){if(c.isSelected()&&!c.isSegmented()&&!c.isToken()&&(l.$isRangeSelection(a)||l.$isGridSelection(a))){var b=a.anchor.getNode(),e=a.focus.getNode(),f=c.is(b),g=c.is(e);if(f||g){f=a.isBackward();let [d,k]=a.getCharacterOffsets();a=b.is(e);g=c.is(f?e:b);e=c.is(f?b:e);b=0;let h=void 0;a?(b=d>k?k:d,h=d>k?d:k):g?(b=f?k:d,h=void 0):e&&(f=f?d:k,b=0,h=f);c.__text=c.__text.slice(b,h)}}return c};
exports.$wrapLeafNodesInElements=function(a,c,b){let e=a.getNodes(),f=e.length;var g=a.anchor;if(0===f||1===f&&"element"===g.type&&0===g.getNode().getChildrenSize()){a="text"===g.type?g.getNode().getParentOrThrow():g.getNode();g=a.getChildren();let r=c();g.forEach(v=>r.append(v));b&&(r=b.append(r));a.replace(r)}else{var d=e[0],k=new Map;g=[];d=l.$isElementNode(d)?d:d.getParentOrThrow();for(d.isInline()&&(d=d.getParentOrThrow());null!==d;){var h=d.getPreviousSibling();if(null!==h){d=h;break}d=d.getParentOrThrow();
if(l.$isRootNode(d))break}h=new Set;for(var m=0;m<f;m++){var n=e[m];l.$isElementNode(n)&&0===n.getChildrenSize()&&h.add(n.getKey())}var q=new Set;for(m=0;m<f;m++){var p=e[m];n=p.getParent();null!==n&&n.isInline()&&(n=n.getParent());if(null!==n&&l.$isLeafNode(p)&&!q.has(p.getKey())){if(p=n.getKey(),void 0===k.get(p)){let r=c();g.push(r);k.set(p,r);n.getChildren().forEach(v=>{r.append(v);q.add(v.getKey())});C(n)}}else h.has(p.getKey())&&(g.push(c()),p.remove())}if(b)for(c=0;c<g.length;c++)b.append(g[c]);
if(l.$isRootNode(d))if(c=d.getFirstChild(),l.$isElementNode(c)&&(d=c),null===c)if(b)d.append(b);else for(b=0;b<g.length;b++)d.append(g[b]);else if(b)c.insertBefore(b);else for(b=0;b<g.length;b++)c.insertBefore(g[b]);else if(b)d.insertAfter(b);else for(b=g.length-1;0<=b;b--)d.insertAfter(g[b]);b=l.$getPreviousSelection();l.$isRangeSelection(b)&&b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()?l.$setSelection(b.clone()):a.dirty=!0}};
exports.createDOMRange=function(a,c,b,e,f){let g=c.getKey(),d=e.getKey(),k=document.createRange(),h=a.getElementByKey(g);a=a.getElementByKey(d);l.$isTextNode(c)&&(h=D(h));l.$isTextNode(e)&&(a=D(a));if(void 0===c||void 0===e||null===h||null===a)return null;"BR"===h.nodeName&&([h,b]=E(h));"BR"===a.nodeName&&([a,f]=E(a));c=h.firstChild;h===a&&null!=c&&"BR"===c.nodeName&&0===b&&0===f&&(f=1);try{k.setStart(h,b),k.setEnd(a,f)}catch(m){return null}!k.collapsed||b===f&&g===d||(k.setStart(a,f),k.setEnd(h,
b));return k};exports.createRectsFromDOMRange=function(a,c){var b=a.getRootElement();if(null===b)return[];a=b.getBoundingClientRect();b=getComputedStyle(b);b=parseFloat(b.paddingLeft)+parseFloat(b.paddingRight);c=Array.from(c.getClientRects());let e=c.length,f;for(let g=0;g<e;g++){let d=c[g],k=d.width+b===a.width;f&&f.top===d.top&&f.left===d.left&&f.width===d.width&&f.height===d.height||k?(c.splice(g--,1),e--):f=d}return c};exports.getStyleObjectFromCSS=y;
exports.trimTextContentFromAnchor=function(a,c,b){let e=c.getNode();if(l.$isElementNode(e)){var f=e.getDescendantByIndex(c.offset);null!==f&&(e=f)}for(;0<b&&null!==e;){var g=e.getPreviousSibling(),d=0;if(null===g){f=e.getParentOrThrow();for(var k=f.getPreviousSibling();null===k;){f=f.getParent();if(null===f){g=null;break}k=f.getPreviousSibling()}null!==f&&(d=f.isInline()?0:2,g=l.$isElementNode(k)?k.getLastDescendant():k)}let h=e.getTextContent();""===h&&l.$isElementNode(e)&&!e.isInline()&&(h="\n\n");
f=h.length;k=f-b;let m=h.slice(0,k),n=F(h)&&!F(m);if(!l.$isTextNode(e)||b>=f||n)k=e.getParent(),e.remove(),0===k.getChildrenSize()&&k.remove(),b-=f+d,e=g;else{let q=e.getKey();g=a.getEditorState().read(()=>{const p=l.$getNodeByKey(q);return l.$isTextNode(p)&&p.isSimpleText()?p.getTextContent():null});null!==g&&g!==h?(b=l.$getPreviousSelection(),f=e,e.isSimpleText()?e.setTextContent(g):(f=l.$createTextNode(g),e.replace(f)),l.$isRangeSelection(b)&&b.isCollapsed()&&(b=b.anchor.offset,f.select(b,b))):
e.isSimpleText()?(g=c.key===q,d=c.offset,d<b&&(d=f),b=g?d-b:0,f=g?d:k,g&&0===b?([b]=e.splitText(b,f),b.remove()):([,b]=e.splitText(b,f),b.remove())):(b=l.$createTextNode(m),e.replace(b));b=0}}}
exports.$sliceSelectedTextNodeContent=function(a,c){if(c.isSelected()&&!c.isSegmented()&&!c.isToken()&&(l.$isRangeSelection(a)||l.$isGridSelection(a))){var b=a.anchor.getNode(),d=a.focus.getNode(),f=c.is(b),g=c.is(d);if(f||g){f=a.isBackward();let [e,h]=a.getCharacterOffsets();a=b.is(d);g=c.is(f?d:b);d=c.is(f?b:d);b=0;let k=void 0;a?(b=e>h?h:e,k=e>h?e:h):g?(b=f?h:e,k=void 0):d&&(f=f?e:h,b=0,k=f);c.__text=c.__text.slice(b,k)}}return c};
exports.$wrapLeafNodesInElements=function(a,c,b){let d=a.getNodes(),f=d.length;var g=a.anchor;if(0===f||1===f&&"element"===g.type&&0===g.getNode().getChildrenSize()){a="text"===g.type?g.getNode().getParentOrThrow():g.getNode();g=a.getChildren();let r=c();g.forEach(v=>r.append(v));b&&(r=b.append(r));a.replace(r)}else{var e=d[0],h=new Map;g=[];e=l.$isElementNode(e)?e:e.getParentOrThrow();for(e.isInline()&&(e=e.getParentOrThrow());null!==e;){var k=e.getPreviousSibling();if(null!==k){e=k;break}e=e.getParentOrThrow();
if(l.$isRootNode(e))break}k=new Set;for(var m=0;m<f;m++){var n=d[m];l.$isElementNode(n)&&0===n.getChildrenSize()&&k.add(n.getKey())}var p=new Set;for(m=0;m<f;m++){var q=d[m];n=q.getParent();null!==n&&n.isInline()&&(n=n.getParent());if(null!==n&&l.$isLeafNode(q)&&!p.has(q.getKey())){if(q=n.getKey(),void 0===h.get(q)){let r=c();g.push(r);h.set(q,r);n.getChildren().forEach(v=>{r.append(v);p.add(v.getKey())});C(n)}}else k.has(q.getKey())&&(g.push(c()),q.remove())}if(b)for(c=0;c<g.length;c++)b.append(g[c]);
if(l.$isRootNode(e))if(c=e.getFirstChild(),l.$isElementNode(c)&&(e=c),null===c)if(b)e.append(b);else for(b=0;b<g.length;b++)e.append(g[b]);else if(b)c.insertBefore(b);else for(b=0;b<g.length;b++)c.insertBefore(g[b]);else if(b)e.insertAfter(b);else for(b=g.length-1;0<=b;b--)e.insertAfter(g[b]);b=l.$getPreviousSelection();l.$isRangeSelection(b)&&b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()?l.$setSelection(b.clone()):a.dirty=!0}};
exports.createDOMRange=function(a,c,b,d,f){let g=c.getKey(),e=d.getKey(),h=document.createRange(),k=a.getElementByKey(g);a=a.getElementByKey(e);l.$isTextNode(c)&&(k=D(k));l.$isTextNode(d)&&(a=D(a));if(void 0===c||void 0===d||null===k||null===a)return null;"BR"===k.nodeName&&([k,b]=E(k));"BR"===a.nodeName&&([a,f]=E(a));c=k.firstChild;k===a&&null!=c&&"BR"===c.nodeName&&0===b&&0===f&&(f=1);try{h.setStart(k,b),h.setEnd(a,f)}catch(m){return null}!h.collapsed||b===f&&g===e||(h.setStart(a,f),h.setEnd(k,
b));return h};exports.createRectsFromDOMRange=function(a,c){var b=a.getRootElement();if(null===b)return[];a=b.getBoundingClientRect();b=getComputedStyle(b);b=parseFloat(b.paddingLeft)+parseFloat(b.paddingRight);c=Array.from(c.getClientRects());let d=c.length,f;for(let g=0;g<d;g++){let e=c[g],h=e.width+b===a.width;f&&f.top===e.top&&f.left===e.left&&f.width===e.width&&f.height===e.height||h?(c.splice(g--,1),d--):f=e}return c};exports.getStyleObjectFromCSS=y;
exports.trimTextContentFromAnchor=function(a,c,b){let d=c.getNode();if(l.$isElementNode(d)){var f=d.getDescendantByIndex(c.offset);null!==f&&(d=f)}for(;0<b&&null!==d;){var g=d.getPreviousSibling(),e=0;if(null===g){f=d.getParentOrThrow();for(var h=f.getPreviousSibling();null===h;){f=f.getParent();if(null===f){g=null;break}h=f.getPreviousSibling()}null!==f&&(e=f.isInline()?0:2,g=l.$isElementNode(h)?h.getLastDescendant():h)}let k=d.getTextContent();""===k&&l.$isElementNode(d)&&!d.isInline()&&(k="\n\n");
f=k.length;h=f-b;let m=k.slice(0,h);if(!l.$isTextNode(d)||b>=f)h=d.getParent(),d.remove(),0===h.getChildrenSize()&&h.remove(),b-=f+e,d=g;else{let n=d.getKey();g=a.getEditorState().read(()=>{const p=l.$getNodeByKey(n);return l.$isTextNode(p)&&p.isSimpleText()?p.getTextContent():null});null!==g&&g!==k?(b=l.$getPreviousSelection(),f=d,d.isSimpleText()?d.setTextContent(g):(f=l.$createTextNode(g),d.replace(f)),l.$isRangeSelection(b)&&b.isCollapsed()&&(b=b.anchor.offset,f.select(b,b))):d.isSimpleText()?
(g=c.key===n,e=c.offset,e<b&&(e=f),b=g?e-b:0,f=g?e:h,g&&0===b?([b]=d.splitText(b,f),b.remove()):([,b]=d.splitText(b,f),b.remove())):(b=l.$createTextNode(m),d.replace(b));b=0}}}

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

"license": "MIT",
"version": "0.3.3",
"version": "0.3.4",
"main": "LexicalSelection.js",
"peerDependencies": {
"lexical": "0.3.3"
"lexical": "0.3.4"
},

@@ -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