@lexical/selection 0.16.2-nightly.20240719.0 → 0.16.2-nightly.20240723.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 +7 -51
- package/LexicalSelection.dev.mjs +9 -52
- package/LexicalSelection.prod.js +24 -24
- package/LexicalSelection.prod.mjs +1 -1
- package/index.d.ts +4 -2
- package/lexical-node.d.ts +0 -6
- package/package.json +2 -2
package/LexicalSelection.dev.js
CHANGED
|
@@ -197,50 +197,6 @@ function getCSSFromStyleObject(styles) {
|
|
|
197
197
|
* LICENSE file in the root directory of this source tree.
|
|
198
198
|
*
|
|
199
199
|
*/
|
|
200
|
-
function $updateElementNodeProperties(target, source) {
|
|
201
|
-
target.__first = source.__first;
|
|
202
|
-
target.__last = source.__last;
|
|
203
|
-
target.__size = source.__size;
|
|
204
|
-
target.__format = source.__format;
|
|
205
|
-
target.__indent = source.__indent;
|
|
206
|
-
target.__dir = source.__dir;
|
|
207
|
-
return target;
|
|
208
|
-
}
|
|
209
|
-
function $updateTextNodeProperties(target, source) {
|
|
210
|
-
target.__format = source.__format;
|
|
211
|
-
target.__style = source.__style;
|
|
212
|
-
target.__mode = source.__mode;
|
|
213
|
-
target.__detail = source.__detail;
|
|
214
|
-
return target;
|
|
215
|
-
}
|
|
216
|
-
function $updateParagraphNodeProperties(target, source) {
|
|
217
|
-
target.__textFormat = source.__textFormat;
|
|
218
|
-
return target;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Returns a copy of a node, but generates a new key for the copy.
|
|
223
|
-
* @param node - The node to be cloned.
|
|
224
|
-
* @returns The clone of the node.
|
|
225
|
-
*/
|
|
226
|
-
function $cloneWithProperties(node) {
|
|
227
|
-
const constructor = node.constructor;
|
|
228
|
-
// @ts-expect-error
|
|
229
|
-
const clone = constructor.clone(node);
|
|
230
|
-
clone.__parent = node.__parent;
|
|
231
|
-
clone.__next = node.__next;
|
|
232
|
-
clone.__prev = node.__prev;
|
|
233
|
-
if (lexical.$isElementNode(node) && lexical.$isElementNode(clone)) {
|
|
234
|
-
return $updateElementNodeProperties(clone, node);
|
|
235
|
-
}
|
|
236
|
-
if (lexical.$isTextNode(node) && lexical.$isTextNode(clone)) {
|
|
237
|
-
return $updateTextNodeProperties(clone, node);
|
|
238
|
-
}
|
|
239
|
-
if (lexical.$isParagraphNode(node) && lexical.$isParagraphNode(clone)) {
|
|
240
|
-
return $updateParagraphNodeProperties(clone, node);
|
|
241
|
-
}
|
|
242
|
-
return clone;
|
|
243
|
-
}
|
|
244
200
|
|
|
245
201
|
/**
|
|
246
202
|
* Generally used to append text content to HTML and JSON. Grabs the text content and "slices"
|
|
@@ -496,8 +452,8 @@ function $patchStyleText(selection, patch) {
|
|
|
496
452
|
return;
|
|
497
453
|
}
|
|
498
454
|
|
|
499
|
-
// The entire node is selected, so just format it
|
|
500
|
-
if (startOffset === 0 && endOffset === firstNodeTextLength) {
|
|
455
|
+
// The entire node is selected or a token/segment, so just format it
|
|
456
|
+
if (lexical.$isTokenOrSegmented(firstNode) || startOffset === 0 && endOffset === firstNodeTextLength) {
|
|
501
457
|
$patchStyle(firstNode, patch);
|
|
502
458
|
firstNode.select(startOffset, endOffset);
|
|
503
459
|
} else {
|
|
@@ -511,8 +467,8 @@ function $patchStyleText(selection, patch) {
|
|
|
511
467
|
} // multiple nodes selected.
|
|
512
468
|
} else {
|
|
513
469
|
if (lexical.$isTextNode(firstNode) && startOffset < firstNode.getTextContentSize() && firstNode.canHaveFormat()) {
|
|
514
|
-
if (startOffset !== 0) {
|
|
515
|
-
// the entire first node isn't selected, so split it
|
|
470
|
+
if (startOffset !== 0 && !lexical.$isTokenOrSegmented(firstNode)) {
|
|
471
|
+
// the entire first node isn't selected and it isn't a token or segmented, so split it
|
|
516
472
|
firstNode = firstNode.splitText(startOffset)[1];
|
|
517
473
|
startOffset = 0;
|
|
518
474
|
if (isBefore) {
|
|
@@ -535,8 +491,8 @@ function $patchStyleText(selection, patch) {
|
|
|
535
491
|
endOffset = lastNodeTextLength;
|
|
536
492
|
}
|
|
537
493
|
|
|
538
|
-
// if the entire last node isn't selected, split it
|
|
539
|
-
if (endOffset !== lastNodeTextLength) {
|
|
494
|
+
// if the entire last node isn't selected and it isn't a token or segmented, split it
|
|
495
|
+
if (endOffset !== lastNodeTextLength && !lexical.$isTokenOrSegmented(lastNode)) {
|
|
540
496
|
[lastNode] = lastNode.splitText(endOffset);
|
|
541
497
|
}
|
|
542
498
|
if (endOffset !== 0 || endType === 'element') {
|
|
@@ -996,8 +952,8 @@ function $getAncestor(node, predicate) {
|
|
|
996
952
|
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
997
953
|
const trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
998
954
|
|
|
955
|
+
exports.$cloneWithProperties = lexical.$cloneWithProperties;
|
|
999
956
|
exports.$addNodeStyle = $addNodeStyle;
|
|
1000
|
-
exports.$cloneWithProperties = $cloneWithProperties;
|
|
1001
957
|
exports.$getSelectionStyleValueForProperty = $getSelectionStyleValueForProperty;
|
|
1002
958
|
exports.$isAtNodeEnd = $isAtNodeEnd;
|
|
1003
959
|
exports.$isParentElementRTL = $isParentElementRTL;
|
package/LexicalSelection.dev.mjs
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { $isTextNode, $
|
|
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
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -195,50 +196,6 @@ function getCSSFromStyleObject(styles) {
|
|
|
195
196
|
* LICENSE file in the root directory of this source tree.
|
|
196
197
|
*
|
|
197
198
|
*/
|
|
198
|
-
function $updateElementNodeProperties(target, source) {
|
|
199
|
-
target.__first = source.__first;
|
|
200
|
-
target.__last = source.__last;
|
|
201
|
-
target.__size = source.__size;
|
|
202
|
-
target.__format = source.__format;
|
|
203
|
-
target.__indent = source.__indent;
|
|
204
|
-
target.__dir = source.__dir;
|
|
205
|
-
return target;
|
|
206
|
-
}
|
|
207
|
-
function $updateTextNodeProperties(target, source) {
|
|
208
|
-
target.__format = source.__format;
|
|
209
|
-
target.__style = source.__style;
|
|
210
|
-
target.__mode = source.__mode;
|
|
211
|
-
target.__detail = source.__detail;
|
|
212
|
-
return target;
|
|
213
|
-
}
|
|
214
|
-
function $updateParagraphNodeProperties(target, source) {
|
|
215
|
-
target.__textFormat = source.__textFormat;
|
|
216
|
-
return target;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Returns a copy of a node, but generates a new key for the copy.
|
|
221
|
-
* @param node - The node to be cloned.
|
|
222
|
-
* @returns The clone of the node.
|
|
223
|
-
*/
|
|
224
|
-
function $cloneWithProperties(node) {
|
|
225
|
-
const constructor = node.constructor;
|
|
226
|
-
// @ts-expect-error
|
|
227
|
-
const clone = constructor.clone(node);
|
|
228
|
-
clone.__parent = node.__parent;
|
|
229
|
-
clone.__next = node.__next;
|
|
230
|
-
clone.__prev = node.__prev;
|
|
231
|
-
if ($isElementNode(node) && $isElementNode(clone)) {
|
|
232
|
-
return $updateElementNodeProperties(clone, node);
|
|
233
|
-
}
|
|
234
|
-
if ($isTextNode(node) && $isTextNode(clone)) {
|
|
235
|
-
return $updateTextNodeProperties(clone, node);
|
|
236
|
-
}
|
|
237
|
-
if ($isParagraphNode(node) && $isParagraphNode(clone)) {
|
|
238
|
-
return $updateParagraphNodeProperties(clone, node);
|
|
239
|
-
}
|
|
240
|
-
return clone;
|
|
241
|
-
}
|
|
242
199
|
|
|
243
200
|
/**
|
|
244
201
|
* Generally used to append text content to HTML and JSON. Grabs the text content and "slices"
|
|
@@ -494,8 +451,8 @@ function $patchStyleText(selection, patch) {
|
|
|
494
451
|
return;
|
|
495
452
|
}
|
|
496
453
|
|
|
497
|
-
// The entire node is selected, so just format it
|
|
498
|
-
if (startOffset === 0 && endOffset === firstNodeTextLength) {
|
|
454
|
+
// The entire node is selected or a token/segment, so just format it
|
|
455
|
+
if ($isTokenOrSegmented(firstNode) || startOffset === 0 && endOffset === firstNodeTextLength) {
|
|
499
456
|
$patchStyle(firstNode, patch);
|
|
500
457
|
firstNode.select(startOffset, endOffset);
|
|
501
458
|
} else {
|
|
@@ -509,8 +466,8 @@ function $patchStyleText(selection, patch) {
|
|
|
509
466
|
} // multiple nodes selected.
|
|
510
467
|
} else {
|
|
511
468
|
if ($isTextNode(firstNode) && startOffset < firstNode.getTextContentSize() && firstNode.canHaveFormat()) {
|
|
512
|
-
if (startOffset !== 0) {
|
|
513
|
-
// the entire first node isn't selected, so split it
|
|
469
|
+
if (startOffset !== 0 && !$isTokenOrSegmented(firstNode)) {
|
|
470
|
+
// the entire first node isn't selected and it isn't a token or segmented, so split it
|
|
514
471
|
firstNode = firstNode.splitText(startOffset)[1];
|
|
515
472
|
startOffset = 0;
|
|
516
473
|
if (isBefore) {
|
|
@@ -533,8 +490,8 @@ function $patchStyleText(selection, patch) {
|
|
|
533
490
|
endOffset = lastNodeTextLength;
|
|
534
491
|
}
|
|
535
492
|
|
|
536
|
-
// if the entire last node isn't selected, split it
|
|
537
|
-
if (endOffset !== lastNodeTextLength) {
|
|
493
|
+
// if the entire last node isn't selected and it isn't a token or segmented, split it
|
|
494
|
+
if (endOffset !== lastNodeTextLength && !$isTokenOrSegmented(lastNode)) {
|
|
538
495
|
[lastNode] = lastNode.splitText(endOffset);
|
|
539
496
|
}
|
|
540
497
|
if (endOffset !== 0 || endType === 'element') {
|
|
@@ -994,4 +951,4 @@ function $getAncestor(node, predicate) {
|
|
|
994
951
|
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
995
952
|
const trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
996
953
|
|
|
997
|
-
export { $addNodeStyle, $
|
|
954
|
+
export { $addNodeStyle, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $patchStyleText, $selectAll, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, $wrapNodes, createDOMRange, createRectsFromDOMRange, getStyleObjectFromCSS, trimTextContentFromAnchor };
|
package/LexicalSelection.prod.js
CHANGED
|
@@ -6,28 +6,28 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
'use strict';var k=require("lexical"),u;function w(a){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
|
|
11
|
-
function E(a,b
|
|
12
|
-
if(!k.$isTextNode(e)||c
|
|
13
|
-
e.isSimpleText()?(h=
|
|
14
|
-
function G(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let
|
|
15
|
-
function H(a,b,
|
|
16
|
-
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!==
|
|
17
|
-
|
|
18
|
-
null!==
|
|
19
|
-
exports.$
|
|
20
|
-
|
|
21
|
-
exports.$isAtNodeEnd=function(a){if("text"===a.type)return a.offset===a.getNode().getTextContentSize();let
|
|
22
|
-
exports.$patchStyleText=function(a,
|
|
23
|
-
"element"===t?l:p>m?p:m,n!==a&&(0===n&&a===l?(F(d
|
|
24
|
-
n.canHaveFormat()&&t!==
|
|
25
|
-
exports.$selectAll=function(a){let
|
|
26
|
-
exports.$setBlocksType=function(a,
|
|
27
|
-
e.replace(
|
|
28
|
-
exports.$sliceSelectedTextNodeContent=function(a,
|
|
29
|
-
exports.$wrapNodes=function(a,b
|
|
30
|
-
[],
|
|
31
|
-
exports.createDOMRange=function(a,b,
|
|
32
|
-
|
|
9
|
+
'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;
|
|
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={};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}
|
|
11
|
+
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;
|
|
12
|
+
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))):
|
|
13
|
+
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])=>{h instanceof Function?c[g]=h(b[g]):null===h?delete c[g]:c[g]=h;return c},{...b});let e=D(d);a.setStyle(e);x.set(e,d)}
|
|
14
|
+
function G(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let d=a.getLatest(),b=a.getParent();0===d.getChildrenSize()&&a.remove(!0);a=b}}
|
|
15
|
+
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!==
|
|
16
|
+
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!==
|
|
17
|
+
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()):
|
|
18
|
+
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;
|
|
19
|
+
exports.$addNodeStyle=function(a){a=a.getStyle();let d=B(a);x.set(a,d)};
|
|
20
|
+
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};
|
|
21
|
+
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")};
|
|
22
|
+
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=
|
|
23
|
+
"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===
|
|
24
|
+
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)}}};
|
|
25
|
+
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))};
|
|
26
|
+
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());
|
|
27
|
+
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()};
|
|
28
|
+
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;
|
|
29
|
+
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=
|
|
30
|
+
[],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)}};
|
|
31
|
+
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,
|
|
32
|
+
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};
|
|
33
33
|
exports.getStyleObjectFromCSS=C;exports.trimTextContentFromAnchor=E
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$isTextNode as e,$isElementNode as t,$isParagraphNode as n,$getCharacterOffsets as o,$isRootNode as l,$getNodeByKey as r,$getPreviousSelection as s,$createTextNode as i,$isRangeSelection as c,$getRoot as f,$isRootOrShadowRoot as u,$hasAncestor as a,$isLeafNode as g,$setSelection as d,$getAdjacentNode as p,$isDecoratorNode as h,$isLineBreakNode as _}from"lexical";function m(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var y=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 S(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function v(t,n,o,l,r){const s=n.getKey(),i=l.getKey(),c=document.createRange();let f=t.getElementByKey(s),u=t.getElementByKey(i),a=o,g=r;if(e(n)&&(f=T(f)),e(l)&&(u=T(u)),void 0===n||void 0===l||null===f||null===u)return null;"BR"===f.nodeName&&([f,a]=S(f)),"BR"===u.nodeName&&([u,g]=S(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 C(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),l=getComputedStyle(n),r=parseFloat(l.paddingLeft)+parseFloat(l.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,l=t.width+r===o.width;n||l?(s.splice(e--,1),c--):i=t}return s}function w(e){const t={},n=e.split(";");for(const e of n)if(""!==e){const[n,o]=e.split(/:([^]+)/);n&&o&&(t[n.trim()]=o.trim())}return t}function N(e){let t=x.get(e);return void 0===t&&(t=w(e),x.set(e,t)),t}function P(o){const l=o.constructor.clone(o);return l.__parent=o.__parent,l.__next=o.__next,l.__prev=o.__prev,t(o)&&t(l)?(s=o,(r=l).__first=s.__first,r.__last=s.__last,r.__size=s.__size,r.__format=s.__format,r.__indent=s.__indent,r.__dir=s.__dir,r):e(o)&&e(l)?function(e,t){return e.__format=t.__format,e.__style=t.__style,e.__mode=t.__mode,e.__detail=t.__detail,e}(l,o):n(o)&&n(l)?function(e,t){return e.__textFormat=t.__textFormat,e}(l,o):l;var r,s}function E(e,t){const n=e.getStartEndPoints();if(t.isSelected(e)&&!t.isSegmented()&&!t.isToken()&&null!==n){const[l,r]=n,s=e.isBackward(),i=l.getNode(),c=r.getNode(),f=t.is(i),u=t.is(c);if(f||u){const[n,l]=o(e),r=i.is(c),f=t.is(s?c:i),u=t.is(s?i:c);let a,g=0;if(r)g=n>l?l:n,a=n>l?n:l;else if(f){g=s?l:n,a=void 0}else if(u){g=0,a=s?n:l}return t.__text=t.__text.slice(g,a),t}}return t}function F(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const n=e.getNode();return t(n)||y(177),e.offset===n.getChildrenSize()}function K(n,o,f){let u=o.getNode(),a=f;if(t(u)){const e=u.getDescendantByIndex(o.offset);null!==e&&(u=e)}for(;a>0&&null!==u;){if(t(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&&t(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 t=u.getKey(),l=n.getEditorState().read((()=>{const n=r(t);return e(n)&&n.isSimpleText()?n.getTextContent():null})),f=p-a,g=d.slice(0,f);if(null!==l&&l!==d){const e=s();let t=u;if(u.isSimpleText())u.setTextContent(l);else{const e=i(l);u.replace(e),t=e}if(c(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n)}}else if(u.isSimpleText()){const e=o.key===t;let n=o.offset;n<a&&(n=p);const l=e?n-a:0,r=e?n:f;if(e&&0===l){const[e]=u.splitText(l,r);e.remove()}else{const[,e]=u.splitText(l,r);e.remove()}}else{const e=i(g);u.replace(e)}a=0}}}function I(e){const t=e.getStyle(),n=w(t);x.set(t,n)}function O(e,t){const n=N("getStyle"in e?e.getStyle():e.style),o=Object.entries(t).reduce(((e,[t,o])=>(o instanceof Function?e[t]=o(n[t]):null===o?delete e[t]:e[t]=o,e)),{...n}||{}),l=function(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}(o);e.setStyle(l),x.set(l,o)}function B(t,n){const o=t.getNodes(),l=o.length,r=t.getStartEndPoints();if(null===r)return;const[s,i]=r,f=l-1;let u=o[0],a=o[f];if(t.isCollapsed()&&c(t))return void O(t,n);const g=u.getTextContent().length,d=i.offset;let p=s.offset;const h=s.isBefore(i);let _=h?p:d,m=h?d:p;const y=h?s.type:i.type,x=h?i.type:s.type,T=h?i.key:s.key;if(e(u)&&_===g){const t=u.getNextSibling();e(t)&&(p=0,_=0,u=t)}if(1===o.length){if(e(u)&&u.canHaveFormat()){if(_="element"===y?0:p>d?d:p,m="element"===x?g:p>d?p:d,_===m)return;if(0===_&&m===g)O(u,n),u.select(_,m);else{const e=u.splitText(_,m),t=0===_?e[0]:e[1];O(t,n),t.select(0,m-_)}}}else{if(e(u)&&_<u.getTextContentSize()&&u.canHaveFormat()&&(0!==_&&(u=u.splitText(_)[1],_=0,h?s.set(u.getKey(),_,"text"):i.set(u.getKey(),_,"text")),O(u,n)),e(a)&&a.canHaveFormat()){const e=a.getTextContent().length;a.__key!==T&&0!==m&&(m=e),m!==e&&([a]=a.splitText(m)),0===m&&"element"!==x||O(a,n)}for(let t=1;t<f;t++){const l=o[t],r=l.getKey();e(l)&&l.canHaveFormat()&&r!==u.getKey()&&r!==a.getKey()&&!l.isToken()&&O(l,n)}}}function k(e,n){if(null===e)return;const o=e.getStartEndPoints(),l=o?o[0]:null;if(null!==l&&"root"===l.key){const e=n(),t=f(),o=t.getFirstChild();return void(o?o.replace(e,!0):t.append(e))}const r=e.getNodes(),s=null!==l&&function(e,t){let n=e;for(;null!==n&&null!==n.getParent()&&!t(n);)n=n.getParentOrThrow();return t(n)?n:null}(l.getNode(),X);s&&-1===r.indexOf(s)&&r.push(s);for(let e=0;e<r.length;e++){const o=r[e];if(!X(o))continue;t(o)||y(178);const l=n();l.setFormat(o.getFormatType()),l.setIndent(o.getIndent()),o.replace(l,!0)}}function b(e){return e.getNode().isAttached()}function z(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 R(e,t,n=null){const o=e.getStartEndPoints(),l=o?o[0]:null,r=e.getNodes(),s=r.length;if(null!==l&&(0===s||1===s&&"element"===l.type&&0===l.getNode().getChildrenSize())){const e="text"===l.type?l.getNode().getParentOrThrow():l.getNode(),o=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),o.forEach((e=>r.append(e))),n&&(r=n.append(r)),void e.replace(r)}let i=null,c=[];for(let o=0;o<s;o++){const l=r[o];u(l)?(A(e,c,c.length,t,n),c=[],i=l):null===i||null!==i&&a(l,i)?c.push(l):(A(e,c,c.length,t,n),c=[l])}A(e,c,c.length,t,n)}function A(e,n,o,l,r=null){if(0===n.length)return;const i=n[0],f=new Map,a=[];let p=t(i)?i:i.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 _=new Set;for(let e=0;e<o;e++){const o=n[e];t(o)&&0===o.getChildrenSize()&&_.add(o.getKey())}const m=new Set;for(let e=0;e<o;e++){const o=n[e];let r=o.getParent();if(null!==r&&r.isInline()&&(r=r.getParent()),null!==r&&g(o)&&!m.has(o.getKey())){const e=r.getKey();if(void 0===f.get(e)){const n=l();n.setFormat(r.getFormatType()),n.setIndent(r.getIndent()),a.push(n),f.set(e,n),r.getChildren().forEach((e=>{n.append(e),m.add(e.getKey()),t(e)&&e.getChildrenKeys().forEach((e=>m.add(e)))})),z(r)}}else if(_.has(o.getKey())){t(o)||y(179);const e=l();e.setFormat(o.getFormatType()),e.setIndent(o.getIndent()),a.push(e),o.remove(!0)}}if(null!==r)for(let e=0;e<a.length;e++){const t=a[e];r.append(t)}let x=null;if(u(p))if(h)if(null!==r)p.insertAfter(r);else for(let e=a.length-1;e>=0;e--){const t=a[e];p.insertAfter(t)}else{const e=p.getFirstChild();if(t(e)&&(p=e),null===e)if(r)p.append(r);else for(let e=0;e<a.length;e++){const t=a[e];p.append(t),x=t}else if(null!==r)e.insertBefore(r);else for(let t=0;t<a.length;t++){const n=a[t];e.insertBefore(n),x=n}}else if(r)p.insertAfter(r);else for(let e=a.length-1;e>=0;e--){const t=a[e];p.insertAfter(t),x=t}const T=s();c(T)&&b(T.anchor)&&b(T.focus)?d(T.clone()):null!==x?x.selectEnd():e.dirty=!0}function L(e,n){const o=p(e.focus,n);return h(o)&&!o.isIsolated()||t(o)&&!o.isInline()&&!o.canBeEmpty()}function D(e,t,n,o){e.modify(t?"extend":"move",n,o)}function M(e){const t=e.anchor.getNode();return"rtl"===(l(t)?t:t.getParentOrThrow()).getDirection()}function H(e,t,n){const o=M(e);D(e,t,n?!o:o,"character")}function $(n){const o=n.anchor,l=n.focus,r=o.getNode().getTopLevelElementOrThrow().getParentOrThrow();let s=r.getFirstDescendant(),i=r.getLastDescendant(),c="element",f="element",u=0;e(s)?c="text":t(s)||null===s||(s=s.getParentOrThrow()),e(i)?(f="text",u=i.getTextContentSize()):t(i)||null===i||(i=i.getParentOrThrow()),s&&i&&(o.set(s.getKey(),0,c),l.set(i.getKey(),u,f))}function j(e,t,n){const o=N(e.getStyle());return null!==o&&o[t]||n}function U(t,n,o=""){let l=null;const r=t.getNodes(),s=t.anchor,i=t.focus,f=t.isBackward(),u=f?i.offset:s.offset,a=f?i.getNode():s.getNode();if(c(t)&&t.isCollapsed()&&""!==t.style){const e=N(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=j(s,n,o);if(null===l)l=e;else if(l!==e){l="";break}}}return null===l?o:l}function X(n){if(h(n))return!1;if(!t(n)||u(n))return!1;const o=n.getFirstChild(),l=null===o||_(o)||e(o)||o.isInline();return!n.isInline()&&!1!==n.canBeEmpty()&&l}const q=K;export{I as $addNodeStyle,P as $cloneWithProperties,U as $getSelectionStyleValueForProperty,F as $isAtNodeEnd,M as $isParentElementRTL,D as $moveCaretSelection,H as $moveCharacter,B as $patchStyleText,$ as $selectAll,k as $setBlocksType,L as $shouldOverrideDefaultCharacterSelection,E as $sliceSelectedTextNodeContent,K as $trimTextContentFromAnchor,R as $wrapNodes,v as createDOMRange,C as createRectsFromDOMRange,N as getStyleObjectFromCSS,q as trimTextContentFromAnchor};
|
|
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,$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}from"lexical";function m(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var T=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 S(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 s=n.getKey(),i=o.getKey(),c=document.createRange();let f=t.getElementByKey(s),u=t.getElementByKey(i),g=l,a=r;if(e(n)&&(f=S(f)),e(o)&&(u=S(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&&s===i||(c.setStart(u,a),c.setEnd(f,g)),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={},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 N(e){let t=x.get(e);return void 0===t&&(t=w(e),x.set(e,t)),t}function E(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 g,a=0;if(r)a=l>o?o:l,g=l>o?l:o;else if(f){a=s?o:l,g=void 0}else if(u){a=0,g=s?l:o}return n.__text=n.__text.slice(a,g),n}}return n}function F(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return n(t)||T(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=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<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=s(a);u.replace(e)}g=0}}}function I(e){const t=e.getStyle(),n=w(t);x.set(t,n)}function O(e,t){const n=N("getStyle"in e?e.getStyle():e.style),l=Object.entries(t).reduce(((e,[t,l])=>(l instanceof Function?e[t]=l(n[t]):null===l?delete e[t]:e[t]=l,e)),{...n}||{}),o=function(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}(l);e.setStyle(o),x.set(o,l)}function B(t,n){const l=t.getNodes(),o=l.length,r=t.getStartEndPoints();if(null===r)return;const[s,f]=r,u=o-1;let g=l[0],a=l[u];if(t.isCollapsed()&&i(t))return void O(t,n);const d=g.getTextContent().length,p=f.offset;let h=s.offset;const y=s.isBefore(f);let m=y?h:p,T=y?p:h;const x=y?s.type:f.type,S=y?f.type:s.type,v=y?f.key:s.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,T="element"===S?d:h>p?h:p,m===T)return;if(c(g)||0===m&&T===d)O(g,n),g.select(m,T);else{const e=g.splitText(m,T),t=0===m?e[0]:e[1];O(t,n),t.select(0,T-m)}}}else{if(e(g)&&m<g.getTextContentSize()&&g.canHaveFormat()&&(0===m||c(g)||(g=g.splitText(m)[1],m=0,y?s.set(g.getKey(),m,"text"):f.set(g.getKey(),m,"text")),O(g,n)),e(a)&&a.canHaveFormat()){const e=a.getTextContent().length;a.__key!==v&&0!==T&&(T=e),T===e||c(a)||([a]=a.splitText(T)),0===T&&"element"!==S||O(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()&&O(o,n)}}}function k(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(),s=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);s&&-1===r.indexOf(s)&&r.push(s);for(let e=0;e<r.length;e++){const l=r[e];if(!U(l))continue;n(l)||T(178);const o=t();o.setFormat(l.getFormatType()),o.setIndent(l.getIndent()),l.replace(o,!0)}}function b(e){return e.getNode().isAttached()}function R(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 _(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];u(o)?(z(e,c,c.length,t,n),c=[],i=o):null===i||null!==i&&g(o,i)?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,s=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(r)}}else if(y.has(l.getKey())){n(l)||T(179);const e=o();e.setFormat(l.getFormatType()),e.setIndent(l.getIndent()),g.push(e),l.remove(!0)}}if(null!==s)for(let e=0;e<g.length;e++){const t=g[e];s.append(t)}let x=null;if(u(p))if(h)if(null!==s)p.insertAfter(s);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(s)p.append(s);else for(let e=0;e<g.length;e++){const t=g[e];p.append(t),x=t}else if(null!==s)e.insertBefore(s);else for(let t=0;t<g.length;t++){const n=g[t];e.insertBefore(n),x=n}}else if(s)p.insertAfter(s);else for(let e=g.length-1;e>=0;e--){const t=g[e];p.insertAfter(t),x=t}const S=r();i(S)&&b(S.anchor)&&b(S.focus)?d(S.clone()):null!==x?x.selectEnd():e.dirty=!0}function A(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 D(e){const t=e.anchor.getNode();return"rtl"===(l(t)?t:t.getParentOrThrow()).getDirection()}function M(e,t,n){const l=D(e);L(e,t,n?!l:l,"character")}function $(t){const l=t.anchor,o=t.focus,r=l.getNode().getTopLevelElementOrThrow().getParentOrThrow();let s=r.getFirstDescendant(),i=r.getLastDescendant(),c="element",f="element",u=0;e(s)?c="text":n(s)||null===s||(s=s.getParentOrThrow()),e(i)?(f="text",u=i.getTextContentSize()):n(i)||null===i||(i=i.getParentOrThrow()),s&&i&&(l.set(s.getKey(),0,c),o.set(i.getKey(),u,f))}function H(e,t,n){const l=N(e.getStyle());return null!==l&&l[t]||n}function j(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,g=f?c.getNode():s.getNode();if(i(t)&&t.isCollapsed()&&""!==t.style){const e=N(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(g))&&e(s)){const e=H(s,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{I as $addNodeStyle,j as $getSelectionStyleValueForProperty,F as $isAtNodeEnd,D as $isParentElementRTL,L as $moveCaretSelection,M as $moveCharacter,B as $patchStyleText,$ as $selectAll,k as $setBlocksType,A as $shouldOverrideDefaultCharacterSelection,E as $sliceSelectedTextNodeContent,K as $trimTextContentFromAnchor,_ as $wrapNodes,C as createDOMRange,P as createRectsFromDOMRange,N as getStyleObjectFromCSS,W as trimTextContentFromAnchor};
|
package/index.d.ts
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { $addNodeStyle, $
|
|
8
|
+
import { $addNodeStyle, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor } from './lexical-node';
|
|
9
9
|
import { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $selectAll, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes } from './range-selection';
|
|
10
10
|
import { createDOMRange, createRectsFromDOMRange, getStyleObjectFromCSS } from './utils';
|
|
11
|
-
export {
|
|
11
|
+
export {
|
|
12
|
+
/** @deprecated moved to the lexical package */ $cloneWithProperties, } from 'lexical';
|
|
13
|
+
export { $addNodeStyle, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, };
|
|
12
14
|
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
13
15
|
export declare const trimTextContentFromAnchor: typeof $trimTextContentFromAnchor;
|
|
14
16
|
export { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $selectAll, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes, };
|
package/lexical-node.d.ts
CHANGED
|
@@ -6,12 +6,6 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import { BaseSelection, LexicalEditor, LexicalNode, Point, TextNode } from 'lexical';
|
|
9
|
-
/**
|
|
10
|
-
* Returns a copy of a node, but generates a new key for the copy.
|
|
11
|
-
* @param node - The node to be cloned.
|
|
12
|
-
* @returns The clone of the node.
|
|
13
|
-
*/
|
|
14
|
-
export declare function $cloneWithProperties<T extends LexicalNode>(node: T): T;
|
|
15
9
|
/**
|
|
16
10
|
* Generally used to append text content to HTML and JSON. Grabs the text content and "slices"
|
|
17
11
|
* it to be generated into the new TextNode.
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"selection"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.16.2-nightly.
|
|
12
|
+
"version": "0.16.2-nightly.20240723.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.16.2-nightly.
|
|
40
|
+
"lexical": "0.16.2-nightly.20240723.0"
|
|
41
41
|
}
|
|
42
42
|
}
|