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
193
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.5.1-next.1 to 0.5.1-next.2

2

lexical-node.d.ts

@@ -19,2 +19,2 @@ /**

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

@@ -552,3 +552,3 @@ /**

if (nodes.length === 0) {
if (nodes.length === 0 || nodes.length === 1 && lexical.$isElementNode(nodes[0]) && nodes[0].excludeFromCopy('clone')) {
return {

@@ -926,5 +926,12 @@ nodeMap: [],

const prevStyles = getStyleObjectFromCSS(node.getStyle());
const newStyles = prevStyles ? { ...prevStyles,
...patch
} : patch;
const newStyles = Object.entries(patch).reduce((styles, [key, value]) => {
if (value === null) {
delete styles[key];
} else {
styles[key] = value;
}
return styles;
}, { ...prevStyles
} || {});
const newCSSText = getCSSFromStyleObject(newStyles);

@@ -952,10 +959,11 @@ node.setStyle(newCSSText);

let anchorOffset = anchor.offset;
let startOffset;
let endOffset;
const isBefore = anchor.isBefore(focus);
startOffset = isBefore ? anchorOffset : focusOffset;
endOffset = isBefore ? focusOffset : anchorOffset; // This is the case where the user only selected the very end of the
let startOffset = isBefore ? anchorOffset : focusOffset;
let endOffset = isBefore ? focusOffset : anchorOffset;
const startType = isBefore ? anchor.type : focus.type;
const endType = isBefore ? focus.type : anchor.type;
const endKey = isBefore ? focus.key : anchor.key; // This is the case where the user only selected the very end of the
// first node so we don't want to include it in the formatting change.
if (startOffset === firstNode.getTextContentSize()) {
if (lexical.$isTextNode(firstNode) && startOffset === firstNodeTextLength) {
const nextSibling = firstNode.getNextSibling();

@@ -974,4 +982,4 @@

if (lexical.$isTextNode(firstNode)) {
startOffset = anchorOffset > focusOffset ? focusOffset : anchorOffset;
endOffset = anchorOffset > focusOffset ? anchorOffset : focusOffset; // No actual text is selected, so do nothing.
startOffset = startType === 'element' ? 0 : anchorOffset > focusOffset ? focusOffset : anchorOffset;
endOffset = endType === 'element' ? firstNodeTextLength : anchorOffset > focusOffset ? anchorOffset : focusOffset; // No actual text is selected, so do nothing.

@@ -1009,4 +1017,12 @@ if (startOffset === endOffset) {

const lastNodeText = lastNode.getTextContent();
const lastNodeTextLength = lastNodeText.length; // if the entire last node isn't selected, split it
const lastNodeTextLength = lastNodeText.length; // The last node might not actually be the end node
//
// If not, assume the last node is fully-selected unless the end offset is
// zero.
if (lastNode.__key !== endKey && endOffset !== 0) {
endOffset = lastNodeTextLength;
} // if the entire last node isn't selected, split it
if (endOffset !== lastNodeTextLength) {

@@ -1013,0 +1029,0 @@ [lastNode] = lastNode.splitText(endOffset);

@@ -7,26 +7,26 @@ /**

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

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

"license": "MIT",
"version": "0.5.1-next.1",
"version": "0.5.1-next.2",
"main": "LexicalSelection.js",
"peerDependencies": {
"lexical": "0.5.1-next.1"
"lexical": "0.5.1-next.2"
},

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

@@ -9,3 +9,3 @@ /**

import type { ICloneSelectionContent } from './lexical-node';
import type { ElementNode, LexicalNode, RangeSelection } from 'lexical';
import type { ElementNode, GridSelection, LexicalNode, RangeSelection } from 'lexical';
/**

@@ -21,4 +21,4 @@ * Attempts to wrap all nodes in the Selection in ElementNodes returned from createElement.

*/
export declare function $wrapNodes(selection: RangeSelection, createElement: () => ElementNode, wrappingElement?: null | ElementNode): void;
export declare function $wrapNodesImpl(selection: RangeSelection, nodes: LexicalNode[], nodesLength: number, createElement: () => ElementNode, wrappingElement?: null | ElementNode): void;
export declare function $wrapNodes(selection: RangeSelection | GridSelection, createElement: () => ElementNode, wrappingElement?: null | ElementNode): void;
export declare function $wrapNodesImpl(selection: RangeSelection | GridSelection, nodes: LexicalNode[], nodesLength: number, createElement: () => ElementNode, wrappingElement?: null | ElementNode): void;
export declare function $shouldOverrideDefaultCharacterSelection(selection: RangeSelection, isBackward: boolean): boolean;

@@ -25,0 +25,0 @@ export declare function $moveCaretSelection(selection: RangeSelection, isHoldingShift: boolean, isBackward: boolean, granularity: 'character' | 'word' | 'lineboundary'): void;

Sorry, the diff of this file is not supported yet

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