@lexical/selection 0.2.9 → 0.3.2
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.d.ts +17 -7
- package/LexicalSelection.dev.js +176 -10
- package/LexicalSelection.js.flow +8 -2
- package/LexicalSelection.prod.js +20 -16
- package/package.json +2 -2
package/LexicalSelection.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
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
|
-
* @flow strict
|
|
8
7
|
*/
|
|
8
|
+
|
|
9
9
|
import type {
|
|
10
10
|
ElementNode,
|
|
11
11
|
GridSelection,
|
|
@@ -15,15 +15,19 @@ import type {
|
|
|
15
15
|
NodeSelection,
|
|
16
16
|
Point,
|
|
17
17
|
RangeSelection,
|
|
18
|
+
TextNode,
|
|
18
19
|
} from 'lexical';
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
export function $cloneContents<T extends LexicalNode>(
|
|
20
22
|
selection: RangeSelection | NodeSelection | GridSelection,
|
|
21
23
|
): {
|
|
22
|
-
nodeMap: Array<[NodeKey,
|
|
24
|
+
nodeMap: Array<[NodeKey, T]>;
|
|
23
25
|
range: Array<NodeKey>;
|
|
24
26
|
};
|
|
25
|
-
export function $cloneWithProperties<LexicalNode>(
|
|
26
|
-
|
|
27
|
+
export function $cloneWithProperties<T extends LexicalNode>(node: T): T;
|
|
28
|
+
export function $sliceSelectedTextNodeContent(
|
|
29
|
+
selection: RangeSelection | GridSelection | NodeSelection,
|
|
30
|
+
node: TextNode,
|
|
27
31
|
): LexicalNode;
|
|
28
32
|
export function getStyleObjectFromCSS(css: string): {
|
|
29
33
|
[key: string]: string;
|
|
@@ -63,7 +67,7 @@ export function $shouldOverrideDefaultCharacterSelection(
|
|
|
63
67
|
isBackward: boolean,
|
|
64
68
|
): boolean;
|
|
65
69
|
|
|
66
|
-
declare function createDOMRange(
|
|
70
|
+
export declare function createDOMRange(
|
|
67
71
|
editor: LexicalEditor,
|
|
68
72
|
anchorNode: LexicalNode,
|
|
69
73
|
anchorOffset: number,
|
|
@@ -71,7 +75,13 @@ declare function createDOMRange(
|
|
|
71
75
|
focusOffset: number,
|
|
72
76
|
): Range | null;
|
|
73
77
|
|
|
74
|
-
declare function createRectsFromDOMRange(
|
|
78
|
+
export declare function createRectsFromDOMRange(
|
|
75
79
|
editor: LexicalEditor,
|
|
76
80
|
range: Range,
|
|
77
81
|
): Array<ClientRect>;
|
|
82
|
+
|
|
83
|
+
export declare function trimTextContentFromAnchor(
|
|
84
|
+
editor: LexicalEditor,
|
|
85
|
+
anchor: Point,
|
|
86
|
+
delCount: number,
|
|
87
|
+
): void;
|
package/LexicalSelection.dev.js
CHANGED
|
@@ -14,12 +14,12 @@ var lexical = require('lexical');
|
|
|
14
14
|
* This source code is licensed under the MIT license found in the
|
|
15
15
|
* LICENSE file in the root directory of this source tree.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
17
|
*/
|
|
19
18
|
const cssToStyles = new Map();
|
|
20
19
|
function $cloneWithProperties(node) {
|
|
21
20
|
const latest = node.getLatest();
|
|
22
|
-
const constructor = latest.constructor;
|
|
21
|
+
const constructor = latest.constructor; // @ts-expect-error
|
|
22
|
+
|
|
23
23
|
const clone = constructor.clone(latest);
|
|
24
24
|
clone.__parent = latest.__parent;
|
|
25
25
|
|
|
@@ -33,8 +33,7 @@ function $cloneWithProperties(node) {
|
|
|
33
33
|
clone.__style = latest.__style;
|
|
34
34
|
clone.__mode = latest.__mode;
|
|
35
35
|
clone.__detail = latest.__detail;
|
|
36
|
-
}
|
|
37
|
-
|
|
36
|
+
}
|
|
38
37
|
|
|
39
38
|
return clone;
|
|
40
39
|
}
|
|
@@ -109,13 +108,13 @@ function errGetLatestOnClone() {
|
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
function $cloneContents(selection) {
|
|
112
|
-
const clone = $cloneContentsImpl(selection);
|
|
111
|
+
const clone = $cloneContentsImpl(selection); // @ts-ignore
|
|
113
112
|
|
|
114
113
|
{
|
|
115
114
|
const nodeMap = clone.nodeMap;
|
|
116
115
|
|
|
117
116
|
for (let i = 0; i < nodeMap.length; i++) {
|
|
118
|
-
const node = nodeMap[i][1];
|
|
117
|
+
const node = nodeMap[i][1];
|
|
119
118
|
|
|
120
119
|
if (node.getLatest === errGetLatestOnClone) {
|
|
121
120
|
continue;
|
|
@@ -314,7 +313,7 @@ function $patchStyleText(selection, patch) {
|
|
|
314
313
|
if (lexical.$isTextNode(firstNode)) {
|
|
315
314
|
if (startOffset !== 0) {
|
|
316
315
|
// the entire first node isn't selected, so split it
|
|
317
|
-
|
|
316
|
+
firstNode = firstNode.splitText(startOffset)[1];
|
|
318
317
|
startOffset = 0;
|
|
319
318
|
}
|
|
320
319
|
|
|
@@ -426,7 +425,6 @@ function $selectAll(selection) {
|
|
|
426
425
|
lastOffset = lastNode.getTextContentSize();
|
|
427
426
|
} else if (!lexical.$isElementNode(lastNode) && lastNode !== null) {
|
|
428
427
|
lastNode = lastNode.getParentOrThrow();
|
|
429
|
-
lastOffset = lastNode.getChildrenSize();
|
|
430
428
|
}
|
|
431
429
|
|
|
432
430
|
if (firstNode && lastNode) {
|
|
@@ -615,8 +613,7 @@ function getDOMTextNode(element) {
|
|
|
615
613
|
let node = element;
|
|
616
614
|
|
|
617
615
|
while (node != null) {
|
|
618
|
-
if (node.nodeType ===
|
|
619
|
-
// $FlowFixMe: this is a Text
|
|
616
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
620
617
|
return node;
|
|
621
618
|
}
|
|
622
619
|
|
|
@@ -722,6 +719,173 @@ function createRectsFromDOMRange(editor, range) {
|
|
|
722
719
|
return selectionRects;
|
|
723
720
|
}
|
|
724
721
|
|
|
722
|
+
function doesContainGrapheme(str) {
|
|
723
|
+
return /[\uD800-\uDBFF][\uDC00-\uDFFF]/g.test(str);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function trimTextContentFromAnchor(editor, anchor, delCount) {
|
|
727
|
+
// Work from the current selection anchor point
|
|
728
|
+
let currentNode = anchor.getNode();
|
|
729
|
+
let remaining = delCount;
|
|
730
|
+
|
|
731
|
+
if (lexical.$isElementNode(currentNode)) {
|
|
732
|
+
const descendantNode = currentNode.getDescendantByIndex(anchor.offset);
|
|
733
|
+
|
|
734
|
+
if (descendantNode !== null) {
|
|
735
|
+
currentNode = descendantNode;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
while (remaining > 0 && currentNode !== null) {
|
|
740
|
+
let nextNode = currentNode.getPreviousSibling();
|
|
741
|
+
let additionalElementWhitespace = 0;
|
|
742
|
+
|
|
743
|
+
if (nextNode === null) {
|
|
744
|
+
let parent = currentNode.getParentOrThrow();
|
|
745
|
+
let parentSibling = parent.getPreviousSibling();
|
|
746
|
+
|
|
747
|
+
while (parentSibling === null) {
|
|
748
|
+
parent = parent.getParent();
|
|
749
|
+
|
|
750
|
+
if (parent === null) {
|
|
751
|
+
nextNode = null;
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
parentSibling = parent.getPreviousSibling();
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
if (parent !== null) {
|
|
759
|
+
additionalElementWhitespace = parent.isInline() ? 0 : 2;
|
|
760
|
+
|
|
761
|
+
if (lexical.$isElementNode(parentSibling)) {
|
|
762
|
+
nextNode = parentSibling.getLastDescendant();
|
|
763
|
+
} else {
|
|
764
|
+
nextNode = parentSibling;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
let text = currentNode.getTextContent(); // If the text is empty, we need to consider adding in two line breaks to match
|
|
770
|
+
// the content if we were to get it from its parent.
|
|
771
|
+
|
|
772
|
+
if (text === '' && lexical.$isElementNode(currentNode) && !currentNode.isInline()) {
|
|
773
|
+
// TODO: should this be handled in core?
|
|
774
|
+
text = '\n\n';
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
const textNodeSize = text.length;
|
|
778
|
+
const offset = textNodeSize - remaining;
|
|
779
|
+
const slicedText = text.slice(0, offset); // Sometimes the text we're putting in might be a partial grapheme.
|
|
780
|
+
// So we just remove the entire thing, rather than show a partial unicode grapheme.
|
|
781
|
+
|
|
782
|
+
const containsPartialGraphemeHeuristic = doesContainGrapheme(text) && !doesContainGrapheme(slicedText);
|
|
783
|
+
|
|
784
|
+
if (!lexical.$isTextNode(currentNode) || remaining >= textNodeSize || containsPartialGraphemeHeuristic) {
|
|
785
|
+
const parent = currentNode.getParent();
|
|
786
|
+
currentNode.remove();
|
|
787
|
+
|
|
788
|
+
if (parent.getChildrenSize() === 0) {
|
|
789
|
+
parent.remove();
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
remaining -= textNodeSize + additionalElementWhitespace;
|
|
793
|
+
currentNode = nextNode;
|
|
794
|
+
} else {
|
|
795
|
+
const key = currentNode.getKey(); // See if we can just revert it to what was in the last editor state
|
|
796
|
+
|
|
797
|
+
const prevTextContent = editor.getEditorState().read(() => {
|
|
798
|
+
const prevNode = lexical.$getNodeByKey(key);
|
|
799
|
+
|
|
800
|
+
if (lexical.$isTextNode(prevNode) && prevNode.isSimpleText()) {
|
|
801
|
+
return prevNode.getTextContent();
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
return null;
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
if (prevTextContent !== null && prevTextContent !== text) {
|
|
808
|
+
const prevSelection = lexical.$getPreviousSelection();
|
|
809
|
+
let target = currentNode;
|
|
810
|
+
|
|
811
|
+
if (!currentNode.isSimpleText()) {
|
|
812
|
+
const textNode = lexical.$createTextNode(prevTextContent);
|
|
813
|
+
currentNode.replace(textNode);
|
|
814
|
+
target = textNode;
|
|
815
|
+
} else {
|
|
816
|
+
currentNode.setTextContent(prevTextContent);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
if (lexical.$isRangeSelection(prevSelection) && prevSelection.isCollapsed()) {
|
|
820
|
+
const prevOffset = prevSelection.anchor.offset;
|
|
821
|
+
target.select(prevOffset, prevOffset);
|
|
822
|
+
}
|
|
823
|
+
} else if (currentNode.isSimpleText()) {
|
|
824
|
+
// Split text
|
|
825
|
+
const isSelected = anchor.key === key;
|
|
826
|
+
let anchorOffset = anchor.offset; // Move offset to end if it's less than the remaniing number, otherwise
|
|
827
|
+
// we'll have a negative splitStart.
|
|
828
|
+
|
|
829
|
+
if (anchorOffset < remaining) {
|
|
830
|
+
anchorOffset = textNodeSize;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
const splitStart = isSelected ? anchorOffset - remaining : 0;
|
|
834
|
+
const splitEnd = isSelected ? anchorOffset : offset;
|
|
835
|
+
|
|
836
|
+
if (isSelected && splitStart === 0) {
|
|
837
|
+
const [excessNode] = currentNode.splitText(splitStart, splitEnd);
|
|
838
|
+
excessNode.remove();
|
|
839
|
+
} else {
|
|
840
|
+
const [, excessNode] = currentNode.splitText(splitStart, splitEnd);
|
|
841
|
+
excessNode.remove();
|
|
842
|
+
}
|
|
843
|
+
} else {
|
|
844
|
+
const textNode = lexical.$createTextNode(slicedText);
|
|
845
|
+
currentNode.replace(textNode);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
remaining = 0;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function $sliceSelectedTextNodeContent(selection, textNode) {
|
|
853
|
+
if (textNode.isSelected() && !textNode.isSegmented() && !textNode.isToken() && (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection))) {
|
|
854
|
+
const anchorNode = selection.anchor.getNode();
|
|
855
|
+
const focusNode = selection.focus.getNode();
|
|
856
|
+
const isAnchor = textNode.is(anchorNode);
|
|
857
|
+
const isFocus = textNode.is(focusNode);
|
|
858
|
+
|
|
859
|
+
if (isAnchor || isFocus) {
|
|
860
|
+
const isBackward = selection.isBackward();
|
|
861
|
+
const [anchorOffset, focusOffset] = selection.getCharacterOffsets();
|
|
862
|
+
const isSame = anchorNode.is(focusNode);
|
|
863
|
+
const isFirst = textNode.is(isBackward ? focusNode : anchorNode);
|
|
864
|
+
const isLast = textNode.is(isBackward ? anchorNode : focusNode);
|
|
865
|
+
let startOffset = 0;
|
|
866
|
+
let endOffset = undefined;
|
|
867
|
+
|
|
868
|
+
if (isSame) {
|
|
869
|
+
startOffset = anchorOffset > focusOffset ? focusOffset : anchorOffset;
|
|
870
|
+
endOffset = anchorOffset > focusOffset ? anchorOffset : focusOffset;
|
|
871
|
+
} else if (isFirst) {
|
|
872
|
+
const offset = isBackward ? focusOffset : anchorOffset;
|
|
873
|
+
startOffset = offset;
|
|
874
|
+
endOffset = undefined;
|
|
875
|
+
} else if (isLast) {
|
|
876
|
+
const offset = isBackward ? anchorOffset : focusOffset;
|
|
877
|
+
startOffset = 0;
|
|
878
|
+
endOffset = offset;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
textNode.__text = textNode.__text.slice(startOffset, endOffset);
|
|
882
|
+
return textNode;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
return textNode;
|
|
887
|
+
}
|
|
888
|
+
|
|
725
889
|
exports.$cloneContents = $cloneContents;
|
|
726
890
|
exports.$cloneWithProperties = $cloneWithProperties;
|
|
727
891
|
exports.$getSelectionStyleValueForProperty = $getSelectionStyleValueForProperty;
|
|
@@ -732,7 +896,9 @@ exports.$moveCharacter = $moveCharacter;
|
|
|
732
896
|
exports.$patchStyleText = $patchStyleText;
|
|
733
897
|
exports.$selectAll = $selectAll;
|
|
734
898
|
exports.$shouldOverrideDefaultCharacterSelection = $shouldOverrideDefaultCharacterSelection;
|
|
899
|
+
exports.$sliceSelectedTextNodeContent = $sliceSelectedTextNodeContent;
|
|
735
900
|
exports.$wrapLeafNodesInElements = $wrapLeafNodesInElements;
|
|
736
901
|
exports.createDOMRange = createDOMRange;
|
|
737
902
|
exports.createRectsFromDOMRange = createRectsFromDOMRange;
|
|
738
903
|
exports.getStyleObjectFromCSS = getStyleObjectFromCSS;
|
|
904
|
+
exports.trimTextContentFromAnchor = trimTextContentFromAnchor;
|
package/LexicalSelection.js.flow
CHANGED
|
@@ -16,10 +16,10 @@ import type {
|
|
|
16
16
|
Point,
|
|
17
17
|
RangeSelection,
|
|
18
18
|
} from 'lexical';
|
|
19
|
-
declare export function $cloneContents(
|
|
19
|
+
declare export function $cloneContents<T: LexicalNode>(
|
|
20
20
|
selection: RangeSelection | NodeSelection | GridSelection,
|
|
21
21
|
): {
|
|
22
|
-
nodeMap: Array<[NodeKey,
|
|
22
|
+
nodeMap: Array<[NodeKey, T]>,
|
|
23
23
|
range: Array<NodeKey>,
|
|
24
24
|
};
|
|
25
25
|
declare export function $cloneWithProperties<T: LexicalNode>(node: T): T;
|
|
@@ -73,3 +73,9 @@ declare export function createRectsFromDOMRange(
|
|
|
73
73
|
editor: LexicalEditor,
|
|
74
74
|
range: Range,
|
|
75
75
|
): Array<ClientRect>;
|
|
76
|
+
|
|
77
|
+
declare export function trimTextContentFromAnchor(
|
|
78
|
+
editor: LexicalEditor,
|
|
79
|
+
anchor: Point,
|
|
80
|
+
delCount: number,
|
|
81
|
+
): void;
|
package/LexicalSelection.prod.js
CHANGED
|
@@ -4,21 +4,25 @@
|
|
|
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
|
-
var l=require("lexical");
|
|
8
|
-
function w(a,c,b,
|
|
7
|
+
'use strict';var l=require("lexical");let t=new Map;function u(a){a=a.getLatest();let c=a.constructor.clone(a);c.__parent=a.__parent;l.$isElementNode(a)&&l.$isElementNode(c)?(c.__children=Array.from(a.__children),c.__format=a.__format,c.__indent=a.__indent,c.__dir=a.__dir):l.$isTextNode(a)&&l.$isTextNode(c)&&(c.__format=a.__format,c.__style=a.__style,c.__mode=a.__mode,c.__detail=a.__detail);return c}
|
|
8
|
+
function w(a,c,b,e,f,g){for(var d=c;null!==a;){for(c=a.getParent();null!==c&&c.excludeFromCopy("clone");)c=c.getParent();if(null===c)break;if(!l.$isElementNode(a)||!a.excludeFromCopy("clone")){let k=a.getKey(),h=g.get(k),m=void 0===h;m&&(h=u(a),g.set(k,h));!l.$isTextNode(h)||h.isSegmented()||h.isToken()?l.$isElementNode(h)&&(h.__children=h.__children.slice(e?d:0,e?void 0:(d||0)+1)):h.__text=h.__text.slice(e?d:0,e?b:d);if(l.$isRootNode(c)){m&&f.push(k);break}}d=g.get(c.getKey());d=l.$isElementNode(d)?
|
|
9
9
|
d.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}}
|
|
10
|
-
function x(a){if(l.$isRangeSelection(a)){var c=a.anchor,b=a.focus;
|
|
11
|
-
|
|
12
|
-
}function y(a){return t.get(a)||null}function z(a,c){var b=y(a.getStyle());c=b?{...b,...c}:c;b="";for(
|
|
13
|
-
function D(a){for(;null!=a;){if(
|
|
14
|
-
exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let
|
|
15
|
-
exports.$isParentElementRTL=B;exports.$moveCaretSelection=A;exports.$moveCharacter=function(a,c,b){
|
|
16
|
-
exports.$patchStyleText=function(a,c){var b=a.getNodes();
|
|
17
|
-
|
|
18
|
-
exports.$selectAll=function(a){
|
|
10
|
+
function x(a){if(l.$isRangeSelection(a)){var c=a.anchor,b=a.focus;let [h,m]=a.getCharacterOffsets();a=a.getNodes();if(0===a.length)return{nodeMap:[],range:[]};let n=a.length;var e=a[0],f=e.getParent();if(null!==f&&(!f.canBeEmpty()||l.$isRootNode(f))){var g=f.__children;if(g.length===n){var d=!0;for(var k=0;k<g.length;k++)if(g[k]!==a[k].__key){d=!1;break}d&&(n++,a.push(f))}}f=a[n-1];c=c.isBefore(b);b=new Map;g=[];d=l.$isTextNode(e)&&1===n;w(e,c?h:m,d?c?m:h:void 0,!0,g,b);for(e=0;e<n;e++){k=a[e];let q=
|
|
11
|
+
k.getKey();if(!(b.has(q)||l.$isElementNode(k)&&k.excludeFromCopy("clone"))){let p=u(k);l.$isRootNode(k.getParent())&&g.push(k.getKey());"root"!==q&&b.set(q,p)}}w(f,d?void 0:c?m:h,void 0,!1,g,b);return{nodeMap:Array.from(b.entries()),range:g}}if(l.$isGridSelection(a))return{nodeMap:a.getNodes().map(h=>{const m=h.getKey();h=u(h);return[m,h]}),range:[a.gridKey]};throw Error("Minified Lexical error #1; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
|
|
12
|
+
}function y(a){return t.get(a)||null}function z(a,c){var b=y(a.getStyle());c=b?{...b,...c}:c;b="";for(e in c)e&&(b+=`${e}: ${c[e]};`);var e=b;a.setStyle(e);t.set(e,c)}function A(a,c,b,e){a.modify(c?"extend":"move",b,e)}function B(a){a=a.anchor.getNode();return"rtl"===(l.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function C(a){for(;null!==a&&!l.$isRootNode(a);){let c=a.getLatest(),b=a.getParent();0===c.__children.length&&a.remove(!0);a=b}}
|
|
13
|
+
function D(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function E(a){let c=a.parentNode;if(null==c)throw Error("Should never happen");return[c,Array.from(c.childNodes).indexOf(a)]}function F(a){return/[\uD800-\uDBFF][\uDC00-\uDFFF]/g.test(a)}exports.$cloneContents=function(a){return x(a)};exports.$cloneWithProperties=u;
|
|
14
|
+
exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let e=null,f=a.getNodes();var g=a.anchor,d=a.focus,k=a.isBackward();a=k?d.offset:g.offset;g=k?d.getNode():g.getNode();for(d=0;d<f.length;d++){var h=f[d];if((0===d||0!==a||!h.is(g))&&l.$isTextNode(h)){k=c;var m=b;h=h.getStyle();h=y(h);k=null!==h?h[k]||m:m;if(null===e)e=k;else if(e!==k){e="";break}}}return null===e?b:e};exports.$isAtNodeEnd=function(a){return"text"===a.type?a.offset===a.getNode().getTextContentSize():a.offset===a.getNode().getChildrenSize()};
|
|
15
|
+
exports.$isParentElementRTL=B;exports.$moveCaretSelection=A;exports.$moveCharacter=function(a,c,b){let e=B(a);A(a,c,b?!e:e,"character")};
|
|
16
|
+
exports.$patchStyleText=function(a,c){var b=a.getNodes();let e=b.length-1,f=b[0],g=b[e];if(!a.isCollapsed()){var d=a.anchor,k=a.focus;a=f.getTextContent().length;var h=k.offset,m=d.offset;d=(k=d.isBefore(k))?m:h;k=k?h:m;if(d===f.getTextContentSize()){let n=f.getNextSibling();l.$isTextNode(n)&&(d=m=0,f=n)}if(f.is(g))l.$isTextNode(f)&&(d=m>h?h:m,k=m>h?m:h,d!==k&&(0===d&&k===a?(z(f,c),f.select(d,k)):(b=f.splitText(d,k),b=0===d?b[0]:b[1],z(b,c),b.select(0,k-d))));else for(l.$isTextNode(f)&&(0!==d&&(f=
|
|
17
|
+
f.splitText(d)[1]),z(f,c)),l.$isTextNode(g)&&(a=g.getTextContent().length,k!==a&&([g]=g.splitText(k)),0!==k&&z(g,c)),a=1;a<e;a++)h=b[a],m=h.getKey(),l.$isTextNode(h)&&m!==f.getKey()&&m!==g.getKey()&&!h.isToken()&&z(h,c)}};
|
|
18
|
+
exports.$selectAll=function(a){let c=a.anchor;a=a.focus;var b=c.getNode().getTopLevelElementOrThrow().getParentOrThrow();let e=b.getFirstDescendant();b=b.getLastDescendant();let f="element",g="element",d=0;l.$isTextNode(e)?f="text":l.$isElementNode(e)||null===e||(e=e.getParentOrThrow());l.$isTextNode(b)?(g="text",d=b.getTextContentSize()):l.$isElementNode(b)||null===b||(b=b.getParentOrThrow());e&&b&&(c.set(e.getKey(),0,f),a.set(b.getKey(),d,g))};
|
|
19
19
|
exports.$shouldOverrideDefaultCharacterSelection=function(a,c){a=l.$getDecoratorNode(a.focus,c);return l.$isDecoratorNode(a)&&!a.isIsolated()};
|
|
20
|
-
exports.$
|
|
21
|
-
|
|
22
|
-
if(l.$isRootNode(d))
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
exports.$sliceSelectedTextNodeContent=function(a,c){if(c.isSelected()&&!c.isSegmented()&&!c.isToken()&&(l.$isRangeSelection(a)||l.$isGridSelection(a))){var b=a.anchor.getNode(),e=a.focus.getNode(),f=c.is(b),g=c.is(e);if(f||g){f=a.isBackward();let [d,k]=a.getCharacterOffsets();a=b.is(e);g=c.is(f?e:b);e=c.is(f?b:e);b=0;let h=void 0;a?(b=d>k?k:d,h=d>k?d:k):g?(b=f?k:d,h=void 0):e&&(f=f?d:k,b=0,h=f);c.__text=c.__text.slice(b,h)}}return c};
|
|
21
|
+
exports.$wrapLeafNodesInElements=function(a,c,b){let e=a.getNodes(),f=e.length;var g=a.anchor;if(0===f||1===f&&"element"===g.type&&0===g.getNode().getChildrenSize()){a="text"===g.type?g.getNode().getParentOrThrow():g.getNode();g=a.getChildren();let r=c();g.forEach(v=>r.append(v));b&&(r=b.append(r));a.replace(r)}else{var d=e[0],k=new Map;g=[];d=l.$isElementNode(d)?d:d.getParentOrThrow();for(d.isInline()&&(d=d.getParentOrThrow());null!==d;){var h=d.getPreviousSibling();if(null!==h){d=h;break}d=d.getParentOrThrow();
|
|
22
|
+
if(l.$isRootNode(d))break}h=new Set;for(var m=0;m<f;m++){var n=e[m];l.$isElementNode(n)&&0===n.getChildrenSize()&&h.add(n.getKey())}var q=new Set;for(m=0;m<f;m++){var p=e[m];n=p.getParent();null!==n&&n.isInline()&&(n=n.getParent());if(null!==n&&l.$isLeafNode(p)&&!q.has(p.getKey())){if(p=n.getKey(),void 0===k.get(p)){let r=c();g.push(r);k.set(p,r);n.getChildren().forEach(v=>{r.append(v);q.add(v.getKey())});C(n)}}else h.has(p.getKey())&&(g.push(c()),p.remove())}if(b)for(c=0;c<g.length;c++)b.append(g[c]);
|
|
23
|
+
if(l.$isRootNode(d))if(c=d.getFirstChild(),l.$isElementNode(c)&&(d=c),null===c)if(b)d.append(b);else for(b=0;b<g.length;b++)d.append(g[b]);else if(b)c.insertBefore(b);else for(b=0;b<g.length;b++)c.insertBefore(g[b]);else if(b)d.insertAfter(b);else for(b=g.length-1;0<=b;b--)d.insertAfter(g[b]);b=l.$getPreviousSelection();l.$isRangeSelection(b)&&b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()?l.$setSelection(b.clone()):a.dirty=!0}};
|
|
24
|
+
exports.createDOMRange=function(a,c,b,e,f){let g=c.getKey(),d=e.getKey(),k=document.createRange(),h=a.getElementByKey(g);a=a.getElementByKey(d);l.$isTextNode(c)&&(h=D(h));l.$isTextNode(e)&&(a=D(a));if(void 0===c||void 0===e||null===h||null===a)return null;"BR"===h.nodeName&&([h,b]=E(h));"BR"===a.nodeName&&([a,f]=E(a));c=h.firstChild;h===a&&null!=c&&"BR"===c.nodeName&&0===b&&0===f&&(f=1);try{k.setStart(h,b),k.setEnd(a,f)}catch(m){return null}!k.collapsed||b===f&&g===d||(k.setStart(a,f),k.setEnd(h,
|
|
25
|
+
b));return k};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,f;for(let g=0;g<e;g++){let d=c[g],k=d.width+b===a.width;f&&f.top===d.top&&f.left===d.left&&f.width===d.width&&f.height===d.height||k?(c.splice(g--,1),e--):f=d}return c};exports.getStyleObjectFromCSS=y;
|
|
26
|
+
exports.trimTextContentFromAnchor=function(a,c,b){let e=c.getNode();if(l.$isElementNode(e)){var f=e.getDescendantByIndex(c.offset);null!==f&&(e=f)}for(;0<b&&null!==e;){var g=e.getPreviousSibling(),d=0;if(null===g){f=e.getParentOrThrow();for(var k=f.getPreviousSibling();null===k;){f=f.getParent();if(null===f){g=null;break}k=f.getPreviousSibling()}null!==f&&(d=f.isInline()?0:2,g=l.$isElementNode(k)?k.getLastDescendant():k)}let h=e.getTextContent();""===h&&l.$isElementNode(e)&&!e.isInline()&&(h="\n\n");
|
|
27
|
+
f=h.length;k=f-b;let m=h.slice(0,k),n=F(h)&&!F(m);if(!l.$isTextNode(e)||b>=f||n)k=e.getParent(),e.remove(),0===k.getChildrenSize()&&k.remove(),b-=f+d,e=g;else{let q=e.getKey();g=a.getEditorState().read(()=>{const p=l.$getNodeByKey(q);return l.$isTextNode(p)&&p.isSimpleText()?p.getTextContent():null});null!==g&&g!==h?(b=l.$getPreviousSelection(),f=e,e.isSimpleText()?e.setTextContent(g):(f=l.$createTextNode(g),e.replace(f)),l.$isRangeSelection(b)&&b.isCollapsed()&&(b=b.anchor.offset,f.select(b,b))):
|
|
28
|
+
e.isSimpleText()?(g=c.key===q,d=c.offset,d<b&&(d=f),b=g?d-b:0,f=g?d:k,g&&0===b?([b]=e.splitText(b,f),b.remove()):([,b]=e.splitText(b,f),b.remove())):(b=l.$createTextNode(m),e.replace(b));b=0}}}
|
package/package.json
CHANGED