lexical 0.3.3 → 0.3.4
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 +153 -143
- package/Lexical.js.flow +13 -9
- package/Lexical.prod.js +171 -170
- package/LexicalCommands.d.ts +50 -0
- package/LexicalConstants.d.ts +42 -0
- package/LexicalEditor.d.ts +200 -0
- package/LexicalEditorState.d.ts +28 -0
- package/LexicalEvents.d.ts +14 -0
- package/LexicalGC.d.ts +12 -0
- package/LexicalMutations.d.ts +12 -0
- package/LexicalNode.d.ts +82 -0
- package/LexicalNormalization.d.ts +9 -0
- package/LexicalReconciler.d.ts +12 -0
- package/LexicalSelection.d.ts +147 -0
- package/LexicalUpdates.d.ts +25 -0
- package/LexicalUtils.d.ts +95 -0
- package/LexicalVersion.d.ts +8 -0
- package/index.d.ts +31 -0
- package/nodes/LexicalDecoratorNode.d.ts +18 -0
- package/nodes/LexicalElementNode.d.ts +71 -0
- package/nodes/LexicalGridCellNode.d.ts +18 -0
- package/nodes/LexicalGridNode.d.ts +12 -0
- package/nodes/LexicalGridRowNode.d.ts +12 -0
- package/nodes/LexicalLineBreakNode.d.ts +26 -0
- package/nodes/LexicalParagraphNode.d.ts +30 -0
- package/nodes/LexicalRootNode.d.ts +29 -0
- package/nodes/LexicalTextNode.d.ts +74 -0
- package/package.json +1 -2
- package/Lexical.d.ts +0 -853
package/Lexical.dev.js
CHANGED
|
@@ -6,6 +6,58 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
11
|
+
*
|
|
12
|
+
* This source code is licensed under the MIT license found in the
|
|
13
|
+
* LICENSE file in the root directory of this source tree.
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
function createCommand() {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
const SELECTION_CHANGE_COMMAND = createCommand();
|
|
20
|
+
const CLICK_COMMAND = createCommand();
|
|
21
|
+
const DELETE_CHARACTER_COMMAND = createCommand();
|
|
22
|
+
const INSERT_LINE_BREAK_COMMAND = createCommand();
|
|
23
|
+
const INSERT_PARAGRAPH_COMMAND = createCommand();
|
|
24
|
+
const CONTROLLED_TEXT_INSERTION_COMMAND = createCommand();
|
|
25
|
+
const PASTE_COMMAND = createCommand();
|
|
26
|
+
const REMOVE_TEXT_COMMAND = createCommand();
|
|
27
|
+
const DELETE_WORD_COMMAND = createCommand();
|
|
28
|
+
const DELETE_LINE_COMMAND = createCommand();
|
|
29
|
+
const FORMAT_TEXT_COMMAND = createCommand();
|
|
30
|
+
const UNDO_COMMAND = createCommand();
|
|
31
|
+
const REDO_COMMAND = createCommand();
|
|
32
|
+
const KEY_ARROW_RIGHT_COMMAND = createCommand();
|
|
33
|
+
const MOVE_TO_END = createCommand();
|
|
34
|
+
const KEY_ARROW_LEFT_COMMAND = createCommand();
|
|
35
|
+
const MOVE_TO_START = createCommand();
|
|
36
|
+
const KEY_ARROW_UP_COMMAND = createCommand();
|
|
37
|
+
const KEY_ARROW_DOWN_COMMAND = createCommand();
|
|
38
|
+
const KEY_ENTER_COMMAND = createCommand();
|
|
39
|
+
const KEY_SPACE_COMMAND = createCommand();
|
|
40
|
+
const KEY_BACKSPACE_COMMAND = createCommand();
|
|
41
|
+
const KEY_ESCAPE_COMMAND = createCommand();
|
|
42
|
+
const KEY_DELETE_COMMAND = createCommand();
|
|
43
|
+
const KEY_TAB_COMMAND = createCommand();
|
|
44
|
+
const INDENT_CONTENT_COMMAND = createCommand();
|
|
45
|
+
const OUTDENT_CONTENT_COMMAND = createCommand();
|
|
46
|
+
const DROP_COMMAND = createCommand();
|
|
47
|
+
const FORMAT_ELEMENT_COMMAND = createCommand();
|
|
48
|
+
const DRAGSTART_COMMAND = createCommand();
|
|
49
|
+
const DRAGOVER_COMMAND = createCommand();
|
|
50
|
+
const DRAGEND_COMMAND = createCommand();
|
|
51
|
+
const COPY_COMMAND = createCommand();
|
|
52
|
+
const CUT_COMMAND = createCommand();
|
|
53
|
+
const CLEAR_EDITOR_COMMAND = createCommand();
|
|
54
|
+
const CLEAR_HISTORY_COMMAND = createCommand();
|
|
55
|
+
const CAN_REDO_COMMAND = createCommand();
|
|
56
|
+
const CAN_UNDO_COMMAND = createCommand();
|
|
57
|
+
const FOCUS_COMMAND = createCommand();
|
|
58
|
+
const BLUR_COMMAND = createCommand();
|
|
59
|
+
const KEY_MODIFIER_COMMAND = createCommand();
|
|
60
|
+
|
|
9
61
|
/**
|
|
10
62
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
11
63
|
*
|
|
@@ -173,12 +225,25 @@ function handleTextMutation(target, node, editor) {
|
|
|
173
225
|
$updateTextNodeFromDOMContent(node, text, anchorOffset, focusOffset, false);
|
|
174
226
|
}
|
|
175
227
|
|
|
228
|
+
function shouldUpdateTextNodeFromMutation(selection, targetDOM, targetNode) {
|
|
229
|
+
if ($isRangeSelection(selection)) {
|
|
230
|
+
const anchorNode = selection.anchor.getNode();
|
|
231
|
+
|
|
232
|
+
if (anchorNode.is(targetNode) && selection.format !== anchorNode.getFormat()) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return targetDOM.nodeType === DOM_TEXT_TYPE && targetNode.isAttached();
|
|
238
|
+
}
|
|
239
|
+
|
|
176
240
|
function $flushMutations$1(editor, mutations, observer) {
|
|
177
241
|
isProcessingMutations = true;
|
|
178
242
|
const shouldFlushTextMutations = performance.now() - lastTextEntryTimeStamp > TEXT_MUTATION_VARIANCE;
|
|
179
243
|
|
|
180
244
|
try {
|
|
181
245
|
updateEditor(editor, () => {
|
|
246
|
+
const selection = $getSelection() || getLastSelection(editor);
|
|
182
247
|
const badDOMTargets = new Map();
|
|
183
248
|
const rootElement = editor.getRootElement(); // We use the current edtior state, as that reflects what is
|
|
184
249
|
// actually "on screen".
|
|
@@ -200,7 +265,7 @@ function $flushMutations$1(editor, mutations, observer) {
|
|
|
200
265
|
if (type === 'characterData') {
|
|
201
266
|
// Text mutations are deferred and passed to mutation listeners to be
|
|
202
267
|
// processed outside of the Lexical engine.
|
|
203
|
-
if (shouldFlushTextMutations &&
|
|
268
|
+
if (shouldFlushTextMutations && $isTextNode(targetNode) && shouldUpdateTextNodeFromMutation(selection, targetDOM, targetNode)) {
|
|
204
269
|
handleTextMutation( // nodeType === DOM_TEXT_TYPE is a Text DOM node
|
|
205
270
|
targetDOM, targetNode);
|
|
206
271
|
}
|
|
@@ -315,8 +380,6 @@ function $flushMutations$1(editor, mutations, observer) {
|
|
|
315
380
|
observer.takeRecords();
|
|
316
381
|
}
|
|
317
382
|
|
|
318
|
-
const selection = $getSelection() || getLastSelection(editor);
|
|
319
|
-
|
|
320
383
|
if (selection !== null) {
|
|
321
384
|
if (shouldRevertSelection) {
|
|
322
385
|
selection.dirty = true;
|
|
@@ -664,7 +727,6 @@ function $setSelection(selection) {
|
|
|
664
727
|
const editorState = getActiveEditorState();
|
|
665
728
|
|
|
666
729
|
if (selection !== null) {
|
|
667
|
-
// @ts-ignore
|
|
668
730
|
{
|
|
669
731
|
if (Object.isFrozen(selection)) {
|
|
670
732
|
{
|
|
@@ -1474,7 +1536,7 @@ function createNode(key, parentDOM, insertDOM) {
|
|
|
1474
1536
|
const text = node.getTextContent();
|
|
1475
1537
|
|
|
1476
1538
|
if ($isDecoratorNode(node)) {
|
|
1477
|
-
const decorator = node.decorate(activeEditor$1);
|
|
1539
|
+
const decorator = node.decorate(activeEditor$1, activeEditorConfig);
|
|
1478
1540
|
|
|
1479
1541
|
if (decorator !== null) {
|
|
1480
1542
|
reconcileDecorator(key, decorator);
|
|
@@ -1514,8 +1576,7 @@ function createNode(key, parentDOM, insertDOM) {
|
|
|
1514
1576
|
parentDOM.appendChild(dom);
|
|
1515
1577
|
}
|
|
1516
1578
|
}
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1579
|
+
}
|
|
1519
1580
|
|
|
1520
1581
|
{
|
|
1521
1582
|
// Freeze the node in DEV to prevent accidental mutations
|
|
@@ -1790,7 +1851,7 @@ function reconcileNode(key, parentDOM) {
|
|
|
1790
1851
|
const text = nextNode.getTextContent();
|
|
1791
1852
|
|
|
1792
1853
|
if ($isDecoratorNode(nextNode)) {
|
|
1793
|
-
const decorator = nextNode.decorate(activeEditor$1);
|
|
1854
|
+
const decorator = nextNode.decorate(activeEditor$1, activeEditorConfig);
|
|
1794
1855
|
|
|
1795
1856
|
if (decorator !== null) {
|
|
1796
1857
|
reconcileDecorator(key, decorator);
|
|
@@ -1811,8 +1872,7 @@ function reconcileNode(key, parentDOM) {
|
|
|
1811
1872
|
// Cache the latest text content.
|
|
1812
1873
|
nextNode = nextNode.getWritable();
|
|
1813
1874
|
nextNode.__cachedText = editorTextContent;
|
|
1814
|
-
}
|
|
1815
|
-
|
|
1875
|
+
}
|
|
1816
1876
|
|
|
1817
1877
|
{
|
|
1818
1878
|
// Freeze the node in DEV to prevent accidental mutations
|
|
@@ -1971,58 +2031,6 @@ function getPrevElementByKeyOrThrow(key) {
|
|
|
1971
2031
|
return element;
|
|
1972
2032
|
}
|
|
1973
2033
|
|
|
1974
|
-
/**
|
|
1975
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1976
|
-
*
|
|
1977
|
-
* This source code is licensed under the MIT license found in the
|
|
1978
|
-
* LICENSE file in the root directory of this source tree.
|
|
1979
|
-
*
|
|
1980
|
-
*/
|
|
1981
|
-
function createCommand() {
|
|
1982
|
-
return {};
|
|
1983
|
-
}
|
|
1984
|
-
const SELECTION_CHANGE_COMMAND = createCommand();
|
|
1985
|
-
const CLICK_COMMAND = createCommand();
|
|
1986
|
-
const DELETE_CHARACTER_COMMAND = createCommand();
|
|
1987
|
-
const INSERT_LINE_BREAK_COMMAND = createCommand();
|
|
1988
|
-
const INSERT_PARAGRAPH_COMMAND = createCommand();
|
|
1989
|
-
const CONTROLLED_TEXT_INSERTION_COMMAND = createCommand();
|
|
1990
|
-
const PASTE_COMMAND = createCommand();
|
|
1991
|
-
const REMOVE_TEXT_COMMAND = createCommand();
|
|
1992
|
-
const DELETE_WORD_COMMAND = createCommand();
|
|
1993
|
-
const DELETE_LINE_COMMAND = createCommand();
|
|
1994
|
-
const FORMAT_TEXT_COMMAND = createCommand();
|
|
1995
|
-
const UNDO_COMMAND = createCommand();
|
|
1996
|
-
const REDO_COMMAND = createCommand();
|
|
1997
|
-
const KEY_ARROW_RIGHT_COMMAND = createCommand();
|
|
1998
|
-
const MOVE_TO_END = createCommand();
|
|
1999
|
-
const KEY_ARROW_LEFT_COMMAND = createCommand();
|
|
2000
|
-
const MOVE_TO_START = createCommand();
|
|
2001
|
-
const KEY_ARROW_UP_COMMAND = createCommand();
|
|
2002
|
-
const KEY_ARROW_DOWN_COMMAND = createCommand();
|
|
2003
|
-
const KEY_ENTER_COMMAND = createCommand();
|
|
2004
|
-
const KEY_SPACE_COMMAND = createCommand();
|
|
2005
|
-
const KEY_BACKSPACE_COMMAND = createCommand();
|
|
2006
|
-
const KEY_ESCAPE_COMMAND = createCommand();
|
|
2007
|
-
const KEY_DELETE_COMMAND = createCommand();
|
|
2008
|
-
const KEY_TAB_COMMAND = createCommand();
|
|
2009
|
-
const INDENT_CONTENT_COMMAND = createCommand();
|
|
2010
|
-
const OUTDENT_CONTENT_COMMAND = createCommand();
|
|
2011
|
-
const DROP_COMMAND = createCommand();
|
|
2012
|
-
const FORMAT_ELEMENT_COMMAND = createCommand();
|
|
2013
|
-
const DRAGSTART_COMMAND = createCommand();
|
|
2014
|
-
const DRAGOVER_COMMAND = createCommand();
|
|
2015
|
-
const DRAGEND_COMMAND = createCommand();
|
|
2016
|
-
const COPY_COMMAND = createCommand();
|
|
2017
|
-
const CUT_COMMAND = createCommand();
|
|
2018
|
-
const CLEAR_EDITOR_COMMAND = createCommand();
|
|
2019
|
-
const CLEAR_HISTORY_COMMAND = createCommand();
|
|
2020
|
-
const CAN_REDO_COMMAND = createCommand();
|
|
2021
|
-
const CAN_UNDO_COMMAND = createCommand();
|
|
2022
|
-
const FOCUS_COMMAND = createCommand();
|
|
2023
|
-
const BLUR_COMMAND = createCommand();
|
|
2024
|
-
const KEY_MODIFIER_COMMAND = createCommand();
|
|
2025
|
-
|
|
2026
2034
|
/**
|
|
2027
2035
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2028
2036
|
*
|
|
@@ -2039,6 +2047,7 @@ if (CAN_USE_BEFORE_INPUT) {
|
|
|
2039
2047
|
}
|
|
2040
2048
|
|
|
2041
2049
|
let lastKeyDownTimeStamp = 0;
|
|
2050
|
+
let lastKeyCode = 0;
|
|
2042
2051
|
let rootElementsRegistered = 0;
|
|
2043
2052
|
let isSelectionChangeFromDOMUpdate = false;
|
|
2044
2053
|
let isInsertLineBreak = false;
|
|
@@ -2180,6 +2189,10 @@ function $canRemoveText(anchorNode, focusNode) {
|
|
|
2180
2189
|
return anchorNode !== focusNode || $isElementNode(anchorNode) || $isElementNode(focusNode) || !$isTokenOrInert(anchorNode) || !$isTokenOrInert(focusNode);
|
|
2181
2190
|
}
|
|
2182
2191
|
|
|
2192
|
+
function isPossiblyAndroidKeyPress(timeStamp) {
|
|
2193
|
+
return lastKeyCode === 229 && timeStamp < lastKeyDownTimeStamp + ANDROID_COMPOSITION_LATENCY;
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2183
2196
|
function onBeforeInput(event, editor) {
|
|
2184
2197
|
const inputType = event.inputType; // We let the browser do its own thing for composition.
|
|
2185
2198
|
|
|
@@ -2196,7 +2209,9 @@ function onBeforeInput(event, editor) {
|
|
|
2196
2209
|
// during composition and see if the previous text contains
|
|
2197
2210
|
// part of the composed text to work out the actual text that
|
|
2198
2211
|
// we need to insert.
|
|
2199
|
-
const composedText = event.data;
|
|
2212
|
+
const composedText = event.data; // TODO: evaluate if this is Android only. It doesn't always seem
|
|
2213
|
+
// to have any real impact, so could probably be refactored or removed
|
|
2214
|
+
// for an alternative approach.
|
|
2200
2215
|
|
|
2201
2216
|
if (composedText) {
|
|
2202
2217
|
updateEditor(editor, () => {
|
|
@@ -2240,20 +2255,32 @@ function onBeforeInput(event, editor) {
|
|
|
2240
2255
|
}
|
|
2241
2256
|
|
|
2242
2257
|
$setSelection(prevSelection.clone());
|
|
2243
|
-
}
|
|
2258
|
+
}
|
|
2244
2259
|
|
|
2260
|
+
if ($isRangeSelection(selection)) {
|
|
2261
|
+
// Used for handling backspace in Android.
|
|
2262
|
+
if (isPossiblyAndroidKeyPress(event.timeStamp) && selection.anchor.key === selection.focus.key) {
|
|
2263
|
+
$setCompositionKey(null);
|
|
2264
|
+
lastKeyDownTimeStamp = 0; // Fixes an Android bug where selection flickers when backspacing
|
|
2245
2265
|
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2266
|
+
setTimeout(() => {
|
|
2267
|
+
updateEditor(editor, () => {
|
|
2268
|
+
$setCompositionKey(null);
|
|
2269
|
+
});
|
|
2270
|
+
}, ANDROID_COMPOSITION_LATENCY);
|
|
2250
2271
|
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2272
|
+
if ($isRangeSelection(selection)) {
|
|
2273
|
+
const anchorNode = selection.anchor.getNode();
|
|
2274
|
+
anchorNode.markDirty();
|
|
2275
|
+
selection.format = anchorNode.getFormat();
|
|
2276
|
+
}
|
|
2277
|
+
} else {
|
|
2278
|
+
event.preventDefault();
|
|
2279
|
+
dispatchCommand(editor, DELETE_CHARACTER_COMMAND, false);
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
return;
|
|
2283
|
+
}
|
|
2257
2284
|
}
|
|
2258
2285
|
|
|
2259
2286
|
if (!$isRangeSelection(selection)) {
|
|
@@ -2548,6 +2575,7 @@ function onCompositionEnd(event, editor) {
|
|
|
2548
2575
|
|
|
2549
2576
|
function onKeyDown(event, editor) {
|
|
2550
2577
|
lastKeyDownTimeStamp = event.timeStamp;
|
|
2578
|
+
lastKeyCode = event.keyCode;
|
|
2551
2579
|
|
|
2552
2580
|
if (editor.isComposing()) {
|
|
2553
2581
|
return;
|
|
@@ -2813,7 +2841,6 @@ function markCollapsedSelectionFormat(format, offset, key, timeStamp) {
|
|
|
2813
2841
|
* LICENSE file in the root directory of this source tree.
|
|
2814
2842
|
*
|
|
2815
2843
|
*/
|
|
2816
|
-
|
|
2817
2844
|
class Point {
|
|
2818
2845
|
constructor(key, offset, type) {
|
|
2819
2846
|
this._selection = null;
|
|
@@ -3450,6 +3477,7 @@ class RangeSelection {
|
|
|
3450
3477
|
|
|
3451
3478
|
if (!$isTextNode(nextSibling) || $isTokenOrInertOrSegmented(nextSibling)) {
|
|
3452
3479
|
nextSibling = $createTextNode();
|
|
3480
|
+
nextSibling.setFormat(format);
|
|
3453
3481
|
|
|
3454
3482
|
if (!firstNodeParent.canInsertTextAfter()) {
|
|
3455
3483
|
firstNodeParent.insertAfter(nextSibling);
|
|
@@ -3470,6 +3498,7 @@ class RangeSelection {
|
|
|
3470
3498
|
|
|
3471
3499
|
if (!$isTextNode(prevSibling) || $isTokenOrInertOrSegmented(prevSibling)) {
|
|
3472
3500
|
prevSibling = $createTextNode();
|
|
3501
|
+
prevSibling.setFormat(format);
|
|
3473
3502
|
|
|
3474
3503
|
if (!firstNodeParent.canInsertTextBefore()) {
|
|
3475
3504
|
firstNodeParent.insertBefore(prevSibling);
|
|
@@ -3487,6 +3516,7 @@ class RangeSelection {
|
|
|
3487
3516
|
}
|
|
3488
3517
|
} else if (firstNode.isSegmented() && startOffset !== firstNodeTextLength) {
|
|
3489
3518
|
const textNode = $createTextNode(firstNode.getTextContent());
|
|
3519
|
+
textNode.setFormat(format);
|
|
3490
3520
|
firstNode.replace(textNode);
|
|
3491
3521
|
firstNode = textNode;
|
|
3492
3522
|
} else if (!this.isCollapsed() && text !== '') {
|
|
@@ -3544,10 +3574,14 @@ class RangeSelection {
|
|
|
3544
3574
|
|
|
3545
3575
|
if (firstNode.getTextContent() === '') {
|
|
3546
3576
|
firstNode.remove();
|
|
3547
|
-
} else if (
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3577
|
+
} else if (this.anchor.type === 'text') {
|
|
3578
|
+
if (firstNode.isComposing()) {
|
|
3579
|
+
// When composing, we need to adjust the anchor offset so that
|
|
3580
|
+
// we correctly replace that right range.
|
|
3581
|
+
this.anchor.offset -= text.length;
|
|
3582
|
+
} else {
|
|
3583
|
+
this.format = firstNodeFormat;
|
|
3584
|
+
}
|
|
3551
3585
|
}
|
|
3552
3586
|
} else {
|
|
3553
3587
|
const markedNodeKeysForKeep = new Set([...firstNode.getParentKeys(), ...lastNode.getParentKeys()]); // We have to get the parent elements before the next section,
|
|
@@ -4746,15 +4780,15 @@ function internalMakeRangeSelection(anchorKey, anchorOffset, focusKey, focusOffs
|
|
|
4746
4780
|
editorState._selection = selection;
|
|
4747
4781
|
return selection;
|
|
4748
4782
|
}
|
|
4749
|
-
function $
|
|
4783
|
+
function $createRangeSelection() {
|
|
4750
4784
|
const anchor = $createPoint('root', 0, 'element');
|
|
4751
4785
|
const focus = $createPoint('root', 0, 'element');
|
|
4752
4786
|
return new RangeSelection(anchor, focus, 0);
|
|
4753
4787
|
}
|
|
4754
|
-
function $
|
|
4788
|
+
function $createNodeSelection() {
|
|
4755
4789
|
return new NodeSelection(new Set());
|
|
4756
4790
|
}
|
|
4757
|
-
function $
|
|
4791
|
+
function $createGridSelection() {
|
|
4758
4792
|
const anchor = $createPoint('root', 0, 'element');
|
|
4759
4793
|
const focus = $createPoint('root', 0, 'element');
|
|
4760
4794
|
return new GridSelection('root', anchor, focus);
|
|
@@ -5348,7 +5382,7 @@ function parseEditorState(serializedEditorState, editor, updateFn) {
|
|
|
5348
5382
|
} // Make the editorState immutable
|
|
5349
5383
|
|
|
5350
5384
|
|
|
5351
|
-
editorState._readOnly = true;
|
|
5385
|
+
editorState._readOnly = true;
|
|
5352
5386
|
|
|
5353
5387
|
{
|
|
5354
5388
|
handleDEVOnlyPendingUpdateGuarantees(editorState);
|
|
@@ -5472,7 +5506,7 @@ function commitPendingUpdates(editor) {
|
|
|
5472
5506
|
}
|
|
5473
5507
|
}
|
|
5474
5508
|
|
|
5475
|
-
pendingEditorState._readOnly = true;
|
|
5509
|
+
pendingEditorState._readOnly = true;
|
|
5476
5510
|
|
|
5477
5511
|
{
|
|
5478
5512
|
handleDEVOnlyPendingUpdateGuarantees(pendingEditorState);
|
|
@@ -5817,7 +5851,13 @@ function internalGetActiveEditor() {
|
|
|
5817
5851
|
return activeEditor;
|
|
5818
5852
|
}
|
|
5819
5853
|
|
|
5820
|
-
|
|
5854
|
+
/**
|
|
5855
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5856
|
+
*
|
|
5857
|
+
* This source code is licensed under the MIT license found in the
|
|
5858
|
+
* LICENSE file in the root directory of this source tree.
|
|
5859
|
+
*
|
|
5860
|
+
*/
|
|
5821
5861
|
function removeNode(nodeToRemove, restoreSelection, preserveEmptyParent) {
|
|
5822
5862
|
errorOnReadOnly();
|
|
5823
5863
|
const key = nodeToRemove.__key;
|
|
@@ -5906,7 +5946,7 @@ class LexicalNode {
|
|
|
5906
5946
|
// @ts-expect-error
|
|
5907
5947
|
this.__type = this.constructor.getType();
|
|
5908
5948
|
this.__parent = null;
|
|
5909
|
-
$setNodeKey(this, key);
|
|
5949
|
+
$setNodeKey(this, key);
|
|
5910
5950
|
|
|
5911
5951
|
{
|
|
5912
5952
|
if (this.__type !== 'root') {
|
|
@@ -6375,52 +6415,11 @@ class LexicalNode {
|
|
|
6375
6415
|
|
|
6376
6416
|
exportDOM(editor) {
|
|
6377
6417
|
const element = this.createDOM(editor._config, editor);
|
|
6378
|
-
const serializedNode = this.exportJSON();
|
|
6379
|
-
element.setAttribute('data-lexical-node-type', this.__type);
|
|
6380
|
-
element.setAttribute('data-lexical-node-json', JSON.stringify(serializedNode));
|
|
6381
|
-
element.setAttribute('data-lexical-editor-key', editor._key);
|
|
6382
6418
|
return {
|
|
6383
6419
|
element
|
|
6384
6420
|
};
|
|
6385
6421
|
}
|
|
6386
6422
|
|
|
6387
|
-
static importDOM() {
|
|
6388
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6389
|
-
const proto = this.prototype.constructor;
|
|
6390
|
-
return {
|
|
6391
|
-
// Catch-all key because we don't know the nodeName of the element returned by exportDOM.
|
|
6392
|
-
'*': domNode => {
|
|
6393
|
-
if (!(domNode instanceof HTMLElement)) return null;
|
|
6394
|
-
const editorKey = domNode.getAttribute('data-lexical-editor-key');
|
|
6395
|
-
const nodeType = domNode.getAttribute('data-lexical-node-type');
|
|
6396
|
-
if (editorKey == null || nodeType == null) return null;
|
|
6397
|
-
const editor = getActiveEditor();
|
|
6398
|
-
|
|
6399
|
-
if (editorKey === editor.getKey() && nodeType === proto.getType()) {
|
|
6400
|
-
try {
|
|
6401
|
-
const json = domNode.getAttribute('data-lexical-node-json');
|
|
6402
|
-
|
|
6403
|
-
if (json != null) {
|
|
6404
|
-
const serializedNode = JSON.parse(json);
|
|
6405
|
-
const node = proto.importJSON(serializedNode);
|
|
6406
|
-
return {
|
|
6407
|
-
conversion: () => ({
|
|
6408
|
-
node
|
|
6409
|
-
}),
|
|
6410
|
-
// Max priority because of the 'data-lexical-node-type' attribute
|
|
6411
|
-
// matching the one on node klass guarantees a match.
|
|
6412
|
-
priority: 4
|
|
6413
|
-
}; // eslint-disable-next-line no-empty
|
|
6414
|
-
} // eslint-disable-next-line no-empty
|
|
6415
|
-
|
|
6416
|
-
} catch {}
|
|
6417
|
-
}
|
|
6418
|
-
|
|
6419
|
-
return null;
|
|
6420
|
-
}
|
|
6421
|
-
};
|
|
6422
|
-
}
|
|
6423
|
-
|
|
6424
6423
|
exportJSON() {
|
|
6425
6424
|
{
|
|
6426
6425
|
throw Error(`exportJSON: base method not extended`);
|
|
@@ -6639,7 +6638,7 @@ class DecoratorNode extends LexicalNode {
|
|
|
6639
6638
|
super(key);
|
|
6640
6639
|
}
|
|
6641
6640
|
|
|
6642
|
-
decorate(editor) {
|
|
6641
|
+
decorate(editor, config) {
|
|
6643
6642
|
{
|
|
6644
6643
|
throw Error(`decorate: base method not extended`);
|
|
6645
6644
|
}
|
|
@@ -7108,7 +7107,7 @@ class ElementNode extends LexicalNode {
|
|
|
7108
7107
|
return false;
|
|
7109
7108
|
}
|
|
7110
7109
|
|
|
7111
|
-
excludeFromCopy() {
|
|
7110
|
+
excludeFromCopy(destination) {
|
|
7112
7111
|
return false;
|
|
7113
7112
|
}
|
|
7114
7113
|
|
|
@@ -8162,8 +8161,21 @@ function convertBringAttentionToElement(domNode) {
|
|
|
8162
8161
|
}
|
|
8163
8162
|
|
|
8164
8163
|
function convertTextDOMNode(domNode) {
|
|
8164
|
+
const {
|
|
8165
|
+
parentElement,
|
|
8166
|
+
textContent
|
|
8167
|
+
} = domNode;
|
|
8168
|
+
const textContentTrim = textContent.trim();
|
|
8169
|
+
const isPre = parentElement != null && parentElement.tagName.toLowerCase() === 'pre';
|
|
8170
|
+
|
|
8171
|
+
if (!isPre && textContentTrim.length === 0 && textContent.includes('\n')) {
|
|
8172
|
+
return {
|
|
8173
|
+
node: null
|
|
8174
|
+
};
|
|
8175
|
+
}
|
|
8176
|
+
|
|
8165
8177
|
return {
|
|
8166
|
-
node: $createTextNode(
|
|
8178
|
+
node: $createTextNode(textContent)
|
|
8167
8179
|
};
|
|
8168
8180
|
}
|
|
8169
8181
|
|
|
@@ -8376,10 +8388,11 @@ function initializeConversionCache(nodes) {
|
|
|
8376
8388
|
const conversionCache = new Map();
|
|
8377
8389
|
const handledConversions = new Set();
|
|
8378
8390
|
nodes.forEach(node => {
|
|
8379
|
-
// @ts-expect-error TODO Replace Class utility type with InstanceType
|
|
8380
|
-
|
|
8391
|
+
const importDOM = // @ts-expect-error TODO Replace Class utility type with InstanceType
|
|
8392
|
+
node.klass.importDOM != null ? // @ts-expect-error TODO Replace Class utility type with InstanceType
|
|
8393
|
+
node.klass.importDOM.bind(node.klass) : null;
|
|
8381
8394
|
|
|
8382
|
-
if (handledConversions.has(importDOM)) {
|
|
8395
|
+
if (importDOM == null || handledConversions.has(importDOM)) {
|
|
8383
8396
|
return;
|
|
8384
8397
|
}
|
|
8385
8398
|
|
|
@@ -8423,7 +8436,6 @@ function createEditor(editorConfig) {
|
|
|
8423
8436
|
|
|
8424
8437
|
for (let i = 0; i < nodes.length; i++) {
|
|
8425
8438
|
const klass = nodes[i]; // Ensure custom nodes implement required methods.
|
|
8426
|
-
// @ts-ignore
|
|
8427
8439
|
|
|
8428
8440
|
{
|
|
8429
8441
|
const name = klass.name;
|
|
@@ -8630,9 +8642,7 @@ class LexicalEditor {
|
|
|
8630
8642
|
};
|
|
8631
8643
|
}
|
|
8632
8644
|
|
|
8633
|
-
registerNodeTransform(
|
|
8634
|
-
// declaration below guarantees these are LexicalNodes.
|
|
8635
|
-
klass, listener) {
|
|
8645
|
+
registerNodeTransform(klass, listener) {
|
|
8636
8646
|
// @ts-expect-error TODO Replace Class utility type with InstanceType
|
|
8637
8647
|
const type = klass.getType();
|
|
8638
8648
|
|
|
@@ -8654,7 +8664,7 @@ class LexicalEditor {
|
|
|
8654
8664
|
|
|
8655
8665
|
hasNodes(nodes) {
|
|
8656
8666
|
for (let i = 0; i < nodes.length; i++) {
|
|
8657
|
-
const klass = nodes[i]; // @ts-expect-error
|
|
8667
|
+
const klass = nodes[i]; // @ts-expect-error
|
|
8658
8668
|
|
|
8659
8669
|
const type = klass.getType();
|
|
8660
8670
|
|
|
@@ -8823,7 +8833,7 @@ class LexicalEditor {
|
|
|
8823
8833
|
|
|
8824
8834
|
toJSON() {
|
|
8825
8835
|
return {
|
|
8826
|
-
editorState: this._editorState
|
|
8836
|
+
editorState: this._editorState.toJSON()
|
|
8827
8837
|
};
|
|
8828
8838
|
}
|
|
8829
8839
|
|
|
@@ -8836,7 +8846,7 @@ class LexicalEditor {
|
|
|
8836
8846
|
* LICENSE file in the root directory of this source tree.
|
|
8837
8847
|
*
|
|
8838
8848
|
*/
|
|
8839
|
-
const VERSION = '0.3.
|
|
8849
|
+
const VERSION = '0.3.4';
|
|
8840
8850
|
|
|
8841
8851
|
/**
|
|
8842
8852
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -8886,11 +8896,11 @@ function $isGridRowNode(node) {
|
|
|
8886
8896
|
return node instanceof GridRowNode;
|
|
8887
8897
|
}
|
|
8888
8898
|
|
|
8889
|
-
exports.$createGridSelection = $
|
|
8899
|
+
exports.$createGridSelection = $createGridSelection;
|
|
8890
8900
|
exports.$createLineBreakNode = $createLineBreakNode;
|
|
8891
|
-
exports.$createNodeSelection = $
|
|
8901
|
+
exports.$createNodeSelection = $createNodeSelection;
|
|
8892
8902
|
exports.$createParagraphNode = $createParagraphNode;
|
|
8893
|
-
exports.$createRangeSelection = $
|
|
8903
|
+
exports.$createRangeSelection = $createRangeSelection;
|
|
8894
8904
|
exports.$createTextNode = $createTextNode;
|
|
8895
8905
|
exports.$getDecoratorNode = $getDecoratorNode;
|
|
8896
8906
|
exports.$getNearestNodeFromDOMNode = $getNearestNodeFromDOMNode;
|
package/Lexical.js.flow
CHANGED
|
@@ -164,8 +164,8 @@ declare export class LexicalEditor {
|
|
|
164
164
|
getElementByKey(key: NodeKey): null | HTMLElement;
|
|
165
165
|
getEditorState(): EditorState;
|
|
166
166
|
setEditorState(editorState: EditorState, options?: EditorSetOptions): void;
|
|
167
|
-
parseEditorState
|
|
168
|
-
maybeStringifiedEditorState: string | SerializedEditorState
|
|
167
|
+
parseEditorState(
|
|
168
|
+
maybeStringifiedEditorState: string | SerializedEditorState,
|
|
169
169
|
updateFn?: () => void,
|
|
170
170
|
): EditorState;
|
|
171
171
|
update(updateFn: () => void, options?: EditorUpdateOptions): boolean;
|
|
@@ -173,7 +173,7 @@ declare export class LexicalEditor {
|
|
|
173
173
|
blur(): void;
|
|
174
174
|
isReadOnly(): boolean;
|
|
175
175
|
setReadOnly(readOnly: boolean): void;
|
|
176
|
-
toJSON(): SerializedEditor
|
|
176
|
+
toJSON(): SerializedEditor;
|
|
177
177
|
}
|
|
178
178
|
type EditorUpdateOptions = {
|
|
179
179
|
onUpdate?: () => void,
|
|
@@ -233,6 +233,10 @@ export type EditorThemeClasses = {
|
|
|
233
233
|
h5?: EditorThemeClassName,
|
|
234
234
|
h6?: EditorThemeClassName,
|
|
235
235
|
},
|
|
236
|
+
embedBlock?: {
|
|
237
|
+
base?: EditorThemeClassName,
|
|
238
|
+
focus?: EditorThemeClassName,
|
|
239
|
+
},
|
|
236
240
|
// Handle other generic values
|
|
237
241
|
[string]: EditorThemeClassName | {[string]: EditorThemeClassName},
|
|
238
242
|
};
|
|
@@ -275,7 +279,7 @@ export interface EditorState {
|
|
|
275
279
|
): void;
|
|
276
280
|
isEmpty(): boolean;
|
|
277
281
|
read<V>(callbackFn: () => V): V;
|
|
278
|
-
toJSON
|
|
282
|
+
toJSON(): SerializedEditorState;
|
|
279
283
|
clone(
|
|
280
284
|
selection?: RangeSelection | NodeSelection | GridSelection | null,
|
|
281
285
|
): EditorState;
|
|
@@ -729,7 +733,7 @@ declare export function $isElementNode(
|
|
|
729
733
|
|
|
730
734
|
declare export class DecoratorNode<X> extends LexicalNode {
|
|
731
735
|
constructor(key?: NodeKey): void;
|
|
732
|
-
decorate(editor: LexicalEditor): X;
|
|
736
|
+
decorate(editor: LexicalEditor, config: EditorConfig): X;
|
|
733
737
|
isIsolated(): boolean;
|
|
734
738
|
isTopLevel(): boolean;
|
|
735
739
|
}
|
|
@@ -877,10 +881,10 @@ export type SerializedGridCellNode = {
|
|
|
877
881
|
...
|
|
878
882
|
};
|
|
879
883
|
|
|
880
|
-
export interface SerializedEditorState
|
|
881
|
-
root: SerializedRootNode
|
|
884
|
+
export interface SerializedEditorState {
|
|
885
|
+
root: SerializedRootNode;
|
|
882
886
|
}
|
|
883
887
|
|
|
884
|
-
export type SerializedEditor
|
|
885
|
-
editorState: SerializedEditorState
|
|
888
|
+
export type SerializedEditor = {
|
|
889
|
+
editorState: SerializedEditorState,
|
|
886
890
|
};
|