@lexical/selection 0.2.5 → 0.2.8
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 +118 -9
- package/LexicalSelection.js.flow +15 -0
- package/LexicalSelection.prod.js +17 -14
- 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;
|
|
@@ -30,12 +29,10 @@ function $cloneWithProperties(node) {
|
|
|
30
29
|
clone.__indent = latest.__indent;
|
|
31
30
|
clone.__dir = latest.__dir;
|
|
32
31
|
} else if (lexical.$isTextNode(latest) && lexical.$isTextNode(clone)) {
|
|
33
|
-
const marks = latest.__marks;
|
|
34
32
|
clone.__format = latest.__format;
|
|
35
33
|
clone.__style = latest.__style;
|
|
36
34
|
clone.__mode = latest.__mode;
|
|
37
35
|
clone.__detail = latest.__detail;
|
|
38
|
-
clone.__marks = marks === null ? null : Array.from(marks);
|
|
39
36
|
} // $FlowFixMe
|
|
40
37
|
|
|
41
38
|
|
|
@@ -55,7 +52,7 @@ function $getIndexFromPossibleClone(node, parent, nodeMap) {
|
|
|
55
52
|
function $getParentAvoidingExcludedElements(node) {
|
|
56
53
|
let parent = node.getParent();
|
|
57
54
|
|
|
58
|
-
while (parent !== null && parent.excludeFromCopy()) {
|
|
55
|
+
while (parent !== null && parent.excludeFromCopy('clone')) {
|
|
59
56
|
parent = parent.getParent();
|
|
60
57
|
}
|
|
61
58
|
|
|
@@ -73,7 +70,7 @@ function $copyLeafNodeBranchToRoot(leaf, startingOffset, endingOffset, isLeftSid
|
|
|
73
70
|
break;
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
if (!lexical.$isElementNode(node) || !node.excludeFromCopy()) {
|
|
73
|
+
if (!lexical.$isElementNode(node) || !node.excludeFromCopy('clone')) {
|
|
77
74
|
const key = node.getKey();
|
|
78
75
|
let clone = nodeMap.get(key);
|
|
79
76
|
const needsClone = clone === undefined;
|
|
@@ -192,7 +189,7 @@ function $cloneContentsImpl(selection) {
|
|
|
192
189
|
const node = nodes[i];
|
|
193
190
|
const key = node.getKey();
|
|
194
191
|
|
|
195
|
-
if (!nodeMap.has(key) && (!lexical.$isElementNode(node) || !node.excludeFromCopy())) {
|
|
192
|
+
if (!nodeMap.has(key) && (!lexical.$isElementNode(node) || !node.excludeFromCopy('clone'))) {
|
|
196
193
|
const clone = $cloneWithProperties(node);
|
|
197
194
|
|
|
198
195
|
if (lexical.$isRootNode(node.getParent())) {
|
|
@@ -592,9 +589,7 @@ function $wrapLeafNodesInElements(selection, createElement, wrappingElement) {
|
|
|
592
589
|
const prevSelection = lexical.$getPreviousSelection();
|
|
593
590
|
|
|
594
591
|
if (lexical.$isRangeSelection(prevSelection) && isPointAttached(prevSelection.anchor) && isPointAttached(prevSelection.focus)) {
|
|
595
|
-
|
|
596
|
-
clonedSelection.dirty = true;
|
|
597
|
-
lexical.$setSelection(clonedSelection);
|
|
592
|
+
lexical.$setSelection(prevSelection.clone());
|
|
598
593
|
} else {
|
|
599
594
|
selection.dirty = true;
|
|
600
595
|
}
|
|
@@ -616,7 +611,119 @@ function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
|
616
611
|
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
617
612
|
}
|
|
618
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
|
+
|
|
619
725
|
exports.$cloneContents = $cloneContents;
|
|
726
|
+
exports.$cloneWithProperties = $cloneWithProperties;
|
|
620
727
|
exports.$getSelectionStyleValueForProperty = $getSelectionStyleValueForProperty;
|
|
621
728
|
exports.$isAtNodeEnd = $isAtNodeEnd;
|
|
622
729
|
exports.$isParentElementRTL = $isParentElementRTL;
|
|
@@ -626,4 +733,6 @@ exports.$patchStyleText = $patchStyleText;
|
|
|
626
733
|
exports.$selectAll = $selectAll;
|
|
627
734
|
exports.$shouldOverrideDefaultCharacterSelection = $shouldOverrideDefaultCharacterSelection;
|
|
628
735
|
exports.$wrapLeafNodesInElements = $wrapLeafNodesInElements;
|
|
736
|
+
exports.createDOMRange = createDOMRange;
|
|
737
|
+
exports.createRectsFromDOMRange = createRectsFromDOMRange;
|
|
629
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
|
@@ -4,18 +4,21 @@
|
|
|
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
|
|
8
|
-
function w(a,c,b,
|
|
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,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
9
|
d.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}}
|
|
10
|
-
function x(a){if(
|
|
11
|
-
const r=h.getKey();if(!(b.has(r)||
|
|
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
|
-
|
|
14
|
-
exports.$
|
|
15
|
-
exports.$
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
exports.$
|
|
19
|
-
exports.$
|
|
20
|
-
|
|
21
|
-
if(
|
|
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
|
+
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 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
|
+
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(),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