@lexical/selection 0.14.4 → 0.15.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 +18 -2
- package/LexicalSelection.dev.mjs +18 -3
- package/LexicalSelection.js +2 -0
- package/LexicalSelection.js.flow +4 -1
- package/LexicalSelection.mjs +3 -0
- package/LexicalSelection.node.mjs +3 -0
- package/LexicalSelection.prod.js +24 -22
- package/LexicalSelection.prod.mjs +3 -1
- package/index.d.ts +4 -2
- package/lexical-node.d.ts +1 -1
- package/package.json +2 -2
- package/range-selection.d.ts +2 -1
package/LexicalSelection.dev.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';
|
|
8
10
|
|
|
9
11
|
var lexical = require('lexical');
|
|
@@ -24,6 +26,7 @@ const CSS_TO_STYLES = new Map();
|
|
|
24
26
|
* LICENSE file in the root directory of this source tree.
|
|
25
27
|
*
|
|
26
28
|
*/
|
|
29
|
+
|
|
27
30
|
function getDOMTextNode(element) {
|
|
28
31
|
let node = element;
|
|
29
32
|
while (node != null) {
|
|
@@ -305,7 +308,7 @@ function $isAtNodeEnd(point) {
|
|
|
305
308
|
* @param anchor - The anchor of the current selection, where the selection should be pointing.
|
|
306
309
|
* @param delCount - The amount of characters to delete. Useful as a dynamic variable eg. textContentSize - maxLength;
|
|
307
310
|
*/
|
|
308
|
-
function trimTextContentFromAnchor(editor, anchor, delCount) {
|
|
311
|
+
function $trimTextContentFromAnchor(editor, anchor, delCount) {
|
|
309
312
|
// Work from the current selection anchor point
|
|
310
313
|
let currentNode = anchor.getNode();
|
|
311
314
|
let remaining = delCount;
|
|
@@ -556,6 +559,7 @@ function $patchStyleText(selection, patch) {
|
|
|
556
559
|
*
|
|
557
560
|
*/
|
|
558
561
|
|
|
562
|
+
|
|
559
563
|
/**
|
|
560
564
|
* Converts all nodes in the selection that are of one block type to another.
|
|
561
565
|
* @param selection - The selected blocks to be converted.
|
|
@@ -923,7 +927,7 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
|
|
|
923
927
|
const isBackward = selection.isBackward();
|
|
924
928
|
const endOffset = isBackward ? focus.offset : anchor.offset;
|
|
925
929
|
const endNode = isBackward ? focus.getNode() : anchor.getNode();
|
|
926
|
-
if (selection.isCollapsed() && selection.style !== '') {
|
|
930
|
+
if (lexical.$isRangeSelection(selection) && selection.isCollapsed() && selection.style !== '') {
|
|
927
931
|
const css = selection.style;
|
|
928
932
|
const styleObject = getStyleObjectFromCSS(css);
|
|
929
933
|
if (styleObject !== null && styleProperty in styleObject) {
|
|
@@ -977,6 +981,17 @@ function $getAncestor(node, predicate) {
|
|
|
977
981
|
return predicate(parent) ? parent : null;
|
|
978
982
|
}
|
|
979
983
|
|
|
984
|
+
/**
|
|
985
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
986
|
+
*
|
|
987
|
+
* This source code is licensed under the MIT license found in the
|
|
988
|
+
* LICENSE file in the root directory of this source tree.
|
|
989
|
+
*
|
|
990
|
+
*/
|
|
991
|
+
|
|
992
|
+
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
993
|
+
const trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
994
|
+
|
|
980
995
|
exports.$addNodeStyle = $addNodeStyle;
|
|
981
996
|
exports.$cloneWithProperties = $cloneWithProperties;
|
|
982
997
|
exports.$getSelectionStyleValueForProperty = $getSelectionStyleValueForProperty;
|
|
@@ -989,6 +1004,7 @@ exports.$selectAll = $selectAll;
|
|
|
989
1004
|
exports.$setBlocksType = $setBlocksType;
|
|
990
1005
|
exports.$shouldOverrideDefaultCharacterSelection = $shouldOverrideDefaultCharacterSelection;
|
|
991
1006
|
exports.$sliceSelectedTextNodeContent = $sliceSelectedTextNodeContent;
|
|
1007
|
+
exports.$trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
992
1008
|
exports.$wrapNodes = $wrapNodes;
|
|
993
1009
|
exports.createDOMRange = createDOMRange;
|
|
994
1010
|
exports.createRectsFromDOMRange = createRectsFromDOMRange;
|
package/LexicalSelection.dev.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
8
|
+
|
|
7
9
|
import { $isTextNode, $isElementNode, $isParagraphNode, $getCharacterOffsets, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $getRoot, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $setSelection, $getAdjacentNode, $isDecoratorNode, $isLineBreakNode } from 'lexical';
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -22,6 +24,7 @@ const CSS_TO_STYLES = new Map();
|
|
|
22
24
|
* LICENSE file in the root directory of this source tree.
|
|
23
25
|
*
|
|
24
26
|
*/
|
|
27
|
+
|
|
25
28
|
function getDOMTextNode(element) {
|
|
26
29
|
let node = element;
|
|
27
30
|
while (node != null) {
|
|
@@ -303,7 +306,7 @@ function $isAtNodeEnd(point) {
|
|
|
303
306
|
* @param anchor - The anchor of the current selection, where the selection should be pointing.
|
|
304
307
|
* @param delCount - The amount of characters to delete. Useful as a dynamic variable eg. textContentSize - maxLength;
|
|
305
308
|
*/
|
|
306
|
-
function trimTextContentFromAnchor(editor, anchor, delCount) {
|
|
309
|
+
function $trimTextContentFromAnchor(editor, anchor, delCount) {
|
|
307
310
|
// Work from the current selection anchor point
|
|
308
311
|
let currentNode = anchor.getNode();
|
|
309
312
|
let remaining = delCount;
|
|
@@ -554,6 +557,7 @@ function $patchStyleText(selection, patch) {
|
|
|
554
557
|
*
|
|
555
558
|
*/
|
|
556
559
|
|
|
560
|
+
|
|
557
561
|
/**
|
|
558
562
|
* Converts all nodes in the selection that are of one block type to another.
|
|
559
563
|
* @param selection - The selected blocks to be converted.
|
|
@@ -921,7 +925,7 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
|
|
|
921
925
|
const isBackward = selection.isBackward();
|
|
922
926
|
const endOffset = isBackward ? focus.offset : anchor.offset;
|
|
923
927
|
const endNode = isBackward ? focus.getNode() : anchor.getNode();
|
|
924
|
-
if (selection.isCollapsed() && selection.style !== '') {
|
|
928
|
+
if ($isRangeSelection(selection) && selection.isCollapsed() && selection.style !== '') {
|
|
925
929
|
const css = selection.style;
|
|
926
930
|
const styleObject = getStyleObjectFromCSS(css);
|
|
927
931
|
if (styleObject !== null && styleProperty in styleObject) {
|
|
@@ -975,4 +979,15 @@ function $getAncestor(node, predicate) {
|
|
|
975
979
|
return predicate(parent) ? parent : null;
|
|
976
980
|
}
|
|
977
981
|
|
|
978
|
-
|
|
982
|
+
/**
|
|
983
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
984
|
+
*
|
|
985
|
+
* This source code is licensed under the MIT license found in the
|
|
986
|
+
* LICENSE file in the root directory of this source tree.
|
|
987
|
+
*
|
|
988
|
+
*/
|
|
989
|
+
|
|
990
|
+
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
991
|
+
const trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
992
|
+
|
|
993
|
+
export { $addNodeStyle, $cloneWithProperties, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $patchStyleText, $selectAll, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, $wrapNodes, createDOMRange, createRectsFromDOMRange, getStyleObjectFromCSS, trimTextContentFromAnchor };
|
package/LexicalSelection.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict'
|
|
8
10
|
const LexicalSelection = process.env.NODE_ENV === 'development' ? require('./LexicalSelection.dev.js') : require('./LexicalSelection.prod.js');
|
|
9
11
|
module.exports = LexicalSelection;
|
package/LexicalSelection.js.flow
CHANGED
|
@@ -72,8 +72,11 @@ declare export function createRectsFromDOMRange(
|
|
|
72
72
|
range: Range,
|
|
73
73
|
): Array<ClientRect>;
|
|
74
74
|
|
|
75
|
-
declare export function trimTextContentFromAnchor(
|
|
75
|
+
declare export function $trimTextContentFromAnchor(
|
|
76
76
|
editor: LexicalEditor,
|
|
77
77
|
anchor: Point,
|
|
78
78
|
delCount: number,
|
|
79
79
|
): void;
|
|
80
|
+
|
|
81
|
+
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
82
|
+
declare export const trimTextContentFromAnchor: typeof $trimTextContentFromAnchor;
|
package/LexicalSelection.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
8
|
+
|
|
7
9
|
import * as modDev from './LexicalSelection.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalSelection.prod.mjs';
|
|
9
11
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
@@ -19,6 +21,7 @@ export const $selectAll = mod.$selectAll;
|
|
|
19
21
|
export const $setBlocksType = mod.$setBlocksType;
|
|
20
22
|
export const $shouldOverrideDefaultCharacterSelection = mod.$shouldOverrideDefaultCharacterSelection;
|
|
21
23
|
export const $sliceSelectedTextNodeContent = mod.$sliceSelectedTextNodeContent;
|
|
24
|
+
export const $trimTextContentFromAnchor = mod.$trimTextContentFromAnchor;
|
|
22
25
|
export const $wrapNodes = mod.$wrapNodes;
|
|
23
26
|
export const createDOMRange = mod.createDOMRange;
|
|
24
27
|
export const createRectsFromDOMRange = mod.createRectsFromDOMRange;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
8
|
+
|
|
7
9
|
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalSelection.dev.mjs') : import('./LexicalSelection.prod.mjs'));
|
|
8
10
|
export const $addNodeStyle = mod.$addNodeStyle;
|
|
9
11
|
export const $cloneWithProperties = mod.$cloneWithProperties;
|
|
@@ -17,6 +19,7 @@ export const $selectAll = mod.$selectAll;
|
|
|
17
19
|
export const $setBlocksType = mod.$setBlocksType;
|
|
18
20
|
export const $shouldOverrideDefaultCharacterSelection = mod.$shouldOverrideDefaultCharacterSelection;
|
|
19
21
|
export const $sliceSelectedTextNodeContent = mod.$sliceSelectedTextNodeContent;
|
|
22
|
+
export const $trimTextContentFromAnchor = mod.$trimTextContentFromAnchor;
|
|
20
23
|
export const $wrapNodes = mod.$wrapNodes;
|
|
21
24
|
export const createDOMRange = mod.createDOMRange;
|
|
22
25
|
export const createRectsFromDOMRange = mod.createRectsFromDOMRange;
|
package/LexicalSelection.prod.js
CHANGED
|
@@ -3,28 +3,30 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
d)
|
|
12
|
-
|
|
13
|
-
function
|
|
8
|
+
|
|
9
|
+
'use strict';var k=require("lexical"),v;function w(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);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 y(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function z(a){let b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}function A(a){let b={};a=a.split(";");for(let c of a)if(""!==c){let [e,d]=c.split(/:([^]+)/);e&&d&&(b[e.trim()]=d.trim())}return b}function B(a){let b=x.get(a);void 0===b&&(b=A(a),x.set(a,b));return b}function C(a){let b="";for(let c in a)c&&(b+=`${c}: ${a[c]};`);return b}
|
|
11
|
+
function D(a,b,c){let e=b.getNode();if(k.$isElementNode(e)){var d=e.getDescendantByIndex(b.offset);null!==d&&(e=d)}for(;0<c&&null!==e;){k.$isElementNode(e)&&(d=e.getLastDescendant(),null!==d&&(e=d));var g=e.getPreviousSibling(),h=0;if(null===g){d=e.getParentOrThrow();for(var f=d.getPreviousSibling();null===f;){d=d.getParent();if(null===d){g=null;break}f=d.getPreviousSibling()}null!==d&&(h=d.isInline()?0:2,g=f)}f=e.getTextContent();""===f&&k.$isElementNode(e)&&!e.isInline()&&(f="\n\n");d=f.length;
|
|
12
|
+
if(!k.$isTextNode(e)||c>=d)f=e.getParent(),e.remove(),null==f||0!==f.getChildrenSize()||k.$isRootNode(f)||f.remove(),c-=d+h,e=g;else{let l=e.getKey();h=a.getEditorState().read(()=>{const p=k.$getNodeByKey(l);return k.$isTextNode(p)&&p.isSimpleText()?p.getTextContent():null});g=d-c;let m=f.slice(0,g);null!==h&&h!==f?(c=k.$getPreviousSelection(),d=e,e.isSimpleText()?e.setTextContent(h):(d=k.$createTextNode(h),e.replace(d)),k.$isRangeSelection(c)&&c.isCollapsed()&&(c=c.anchor.offset,d.select(c,c))):
|
|
13
|
+
e.isSimpleText()?(h=b.key===l,f=b.offset,f<c&&(f=d),c=h?f-c:0,d=h?f:g,h&&0===c?([c]=e.splitText(c,d),c.remove()):([,c]=e.splitText(c,d),c.remove())):(c=k.$createTextNode(m),e.replace(c));c=0}}}function E(a,b){let c=B("getStyle"in a?a.getStyle():a.style);b=Object.entries(b).reduce((d,[g,h])=>{h instanceof Function?d[g]=h(c[g]):null===h?delete d[g]:d[g]=h;return d},{...c});let e=C(b);a.setStyle(e);x.set(e,b)}
|
|
14
|
+
function F(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let b=a.getLatest(),c=a.getParent();0===b.getChildrenSize()&&a.remove(!0);a=c}}
|
|
15
|
+
function G(a,b,c,e,d=null){if(0!==b.length){var g=b[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=b[p];k.$isElementNode(q)&&0===q.getChildrenSize()&&m.add(q.getKey())}var n=new Set;for(p=0;p<c;p++){q=b[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(u=>{t.append(u);n.add(u.getKey());k.$isElementNode(u)&&u.getChildrenKeys().forEach(K=>n.add(K))});F(r)}}else m.has(q.getKey())&&(k.$isElementNode(q)||v(179),r=e(),r.setFormat(q.getFormatType()),r.setIndent(q.getIndent()),f.push(r),q.remove(!0))}if(null!==d)for(b=0;b<f.length;b++)d.append(f[b]);b=null;if(k.$isRootOrShadowRoot(g))if(l)if(null!==
|
|
17
|
+
d)g.insertAfter(d);else for(d=f.length-1;0<=d;d--)g.insertAfter(f[d]);else if(l=g.getFirstChild(),k.$isElementNode(l)&&(g=l),null===l)if(d)g.append(d);else for(d=0;d<f.length;d++)l=f[d],g.append(l),b=l;else if(null!==d)l.insertBefore(d);else for(g=0;g<f.length;g++)d=f[g],l.insertBefore(d),b=d;else if(d)g.insertAfter(d);else for(d=f.length-1;0<=d;d--)l=f[d],g.insertAfter(l),b=l;f=k.$getPreviousSelection();k.$isRangeSelection(f)&&f.anchor.getNode().isAttached()&&f.focus.getNode().isAttached()?k.$setSelection(f.clone()):
|
|
18
|
+
null!==b?b.selectEnd():a.dirty=!0}}function H(a,b,c,e){a.modify(b?"extend":"move",c,e)}function I(a){a=a.anchor.getNode();return"rtl"===(k.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function J(a){if(k.$isDecoratorNode(a)||!k.$isElementNode(a)||k.$isRootOrShadowRoot(a))return!1;var b=a.getFirstChild();b=null===b||k.$isLineBreakNode(b)||k.$isTextNode(b)||b.isInline();return!a.isInline()&&!1!==a.canBeEmpty()&&b}exports.$addNodeStyle=function(a){a=a.getStyle();let b=A(a);x.set(a,b)};
|
|
14
19
|
exports.$cloneWithProperties=function(a){let b=a.constructor.clone(a);b.__parent=a.__parent;b.__next=a.__next;b.__prev=a.__prev;if(k.$isElementNode(a)&&k.$isElementNode(b))return b.__first=a.__first,b.__last=a.__last,b.__size=a.__size,b.__format=a.__format,b.__indent=a.__indent,b.__dir=a.__dir,b;if(k.$isTextNode(a)&&k.$isTextNode(b))return b.__format=a.__format,b.__style=a.__style,b.__mode=a.__mode,b.__detail=a.__detail,b;k.$isParagraphNode(a)&&k.$isParagraphNode(b)&&(b.__textFormat=a.__textFormat);
|
|
15
|
-
return b};exports.$getSelectionStyleValueForProperty=function(a,b,c=""){let e=null,d=a.getNodes();var g=a.anchor,h=a.focus,f=a.isBackward();let l=f?h.offset:g.offset;g=f?h.getNode():g.getNode();if(a.isCollapsed()&&""!==a.style&&(a=
|
|
16
|
-
exports.$isAtNodeEnd=function(a){if("text"===a.type)return a.offset===a.getNode().getTextContentSize();let b=a.getNode();
|
|
17
|
-
exports.$patchStyleText=function(a,b){var c=a.getNodes(),e=c.length,d=a.getStartEndPoints();if(null!==d){var [g,h]=d;--e;d=c[0];var f=c[e];if(a.isCollapsed()&&k.$isRangeSelection(a))
|
|
18
|
-
"element"===t?l:p>m?p:m,n!==a&&(0===n&&a===l?(
|
|
19
|
-
t!==f.getKey()&&!n.isToken()&&
|
|
20
|
-
exports.$setBlocksType=function(a,b){if(null!==a){var c=a.getStartEndPoints();c=c?c[0]:null;if(null!==c&&"root"===c.key)b=b(),a=k.$getRoot(),(c=a.getFirstChild())?c.replace(b,!0):a.append(b);else{a=a.getNodes();if(null!==c){for(c=c.getNode();null!==c&&null!==c.getParent()&&!
|
|
21
|
-
|
|
22
|
-
exports.$sliceSelectedTextNodeContent=function(a,b){var c=a.getStartEndPoints();if(b.isSelected(a)&&!b.isSegmented()&&!b.isToken()&&null!==c){let [f,l]=c;c=a.isBackward();var e=f.getNode(),d=l.getNode(),g=b.is(e),h=b.is(d);if(g||h){let [m,p]=k.$getCharacterOffsets(a);a=e.is(d);g=b.is(c?d:e);d=b.is(c?e:d);e=0;h=void 0;a?(e=m>p?p:m,h=m>p?m:p):g?(e=c?p:m,h=void 0):d&&(c=c?m:p,e=0,h=c);b.__text=b.__text.slice(e,h)}}return b};
|
|
23
|
-
exports.$wrapNodes=function(a,b,c=null){var e=a.getStartEndPoints(),d=e?e[0]:null;e=a.getNodes();let g=e.length;if(null!==d&&(0===g||1===g&&"element"===d.type&&0===d.getNode().getChildrenSize())){a="text"===d.type?d.getNode().getParentOrThrow():d.getNode();e=a.getChildren();let f=b();f.setFormat(a.getFormatType());f.setIndent(a.getIndent());e.forEach(l=>f.append(l));c&&(f=c.append(f));a.replace(f)}else{d=null;var h=[];for(let f=0;f<g;f++){let l=e[f];k.$isRootOrShadowRoot(l)?(
|
|
24
|
-
[],d=l):null===d||null!==d&&k.$hasAncestor(l,d)?h.push(l):(
|
|
25
|
-
exports.createDOMRange=function(a,b,c,e,d){let g=b.getKey(),h=e.getKey(),f=document.createRange(),l=a.getElementByKey(g);a=a.getElementByKey(h);k.$isTextNode(b)&&(l=
|
|
20
|
+
return b};exports.$getSelectionStyleValueForProperty=function(a,b,c=""){let e=null,d=a.getNodes();var g=a.anchor,h=a.focus,f=a.isBackward();let l=f?h.offset:g.offset;g=f?h.getNode():g.getNode();if(k.$isRangeSelection(a)&&a.isCollapsed()&&""!==a.style&&(a=B(a.style),null!==a&&b in a))return a[b];for(a=0;a<d.length;a++){var m=d[a];if((0===a||0!==l||!m.is(g))&&k.$isTextNode(m))if(h=b,f=c,m=m.getStyle(),m=B(m),h=null!==m?m[h]||f:f,null===e)e=h;else if(e!==h){e="";break}}return null===e?c:e};
|
|
21
|
+
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=I;exports.$moveCaretSelection=H;exports.$moveCharacter=function(a,b,c){let e=I(a);H(a,b,c?!e:e,"character")};
|
|
22
|
+
exports.$patchStyleText=function(a,b){var c=a.getNodes(),e=c.length,d=a.getStartEndPoints();if(null!==d){var [g,h]=d;--e;d=c[0];var f=c[e];if(a.isCollapsed()&&k.$isRangeSelection(a))E(a,b);else{var l=d.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;q=q?h.key:g.key;if(k.$isTextNode(d)&&n===l){let u=d.getNextSibling();k.$isTextNode(u)&&(n=p=0,d=u)}if(1===c.length)k.$isTextNode(d)&&d.canHaveFormat()&&(n="element"===r?0:p>m?m:p,a=
|
|
23
|
+
"element"===t?l:p>m?p:m,n!==a&&(0===n&&a===l?(E(d,b),d.select(n,a)):(c=d.splitText(n,a),c=0===n?c[0]:c[1],E(c,b),c.select(0,a-n))));else for(k.$isTextNode(d)&&n<d.getTextContentSize()&&d.canHaveFormat()&&(0!==n&&(d=d.splitText(n)[1],n=0,g.set(d.getKey(),n,"text")),E(d,b)),k.$isTextNode(f)&&f.canHaveFormat()&&(n=f.getTextContent().length,f.__key!==q&&0!==a&&(a=n),a!==n&&([f]=f.splitText(a)),0===a&&"element"!==t||E(f,b)),a=1;a<e;a++)n=c[a],t=n.getKey(),k.$isTextNode(n)&&n.canHaveFormat()&&t!==d.getKey()&&
|
|
24
|
+
t!==f.getKey()&&!n.isToken()&&E(n,b)}}};exports.$selectAll=function(a){let b=a.anchor;a=a.focus;var c=b.getNode().getTopLevelElementOrThrow().getParentOrThrow();let e=c.getFirstDescendant();c=c.getLastDescendant();let d="element",g="element",h=0;k.$isTextNode(e)?d="text":k.$isElementNode(e)||null===e||(e=e.getParentOrThrow());k.$isTextNode(c)?(g="text",h=c.getTextContentSize()):k.$isElementNode(c)||null===c||(c=c.getParentOrThrow());e&&c&&(b.set(e.getKey(),0,d),a.set(c.getKey(),h,g))};
|
|
25
|
+
exports.$setBlocksType=function(a,b){if(null!==a){var c=a.getStartEndPoints();c=c?c[0]:null;if(null!==c&&"root"===c.key)b=b(),a=k.$getRoot(),(c=a.getFirstChild())?c.replace(b,!0):a.append(b);else{a=a.getNodes();if(null!==c){for(c=c.getNode();null!==c&&null!==c.getParent()&&!J(c);)c=c.getParentOrThrow();c=J(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(!J(e))continue;k.$isElementNode(e)||v(178);let d=b();d.setFormat(e.getFormatType());d.setIndent(e.getIndent());
|
|
26
|
+
e.replace(d,!0)}}}};exports.$shouldOverrideDefaultCharacterSelection=function(a,b){a=k.$getAdjacentNode(a.focus,b);return k.$isDecoratorNode(a)&&!a.isIsolated()||k.$isElementNode(a)&&!a.isInline()&&!a.canBeEmpty()};
|
|
27
|
+
exports.$sliceSelectedTextNodeContent=function(a,b){var c=a.getStartEndPoints();if(b.isSelected(a)&&!b.isSegmented()&&!b.isToken()&&null!==c){let [f,l]=c;c=a.isBackward();var e=f.getNode(),d=l.getNode(),g=b.is(e),h=b.is(d);if(g||h){let [m,p]=k.$getCharacterOffsets(a);a=e.is(d);g=b.is(c?d:e);d=b.is(c?e:d);e=0;h=void 0;a?(e=m>p?p:m,h=m>p?m:p):g?(e=c?p:m,h=void 0):d&&(c=c?m:p,e=0,h=c);b.__text=b.__text.slice(e,h)}}return b};exports.$trimTextContentFromAnchor=D;
|
|
28
|
+
exports.$wrapNodes=function(a,b,c=null){var e=a.getStartEndPoints(),d=e?e[0]:null;e=a.getNodes();let g=e.length;if(null!==d&&(0===g||1===g&&"element"===d.type&&0===d.getNode().getChildrenSize())){a="text"===d.type?d.getNode().getParentOrThrow():d.getNode();e=a.getChildren();let f=b();f.setFormat(a.getFormatType());f.setIndent(a.getIndent());e.forEach(l=>f.append(l));c&&(f=c.append(f));a.replace(f)}else{d=null;var h=[];for(let f=0;f<g;f++){let l=e[f];k.$isRootOrShadowRoot(l)?(G(a,h,h.length,b,c),h=
|
|
29
|
+
[],d=l):null===d||null!==d&&k.$hasAncestor(l,d)?h.push(l):(G(a,h,h.length,b,c),h=[l])}G(a,h,h.length,b,c)}};
|
|
30
|
+
exports.createDOMRange=function(a,b,c,e,d){let g=b.getKey(),h=e.getKey(),f=document.createRange(),l=a.getElementByKey(g);a=a.getElementByKey(h);k.$isTextNode(b)&&(l=y(l));k.$isTextNode(e)&&(a=y(a));if(void 0===b||void 0===e||null===l||null===a)return null;"BR"===l.nodeName&&([l,c]=z(l));"BR"===a.nodeName&&([a,d]=z(a));b=l.firstChild;l===a&&null!=b&&"BR"===b.nodeName&&0===c&&0===d&&(d=1);try{f.setStart(l,c),f.setEnd(a,d)}catch(m){return null}!f.collapsed||c===d&&g===h||(f.setStart(a,d),f.setEnd(l,
|
|
26
31
|
c));return f};exports.createRectsFromDOMRange=function(a,b){var c=a.getRootElement();if(null===c)return[];a=c.getBoundingClientRect();c=getComputedStyle(c);c=parseFloat(c.paddingLeft)+parseFloat(c.paddingRight);b=Array.from(b.getClientRects());let e=b.length;b.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=b[g],f=h.width+c===a.width;d&&d.top<=h.top&&d.top+d.height>h.top&&d.left+d.width>h.left||f?(b.splice(g--,1),e--):d=h}return b};
|
|
27
|
-
exports.getStyleObjectFromCSS=
|
|
28
|
-
exports.trimTextContentFromAnchor=function(a,b,c){let e=b.getNode();if(k.$isElementNode(e)){var d=e.getDescendantByIndex(b.offset);null!==d&&(e=d)}for(;0<c&&null!==e;){k.$isElementNode(e)&&(d=e.getLastDescendant(),null!==d&&(e=d));var g=e.getPreviousSibling(),h=0;if(null===g){d=e.getParentOrThrow();for(var f=d.getPreviousSibling();null===f;){d=d.getParent();if(null===d){g=null;break}f=d.getPreviousSibling()}null!==d&&(h=d.isInline()?0:2,g=f)}f=e.getTextContent();""===f&&k.$isElementNode(e)&&!e.isInline()&&
|
|
29
|
-
(f="\n\n");d=f.length;if(!k.$isTextNode(e)||c>=d)f=e.getParent(),e.remove(),null==f||0!==f.getChildrenSize()||k.$isRootNode(f)||f.remove(),c-=d+h,e=g;else{let l=e.getKey();h=a.getEditorState().read(()=>{const p=k.$getNodeByKey(l);return k.$isTextNode(p)&&p.isSimpleText()?p.getTextContent():null});g=d-c;let m=f.slice(0,g);null!==h&&h!==f?(c=k.$getPreviousSelection(),d=e,e.isSimpleText()?e.setTextContent(h):(d=k.$createTextNode(h),e.replace(d)),k.$isRangeSelection(c)&&c.isCollapsed()&&(c=c.anchor.offset,
|
|
30
|
-
d.select(c,c))):e.isSimpleText()?(h=b.key===l,f=b.offset,f<c&&(f=d),c=h?f-c:0,d=h?f:g,h&&0===c?([c]=e.splitText(c,d),c.remove()):([,c]=e.splitText(c,d),c.remove())):(c=k.$createTextNode(m),e.replace(c));c=0}}}
|
|
32
|
+
exports.getStyleObjectFromCSS=B;exports.trimTextContentFromAnchor=D
|
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
7
|
-
|
|
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 T=new Map;function x(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=x(f)),e(l)&&(u=x(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=T.get(e);return void 0===t&&(t=w(e),T.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 I(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 K(e){const t=e.getStyle(),n=w(t);T.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),T.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,T=h?i.type:s.type,x=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"===T?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,s.set(u.getKey(),_,"text")),O(u,n)),e(a)&&a.canHaveFormat()){const e=a.getTextContent().length;a.__key!==x&&0!==m&&(m=e),m!==e&&([a]=a.splitText(m)),0===m&&"element"!==T||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 T=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),T=t}else if(null!==r)e.insertBefore(r);else for(let t=0;t<a.length;t++){const n=a[t];e.insertBefore(n),T=n}}else if(r)p.insertAfter(r);else for(let e=a.length-1;e>=0;e--){const t=a[e];p.insertAfter(t),T=t}const x=s();c(x)&&b(x.anchor)&&b(x.focus)?d(x.clone()):null!==T?T.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=I;export{K 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,I as $trimTextContentFromAnchor,R as $wrapNodes,v as createDOMRange,C as createRectsFromDOMRange,N as getStyleObjectFromCSS,q as trimTextContentFromAnchor};
|
package/index.d.ts
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { $addNodeStyle, $cloneWithProperties, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, trimTextContentFromAnchor } from './lexical-node';
|
|
8
|
+
import { $addNodeStyle, $cloneWithProperties, $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 { $addNodeStyle, $cloneWithProperties, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, trimTextContentFromAnchor, };
|
|
11
|
+
export { $addNodeStyle, $cloneWithProperties, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, };
|
|
12
|
+
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
13
|
+
export declare const trimTextContentFromAnchor: typeof $trimTextContentFromAnchor;
|
|
12
14
|
export { $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $selectAll, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes, };
|
|
13
15
|
export { createDOMRange, createRectsFromDOMRange, getStyleObjectFromCSS };
|
package/lexical-node.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare function $isAtNodeEnd(point: Point): boolean;
|
|
|
34
34
|
* @param anchor - The anchor of the current selection, where the selection should be pointing.
|
|
35
35
|
* @param delCount - The amount of characters to delete. Useful as a dynamic variable eg. textContentSize - maxLength;
|
|
36
36
|
*/
|
|
37
|
-
export declare function trimTextContentFromAnchor(editor: LexicalEditor, anchor: Point, delCount: number): void;
|
|
37
|
+
export declare function $trimTextContentFromAnchor(editor: LexicalEditor, anchor: Point, delCount: number): void;
|
|
38
38
|
/**
|
|
39
39
|
* Gets the TextNode's style object and adds the styles to the CSS.
|
|
40
40
|
* @param node - The TextNode to add styles to.
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"selection"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.15.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.
|
|
40
|
+
"lexical": "0.15.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/range-selection.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import type { BaseSelection, ElementNode, LexicalNode, RangeSelection } from 'lexical';
|
|
9
|
+
import { TableSelection } from '@lexical/table';
|
|
9
10
|
/**
|
|
10
11
|
* Converts all nodes in the selection that are of one block type to another.
|
|
11
12
|
* @param selection - The selected blocks to be converted.
|
|
@@ -71,7 +72,7 @@ export declare function $selectAll(selection: RangeSelection): void;
|
|
|
71
72
|
* @param defaultValue - The default value for the property, defaults to an empty string.
|
|
72
73
|
* @returns The value of the property for the selected TextNodes.
|
|
73
74
|
*/
|
|
74
|
-
export declare function $getSelectionStyleValueForProperty(selection: RangeSelection, styleProperty: string, defaultValue?: string): string;
|
|
75
|
+
export declare function $getSelectionStyleValueForProperty(selection: RangeSelection | TableSelection, styleProperty: string, defaultValue?: string): string;
|
|
75
76
|
/**
|
|
76
77
|
* This function is for internal use of the library.
|
|
77
78
|
* Please do not use it as it may change in the future.
|