@lexical/selection 0.1.16 → 0.1.19
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/LICENSE +1 -1
- package/LexicalSelection.d.ts +60 -0
- package/LexicalSelection.dev.js +134 -71
- package/LexicalSelection.js.flow +60 -0
- package/LexicalSelection.prod.js +15 -14
- package/package.json +2 -6
package/LICENSE
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
import type {
|
|
10
|
+
ElementNode,
|
|
11
|
+
GridSelection,
|
|
12
|
+
LexicalNode,
|
|
13
|
+
NodeKey,
|
|
14
|
+
NodeSelection,
|
|
15
|
+
Point,
|
|
16
|
+
RangeSelection,
|
|
17
|
+
} from 'lexical';
|
|
18
|
+
export function $cloneContents(
|
|
19
|
+
selection: RangeSelection | NodeSelection | GridSelection,
|
|
20
|
+
): {
|
|
21
|
+
nodeMap: Array<[NodeKey, LexicalNode]>;
|
|
22
|
+
range: Array<NodeKey>;
|
|
23
|
+
};
|
|
24
|
+
export function getStyleObjectFromCSS(css: string): {
|
|
25
|
+
[key: string]: string;
|
|
26
|
+
} | null;
|
|
27
|
+
export function $patchStyleText(
|
|
28
|
+
selection: RangeSelection | GridSelection,
|
|
29
|
+
patch: {
|
|
30
|
+
[key: string]: string;
|
|
31
|
+
},
|
|
32
|
+
): void;
|
|
33
|
+
export function $getSelectionStyleValueForProperty(
|
|
34
|
+
selection: RangeSelection,
|
|
35
|
+
styleProperty: string,
|
|
36
|
+
defaultValue: string,
|
|
37
|
+
): string;
|
|
38
|
+
export function $moveCaretSelection(
|
|
39
|
+
selection: RangeSelection,
|
|
40
|
+
isHoldingShift: boolean,
|
|
41
|
+
isBackward: boolean,
|
|
42
|
+
granularity: 'character' | 'word' | 'lineboundary',
|
|
43
|
+
): void;
|
|
44
|
+
export function $isParentElementRTL(selection: RangeSelection): boolean;
|
|
45
|
+
export function $moveCharacter(
|
|
46
|
+
selection: RangeSelection,
|
|
47
|
+
isHoldingShift: boolean,
|
|
48
|
+
isBackward: boolean,
|
|
49
|
+
): void;
|
|
50
|
+
export function $selectAll(selection: RangeSelection): void;
|
|
51
|
+
export function $wrapLeafNodesInElements(
|
|
52
|
+
selection: RangeSelection,
|
|
53
|
+
createElement: () => ElementNode,
|
|
54
|
+
wrappingElement?: ElementNode,
|
|
55
|
+
): void;
|
|
56
|
+
export function $isAtNodeEnd(point: Point): boolean;
|
|
57
|
+
export function $shouldOverrideDefaultCharacterSelection(
|
|
58
|
+
selection: RangeSelection,
|
|
59
|
+
isBackward: boolean,
|
|
60
|
+
): boolean;
|
package/LexicalSelection.dev.js
CHANGED
|
@@ -105,100 +105,144 @@ function $copyLeafNodeBranchToRoot(leaf, startingOffset, isLeftSide, range, node
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
function errGetLatestOnClone() {
|
|
109
|
+
{
|
|
110
|
+
throw Error(`getLatest() on clone node`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
108
114
|
function $cloneContents(selection) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
const clone = $cloneContentsImpl(selection);
|
|
116
|
+
|
|
117
|
+
{
|
|
118
|
+
const nodeMap = clone.nodeMap;
|
|
119
|
+
|
|
120
|
+
for (let i = 0; i < nodeMap.length; i++) {
|
|
121
|
+
const node = nodeMap[i][1]; // $FlowFixMe[method-unbinding]
|
|
122
|
+
|
|
123
|
+
if (node.getLatest === errGetLatestOnClone) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
Object.setPrototypeOf(node, Object.create(Object.getPrototypeOf(node), {
|
|
128
|
+
getLatest: {
|
|
129
|
+
configurable: true,
|
|
130
|
+
enumerable: true,
|
|
131
|
+
value: errGetLatestOnClone,
|
|
132
|
+
writable: true
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
112
135
|
}
|
|
113
136
|
}
|
|
114
137
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const anchorOffset = anchor.getCharacterOffset();
|
|
118
|
-
const focusOffset = focus.getCharacterOffset();
|
|
119
|
-
const anchorNode = anchor.getNode();
|
|
120
|
-
const focusNode = focus.getNode();
|
|
121
|
-
const anchorNodeParent = anchorNode.getParentOrThrow(); // Handle a single text node extraction
|
|
122
|
-
|
|
123
|
-
if (anchorNode === focusNode && lexical.$isTextNode(anchorNode) && (anchorNodeParent.canBeEmpty() || anchorNodeParent.getChildrenSize() > 1)) {
|
|
124
|
-
const clonedFirstNode = $cloneWithProperties(anchorNode);
|
|
125
|
-
const isBefore = focusOffset > anchorOffset;
|
|
126
|
-
const startOffset = isBefore ? anchorOffset : focusOffset;
|
|
127
|
-
const endOffset = isBefore ? focusOffset : anchorOffset;
|
|
128
|
-
clonedFirstNode.__text = clonedFirstNode.__text.slice(startOffset, endOffset);
|
|
129
|
-
const key = clonedFirstNode.getKey();
|
|
130
|
-
return {
|
|
131
|
-
nodeMap: [[key, clonedFirstNode]],
|
|
132
|
-
range: [key]
|
|
133
|
-
};
|
|
134
|
-
}
|
|
138
|
+
return clone;
|
|
139
|
+
}
|
|
135
140
|
|
|
136
|
-
|
|
141
|
+
function $cloneContentsImpl(selection) {
|
|
142
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
143
|
+
const anchor = selection.anchor;
|
|
144
|
+
const focus = selection.focus;
|
|
145
|
+
const anchorOffset = anchor.getCharacterOffset();
|
|
146
|
+
const focusOffset = focus.getCharacterOffset();
|
|
147
|
+
const anchorNode = anchor.getNode();
|
|
148
|
+
const focusNode = focus.getNode();
|
|
149
|
+
const anchorNodeParent = anchorNode.getParentOrThrow(); // Handle a single text node extraction
|
|
150
|
+
|
|
151
|
+
if (anchorNode === focusNode && lexical.$isTextNode(anchorNode) && (anchorNodeParent.canBeEmpty() || anchorNodeParent.getChildrenSize() > 1)) {
|
|
152
|
+
const clonedFirstNode = $cloneWithProperties(anchorNode);
|
|
153
|
+
const isBefore = focusOffset > anchorOffset;
|
|
154
|
+
const startOffset = isBefore ? anchorOffset : focusOffset;
|
|
155
|
+
const endOffset = isBefore ? focusOffset : anchorOffset;
|
|
156
|
+
clonedFirstNode.__text = clonedFirstNode.__text.slice(startOffset, endOffset);
|
|
157
|
+
const key = clonedFirstNode.getKey();
|
|
158
|
+
return {
|
|
159
|
+
nodeMap: [[key, clonedFirstNode]],
|
|
160
|
+
range: [key]
|
|
161
|
+
};
|
|
162
|
+
}
|
|
137
163
|
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
nodeMap: [],
|
|
141
|
-
range: []
|
|
142
|
-
};
|
|
143
|
-
} // Check if we can use the parent of the nodes, if the
|
|
144
|
-
// parent can't be empty, then it's important that we
|
|
145
|
-
// also copy that element node along with its children.
|
|
164
|
+
const nodes = selection.getNodes();
|
|
146
165
|
|
|
166
|
+
if (nodes.length === 0) {
|
|
167
|
+
return {
|
|
168
|
+
nodeMap: [],
|
|
169
|
+
range: []
|
|
170
|
+
};
|
|
171
|
+
} // Check if we can use the parent of the nodes, if the
|
|
172
|
+
// parent can't be empty, then it's important that we
|
|
173
|
+
// also copy that element node along with its children.
|
|
147
174
|
|
|
148
|
-
let nodesLength = nodes.length;
|
|
149
|
-
const firstNode = nodes[0];
|
|
150
|
-
const firstNodeParent = firstNode.getParent();
|
|
151
175
|
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
const
|
|
176
|
+
let nodesLength = nodes.length;
|
|
177
|
+
const firstNode = nodes[0];
|
|
178
|
+
const firstNodeParent = firstNode.getParent();
|
|
155
179
|
|
|
156
|
-
if (
|
|
157
|
-
|
|
180
|
+
if (firstNodeParent !== null && (!firstNodeParent.canBeEmpty() || lexical.$isRootNode(firstNodeParent))) {
|
|
181
|
+
const parentChildren = firstNodeParent.__children;
|
|
182
|
+
const parentChildrenLength = parentChildren.length;
|
|
158
183
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
184
|
+
if (parentChildrenLength === nodesLength) {
|
|
185
|
+
let areTheSame = true;
|
|
186
|
+
|
|
187
|
+
for (let i = 0; i < parentChildren.length; i++) {
|
|
188
|
+
if (parentChildren[i] !== nodes[i].__key) {
|
|
189
|
+
areTheSame = false;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
163
192
|
}
|
|
164
|
-
}
|
|
165
193
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
194
|
+
if (areTheSame) {
|
|
195
|
+
nodesLength++;
|
|
196
|
+
nodes.push(firstNodeParent);
|
|
197
|
+
}
|
|
169
198
|
}
|
|
170
199
|
}
|
|
171
|
-
}
|
|
172
200
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
201
|
+
const lastNode = nodes[nodesLength - 1];
|
|
202
|
+
const isBefore = anchor.isBefore(focus);
|
|
203
|
+
const nodeMap = new Map();
|
|
204
|
+
const range = []; // Do first node to root
|
|
177
205
|
|
|
178
|
-
|
|
206
|
+
$copyLeafNodeBranchToRoot(firstNode, isBefore ? anchorOffset : focusOffset, true, range, nodeMap); // Copy all nodes between
|
|
179
207
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
208
|
+
for (let i = 0; i < nodesLength; i++) {
|
|
209
|
+
const node = nodes[i];
|
|
210
|
+
const key = node.getKey();
|
|
183
211
|
|
|
184
|
-
|
|
185
|
-
|
|
212
|
+
if (!nodeMap.has(key) && (!lexical.$isElementNode(node) || !node.excludeFromCopy())) {
|
|
213
|
+
const clone = $cloneWithProperties(node);
|
|
186
214
|
|
|
187
|
-
|
|
188
|
-
|
|
215
|
+
if (lexical.$isRootNode(node.getParent())) {
|
|
216
|
+
range.push(node.getKey());
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
nodeMap.set(key, clone);
|
|
189
220
|
}
|
|
221
|
+
} // Do last node to root
|
|
190
222
|
|
|
191
|
-
nodeMap.set(key, clone);
|
|
192
|
-
}
|
|
193
|
-
} // Do last node to root
|
|
194
223
|
|
|
224
|
+
$copyLeafNodeBranchToRoot(lastNode, isBefore ? focusOffset : anchorOffset, false, range, nodeMap);
|
|
225
|
+
return {
|
|
226
|
+
nodeMap: Array.from(nodeMap.entries()),
|
|
227
|
+
range
|
|
228
|
+
};
|
|
229
|
+
} else if (lexical.$isGridSelection(selection)) {
|
|
230
|
+
const nodeMap = selection.getNodes().map(node => {
|
|
231
|
+
const nodeKey = node.getKey();
|
|
232
|
+
const clone = $cloneWithProperties(node);
|
|
233
|
+
return [nodeKey, clone];
|
|
234
|
+
});
|
|
235
|
+
return {
|
|
236
|
+
nodeMap,
|
|
237
|
+
range: [selection.gridKey]
|
|
238
|
+
};
|
|
239
|
+
}
|
|
195
240
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
range
|
|
200
|
-
};
|
|
241
|
+
{
|
|
242
|
+
throw Error(`TODO`);
|
|
243
|
+
}
|
|
201
244
|
}
|
|
245
|
+
|
|
202
246
|
function getStyleObjectFromCSS(css) {
|
|
203
247
|
return cssToStyles.get(css) || null;
|
|
204
248
|
}
|
|
@@ -452,6 +496,10 @@ function $wrapLeafNodesInElements(selection, createElement, wrappingElement) {
|
|
|
452
496
|
|
|
453
497
|
let target = lexical.$isElementNode(firstNode) ? firstNode : firstNode.getParentOrThrow();
|
|
454
498
|
|
|
499
|
+
if (target.isInline()) {
|
|
500
|
+
target = target.getParentOrThrow();
|
|
501
|
+
}
|
|
502
|
+
|
|
455
503
|
while (target !== null) {
|
|
456
504
|
const prevSibling = target.getPreviousSibling();
|
|
457
505
|
|
|
@@ -483,7 +531,11 @@ function $wrapLeafNodesInElements(selection, createElement, wrappingElement) {
|
|
|
483
531
|
|
|
484
532
|
for (let i = 0; i < nodesLength; i++) {
|
|
485
533
|
const node = nodes[i];
|
|
486
|
-
|
|
534
|
+
let parent = node.getParent();
|
|
535
|
+
|
|
536
|
+
if (parent !== null && parent.isInline()) {
|
|
537
|
+
parent = parent.getParent();
|
|
538
|
+
}
|
|
487
539
|
|
|
488
540
|
if (parent !== null && lexical.$isLeafNode(node) && !movedLeafNodes.has(node.getKey())) {
|
|
489
541
|
const parentKey = parent.getKey();
|
|
@@ -552,8 +604,19 @@ function $wrapLeafNodesInElements(selection, createElement, wrappingElement) {
|
|
|
552
604
|
}
|
|
553
605
|
}
|
|
554
606
|
|
|
555
|
-
|
|
607
|
+
const prevSelection = lexical.$getPreviousSelection();
|
|
608
|
+
|
|
609
|
+
if (lexical.$isRangeSelection(prevSelection) && isPointAttached(prevSelection.anchor) && isPointAttached(prevSelection.focus)) {
|
|
610
|
+
lexical.$setSelection(prevSelection);
|
|
611
|
+
} else {
|
|
612
|
+
selection.dirty = true;
|
|
613
|
+
}
|
|
556
614
|
}
|
|
615
|
+
|
|
616
|
+
function isPointAttached(point) {
|
|
617
|
+
return point.getNode().isAttached();
|
|
618
|
+
}
|
|
619
|
+
|
|
557
620
|
function $isAtNodeEnd(point) {
|
|
558
621
|
if (point.type === 'text') {
|
|
559
622
|
return point.offset === point.getNode().getTextContentSize();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
import type {
|
|
10
|
+
ElementNode,
|
|
11
|
+
GridSelection,
|
|
12
|
+
LexicalNode,
|
|
13
|
+
NodeKey,
|
|
14
|
+
NodeSelection,
|
|
15
|
+
Point,
|
|
16
|
+
RangeSelection,
|
|
17
|
+
} from 'lexical';
|
|
18
|
+
declare export function $cloneContents(
|
|
19
|
+
selection: RangeSelection | NodeSelection | GridSelection,
|
|
20
|
+
): {
|
|
21
|
+
nodeMap: Array<[NodeKey, LexicalNode]>,
|
|
22
|
+
range: Array<NodeKey>,
|
|
23
|
+
};
|
|
24
|
+
declare export function getStyleObjectFromCSS(css: string): {
|
|
25
|
+
[string]: string,
|
|
26
|
+
} | null;
|
|
27
|
+
declare export function $patchStyleText(
|
|
28
|
+
selection: RangeSelection | GridSelection,
|
|
29
|
+
patch: {
|
|
30
|
+
[string]: string,
|
|
31
|
+
},
|
|
32
|
+
): void;
|
|
33
|
+
declare export function $getSelectionStyleValueForProperty(
|
|
34
|
+
selection: RangeSelection,
|
|
35
|
+
styleProperty: string,
|
|
36
|
+
defaultValue: string,
|
|
37
|
+
): string;
|
|
38
|
+
declare export function $moveCaretSelection(
|
|
39
|
+
selection: RangeSelection,
|
|
40
|
+
isHoldingShift: boolean,
|
|
41
|
+
isBackward: boolean,
|
|
42
|
+
granularity: 'character' | 'word' | 'lineboundary',
|
|
43
|
+
): void;
|
|
44
|
+
declare export function $isParentElementRTL(selection: RangeSelection): boolean;
|
|
45
|
+
declare export function $moveCharacter(
|
|
46
|
+
selection: RangeSelection,
|
|
47
|
+
isHoldingShift: boolean,
|
|
48
|
+
isBackward: boolean,
|
|
49
|
+
): void;
|
|
50
|
+
declare export function $selectAll(selection: RangeSelection): void;
|
|
51
|
+
declare export function $wrapLeafNodesInElements(
|
|
52
|
+
selection: RangeSelection,
|
|
53
|
+
createElement: () => ElementNode,
|
|
54
|
+
wrappingElement?: ElementNode,
|
|
55
|
+
): void;
|
|
56
|
+
declare export function $isAtNodeEnd(point: Point): boolean;
|
|
57
|
+
declare export function $shouldOverrideDefaultCharacterSelection(
|
|
58
|
+
selection: RangeSelection,
|
|
59
|
+
isBackward: boolean,
|
|
60
|
+
): boolean;
|
package/LexicalSelection.prod.js
CHANGED
|
@@ -4,18 +4,19 @@
|
|
|
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 k=require("lexical");const
|
|
8
|
-
function w(a,c,b,g,
|
|
9
|
-
e.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}}
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
exports.$
|
|
15
|
-
exports.$
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
var k=require("lexical");const t=new Map;function u(a){a=a.getLatest();const c=a.constructor.clone(a);c.__parent=a.__parent;k.$isElementNode(a)&&k.$isElementNode(c)?(c.__children=Array.from(a.__children),c.__format=a.__format,c.__indent=a.__indent,c.__dir=a.__dir):k.$isTextNode(a)&&k.$isTextNode(c)?(c.__format=a.__format,c.__style=a.__style,c.__mode=a.__mode,c.__detail=a.__detail):k.$isDecoratorNode(a)&&k.$isDecoratorNode(c)&&(c.__state=a.__state);return c}
|
|
8
|
+
function w(a,c,b,g,h){for(var e=c;null!==a;){for(c=a.getParent();null!==c&&c.excludeFromCopy();)c=c.getParent();if(null===c)break;if(!k.$isElementNode(a)||!a.excludeFromCopy()){const d=a.getKey();let f=h.get(d);const l=void 0===f;l&&(f=u(a),h.set(d,f));!k.$isTextNode(f)||f.isSegmented()||f.isToken()?k.$isElementNode(f)&&(f.__children=f.__children.slice(b?e:0,b?void 0:e+1)):f.__text=f.__text.slice(b?e:0,b?void 0:e);if(k.$isRootNode(c)){l&&g.push(d);break}}e=h.get(c.getKey());e=k.$isElementNode(e)?
|
|
9
|
+
e.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}}
|
|
10
|
+
function x(a){if(k.$isRangeSelection(a)){var c=a.anchor,b=a.focus,g=c.getCharacterOffset();const n=b.getCharacterOffset();var h=c.getNode(),e=b.getNode(),d=h.getParentOrThrow();if(h===e&&k.$isTextNode(h)&&(d.canBeEmpty()||1<d.getChildrenSize()))return a=u(h),h=n>g,a.__text=a.__text.slice(h?g:n,h?n:g),g=a.getKey(),{nodeMap:[[g,a]],range:[g]};a=a.getNodes();if(0===a.length)return{nodeMap:[],range:[]};h=a.length;e=a[0];d=e.getParent();if(null!==d&&(!d.canBeEmpty()||k.$isRootNode(d))){var f=d.__children;
|
|
11
|
+
if(f.length===h){var l=!0;for(var m=0;m<f.length;m++)if(f[m]!==a[m].__key){l=!1;break}l&&(h++,a.push(d))}}d=a[h-1];c=c.isBefore(b);b=new Map;f=[];w(e,c?g:n,!0,f,b);for(e=0;e<h;e++)if(l=a[e],m=l.getKey(),!(b.has(m)||k.$isElementNode(l)&&l.excludeFromCopy())){const r=u(l);k.$isRootNode(l.getParent())&&f.push(l.getKey());b.set(m,r)}w(d,c?n:g,!1,f,b);return{nodeMap:Array.from(b.entries()),range:f}}if(k.$isGridSelection(a))return{nodeMap:a.getNodes().map(n=>{const r=n.getKey();n=u(n);return[r,n]}),range:[a.gridKey]};
|
|
12
|
+
throw Error("Minified Lexical error #68; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");}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"===(k.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
|
|
13
|
+
function C(a){for(;null!==a&&!k.$isRootNode(a);){const c=a.getLatest(),b=a.getParent();0===c.__children.length&&a.remove();a=b}}exports.$cloneContents=function(a){return x(a)};
|
|
14
|
+
exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let g=null;const h=a.getNodes();var e=a.anchor,d=a.focus,f=a.isBackward();a=f?d.offset:e.offset;e=f?d.getNode():e.getNode();for(d=0;d<h.length;d++){var l=h[d];if((0===d||0!==a||!l.is(e))&&k.$isTextNode(l)){f=c;var m=b;l=l.getStyle();l=y(l);f=null!==l?l[f]||m:m;if(null===g)g=f;else if(g!==f){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 h=b[0],e=b[g];if(!a.isCollapsed()){var d=a.anchor,f=a.focus;a=h.getTextContent().length;var l=f.offset,m=d.offset;d=(f=d.isBefore(f))?m:l;f=f?l:m;if(d===h.getTextContentSize()){const n=h.getNextSibling();k.$isTextNode(n)&&(d=m=0,h=n)}if(h.is(e))k.$isTextNode(h)&&(d=m>l?l:m,f=m>l?m:l,d!==f&&(0===d&&f===a?(z(h,c),h.select(d,f)):(b=h.splitText(d,f),b=0===d?b[0]:b[1],z(b,c),b.select(0,f-d))));else for(k.$isTextNode(h)&&(0!==
|
|
17
|
+
d&&([,h]=h.splitText(d)),z(h,c)),k.$isTextNode(e)&&(a=e.getTextContent().length,f!==a&&([e]=e.splitText(f)),0!==f&&z(e,c)),a=1;a<g;a++)l=b[a],m=l.getKey(),k.$isTextNode(l)&&m!==h.getKey()&&m!==e.getKey()&&!l.isToken()&&z(l,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 h="element",e="element",d=0;k.$isTextNode(g)?h="text":k.$isElementNode(g)||null===g||(g=g.getParentOrThrow());k.$isTextNode(b)?(e="text",d=b.getTextContentSize()):k.$isElementNode(b)||null===b||(b=b.getParentOrThrow(),d=b.getChildrenSize());g&&b&&(c.set(g.getKey(),0,h),a.set(b.getKey(),d,e))};
|
|
18
19
|
exports.$shouldOverrideDefaultCharacterSelection=function(a,c){a=k.$getDecoratorNode(a.focus,c);return k.$isDecoratorNode(a)&&!a.isIsolated()};
|
|
19
|
-
exports.$wrapLeafNodesInElements=function(a,c,b){const g=a.getNodes(),
|
|
20
|
-
0===n.getChildrenSize()&&
|
|
21
|
-
else if(b)c.insertBefore(b);else for(b=0;b<e.length;b++)c.insertBefore(e[b]);else if(b)d.insertAfter(b);else for(b=e.length-1;0<=b;b--)d.insertAfter(e[b]);a.dirty=!0}};exports.getStyleObjectFromCSS=
|
|
20
|
+
exports.$wrapLeafNodesInElements=function(a,c,b){const g=a.getNodes(),h=g.length;if(0===h){a=a.anchor;a="text"===a.type?a.getNode().getParentOrThrow():a.getNode();var e=a.getChildren();let p=c();e.forEach(v=>p.append(v));b&&(p=b.append(p));a.replace(p)}else{var d=g[0],f=new Map;e=[];d=k.$isElementNode(d)?d:d.getParentOrThrow();for(d.isInline()&&(d=d.getParentOrThrow());null!==d;){var l=d.getPreviousSibling();if(null!==l){d=l;break}d=d.getParentOrThrow();if(k.$isRootNode(d))break}l=new Set;for(var m=
|
|
21
|
+
0;m<h;m++){var n=g[m];k.$isElementNode(n)&&0===n.getChildrenSize()&&l.add(n.getKey())}var r=new Set;for(m=0;m<h;m++){var q=g[m];n=q.getParent();null!==n&&n.isInline()&&(n=n.getParent());if(null!==n&&k.$isLeafNode(q)&&!r.has(q.getKey())){if(q=n.getKey(),void 0===f.get(q)){const p=c();e.push(p);f.set(q,p);n.getChildren().forEach(v=>{p.append(v);r.add(v.getKey())});C(n)}}else l.has(q.getKey())&&(e.push(c()),q.remove())}if(b)for(c=0;c<e.length;c++)b.append(e[c]);if(k.$isRootNode(d))if(c=d.getFirstChild(),
|
|
22
|
+
k.$isElementNode(c)&&(d=c),null===c)if(b)d.append(b);else for(b=0;b<e.length;b++)d.append(e[b]);else if(b)c.insertBefore(b);else for(b=0;b<e.length;b++)c.insertBefore(e[b]);else if(b)d.insertAfter(b);else for(b=e.length-1;0<=b;b--)d.insertAfter(e[b]);b=k.$getPreviousSelection();k.$isRangeSelection(b)&&b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()?k.$setSelection(b):a.dirty=!0}};exports.getStyleObjectFromCSS=y;
|
package/package.json
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexical/selection",
|
|
3
|
-
"author": {
|
|
4
|
-
"name": "Dominic Gannaway",
|
|
5
|
-
"email": "dg@domgan.com"
|
|
6
|
-
},
|
|
7
3
|
"description": "This package contains utilities and helpers for handling Lexical selection.",
|
|
8
4
|
"keywords": [
|
|
9
5
|
"lexical",
|
|
@@ -13,10 +9,10 @@
|
|
|
13
9
|
"selection"
|
|
14
10
|
],
|
|
15
11
|
"license": "MIT",
|
|
16
|
-
"version": "0.1.
|
|
12
|
+
"version": "0.1.19",
|
|
17
13
|
"main": "LexicalSelection.js",
|
|
18
14
|
"peerDependencies": {
|
|
19
|
-
"lexical": "0.1.
|
|
15
|
+
"lexical": "0.1.19"
|
|
20
16
|
},
|
|
21
17
|
"repository": {
|
|
22
18
|
"type": "git",
|