@lexical/selection
Advanced tools
Comparing version 0.21.1-nightly.20241220.0 to 0.21.1-nightly.20241223.0
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
import { $addNodeStyle, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor } from './lexical-node'; | ||
import { $addNodeStyle, $forEachSelectedTextNode, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor } from './lexical-node'; | ||
import { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes } from './range-selection'; | ||
@@ -15,3 +15,3 @@ import { createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, getStyleObjectFromCSS } from './utils'; | ||
/** @deprecated moved to the lexical package */ $selectAll, } from 'lexical'; | ||
export { $addNodeStyle, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, }; | ||
export { $addNodeStyle, $forEachSelectedTextNode, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, }; | ||
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */ | ||
@@ -18,0 +18,0 @@ export declare const trimTextContentFromAnchor: typeof $trimTextContentFromAnchor; |
@@ -45,1 +45,2 @@ /** | ||
export declare function $patchStyleText(selection: BaseSelection, patch: Record<string, string | null | ((currentStyleValue: string | null, target: TextNode | RangeSelection) => string)>): void; | ||
export declare function $forEachSelectedTextNode(fn: (textNode: TextNode) => void): void; |
@@ -410,16 +410,24 @@ /** | ||
function $patchStyleText(selection, patch) { | ||
if (selection.isCollapsed() && lexical.$isRangeSelection(selection)) { | ||
$patchStyle(selection, patch); | ||
} else { | ||
$forEachSelectedTextNode(textNode => { | ||
$patchStyle(textNode, patch); | ||
}); | ||
} | ||
} | ||
function $forEachSelectedTextNode(fn) { | ||
const selection = lexical.$getSelection(); | ||
if (!lexical.$isRangeSelection(selection)) { | ||
return; | ||
} | ||
const selectedNodes = selection.getNodes(); | ||
const selectedNodesLength = selectedNodes.length; | ||
const anchorAndFocus = selection.getStartEndPoints(); | ||
if (anchorAndFocus === null) { | ||
return; | ||
} | ||
const [anchor, focus] = anchorAndFocus; | ||
const { | ||
anchor, | ||
focus | ||
} = selection; | ||
const lastIndex = selectedNodesLength - 1; | ||
let firstNode = selectedNodes[0]; | ||
let lastNode = selectedNodes[lastIndex]; | ||
if (selection.isCollapsed() && lexical.$isRangeSelection(selection)) { | ||
$patchStyle(selection, patch); | ||
return; | ||
} | ||
const firstNodeText = firstNode.getTextContent(); | ||
@@ -461,3 +469,3 @@ const firstNodeTextLength = firstNodeText.length; | ||
if (lexical.$isTokenOrSegmented(firstNode) || startOffset === 0 && endOffset === firstNodeTextLength) { | ||
$patchStyle(firstNode, patch); | ||
fn(firstNode); | ||
firstNode.select(startOffset, endOffset); | ||
@@ -469,3 +477,3 @@ } else { | ||
const replacement = startOffset === 0 ? splitNodes[0] : splitNodes[1]; | ||
$patchStyle(replacement, patch); | ||
fn(replacement); | ||
replacement.select(0, endOffset - startOffset); | ||
@@ -486,3 +494,3 @@ } | ||
} | ||
$patchStyle(firstNode, patch); | ||
fn(firstNode); | ||
} | ||
@@ -506,3 +514,3 @@ if (lexical.$isTextNode(lastNode) && lastNode.canHaveFormat()) { | ||
if (endOffset !== 0 || endType === 'element') { | ||
$patchStyle(lastNode, patch); | ||
fn(lastNode); | ||
} | ||
@@ -516,3 +524,3 @@ } | ||
if (lexical.$isTextNode(selectedNode) && selectedNode.canHaveFormat() && selectedNodeKey !== firstNode.getKey() && selectedNodeKey !== lastNode.getKey() && !selectedNode.isToken()) { | ||
$patchStyle(selectedNode, patch); | ||
fn(selectedNode); | ||
} | ||
@@ -935,2 +943,3 @@ } | ||
exports.$addNodeStyle = $addNodeStyle; | ||
exports.$forEachSelectedTextNode = $forEachSelectedTextNode; | ||
exports.$getSelectionStyleValueForProperty = $getSelectionStyleValueForProperty; | ||
@@ -937,0 +946,0 @@ exports.$isAtNodeEnd = $isAtNodeEnd; |
@@ -9,26 +9,25 @@ /** | ||
'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,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}; | ||
'use strict';var k=require("lexical"),v;function w(a){let c=new URLSearchParams;c.append("code",a);for(let b=1;b<arguments.length;b++)c.append("v",arguments[b]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${c} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}v=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 A(a){let c=a.parentNode;if(null==c)throw Error("Should never happen");return[c,Array.from(c.childNodes).indexOf(a)]}function B(a){let c={};if(!a)return c;a=a.split(";");for(let b of a)if(""!==b){let [e,d]=b.split(/:([^]+)/);e&&d&&(c[e.trim()]=d.trim())}return c}function C(a){let c=x.get(a);void 0===c&&(c=B(a),x.set(a,c));return c} | ||
function D(a){let c="";for(let b in a)b&&(c+=`${b}: ${a[b]};`);return c} | ||
function E(a,c,b){let e=c.getNode();if(k.$isElementNode(e)){var d=e.getDescendantByIndex(c.offset);null!==d&&(e=d)}for(;0<b&&null!==e;){k.$isElementNode(e)&&(d=e.getLastDescendant(),null!==d&&(e=d));var g=e.getPreviousSibling(),h=0;if(null===g){d=e.getParentOrThrow();for(var f=d.getPreviousSibling();null===f;){d=d.getParent();if(null===d){g=null;break}f=d.getPreviousSibling()}null!==d&&(h=d.isInline()?0:2,g=f)}f=e.getTextContent();""===f&&k.$isElementNode(e)&&!e.isInline()&&(f="\n\n");d=f.length; | ||
if(!k.$isTextNode(e)||b>=d)f=e.getParent(),e.remove(),null==f||0!==f.getChildrenSize()||k.$isRootNode(f)||f.remove(),b-=d+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=d-b;let n=f.slice(0,g);null!==h&&h!==f?(b=k.$getPreviousSelection(),d=e,e.isSimpleText()?e.setTextContent(h):(d=k.$createTextNode(h),e.replace(d)),k.$isRangeSelection(b)&&b.isCollapsed()&&(b=b.anchor.offset,d.select(b,b))): | ||
e.isSimpleText()?(h=c.key===l,f=c.offset,f<b&&(f=d),b=h?f-b:0,d=h?f:g,h&&0===b?([b]=e.splitText(b,d),b.remove()):([,b]=e.splitText(b,d),b.remove())):(b=k.$createTextNode(n),e.replace(b));b=0}}}function F(a,c){let b=C("getStyle"in a?a.getStyle():a.style);c=Object.entries(c).reduce((d,[g,h])=>{"function"===typeof h?d[g]=h(b[g],a):null===h?delete d[g]:d[g]=h;return d},{...b});let e=D(c);a.setStyle(e);x.set(e,c)} | ||
function G(a){var c=k.$getSelection();if(k.$isRangeSelection(c)){var b=c.getNodes(),e=b.length,{anchor:d,focus:g}=c;c=e-1;e=b[0];var h=b[c],f=e.getTextContent().length,l=g.offset,n=d.offset,p=d.isBefore(g),m=p?n:l,q=p?l:n,r=p?d.type:g.type,t=p?g.type:d.type,u=p?g.key:d.key;if(k.$isTextNode(e)&&m===f){let z=e.getNextSibling();k.$isTextNode(z)&&(m=n=0,e=z)}if(1===b.length)k.$isTextNode(e)&&e.canHaveFormat()&&(m="element"===r?0:n>l?l:n,q="element"===t?f:n>l?n:l,m!==q&&(k.$isTokenOrSegmented(e)||0=== | ||
m&&q===f?(a(e),e.select(m,q)):(b=e.splitText(m,q),b=0===m?b[0]:b[1],a(b),b.select(0,q-m))));else for(k.$isTextNode(e)&&m<e.getTextContentSize()&&e.canHaveFormat()&&(0===m||k.$isTokenOrSegmented(e)||(e=e.splitText(m)[1],m=0,p?d.set(e.getKey(),m,"text"):g.set(e.getKey(),m,"text")),a(e)),k.$isTextNode(h)&&h.canHaveFormat()&&(m=h.getTextContent().length,h.__key!==u&&0!==q&&(q=m),q===m||k.$isTokenOrSegmented(h)||([h]=h.splitText(q)),0===q&&"element"!==t||a(h)),q=1;q<c;q++)m=b[q],t=m.getKey(),k.$isTextNode(m)&& | ||
m.canHaveFormat()&&t!==e.getKey()&&t!==h.getKey()&&!m.isToken()&&a(m)}}function H(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let c=a.getLatest(),b=a.getParent();0===c.getChildrenSize()&&a.remove(!0);a=b}} | ||
function I(a,c,b,e,d=null){if(0!==c.length){var g=c[0],h=new Map,f=[];g=k.$isElementNode(g)?g:g.getParentOrThrow();g.isInline()&&(g=g.getParentOrThrow());for(var l=!1;null!==g;){var n=g.getPreviousSibling();if(null!==n){g=n;l=!0;break}g=g.getParentOrThrow();if(k.$isRootOrShadowRoot(g))break}n=new Set;for(var p=0;p<b;p++){var m=c[p];k.$isElementNode(m)&&0===m.getChildrenSize()&&n.add(m.getKey())}var q=new Set;for(p=0;p<b;p++){m=c[p];var r=m.getParent();null!==r&&r.isInline()&&(r=r.getParent());if(null!== | ||
r&&k.$isLeafNode(m)&&!q.has(m.getKey())){if(m=r.getKey(),void 0===h.get(m)){let t=e();t.setFormat(r.getFormatType());t.setIndent(r.getIndent());f.push(t);h.set(m,t);r.getChildren().forEach(u=>{t.append(u);q.add(u.getKey());k.$isElementNode(u)&&u.getChildrenKeys().forEach(z=>q.add(z))});H(r)}}else n.has(m.getKey())&&(k.$isElementNode(m)||v(179),r=e(),r.setFormat(m.getFormatType()),r.setIndent(m.getIndent()),f.push(r),m.remove(!0))}if(null!==d)for(c=0;c<f.length;c++)d.append(f[c]);c=null;if(k.$isRootOrShadowRoot(g))if(l)if(null!== | ||
d)g.insertAfter(d);else for(d=f.length-1;0<=d;d--)g.insertAfter(f[d]);else if(l=g.getFirstChild(),k.$isElementNode(l)&&(g=l),null===l)if(d)g.append(d);else for(d=0;d<f.length;d++)l=f[d],g.append(l),c=l;else if(null!==d)l.insertBefore(d);else for(g=0;g<f.length;g++)d=f[g],l.insertBefore(d),c=d;else if(d)g.insertAfter(d);else for(d=f.length-1;0<=d;d--)l=f[d],g.insertAfter(l),c=l;f=k.$getPreviousSelection();k.$isRangeSelection(f)&&f.anchor.getNode().isAttached()&&f.focus.getNode().isAttached()?k.$setSelection(f.clone()): | ||
null!==c?c.selectEnd():a.dirty=!0}}function J(a,c,b,e){a.modify(c?"extend":"move",b,e)}function K(a){a=a.anchor.getNode();return"rtl"===(k.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function L(a){if(k.$isDecoratorNode(a)||!k.$isElementNode(a)||k.$isRootOrShadowRoot(a))return!1;var c=a.getFirstChild();c=null===c||k.$isLineBreakNode(c)||k.$isTextNode(c)||c.isInline();return!a.isInline()&&!1!==a.canBeEmpty()&&c}exports.$cloneWithProperties=k.$cloneWithProperties;exports.$selectAll=k.$selectAll; | ||
exports.$addNodeStyle=function(a){a=a.getStyle();let c=B(a);x.set(a,c)};exports.$forEachSelectedTextNode=G; | ||
exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let e=null,d=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&&c in a))return a[c];for(a=0;a<d.length;a++){var n=d[a];if((0===a||0!==l||!n.is(g))&&k.$isTextNode(n))if(h=c,f=b,n=n.getStyle(),n=C(n),h=null!==n?n[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 c=a.getNode();k.$isElementNode(c)||v(177);return a.offset===c.getChildrenSize()};exports.$isParentElementRTL=K;exports.$moveCaretSelection=J;exports.$moveCharacter=function(a,c,b){let e=K(a);J(a,c,b?!e:e,"character")};exports.$patchStyleText=function(a,c){a.isCollapsed()&&k.$isRangeSelection(a)?F(a,c):G(b=>{F(b,c)})}; | ||
exports.$setBlocksType=function(a,c){if(null!==a){var b=a.getStartEndPoints();b=b?b[0]:null;if(null!==b&&"root"===b.key)c=c(),a=k.$getRoot(),(b=a.getFirstChild())?b.replace(c,!0):a.append(c);else{a=a.getNodes();if(null!==b){for(b=b.getNode();null!==b&&null!==b.getParent()&&!L(b);)b=b.getParentOrThrow();b=L(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(!L(e))continue;k.$isElementNode(e)||v(178);let d=c();d.setFormat(e.getFormatType());d.setIndent(e.getIndent()); | ||
e.replace(d,!0)}}}};exports.$shouldOverrideDefaultCharacterSelection=function(a,c){a=k.$getAdjacentNode(a.focus,c);return k.$isDecoratorNode(a)&&!a.isIsolated()||k.$isElementNode(a)&&!a.isInline()&&!a.canBeEmpty()}; | ||
exports.$sliceSelectedTextNodeContent=function(a,c){var b=a.getStartEndPoints();if(c.isSelected(a)&&!c.isSegmented()&&!c.isToken()&&null!==b){let [f,l]=b;b=a.isBackward();var e=f.getNode(),d=l.getNode(),g=c.is(e),h=c.is(d);if(g||h){let [n,p]=k.$getCharacterOffsets(a);a=e.is(d);g=c.is(b?d:e);d=c.is(b?e:d);e=0;h=void 0;a?(e=n>p?p:n,h=n>p?n:p):g?(e=b?p:n,h=void 0):d&&(b=b?n:p,e=0,h=b);c.__text=c.__text.slice(e,h)}}return c};exports.$trimTextContentFromAnchor=E; | ||
exports.$wrapNodes=function(a,c,b=null){var e=a.getStartEndPoints(),d=e?e[0]:null;e=a.getNodes();let g=e.length;if(null!==d&&(0===g||1===g&&"element"===d.type&&0===d.getNode().getChildrenSize())){a="text"===d.type?d.getNode().getParentOrThrow():d.getNode();e=a.getChildren();let f=c();f.setFormat(a.getFormatType());f.setIndent(a.getIndent());e.forEach(l=>f.append(l));b&&(f=b.append(f));a.replace(f)}else{d=null;var h=[];for(let f=0;f<g;f++){let l=e[f];k.$isRootOrShadowRoot(l)?(I(a,h,h.length,c,b),h= | ||
[],d=l):null===d||null!==d&&k.$hasAncestor(l,d)?h.push(l):(I(a,h,h.length,c,b),h=[l])}I(a,h,h.length,c,b)}}; | ||
exports.createDOMRange=function(a,c,b,e,d){let g=c.getKey(),h=e.getKey(),f=document.createRange(),l=a.getElementByKey(g);a=a.getElementByKey(h);k.$isTextNode(c)&&(l=y(l));k.$isTextNode(e)&&(a=y(a));if(void 0===c||void 0===e||null===l||null===a)return null;"BR"===l.nodeName&&([l,b]=A(l));"BR"===a.nodeName&&([a,d]=A(a));c=l.firstChild;l===a&&null!=c&&"BR"===c.nodeName&&0===b&&0===d&&(d=1);try{f.setStart(l,b),f.setEnd(a,d)}catch(n){return null}!f.collapsed||b===d&&g===h||(f.setStart(a,d),f.setEnd(l, | ||
b));return f};exports.createRectsFromDOMRange=function(a,c){var b=a.getRootElement();if(null===b)return[];a=b.getBoundingClientRect();b=getComputedStyle(b);b=parseFloat(b.paddingLeft)+parseFloat(b.paddingRight);c=Array.from(c.getClientRects());let e=c.length;c.sort((g,h)=>{let f=g.top-h.top;return 3>=Math.abs(f)?g.left-h.left:f});let d;for(let g=0;g<e;g++){let h=c[g],f=h.width+b===a.width;d&&d.top<=h.top&&d.top+d.height>h.top&&d.left+d.width>h.left||f?(c.splice(g--,1),e--):d=h}return c}; | ||
exports.getCSSFromStyleObject=D;exports.getStyleObjectFromCSS=C;exports.trimTextContentFromAnchor=E |
@@ -12,3 +12,3 @@ { | ||
"license": "MIT", | ||
"version": "0.21.1-nightly.20241220.0", | ||
"version": "0.21.1-nightly.20241223.0", | ||
"main": "LexicalSelection.js", | ||
@@ -41,4 +41,4 @@ "types": "index.d.ts", | ||
"dependencies": { | ||
"lexical": "0.21.1-nightly.20241220.0" | ||
"lexical": "0.21.1-nightly.20241223.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
109984
2155
+ Addedlexical@0.21.1-nightly.20241223.0(transitive)
- Removedlexical@0.21.1-nightly.20241220.0(transitive)