@lexical/selection 0.2.4 → 0.2.7
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 -0
- package/LexicalSelection.dev.js +131 -35
- package/LexicalSelection.js.flow +15 -0
- package/LexicalSelection.prod.js +15 -13
- package/package.json +2 -2
package/LexicalSelection.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type {
|
|
10
10
|
ElementNode,
|
|
11
11
|
GridSelection,
|
|
12
|
+
LexicalEditor,
|
|
12
13
|
LexicalNode,
|
|
13
14
|
NodeKey,
|
|
14
15
|
NodeSelection,
|
|
@@ -21,6 +22,9 @@ export function $cloneContents(
|
|
|
21
22
|
nodeMap: Array<[NodeKey, LexicalNode]>;
|
|
22
23
|
range: Array<NodeKey>;
|
|
23
24
|
};
|
|
25
|
+
export function $cloneWithProperties<LexicalNode>(
|
|
26
|
+
node: LexicalNode,
|
|
27
|
+
): LexicalNode;
|
|
24
28
|
export function getStyleObjectFromCSS(css: string): {
|
|
25
29
|
[key: string]: string;
|
|
26
30
|
} | null;
|
|
@@ -58,3 +62,16 @@ export function $shouldOverrideDefaultCharacterSelection(
|
|
|
58
62
|
selection: RangeSelection,
|
|
59
63
|
isBackward: boolean,
|
|
60
64
|
): boolean;
|
|
65
|
+
|
|
66
|
+
declare function createDOMRange(
|
|
67
|
+
editor: LexicalEditor,
|
|
68
|
+
anchorNode: LexicalNode,
|
|
69
|
+
anchorOffset: number,
|
|
70
|
+
focusNode: LexicalNode,
|
|
71
|
+
focusOffset: number,
|
|
72
|
+
): Range | null;
|
|
73
|
+
|
|
74
|
+
declare function createRectsFromDOMRange(
|
|
75
|
+
editor: LexicalEditor,
|
|
76
|
+
range: Range,
|
|
77
|
+
): Array<ClientRect>;
|
package/LexicalSelection.dev.js
CHANGED
|
@@ -17,7 +17,6 @@ var lexical = require('lexical');
|
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
19
|
const cssToStyles = new Map();
|
|
20
|
-
|
|
21
20
|
function $cloneWithProperties(node) {
|
|
22
21
|
const latest = node.getLatest();
|
|
23
22
|
const constructor = latest.constructor;
|
|
@@ -53,14 +52,14 @@ function $getIndexFromPossibleClone(node, parent, nodeMap) {
|
|
|
53
52
|
function $getParentAvoidingExcludedElements(node) {
|
|
54
53
|
let parent = node.getParent();
|
|
55
54
|
|
|
56
|
-
while (parent !== null && parent.excludeFromCopy()) {
|
|
55
|
+
while (parent !== null && parent.excludeFromCopy('clone')) {
|
|
57
56
|
parent = parent.getParent();
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
return parent;
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
function $copyLeafNodeBranchToRoot(leaf, startingOffset, isLeftSide, range, nodeMap) {
|
|
62
|
+
function $copyLeafNodeBranchToRoot(leaf, startingOffset, endingOffset, isLeftSide, range, nodeMap) {
|
|
64
63
|
let node = leaf;
|
|
65
64
|
let offset = startingOffset;
|
|
66
65
|
|
|
@@ -71,7 +70,7 @@ function $copyLeafNodeBranchToRoot(leaf, startingOffset, isLeftSide, range, node
|
|
|
71
70
|
break;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
if (!lexical.$isElementNode(node) || !node.excludeFromCopy()) {
|
|
73
|
+
if (!lexical.$isElementNode(node) || !node.excludeFromCopy('clone')) {
|
|
75
74
|
const key = node.getKey();
|
|
76
75
|
let clone = nodeMap.get(key);
|
|
77
76
|
const needsClone = clone === undefined;
|
|
@@ -82,9 +81,9 @@ function $copyLeafNodeBranchToRoot(leaf, startingOffset, isLeftSide, range, node
|
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
if (lexical.$isTextNode(clone) && !clone.isSegmented() && !clone.isToken()) {
|
|
85
|
-
clone.__text = clone.__text.slice(isLeftSide ? offset : 0, isLeftSide ?
|
|
84
|
+
clone.__text = clone.__text.slice(isLeftSide ? offset : 0, isLeftSide ? endingOffset : offset);
|
|
86
85
|
} else if (lexical.$isElementNode(clone)) {
|
|
87
|
-
clone.__children = clone.__children.slice(isLeftSide ? offset : 0, isLeftSide ? undefined : offset + 1);
|
|
86
|
+
clone.__children = clone.__children.slice(isLeftSide ? offset : 0, isLeftSide ? undefined : (offset || 0) + 1);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
if (lexical.$isRootNode(parent)) {
|
|
@@ -140,25 +139,7 @@ function $cloneContentsImpl(selection) {
|
|
|
140
139
|
if (lexical.$isRangeSelection(selection)) {
|
|
141
140
|
const anchor = selection.anchor;
|
|
142
141
|
const focus = selection.focus;
|
|
143
|
-
const anchorOffset =
|
|
144
|
-
const focusOffset = focus.getCharacterOffset();
|
|
145
|
-
const anchorNode = anchor.getNode();
|
|
146
|
-
const focusNode = focus.getNode();
|
|
147
|
-
const anchorNodeParent = anchorNode.getParentOrThrow(); // Handle a single text node extraction
|
|
148
|
-
|
|
149
|
-
if (anchorNode === focusNode && lexical.$isTextNode(anchorNode) && (anchorNodeParent.canBeEmpty() || anchorNodeParent.getChildrenSize() > 1)) {
|
|
150
|
-
const clonedFirstNode = $cloneWithProperties(anchorNode);
|
|
151
|
-
const isBefore = focusOffset > anchorOffset;
|
|
152
|
-
const startOffset = isBefore ? anchorOffset : focusOffset;
|
|
153
|
-
const endOffset = isBefore ? focusOffset : anchorOffset;
|
|
154
|
-
clonedFirstNode.__text = clonedFirstNode.__text.slice(startOffset, endOffset);
|
|
155
|
-
const key = clonedFirstNode.getKey();
|
|
156
|
-
return {
|
|
157
|
-
nodeMap: [[key, clonedFirstNode]],
|
|
158
|
-
range: [key]
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
142
|
+
const [anchorOffset, focusOffset] = selection.getCharacterOffsets();
|
|
162
143
|
const nodes = selection.getNodes();
|
|
163
144
|
|
|
164
145
|
if (nodes.length === 0) {
|
|
@@ -199,27 +180,30 @@ function $cloneContentsImpl(selection) {
|
|
|
199
180
|
const lastNode = nodes[nodesLength - 1];
|
|
200
181
|
const isBefore = anchor.isBefore(focus);
|
|
201
182
|
const nodeMap = new Map();
|
|
202
|
-
const range = [];
|
|
183
|
+
const range = [];
|
|
184
|
+
const isOnlyText = lexical.$isTextNode(firstNode) && nodesLength === 1; // Do first node to root
|
|
203
185
|
|
|
204
|
-
$copyLeafNodeBranchToRoot(firstNode, isBefore ? anchorOffset : focusOffset, true, range, nodeMap); // Copy all nodes between
|
|
186
|
+
$copyLeafNodeBranchToRoot(firstNode, isBefore ? anchorOffset : focusOffset, isOnlyText ? isBefore ? focusOffset : anchorOffset : undefined, true, range, nodeMap); // Copy all nodes between
|
|
205
187
|
|
|
206
188
|
for (let i = 0; i < nodesLength; i++) {
|
|
207
189
|
const node = nodes[i];
|
|
208
190
|
const key = node.getKey();
|
|
209
191
|
|
|
210
|
-
if (!nodeMap.has(key) && (!lexical.$isElementNode(node) || !node.excludeFromCopy())) {
|
|
192
|
+
if (!nodeMap.has(key) && (!lexical.$isElementNode(node) || !node.excludeFromCopy('clone'))) {
|
|
211
193
|
const clone = $cloneWithProperties(node);
|
|
212
194
|
|
|
213
195
|
if (lexical.$isRootNode(node.getParent())) {
|
|
214
196
|
range.push(node.getKey());
|
|
215
197
|
}
|
|
216
198
|
|
|
217
|
-
|
|
199
|
+
if (key !== 'root') {
|
|
200
|
+
nodeMap.set(key, clone);
|
|
201
|
+
}
|
|
218
202
|
}
|
|
219
203
|
} // Do last node to root
|
|
220
204
|
|
|
221
205
|
|
|
222
|
-
$copyLeafNodeBranchToRoot(lastNode, isBefore ? focusOffset : anchorOffset, false, range, nodeMap);
|
|
206
|
+
$copyLeafNodeBranchToRoot(lastNode, isOnlyText ? undefined : isBefore ? focusOffset : anchorOffset, undefined, false, range, nodeMap);
|
|
223
207
|
return {
|
|
224
208
|
nodeMap: Array.from(nodeMap.entries()),
|
|
225
209
|
range
|
|
@@ -469,9 +453,9 @@ function $removeParentEmptyElements(startingNode) {
|
|
|
469
453
|
function $wrapLeafNodesInElements(selection, createElement, wrappingElement) {
|
|
470
454
|
const nodes = selection.getNodes();
|
|
471
455
|
const nodesLength = nodes.length;
|
|
456
|
+
const anchor = selection.anchor;
|
|
472
457
|
|
|
473
|
-
if (nodesLength === 0) {
|
|
474
|
-
const anchor = selection.anchor;
|
|
458
|
+
if (nodesLength === 0 || nodesLength === 1 && anchor.type === 'element' && anchor.getNode().getChildrenSize() === 0) {
|
|
475
459
|
const target = anchor.type === 'text' ? anchor.getNode().getParentOrThrow() : anchor.getNode();
|
|
476
460
|
const children = target.getChildren();
|
|
477
461
|
let element = createElement();
|
|
@@ -605,9 +589,7 @@ function $wrapLeafNodesInElements(selection, createElement, wrappingElement) {
|
|
|
605
589
|
const prevSelection = lexical.$getPreviousSelection();
|
|
606
590
|
|
|
607
591
|
if (lexical.$isRangeSelection(prevSelection) && isPointAttached(prevSelection.anchor) && isPointAttached(prevSelection.focus)) {
|
|
608
|
-
|
|
609
|
-
clonedSelection.dirty = true;
|
|
610
|
-
lexical.$setSelection(clonedSelection);
|
|
592
|
+
lexical.$setSelection(prevSelection.clone());
|
|
611
593
|
} else {
|
|
612
594
|
selection.dirty = true;
|
|
613
595
|
}
|
|
@@ -629,7 +611,119 @@ function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
|
629
611
|
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
630
612
|
}
|
|
631
613
|
|
|
614
|
+
function getDOMTextNode(element) {
|
|
615
|
+
let node = element;
|
|
616
|
+
|
|
617
|
+
while (node != null) {
|
|
618
|
+
if (node.nodeType === 3) {
|
|
619
|
+
// $FlowFixMe: this is a Text
|
|
620
|
+
return node;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
node = node.firstChild;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
function getDOMIndexWithinParent(node) {
|
|
630
|
+
const parent = node.parentNode;
|
|
631
|
+
|
|
632
|
+
if (parent == null) {
|
|
633
|
+
throw new Error('Should never happen');
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return [parent, Array.from(parent.childNodes).indexOf(node)];
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
function createDOMRange(editor, anchorNode, _anchorOffset, focusNode, _focusOffset) {
|
|
640
|
+
const anchorKey = anchorNode.getKey();
|
|
641
|
+
const focusKey = focusNode.getKey();
|
|
642
|
+
const range = document.createRange();
|
|
643
|
+
let anchorDOM = editor.getElementByKey(anchorKey);
|
|
644
|
+
let focusDOM = editor.getElementByKey(focusKey);
|
|
645
|
+
let anchorOffset = _anchorOffset;
|
|
646
|
+
let focusOffset = _focusOffset;
|
|
647
|
+
|
|
648
|
+
if (lexical.$isTextNode(anchorNode)) {
|
|
649
|
+
anchorDOM = getDOMTextNode(anchorDOM);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
if (lexical.$isTextNode(focusNode)) {
|
|
653
|
+
focusDOM = getDOMTextNode(focusDOM);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (anchorNode === undefined || focusNode === undefined || anchorDOM === null || focusDOM === null) {
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (anchorDOM.nodeName === 'BR') {
|
|
661
|
+
[anchorDOM, anchorOffset] = getDOMIndexWithinParent(anchorDOM);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
if (focusDOM.nodeName === 'BR') {
|
|
665
|
+
[focusDOM, focusOffset] = getDOMIndexWithinParent(focusDOM);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const firstChild = anchorDOM.firstChild;
|
|
669
|
+
|
|
670
|
+
if (anchorDOM === focusDOM && firstChild != null && firstChild.nodeName === 'BR' && anchorOffset === 0 && focusOffset === 0) {
|
|
671
|
+
focusOffset = 1;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
try {
|
|
675
|
+
range.setStart(anchorDOM, anchorOffset);
|
|
676
|
+
range.setEnd(focusDOM, focusOffset);
|
|
677
|
+
} catch (e) {
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
if (range.collapsed && (anchorOffset !== focusOffset || anchorKey !== focusKey)) {
|
|
682
|
+
// Range is backwards, we need to reverse it
|
|
683
|
+
range.setStart(focusDOM, focusOffset);
|
|
684
|
+
range.setEnd(anchorDOM, anchorOffset);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
return range;
|
|
688
|
+
}
|
|
689
|
+
function createRectsFromDOMRange(editor, range) {
|
|
690
|
+
const rootElement = editor.getRootElement();
|
|
691
|
+
|
|
692
|
+
if (rootElement === null) {
|
|
693
|
+
return [];
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
const rootRect = rootElement.getBoundingClientRect();
|
|
697
|
+
const computedStyle = getComputedStyle(rootElement);
|
|
698
|
+
const rootPadding = parseFloat(computedStyle.paddingLeft) + parseFloat(computedStyle.paddingRight);
|
|
699
|
+
const selectionRects = Array.from(range.getClientRects());
|
|
700
|
+
let selectionRectsLength = selectionRects.length;
|
|
701
|
+
let prevRect;
|
|
702
|
+
|
|
703
|
+
for (let i = 0; i < selectionRectsLength; i++) {
|
|
704
|
+
const selectionRect = selectionRects[i]; // Exclude a rect that is the exact same as the last rect. getClientRects() can return
|
|
705
|
+
// the same rect twice for some elements. A more sophisticated thing to do here is to
|
|
706
|
+
// merge all the rects together into a set of rects that don't overlap, so we don't
|
|
707
|
+
// generate backgrounds that are too dark.
|
|
708
|
+
|
|
709
|
+
const isDuplicateRect = prevRect && prevRect.top === selectionRect.top && prevRect.left === selectionRect.left && prevRect.width === selectionRect.width && prevRect.height === selectionRect.height; // Exclude selections that span the entire element
|
|
710
|
+
|
|
711
|
+
const selectionSpansElement = selectionRect.width + rootPadding === rootRect.width;
|
|
712
|
+
|
|
713
|
+
if (isDuplicateRect || selectionSpansElement) {
|
|
714
|
+
selectionRects.splice(i--, 1);
|
|
715
|
+
selectionRectsLength--;
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
prevRect = selectionRect;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
return selectionRects;
|
|
723
|
+
}
|
|
724
|
+
|
|
632
725
|
exports.$cloneContents = $cloneContents;
|
|
726
|
+
exports.$cloneWithProperties = $cloneWithProperties;
|
|
633
727
|
exports.$getSelectionStyleValueForProperty = $getSelectionStyleValueForProperty;
|
|
634
728
|
exports.$isAtNodeEnd = $isAtNodeEnd;
|
|
635
729
|
exports.$isParentElementRTL = $isParentElementRTL;
|
|
@@ -639,4 +733,6 @@ exports.$patchStyleText = $patchStyleText;
|
|
|
639
733
|
exports.$selectAll = $selectAll;
|
|
640
734
|
exports.$shouldOverrideDefaultCharacterSelection = $shouldOverrideDefaultCharacterSelection;
|
|
641
735
|
exports.$wrapLeafNodesInElements = $wrapLeafNodesInElements;
|
|
736
|
+
exports.createDOMRange = createDOMRange;
|
|
737
|
+
exports.createRectsFromDOMRange = createRectsFromDOMRange;
|
|
642
738
|
exports.getStyleObjectFromCSS = getStyleObjectFromCSS;
|
package/LexicalSelection.js.flow
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type {
|
|
10
10
|
ElementNode,
|
|
11
11
|
GridSelection,
|
|
12
|
+
LexicalEditor,
|
|
12
13
|
LexicalNode,
|
|
13
14
|
NodeKey,
|
|
14
15
|
NodeSelection,
|
|
@@ -21,6 +22,7 @@ declare export function $cloneContents(
|
|
|
21
22
|
nodeMap: Array<[NodeKey, LexicalNode]>,
|
|
22
23
|
range: Array<NodeKey>,
|
|
23
24
|
};
|
|
25
|
+
declare export function $cloneWithProperties<T: LexicalNode>(node: T): T;
|
|
24
26
|
declare export function getStyleObjectFromCSS(css: string): {
|
|
25
27
|
[string]: string,
|
|
26
28
|
} | null;
|
|
@@ -58,3 +60,16 @@ declare export function $shouldOverrideDefaultCharacterSelection(
|
|
|
58
60
|
selection: RangeSelection,
|
|
59
61
|
isBackward: boolean,
|
|
60
62
|
): boolean;
|
|
63
|
+
|
|
64
|
+
declare export function createDOMRange(
|
|
65
|
+
editor: LexicalEditor,
|
|
66
|
+
anchorNode: LexicalNode,
|
|
67
|
+
anchorOffset: number,
|
|
68
|
+
focusNode: LexicalNode,
|
|
69
|
+
focusOffset: number,
|
|
70
|
+
): Range | null;
|
|
71
|
+
|
|
72
|
+
declare export function createRectsFromDOMRange(
|
|
73
|
+
editor: LexicalEditor,
|
|
74
|
+
range: Range,
|
|
75
|
+
): Array<ClientRect>;
|
package/LexicalSelection.prod.js
CHANGED
|
@@ -5,18 +5,20 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
var l=require("lexical");const t=new Map;function u(a){a=a.getLatest();const 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,g,
|
|
9
|
-
|
|
10
|
-
function x(a){if(l.$isRangeSelection(a)){var c=a.anchor,b=a.focus
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let g=null;const
|
|
8
|
+
function w(a,c,b,g,k,f){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")){const h=a.getKey();let e=f.get(h);const m=void 0===e;m&&(e=u(a),f.set(h,e));!l.$isTextNode(e)||e.isSegmented()||e.isToken()?l.$isElementNode(e)&&(e.__children=e.__children.slice(g?d:0,g?void 0:(d||0)+1)):e.__text=e.__text.slice(g?d:0,g?b:d);if(l.$isRootNode(c)){m&&k.push(h);break}}d=f.get(c.getKey());d=l.$isElementNode(d)?
|
|
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;const [e,m]=a.getCharacterOffsets();a=a.getNodes();if(0===a.length)return{nodeMap:[],range:[]};let n=a.length;var g=a[0],k=g.getParent();if(null!==k&&(!k.canBeEmpty()||l.$isRootNode(k))){var f=k.__children;if(f.length===n){var d=!0;for(var h=0;h<f.length;h++)if(f[h]!==a[h].__key){d=!1;break}d&&(n++,a.push(k))}}k=a[n-1];c=c.isBefore(b);b=new Map;f=[];d=l.$isTextNode(g)&&1===n;w(g,c?e:m,d?c?m:e:void 0,!0,f,b);for(g=0;g<n;g++){h=a[g];
|
|
11
|
+
const r=h.getKey();if(!(b.has(r)||l.$isElementNode(h)&&h.excludeFromCopy("clone"))){const p=u(h);l.$isRootNode(h.getParent())&&f.push(h.getKey());"root"!==r&&b.set(r,p)}}w(k,d?void 0:c?m:e,void 0,!1,f,b);return{nodeMap:Array.from(b.entries()),range:f}}if(l.$isGridSelection(a))return{nodeMap:a.getNodes().map(e=>{const m=e.getKey();e=u(e);return[m,e]}),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(g in c)g&&(b+=`${g}: ${c[g]};`);var g=b;a.setStyle(g);t.set(g,c)}function A(a,c,b,g){a.modify(c?"extend":"move",b,g)}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);){const c=a.getLatest(),b=a.getParent();0===c.__children.length&&a.remove(!0);a=b}}
|
|
13
|
+
function D(a){for(;null!=a;){if(3===a.nodeType)return a;a=a.firstChild}return null}function E(a){const c=a.parentNode;if(null==c)throw Error("Should never happen");return[c,Array.from(c.childNodes).indexOf(a)]}exports.$cloneContents=function(a){return x(a)};exports.$cloneWithProperties=u;
|
|
14
|
+
exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let g=null;const k=a.getNodes();var f=a.anchor,d=a.focus,h=a.isBackward();a=h?d.offset:f.offset;f=h?d.getNode():f.getNode();for(d=0;d<k.length;d++){var e=k[d];if((0===d||0!==a||!e.is(f))&&l.$isTextNode(e)){h=c;var m=b;e=e.getStyle();e=y(e);h=null!==e?e[h]||m:m;if(null===g)g=h;else if(g!==h){g="";break}}}return null===g?b:g};exports.$isAtNodeEnd=function(a){return"text"===a.type?a.offset===a.getNode().getTextContentSize():a.offset===a.getNode().getChildrenSize()};
|
|
15
15
|
exports.$isParentElementRTL=B;exports.$moveCaretSelection=A;exports.$moveCharacter=function(a,c,b){const g=B(a);A(a,c,b?!g:g,"character")};
|
|
16
|
-
exports.$patchStyleText=function(a,c){var b=a.getNodes();const g=b.length-1;let
|
|
17
|
-
d&&([,
|
|
18
|
-
exports.$selectAll=function(a){const c=a.anchor;a=a.focus;var b=c.getNode().getTopLevelElementOrThrow().getParentOrThrow();let g=b.getFirstDescendant();b=b.getLastDescendant();let
|
|
16
|
+
exports.$patchStyleText=function(a,c){var b=a.getNodes();const g=b.length-1;let k=b[0],f=b[g];if(!a.isCollapsed()){var d=a.anchor,h=a.focus;a=k.getTextContent().length;var e=h.offset,m=d.offset;d=(h=d.isBefore(h))?m:e;h=h?e:m;if(d===k.getTextContentSize()){const n=k.getNextSibling();l.$isTextNode(n)&&(d=m=0,k=n)}if(k.is(f))l.$isTextNode(k)&&(d=m>e?e:m,h=m>e?m:e,d!==h&&(0===d&&h===a?(z(k,c),k.select(d,h)):(b=k.splitText(d,h),b=0===d?b[0]:b[1],z(b,c),b.select(0,h-d))));else for(l.$isTextNode(k)&&(0!==
|
|
17
|
+
d&&([,k]=k.splitText(d)),z(k,c)),l.$isTextNode(f)&&(a=f.getTextContent().length,h!==a&&([f]=f.splitText(h)),0!==h&&z(f,c)),a=1;a<g;a++)e=b[a],m=e.getKey(),l.$isTextNode(e)&&m!==k.getKey()&&m!==f.getKey()&&!e.isToken()&&z(e,c)}};
|
|
18
|
+
exports.$selectAll=function(a){const c=a.anchor;a=a.focus;var b=c.getNode().getTopLevelElementOrThrow().getParentOrThrow();let g=b.getFirstDescendant();b=b.getLastDescendant();let k="element",f="element",d=0;l.$isTextNode(g)?k="text":l.$isElementNode(g)||null===g||(g=g.getParentOrThrow());l.$isTextNode(b)?(f="text",d=b.getTextContentSize()):l.$isElementNode(b)||null===b||(b=b.getParentOrThrow(),d=b.getChildrenSize());g&&b&&(c.set(g.getKey(),0,k),a.set(b.getKey(),d,f))};
|
|
19
19
|
exports.$shouldOverrideDefaultCharacterSelection=function(a,c){a=l.$getDecoratorNode(a.focus,c);return l.$isDecoratorNode(a)&&!a.isIsolated()};
|
|
20
|
-
exports.$wrapLeafNodesInElements=function(a,c,b){const g=a.getNodes(),
|
|
21
|
-
0;m<
|
|
22
|
-
l.$isElementNode(c)&&(d=c),null===c)if(b)d.append(b);else for(b=0;b<
|
|
20
|
+
exports.$wrapLeafNodesInElements=function(a,c,b){const g=a.getNodes(),k=g.length;var f=a.anchor;if(0===k||1===k&&"element"===f.type&&0===f.getNode().getChildrenSize()){a="text"===f.type?f.getNode().getParentOrThrow():f.getNode();f=a.getChildren();let q=c();f.forEach(v=>q.append(v));b&&(q=b.append(q));a.replace(q)}else{var d=g[0],h=new Map;f=[];d=l.$isElementNode(d)?d:d.getParentOrThrow();for(d.isInline()&&(d=d.getParentOrThrow());null!==d;){var e=d.getPreviousSibling();if(null!==e){d=e;break}d=d.getParentOrThrow();
|
|
21
|
+
if(l.$isRootNode(d))break}e=new Set;for(var m=0;m<k;m++){var n=g[m];l.$isElementNode(n)&&0===n.getChildrenSize()&&e.add(n.getKey())}var r=new Set;for(m=0;m<k;m++){var p=g[m];n=p.getParent();null!==n&&n.isInline()&&(n=n.getParent());if(null!==n&&l.$isLeafNode(p)&&!r.has(p.getKey())){if(p=n.getKey(),void 0===h.get(p)){const q=c();f.push(q);h.set(p,q);n.getChildren().forEach(v=>{q.append(v);r.add(v.getKey())});C(n)}}else e.has(p.getKey())&&(f.push(c()),p.remove())}if(b)for(c=0;c<f.length;c++)b.append(f[c]);
|
|
22
|
+
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<f.length;b++)d.append(f[b]);else if(b)c.insertBefore(b);else for(b=0;b<f.length;b++)c.insertBefore(f[b]);else if(b)d.insertAfter(b);else for(b=f.length-1;0<=b;b--)d.insertAfter(f[b]);b=l.$getPreviousSelection();l.$isRangeSelection(b)&&b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()?l.$setSelection(b.clone()):a.dirty=!0}};
|
|
23
|
+
exports.createDOMRange=function(a,c,b,g,k){const f=c.getKey(),d=g.getKey(),h=document.createRange();let e=a.getElementByKey(f);a=a.getElementByKey(d);l.$isTextNode(c)&&(e=D(e));l.$isTextNode(g)&&(a=D(a));if(void 0===c||void 0===g||null===e||null===a)return null;"BR"===e.nodeName&&([e,b]=E(e));"BR"===a.nodeName&&([a,k]=E(a));c=e.firstChild;e===a&&null!=c&&"BR"===c.nodeName&&0===b&&0===k&&(k=1);try{h.setStart(e,b),h.setEnd(a,k)}catch(m){return null}!h.collapsed||b===k&&f===d||(h.setStart(a,k),h.setEnd(e,
|
|
24
|
+
b));return h};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 g=c.length,k;for(let f=0;f<g;f++){const d=c[f],h=d.width+b===a.width;k&&k.top===d.top&&k.left===d.left&&k.width===d.width&&k.height===d.height||h?(c.splice(f--,1),g--):k=d}return c};exports.getStyleObjectFromCSS=y;
|
package/package.json
CHANGED