@lexical/selection
Advanced tools
Comparing version 0.21.1-nightly.20241206.0 to 0.21.1-nightly.20241209.0
@@ -9,10 +9,11 @@ /** | ||
import { $addNodeStyle, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor } from './lexical-node'; | ||
import { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $selectAll, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes } from './range-selection'; | ||
import { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes } from './range-selection'; | ||
import { createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, getStyleObjectFromCSS } from './utils'; | ||
export { | ||
/** @deprecated moved to the lexical package */ $cloneWithProperties, } from 'lexical'; | ||
/** @deprecated moved to the lexical package */ $cloneWithProperties, | ||
/** @deprecated moved to the lexical package */ $selectAll, } from 'lexical'; | ||
export { $addNodeStyle, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, }; | ||
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */ | ||
export declare const trimTextContentFromAnchor: typeof $trimTextContentFromAnchor; | ||
export { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $selectAll, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes, }; | ||
export { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes, }; | ||
export { createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, getStyleObjectFromCSS, }; |
@@ -830,34 +830,2 @@ /** | ||
/** | ||
* Expands the current Selection to cover all of the content in the editor. | ||
* @param selection - The current selection. | ||
*/ | ||
function $selectAll(selection) { | ||
const anchor = selection.anchor; | ||
const focus = selection.focus; | ||
const anchorNode = anchor.getNode(); | ||
const topParent = anchorNode.getTopLevelElementOrThrow(); | ||
const root = topParent.getParentOrThrow(); | ||
let firstNode = root.getFirstDescendant(); | ||
let lastNode = root.getLastDescendant(); | ||
let firstType = 'element'; | ||
let lastType = 'element'; | ||
let lastOffset = 0; | ||
if (lexical.$isTextNode(firstNode)) { | ||
firstType = 'text'; | ||
} else if (!lexical.$isElementNode(firstNode) && firstNode !== null) { | ||
firstNode = firstNode.getParentOrThrow(); | ||
} | ||
if (lexical.$isTextNode(lastNode)) { | ||
lastType = 'text'; | ||
lastOffset = lastNode.getTextContentSize(); | ||
} else if (!lexical.$isElementNode(lastNode) && lastNode !== null) { | ||
lastNode = lastNode.getParentOrThrow(); | ||
} | ||
if (firstNode && lastNode) { | ||
anchor.set(firstNode.getKey(), 0, firstType); | ||
focus.set(lastNode.getKey(), lastOffset, lastType); | ||
} | ||
} | ||
/** | ||
* Returns the current value of a CSS property for Nodes, if set. If not set, it returns the defaultValue. | ||
@@ -960,2 +928,3 @@ * @param node - The node whose style value to get. | ||
exports.$cloneWithProperties = lexical.$cloneWithProperties; | ||
exports.$selectAll = lexical.$selectAll; | ||
exports.$addNodeStyle = $addNodeStyle; | ||
@@ -968,3 +937,2 @@ exports.$getSelectionStyleValueForProperty = $getSelectionStyleValueForProperty; | ||
exports.$patchStyleText = $patchStyleText; | ||
exports.$selectAll = $selectAll; | ||
exports.$setBlocksType = $setBlocksType; | ||
@@ -971,0 +939,0 @@ exports.$shouldOverrideDefaultCharacterSelection = $shouldOverrideDefaultCharacterSelection; |
@@ -9,27 +9,26 @@ /** | ||
'use strict';var k=require("lexical"),u;function w(a){let d=new URLSearchParams;d.append("code",a);for(let b=1;b<arguments.length;b++)d.append("v",arguments[b]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${d} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}u=w&&w.__esModule&&Object.prototype.hasOwnProperty.call(w,"default")?w["default"]:w;let x=new Map; | ||
function y(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function z(a){let d=a.parentNode;if(null==d)throw Error("Should never happen");return[d,Array.from(d.childNodes).indexOf(a)]}function B(a){let d={};if(!a)return d;a=a.split(";");for(let b of a)if(""!==b){let [e,c]=b.split(/:([^]+)/);e&&c&&(d[e.trim()]=c.trim())}return d}function C(a){let d=x.get(a);void 0===d&&(d=B(a),x.set(a,d));return d} | ||
function D(a){let d="";for(let b in a)b&&(d+=`${b}: ${a[b]};`);return d} | ||
function E(a,d,b){let e=d.getNode();if(k.$isElementNode(e)){var c=e.getDescendantByIndex(d.offset);null!==c&&(e=c)}for(;0<b&&null!==e;){k.$isElementNode(e)&&(c=e.getLastDescendant(),null!==c&&(e=c));var g=e.getPreviousSibling(),h=0;if(null===g){c=e.getParentOrThrow();for(var f=c.getPreviousSibling();null===f;){c=c.getParent();if(null===c){g=null;break}f=c.getPreviousSibling()}null!==c&&(h=c.isInline()?0:2,g=f)}f=e.getTextContent();""===f&&k.$isElementNode(e)&&!e.isInline()&&(f="\n\n");c=f.length; | ||
if(!k.$isTextNode(e)||b>=c)f=e.getParent(),e.remove(),null==f||0!==f.getChildrenSize()||k.$isRootNode(f)||f.remove(),b-=c+h,e=g;else{let l=e.getKey();h=a.getEditorState().read(()=>{const p=k.$getNodeByKey(l);return k.$isTextNode(p)&&p.isSimpleText()?p.getTextContent():null});g=c-b;let m=f.slice(0,g);null!==h&&h!==f?(b=k.$getPreviousSelection(),c=e,e.isSimpleText()?e.setTextContent(h):(c=k.$createTextNode(h),e.replace(c)),k.$isRangeSelection(b)&&b.isCollapsed()&&(b=b.anchor.offset,c.select(b,b))): | ||
e.isSimpleText()?(h=d.key===l,f=d.offset,f<b&&(f=c),b=h?f-b:0,c=h?f:g,h&&0===b?([b]=e.splitText(b,c),b.remove()):([,b]=e.splitText(b,c),b.remove())):(b=k.$createTextNode(m),e.replace(b));b=0}}}function F(a,d){let b=C("getStyle"in a?a.getStyle():a.style);d=Object.entries(d).reduce((c,[g,h])=>{"function"===typeof h?c[g]=h(b[g],a):null===h?delete c[g]:c[g]=h;return c},{...b});let e=D(d);a.setStyle(e);x.set(e,d)} | ||
function G(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let d=a.getLatest(),b=a.getParent();0===d.getChildrenSize()&&a.remove(!0);a=b}} | ||
function H(a,d,b,e,c=null){if(0!==d.length){var g=d[0],h=new Map,f=[];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<b;p++){var q=d[p];k.$isElementNode(q)&&0===q.getChildrenSize()&&m.add(q.getKey())}var n=new Set;for(p=0;p<b;p++){q=d[p];var r=q.getParent();null!==r&&r.isInline()&&(r=r.getParent());if(null!== | ||
r&&k.$isLeafNode(q)&&!n.has(q.getKey())){if(q=r.getKey(),void 0===h.get(q)){let t=e();t.setFormat(r.getFormatType());t.setIndent(r.getIndent());f.push(t);h.set(q,t);r.getChildren().forEach(v=>{t.append(v);n.add(v.getKey());k.$isElementNode(v)&&v.getChildrenKeys().forEach(A=>n.add(A))});G(r)}}else m.has(q.getKey())&&(k.$isElementNode(q)||u(179),r=e(),r.setFormat(q.getFormatType()),r.setIndent(q.getIndent()),f.push(r),q.remove(!0))}if(null!==c)for(d=0;d<f.length;d++)c.append(f[d]);d=null;if(k.$isRootOrShadowRoot(g))if(l)if(null!== | ||
c)g.insertAfter(c);else for(c=f.length-1;0<=c;c--)g.insertAfter(f[c]);else if(l=g.getFirstChild(),k.$isElementNode(l)&&(g=l),null===l)if(c)g.append(c);else for(c=0;c<f.length;c++)l=f[c],g.append(l),d=l;else if(null!==c)l.insertBefore(c);else for(g=0;g<f.length;g++)c=f[g],l.insertBefore(c),d=c;else if(c)g.insertAfter(c);else for(c=f.length-1;0<=c;c--)l=f[c],g.insertAfter(l),d=l;f=k.$getPreviousSelection();k.$isRangeSelection(f)&&f.anchor.getNode().isAttached()&&f.focus.getNode().isAttached()?k.$setSelection(f.clone()): | ||
null!==d?d.selectEnd():a.dirty=!0}}function I(a,d,b,e){a.modify(d?"extend":"move",b,e)}function J(a){a=a.anchor.getNode();return"rtl"===(k.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function K(a){if(k.$isDecoratorNode(a)||!k.$isElementNode(a)||k.$isRootOrShadowRoot(a))return!1;var d=a.getFirstChild();d=null===d||k.$isLineBreakNode(d)||k.$isTextNode(d)||d.isInline();return!a.isInline()&&!1!==a.canBeEmpty()&&d}exports.$cloneWithProperties=k.$cloneWithProperties; | ||
'use strict';var k=require("lexical"),u;function w(a){let d=new URLSearchParams;d.append("code",a);for(let c=1;c<arguments.length;c++)d.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${d} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}u=w&&w.__esModule&&Object.prototype.hasOwnProperty.call(w,"default")?w["default"]:w;let x=new Map; | ||
function y(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function z(a){let d=a.parentNode;if(null==d)throw Error("Should never happen");return[d,Array.from(d.childNodes).indexOf(a)]}function B(a){let d={};if(!a)return d;a=a.split(";");for(let c of a)if(""!==c){let [e,b]=c.split(/:([^]+)/);e&&b&&(d[e.trim()]=b.trim())}return d}function C(a){let d=x.get(a);void 0===d&&(d=B(a),x.set(a,d));return d} | ||
function D(a){let d="";for(let c in a)c&&(d+=`${c}: ${a[c]};`);return d} | ||
function E(a,d,c){let e=d.getNode();if(k.$isElementNode(e)){var b=e.getDescendantByIndex(d.offset);null!==b&&(e=b)}for(;0<c&&null!==e;){k.$isElementNode(e)&&(b=e.getLastDescendant(),null!==b&&(e=b));var g=e.getPreviousSibling(),h=0;if(null===g){b=e.getParentOrThrow();for(var f=b.getPreviousSibling();null===f;){b=b.getParent();if(null===b){g=null;break}f=b.getPreviousSibling()}null!==b&&(h=b.isInline()?0:2,g=f)}f=e.getTextContent();""===f&&k.$isElementNode(e)&&!e.isInline()&&(f="\n\n");b=f.length; | ||
if(!k.$isTextNode(e)||c>=b)f=e.getParent(),e.remove(),null==f||0!==f.getChildrenSize()||k.$isRootNode(f)||f.remove(),c-=b+h,e=g;else{let l=e.getKey();h=a.getEditorState().read(()=>{const p=k.$getNodeByKey(l);return k.$isTextNode(p)&&p.isSimpleText()?p.getTextContent():null});g=b-c;let m=f.slice(0,g);null!==h&&h!==f?(c=k.$getPreviousSelection(),b=e,e.isSimpleText()?e.setTextContent(h):(b=k.$createTextNode(h),e.replace(b)),k.$isRangeSelection(c)&&c.isCollapsed()&&(c=c.anchor.offset,b.select(c,c))): | ||
e.isSimpleText()?(h=d.key===l,f=d.offset,f<c&&(f=b),c=h?f-c:0,b=h?f:g,h&&0===c?([c]=e.splitText(c,b),c.remove()):([,c]=e.splitText(c,b),c.remove())):(c=k.$createTextNode(m),e.replace(c));c=0}}}function F(a,d){let c=C("getStyle"in a?a.getStyle():a.style);d=Object.entries(d).reduce((b,[g,h])=>{"function"===typeof h?b[g]=h(c[g],a):null===h?delete b[g]:b[g]=h;return b},{...c});let e=D(d);a.setStyle(e);x.set(e,d)} | ||
function G(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let d=a.getLatest(),c=a.getParent();0===d.getChildrenSize()&&a.remove(!0);a=c}} | ||
function H(a,d,c,e,b=null){if(0!==d.length){var g=d[0],h=new Map,f=[];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<c;p++){var q=d[p];k.$isElementNode(q)&&0===q.getChildrenSize()&&m.add(q.getKey())}var n=new Set;for(p=0;p<c;p++){q=d[p];var r=q.getParent();null!==r&&r.isInline()&&(r=r.getParent());if(null!== | ||
r&&k.$isLeafNode(q)&&!n.has(q.getKey())){if(q=r.getKey(),void 0===h.get(q)){let t=e();t.setFormat(r.getFormatType());t.setIndent(r.getIndent());f.push(t);h.set(q,t);r.getChildren().forEach(v=>{t.append(v);n.add(v.getKey());k.$isElementNode(v)&&v.getChildrenKeys().forEach(A=>n.add(A))});G(r)}}else m.has(q.getKey())&&(k.$isElementNode(q)||u(179),r=e(),r.setFormat(q.getFormatType()),r.setIndent(q.getIndent()),f.push(r),q.remove(!0))}if(null!==b)for(d=0;d<f.length;d++)b.append(f[d]);d=null;if(k.$isRootOrShadowRoot(g))if(l)if(null!== | ||
b)g.insertAfter(b);else for(b=f.length-1;0<=b;b--)g.insertAfter(f[b]);else if(l=g.getFirstChild(),k.$isElementNode(l)&&(g=l),null===l)if(b)g.append(b);else for(b=0;b<f.length;b++)l=f[b],g.append(l),d=l;else if(null!==b)l.insertBefore(b);else for(g=0;g<f.length;g++)b=f[g],l.insertBefore(b),d=b;else if(b)g.insertAfter(b);else for(b=f.length-1;0<=b;b--)l=f[b],g.insertAfter(l),d=l;f=k.$getPreviousSelection();k.$isRangeSelection(f)&&f.anchor.getNode().isAttached()&&f.focus.getNode().isAttached()?k.$setSelection(f.clone()): | ||
null!==d?d.selectEnd():a.dirty=!0}}function I(a,d,c,e){a.modify(d?"extend":"move",c,e)}function J(a){a=a.anchor.getNode();return"rtl"===(k.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function K(a){if(k.$isDecoratorNode(a)||!k.$isElementNode(a)||k.$isRootOrShadowRoot(a))return!1;var d=a.getFirstChild();d=null===d||k.$isLineBreakNode(d)||k.$isTextNode(d)||d.isInline();return!a.isInline()&&!1!==a.canBeEmpty()&&d}exports.$cloneWithProperties=k.$cloneWithProperties;exports.$selectAll=k.$selectAll; | ||
exports.$addNodeStyle=function(a){a=a.getStyle();let d=B(a);x.set(a,d)}; | ||
exports.$getSelectionStyleValueForProperty=function(a,d,b=""){let e=null,c=a.getNodes();var g=a.anchor,h=a.focus,f=a.isBackward();let l=f?h.offset:g.offset;g=f?h.getNode():g.getNode();if(k.$isRangeSelection(a)&&a.isCollapsed()&&""!==a.style&&(a=C(a.style),null!==a&&d in a))return a[d];for(a=0;a<c.length;a++){var m=c[a];if((0===a||0!==l||!m.is(g))&&k.$isTextNode(m))if(h=d,f=b,m=m.getStyle(),m=C(m),h=null!==m?m[h]||f:f,null===e)e=h;else if(e!==h){e="";break}}return null===e?b:e}; | ||
exports.$isAtNodeEnd=function(a){if("text"===a.type)return a.offset===a.getNode().getTextContentSize();let d=a.getNode();k.$isElementNode(d)||u(177);return a.offset===d.getChildrenSize()};exports.$isParentElementRTL=J;exports.$moveCaretSelection=I;exports.$moveCharacter=function(a,d,b){let e=J(a);I(a,d,b?!e:e,"character")}; | ||
exports.$patchStyleText=function(a,d){var b=a.getNodes(),e=b.length,c=a.getStartEndPoints();if(null!==c){var [g,h]=c;--e;c=b[0];var f=b[e];if(a.isCollapsed()&&k.$isRangeSelection(a))F(a,d);else{var l=c.getTextContent().length,m=h.offset,p=g.offset,q=g.isBefore(h),n=q?p:m;a=q?m:p;var r=q?g.type:h.type,t=q?h.type:g.type,v=q?h.key:g.key;if(k.$isTextNode(c)&&n===l){let A=c.getNextSibling();k.$isTextNode(A)&&(n=p=0,c=A)}if(1===b.length)k.$isTextNode(c)&&c.canHaveFormat()&&(n="element"===r?0:p>m?m:p,a= | ||
"element"===t?l:p>m?p:m,n!==a&&(k.$isTokenOrSegmented(c)||0===n&&a===l?(F(c,d),c.select(n,a)):(b=c.splitText(n,a),b=0===n?b[0]:b[1],F(b,d),b.select(0,a-n))));else for(k.$isTextNode(c)&&n<c.getTextContentSize()&&c.canHaveFormat()&&(0===n||k.$isTokenOrSegmented(c)||(c=c.splitText(n)[1],n=0,q?g.set(c.getKey(),n,"text"):h.set(c.getKey(),n,"text")),F(c,d)),k.$isTextNode(f)&&f.canHaveFormat()&&(n=f.getTextContent().length,f.__key!==v&&0!==a&&(a=n),a===n||k.$isTokenOrSegmented(f)||([f]=f.splitText(a)),0=== | ||
a&&"element"!==t||F(f,d)),a=1;a<e;a++)n=b[a],t=n.getKey(),k.$isTextNode(n)&&n.canHaveFormat()&&t!==c.getKey()&&t!==f.getKey()&&!n.isToken()&&F(n,d)}}}; | ||
exports.$selectAll=function(a){let d=a.anchor;a=a.focus;var b=d.getNode().getTopLevelElementOrThrow().getParentOrThrow();let e=b.getFirstDescendant();b=b.getLastDescendant();let c="element",g="element",h=0;k.$isTextNode(e)?c="text":k.$isElementNode(e)||null===e||(e=e.getParentOrThrow());k.$isTextNode(b)?(g="text",h=b.getTextContentSize()):k.$isElementNode(b)||null===b||(b=b.getParentOrThrow());e&&b&&(d.set(e.getKey(),0,c),a.set(b.getKey(),h,g))}; | ||
exports.$setBlocksType=function(a,d){if(null!==a){var b=a.getStartEndPoints();b=b?b[0]:null;if(null!==b&&"root"===b.key)d=d(),a=k.$getRoot(),(b=a.getFirstChild())?b.replace(d,!0):a.append(d);else{a=a.getNodes();if(null!==b){for(b=b.getNode();null!==b&&null!==b.getParent()&&!K(b);)b=b.getParentOrThrow();b=K(b)?b:null}else b=!1;b&&-1===a.indexOf(b)&&a.push(b);for(b=0;b<a.length;b++){let e=a[b];if(!K(e))continue;k.$isElementNode(e)||u(178);let c=d();c.setFormat(e.getFormatType());c.setIndent(e.getIndent()); | ||
e.replace(c,!0)}}}};exports.$shouldOverrideDefaultCharacterSelection=function(a,d){a=k.$getAdjacentNode(a.focus,d);return k.$isDecoratorNode(a)&&!a.isIsolated()||k.$isElementNode(a)&&!a.isInline()&&!a.canBeEmpty()}; | ||
exports.$sliceSelectedTextNodeContent=function(a,d){var b=a.getStartEndPoints();if(d.isSelected(a)&&!d.isSegmented()&&!d.isToken()&&null!==b){let [f,l]=b;b=a.isBackward();var e=f.getNode(),c=l.getNode(),g=d.is(e),h=d.is(c);if(g||h){let [m,p]=k.$getCharacterOffsets(a);a=e.is(c);g=d.is(b?c:e);c=d.is(b?e:c);e=0;h=void 0;a?(e=m>p?p:m,h=m>p?m:p):g?(e=b?p:m,h=void 0):c&&(b=b?m:p,e=0,h=b);d.__text=d.__text.slice(e,h)}}return d};exports.$trimTextContentFromAnchor=E; | ||
exports.$wrapNodes=function(a,d,b=null){var e=a.getStartEndPoints(),c=e?e[0]:null;e=a.getNodes();let g=e.length;if(null!==c&&(0===g||1===g&&"element"===c.type&&0===c.getNode().getChildrenSize())){a="text"===c.type?c.getNode().getParentOrThrow():c.getNode();e=a.getChildren();let f=d();f.setFormat(a.getFormatType());f.setIndent(a.getIndent());e.forEach(l=>f.append(l));b&&(f=b.append(f));a.replace(f)}else{c=null;var h=[];for(let f=0;f<g;f++){let l=e[f];k.$isRootOrShadowRoot(l)?(H(a,h,h.length,d,b),h= | ||
[],c=l):null===c||null!==c&&k.$hasAncestor(l,c)?h.push(l):(H(a,h,h.length,d,b),h=[l])}H(a,h,h.length,d,b)}}; | ||
exports.createDOMRange=function(a,d,b,e,c){let g=d.getKey(),h=e.getKey(),f=document.createRange(),l=a.getElementByKey(g);a=a.getElementByKey(h);k.$isTextNode(d)&&(l=y(l));k.$isTextNode(e)&&(a=y(a));if(void 0===d||void 0===e||null===l||null===a)return null;"BR"===l.nodeName&&([l,b]=z(l));"BR"===a.nodeName&&([a,c]=z(a));d=l.firstChild;l===a&&null!=d&&"BR"===d.nodeName&&0===b&&0===c&&(c=1);try{f.setStart(l,b),f.setEnd(a,c)}catch(m){return null}!f.collapsed||b===c&&g===h||(f.setStart(a,c),f.setEnd(l, | ||
b));return f};exports.createRectsFromDOMRange=function(a,d){var b=a.getRootElement();if(null===b)return[];a=b.getBoundingClientRect();b=getComputedStyle(b);b=parseFloat(b.paddingLeft)+parseFloat(b.paddingRight);d=Array.from(d.getClientRects());let e=d.length;d.sort((g,h)=>{let f=g.top-h.top;return 3>=Math.abs(f)?g.left-h.left:f});let c;for(let g=0;g<e;g++){let h=d[g],f=h.width+b===a.width;c&&c.top<=h.top&&c.top+c.height>h.top&&c.left+c.width>h.left||f?(d.splice(g--,1),e--):c=h}return d}; | ||
exports.$getSelectionStyleValueForProperty=function(a,d,c=""){let e=null,b=a.getNodes();var g=a.anchor,h=a.focus,f=a.isBackward();let l=f?h.offset:g.offset;g=f?h.getNode():g.getNode();if(k.$isRangeSelection(a)&&a.isCollapsed()&&""!==a.style&&(a=C(a.style),null!==a&&d in a))return a[d];for(a=0;a<b.length;a++){var m=b[a];if((0===a||0!==l||!m.is(g))&&k.$isTextNode(m))if(h=d,f=c,m=m.getStyle(),m=C(m),h=null!==m?m[h]||f:f,null===e)e=h;else if(e!==h){e="";break}}return null===e?c:e}; | ||
exports.$isAtNodeEnd=function(a){if("text"===a.type)return a.offset===a.getNode().getTextContentSize();let d=a.getNode();k.$isElementNode(d)||u(177);return a.offset===d.getChildrenSize()};exports.$isParentElementRTL=J;exports.$moveCaretSelection=I;exports.$moveCharacter=function(a,d,c){let e=J(a);I(a,d,c?!e:e,"character")}; | ||
exports.$patchStyleText=function(a,d){var c=a.getNodes(),e=c.length,b=a.getStartEndPoints();if(null!==b){var [g,h]=b;--e;b=c[0];var f=c[e];if(a.isCollapsed()&&k.$isRangeSelection(a))F(a,d);else{var l=b.getTextContent().length,m=h.offset,p=g.offset,q=g.isBefore(h),n=q?p:m;a=q?m:p;var r=q?g.type:h.type,t=q?h.type:g.type,v=q?h.key:g.key;if(k.$isTextNode(b)&&n===l){let A=b.getNextSibling();k.$isTextNode(A)&&(n=p=0,b=A)}if(1===c.length)k.$isTextNode(b)&&b.canHaveFormat()&&(n="element"===r?0:p>m?m:p,a= | ||
"element"===t?l:p>m?p:m,n!==a&&(k.$isTokenOrSegmented(b)||0===n&&a===l?(F(b,d),b.select(n,a)):(c=b.splitText(n,a),c=0===n?c[0]:c[1],F(c,d),c.select(0,a-n))));else for(k.$isTextNode(b)&&n<b.getTextContentSize()&&b.canHaveFormat()&&(0===n||k.$isTokenOrSegmented(b)||(b=b.splitText(n)[1],n=0,q?g.set(b.getKey(),n,"text"):h.set(b.getKey(),n,"text")),F(b,d)),k.$isTextNode(f)&&f.canHaveFormat()&&(n=f.getTextContent().length,f.__key!==v&&0!==a&&(a=n),a===n||k.$isTokenOrSegmented(f)||([f]=f.splitText(a)),0=== | ||
a&&"element"!==t||F(f,d)),a=1;a<e;a++)n=c[a],t=n.getKey(),k.$isTextNode(n)&&n.canHaveFormat()&&t!==b.getKey()&&t!==f.getKey()&&!n.isToken()&&F(n,d)}}}; | ||
exports.$setBlocksType=function(a,d){if(null!==a){var c=a.getStartEndPoints();c=c?c[0]:null;if(null!==c&&"root"===c.key)d=d(),a=k.$getRoot(),(c=a.getFirstChild())?c.replace(d,!0):a.append(d);else{a=a.getNodes();if(null!==c){for(c=c.getNode();null!==c&&null!==c.getParent()&&!K(c);)c=c.getParentOrThrow();c=K(c)?c:null}else c=!1;c&&-1===a.indexOf(c)&&a.push(c);for(c=0;c<a.length;c++){let e=a[c];if(!K(e))continue;k.$isElementNode(e)||u(178);let b=d();b.setFormat(e.getFormatType());b.setIndent(e.getIndent()); | ||
e.replace(b,!0)}}}};exports.$shouldOverrideDefaultCharacterSelection=function(a,d){a=k.$getAdjacentNode(a.focus,d);return k.$isDecoratorNode(a)&&!a.isIsolated()||k.$isElementNode(a)&&!a.isInline()&&!a.canBeEmpty()}; | ||
exports.$sliceSelectedTextNodeContent=function(a,d){var c=a.getStartEndPoints();if(d.isSelected(a)&&!d.isSegmented()&&!d.isToken()&&null!==c){let [f,l]=c;c=a.isBackward();var e=f.getNode(),b=l.getNode(),g=d.is(e),h=d.is(b);if(g||h){let [m,p]=k.$getCharacterOffsets(a);a=e.is(b);g=d.is(c?b:e);b=d.is(c?e:b);e=0;h=void 0;a?(e=m>p?p:m,h=m>p?m:p):g?(e=c?p:m,h=void 0):b&&(c=c?m:p,e=0,h=c);d.__text=d.__text.slice(e,h)}}return d};exports.$trimTextContentFromAnchor=E; | ||
exports.$wrapNodes=function(a,d,c=null){var e=a.getStartEndPoints(),b=e?e[0]:null;e=a.getNodes();let g=e.length;if(null!==b&&(0===g||1===g&&"element"===b.type&&0===b.getNode().getChildrenSize())){a="text"===b.type?b.getNode().getParentOrThrow():b.getNode();e=a.getChildren();let f=d();f.setFormat(a.getFormatType());f.setIndent(a.getIndent());e.forEach(l=>f.append(l));c&&(f=c.append(f));a.replace(f)}else{b=null;var h=[];for(let f=0;f<g;f++){let l=e[f];k.$isRootOrShadowRoot(l)?(H(a,h,h.length,d,c),h= | ||
[],b=l):null===b||null!==b&&k.$hasAncestor(l,b)?h.push(l):(H(a,h,h.length,d,c),h=[l])}H(a,h,h.length,d,c)}}; | ||
exports.createDOMRange=function(a,d,c,e,b){let g=d.getKey(),h=e.getKey(),f=document.createRange(),l=a.getElementByKey(g);a=a.getElementByKey(h);k.$isTextNode(d)&&(l=y(l));k.$isTextNode(e)&&(a=y(a));if(void 0===d||void 0===e||null===l||null===a)return null;"BR"===l.nodeName&&([l,c]=z(l));"BR"===a.nodeName&&([a,b]=z(a));d=l.firstChild;l===a&&null!=d&&"BR"===d.nodeName&&0===c&&0===b&&(b=1);try{f.setStart(l,c),f.setEnd(a,b)}catch(m){return null}!f.collapsed||c===b&&g===h||(f.setStart(a,b),f.setEnd(l, | ||
c));return f};exports.createRectsFromDOMRange=function(a,d){var c=a.getRootElement();if(null===c)return[];a=c.getBoundingClientRect();c=getComputedStyle(c);c=parseFloat(c.paddingLeft)+parseFloat(c.paddingRight);d=Array.from(d.getClientRects());let e=d.length;d.sort((g,h)=>{let f=g.top-h.top;return 3>=Math.abs(f)?g.left-h.left:f});let b;for(let g=0;g<e;g++){let h=d[g],f=h.width+c===a.width;b&&b.top<=h.top&&b.top+b.height>h.top&&b.left+b.width>h.left||f?(d.splice(g--,1),e--):b=h}return d}; | ||
exports.getCSSFromStyleObject=D;exports.getStyleObjectFromCSS=C;exports.trimTextContentFromAnchor=E |
@@ -12,3 +12,3 @@ { | ||
"license": "MIT", | ||
"version": "0.21.1-nightly.20241206.0", | ||
"version": "0.21.1-nightly.20241209.0", | ||
"main": "LexicalSelection.js", | ||
@@ -41,4 +41,4 @@ "types": "index.d.ts", | ||
"dependencies": { | ||
"lexical": "0.21.1-nightly.20241206.0" | ||
"lexical": "0.21.1-nightly.20241209.0" | ||
} | ||
} |
@@ -63,7 +63,2 @@ /** | ||
/** | ||
* Expands the current Selection to cover all of the content in the editor. | ||
* @param selection - The current selection. | ||
*/ | ||
export declare function $selectAll(selection: RangeSelection): void; | ||
/** | ||
* Returns the current value of a CSS property for TextNodes in the Selection, if set. If not set, it returns the defaultValue. | ||
@@ -70,0 +65,0 @@ * If all TextNodes do not have the same value, it returns an empty string. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
109391
2136
+ Addedlexical@0.21.1-nightly.20241209.0(transitive)
- Removedlexical@0.21.1-nightly.20241206.0(transitive)