@lexical/selection
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -12,2 +12,3 @@ /** | ||
GridSelection, | ||
LexicalEditor, | ||
LexicalNode, | ||
@@ -25,2 +26,5 @@ NodeKey, | ||
}; | ||
export function $cloneWithProperties<LexicalNode>( | ||
node: LexicalNode, | ||
): LexicalNode; | ||
export function getStyleObjectFromCSS(css: string): { | ||
@@ -63,1 +67,14 @@ [key: string]: string; | ||
): boolean; | ||
declare function createDOMRange( | ||
editor: LexicalEditor, | ||
anchorNode: LexicalNode, | ||
anchorOffset: number, | ||
focusNode: LexicalNode, | ||
focusOffset: number, | ||
): Range | null; | ||
declare function createRectsFromDOMRange( | ||
editor: LexicalEditor, | ||
range: Range, | ||
): Array<ClientRect>; |
@@ -20,3 +20,2 @@ /** | ||
const cssToStyles = new Map(); | ||
function $cloneWithProperties(node) { | ||
@@ -34,3 +33,2 @@ const latest = node.getLatest(); | ||
} else if (lexical.$isTextNode(latest) && lexical.$isTextNode(clone)) { | ||
const marks = latest.__marks; | ||
clone.__format = latest.__format; | ||
@@ -40,3 +38,2 @@ clone.__style = latest.__style; | ||
clone.__detail = latest.__detail; | ||
clone.__marks = marks === null ? null : Array.from(marks); | ||
} // $FlowFixMe | ||
@@ -61,3 +58,3 @@ | ||
while (parent !== null && parent.excludeFromCopy()) { | ||
while (parent !== null && parent.excludeFromCopy('clone')) { | ||
parent = parent.getParent(); | ||
@@ -80,3 +77,3 @@ } | ||
if (!lexical.$isElementNode(node) || !node.excludeFromCopy()) { | ||
if (!lexical.$isElementNode(node) || !node.excludeFromCopy('clone')) { | ||
const key = node.getKey(); | ||
@@ -200,3 +197,3 @@ let clone = nodeMap.get(key); | ||
if (!nodeMap.has(key) && (!lexical.$isElementNode(node) || !node.excludeFromCopy())) { | ||
if (!nodeMap.has(key) && (!lexical.$isElementNode(node) || !node.excludeFromCopy('clone'))) { | ||
const clone = $cloneWithProperties(node); | ||
@@ -601,5 +598,3 @@ | ||
if (lexical.$isRangeSelection(prevSelection) && isPointAttached(prevSelection.anchor) && isPointAttached(prevSelection.focus)) { | ||
const clonedSelection = prevSelection.clone(); | ||
clonedSelection.dirty = true; | ||
lexical.$setSelection(clonedSelection); | ||
lexical.$setSelection(prevSelection.clone()); | ||
} else { | ||
@@ -626,3 +621,115 @@ selection.dirty = true; | ||
function getDOMTextNode(element) { | ||
let node = element; | ||
while (node != null) { | ||
if (node.nodeType === 3) { | ||
// $FlowFixMe: this is a Text | ||
return node; | ||
} | ||
node = node.firstChild; | ||
} | ||
return null; | ||
} | ||
function getDOMIndexWithinParent(node) { | ||
const parent = node.parentNode; | ||
if (parent == null) { | ||
throw new Error('Should never happen'); | ||
} | ||
return [parent, Array.from(parent.childNodes).indexOf(node)]; | ||
} | ||
function createDOMRange(editor, anchorNode, _anchorOffset, focusNode, _focusOffset) { | ||
const anchorKey = anchorNode.getKey(); | ||
const focusKey = focusNode.getKey(); | ||
const range = document.createRange(); | ||
let anchorDOM = editor.getElementByKey(anchorKey); | ||
let focusDOM = editor.getElementByKey(focusKey); | ||
let anchorOffset = _anchorOffset; | ||
let focusOffset = _focusOffset; | ||
if (lexical.$isTextNode(anchorNode)) { | ||
anchorDOM = getDOMTextNode(anchorDOM); | ||
} | ||
if (lexical.$isTextNode(focusNode)) { | ||
focusDOM = getDOMTextNode(focusDOM); | ||
} | ||
if (anchorNode === undefined || focusNode === undefined || anchorDOM === null || focusDOM === null) { | ||
return null; | ||
} | ||
if (anchorDOM.nodeName === 'BR') { | ||
[anchorDOM, anchorOffset] = getDOMIndexWithinParent(anchorDOM); | ||
} | ||
if (focusDOM.nodeName === 'BR') { | ||
[focusDOM, focusOffset] = getDOMIndexWithinParent(focusDOM); | ||
} | ||
const firstChild = anchorDOM.firstChild; | ||
if (anchorDOM === focusDOM && firstChild != null && firstChild.nodeName === 'BR' && anchorOffset === 0 && focusOffset === 0) { | ||
focusOffset = 1; | ||
} | ||
try { | ||
range.setStart(anchorDOM, anchorOffset); | ||
range.setEnd(focusDOM, focusOffset); | ||
} catch (e) { | ||
return null; | ||
} | ||
if (range.collapsed && (anchorOffset !== focusOffset || anchorKey !== focusKey)) { | ||
// Range is backwards, we need to reverse it | ||
range.setStart(focusDOM, focusOffset); | ||
range.setEnd(anchorDOM, anchorOffset); | ||
} | ||
return range; | ||
} | ||
function createRectsFromDOMRange(editor, range) { | ||
const rootElement = editor.getRootElement(); | ||
if (rootElement === null) { | ||
return []; | ||
} | ||
const rootRect = rootElement.getBoundingClientRect(); | ||
const computedStyle = getComputedStyle(rootElement); | ||
const rootPadding = parseFloat(computedStyle.paddingLeft) + parseFloat(computedStyle.paddingRight); | ||
const selectionRects = Array.from(range.getClientRects()); | ||
let selectionRectsLength = selectionRects.length; | ||
let prevRect; | ||
for (let i = 0; i < selectionRectsLength; i++) { | ||
const selectionRect = selectionRects[i]; // Exclude a rect that is the exact same as the last rect. getClientRects() can return | ||
// the same rect twice for some elements. A more sophisticated thing to do here is to | ||
// merge all the rects together into a set of rects that don't overlap, so we don't | ||
// generate backgrounds that are too dark. | ||
const isDuplicateRect = prevRect && prevRect.top === selectionRect.top && prevRect.left === selectionRect.left && prevRect.width === selectionRect.width && prevRect.height === selectionRect.height; // Exclude selections that span the entire element | ||
const selectionSpansElement = selectionRect.width + rootPadding === rootRect.width; | ||
if (isDuplicateRect || selectionSpansElement) { | ||
selectionRects.splice(i--, 1); | ||
selectionRectsLength--; | ||
continue; | ||
} | ||
prevRect = selectionRect; | ||
} | ||
return selectionRects; | ||
} | ||
exports.$cloneContents = $cloneContents; | ||
exports.$cloneWithProperties = $cloneWithProperties; | ||
exports.$getSelectionStyleValueForProperty = $getSelectionStyleValueForProperty; | ||
@@ -637,2 +744,4 @@ exports.$isAtNodeEnd = $isAtNodeEnd; | ||
exports.$wrapLeafNodesInElements = $wrapLeafNodesInElements; | ||
exports.createDOMRange = createDOMRange; | ||
exports.createRectsFromDOMRange = createRectsFromDOMRange; | ||
exports.getStyleObjectFromCSS = getStyleObjectFromCSS; |
@@ -7,16 +7,19 @@ /** | ||
*/ | ||
var k=require("lexical");const t=new Map;function v(a){a=a.getLatest();const c=a.constructor.clone(a);c.__parent=a.__parent;if(k.$isElementNode(a)&&k.$isElementNode(c))c.__children=Array.from(a.__children),c.__format=a.__format,c.__indent=a.__indent,c.__dir=a.__dir;else if(k.$isTextNode(a)&&k.$isTextNode(c)){const b=a.__marks;c.__format=a.__format;c.__style=a.__style;c.__mode=a.__mode;c.__detail=a.__detail;c.__marks=null===b?null:Array.from(b)}return c} | ||
function w(a,c,b,e,l,f){for(var d=c;null!==a;){for(c=a.getParent();null!==c&&c.excludeFromCopy();)c=c.getParent();if(null===c)break;if(!k.$isElementNode(a)||!a.excludeFromCopy()){const h=a.getKey();let g=f.get(h);const m=void 0===g;m&&(g=v(a),f.set(h,g));!k.$isTextNode(g)||g.isSegmented()||g.isToken()?k.$isElementNode(g)&&(g.__children=g.__children.slice(e?d:0,e?void 0:(d||0)+1)):g.__text=g.__text.slice(e?d:0,e?b:d);if(k.$isRootNode(c)){m&&l.push(h);break}}d=f.get(c.getKey());d=k.$isElementNode(d)? | ||
var l=require("lexical");const t=new Map;function u(a){a=a.getLatest();const 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,g,k,f){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")){const h=a.getKey();let e=f.get(h);const m=void 0===e;m&&(e=u(a),f.set(h,e));!l.$isTextNode(e)||e.isSegmented()||e.isToken()?l.$isElementNode(e)&&(e.__children=e.__children.slice(g?d:0,g?void 0:(d||0)+1)):e.__text=e.__text.slice(g?d:0,g?b:d);if(l.$isRootNode(c)){m&&k.push(h);break}}d=f.get(c.getKey());d=l.$isElementNode(d)? | ||
d.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}} | ||
function x(a){if(k.$isRangeSelection(a)){var c=a.anchor,b=a.focus;const [g,m]=a.getCharacterOffsets();a=a.getNodes();if(0===a.length)return{nodeMap:[],range:[]};let n=a.length;var e=a[0],l=e.getParent();if(null!==l&&(!l.canBeEmpty()||k.$isRootNode(l))){var f=l.__children;if(f.length===n){var d=!0;for(var h=0;h<f.length;h++)if(f[h]!==a[h].__key){d=!1;break}d&&(n++,a.push(l))}}l=a[n-1];c=c.isBefore(b);b=new Map;f=[];d=k.$isTextNode(e)&&1===n;w(e,c?g:m,d?c?m:g:void 0,!0,f,b);for(e=0;e<n;e++){h=a[e]; | ||
const r=h.getKey();if(!(b.has(r)||k.$isElementNode(h)&&h.excludeFromCopy())){const p=v(h);k.$isRootNode(h.getParent())&&f.push(h.getKey());"root"!==r&&b.set(r,p)}}w(l,d?void 0:c?m:g,void 0,!1,f,b);return{nodeMap:Array.from(b.entries()),range:f}}if(k.$isGridSelection(a))return{nodeMap:a.getNodes().map(g=>{const m=g.getKey();g=v(g);return[m,g]}),range:[a.gridKey]};throw Error("Minified Lexical error #68; 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"===(k.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function C(a){for(;null!==a&&!k.$isRootNode(a);){const c=a.getLatest(),b=a.getParent();0===c.__children.length&&a.remove(!0);a=b}}exports.$cloneContents=function(a){return x(a)}; | ||
exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let e=null;const l=a.getNodes();var f=a.anchor,d=a.focus,h=a.isBackward();a=h?d.offset:f.offset;f=h?d.getNode():f.getNode();for(d=0;d<l.length;d++){var g=l[d];if((0===d||0!==a||!g.is(f))&&k.$isTextNode(g)){h=c;var m=b;g=g.getStyle();g=y(g);h=null!==g?g[h]||m:m;if(null===e)e=h;else if(e!==h){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){const e=B(a);A(a,c,b?!e:e,"character")}; | ||
exports.$patchStyleText=function(a,c){var b=a.getNodes();const e=b.length-1;let l=b[0],f=b[e];if(!a.isCollapsed()){var d=a.anchor,h=a.focus;a=l.getTextContent().length;var g=h.offset,m=d.offset;d=(h=d.isBefore(h))?m:g;h=h?g:m;if(d===l.getTextContentSize()){const n=l.getNextSibling();k.$isTextNode(n)&&(d=m=0,l=n)}if(l.is(f))k.$isTextNode(l)&&(d=m>g?g:m,h=m>g?m:g,d!==h&&(0===d&&h===a?(z(l,c),l.select(d,h)):(b=l.splitText(d,h),b=0===d?b[0]:b[1],z(b,c),b.select(0,h-d))));else for(k.$isTextNode(l)&&(0!== | ||
d&&([,l]=l.splitText(d)),z(l,c)),k.$isTextNode(f)&&(a=f.getTextContent().length,h!==a&&([f]=f.splitText(h)),0!==h&&z(f,c)),a=1;a<e;a++)g=b[a],m=g.getKey(),k.$isTextNode(g)&&m!==l.getKey()&&m!==f.getKey()&&!g.isToken()&&z(g,c)}}; | ||
exports.$selectAll=function(a){const c=a.anchor;a=a.focus;var b=c.getNode().getTopLevelElementOrThrow().getParentOrThrow();let e=b.getFirstDescendant();b=b.getLastDescendant();let l="element",f="element",d=0;k.$isTextNode(e)?l="text":k.$isElementNode(e)||null===e||(e=e.getParentOrThrow());k.$isTextNode(b)?(f="text",d=b.getTextContentSize()):k.$isElementNode(b)||null===b||(b=b.getParentOrThrow(),d=b.getChildrenSize());e&&b&&(c.set(e.getKey(),0,l),a.set(b.getKey(),d,f))}; | ||
exports.$shouldOverrideDefaultCharacterSelection=function(a,c){a=k.$getDecoratorNode(a.focus,c);return k.$isDecoratorNode(a)&&!a.isIsolated()}; | ||
exports.$wrapLeafNodesInElements=function(a,c,b){const e=a.getNodes(),l=e.length;var f=a.anchor;if(0===l||1===l&&"element"===f.type&&0===f.getNode().getChildrenSize()){a="text"===f.type?f.getNode().getParentOrThrow():f.getNode();f=a.getChildren();let q=c();f.forEach(u=>q.append(u));b&&(q=b.append(q));a.replace(q)}else{var d=e[0],h=new Map;f=[];d=k.$isElementNode(d)?d:d.getParentOrThrow();for(d.isInline()&&(d=d.getParentOrThrow());null!==d;){var g=d.getPreviousSibling();if(null!==g){d=g;break}d=d.getParentOrThrow(); | ||
if(k.$isRootNode(d))break}g=new Set;for(var m=0;m<l;m++){var n=e[m];k.$isElementNode(n)&&0===n.getChildrenSize()&&g.add(n.getKey())}var r=new Set;for(m=0;m<l;m++){var p=e[m];n=p.getParent();null!==n&&n.isInline()&&(n=n.getParent());if(null!==n&&k.$isLeafNode(p)&&!r.has(p.getKey())){if(p=n.getKey(),void 0===h.get(p)){const q=c();f.push(q);h.set(p,q);n.getChildren().forEach(u=>{q.append(u);r.add(u.getKey())});C(n)}}else g.has(p.getKey())&&(f.push(c()),p.remove())}if(b)for(c=0;c<f.length;c++)b.append(f[c]); | ||
if(k.$isRootNode(d))if(c=d.getFirstChild(),k.$isElementNode(c)&&(d=c),null===c)if(b)d.append(b);else for(b=0;b<f.length;b++)d.append(f[b]);else if(b)c.insertBefore(b);else for(b=0;b<f.length;b++)c.insertBefore(f[b]);else if(b)d.insertAfter(b);else for(b=f.length-1;0<=b;b--)d.insertAfter(f[b]);b=k.$getPreviousSelection();k.$isRangeSelection(b)&&b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()?(a=b.clone(),a.dirty=!0,k.$setSelection(a)):a.dirty=!0}};exports.getStyleObjectFromCSS=y; | ||
function x(a){if(l.$isRangeSelection(a)){var c=a.anchor,b=a.focus;const [e,m]=a.getCharacterOffsets();a=a.getNodes();if(0===a.length)return{nodeMap:[],range:[]};let n=a.length;var g=a[0],k=g.getParent();if(null!==k&&(!k.canBeEmpty()||l.$isRootNode(k))){var f=k.__children;if(f.length===n){var d=!0;for(var h=0;h<f.length;h++)if(f[h]!==a[h].__key){d=!1;break}d&&(n++,a.push(k))}}k=a[n-1];c=c.isBefore(b);b=new Map;f=[];d=l.$isTextNode(g)&&1===n;w(g,c?e:m,d?c?m:e:void 0,!0,f,b);for(g=0;g<n;g++){h=a[g]; | ||
const r=h.getKey();if(!(b.has(r)||l.$isElementNode(h)&&h.excludeFromCopy("clone"))){const p=u(h);l.$isRootNode(h.getParent())&&f.push(h.getKey());"root"!==r&&b.set(r,p)}}w(k,d?void 0:c?m:e,void 0,!1,f,b);return{nodeMap:Array.from(b.entries()),range:f}}if(l.$isGridSelection(a))return{nodeMap:a.getNodes().map(e=>{const m=e.getKey();e=u(e);return[m,e]}),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(g in c)g&&(b+=`${g}: ${c[g]};`);var g=b;a.setStyle(g);t.set(g,c)}function A(a,c,b,g){a.modify(c?"extend":"move",b,g)}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);){const c=a.getLatest(),b=a.getParent();0===c.__children.length&&a.remove(!0);a=b}} | ||
function D(a){for(;null!=a;){if(3===a.nodeType)return a;a=a.firstChild}return null}function E(a){const c=a.parentNode;if(null==c)throw Error("Should never happen");return[c,Array.from(c.childNodes).indexOf(a)]}exports.$cloneContents=function(a){return x(a)};exports.$cloneWithProperties=u; | ||
exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let g=null;const k=a.getNodes();var f=a.anchor,d=a.focus,h=a.isBackward();a=h?d.offset:f.offset;f=h?d.getNode():f.getNode();for(d=0;d<k.length;d++){var e=k[d];if((0===d||0!==a||!e.is(f))&&l.$isTextNode(e)){h=c;var m=b;e=e.getStyle();e=y(e);h=null!==e?e[h]||m:m;if(null===g)g=h;else if(g!==h){g="";break}}}return null===g?b:g};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){const g=B(a);A(a,c,b?!g:g,"character")}; | ||
exports.$patchStyleText=function(a,c){var b=a.getNodes();const g=b.length-1;let k=b[0],f=b[g];if(!a.isCollapsed()){var d=a.anchor,h=a.focus;a=k.getTextContent().length;var e=h.offset,m=d.offset;d=(h=d.isBefore(h))?m:e;h=h?e:m;if(d===k.getTextContentSize()){const n=k.getNextSibling();l.$isTextNode(n)&&(d=m=0,k=n)}if(k.is(f))l.$isTextNode(k)&&(d=m>e?e:m,h=m>e?m:e,d!==h&&(0===d&&h===a?(z(k,c),k.select(d,h)):(b=k.splitText(d,h),b=0===d?b[0]:b[1],z(b,c),b.select(0,h-d))));else for(l.$isTextNode(k)&&(0!== | ||
d&&([,k]=k.splitText(d)),z(k,c)),l.$isTextNode(f)&&(a=f.getTextContent().length,h!==a&&([f]=f.splitText(h)),0!==h&&z(f,c)),a=1;a<g;a++)e=b[a],m=e.getKey(),l.$isTextNode(e)&&m!==k.getKey()&&m!==f.getKey()&&!e.isToken()&&z(e,c)}}; | ||
exports.$selectAll=function(a){const c=a.anchor;a=a.focus;var b=c.getNode().getTopLevelElementOrThrow().getParentOrThrow();let g=b.getFirstDescendant();b=b.getLastDescendant();let k="element",f="element",d=0;l.$isTextNode(g)?k="text":l.$isElementNode(g)||null===g||(g=g.getParentOrThrow());l.$isTextNode(b)?(f="text",d=b.getTextContentSize()):l.$isElementNode(b)||null===b||(b=b.getParentOrThrow(),d=b.getChildrenSize());g&&b&&(c.set(g.getKey(),0,k),a.set(b.getKey(),d,f))}; | ||
exports.$shouldOverrideDefaultCharacterSelection=function(a,c){a=l.$getDecoratorNode(a.focus,c);return l.$isDecoratorNode(a)&&!a.isIsolated()}; | ||
exports.$wrapLeafNodesInElements=function(a,c,b){const g=a.getNodes(),k=g.length;var f=a.anchor;if(0===k||1===k&&"element"===f.type&&0===f.getNode().getChildrenSize()){a="text"===f.type?f.getNode().getParentOrThrow():f.getNode();f=a.getChildren();let q=c();f.forEach(v=>q.append(v));b&&(q=b.append(q));a.replace(q)}else{var d=g[0],h=new Map;f=[];d=l.$isElementNode(d)?d:d.getParentOrThrow();for(d.isInline()&&(d=d.getParentOrThrow());null!==d;){var e=d.getPreviousSibling();if(null!==e){d=e;break}d=d.getParentOrThrow(); | ||
if(l.$isRootNode(d))break}e=new Set;for(var m=0;m<k;m++){var n=g[m];l.$isElementNode(n)&&0===n.getChildrenSize()&&e.add(n.getKey())}var r=new Set;for(m=0;m<k;m++){var p=g[m];n=p.getParent();null!==n&&n.isInline()&&(n=n.getParent());if(null!==n&&l.$isLeafNode(p)&&!r.has(p.getKey())){if(p=n.getKey(),void 0===h.get(p)){const q=c();f.push(q);h.set(p,q);n.getChildren().forEach(v=>{q.append(v);r.add(v.getKey())});C(n)}}else e.has(p.getKey())&&(f.push(c()),p.remove())}if(b)for(c=0;c<f.length;c++)b.append(f[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<f.length;b++)d.append(f[b]);else if(b)c.insertBefore(b);else for(b=0;b<f.length;b++)c.insertBefore(f[b]);else if(b)d.insertAfter(b);else for(b=f.length-1;0<=b;b--)d.insertAfter(f[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,g,k){const f=c.getKey(),d=g.getKey(),h=document.createRange();let e=a.getElementByKey(f);a=a.getElementByKey(d);l.$isTextNode(c)&&(e=D(e));l.$isTextNode(g)&&(a=D(a));if(void 0===c||void 0===g||null===e||null===a)return null;"BR"===e.nodeName&&([e,b]=E(e));"BR"===a.nodeName&&([a,k]=E(a));c=e.firstChild;e===a&&null!=c&&"BR"===c.nodeName&&0===b&&0===k&&(k=1);try{h.setStart(e,b),h.setEnd(a,k)}catch(m){return null}!h.collapsed||b===k&&f===d||(h.setStart(a,k),h.setEnd(e, | ||
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 g=c.length,k;for(let f=0;f<g;f++){const d=c[f],h=d.width+b===a.width;k&&k.top===d.top&&k.left===d.left&&k.width===d.width&&k.height===d.height||h?(c.splice(f--,1),g--):k=d}return c};exports.getStyleObjectFromCSS=y; |
@@ -12,6 +12,6 @@ { | ||
"license": "MIT", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"main": "LexicalSelection.js", | ||
"peerDependencies": { | ||
"lexical": "0.2.5" | ||
"lexical": "0.2.6" | ||
}, | ||
@@ -18,0 +18,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
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
39266
721