@lexical/selection 0.21.1-nightly.20241205.0 → 0.21.1-nightly.20241209.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalSelection.dev.js +1 -33
- package/LexicalSelection.dev.mjs +2 -34
- package/LexicalSelection.prod.js +23 -24
- package/LexicalSelection.prod.mjs +1 -1
- package/index.d.ts +4 -3
- package/package.json +2 -2
- package/range-selection.d.ts +0 -5
package/LexicalSelection.dev.js
CHANGED
|
@@ -826,38 +826,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
826
826
|
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
827
827
|
}
|
|
828
828
|
|
|
829
|
-
/**
|
|
830
|
-
* Expands the current Selection to cover all of the content in the editor.
|
|
831
|
-
* @param selection - The current selection.
|
|
832
|
-
*/
|
|
833
|
-
function $selectAll(selection) {
|
|
834
|
-
const anchor = selection.anchor;
|
|
835
|
-
const focus = selection.focus;
|
|
836
|
-
const anchorNode = anchor.getNode();
|
|
837
|
-
const topParent = anchorNode.getTopLevelElementOrThrow();
|
|
838
|
-
const root = topParent.getParentOrThrow();
|
|
839
|
-
let firstNode = root.getFirstDescendant();
|
|
840
|
-
let lastNode = root.getLastDescendant();
|
|
841
|
-
let firstType = 'element';
|
|
842
|
-
let lastType = 'element';
|
|
843
|
-
let lastOffset = 0;
|
|
844
|
-
if (lexical.$isTextNode(firstNode)) {
|
|
845
|
-
firstType = 'text';
|
|
846
|
-
} else if (!lexical.$isElementNode(firstNode) && firstNode !== null) {
|
|
847
|
-
firstNode = firstNode.getParentOrThrow();
|
|
848
|
-
}
|
|
849
|
-
if (lexical.$isTextNode(lastNode)) {
|
|
850
|
-
lastType = 'text';
|
|
851
|
-
lastOffset = lastNode.getTextContentSize();
|
|
852
|
-
} else if (!lexical.$isElementNode(lastNode) && lastNode !== null) {
|
|
853
|
-
lastNode = lastNode.getParentOrThrow();
|
|
854
|
-
}
|
|
855
|
-
if (firstNode && lastNode) {
|
|
856
|
-
anchor.set(firstNode.getKey(), 0, firstType);
|
|
857
|
-
focus.set(lastNode.getKey(), lastOffset, lastType);
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
|
|
861
829
|
/**
|
|
862
830
|
* Returns the current value of a CSS property for Nodes, if set. If not set, it returns the defaultValue.
|
|
863
831
|
* @param node - The node whose style value to get.
|
|
@@ -956,6 +924,7 @@ function $getAncestor(node, predicate) {
|
|
|
956
924
|
const trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
957
925
|
|
|
958
926
|
exports.$cloneWithProperties = lexical.$cloneWithProperties;
|
|
927
|
+
exports.$selectAll = lexical.$selectAll;
|
|
959
928
|
exports.$addNodeStyle = $addNodeStyle;
|
|
960
929
|
exports.$getSelectionStyleValueForProperty = $getSelectionStyleValueForProperty;
|
|
961
930
|
exports.$isAtNodeEnd = $isAtNodeEnd;
|
|
@@ -963,7 +932,6 @@ exports.$isParentElementRTL = $isParentElementRTL;
|
|
|
963
932
|
exports.$moveCaretSelection = $moveCaretSelection;
|
|
964
933
|
exports.$moveCharacter = $moveCharacter;
|
|
965
934
|
exports.$patchStyleText = $patchStyleText;
|
|
966
|
-
exports.$selectAll = $selectAll;
|
|
967
935
|
exports.$setBlocksType = $setBlocksType;
|
|
968
936
|
exports.$shouldOverrideDefaultCharacterSelection = $shouldOverrideDefaultCharacterSelection;
|
|
969
937
|
exports.$sliceSelectedTextNodeContent = $sliceSelectedTextNodeContent;
|
package/LexicalSelection.dev.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $isTokenOrSegmented, $getRoot, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $setSelection, $getAdjacentNode, $isDecoratorNode, $isLineBreakNode } from 'lexical';
|
|
10
|
-
export { $cloneWithProperties } from 'lexical';
|
|
10
|
+
export { $cloneWithProperties, $selectAll } from 'lexical';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -825,38 +825,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
825
825
|
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
826
826
|
}
|
|
827
827
|
|
|
828
|
-
/**
|
|
829
|
-
* Expands the current Selection to cover all of the content in the editor.
|
|
830
|
-
* @param selection - The current selection.
|
|
831
|
-
*/
|
|
832
|
-
function $selectAll(selection) {
|
|
833
|
-
const anchor = selection.anchor;
|
|
834
|
-
const focus = selection.focus;
|
|
835
|
-
const anchorNode = anchor.getNode();
|
|
836
|
-
const topParent = anchorNode.getTopLevelElementOrThrow();
|
|
837
|
-
const root = topParent.getParentOrThrow();
|
|
838
|
-
let firstNode = root.getFirstDescendant();
|
|
839
|
-
let lastNode = root.getLastDescendant();
|
|
840
|
-
let firstType = 'element';
|
|
841
|
-
let lastType = 'element';
|
|
842
|
-
let lastOffset = 0;
|
|
843
|
-
if ($isTextNode(firstNode)) {
|
|
844
|
-
firstType = 'text';
|
|
845
|
-
} else if (!$isElementNode(firstNode) && firstNode !== null) {
|
|
846
|
-
firstNode = firstNode.getParentOrThrow();
|
|
847
|
-
}
|
|
848
|
-
if ($isTextNode(lastNode)) {
|
|
849
|
-
lastType = 'text';
|
|
850
|
-
lastOffset = lastNode.getTextContentSize();
|
|
851
|
-
} else if (!$isElementNode(lastNode) && lastNode !== null) {
|
|
852
|
-
lastNode = lastNode.getParentOrThrow();
|
|
853
|
-
}
|
|
854
|
-
if (firstNode && lastNode) {
|
|
855
|
-
anchor.set(firstNode.getKey(), 0, firstType);
|
|
856
|
-
focus.set(lastNode.getKey(), lastOffset, lastType);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
|
|
860
828
|
/**
|
|
861
829
|
* Returns the current value of a CSS property for Nodes, if set. If not set, it returns the defaultValue.
|
|
862
830
|
* @param node - The node whose style value to get.
|
|
@@ -954,4 +922,4 @@ function $getAncestor(node, predicate) {
|
|
|
954
922
|
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
955
923
|
const trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
956
924
|
|
|
957
|
-
export { $addNodeStyle, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $patchStyleText, $
|
|
925
|
+
export { $addNodeStyle, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $patchStyleText, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, $wrapNodes, createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, getStyleObjectFromCSS, trimTextContentFromAnchor };
|
package/LexicalSelection.prod.js
CHANGED
|
@@ -6,29 +6,28 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var k=require("lexical"),u;function w(a){let d=new URLSearchParams;d.append("code",a);for(let
|
|
10
|
-
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
|
|
11
|
-
function D(a){let d="";for(let
|
|
12
|
-
function E(a,d,
|
|
13
|
-
if(!k.$isTextNode(e)||b
|
|
14
|
-
e.isSimpleText()?(h=d.key===l,f=d.offset,f<
|
|
15
|
-
function G(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let d=a.getLatest(),
|
|
16
|
-
function H(a,d,
|
|
17
|
-
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!==
|
|
18
|
-
|
|
19
|
-
null!==d?d.selectEnd():a.dirty=!0}}function I(a,d,
|
|
9
|
+
'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;
|
|
10
|
+
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}
|
|
11
|
+
function D(a){let d="";for(let c in a)c&&(d+=`${c}: ${a[c]};`);return d}
|
|
12
|
+
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;
|
|
13
|
+
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))):
|
|
14
|
+
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)}
|
|
15
|
+
function G(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let d=a.getLatest(),c=a.getParent();0===d.getChildrenSize()&&a.remove(!0);a=c}}
|
|
16
|
+
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!==
|
|
17
|
+
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!==
|
|
18
|
+
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()):
|
|
19
|
+
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;
|
|
20
20
|
exports.$addNodeStyle=function(a){a=a.getStyle();let d=B(a);x.set(a,d)};
|
|
21
|
-
exports.$getSelectionStyleValueForProperty=function(a,d,
|
|
22
|
-
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,
|
|
23
|
-
exports.$patchStyleText=function(a,d){var
|
|
24
|
-
"element"===t?l:p>m?p:m,n!==a&&(k.$isTokenOrSegmented(
|
|
25
|
-
a&&"element"!==t||F(f,d)),a=1;a<e;a++)n=
|
|
26
|
-
exports.$
|
|
27
|
-
exports.$
|
|
28
|
-
|
|
29
|
-
exports.$
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
exports.
|
|
33
|
-
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};
|
|
21
|
+
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};
|
|
22
|
+
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")};
|
|
23
|
+
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=
|
|
24
|
+
"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===
|
|
25
|
+
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)}}};
|
|
26
|
+
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());
|
|
27
|
+
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()};
|
|
28
|
+
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;
|
|
29
|
+
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=
|
|
30
|
+
[],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)}};
|
|
31
|
+
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,
|
|
32
|
+
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};
|
|
34
33
|
exports.getCSSFromStyleObject=D;exports.getStyleObjectFromCSS=C;exports.trimTextContentFromAnchor=E
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$isTextNode as e,$getCharacterOffsets as t,$isElementNode as n,$isRootNode as l,$getNodeByKey as o,$getPreviousSelection as r,$createTextNode as
|
|
9
|
+
import{$isTextNode as e,$getCharacterOffsets as t,$isElementNode as n,$isRootNode as l,$getNodeByKey as o,$getPreviousSelection as r,$createTextNode as i,$isRangeSelection as s,$isTokenOrSegmented as c,$getRoot as f,$isRootOrShadowRoot as u,$hasAncestor as g,$isLeafNode as a,$setSelection as d,$getAdjacentNode as p,$isDecoratorNode as h,$isLineBreakNode as y}from"lexical";export{$cloneWithProperties,$selectAll}from"lexical";function m(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var S=m((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const x=new Map;function T(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function v(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function C(t,n,l,o,r){const i=n.getKey(),s=o.getKey(),c=document.createRange();let f=t.getElementByKey(i),u=t.getElementByKey(s),g=l,a=r;if(e(n)&&(f=T(f)),e(o)&&(u=T(u)),void 0===n||void 0===o||null===f||null===u)return null;"BR"===f.nodeName&&([f,g]=v(f)),"BR"===u.nodeName&&([u,a]=v(u));const d=f.firstChild;f===u&&null!=d&&"BR"===d.nodeName&&0===g&&0===a&&(a=1);try{c.setStart(f,g),c.setEnd(u,a)}catch(e){return null}return!c.collapsed||g===a&&i===s||(c.setStart(u,a),c.setEnd(f,g)),c}function N(e,t){const n=e.getRootElement();if(null===n)return[];const l=n.getBoundingClientRect(),o=getComputedStyle(n),r=parseFloat(o.paddingLeft)+parseFloat(o.paddingRight),i=Array.from(t.getClientRects());let s,c=i.length;i.sort(((e,t)=>{const n=e.top-t.top;return Math.abs(n)<=3?e.left-t.left:n}));for(let e=0;e<c;e++){const t=i[e],n=s&&s.top<=t.top&&s.top+s.height>t.top&&s.left+s.width>t.left,o=t.width+r===l.width;n||o?(i.splice(e--,1),c--):s=t}return i}function P(e){const t={};if(!e)return t;const n=e.split(";");for(const e of n)if(""!==e){const[n,l]=e.split(/:([^]+)/);n&&l&&(t[n.trim()]=l.trim())}return t}function w(e){let t=x.get(e);return void 0===t&&(t=P(e),x.set(e,t)),t}function E(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function F(e,n){const l=e.getStartEndPoints();if(n.isSelected(e)&&!n.isSegmented()&&!n.isToken()&&null!==l){const[o,r]=l,i=e.isBackward(),s=o.getNode(),c=r.getNode(),f=n.is(s),u=n.is(c);if(f||u){const[l,o]=t(e),r=s.is(c),f=n.is(i?c:s),u=n.is(i?s:c);let g,a=0;if(r)a=l>o?o:l,g=l>o?l:o;else if(f){a=i?o:l,g=void 0}else if(u){a=0,g=i?l:o}return n.__text=n.__text.slice(a,g),n}}return n}function I(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return n(t)||S(177),e.offset===t.getChildrenSize()}function K(t,c,f){let u=c.getNode(),g=f;if(n(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e)}for(;g>0&&null!==u;){if(n(u)){const e=u.getLastDescendant();null!==e&&(u=e)}let f=u.getPreviousSibling(),a=0;if(null===f){let e=u.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){f=null;break}t=e.getPreviousSibling()}null!==e&&(a=e.isInline()?0:2,f=t)}let d=u.getTextContent();""===d&&n(u)&&!u.isInline()&&(d="\n\n");const p=d.length;if(!e(u)||g>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||l(e)||e.remove(),g-=p+a,u=f}else{const n=u.getKey(),l=t.getEditorState().read((()=>{const t=o(n);return e(t)&&t.isSimpleText()?t.getTextContent():null})),f=p-g,a=d.slice(0,f);if(null!==l&&l!==d){const e=r();let t=u;if(u.isSimpleText())u.setTextContent(l);else{const e=i(l);u.replace(e),t=e}if(s(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n)}}else if(u.isSimpleText()){const e=c.key===n;let t=c.offset;t<g&&(t=p);const l=e?t-g:0,o=e?t:f;if(e&&0===l){const[e]=u.splitText(l,o);e.remove()}else{const[,e]=u.splitText(l,o);e.remove()}}else{const e=i(a);u.replace(e)}g=0}}}function B(e){const t=e.getStyle(),n=P(t);x.set(t,n)}function k(e,t){const n=w("getStyle"in e?e.getStyle():e.style),l=Object.entries(t).reduce(((t,[l,o])=>("function"==typeof o?t[l]=o(n[l],e):null===o?delete t[l]:t[l]=o,t)),{...n}||{}),o=E(l);e.setStyle(o),x.set(o,l)}function O(t,n){const l=t.getNodes(),o=l.length,r=t.getStartEndPoints();if(null===r)return;const[i,f]=r,u=o-1;let g=l[0],a=l[u];if(t.isCollapsed()&&s(t))return void k(t,n);const d=g.getTextContent().length,p=f.offset;let h=i.offset;const y=i.isBefore(f);let m=y?h:p,S=y?p:h;const x=y?i.type:f.type,T=y?f.type:i.type,v=y?f.key:i.key;if(e(g)&&m===d){const t=g.getNextSibling();e(t)&&(h=0,m=0,g=t)}if(1===l.length){if(e(g)&&g.canHaveFormat()){if(m="element"===x?0:h>p?p:h,S="element"===T?d:h>p?h:p,m===S)return;if(c(g)||0===m&&S===d)k(g,n),g.select(m,S);else{const e=g.splitText(m,S),t=0===m?e[0]:e[1];k(t,n),t.select(0,S-m)}}}else{if(e(g)&&m<g.getTextContentSize()&&g.canHaveFormat()&&(0===m||c(g)||(g=g.splitText(m)[1],m=0,y?i.set(g.getKey(),m,"text"):f.set(g.getKey(),m,"text")),k(g,n)),e(a)&&a.canHaveFormat()){const e=a.getTextContent().length;a.__key!==v&&0!==S&&(S=e),S===e||c(a)||([a]=a.splitText(S)),0===S&&"element"!==T||k(a,n)}for(let t=1;t<u;t++){const o=l[t],r=o.getKey();e(o)&&o.canHaveFormat()&&r!==g.getKey()&&r!==a.getKey()&&!o.isToken()&&k(o,n)}}}function b(e,t){if(null===e)return;const l=e.getStartEndPoints(),o=l?l[0]:null;if(null!==o&&"root"===o.key){const e=t(),n=f(),l=n.getFirstChild();return void(l?l.replace(e,!0):n.append(e))}const r=e.getNodes(),i=null!==o&&function(e,t){let n=e;for(;null!==n&&null!==n.getParent()&&!t(n);)n=n.getParentOrThrow();return t(n)?n:null}(o.getNode(),U);i&&-1===r.indexOf(i)&&r.push(i);for(let e=0;e<r.length;e++){const l=r[e];if(!U(l))continue;n(l)||S(178);const o=t();o.setFormat(l.getFormatType()),o.setIndent(l.getIndent()),l.replace(o,!0)}}function R(e){return e.getNode().isAttached()}function _(e){let t=e;for(;null!==t&&!u(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function A(e,t,n=null){const l=e.getStartEndPoints(),o=l?l[0]:null,r=e.getNodes(),i=r.length;if(null!==o&&(0===i||1===i&&"element"===o.type&&0===o.getNode().getChildrenSize())){const e="text"===o.type?o.getNode().getParentOrThrow():o.getNode(),l=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),l.forEach((e=>r.append(e))),n&&(r=n.append(r)),void e.replace(r)}let s=null,c=[];for(let l=0;l<i;l++){const o=r[l];u(o)?(z(e,c,c.length,t,n),c=[],s=o):null===s||null!==s&&g(o,s)?c.push(o):(z(e,c,c.length,t,n),c=[o])}z(e,c,c.length,t,n)}function z(e,t,l,o,i=null){if(0===t.length)return;const c=t[0],f=new Map,g=[];let p=n(c)?c:c.getParentOrThrow();p.isInline()&&(p=p.getParentOrThrow());let h=!1;for(;null!==p;){const e=p.getPreviousSibling();if(null!==e){p=e,h=!0;break}if(p=p.getParentOrThrow(),u(p))break}const y=new Set;for(let e=0;e<l;e++){const l=t[e];n(l)&&0===l.getChildrenSize()&&y.add(l.getKey())}const m=new Set;for(let e=0;e<l;e++){const l=t[e];let r=l.getParent();if(null!==r&&r.isInline()&&(r=r.getParent()),null!==r&&a(l)&&!m.has(l.getKey())){const e=r.getKey();if(void 0===f.get(e)){const t=o();t.setFormat(r.getFormatType()),t.setIndent(r.getIndent()),g.push(t),f.set(e,t),r.getChildren().forEach((e=>{t.append(e),m.add(e.getKey()),n(e)&&e.getChildrenKeys().forEach((e=>m.add(e)))})),_(r)}}else if(y.has(l.getKey())){n(l)||S(179);const e=o();e.setFormat(l.getFormatType()),e.setIndent(l.getIndent()),g.push(e),l.remove(!0)}}if(null!==i)for(let e=0;e<g.length;e++){const t=g[e];i.append(t)}let x=null;if(u(p))if(h)if(null!==i)p.insertAfter(i);else for(let e=g.length-1;e>=0;e--){const t=g[e];p.insertAfter(t)}else{const e=p.getFirstChild();if(n(e)&&(p=e),null===e)if(i)p.append(i);else for(let e=0;e<g.length;e++){const t=g[e];p.append(t),x=t}else if(null!==i)e.insertBefore(i);else for(let t=0;t<g.length;t++){const n=g[t];e.insertBefore(n),x=n}}else if(i)p.insertAfter(i);else for(let e=g.length-1;e>=0;e--){const t=g[e];p.insertAfter(t),x=t}const T=r();s(T)&&R(T.anchor)&&R(T.focus)?d(T.clone()):null!==x?x.selectEnd():e.dirty=!0}function $(e,t){const l=p(e.focus,t);return h(l)&&!l.isIsolated()||n(l)&&!l.isInline()&&!l.canBeEmpty()}function L(e,t,n,l){e.modify(t?"extend":"move",n,l)}function M(e){const t=e.anchor.getNode();return"rtl"===(l(t)?t:t.getParentOrThrow()).getDirection()}function D(e,t,n){const l=M(e);L(e,t,n?!l:l,"character")}function H(e,t,n){const l=w(e.getStyle());return null!==l&&l[t]||n}function j(t,n,l=""){let o=null;const r=t.getNodes(),i=t.anchor,c=t.focus,f=t.isBackward(),u=f?c.offset:i.offset,g=f?c.getNode():i.getNode();if(s(t)&&t.isCollapsed()&&""!==t.style){const e=w(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<r.length;t++){const i=r[t];if((0===t||0!==u||!i.is(g))&&e(i)){const e=H(i,n,l);if(null===o)o=e;else if(o!==e){o="";break}}}return null===o?l:o}function U(t){if(h(t))return!1;if(!n(t)||u(t))return!1;const l=t.getFirstChild(),o=null===l||y(l)||e(l)||l.isInline();return!t.isInline()&&!1!==t.canBeEmpty()&&o}const W=K;export{B as $addNodeStyle,j as $getSelectionStyleValueForProperty,I as $isAtNodeEnd,M as $isParentElementRTL,L as $moveCaretSelection,D as $moveCharacter,O as $patchStyleText,b as $setBlocksType,$ as $shouldOverrideDefaultCharacterSelection,F as $sliceSelectedTextNodeContent,K as $trimTextContentFromAnchor,A as $wrapNodes,C as createDOMRange,N as createRectsFromDOMRange,E as getCSSFromStyleObject,w as getStyleObjectFromCSS,W as trimTextContentFromAnchor};
|
package/index.d.ts
CHANGED
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import { $addNodeStyle, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor } from './lexical-node';
|
|
9
|
-
import { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $
|
|
9
|
+
import { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes } from './range-selection';
|
|
10
10
|
import { createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, getStyleObjectFromCSS } from './utils';
|
|
11
11
|
export {
|
|
12
|
-
/** @deprecated moved to the lexical package */ $cloneWithProperties,
|
|
12
|
+
/** @deprecated moved to the lexical package */ $cloneWithProperties,
|
|
13
|
+
/** @deprecated moved to the lexical package */ $selectAll, } from 'lexical';
|
|
13
14
|
export { $addNodeStyle, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, };
|
|
14
15
|
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
15
16
|
export declare const trimTextContentFromAnchor: typeof $trimTextContentFromAnchor;
|
|
16
|
-
export { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $
|
|
17
|
+
export { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes, };
|
|
17
18
|
export { createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, getStyleObjectFromCSS, };
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"selection"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.21.1-nightly.
|
|
12
|
+
"version": "0.21.1-nightly.20241209.0",
|
|
13
13
|
"main": "LexicalSelection.js",
|
|
14
14
|
"types": "index.d.ts",
|
|
15
15
|
"repository": {
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"lexical": "0.21.1-nightly.
|
|
40
|
+
"lexical": "0.21.1-nightly.20241209.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/range-selection.d.ts
CHANGED
|
@@ -59,11 +59,6 @@ export declare function $isParentElementRTL(selection: RangeSelection): boolean;
|
|
|
59
59
|
* @param isBackward - Is the selection backward (the focus comes before the anchor)?
|
|
60
60
|
*/
|
|
61
61
|
export declare function $moveCharacter(selection: RangeSelection, isHoldingShift: boolean, isBackward: boolean): void;
|
|
62
|
-
/**
|
|
63
|
-
* Expands the current Selection to cover all of the content in the editor.
|
|
64
|
-
* @param selection - The current selection.
|
|
65
|
-
*/
|
|
66
|
-
export declare function $selectAll(selection: RangeSelection): void;
|
|
67
62
|
/**
|
|
68
63
|
* Returns the current value of a CSS property for TextNodes in the Selection, if set. If not set, it returns the defaultValue.
|
|
69
64
|
* If all TextNodes do not have the same value, it returns an empty string.
|