lexical 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Lexical.dev.js +52 -47
- package/Lexical.js.flow +1 -6
- package/Lexical.prod.js +183 -181
- package/LexicalNode.d.ts +1 -1
- package/LexicalSelection.d.ts +1 -1
- package/LexicalUpdates.d.ts +1 -1
- package/LexicalUtils.d.ts +2 -1
- package/index.d.ts +0 -1
- package/package.json +1 -1
- package/LexicalVersion.d.ts +0 -8
package/Lexical.dev.js
CHANGED
|
@@ -69,18 +69,6 @@ const KEY_MODIFIER_COMMAND = createCommand('KEY_MODIFIER_COMMAND');
|
|
|
69
69
|
*/
|
|
70
70
|
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
71
71
|
|
|
72
|
-
/**
|
|
73
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
74
|
-
*
|
|
75
|
-
* This source code is licensed under the MIT license found in the
|
|
76
|
-
* LICENSE file in the root directory of this source tree.
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
const getSelection = () => CAN_USE_DOM ? window.getSelection() : null;
|
|
81
|
-
|
|
82
|
-
var getDOMSelection = getSelection;
|
|
83
|
-
|
|
84
72
|
/**
|
|
85
73
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
86
74
|
*
|
|
@@ -489,7 +477,7 @@ function getNearestEditorFromDOMNode(node) {
|
|
|
489
477
|
return editor;
|
|
490
478
|
}
|
|
491
479
|
|
|
492
|
-
currentNode = currentNode
|
|
480
|
+
currentNode = getParentElement(currentNode);
|
|
493
481
|
}
|
|
494
482
|
|
|
495
483
|
return null;
|
|
@@ -750,7 +738,7 @@ function $getNearestNodeFromDOMNode(startingDOM, editorState) {
|
|
|
750
738
|
return node;
|
|
751
739
|
}
|
|
752
740
|
|
|
753
|
-
dom = dom
|
|
741
|
+
dom = getParentElement(dom);
|
|
754
742
|
}
|
|
755
743
|
|
|
756
744
|
return null;
|
|
@@ -794,6 +782,7 @@ function internalGetRoot(editorState) {
|
|
|
794
782
|
return editorState._nodeMap.get('root');
|
|
795
783
|
}
|
|
796
784
|
function $setSelection(selection) {
|
|
785
|
+
errorOnReadOnly();
|
|
797
786
|
const editorState = getActiveEditorState();
|
|
798
787
|
|
|
799
788
|
if (selection !== null) {
|
|
@@ -848,7 +837,7 @@ dom, editor) {
|
|
|
848
837
|
return key;
|
|
849
838
|
}
|
|
850
839
|
|
|
851
|
-
node = node
|
|
840
|
+
node = getParentElement(node);
|
|
852
841
|
}
|
|
853
842
|
|
|
854
843
|
return null;
|
|
@@ -1290,8 +1279,8 @@ function getElementByKeyOrThrow(editor, key) {
|
|
|
1290
1279
|
|
|
1291
1280
|
return element;
|
|
1292
1281
|
}
|
|
1293
|
-
function getParentElement(
|
|
1294
|
-
const parentElement =
|
|
1282
|
+
function getParentElement(node) {
|
|
1283
|
+
const parentElement = node.assignedSlot || node.parentElement;
|
|
1295
1284
|
return parentElement !== null && parentElement.nodeType === 11 ? parentElement.host : parentElement;
|
|
1296
1285
|
}
|
|
1297
1286
|
function scrollIntoViewIfNeeded(editor, selectionRect, rootElement) {
|
|
@@ -1566,6 +1555,16 @@ function updateDOMBlockCursorElement(editor, rootElement, nextSelection) {
|
|
|
1566
1555
|
removeDOMBlockCursorElement(blockCursorElement, editor, rootElement);
|
|
1567
1556
|
}
|
|
1568
1557
|
}
|
|
1558
|
+
function getDOMSelection() {
|
|
1559
|
+
const editor = internalGetActiveEditor();
|
|
1560
|
+
|
|
1561
|
+
if (!CAN_USE_DOM) {
|
|
1562
|
+
return null;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
const win = editor && editor._window || window;
|
|
1566
|
+
return win.getSelection();
|
|
1567
|
+
}
|
|
1569
1568
|
|
|
1570
1569
|
/**
|
|
1571
1570
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -2430,7 +2429,7 @@ function getPrevElementByKeyOrThrow(key) {
|
|
|
2430
2429
|
*/
|
|
2431
2430
|
const PASS_THROUGH_COMMAND = Object.freeze({});
|
|
2432
2431
|
const ANDROID_COMPOSITION_LATENCY = 30;
|
|
2433
|
-
const rootElementEvents = [['keydown', onKeyDown], ['
|
|
2432
|
+
const rootElementEvents = [['keydown', onKeyDown], ['pointerdown', onPointerDown], ['compositionstart', onCompositionStart], ['compositionend', onCompositionEnd], ['input', onInput], ['click', onClick], ['cut', PASS_THROUGH_COMMAND], ['copy', PASS_THROUGH_COMMAND], ['dragstart', PASS_THROUGH_COMMAND], ['dragover', PASS_THROUGH_COMMAND], ['dragend', PASS_THROUGH_COMMAND], ['paste', PASS_THROUGH_COMMAND], ['focus', PASS_THROUGH_COMMAND], ['blur', PASS_THROUGH_COMMAND], ['drop', PASS_THROUGH_COMMAND]];
|
|
2434
2433
|
|
|
2435
2434
|
if (CAN_USE_BEFORE_INPUT) {
|
|
2436
2435
|
rootElementEvents.push(['beforeinput', (event, editor) => onBeforeInput(event, editor)]);
|
|
@@ -2595,11 +2594,12 @@ function onClick(event, editor) {
|
|
|
2595
2594
|
});
|
|
2596
2595
|
}
|
|
2597
2596
|
|
|
2598
|
-
function
|
|
2597
|
+
function onPointerDown(event, editor) {
|
|
2599
2598
|
// TODO implement text drag & drop
|
|
2600
2599
|
const target = event.target;
|
|
2600
|
+
const pointerType = event.pointerType;
|
|
2601
2601
|
|
|
2602
|
-
if (target instanceof Node) {
|
|
2602
|
+
if (target instanceof Node && pointerType !== 'touch') {
|
|
2603
2603
|
updateEditor(editor, () => {
|
|
2604
2604
|
// Drag & drop should not recompute selection until mouse up; otherwise the initially
|
|
2605
2605
|
// selected content is lost.
|
|
@@ -4115,7 +4115,7 @@ class RangeSelection {
|
|
|
4115
4115
|
if ($isTextNode(lastNode) && !lastNode.isToken() && endOffset !== lastNode.getTextContentSize()) {
|
|
4116
4116
|
if (lastNode.isSegmented()) {
|
|
4117
4117
|
const textNode = $createTextNode(lastNode.getTextContent());
|
|
4118
|
-
lastNode.replace(textNode
|
|
4118
|
+
lastNode.replace(textNode);
|
|
4119
4119
|
lastNode = textNode;
|
|
4120
4120
|
}
|
|
4121
4121
|
|
|
@@ -4203,7 +4203,7 @@ class RangeSelection {
|
|
|
4203
4203
|
} else {
|
|
4204
4204
|
const textNode = $createTextNode(text);
|
|
4205
4205
|
textNode.select();
|
|
4206
|
-
firstNode.replace(textNode
|
|
4206
|
+
firstNode.replace(textNode);
|
|
4207
4207
|
} // Remove all selected nodes that haven't already been removed.
|
|
4208
4208
|
|
|
4209
4209
|
|
|
@@ -5025,7 +5025,8 @@ class RangeSelection {
|
|
|
5025
5025
|
|
|
5026
5026
|
if (!isBackward && ( // Delete forward handle case
|
|
5027
5027
|
anchor.type === 'element' && $isElementNode(anchorNode) && anchor.offset === anchorNode.getChildrenSize() || anchor.type === 'text' && anchor.offset === anchorNode.getTextContentSize())) {
|
|
5028
|
-
const
|
|
5028
|
+
const parent = anchorNode.getParent();
|
|
5029
|
+
const nextSibling = anchorNode.getNextSibling() || (parent === null ? null : parent.getNextSibling());
|
|
5029
5030
|
|
|
5030
5031
|
if ($isElementNode(nextSibling) && !nextSibling.canExtractContents()) {
|
|
5031
5032
|
return;
|
|
@@ -5718,7 +5719,7 @@ function adjustPointOffsetForMergedSibling(point, isBefore, key, target, textLen
|
|
|
5718
5719
|
point.offset -= 1;
|
|
5719
5720
|
}
|
|
5720
5721
|
}
|
|
5721
|
-
function updateDOMSelection(prevSelection, nextSelection, editor, domSelection, tags, rootElement,
|
|
5722
|
+
function updateDOMSelection(prevSelection, nextSelection, editor, domSelection, tags, rootElement, nodeCount) {
|
|
5722
5723
|
const anchorDOMNode = domSelection.anchorNode;
|
|
5723
5724
|
const focusDOMNode = domSelection.focusNode;
|
|
5724
5725
|
const anchorOffset = domSelection.anchorOffset;
|
|
@@ -5803,7 +5804,7 @@ function updateDOMSelection(prevSelection, nextSelection, editor, domSelection,
|
|
|
5803
5804
|
// The downside is that is makes the computation within Lexical more
|
|
5804
5805
|
// complex, as now, we've sync update the DOM, but selection no longer
|
|
5805
5806
|
// matches.
|
|
5806
|
-
if (IS_CHROME &&
|
|
5807
|
+
if (IS_CHROME && nodeCount > 1000) {
|
|
5807
5808
|
window.requestAnimationFrame(() => domSelection.setBaseAndExtent(nextAnchorNode, nextAnchorOffset, nextFocusNode, nextFocusOffset));
|
|
5808
5809
|
} else {
|
|
5809
5810
|
domSelection.setBaseAndExtent(nextAnchorNode, nextAnchorOffset, nextFocusNode, nextFocusOffset);
|
|
@@ -5862,7 +5863,7 @@ const observerOptions = {
|
|
|
5862
5863
|
subtree: true
|
|
5863
5864
|
};
|
|
5864
5865
|
function isCurrentlyReadOnlyMode() {
|
|
5865
|
-
return isReadOnlyMode;
|
|
5866
|
+
return isReadOnlyMode || activeEditorState !== null && activeEditorState._readOnly;
|
|
5866
5867
|
}
|
|
5867
5868
|
function errorOnReadOnly() {
|
|
5868
5869
|
if (isReadOnlyMode) {
|
|
@@ -5896,6 +5897,9 @@ function getActiveEditor() {
|
|
|
5896
5897
|
|
|
5897
5898
|
return activeEditor;
|
|
5898
5899
|
}
|
|
5900
|
+
function internalGetActiveEditor() {
|
|
5901
|
+
return activeEditor;
|
|
5902
|
+
}
|
|
5899
5903
|
function $applyTransforms(editor, node, transformsCache) {
|
|
5900
5904
|
const type = node.__type;
|
|
5901
5905
|
const registeredNode = getRegisteredNodeOrThrow(editor, type);
|
|
@@ -6225,7 +6229,7 @@ function commitPendingUpdates(editor) {
|
|
|
6225
6229
|
const normalizedNodes = editor._normalizedNodes;
|
|
6226
6230
|
const tags = editor._updateTags;
|
|
6227
6231
|
const deferred = editor._deferred;
|
|
6228
|
-
const
|
|
6232
|
+
const nodeCount = pendingEditorState._nodeMap.size;
|
|
6229
6233
|
|
|
6230
6234
|
if (needsUpdate) {
|
|
6231
6235
|
editor._dirtyType = NO_DIRTY_NODES;
|
|
@@ -6262,7 +6266,7 @@ function commitPendingUpdates(editor) {
|
|
|
6262
6266
|
removeDOMBlockCursorElement(blockCursorElement, editor, rootElement);
|
|
6263
6267
|
}
|
|
6264
6268
|
|
|
6265
|
-
updateDOMSelection(currentSelection, pendingSelection, editor, domSelection, tags, rootElement,
|
|
6269
|
+
updateDOMSelection(currentSelection, pendingSelection, editor, domSelection, tags, rootElement, nodeCount);
|
|
6266
6270
|
}
|
|
6267
6271
|
|
|
6268
6272
|
updateDOMBlockCursorElement(editor, rootElement, pendingSelection);
|
|
@@ -6602,9 +6606,6 @@ function updateEditor(editor, updateFn, options) {
|
|
|
6602
6606
|
beginUpdate(editor, updateFn, options);
|
|
6603
6607
|
}
|
|
6604
6608
|
}
|
|
6605
|
-
function internalGetActiveEditor() {
|
|
6606
|
-
return activeEditor;
|
|
6607
|
-
}
|
|
6608
6609
|
|
|
6609
6610
|
/**
|
|
6610
6611
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -6849,7 +6850,12 @@ class LexicalNode {
|
|
|
6849
6850
|
|
|
6850
6851
|
getPreviousSiblings() {
|
|
6851
6852
|
const siblings = [];
|
|
6852
|
-
const parent = this.
|
|
6853
|
+
const parent = this.getParent();
|
|
6854
|
+
|
|
6855
|
+
if (parent === null) {
|
|
6856
|
+
return siblings;
|
|
6857
|
+
}
|
|
6858
|
+
|
|
6853
6859
|
let node = parent.getFirstChild();
|
|
6854
6860
|
|
|
6855
6861
|
while (node !== null) {
|
|
@@ -6981,7 +6987,8 @@ class LexicalNode {
|
|
|
6981
6987
|
}
|
|
6982
6988
|
|
|
6983
6989
|
return false;
|
|
6984
|
-
}
|
|
6990
|
+
} // TO-DO: this function can be simplified a lot
|
|
6991
|
+
|
|
6985
6992
|
|
|
6986
6993
|
getNodesBetween(targetNode) {
|
|
6987
6994
|
const isBefore = this.isBefore(targetNode);
|
|
@@ -7180,8 +7187,10 @@ class LexicalNode {
|
|
|
7180
7187
|
removeNode(this, true, preserveEmptyParent);
|
|
7181
7188
|
}
|
|
7182
7189
|
|
|
7183
|
-
replace(replaceWith,
|
|
7190
|
+
replace(replaceWith, includeChildren) {
|
|
7184
7191
|
errorOnReadOnly();
|
|
7192
|
+
let selection = $getSelection();
|
|
7193
|
+
if (selection !== null) selection = selection.clone();
|
|
7185
7194
|
errorOnInsertTextNodeOnRoot(this, replaceWith);
|
|
7186
7195
|
const self = this.getLatest();
|
|
7187
7196
|
const toReplaceKey = this.__key;
|
|
@@ -7216,9 +7225,15 @@ class LexicalNode {
|
|
|
7216
7225
|
writableReplaceWith.__next = nextKey;
|
|
7217
7226
|
writableReplaceWith.__parent = parentKey;
|
|
7218
7227
|
writableParent.__size = size;
|
|
7219
|
-
const selection = $getSelection();
|
|
7220
7228
|
|
|
7221
|
-
if (
|
|
7229
|
+
if (includeChildren) {
|
|
7230
|
+
this.getChildren().forEach(child => {
|
|
7231
|
+
writableReplaceWith.append(child);
|
|
7232
|
+
});
|
|
7233
|
+
}
|
|
7234
|
+
|
|
7235
|
+
if ($isRangeSelection(selection)) {
|
|
7236
|
+
$setSelection(selection);
|
|
7222
7237
|
const anchor = selection.anchor;
|
|
7223
7238
|
const focus = selection.focus;
|
|
7224
7239
|
|
|
@@ -8003,7 +8018,7 @@ class ElementNode extends LexicalNode {
|
|
|
8003
8018
|
return false;
|
|
8004
8019
|
} // A shadow root is a Node that behaves like RootNode. The shadow root (and RootNode) mark the
|
|
8005
8020
|
// end of the hiercharchy, most implementations should treat it as there's nothing (upwards)
|
|
8006
|
-
// beyond this point. For example, node.
|
|
8021
|
+
// beyond this point. For example, node.getTopLevelElement(), when performed inside a TableCellNode
|
|
8007
8022
|
// will return the immediate first child underneath TableCellNode instead of RootNode.
|
|
8008
8023
|
|
|
8009
8024
|
|
|
@@ -9821,15 +9836,6 @@ class LexicalEditor {
|
|
|
9821
9836
|
|
|
9822
9837
|
}
|
|
9823
9838
|
|
|
9824
|
-
/**
|
|
9825
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9826
|
-
*
|
|
9827
|
-
* This source code is licensed under the MIT license found in the
|
|
9828
|
-
* LICENSE file in the root directory of this source tree.
|
|
9829
|
-
*
|
|
9830
|
-
*/
|
|
9831
|
-
const VERSION = '0.7.0';
|
|
9832
|
-
|
|
9833
9839
|
/**
|
|
9834
9840
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9835
9841
|
*
|
|
@@ -9975,6 +9981,5 @@ exports.RootNode = RootNode;
|
|
|
9975
9981
|
exports.SELECTION_CHANGE_COMMAND = SELECTION_CHANGE_COMMAND;
|
|
9976
9982
|
exports.TextNode = TextNode;
|
|
9977
9983
|
exports.UNDO_COMMAND = UNDO_COMMAND;
|
|
9978
|
-
exports.VERSION = VERSION;
|
|
9979
9984
|
exports.createCommand = createCommand;
|
|
9980
9985
|
exports.createEditor = createEditor;
|
package/Lexical.js.flow
CHANGED
|
@@ -58,7 +58,7 @@ declare export function createCommand<T>(type?: string): LexicalCommand<T>;
|
|
|
58
58
|
/**
|
|
59
59
|
* LexicalEditor
|
|
60
60
|
*/
|
|
61
|
-
type IntentionallyMarkedAsDirtyElement =
|
|
61
|
+
type IntentionallyMarkedAsDirtyElement = boolean;
|
|
62
62
|
|
|
63
63
|
type MutationListeners = Map<MutationListener, Class<LexicalNode>>;
|
|
64
64
|
export type NodeMutation = 'created' | 'updated' | 'destroyed';
|
|
@@ -846,11 +846,6 @@ declare export function $copyNode(
|
|
|
846
846
|
offset: number,
|
|
847
847
|
): [ElementNode, ElementNode];
|
|
848
848
|
|
|
849
|
-
/**
|
|
850
|
-
* LexicalVersion
|
|
851
|
-
*/
|
|
852
|
-
declare export var VERSION: string;
|
|
853
|
-
|
|
854
849
|
/**
|
|
855
850
|
* Serialization/Deserialization
|
|
856
851
|
* */
|