@lexical/selection
Advanced tools
Comparing version 0.12.5 to 0.12.6
@@ -243,3 +243,3 @@ /** | ||
function $sliceSelectedTextNodeContent(selection, textNode) { | ||
if (textNode.isSelected() && !textNode.isSegmented() && !textNode.isToken() && lexical.$INTERNAL_isPointSelection(selection)) { | ||
if (textNode.isSelected(selection) && !textNode.isSegmented() && !textNode.isToken() && lexical.$INTERNAL_isPointSelection(selection)) { | ||
const anchorNode = selection.anchor.getNode(); | ||
@@ -285,3 +285,7 @@ const focusNode = selection.focus.getNode(); | ||
} | ||
return point.offset === point.getNode().getChildrenSize(); | ||
const node = point.getNode(); | ||
if (!lexical.$isElementNode(node)) { | ||
throw Error(`isAtNodeEnd: node must be a TextNode or ElementNode`); | ||
} | ||
return point.offset === node.getChildrenSize(); | ||
} | ||
@@ -437,3 +441,3 @@ | ||
const selectedNodesLength = selectedNodes.length; | ||
if (lexical.DEPRECATED_$isGridSelection(selection)) { | ||
if (!lexical.$isRangeSelection(selection)) { | ||
const cellSelection = lexical.$createRangeSelection(); | ||
@@ -586,2 +590,5 @@ const cellSelectionAnchor = cellSelection.anchor; | ||
} | ||
if (!lexical.$isElementNode(node)) { | ||
throw Error(`Expected block node to be an ElementNode`); | ||
} | ||
const targetElement = createElement(); | ||
@@ -732,2 +739,5 @@ targetElement.setFormat(node.getFormatType()); | ||
} else if (emptyElements.has(node.getKey())) { | ||
if (!lexical.$isElementNode(node)) { | ||
throw Error(`Expected node in emptyElements to be an ElementNode`); | ||
} | ||
const targetElement = createElement(); | ||
@@ -734,0 +744,0 @@ targetElement.setFormat(node.getFormatType()); |
@@ -7,25 +7,26 @@ /** | ||
*/ | ||
'use strict';var k=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 w(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 d of a)if(""!==d){let [f,c]=d.split(/:([^]+)/);f&&c&&(b[f.trim()]=c.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 d in a)d&&(b+=`${d}: ${a[d]};`);return b}function B(a,b){var d=z("getStyle"in a?a.getStyle():a.style);b=Object.entries(b).reduce((f,[c,g])=>{null===g?delete f[c]:f[c]=g;return f},{...d});d=A(b);a.setStyle(d);u.set(d,b)} | ||
function C(a,b){var d=a.getNodes(),f=d.length;if(k.DEPRECATED_$isGridSelection(a)){var c=k.$createRangeSelection(),g=c.anchor,h=c.focus;for(var e=0;e<f;e++){var l=d[e];k.DEPRECATED_$isGridCellNode(l)&&(g.set(l.getKey(),0,"element"),h.set(l.getKey(),l.getChildrenSize(),"element"),C(k.$normalizeSelection__EXPERIMENTAL(c),b))}k.$setSelection(a)}else if(--f,c=d[0],g=d[f],a.isCollapsed()&&k.$isRangeSelection(a))B(a,b);else{e=a.anchor;var m=a.focus;l=c.getTextContent().length;var p=m.offset,n=e.offset, | ||
r=e.isBefore(m);h=r?n:p;a=r?p:n;var q=r?e.type:m.type,t=r?m.type:e.type;m=r?m.key:e.key;k.$isTextNode(c)&&h===l&&(r=c.getNextSibling(),k.$isTextNode(r)&&(h=n=0,c=r));if(1===d.length)k.$isTextNode(c)&&(h="element"===q?0:n>p?p:n,a="element"===t?l:n>p?n:p,h!==a&&(0===h&&a===l?(B(c,b),c.select(h,a)):(d=c.splitText(h,a),d=0===h?d[0]:d[1],B(d,b),d.select(0,a-h))));else for(k.$isTextNode(c)&&h<c.getTextContentSize()&&(0!==h&&(c=c.splitText(h)[1],h=0,e.set(c.getKey(),h,"text")),B(c,b)),k.$isTextNode(g)&& | ||
(h=g.getTextContent().length,g.__key!==m&&0!==a&&(a=h),a!==h&&([g]=g.splitText(a)),0!==a&&B(g,b)),a=1;a<f;a++)h=d[a],e=h.getKey(),k.$isTextNode(h)&&e!==c.getKey()&&e!==g.getKey()&&!h.isToken()&&B(h,b)}}function D(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let b=a.getLatest(),d=a.getParent();0===b.getChildrenSize()&&a.remove(!0);a=d}} | ||
function E(a,b,d,f,c=null){if(0!==b.length){var g=b[0],h=new Map,e=[];g=k.$isElementNode(g)?g:g.getParentOrThrow();g.isInline()&&(g=g.getParentOrThrow());for(var l=!1;null!==g;){var m=g.getPreviousSibling();if(null!==m){g=m;l=!0;break}g=g.getParentOrThrow();if(k.$isRootOrShadowRoot(g))break}m=new Set;for(var p=0;p<d;p++){var n=b[p];k.$isElementNode(n)&&0===n.getChildrenSize()&&m.add(n.getKey())}var r=new Set;for(p=0;p<d;p++){n=b[p];var q=n.getParent();null!==q&&q.isInline()&&(q=q.getParent());if(null!== | ||
q&&k.$isLeafNode(n)&&!r.has(n.getKey())){if(n=q.getKey(),void 0===h.get(n)){let t=f();t.setFormat(q.getFormatType());t.setIndent(q.getIndent());e.push(t);h.set(n,t);q.getChildren().forEach(x=>{t.append(x);r.add(x.getKey());k.$isElementNode(x)&&x.getChildrenKeys().forEach(I=>r.add(I))});D(q)}}else m.has(n.getKey())&&(q=f(),q.setFormat(n.getFormatType()),q.setIndent(n.getIndent()),e.push(q),n.remove(!0))}if(null!==c)for(b=0;b<e.length;b++)c.append(e[b]);b=null;if(k.$isRootOrShadowRoot(g))if(l)if(null!== | ||
c)g.insertAfter(c);else for(c=e.length-1;0<=c;c--)g.insertAfter(e[c]);else if(l=g.getFirstChild(),k.$isElementNode(l)&&(g=l),null===l)if(c)g.append(c);else for(c=0;c<e.length;c++)l=e[c],g.append(l),b=l;else if(null!==c)l.insertBefore(c);else for(g=0;g<e.length;g++)c=e[g],l.insertBefore(c),b=c;else if(c)g.insertAfter(c);else for(c=e.length-1;0<=c;c--)l=e[c],g.insertAfter(l),b=l;e=k.$getPreviousSelection();k.$isRangeSelection(e)&&e.anchor.getNode().isAttached()&&e.focus.getNode().isAttached()?k.$setSelection(e.clone()): | ||
null!==b?b.selectEnd():a.dirty=!0}}function F(a,b,d,f){a.modify(b?"extend":"move",d,f)}function G(a){a=a.anchor.getNode();return"rtl"===(k.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function H(a){if(k.$isDecoratorNode(a)&&!a.isInline())return!0;if(!k.$isElementNode(a)||k.$isRootOrShadowRoot(a))return!1;var b=a.getFirstChild();b=null===b||k.$isLineBreakNode(b)||k.$isTextNode(b)||b.isInline();return!a.isInline()&&!1!==a.canBeEmpty()&&b} | ||
exports.$addNodeStyle=function(a){a=a.getStyle();let b=y(a);u.set(a,b)};exports.$cloneWithProperties=function(a){let b=a.constructor.clone(a);b.__parent=a.__parent;b.__next=a.__next;b.__prev=a.__prev;if(k.$isElementNode(a)&&k.$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;k.$isTextNode(a)&&k.$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,d=""){let f=null,c=a.getNodes();var g=a.anchor,h=a.focus,e=a.isBackward();let l=e?h.offset:g.offset;g=e?h.getNode():g.getNode();if(a.isCollapsed()&&""!==a.style&&(a=z(a.style),null!==a&&b in a))return a[b];for(a=0;a<c.length;a++){var m=c[a];if((0===a||0!==l||!m.is(g))&&k.$isTextNode(m))if(h=b,e=d,m=m.getStyle(),m=z(m),h=null!==m?m[h]||e:e,null===f)f=h;else if(f!==h){f="";break}}return null===f?d: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,d){let f=G(a);F(a,b,d?!f:f,"character")};exports.$patchStyleText=C; | ||
exports.$selectAll=function(a){let b=a.anchor;a=a.focus;var d=b.getNode().getTopLevelElementOrThrow().getParentOrThrow();let f=d.getFirstDescendant();d=d.getLastDescendant();let c="element",g="element",h=0;k.$isTextNode(f)?c="text":k.$isElementNode(f)||null===f||(f=f.getParentOrThrow());k.$isTextNode(d)?(g="text",h=d.getTextContentSize()):k.$isElementNode(d)||null===d||(d=d.getParentOrThrow());f&&d&&(b.set(f.getKey(),0,c),a.set(d.getKey(),h,g))}; | ||
exports.$setBlocksType=function(a,b){if("root"===a.anchor.key){b=b();var d=k.$getRoot();(a=d.getFirstChild())?a.replace(b,!0):d.append(b)}else{d=a.getNodes();for(a=a.anchor.getNode();null!==a&&null!==a.getParent()&&!H(a);)a=a.getParentOrThrow();(a=H(a)?a:null)&&-1===d.indexOf(a)&&d.push(a);for(a=0;a<d.length;a++){let f=d[a];if(!H(f))continue;let c=b();c.setFormat(f.getFormatType());c.setIndent(f.getIndent());f.replace(c,!0)}}}; | ||
exports.$shouldOverrideDefaultCharacterSelection=function(a,b){a=k.$getAdjacentNode(a.focus,b);return k.$isDecoratorNode(a)&&!a.isIsolated()||k.$isElementNode(a)&&!a.isInline()&&!a.canBeEmpty()}; | ||
exports.$sliceSelectedTextNodeContent=function(a,b){if(b.isSelected()&&!b.isSegmented()&&!b.isToken()&&k.$INTERNAL_isPointSelection(a)){var d=a.anchor.getNode(),f=a.focus.getNode(),c=b.is(d),g=b.is(f);if(c||g){c=a.isBackward();let [h,e]=a.getCharacterOffsets();a=d.is(f);g=b.is(c?f:d);f=b.is(c?d:f);d=0;let l=void 0;a?(d=h>e?e:h,l=h>e?h:e):g?(d=c?e:h,l=void 0):f&&(c=c?h:e,d=0,l=c);b.__text=b.__text.slice(d,l)}}return b}; | ||
exports.$wrapNodes=function(a,b,d=null){var f=a.getNodes();let c=f.length;var g=a.anchor;if(0===c||1===c&&"element"===g.type&&0===g.getNode().getChildrenSize()){a="text"===g.type?g.getNode().getParentOrThrow():g.getNode();f=a.getChildren();let e=b();e.setFormat(a.getFormatType());e.setIndent(a.getIndent());f.forEach(l=>e.append(l));d&&(e=d.append(e));a.replace(e)}else{g=null;var h=[];for(let e=0;e<c;e++){let l=f[e];k.$isRootOrShadowRoot(l)?(E(a,h,h.length,b,d),h=[],g=l):null===g||null!==g&&k.$hasAncestor(l, | ||
g)?h.push(l):(E(a,h,h.length,b,d),h=[l])}E(a,h,h.length,b,d)}}; | ||
exports.createDOMRange=function(a,b,d,f,c){let g=b.getKey(),h=f.getKey(),e=document.createRange(),l=a.getElementByKey(g);a=a.getElementByKey(h);k.$isTextNode(b)&&(l=v(l));k.$isTextNode(f)&&(a=v(a));if(void 0===b||void 0===f||null===l||null===a)return null;"BR"===l.nodeName&&([l,d]=w(l));"BR"===a.nodeName&&([a,c]=w(a));b=l.firstChild;l===a&&null!=b&&"BR"===b.nodeName&&0===d&&0===c&&(c=1);try{e.setStart(l,d),e.setEnd(a,c)}catch(m){return null}!e.collapsed||d===c&&g===h||(e.setStart(a,c),e.setEnd(l, | ||
d));return e};exports.createRectsFromDOMRange=function(a,b){var d=a.getRootElement();if(null===d)return[];a=d.getBoundingClientRect();d=getComputedStyle(d);d=parseFloat(d.paddingLeft)+parseFloat(d.paddingRight);b=Array.from(b.getClientRects());let f=b.length;b.sort((g,h)=>{let e=g.top-h.top;return 3>=Math.abs(e)?g.left-h.left:e});let c;for(let g=0;g<f;g++){let h=b[g],e=h.width+d===a.width;c&&c.top<=h.top&&c.top+c.height>h.top&&c.left+c.width>h.left||e?(b.splice(g--,1),f--):c=h}return b}; | ||
'use strict';var k=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 w(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 d of a)if(""!==d){let [e,c]=d.split(/:([^]+)/);e&&c&&(b[e.trim()]=c.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 d in a)d&&(b+=`${d}: ${a[d]};`);return b}function B(a,b){var d=z("getStyle"in a?a.getStyle():a.style);b=Object.entries(b).reduce((e,[c,f])=>{null===f?delete e[c]:e[c]=f;return e},{...d});d=A(b);a.setStyle(d);u.set(d,b)} | ||
function C(a,b){var d=a.getNodes(),e=d.length;if(k.$isRangeSelection(a)){--e;var c=d[0],f=d[e];if(a.isCollapsed()&&k.$isRangeSelection(a))B(a,b);else{var h=a.anchor,g=a.focus,l=c.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,t=p?g.type:h.type;g=p?g.key:h.key;k.$isTextNode(c)&&m===l&&(p=c.getNextSibling(),k.$isTextNode(p)&&(m=q=0,c=p));if(1===d.length)k.$isTextNode(c)&&(m="element"===r?0:q>n?n:q,a="element"===t?l:q>n?q:n,m!==a&&(0===m&&a===l?(B(c, | ||
b),c.select(m,a)):(d=c.splitText(m,a),d=0===m?d[0]:d[1],B(d,b),d.select(0,a-m))));else for(k.$isTextNode(c)&&m<c.getTextContentSize()&&(0!==m&&(c=c.splitText(m)[1],m=0,h.set(c.getKey(),m,"text")),B(c,b)),k.$isTextNode(f)&&(m=f.getTextContent().length,f.__key!==g&&0!==a&&(a=m),a!==m&&([f]=f.splitText(a)),0!==a&&B(f,b)),a=1;a<e;a++)m=d[a],h=m.getKey(),k.$isTextNode(m)&&h!==c.getKey()&&h!==f.getKey()&&!m.isToken()&&B(m,b)}}else{c=k.$createRangeSelection();f=c.anchor;m=c.focus;for(h=0;h<e;h++)l=d[h], | ||
k.DEPRECATED_$isGridCellNode(l)&&(f.set(l.getKey(),0,"element"),m.set(l.getKey(),l.getChildrenSize(),"element"),C(k.$normalizeSelection__EXPERIMENTAL(c),b));k.$setSelection(a)}}function D(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let b=a.getLatest(),d=a.getParent();0===b.getChildrenSize()&&a.remove(!0);a=d}} | ||
function E(a,b,d,e,c=null){if(0!==b.length){var f=b[0],h=new Map,g=[];f=k.$isElementNode(f)?f:f.getParentOrThrow();f.isInline()&&(f=f.getParentOrThrow());for(var l=!1;null!==f;){var n=f.getPreviousSibling();if(null!==n){f=n;l=!0;break}f=f.getParentOrThrow();if(k.$isRootOrShadowRoot(f))break}n=new Set;for(var q=0;q<d;q++){var p=b[q];k.$isElementNode(p)&&0===p.getChildrenSize()&&n.add(p.getKey())}var m=new Set;for(q=0;q<d;q++){p=b[q];var r=p.getParent();null!==r&&r.isInline()&&(r=r.getParent());if(null!== | ||
r&&k.$isLeafNode(p)&&!m.has(p.getKey())){if(p=r.getKey(),void 0===h.get(p)){let t=e();t.setFormat(r.getFormatType());t.setIndent(r.getIndent());g.push(t);h.set(p,t);r.getChildren().forEach(x=>{t.append(x);m.add(x.getKey());k.$isElementNode(x)&&x.getChildrenKeys().forEach(I=>m.add(I))});D(r)}}else if(n.has(p.getKey())){if(!k.$isElementNode(p))throw Error("Expected node in emptyElements to be an ElementNode");r=e();r.setFormat(p.getFormatType());r.setIndent(p.getIndent());g.push(r);p.remove(!0)}}if(null!== | ||
c)for(b=0;b<g.length;b++)c.append(g[b]);b=null;if(k.$isRootOrShadowRoot(f))if(l)if(null!==c)f.insertAfter(c);else for(c=g.length-1;0<=c;c--)f.insertAfter(g[c]);else if(l=f.getFirstChild(),k.$isElementNode(l)&&(f=l),null===l)if(c)f.append(c);else for(c=0;c<g.length;c++)l=g[c],f.append(l),b=l;else if(null!==c)l.insertBefore(c);else for(f=0;f<g.length;f++)c=g[f],l.insertBefore(c),b=c;else if(c)f.insertAfter(c);else for(c=g.length-1;0<=c;c--)l=g[c],f.insertAfter(l),b=l;g=k.$getPreviousSelection();k.$isRangeSelection(g)&& | ||
g.anchor.getNode().isAttached()&&g.focus.getNode().isAttached()?k.$setSelection(g.clone()):null!==b?b.selectEnd():a.dirty=!0}}function F(a,b,d,e){a.modify(b?"extend":"move",d,e)}function G(a){a=a.anchor.getNode();return"rtl"===(k.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()} | ||
function H(a){if(k.$isDecoratorNode(a)&&!a.isInline())return!0;if(!k.$isElementNode(a)||k.$isRootOrShadowRoot(a))return!1;var b=a.getFirstChild();b=null===b||k.$isLineBreakNode(b)||k.$isTextNode(b)||b.isInline();return!a.isInline()&&!1!==a.canBeEmpty()&&b}exports.$addNodeStyle=function(a){a=a.getStyle();let b=y(a);u.set(a,b)}; | ||
exports.$cloneWithProperties=function(a){let b=a.constructor.clone(a);b.__parent=a.__parent;b.__next=a.__next;b.__prev=a.__prev;if(k.$isElementNode(a)&&k.$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;k.$isTextNode(a)&&k.$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,d=""){let e=null,c=a.getNodes();var f=a.anchor,h=a.focus,g=a.isBackward();let l=g?h.offset:f.offset;f=g?h.getNode():f.getNode();if(a.isCollapsed()&&""!==a.style&&(a=z(a.style),null!==a&&b in a))return a[b];for(a=0;a<c.length;a++){var n=c[a];if((0===a||0!==l||!n.is(f))&&k.$isTextNode(n))if(h=b,g=d,n=n.getStyle(),n=z(n),h=null!==n?n[h]||g:g,null===e)e=h;else if(e!==h){e="";break}}return null===e?d:e}; | ||
exports.$isAtNodeEnd=function(a){if("text"===a.type)return a.offset===a.getNode().getTextContentSize();let b=a.getNode();if(!k.$isElementNode(b))throw Error("isAtNodeEnd: node must be a TextNode or ElementNode");return a.offset===b.getChildrenSize()};exports.$isParentElementRTL=G;exports.$moveCaretSelection=F;exports.$moveCharacter=function(a,b,d){let e=G(a);F(a,b,d?!e:e,"character")};exports.$patchStyleText=C; | ||
exports.$selectAll=function(a){let b=a.anchor;a=a.focus;var d=b.getNode().getTopLevelElementOrThrow().getParentOrThrow();let e=d.getFirstDescendant();d=d.getLastDescendant();let c="element",f="element",h=0;k.$isTextNode(e)?c="text":k.$isElementNode(e)||null===e||(e=e.getParentOrThrow());k.$isTextNode(d)?(f="text",h=d.getTextContentSize()):k.$isElementNode(d)||null===d||(d=d.getParentOrThrow());e&&d&&(b.set(e.getKey(),0,c),a.set(d.getKey(),h,f))}; | ||
exports.$setBlocksType=function(a,b){if("root"===a.anchor.key){b=b();var d=k.$getRoot();(a=d.getFirstChild())?a.replace(b,!0):d.append(b)}else{d=a.getNodes();for(a=a.anchor.getNode();null!==a&&null!==a.getParent()&&!H(a);)a=a.getParentOrThrow();(a=H(a)?a:null)&&-1===d.indexOf(a)&&d.push(a);for(a=0;a<d.length;a++){let e=d[a];if(!H(e))continue;if(!k.$isElementNode(e))throw Error("Expected block node to be an ElementNode");let c=b();c.setFormat(e.getFormatType());c.setIndent(e.getIndent());e.replace(c, | ||
!0)}}};exports.$shouldOverrideDefaultCharacterSelection=function(a,b){a=k.$getAdjacentNode(a.focus,b);return k.$isDecoratorNode(a)&&!a.isIsolated()||k.$isElementNode(a)&&!a.isInline()&&!a.canBeEmpty()}; | ||
exports.$sliceSelectedTextNodeContent=function(a,b){if(b.isSelected(a)&&!b.isSegmented()&&!b.isToken()&&k.$INTERNAL_isPointSelection(a)){var d=a.anchor.getNode(),e=a.focus.getNode(),c=b.is(d),f=b.is(e);if(c||f){c=a.isBackward();let [h,g]=a.getCharacterOffsets();a=d.is(e);f=b.is(c?e:d);e=b.is(c?d:e);d=0;let l=void 0;a?(d=h>g?g:h,l=h>g?h:g):f?(d=c?g:h,l=void 0):e&&(c=c?h:g,d=0,l=c);b.__text=b.__text.slice(d,l)}}return b}; | ||
exports.$wrapNodes=function(a,b,d=null){var e=a.getNodes();let c=e.length;var f=a.anchor;if(0===c||1===c&&"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(l=>g.append(l));d&&(g=d.append(g));a.replace(g)}else{f=null;var h=[];for(let g=0;g<c;g++){let l=e[g];k.$isRootOrShadowRoot(l)?(E(a,h,h.length,b,d),h=[],f=l):null===f||null!==f&&k.$hasAncestor(l, | ||
f)?h.push(l):(E(a,h,h.length,b,d),h=[l])}E(a,h,h.length,b,d)}}; | ||
exports.createDOMRange=function(a,b,d,e,c){let f=b.getKey(),h=e.getKey(),g=document.createRange(),l=a.getElementByKey(f);a=a.getElementByKey(h);k.$isTextNode(b)&&(l=v(l));k.$isTextNode(e)&&(a=v(a));if(void 0===b||void 0===e||null===l||null===a)return null;"BR"===l.nodeName&&([l,d]=w(l));"BR"===a.nodeName&&([a,c]=w(a));b=l.firstChild;l===a&&null!=b&&"BR"===b.nodeName&&0===d&&0===c&&(c=1);try{g.setStart(l,d),g.setEnd(a,c)}catch(n){return null}!g.collapsed||d===c&&f===h||(g.setStart(a,c),g.setEnd(l, | ||
d));return g};exports.createRectsFromDOMRange=function(a,b){var d=a.getRootElement();if(null===d)return[];a=d.getBoundingClientRect();d=getComputedStyle(d);d=parseFloat(d.paddingLeft)+parseFloat(d.paddingRight);b=Array.from(b.getClientRects());let e=b.length;b.sort((f,h)=>{let g=f.top-h.top;return 3>=Math.abs(g)?f.left-h.left:g});let c;for(let f=0;f<e;f++){let h=b[f],g=h.width+d===a.width;c&&c.top<=h.top&&c.top+c.height>h.top&&c.left+c.width>h.left||g?(b.splice(f--,1),e--):c=h}return b}; | ||
exports.getStyleObjectFromCSS=z; | ||
exports.trimTextContentFromAnchor=function(a,b,d){let f=b.getNode();if(k.$isElementNode(f)){var c=f.getDescendantByIndex(b.offset);null!==c&&(f=c)}for(;0<d&&null!==f;){k.$isElementNode(f)&&(c=f.getLastDescendant(),null!==c&&(f=c));var g=f.getPreviousSibling(),h=0;if(null===g){c=f.getParentOrThrow();for(var e=c.getPreviousSibling();null===e;){c=c.getParent();if(null===c){g=null;break}e=c.getPreviousSibling()}null!==c&&(h=c.isInline()?0:2,g=e)}e=f.getTextContent();""===e&&k.$isElementNode(f)&&!f.isInline()&& | ||
(e="\n\n");c=e.length;if(!k.$isTextNode(f)||d>=c)e=f.getParent(),f.remove(),null==e||0!==e.getChildrenSize()||k.$isRootNode(e)||e.remove(),d-=c+h,f=g;else{let l=f.getKey();h=a.getEditorState().read(()=>{const p=k.$getNodeByKey(l);return k.$isTextNode(p)&&p.isSimpleText()?p.getTextContent():null});g=c-d;let m=e.slice(0,g);null!==h&&h!==e?(d=k.$getPreviousSelection(),c=f,f.isSimpleText()?f.setTextContent(h):(c=k.$createTextNode(h),f.replace(c)),k.$isRangeSelection(d)&&d.isCollapsed()&&(d=d.anchor.offset, | ||
c.select(d,d))):f.isSimpleText()?(h=b.key===l,e=b.offset,e<d&&(e=c),d=h?e-d:0,c=h?e:g,h&&0===d?([d]=f.splitText(d,c),d.remove()):([,d]=f.splitText(d,c),d.remove())):(d=k.$createTextNode(m),f.replace(d));d=0}}} | ||
exports.trimTextContentFromAnchor=function(a,b,d){let e=b.getNode();if(k.$isElementNode(e)){var c=e.getDescendantByIndex(b.offset);null!==c&&(e=c)}for(;0<d&&null!==e;){k.$isElementNode(e)&&(c=e.getLastDescendant(),null!==c&&(e=c));var f=e.getPreviousSibling(),h=0;if(null===f){c=e.getParentOrThrow();for(var g=c.getPreviousSibling();null===g;){c=c.getParent();if(null===c){f=null;break}g=c.getPreviousSibling()}null!==c&&(h=c.isInline()?0:2,f=g)}g=e.getTextContent();""===g&&k.$isElementNode(e)&&!e.isInline()&& | ||
(g="\n\n");c=g.length;if(!k.$isTextNode(e)||d>=c)g=e.getParent(),e.remove(),null==g||0!==g.getChildrenSize()||k.$isRootNode(g)||g.remove(),d-=c+h,e=f;else{let l=e.getKey();h=a.getEditorState().read(()=>{const q=k.$getNodeByKey(l);return k.$isTextNode(q)&&q.isSimpleText()?q.getTextContent():null});f=c-d;let n=g.slice(0,f);null!==h&&h!==g?(d=k.$getPreviousSelection(),c=e,e.isSimpleText()?e.setTextContent(h):(c=k.$createTextNode(h),e.replace(c)),k.$isRangeSelection(d)&&d.isCollapsed()&&(d=d.anchor.offset, | ||
c.select(d,d))):e.isSimpleText()?(h=b.key===l,g=b.offset,g<d&&(g=c),d=h?g-d:0,c=h?g:f,h&&0===d?([d]=e.splitText(d,c),d.remove()):([,d]=e.splitText(d,c),d.remove())):(d=k.$createTextNode(n),e.replace(d));d=0}}} |
@@ -12,6 +12,6 @@ { | ||
"license": "MIT", | ||
"version": "0.12.5", | ||
"version": "0.12.6", | ||
"main": "LexicalSelection.js", | ||
"peerDependencies": { | ||
"lexical": "0.12.5" | ||
"lexical": "0.12.6" | ||
}, | ||
@@ -18,0 +18,0 @@ "repository": { |
@@ -24,3 +24,3 @@ # `@lexical/selection` | ||
export function $patchStyleText( | ||
selection: RangeSelection | GridSelection, | ||
selection: BaseSelection, | ||
patch: { | ||
@@ -27,0 +27,0 @@ [key: string]: string; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64666
1207