@react-fabric/lexical 1.0.0-beta.5 → 1.0.0-beta.52
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/{src/editor/Lexical.module.css → css/_lexical.css} +4 -4
- package/css/styles.css +24 -0
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +9 -9
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +142 -75
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +25 -21
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +10 -3
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +147 -103
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +254 -178
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +19 -16
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +53 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +176 -194
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +1 -1
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +25 -18
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +1925 -793
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +48 -40
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +426 -144
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +11 -1
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +46 -32
- package/dist/cjs/node_modules/prismjs/prism.js +1 -1
- package/dist/cjs/packages/lexical/src/components/StickyComponent.js +1 -1
- package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +29 -5
- package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +81 -76
- package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +4 -6
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +139 -76
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +11 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +149 -105
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +253 -180
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -30
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +171 -196
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +1 -1
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +1920 -796
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +413 -145
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +7 -2
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
- package/dist/esm/node_modules/prismjs/prism.js +1 -1
- package/dist/esm/packages/lexical/src/components/StickyComponent.js +1 -1
- package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +29 -5
- package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +82 -77
- package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +4 -6
- package/dist/types/editor/LexicalEditor.d.ts +25 -0
- package/dist/types/hooks/useFormatWatcher.d.ts +2 -2
- package/dist/types/nodes/StickyNode.d.ts +0 -1
- package/package.json +13 -12
- package/src/components/StickyComponent.tsx +2 -2
- package/src/editor/LexicalEditor.tsx +53 -25
- package/src/hooks/useFormatWatcher.ts +28 -27
- package/src/plugins/ToolbarPlugin.tsx +22 -6
- package/dist/cjs/editor/Lexical.module.css +0 -1
- package/dist/esm/editor/Lexical.module.css +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $isTokenOrSegmented, $
|
|
4
|
-
export { $cloneWithProperties } from 'lexical';
|
|
3
|
+
import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $getSelection, $caretRangeFromSelection, $isTokenOrSegmented, $createRangeSelection, INTERNAL_$isBlock, $setSelection, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isChildCaret, $isDecoratorNode } from 'lexical';
|
|
4
|
+
export { $cloneWithProperties, $selectAll } from 'lexical';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -12,6 +12,20 @@ export { $cloneWithProperties } from 'lexical';
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
17
|
+
*
|
|
18
|
+
* This source code is licensed under the MIT license found in the
|
|
19
|
+
* LICENSE file in the root directory of this source tree.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
24
|
+
|
|
25
|
+
function formatDevErrorMessage(message) {
|
|
26
|
+
throw new Error(message);
|
|
27
|
+
}
|
|
28
|
+
|
|
15
29
|
/**
|
|
16
30
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
17
31
|
*
|
|
@@ -147,6 +161,9 @@ function createRectsFromDOMRange(editor, range) {
|
|
|
147
161
|
*/
|
|
148
162
|
function getStyleObjectFromRawCSS(css) {
|
|
149
163
|
const styleObject = {};
|
|
164
|
+
if (!css) {
|
|
165
|
+
return styleObject;
|
|
166
|
+
}
|
|
150
167
|
const styles = css.split(';');
|
|
151
168
|
for (const style of styles) {
|
|
152
169
|
if (style !== '') {
|
|
@@ -192,14 +209,6 @@ function getCSSFromStyleObject(styles) {
|
|
|
192
209
|
return css;
|
|
193
210
|
}
|
|
194
211
|
|
|
195
|
-
/**
|
|
196
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
197
|
-
*
|
|
198
|
-
* This source code is licensed under the MIT license found in the
|
|
199
|
-
* LICENSE file in the root directory of this source tree.
|
|
200
|
-
*
|
|
201
|
-
*/
|
|
202
|
-
|
|
203
212
|
/**
|
|
204
213
|
* Generally used to append text content to HTML and JSON. Grabs the text content and "slices"
|
|
205
214
|
* it to be generated into the new TextNode.
|
|
@@ -253,7 +262,7 @@ function $isAtNodeEnd(point) {
|
|
|
253
262
|
}
|
|
254
263
|
const node = point.getNode();
|
|
255
264
|
if (!$isElementNode(node)) {
|
|
256
|
-
|
|
265
|
+
formatDevErrorMessage(`isAtNodeEnd: node must be a TextNode or ElementNode`);
|
|
257
266
|
}
|
|
258
267
|
return point.offset === node.getChildrenSize();
|
|
259
268
|
}
|
|
@@ -379,8 +388,19 @@ function $addNodeStyle(node) {
|
|
|
379
388
|
const styles = getStyleObjectFromRawCSS(CSSText);
|
|
380
389
|
CSS_TO_STYLES.set(CSSText, styles);
|
|
381
390
|
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Applies the provided styles to the given TextNode, ElementNode, or
|
|
394
|
+
* collapsed RangeSelection.
|
|
395
|
+
*
|
|
396
|
+
* @param target - The TextNode, ElementNode, or collapsed RangeSelection to apply the styles to
|
|
397
|
+
* @param patch - The patch to apply, which can include multiple styles. \\{CSSProperty: value\\} . Can also accept a function that returns the new property value.
|
|
398
|
+
*/
|
|
382
399
|
function $patchStyle(target, patch) {
|
|
383
|
-
|
|
400
|
+
if (!($isRangeSelection(target) ? target.isCollapsed() : $isTextNode(target) || $isElementNode(target))) {
|
|
401
|
+
formatDevErrorMessage(`$patchStyle must only be called with a TextNode, ElementNode, or collapsed RangeSelection`);
|
|
402
|
+
}
|
|
403
|
+
const prevStyles = getStyleObjectFromCSS($isRangeSelection(target) ? target.style : $isTextNode(target) ? target.getStyle() : target.getTextStyle());
|
|
384
404
|
const newStyles = Object.entries(patch).reduce((styles, [key, value]) => {
|
|
385
405
|
if (typeof value === 'function') {
|
|
386
406
|
styles[key] = value(prevStyles[key], target);
|
|
@@ -392,9 +412,13 @@ function $patchStyle(target, patch) {
|
|
|
392
412
|
return styles;
|
|
393
413
|
}, {
|
|
394
414
|
...prevStyles
|
|
395
|
-
}
|
|
415
|
+
});
|
|
396
416
|
const newCSSText = getCSSFromStyleObject(newStyles);
|
|
397
|
-
target
|
|
417
|
+
if ($isRangeSelection(target) || $isTextNode(target)) {
|
|
418
|
+
target.setStyle(newCSSText);
|
|
419
|
+
} else {
|
|
420
|
+
target.setTextStyle(newCSSText);
|
|
421
|
+
}
|
|
398
422
|
CSS_TO_STYLES.set(newCSSText, newStyles);
|
|
399
423
|
}
|
|
400
424
|
|
|
@@ -406,161 +430,147 @@ function $patchStyle(target, patch) {
|
|
|
406
430
|
* @param patch - The patch to apply, which can include multiple styles. \\{CSSProperty: value\\} . Can also accept a function that returns the new property value.
|
|
407
431
|
*/
|
|
408
432
|
function $patchStyleText(selection, patch) {
|
|
409
|
-
|
|
410
|
-
const selectedNodesLength = selectedNodes.length;
|
|
411
|
-
const anchorAndFocus = selection.getStartEndPoints();
|
|
412
|
-
if (anchorAndFocus === null) {
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
const [anchor, focus] = anchorAndFocus;
|
|
416
|
-
const lastIndex = selectedNodesLength - 1;
|
|
417
|
-
let firstNode = selectedNodes[0];
|
|
418
|
-
let lastNode = selectedNodes[lastIndex];
|
|
419
|
-
if (selection.isCollapsed() && $isRangeSelection(selection)) {
|
|
433
|
+
if ($isRangeSelection(selection) && selection.isCollapsed()) {
|
|
420
434
|
$patchStyle(selection, patch);
|
|
435
|
+
const emptyNode = selection.anchor.getNode();
|
|
436
|
+
if ($isElementNode(emptyNode) && emptyNode.isEmpty()) {
|
|
437
|
+
$patchStyle(emptyNode, patch);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
$forEachSelectedTextNode(textNode => {
|
|
441
|
+
$patchStyle(textNode, patch);
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
function $forEachSelectedTextNode(fn) {
|
|
445
|
+
const selection = $getSelection();
|
|
446
|
+
if (!selection) {
|
|
421
447
|
return;
|
|
422
448
|
}
|
|
423
|
-
const
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
let endOffset = isBefore ? focusOffset : anchorOffset;
|
|
430
|
-
const startType = isBefore ? anchor.type : focus.type;
|
|
431
|
-
const endType = isBefore ? focus.type : anchor.type;
|
|
432
|
-
const endKey = isBefore ? focus.key : anchor.key;
|
|
433
|
-
|
|
434
|
-
// This is the case where the user only selected the very end of the
|
|
435
|
-
// first node so we don't want to include it in the formatting change.
|
|
436
|
-
if ($isTextNode(firstNode) && startOffset === firstNodeTextLength) {
|
|
437
|
-
const nextSibling = firstNode.getNextSibling();
|
|
438
|
-
if ($isTextNode(nextSibling)) {
|
|
439
|
-
// we basically make the second node the firstNode, changing offsets accordingly
|
|
440
|
-
anchorOffset = 0;
|
|
441
|
-
startOffset = 0;
|
|
442
|
-
firstNode = nextSibling;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// This is the case where we only selected a single node
|
|
447
|
-
if (selectedNodes.length === 1) {
|
|
448
|
-
if ($isTextNode(firstNode) && firstNode.canHaveFormat()) {
|
|
449
|
-
startOffset = startType === 'element' ? 0 : anchorOffset > focusOffset ? focusOffset : anchorOffset;
|
|
450
|
-
endOffset = endType === 'element' ? firstNodeTextLength : anchorOffset > focusOffset ? anchorOffset : focusOffset;
|
|
451
|
-
|
|
452
|
-
// No actual text is selected, so do nothing.
|
|
453
|
-
if (startOffset === endOffset) {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
// The entire node is selected or a token/segment, so just format it
|
|
458
|
-
if ($isTokenOrSegmented(firstNode) || startOffset === 0 && endOffset === firstNodeTextLength) {
|
|
459
|
-
$patchStyle(firstNode, patch);
|
|
460
|
-
firstNode.select(startOffset, endOffset);
|
|
461
|
-
} else {
|
|
462
|
-
// The node is partially selected, so split it into two nodes
|
|
463
|
-
// and style the selected one.
|
|
464
|
-
const splitNodes = firstNode.splitText(startOffset, endOffset);
|
|
465
|
-
const replacement = startOffset === 0 ? splitNodes[0] : splitNodes[1];
|
|
466
|
-
$patchStyle(replacement, patch);
|
|
467
|
-
replacement.select(0, endOffset - startOffset);
|
|
468
|
-
}
|
|
469
|
-
} // multiple nodes selected.
|
|
470
|
-
} else {
|
|
471
|
-
if ($isTextNode(firstNode) && startOffset < firstNode.getTextContentSize() && firstNode.canHaveFormat()) {
|
|
472
|
-
if (startOffset !== 0 && !$isTokenOrSegmented(firstNode)) {
|
|
473
|
-
// the entire first node isn't selected and it isn't a token or segmented, so split it
|
|
474
|
-
firstNode = firstNode.splitText(startOffset)[1];
|
|
475
|
-
startOffset = 0;
|
|
476
|
-
if (isBefore) {
|
|
477
|
-
anchor.set(firstNode.getKey(), startOffset, 'text');
|
|
478
|
-
} else {
|
|
479
|
-
focus.set(firstNode.getKey(), startOffset, 'text');
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
$patchStyle(firstNode, patch);
|
|
483
|
-
}
|
|
484
|
-
if ($isTextNode(lastNode) && lastNode.canHaveFormat()) {
|
|
485
|
-
const lastNodeText = lastNode.getTextContent();
|
|
486
|
-
const lastNodeTextLength = lastNodeText.length;
|
|
487
|
-
|
|
488
|
-
// The last node might not actually be the end node
|
|
489
|
-
//
|
|
490
|
-
// If not, assume the last node is fully-selected unless the end offset is
|
|
491
|
-
// zero.
|
|
492
|
-
if (lastNode.__key !== endKey && endOffset !== 0) {
|
|
493
|
-
endOffset = lastNodeTextLength;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// if the entire last node isn't selected and it isn't a token or segmented, split it
|
|
497
|
-
if (endOffset !== lastNodeTextLength && !$isTokenOrSegmented(lastNode)) {
|
|
498
|
-
[lastNode] = lastNode.splitText(endOffset);
|
|
499
|
-
}
|
|
500
|
-
if (endOffset !== 0 || endType === 'element') {
|
|
501
|
-
$patchStyle(lastNode, patch);
|
|
449
|
+
const slicedTextNodes = new Map();
|
|
450
|
+
const getSliceIndices = node => slicedTextNodes.get(node.getKey()) || [0, node.getTextContentSize()];
|
|
451
|
+
if ($isRangeSelection(selection)) {
|
|
452
|
+
for (const slice of $caretRangeFromSelection(selection).getTextSlices()) {
|
|
453
|
+
if (slice) {
|
|
454
|
+
slicedTextNodes.set(slice.caret.origin.getKey(), slice.getSliceIndices());
|
|
502
455
|
}
|
|
503
456
|
}
|
|
457
|
+
}
|
|
458
|
+
const selectedNodes = selection.getNodes();
|
|
459
|
+
for (const selectedNode of selectedNodes) {
|
|
460
|
+
if (!($isTextNode(selectedNode) && selectedNode.canHaveFormat())) {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
const [startOffset, endOffset] = getSliceIndices(selectedNode);
|
|
464
|
+
// No actual text is selected, so do nothing.
|
|
465
|
+
if (endOffset === startOffset) {
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
504
468
|
|
|
505
|
-
//
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
469
|
+
// The entire node is selected or a token/segment, so just format it
|
|
470
|
+
if ($isTokenOrSegmented(selectedNode) || startOffset === 0 && endOffset === selectedNode.getTextContentSize()) {
|
|
471
|
+
fn(selectedNode);
|
|
472
|
+
} else {
|
|
473
|
+
// The node is partially selected, so split it into two or three nodes
|
|
474
|
+
// and style the selected one.
|
|
475
|
+
const splitNodes = selectedNode.splitText(startOffset, endOffset);
|
|
476
|
+
const replacement = splitNodes[startOffset === 0 ? 0 : 1];
|
|
477
|
+
fn(replacement);
|
|
512
478
|
}
|
|
513
479
|
}
|
|
480
|
+
// Prior to NodeCaret #7046 this would have been a side-effect
|
|
481
|
+
// so we do this for test compatibility.
|
|
482
|
+
// TODO: we may want to consider simplifying by removing this
|
|
483
|
+
if ($isRangeSelection(selection) && selection.anchor.type === 'text' && selection.focus.type === 'text' && selection.anchor.key === selection.focus.key) {
|
|
484
|
+
$ensureForwardRangeSelection(selection);
|
|
485
|
+
}
|
|
514
486
|
}
|
|
515
487
|
|
|
516
488
|
/**
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
489
|
+
* Ensure that the given RangeSelection is not backwards. If it
|
|
490
|
+
* is backwards, then the anchor and focus points will be swapped
|
|
491
|
+
* in-place. Ensuring that the selection is a writable RangeSelection
|
|
492
|
+
* is the responsibility of the caller (e.g. in a read-only context
|
|
493
|
+
* you will want to clone $getSelection() before using this).
|
|
521
494
|
*
|
|
495
|
+
* @param selection a writable RangeSelection
|
|
522
496
|
*/
|
|
497
|
+
function $ensureForwardRangeSelection(selection) {
|
|
498
|
+
if (selection.isBackward()) {
|
|
499
|
+
const {
|
|
500
|
+
anchor,
|
|
501
|
+
focus
|
|
502
|
+
} = selection;
|
|
503
|
+
// stash for the in-place swap
|
|
504
|
+
const {
|
|
505
|
+
key,
|
|
506
|
+
offset,
|
|
507
|
+
type
|
|
508
|
+
} = anchor;
|
|
509
|
+
anchor.set(focus.key, focus.offset, focus.type);
|
|
510
|
+
focus.set(key, offset, type);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
523
513
|
|
|
514
|
+
function $copyBlockFormatIndent(srcNode, destNode) {
|
|
515
|
+
const format = srcNode.getFormatType();
|
|
516
|
+
const indent = srcNode.getIndent();
|
|
517
|
+
if (format !== destNode.getFormatType()) {
|
|
518
|
+
destNode.setFormat(format);
|
|
519
|
+
}
|
|
520
|
+
if (indent !== destNode.getIndent()) {
|
|
521
|
+
destNode.setIndent(indent);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
524
|
|
|
525
525
|
/**
|
|
526
526
|
* Converts all nodes in the selection that are of one block type to another.
|
|
527
527
|
* @param selection - The selected blocks to be converted.
|
|
528
|
-
* @param createElement - The function that creates the node. eg. $createParagraphNode.
|
|
528
|
+
* @param $createElement - The function that creates the node. eg. $createParagraphNode.
|
|
529
|
+
* @param $afterCreateElement - The function that updates the new node based on the previous one ($copyBlockFormatIndent by default)
|
|
529
530
|
*/
|
|
530
|
-
function $setBlocksType(selection, createElement) {
|
|
531
|
+
function $setBlocksType(selection, $createElement, $afterCreateElement = $copyBlockFormatIndent) {
|
|
531
532
|
if (selection === null) {
|
|
532
533
|
return;
|
|
533
534
|
}
|
|
535
|
+
// Selections tend to not include their containing blocks so we effectively
|
|
536
|
+
// expand it here
|
|
534
537
|
const anchorAndFocus = selection.getStartEndPoints();
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
538
|
+
const blockMap = new Map();
|
|
539
|
+
let newSelection = null;
|
|
540
|
+
if (anchorAndFocus) {
|
|
541
|
+
const [anchor, focus] = anchorAndFocus;
|
|
542
|
+
newSelection = $createRangeSelection();
|
|
543
|
+
newSelection.anchor.set(anchor.key, anchor.offset, anchor.type);
|
|
544
|
+
newSelection.focus.set(focus.key, focus.offset, focus.type);
|
|
545
|
+
const anchorBlock = $getAncestor(anchor.getNode(), INTERNAL_$isBlock);
|
|
546
|
+
const focusBlock = $getAncestor(focus.getNode(), INTERNAL_$isBlock);
|
|
547
|
+
if ($isElementNode(anchorBlock)) {
|
|
548
|
+
blockMap.set(anchorBlock.getKey(), anchorBlock);
|
|
549
|
+
}
|
|
550
|
+
if ($isElementNode(focusBlock)) {
|
|
551
|
+
blockMap.set(focusBlock.getKey(), focusBlock);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
for (const node of selection.getNodes()) {
|
|
555
|
+
if ($isElementNode(node) && INTERNAL_$isBlock(node)) {
|
|
556
|
+
blockMap.set(node.getKey(), node);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
for (const [key, prevNode] of blockMap) {
|
|
560
|
+
const element = $createElement();
|
|
561
|
+
$afterCreateElement(prevNode, element);
|
|
562
|
+
prevNode.replace(element, true);
|
|
563
|
+
if (newSelection) {
|
|
564
|
+
if (key === newSelection.anchor.key) {
|
|
565
|
+
newSelection.anchor.set(element.getKey(), newSelection.anchor.offset, newSelection.anchor.type);
|
|
566
|
+
}
|
|
567
|
+
if (key === newSelection.focus.key) {
|
|
568
|
+
newSelection.focus.set(element.getKey(), newSelection.focus.offset, newSelection.focus.type);
|
|
569
|
+
}
|
|
544
570
|
}
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
const nodes = selection.getNodes();
|
|
548
|
-
const firstSelectedBlock = anchor !== null ? $getAncestor(anchor.getNode(), INTERNAL_$isBlock) : false;
|
|
549
|
-
if (firstSelectedBlock && nodes.indexOf(firstSelectedBlock) === -1) {
|
|
550
|
-
nodes.push(firstSelectedBlock);
|
|
551
571
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
if (!INTERNAL_$isBlock(node)) {
|
|
555
|
-
continue;
|
|
556
|
-
}
|
|
557
|
-
if (!$isElementNode(node)) {
|
|
558
|
-
throw Error(`Expected block node to be an ElementNode`);
|
|
559
|
-
}
|
|
560
|
-
const targetElement = createElement();
|
|
561
|
-
targetElement.setFormat(node.getFormatType());
|
|
562
|
-
targetElement.setIndent(node.getIndent());
|
|
563
|
-
node.replace(targetElement, true);
|
|
572
|
+
if (newSelection && selection.is($getSelection())) {
|
|
573
|
+
$setSelection(newSelection);
|
|
564
574
|
}
|
|
565
575
|
}
|
|
566
576
|
function isPointAttached(point) {
|
|
@@ -704,7 +714,7 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
|
|
|
704
714
|
}
|
|
705
715
|
} else if (emptyElements.has(node.getKey())) {
|
|
706
716
|
if (!$isElementNode(node)) {
|
|
707
|
-
|
|
717
|
+
formatDevErrorMessage(`Expected node in emptyElements to be an ElementNode`);
|
|
708
718
|
}
|
|
709
719
|
const targetElement = createElement();
|
|
710
720
|
targetElement.setFormat(node.getFormatType());
|
|
@@ -788,8 +798,21 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
|
|
|
788
798
|
* @returns true if it should be overridden, false if not.
|
|
789
799
|
*/
|
|
790
800
|
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
791
|
-
const
|
|
792
|
-
|
|
801
|
+
const focusCaret = $caretFromPoint(selection.focus, isBackward ? 'previous' : 'next');
|
|
802
|
+
if ($isExtendableTextPointCaret(focusCaret)) {
|
|
803
|
+
return false;
|
|
804
|
+
}
|
|
805
|
+
for (const nextCaret of $extendCaretToRange(focusCaret)) {
|
|
806
|
+
if ($isChildCaret(nextCaret)) {
|
|
807
|
+
return !nextCaret.origin.isInline();
|
|
808
|
+
} else if ($isElementNode(nextCaret.origin)) {
|
|
809
|
+
continue;
|
|
810
|
+
} else if ($isDecoratorNode(nextCaret.origin)) {
|
|
811
|
+
return true;
|
|
812
|
+
}
|
|
813
|
+
break;
|
|
814
|
+
}
|
|
815
|
+
return false;
|
|
793
816
|
}
|
|
794
817
|
|
|
795
818
|
/**
|
|
@@ -825,38 +848,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
825
848
|
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
826
849
|
}
|
|
827
850
|
|
|
828
|
-
/**
|
|
829
|
-
* Expands the current Selection to cover all of the content in the editor.
|
|
830
|
-
* @param selection - The current selection.
|
|
831
|
-
*/
|
|
832
|
-
function $selectAll(selection) {
|
|
833
|
-
const anchor = selection.anchor;
|
|
834
|
-
const focus = selection.focus;
|
|
835
|
-
const anchorNode = anchor.getNode();
|
|
836
|
-
const topParent = anchorNode.getTopLevelElementOrThrow();
|
|
837
|
-
const root = topParent.getParentOrThrow();
|
|
838
|
-
let firstNode = root.getFirstDescendant();
|
|
839
|
-
let lastNode = root.getLastDescendant();
|
|
840
|
-
let firstType = 'element';
|
|
841
|
-
let lastType = 'element';
|
|
842
|
-
let lastOffset = 0;
|
|
843
|
-
if ($isTextNode(firstNode)) {
|
|
844
|
-
firstType = 'text';
|
|
845
|
-
} else if (!$isElementNode(firstNode) && firstNode !== null) {
|
|
846
|
-
firstNode = firstNode.getParentOrThrow();
|
|
847
|
-
}
|
|
848
|
-
if ($isTextNode(lastNode)) {
|
|
849
|
-
lastType = 'text';
|
|
850
|
-
lastOffset = lastNode.getTextContentSize();
|
|
851
|
-
} else if (!$isElementNode(lastNode) && lastNode !== null) {
|
|
852
|
-
lastNode = lastNode.getParentOrThrow();
|
|
853
|
-
}
|
|
854
|
-
if (firstNode && lastNode) {
|
|
855
|
-
anchor.set(firstNode.getKey(), 0, firstType);
|
|
856
|
-
focus.set(lastNode.getKey(), lastOffset, lastType);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
|
|
860
851
|
/**
|
|
861
852
|
* Returns the current value of a CSS property for Nodes, if set. If not set, it returns the defaultValue.
|
|
862
853
|
* @param node - The node whose style value to get.
|
|
@@ -919,22 +910,6 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
|
|
|
919
910
|
}
|
|
920
911
|
return styleValue === null ? defaultValue : styleValue;
|
|
921
912
|
}
|
|
922
|
-
|
|
923
|
-
/**
|
|
924
|
-
* This function is for internal use of the library.
|
|
925
|
-
* Please do not use it as it may change in the future.
|
|
926
|
-
*/
|
|
927
|
-
function INTERNAL_$isBlock(node) {
|
|
928
|
-
if ($isDecoratorNode(node)) {
|
|
929
|
-
return false;
|
|
930
|
-
}
|
|
931
|
-
if (!$isElementNode(node) || $isRootOrShadowRoot(node)) {
|
|
932
|
-
return false;
|
|
933
|
-
}
|
|
934
|
-
const firstChild = node.getFirstChild();
|
|
935
|
-
const isLeafElement = firstChild === null || $isLineBreakNode(firstChild) || $isTextNode(firstChild) || firstChild.isInline();
|
|
936
|
-
return !node.isInline() && node.canBeEmpty() !== false && isLeafElement;
|
|
937
|
-
}
|
|
938
913
|
function $getAncestor(node, predicate) {
|
|
939
914
|
let parent = node;
|
|
940
915
|
while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
|
|
@@ -954,4 +929,4 @@ function $getAncestor(node, predicate) {
|
|
|
954
929
|
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
955
930
|
const trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
956
931
|
|
|
957
|
-
export { $addNodeStyle, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $patchStyleText, $
|
|
932
|
+
export { $addNodeStyle, $copyBlockFormatIndent, $ensureForwardRangeSelection, $forEachSelectedTextNode, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $patchStyleText, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, $wrapNodes, createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, getStyleObjectFromCSS, trimTextContentFromAnchor };
|
|
@@ -11,7 +11,7 @@ import * as LexicalSelection_prod from './LexicalSelection.prod.js';
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const mod = process.env.NODE_ENV
|
|
14
|
+
const mod = process.env.NODE_ENV !== 'production' ? LexicalSelection_dev : LexicalSelection_prod;
|
|
15
15
|
const $addNodeStyle = mod.$addNodeStyle;
|
|
16
16
|
const $getSelectionStyleValueForProperty = mod.$getSelectionStyleValueForProperty;
|
|
17
17
|
const $isAtNodeEnd = mod.$isAtNodeEnd;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $isTokenOrSegmented, $
|
|
4
|
-
export { $cloneWithProperties } from 'lexical';
|
|
3
|
+
import { $isTextNode, $getCharacterOffsets, $isElementNode, $isRootNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $getSelection, $caretRangeFromSelection, $isTokenOrSegmented, $createRangeSelection, INTERNAL_$isBlock, $setSelection, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isChildCaret, $isDecoratorNode } from 'lexical';
|
|
4
|
+
export { $cloneWithProperties, $selectAll } from 'lexical';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -11,6 +11,6 @@ export { $cloneWithProperties } from 'lexical';
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
function
|
|
14
|
+
function N(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const w=new Map;function C(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild;}return null}function P(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return [t,Array.from(t.childNodes).indexOf(e)]}function k(t,n,o,l,r){const s=n.getKey(),i=l.getKey(),c=document.createRange();let f=t.getElementByKey(s),u=t.getElementByKey(i),g=o,a=r;if($isTextNode(n)&&(f=C(f)),$isTextNode(l)&&(u=C(u)),void 0===n||void 0===l||null===f||null===u)return null;"BR"===f.nodeName&&([f,g]=P(f)),"BR"===u.nodeName&&([u,a]=P(u));const d=f.firstChild;f===u&&null!=d&&"BR"===d.nodeName&&0===g&&0===a&&(a=1);try{c.setStart(f,g),c.setEnd(u,a);}catch(e){return null}return !c.collapsed||g===a&&s===i||(c.setStart(u,a),c.setEnd(f,g)),c}function E(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 K(e){const t={};if(!e)return t;const 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 I(e){let t=w.get(e);return void 0===t&&(t=K(e),w.set(e,t)),t}function F(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function B(e,n){const o=e.getStartEndPoints();if(n.isSelected(e)&&!n.isSegmented()&&!n.isToken()&&null!==o){const[l,r]=o,s=e.isBackward(),i=l.getNode(),c=r.getNode(),f=n.is(i),u=n.is(c);if(f||u){const[o,l]=$getCharacterOffsets(e),r=i.is(c),f=n.is(s?c:i),u=n.is(s?i:c);let g,a=0;if(r)a=o>l?l:o,g=o>l?o:l;else if(f){a=s?l:o,g=void 0;}else if(u){a=0,g=s?o:l;}return n.__text=n.__text.slice(a,g),n}}return n}function b(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return $isElementNode(t)||N(177),e.offset===t.getChildrenSize()}function O(t,c,f){let u=c.getNode(),g=f;if($isElementNode(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e);}for(;g>0&&null!==u;){if($isElementNode(u)){const e=u.getLastDescendant();null!==e&&(u=e);}let f=u.getPreviousSibling(),a=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&&(a=e.isInline()?0:2,f=t);}let d=u.getTextContent();""===d&&$isElementNode(u)&&!u.isInline()&&(d="\n\n");const p=d.length;if(!$isTextNode(u)||g>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||$isRootNode(e)||e.remove(),g-=p+a,u=f;}else {const n=u.getKey(),o=t.getEditorState().read((()=>{const t=$getNodeByKey(n);return $isTextNode(t)&&t.isSimpleText()?t.getTextContent():null})),f=p-g,a=d.slice(0,f);if(null!==o&&o!==d){const e=$getPreviousSelection();let t=u;if(u.isSimpleText())u.setTextContent(o);else {const e=$createTextNode(o);u.replace(e),t=e;}if($isRangeSelection(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n);}}else if(u.isSimpleText()){const e=c.key===n;let t=c.offset;t<g&&(t=p);const o=e?t-g:0,l=e?t:f;if(e&&0===o){const[e]=u.splitText(o,l);e.remove();}else {const[,e]=u.splitText(o,l);e.remove();}}else {const e=$createTextNode(a);u.replace(e);}g=0;}}}function R(e){const t=e.getStyle(),n=K(t);w.set(t,n);}function z(t,o){($isRangeSelection(t)?t.isCollapsed():$isTextNode(t)||$isElementNode(t))||N(280);const l=I($isRangeSelection(t)?t.style:$isTextNode(t)?t.getStyle():t.getTextStyle()),r=Object.entries(o).reduce(((e,[n,o])=>("function"==typeof o?e[n]=o(l[n],t):null===o?delete e[n]:e[n]=o,e)),{...l}),s=F(r);$isRangeSelection(t)||$isTextNode(t)?t.setStyle(s):t.setTextStyle(s),w.set(s,r);}function A(e,t){if($isRangeSelection(e)&&e.isCollapsed()){z(e,t);const o=e.anchor.getNode();$isElementNode(o)&&o.isEmpty()&&z(o,t);}L((e=>{z(e,t);}));}function L(t){const n=$getSelection();if(!n)return;const o=new Map;if($isRangeSelection(n))for(const e of $caretRangeFromSelection(n).getTextSlices())e&&o.set(e.caret.origin.getKey(),e.getSliceIndices());const l=n.getNodes();for(const n of l){if(!$isTextNode(n)||!n.canHaveFormat())continue;const[l,s]=(r=n,o.get(r.getKey())||[0,r.getTextContentSize()]);if(s!==l)if($isTokenOrSegmented(n)||0===l&&s===n.getTextContentSize())t(n);else {t(n.splitText(l,s)[0===l?0:1]);}}var r;$isRangeSelection(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&M(n);}function M(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:o,offset:l,type:r}=t;t.set(n.key,n.offset,n.type),n.set(o,l,r);}}function $(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o);}function _(e,t,o=$){if(null===e)return;const l=e.getStartEndPoints(),r=new Map;let s=null;if(l){const[e,t]=l;s=$createRangeSelection(),s.anchor.set(e.key,e.offset,e.type),s.focus.set(t.key,t.offset,t.type);const o=V(e.getNode(),INTERNAL_$isBlock),i=V(t.getNode(),INTERNAL_$isBlock);$isElementNode(o)&&r.set(o.getKey(),o),$isElementNode(i)&&r.set(i.getKey(),i);}for(const t of e.getNodes())$isElementNode(t)&&INTERNAL_$isBlock(t)&&r.set(t.getKey(),t);for(const[e,n]of r){const l=t();o(n,l),n.replace(l,!0),s&&(e===s.anchor.key&&s.anchor.set(l.getKey(),s.anchor.offset,s.anchor.type),e===s.focus.key&&s.focus.set(l.getKey(),s.focus.offset,s.focus.type));}s&&e.is($getSelection())&&$setSelection(s);}function D(e){return e.getNode().isAttached()}function U(e){let t=e;for(;null!==t&&!$isRootOrShadowRoot(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n;}}function j(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];$isRootOrShadowRoot(l)?(H(e,c,c.length,t,n),c=[],i=l):null===i||null!==i&&$hasAncestor(l,i)?c.push(l):(H(e,c,c.length,t,n),c=[l]);}H(e,c,c.length,t,n);}function H(e,t,o,l,s=null){if(0===t.length)return;const c=t[0],f=new Map,u=[];let g=$isElementNode(c)?c:c.getParentOrThrow();g.isInline()&&(g=g.getParentOrThrow());let a=!1;for(;null!==g;){const e=g.getPreviousSibling();if(null!==e){g=e,a=!0;break}if(g=g.getParentOrThrow(),$isRootOrShadowRoot(g))break}const h=new Set;for(let e=0;e<o;e++){const o=t[e];$isElementNode(o)&&0===o.getChildrenSize()&&h.add(o.getKey());}const m=new Set;for(let e=0;e<o;e++){const o=t[e];let r=o.getParent();if(null!==r&&r.isInline()&&(r=r.getParent()),null!==r&&$isLeafNode(o)&&!m.has(o.getKey())){const e=r.getKey();if(void 0===f.get(e)){const t=l();t.setFormat(r.getFormatType()),t.setIndent(r.getIndent()),u.push(t),f.set(e,t),r.getChildren().forEach((e=>{t.append(e),m.add(e.getKey()),$isElementNode(e)&&e.getChildrenKeys().forEach((e=>m.add(e)));})),U(r);}}else if(h.has(o.getKey())){$isElementNode(o)||N(179);const e=l();e.setFormat(o.getFormatType()),e.setIndent(o.getIndent()),u.push(e),o.remove(!0);}}if(null!==s)for(let e=0;e<u.length;e++){const t=u[e];s.append(t);}let S=null;if($isRootOrShadowRoot(g))if(a)if(null!==s)g.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];g.insertAfter(t);}else {const e=g.getFirstChild();if($isElementNode(e)&&(g=e),null===e)if(s)g.append(s);else for(let e=0;e<u.length;e++){const t=u[e];g.append(t),S=t;}else if(null!==s)e.insertBefore(s);else for(let t=0;t<u.length;t++){const n=u[t];e.insertBefore(n),S=n;}}else if(s)g.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];g.insertAfter(t),S=t;}const x=$getPreviousSelection();$isRangeSelection(x)&&D(x.anchor)&&D(x.focus)?$setSelection(x.clone()):null!==S?S.selectEnd():e.dirty=!0;}function W(e,t){const o=$caretFromPoint(e.focus,t?"previous":"next");if($isExtendableTextPointCaret(o))return !1;for(const e of $extendCaretToRange(o)){if($isChildCaret(e))return !e.origin.isInline();if(!$isElementNode(e.origin)){if($isDecoratorNode(e.origin))return !0;break}}return !1}function X(e,t,n,o){e.modify(t?"extend":"move",n,o);}function q(e){const t=e.anchor.getNode();return "rtl"===($isRootNode(t)?t:t.getParentOrThrow()).getDirection()}function G(e,t,n){const o=q(e);X(e,t,n?!o:o,"character");}function J(e,t,n){const o=I(e.getStyle());return null!==o&&o[t]||n}function Q(t,n,o=""){let l=null;const r=t.getNodes(),s=t.anchor,c=t.focus,f=t.isBackward(),u=f?c.offset:s.offset,g=f?c.getNode():s.getNode();if($isRangeSelection(t)&&t.isCollapsed()&&""!==t.style){const e=I(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(g))&&$isTextNode(s)){const e=J(s,n,o);if(null===l)l=e;else if(l!==e){l="";break}}}return null===l?o:l}function V(e,t){let n=e;for(;null!==n&&null!==n.getParent()&&!t(n);)n=n.getParentOrThrow();return t(n)?n:null}const Y=O;
|
|
15
15
|
|
|
16
|
-
export {
|
|
16
|
+
export { R as $addNodeStyle, $ as $copyBlockFormatIndent, M as $ensureForwardRangeSelection, L as $forEachSelectedTextNode, Q as $getSelectionStyleValueForProperty, b as $isAtNodeEnd, q as $isParentElementRTL, X as $moveCaretSelection, G as $moveCharacter, A as $patchStyleText, _ as $setBlocksType, W as $shouldOverrideDefaultCharacterSelection, B as $sliceSelectedTextNodeContent, O as $trimTextContentFromAnchor, j as $wrapNodes, k as createDOMRange, E as createRectsFromDOMRange, F as getCSSFromStyleObject, I as getStyleObjectFromCSS, Y as trimTextContentFromAnchor };
|