@lexical/selection 0.23.1 → 0.23.2-nightly.20250113.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 +11 -27
- package/LexicalSelection.dev.mjs +12 -28
- package/LexicalSelection.prod.js +22 -23
- package/LexicalSelection.prod.mjs +1 -1
- package/package.json +2 -2
- package/range-selection.d.ts +0 -5
package/LexicalSelection.dev.js
CHANGED
|
@@ -542,6 +542,7 @@ function $setBlocksType(selection, createElement) {
|
|
|
542
542
|
}
|
|
543
543
|
const anchorAndFocus = selection.getStartEndPoints();
|
|
544
544
|
const anchor = anchorAndFocus ? anchorAndFocus[0] : null;
|
|
545
|
+
const isCollapsedSelection = selection.is(lexical.$getSelection()) && selection.isCollapsed();
|
|
545
546
|
if (anchor !== null && anchor.key === 'root') {
|
|
546
547
|
const element = createElement();
|
|
547
548
|
const root = lexical.$getRoot();
|
|
@@ -551,25 +552,24 @@ function $setBlocksType(selection, createElement) {
|
|
|
551
552
|
} else {
|
|
552
553
|
root.append(element);
|
|
553
554
|
}
|
|
555
|
+
if (isCollapsedSelection) {
|
|
556
|
+
element.select();
|
|
557
|
+
}
|
|
554
558
|
return;
|
|
555
559
|
}
|
|
556
|
-
const nodes = selection.getNodes();
|
|
557
|
-
const firstSelectedBlock = anchor
|
|
558
|
-
if (firstSelectedBlock && nodes.
|
|
560
|
+
const nodes = selection.getNodes().filter(lexical.INTERNAL_$isBlock).filter(lexical.$isElementNode);
|
|
561
|
+
const firstSelectedBlock = anchor ? $getAncestor(anchor.getNode(), lexical.INTERNAL_$isBlock) : null;
|
|
562
|
+
if (lexical.$isElementNode(firstSelectedBlock) && !nodes.find(node => node.is(firstSelectedBlock))) {
|
|
559
563
|
nodes.push(firstSelectedBlock);
|
|
560
564
|
}
|
|
561
|
-
for (
|
|
562
|
-
const node = nodes[i];
|
|
563
|
-
if (!INTERNAL_$isBlock(node)) {
|
|
564
|
-
continue;
|
|
565
|
-
}
|
|
566
|
-
if (!lexical.$isElementNode(node)) {
|
|
567
|
-
throw Error(`Expected block node to be an ElementNode`);
|
|
568
|
-
}
|
|
565
|
+
for (const node of nodes) {
|
|
569
566
|
const targetElement = createElement();
|
|
570
567
|
targetElement.setFormat(node.getFormatType());
|
|
571
568
|
targetElement.setIndent(node.getIndent());
|
|
572
569
|
node.replace(targetElement, true);
|
|
570
|
+
if (node.is(firstSelectedBlock) && isCollapsedSelection) {
|
|
571
|
+
targetElement.select();
|
|
572
|
+
}
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
575
|
function isPointAttached(point) {
|
|
@@ -896,22 +896,6 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
|
|
|
896
896
|
}
|
|
897
897
|
return styleValue === null ? defaultValue : styleValue;
|
|
898
898
|
}
|
|
899
|
-
|
|
900
|
-
/**
|
|
901
|
-
* This function is for internal use of the library.
|
|
902
|
-
* Please do not use it as it may change in the future.
|
|
903
|
-
*/
|
|
904
|
-
function INTERNAL_$isBlock(node) {
|
|
905
|
-
if (lexical.$isDecoratorNode(node)) {
|
|
906
|
-
return false;
|
|
907
|
-
}
|
|
908
|
-
if (!lexical.$isElementNode(node) || lexical.$isRootOrShadowRoot(node)) {
|
|
909
|
-
return false;
|
|
910
|
-
}
|
|
911
|
-
const firstChild = node.getFirstChild();
|
|
912
|
-
const isLeafElement = firstChild === null || lexical.$isLineBreakNode(firstChild) || lexical.$isTextNode(firstChild) || firstChild.isInline();
|
|
913
|
-
return !node.isInline() && node.canBeEmpty() !== false && isLeafElement;
|
|
914
|
-
}
|
|
915
899
|
function $getAncestor(node, predicate) {
|
|
916
900
|
let parent = node;
|
|
917
901
|
while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
|
package/LexicalSelection.dev.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $getSelection, $isTokenOrSegmented, $getRoot, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $setSelection, $getAdjacentNode, $isDecoratorNode
|
|
9
|
+
import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $getSelection, $isTokenOrSegmented, $getRoot, INTERNAL_$isBlock, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $setSelection, $getAdjacentNode, $isDecoratorNode } from 'lexical';
|
|
10
10
|
export { $cloneWithProperties, $selectAll } from 'lexical';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -541,6 +541,7 @@ function $setBlocksType(selection, createElement) {
|
|
|
541
541
|
}
|
|
542
542
|
const anchorAndFocus = selection.getStartEndPoints();
|
|
543
543
|
const anchor = anchorAndFocus ? anchorAndFocus[0] : null;
|
|
544
|
+
const isCollapsedSelection = selection.is($getSelection()) && selection.isCollapsed();
|
|
544
545
|
if (anchor !== null && anchor.key === 'root') {
|
|
545
546
|
const element = createElement();
|
|
546
547
|
const root = $getRoot();
|
|
@@ -550,25 +551,24 @@ function $setBlocksType(selection, createElement) {
|
|
|
550
551
|
} else {
|
|
551
552
|
root.append(element);
|
|
552
553
|
}
|
|
554
|
+
if (isCollapsedSelection) {
|
|
555
|
+
element.select();
|
|
556
|
+
}
|
|
553
557
|
return;
|
|
554
558
|
}
|
|
555
|
-
const nodes = selection.getNodes();
|
|
556
|
-
const firstSelectedBlock = anchor
|
|
557
|
-
if (firstSelectedBlock && nodes.
|
|
559
|
+
const nodes = selection.getNodes().filter(INTERNAL_$isBlock).filter($isElementNode);
|
|
560
|
+
const firstSelectedBlock = anchor ? $getAncestor(anchor.getNode(), INTERNAL_$isBlock) : null;
|
|
561
|
+
if ($isElementNode(firstSelectedBlock) && !nodes.find(node => node.is(firstSelectedBlock))) {
|
|
558
562
|
nodes.push(firstSelectedBlock);
|
|
559
563
|
}
|
|
560
|
-
for (
|
|
561
|
-
const node = nodes[i];
|
|
562
|
-
if (!INTERNAL_$isBlock(node)) {
|
|
563
|
-
continue;
|
|
564
|
-
}
|
|
565
|
-
if (!$isElementNode(node)) {
|
|
566
|
-
throw Error(`Expected block node to be an ElementNode`);
|
|
567
|
-
}
|
|
564
|
+
for (const node of nodes) {
|
|
568
565
|
const targetElement = createElement();
|
|
569
566
|
targetElement.setFormat(node.getFormatType());
|
|
570
567
|
targetElement.setIndent(node.getIndent());
|
|
571
568
|
node.replace(targetElement, true);
|
|
569
|
+
if (node.is(firstSelectedBlock) && isCollapsedSelection) {
|
|
570
|
+
targetElement.select();
|
|
571
|
+
}
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
574
|
function isPointAttached(point) {
|
|
@@ -895,22 +895,6 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
|
|
|
895
895
|
}
|
|
896
896
|
return styleValue === null ? defaultValue : styleValue;
|
|
897
897
|
}
|
|
898
|
-
|
|
899
|
-
/**
|
|
900
|
-
* This function is for internal use of the library.
|
|
901
|
-
* Please do not use it as it may change in the future.
|
|
902
|
-
*/
|
|
903
|
-
function INTERNAL_$isBlock(node) {
|
|
904
|
-
if ($isDecoratorNode(node)) {
|
|
905
|
-
return false;
|
|
906
|
-
}
|
|
907
|
-
if (!$isElementNode(node) || $isRootOrShadowRoot(node)) {
|
|
908
|
-
return false;
|
|
909
|
-
}
|
|
910
|
-
const firstChild = node.getFirstChild();
|
|
911
|
-
const isLeafElement = firstChild === null || $isLineBreakNode(firstChild) || $isTextNode(firstChild) || firstChild.isInline();
|
|
912
|
-
return !node.isInline() && node.canBeEmpty() !== false && isLeafElement;
|
|
913
|
-
}
|
|
914
898
|
function $getAncestor(node, predicate) {
|
|
915
899
|
let parent = node;
|
|
916
900
|
while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
|
package/LexicalSelection.prod.js
CHANGED
|
@@ -6,27 +6,26 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var k=require("lexical"),v;function w(a){let
|
|
10
|
-
function
|
|
11
|
-
function D(a){let
|
|
12
|
-
function E(a,
|
|
13
|
-
if(!k.$isTextNode(e)||
|
|
14
|
-
e.isSimpleText()?(h=
|
|
15
|
-
function G(a){var
|
|
16
|
-
m&&q===
|
|
17
|
-
m.canHaveFormat()&&t!==e.getKey()&&t!==h.getKey()&&!m.isToken()&&a(m)}}function H(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let
|
|
18
|
-
function I(a,
|
|
19
|
-
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());
|
|
20
|
-
|
|
21
|
-
null!==
|
|
22
|
-
exports.$
|
|
23
|
-
exports.$
|
|
24
|
-
exports.$
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
exports.$
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
exports.
|
|
31
|
-
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};
|
|
9
|
+
'use strict';var k=require("lexical"),v;function w(a){let b=new URLSearchParams;b.append("code",a);for(let d=1;d<arguments.length;d++)b.append("v",arguments[d]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} 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;
|
|
10
|
+
function z(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function A(a){let b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}function B(a){let b={};if(!a)return b;a=a.split(";");for(let d of a)if(""!==d){let [e,c]=d.split(/:([^]+)/);e&&c&&(b[e.trim()]=c.trim())}return b}function C(a){let b=x.get(a);void 0===b&&(b=B(a),x.set(a,b));return b}
|
|
11
|
+
function D(a){let b="";for(let d in a)d&&(b+=`${d}: ${a[d]};`);return b}
|
|
12
|
+
function E(a,b,d){let e=b.getNode();if(k.$isElementNode(e)){var c=e.getDescendantByIndex(b.offset);null!==c&&(e=c)}for(;0<d&&null!==e;){k.$isElementNode(e)&&(c=e.getLastDescendant(),null!==c&&(e=c));var f=e.getPreviousSibling(),h=0;if(null===f){c=e.getParentOrThrow();for(var g=c.getPreviousSibling();null===g;){c=c.getParent();if(null===c){f=null;break}g=c.getPreviousSibling()}null!==c&&(h=c.isInline()?0:2,f=g)}g=e.getTextContent();""===g&&k.$isElementNode(e)&&!e.isInline()&&(g="\n\n");c=g.length;
|
|
13
|
+
if(!k.$isTextNode(e)||d>=c)g=e.getParent(),e.remove(),null==g||0!==g.getChildrenSize()||k.$isRootNode(g)||g.remove(),d-=c+h,e=f;else{let l=e.getKey();h=a.getEditorState().read(()=>{const p=k.$getNodeByKey(l);return k.$isTextNode(p)&&p.isSimpleText()?p.getTextContent():null});f=c-d;let n=g.slice(0,f);null!==h&&h!==g?(d=k.$getPreviousSelection(),c=e,e.isSimpleText()?e.setTextContent(h):(c=k.$createTextNode(h),e.replace(c)),k.$isRangeSelection(d)&&d.isCollapsed()&&(d=d.anchor.offset,c.select(d,d))):
|
|
14
|
+
e.isSimpleText()?(h=b.key===l,g=b.offset,g<d&&(g=c),d=h?g-d:0,c=h?g:f,h&&0===d?([d]=e.splitText(d,c),d.remove()):([,d]=e.splitText(d,c),d.remove())):(d=k.$createTextNode(n),e.replace(d));d=0}}}function F(a,b){let d=C("getStyle"in a?a.getStyle():a.style);b=Object.entries(b).reduce((c,[f,h])=>{"function"===typeof h?c[f]=h(d[f],a):null===h?delete c[f]:c[f]=h;return c},{...d});let e=D(b);a.setStyle(e);x.set(e,b)}
|
|
15
|
+
function G(a){var b=k.$getSelection();if(k.$isRangeSelection(b)){var d=b.getNodes(),e=d.length,{anchor:c,focus:f}=b;b=e-1;e=d[0];var h=d[b],g=e.getTextContent().length,l=f.offset,n=c.offset,p=c.isBefore(f),m=p?n:l,q=p?l:n,r=p?c.type:f.type,t=p?f.type:c.type,u=p?f.key:c.key;if(k.$isTextNode(e)&&m===g){let y=e.getNextSibling();k.$isTextNode(y)&&(m=n=0,e=y)}if(1===d.length)k.$isTextNode(e)&&e.canHaveFormat()&&(m="element"===r?0:n>l?l:n,q="element"===t?g:n>l?n:l,m!==q&&(k.$isTokenOrSegmented(e)||0===
|
|
16
|
+
m&&q===g?(a(e),e.select(m,q)):(d=e.splitText(m,q),d=0===m?d[0]:d[1],a(d),d.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?c.set(e.getKey(),m,"text"):f.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<b;q++)m=d[q],t=m.getKey(),k.$isTextNode(m)&&
|
|
17
|
+
m.canHaveFormat()&&t!==e.getKey()&&t!==h.getKey()&&!m.isToken()&&a(m)}}function H(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let b=a.getLatest(),d=a.getParent();0===b.getChildrenSize()&&a.remove(!0);a=d}}
|
|
18
|
+
function I(a,b,d,e,c=null){if(0!==b.length){var f=b[0],h=new Map,g=[];f=k.$isElementNode(f)?f:f.getParentOrThrow();f.isInline()&&(f=f.getParentOrThrow());for(var l=!1;null!==f;){var n=f.getPreviousSibling();if(null!==n){f=n;l=!0;break}f=f.getParentOrThrow();if(k.$isRootOrShadowRoot(f))break}n=new Set;for(var p=0;p<d;p++){var m=b[p];k.$isElementNode(m)&&0===m.getChildrenSize()&&n.add(m.getKey())}var q=new Set;for(p=0;p<d;p++){m=b[p];var r=m.getParent();null!==r&&r.isInline()&&(r=r.getParent());if(null!==
|
|
19
|
+
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());g.push(t);h.set(m,t);r.getChildren().forEach(u=>{t.append(u);q.add(u.getKey());k.$isElementNode(u)&&u.getChildrenKeys().forEach(y=>q.add(y))});H(r)}}else n.has(m.getKey())&&(k.$isElementNode(m)||v(179),r=e(),r.setFormat(m.getFormatType()),r.setIndent(m.getIndent()),g.push(r),m.remove(!0))}if(null!==c)for(b=0;b<g.length;b++)c.append(g[b]);b=null;if(k.$isRootOrShadowRoot(f))if(l)if(null!==
|
|
20
|
+
c)f.insertAfter(c);else for(c=g.length-1;0<=c;c--)f.insertAfter(g[c]);else if(l=f.getFirstChild(),k.$isElementNode(l)&&(f=l),null===l)if(c)f.append(c);else for(c=0;c<g.length;c++)l=g[c],f.append(l),b=l;else if(null!==c)l.insertBefore(c);else for(f=0;f<g.length;f++)c=g[f],l.insertBefore(c),b=c;else if(c)f.insertAfter(c);else for(c=g.length-1;0<=c;c--)l=g[c],f.insertAfter(l),b=l;g=k.$getPreviousSelection();k.$isRangeSelection(g)&&g.anchor.getNode().isAttached()&&g.focus.getNode().isAttached()?k.$setSelection(g.clone()):
|
|
21
|
+
null!==b?b.selectEnd():a.dirty=!0}}function J(a,b,d,e){a.modify(b?"extend":"move",d,e)}function K(a){a=a.anchor.getNode();return"rtl"===(k.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function L(a,b){for(;null!==a&&null!==a.getParent()&&!b(a);)a=a.getParentOrThrow();return b(a)?a:null}exports.$cloneWithProperties=k.$cloneWithProperties;exports.$selectAll=k.$selectAll;exports.$addNodeStyle=function(a){a=a.getStyle();let b=B(a);x.set(a,b)};exports.$forEachSelectedTextNode=G;
|
|
22
|
+
exports.$getSelectionStyleValueForProperty=function(a,b,d=""){let e=null,c=a.getNodes();var f=a.anchor,h=a.focus,g=a.isBackward();let l=g?h.offset:f.offset;f=g?h.getNode():f.getNode();if(k.$isRangeSelection(a)&&a.isCollapsed()&&""!==a.style&&(a=C(a.style),null!==a&&b in a))return a[b];for(a=0;a<c.length;a++){var n=c[a];if((0===a||0!==l||!n.is(f))&&k.$isTextNode(n))if(h=b,g=d,n=n.getStyle(),n=C(n),h=null!==n?n[h]||g:g,null===e)e=h;else if(e!==h){e="";break}}return null===e?d:e};
|
|
23
|
+
exports.$isAtNodeEnd=function(a){if("text"===a.type)return a.offset===a.getNode().getTextContentSize();let b=a.getNode();k.$isElementNode(b)||v(177);return a.offset===b.getChildrenSize()};exports.$isParentElementRTL=K;exports.$moveCaretSelection=J;exports.$moveCharacter=function(a,b,d){let e=K(a);J(a,b,d?!e:e,"character")};exports.$patchStyleText=function(a,b){a.isCollapsed()&&k.$isRangeSelection(a)?F(a,b):G(d=>{F(d,b)})};
|
|
24
|
+
exports.$setBlocksType=function(a,b){if(null!==a){var d=a.getStartEndPoints(),e=d?d[0]:null;d=a.is(k.$getSelection())&&a.isCollapsed();if(null!==e&&"root"===e.key){b=b();var c=k.$getRoot();(a=c.getFirstChild())?a.replace(b,!0):c.append(b);d&&b.select()}else{a=a.getNodes().filter(k.INTERNAL_$isBlock).filter(k.$isElementNode);var f=e?L(e.getNode(),k.INTERNAL_$isBlock):null;k.$isElementNode(f)&&!a.find(h=>h.is(f))&&a.push(f);for(c of a)a=b(),a.setFormat(c.getFormatType()),a.setIndent(c.getIndent()),
|
|
25
|
+
c.replace(a,!0),c.is(f)&&d&&a.select()}}};exports.$shouldOverrideDefaultCharacterSelection=function(a,b){a=k.$getAdjacentNode(a.focus,b);return k.$isDecoratorNode(a)&&!a.isIsolated()||k.$isElementNode(a)&&!a.isInline()&&!a.canBeEmpty()};
|
|
26
|
+
exports.$sliceSelectedTextNodeContent=function(a,b){var d=a.getStartEndPoints();if(b.isSelected(a)&&!b.isSegmented()&&!b.isToken()&&null!==d){let [g,l]=d;d=a.isBackward();var e=g.getNode(),c=l.getNode(),f=b.is(e),h=b.is(c);if(f||h){let [n,p]=k.$getCharacterOffsets(a);a=e.is(c);f=b.is(d?c:e);c=b.is(d?e:c);e=0;h=void 0;a?(e=n>p?p:n,h=n>p?n:p):f?(e=d?p:n,h=void 0):c&&(d=d?n:p,e=0,h=d);b.__text=b.__text.slice(e,h)}}return b};exports.$trimTextContentFromAnchor=E;
|
|
27
|
+
exports.$wrapNodes=function(a,b,d=null){var e=a.getStartEndPoints(),c=e?e[0]:null;e=a.getNodes();let f=e.length;if(null!==c&&(0===f||1===f&&"element"===c.type&&0===c.getNode().getChildrenSize())){a="text"===c.type?c.getNode().getParentOrThrow():c.getNode();e=a.getChildren();let g=b();g.setFormat(a.getFormatType());g.setIndent(a.getIndent());e.forEach(l=>g.append(l));d&&(g=d.append(g));a.replace(g)}else{c=null;var h=[];for(let g=0;g<f;g++){let l=e[g];k.$isRootOrShadowRoot(l)?(I(a,h,h.length,b,d),h=
|
|
28
|
+
[],c=l):null===c||null!==c&&k.$hasAncestor(l,c)?h.push(l):(I(a,h,h.length,b,d),h=[l])}I(a,h,h.length,b,d)}};
|
|
29
|
+
exports.createDOMRange=function(a,b,d,e,c){let f=b.getKey(),h=e.getKey(),g=document.createRange(),l=a.getElementByKey(f);a=a.getElementByKey(h);k.$isTextNode(b)&&(l=z(l));k.$isTextNode(e)&&(a=z(a));if(void 0===b||void 0===e||null===l||null===a)return null;"BR"===l.nodeName&&([l,d]=A(l));"BR"===a.nodeName&&([a,c]=A(a));b=l.firstChild;l===a&&null!=b&&"BR"===b.nodeName&&0===d&&0===c&&(c=1);try{g.setStart(l,d),g.setEnd(a,c)}catch(n){return null}!g.collapsed||d===c&&f===h||(g.setStart(a,c),g.setEnd(l,
|
|
30
|
+
d));return g};exports.createRectsFromDOMRange=function(a,b){var d=a.getRootElement();if(null===d)return[];a=d.getBoundingClientRect();d=getComputedStyle(d);d=parseFloat(d.paddingLeft)+parseFloat(d.paddingRight);b=Array.from(b.getClientRects());let e=b.length;b.sort((f,h)=>{let g=f.top-h.top;return 3>=Math.abs(g)?f.left-h.left:g});let c;for(let f=0;f<e;f++){let h=b[f],g=h.width+d===a.width;c&&c.top<=h.top&&c.top+c.height>h.top&&c.left+c.width>h.left||g?(b.splice(f--,1),e--):c=h}return b};
|
|
32
31
|
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 s,$isRangeSelection as i,$getSelection as c,$isTokenOrSegmented as f,$getRoot as u
|
|
9
|
+
import{$isTextNode as e,$getCharacterOffsets as t,$isElementNode as n,$isRootNode as l,$getNodeByKey as o,$getPreviousSelection as r,$createTextNode as s,$isRangeSelection as i,$getSelection as c,$isTokenOrSegmented as f,$getRoot as u,INTERNAL_$isBlock as a,$isRootOrShadowRoot as g,$hasAncestor as d,$isLeafNode as p,$setSelection as h,$getAdjacentNode as y,$isDecoratorNode as m}from"lexical";export{$cloneWithProperties,$selectAll}from"lexical";function S(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var x=S((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 T=new Map;function v(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function C(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function N(t,n,l,o,r){const s=n.getKey(),i=o.getKey(),c=document.createRange();let f=t.getElementByKey(s),u=t.getElementByKey(i),a=l,g=r;if(e(n)&&(f=v(f)),e(o)&&(u=v(u)),void 0===n||void 0===o||null===f||null===u)return null;"BR"===f.nodeName&&([f,a]=C(f)),"BR"===u.nodeName&&([u,g]=C(u));const d=f.firstChild;f===u&&null!=d&&"BR"===d.nodeName&&0===a&&0===g&&(g=1);try{c.setStart(f,a),c.setEnd(u,g)}catch(e){return null}return!c.collapsed||a===g&&s===i||(c.setStart(u,g),c.setEnd(f,a)),c}function P(e,t){const n=e.getRootElement();if(null===n)return[];const l=n.getBoundingClientRect(),o=getComputedStyle(n),r=parseFloat(o.paddingLeft)+parseFloat(o.paddingRight),s=Array.from(t.getClientRects());let i,c=s.length;s.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=s[e],n=i&&i.top<=t.top&&i.top+i.height>t.top&&i.left+i.width>t.left,o=t.width+r===l.width;n||o?(s.splice(e--,1),c--):i=t}return s}function w(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 E(e){let t=T.get(e);return void 0===t&&(t=w(e),T.set(e,t)),t}function F(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function K(e,n){const l=e.getStartEndPoints();if(n.isSelected(e)&&!n.isSegmented()&&!n.isToken()&&null!==l){const[o,r]=l,s=e.isBackward(),i=o.getNode(),c=r.getNode(),f=n.is(i),u=n.is(c);if(f||u){const[l,o]=t(e),r=i.is(c),f=n.is(s?c:i),u=n.is(s?i:c);let a,g=0;if(r)g=l>o?o:l,a=l>o?l:o;else if(f){g=s?o:l,a=void 0}else if(u){g=0,a=s?l:o}return n.__text=n.__text.slice(g,a),n}}return n}function I(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return n(t)||x(177),e.offset===t.getChildrenSize()}function k(t,c,f){let u=c.getNode(),a=f;if(n(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e)}for(;a>0&&null!==u;){if(n(u)){const e=u.getLastDescendant();null!==e&&(u=e)}let f=u.getPreviousSibling(),g=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&&(g=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)||a>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||l(e)||e.remove(),a-=p+g,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-a,g=d.slice(0,f);if(null!==l&&l!==d){const e=r();let t=u;if(u.isSimpleText())u.setTextContent(l);else{const e=s(l);u.replace(e),t=e}if(i(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<a&&(t=p);const l=e?t-a: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=s(g);u.replace(e)}a=0}}}function B(e){const t=e.getStyle(),n=w(t);T.set(t,n)}function b(e,t){const n=E("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=F(l);e.setStyle(o),T.set(o,l)}function O(e,t){e.isCollapsed()&&i(e)?b(e,t):R((e=>{b(e,t)}))}function R(t){const n=c();if(!i(n))return;const l=n.getNodes(),o=l.length,{anchor:r,focus:s}=n,u=o-1;let a=l[0],g=l[u];const d=a.getTextContent().length,p=s.offset;let h=r.offset;const y=r.isBefore(s);let m=y?h:p,S=y?p:h;const x=y?r.type:s.type,T=y?s.type:r.type,v=y?s.key:r.key;if(e(a)&&m===d){const t=a.getNextSibling();e(t)&&(h=0,m=0,a=t)}if(1===l.length){if(e(a)&&a.canHaveFormat()){if(m="element"===x?0:h>p?p:h,S="element"===T?d:h>p?h:p,m===S)return;if(f(a)||0===m&&S===d)t(a),a.select(m,S);else{const e=a.splitText(m,S),n=0===m?e[0]:e[1];t(n),n.select(0,S-m)}}}else{if(e(a)&&m<a.getTextContentSize()&&a.canHaveFormat()&&(0===m||f(a)||(a=a.splitText(m)[1],m=0,y?r.set(a.getKey(),m,"text"):s.set(a.getKey(),m,"text")),t(a)),e(g)&&g.canHaveFormat()){const e=g.getTextContent().length;g.__key!==v&&0!==S&&(S=e),S===e||f(g)||([g]=g.splitText(S)),0===S&&"element"!==T||t(g)}for(let n=1;n<u;n++){const o=l[n],r=o.getKey();e(o)&&o.canHaveFormat()&&r!==a.getKey()&&r!==g.getKey()&&!o.isToken()&&t(o)}}}function _(e,t){if(null===e)return;const l=e.getStartEndPoints(),o=l?l[0]:null,r=e.is(c())&&e.isCollapsed();if(null!==o&&"root"===o.key){const e=t(),n=u(),l=n.getFirstChild();return l?l.replace(e,!0):n.append(e),void(r&&e.select())}const s=e.getNodes().filter(a).filter(n),i=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(),a):null;n(i)&&!s.find((e=>e.is(i)))&&s.push(i);for(const e of s){const n=t();n.setFormat(e.getFormatType()),n.setIndent(e.getIndent()),e.replace(n,!0),e.is(i)&&r&&n.select()}}function A(e){return e.getNode().isAttached()}function z(e){let t=e;for(;null!==t&&!g(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function $(e,t,n=null){const l=e.getStartEndPoints(),o=l?l[0]:null,r=e.getNodes(),s=r.length;if(null!==o&&(0===s||1===s&&"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 i=null,c=[];for(let l=0;l<s;l++){const o=r[l];g(o)?(L(e,c,c.length,t,n),c=[],i=o):null===i||null!==i&&d(o,i)?c.push(o):(L(e,c,c.length,t,n),c=[o])}L(e,c,c.length,t,n)}function L(e,t,l,o,s=null){if(0===t.length)return;const c=t[0],f=new Map,u=[];let a=n(c)?c:c.getParentOrThrow();a.isInline()&&(a=a.getParentOrThrow());let d=!1;for(;null!==a;){const e=a.getPreviousSibling();if(null!==e){a=e,d=!0;break}if(a=a.getParentOrThrow(),g(a))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&&p(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()),u.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)))})),z(r)}}else if(y.has(l.getKey())){n(l)||x(179);const e=o();e.setFormat(l.getFormatType()),e.setIndent(l.getIndent()),u.push(e),l.remove(!0)}}if(null!==s)for(let e=0;e<u.length;e++){const t=u[e];s.append(t)}let S=null;if(g(a))if(d)if(null!==s)a.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];a.insertAfter(t)}else{const e=a.getFirstChild();if(n(e)&&(a=e),null===e)if(s)a.append(s);else for(let e=0;e<u.length;e++){const t=u[e];a.append(t),S=t}else if(null!==s)e.insertBefore(s);else for(let t=0;t<u.length;t++){const n=u[t];e.insertBefore(n),S=n}}else if(s)a.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];a.insertAfter(t),S=t}const T=r();i(T)&&A(T.anchor)&&A(T.focus)?h(T.clone()):null!==S?S.selectEnd():e.dirty=!0}function M(e,t){const l=y(e.focus,t);return m(l)&&!l.isIsolated()||n(l)&&!l.isInline()&&!l.canBeEmpty()}function D(e,t,n,l){e.modify(t?"extend":"move",n,l)}function H(e){const t=e.anchor.getNode();return"rtl"===(l(t)?t:t.getParentOrThrow()).getDirection()}function j(e,t,n){const l=H(e);D(e,t,n?!l:l,"character")}function U(e,t,n){const l=E(e.getStyle());return null!==l&&l[t]||n}function W(t,n,l=""){let o=null;const r=t.getNodes(),s=t.anchor,c=t.focus,f=t.isBackward(),u=f?c.offset:s.offset,a=f?c.getNode():s.getNode();if(i(t)&&t.isCollapsed()&&""!==t.style){const e=E(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<r.length;t++){const s=r[t];if((0===t||0!==u||!s.is(a))&&e(s)){const e=U(s,n,l);if(null===o)o=e;else if(o!==e){o="";break}}}return null===o?l:o}const X=k;export{B as $addNodeStyle,R as $forEachSelectedTextNode,W as $getSelectionStyleValueForProperty,I as $isAtNodeEnd,H as $isParentElementRTL,D as $moveCaretSelection,j as $moveCharacter,O as $patchStyleText,_ as $setBlocksType,M as $shouldOverrideDefaultCharacterSelection,K as $sliceSelectedTextNodeContent,k as $trimTextContentFromAnchor,$ as $wrapNodes,N as createDOMRange,P as createRectsFromDOMRange,F as getCSSFromStyleObject,E as getStyleObjectFromCSS,X as trimTextContentFromAnchor};
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"selection"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.23.
|
|
12
|
+
"version": "0.23.2-nightly.20250113.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.23.
|
|
40
|
+
"lexical": "0.23.2-nightly.20250113.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/range-selection.d.ts
CHANGED
|
@@ -68,9 +68,4 @@ export declare function $moveCharacter(selection: RangeSelection, isHoldingShift
|
|
|
68
68
|
* @returns The value of the property for the selected TextNodes.
|
|
69
69
|
*/
|
|
70
70
|
export declare function $getSelectionStyleValueForProperty(selection: RangeSelection | TableSelection, styleProperty: string, defaultValue?: string): string;
|
|
71
|
-
/**
|
|
72
|
-
* This function is for internal use of the library.
|
|
73
|
-
* Please do not use it as it may change in the future.
|
|
74
|
-
*/
|
|
75
|
-
export declare function INTERNAL_$isBlock(node: LexicalNode): node is ElementNode;
|
|
76
71
|
export declare function $getAncestor<NodeType extends LexicalNode = LexicalNode>(node: LexicalNode, predicate: (ancestor: LexicalNode) => ancestor is NodeType): NodeType | null;
|