lexical 0.1.14 → 0.1.15
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.d.ts +13 -11
- package/Lexical.dev.js +158 -49
- package/Lexical.js.flow +15 -23
- package/Lexical.prod.js +156 -153
- package/LexicalCodeHighlightNode.dev.js +4 -24
- package/LexicalCodeHighlightNode.prod.js +3 -3
- package/LexicalCodeNode.dev.js +2 -17
- package/LexicalCodeNode.prod.js +6 -6
- package/LexicalExtendedNodes.dev.js +2 -2
- package/LexicalExtendedNodes.prod.js +2 -2
- package/LexicalHeadingNode.dev.js +2 -17
- package/LexicalHeadingNode.prod.js +4 -3
- package/LexicalLinkNode.dev.js +2 -17
- package/LexicalLinkNode.prod.js +3 -3
- package/LexicalQuoteNode.dev.js +2 -17
- package/LexicalQuoteNode.prod.js +3 -3
- package/README.md +1 -1
- package/package.json +1 -1
- package/HashtagNode.js +0 -9
- package/HashtagNode.js.flow +0 -27
- package/LexicalHashtagNode.dev.js +0 -111
- package/LexicalHashtagNode.prod.js +0 -9
package/Lexical.d.ts
CHANGED
|
@@ -97,7 +97,7 @@ export declare class LexicalEditor {
|
|
|
97
97
|
klass: Class<LexicalNode>,
|
|
98
98
|
listener: MutationListener,
|
|
99
99
|
): () => void;
|
|
100
|
-
|
|
100
|
+
addNodeTransform<T extends LexicalNode>(
|
|
101
101
|
klass: Class<T>,
|
|
102
102
|
listener: Transform<T>,
|
|
103
103
|
): () => void;
|
|
@@ -144,17 +144,9 @@ export type EditorThemeClasses = {
|
|
|
144
144
|
//@ts-expect-error
|
|
145
145
|
list?: {
|
|
146
146
|
ul?: EditorThemeClassName;
|
|
147
|
-
|
|
148
|
-
ul2?: EditorThemeClassName;
|
|
149
|
-
ul3?: EditorThemeClassName;
|
|
150
|
-
ul4?: EditorThemeClassName;
|
|
151
|
-
ul5?: EditorThemeClassName;
|
|
147
|
+
ulDepth?: Array<EditorThemeClassName>;
|
|
152
148
|
ol?: EditorThemeClassName;
|
|
153
|
-
|
|
154
|
-
ol2?: EditorThemeClassName;
|
|
155
|
-
ol3?: EditorThemeClassName;
|
|
156
|
-
ol4?: EditorThemeClassName;
|
|
157
|
-
ol5?: EditorThemeClassName;
|
|
149
|
+
olDepth?: Array<EditorThemeClassName>;
|
|
158
150
|
listitem?: EditorThemeClassName;
|
|
159
151
|
nested?: {
|
|
160
152
|
list?: EditorThemeClassName;
|
|
@@ -370,18 +362,28 @@ interface BaseSelection {
|
|
|
370
362
|
insertRawText(text: string): void;
|
|
371
363
|
is(selection: null | RangeSelection | NodeSelection | GridSelection): boolean;
|
|
372
364
|
}
|
|
365
|
+
export type GridSelectionShape = {
|
|
366
|
+
fromX: number;
|
|
367
|
+
fromY: number;
|
|
368
|
+
toX: number;
|
|
369
|
+
toY: number;
|
|
370
|
+
};
|
|
373
371
|
export declare class GridSelection {
|
|
374
372
|
gridKey: NodeKey;
|
|
375
373
|
anchorCellKey: NodeKey;
|
|
374
|
+
anchor: PointType;
|
|
376
375
|
focusCellKey: NodeKey;
|
|
376
|
+
focus: PointType;
|
|
377
377
|
dirty: boolean;
|
|
378
378
|
constructor(gridKey: NodeKey, anchorCellKey: NodeKey, focusCellKey: NodeKey);
|
|
379
379
|
is(selection: null | RangeSelection | NodeSelection | GridSelection): boolean;
|
|
380
380
|
set(gridKey: NodeKey, anchorCellKey: NodeKey, focusCellKey: NodeKey): void;
|
|
381
381
|
clone(): GridSelection;
|
|
382
382
|
extract(): Array<LexicalNode>;
|
|
383
|
+
isCollapsed(): boolean;
|
|
383
384
|
insertRawText(): void;
|
|
384
385
|
insertText(): void;
|
|
386
|
+
getShape(): GridSelectionShape;
|
|
385
387
|
getNodes(): Array<LexicalNode>;
|
|
386
388
|
getTextContent(): string;
|
|
387
389
|
}
|
package/Lexical.dev.js
CHANGED
|
@@ -137,12 +137,19 @@ const scheduleMicroTask = typeof queueMicrotask === 'function' ? queueMicrotask
|
|
|
137
137
|
// No window prefix intended (#1400)
|
|
138
138
|
Promise.resolve().then(fn);
|
|
139
139
|
};
|
|
140
|
+
|
|
141
|
+
function isSelectionCapturedInDecoratorInput(anchorDOM) {
|
|
142
|
+
const activeElement = document.activeElement;
|
|
143
|
+
const nodeName = activeElement !== null ? activeElement.nodeName : null;
|
|
144
|
+
return !$isDecoratorNode($getNearestNodeFromDOMNode(anchorDOM)) || nodeName !== 'INPUT' && nodeName !== 'TEXTAREA';
|
|
145
|
+
}
|
|
146
|
+
|
|
140
147
|
function isSelectionWithinEditor(editor, anchorDOM, focusDOM) {
|
|
141
148
|
const rootElement = editor.getRootElement();
|
|
142
149
|
|
|
143
150
|
try {
|
|
144
151
|
return rootElement !== null && rootElement.contains(anchorDOM) && rootElement.contains(focusDOM) && // Ignore if selection is within nested editor
|
|
145
|
-
anchorDOM !== null && getNearestEditorFromDOMNode(anchorDOM) === editor;
|
|
152
|
+
anchorDOM !== null && isSelectionCapturedInDecoratorInput(anchorDOM) && getNearestEditorFromDOMNode(anchorDOM) === editor;
|
|
146
153
|
} catch (error) {
|
|
147
154
|
return false;
|
|
148
155
|
}
|
|
@@ -722,12 +729,18 @@ function getCachedClassNameArray(classNamesTheme, classNameThemeType) {
|
|
|
722
729
|
|
|
723
730
|
return classNames;
|
|
724
731
|
}
|
|
725
|
-
function setMutatedNode(mutatedNodes, registeredNodes, node, mutation) {
|
|
726
|
-
|
|
732
|
+
function setMutatedNode(mutatedNodes, registeredNodes, mutationListeners, node, mutation) {
|
|
733
|
+
if (mutationListeners.size === 0) {
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
const nodeType = node.__type;
|
|
738
|
+
const nodeKey = node.__key;
|
|
739
|
+
const registeredNode = registeredNodes.get(nodeType);
|
|
727
740
|
|
|
728
741
|
if (registeredNode === undefined) {
|
|
729
742
|
{
|
|
730
|
-
throw Error(`Type ${
|
|
743
|
+
throw Error(`Type ${nodeType} not in registeredNodes`);
|
|
731
744
|
}
|
|
732
745
|
}
|
|
733
746
|
|
|
@@ -739,7 +752,9 @@ function setMutatedNode(mutatedNodes, registeredNodes, node, mutation) {
|
|
|
739
752
|
mutatedNodes.set(klass, mutatedNodesByType);
|
|
740
753
|
}
|
|
741
754
|
|
|
742
|
-
mutatedNodesByType.
|
|
755
|
+
if (!mutatedNodesByType.has(nodeKey)) {
|
|
756
|
+
mutatedNodesByType.set(nodeKey, mutation);
|
|
757
|
+
}
|
|
743
758
|
}
|
|
744
759
|
function $nodesOfType(klass) {
|
|
745
760
|
const editorState = getActiveEditorState();
|
|
@@ -800,6 +815,11 @@ function $getDecoratorNode(focus, isBackward) {
|
|
|
800
815
|
|
|
801
816
|
return null;
|
|
802
817
|
}
|
|
818
|
+
function isFirefoxClipboardEvents() {
|
|
819
|
+
const event = window.event;
|
|
820
|
+
const inputType = event && event.inputType;
|
|
821
|
+
return inputType === 'insertFromPaste' || inputType === 'insertFromPasteAsQuotation';
|
|
822
|
+
}
|
|
803
823
|
|
|
804
824
|
/**
|
|
805
825
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -1015,9 +1035,24 @@ function removeNode(nodeToRemove, restoreSelection) {
|
|
|
1015
1035
|
$updateElementSelectionOnCreateDeleteNode(selection, parent, index, -1);
|
|
1016
1036
|
}
|
|
1017
1037
|
|
|
1018
|
-
if (parent !== null && !$isRootNode(parent) && !parent.canBeEmpty() && parent.
|
|
1038
|
+
if (parent !== null && !$isRootNode(parent) && !parent.canBeEmpty() && parent.isEmpty()) {
|
|
1019
1039
|
removeNode(parent, restoreSelection);
|
|
1020
1040
|
}
|
|
1041
|
+
|
|
1042
|
+
if (parent !== null && $isRootNode(parent) && parent.isEmpty()) {
|
|
1043
|
+
parent.selectEnd();
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
function $getNodeByKeyOrThrow(key) {
|
|
1047
|
+
const node = $getNodeByKey(key);
|
|
1048
|
+
|
|
1049
|
+
if (node === null) {
|
|
1050
|
+
{
|
|
1051
|
+
throw Error(`Expected node with key ${key} to exist but it's not in the nodeMap.`);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
return node;
|
|
1021
1056
|
}
|
|
1022
1057
|
class LexicalNode {
|
|
1023
1058
|
// Flow doesn't support abstract classes unfortunately, so we can't _force_
|
|
@@ -1449,8 +1484,7 @@ class LexicalNode {
|
|
|
1449
1484
|
|
|
1450
1485
|
isComposing() {
|
|
1451
1486
|
return this.__key === $getCompositionKey();
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1487
|
+
}
|
|
1454
1488
|
|
|
1455
1489
|
getLatest() {
|
|
1456
1490
|
const latest = $getNodeByKey(this.__key);
|
|
@@ -1758,18 +1792,6 @@ class LexicalNode {
|
|
|
1758
1792
|
|
|
1759
1793
|
}
|
|
1760
1794
|
|
|
1761
|
-
function $getNodeByKeyOrThrow(key) {
|
|
1762
|
-
const node = $getNodeByKey(key);
|
|
1763
|
-
|
|
1764
|
-
if (node === null) {
|
|
1765
|
-
{
|
|
1766
|
-
throw Error(`Expected node with key ${key} to exist but it's not in the nodeMap.`);
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
return node;
|
|
1771
|
-
}
|
|
1772
|
-
|
|
1773
1795
|
function errorOnTypeKlassMismatch(type, klass) {
|
|
1774
1796
|
const registeredNode = getActiveEditor()._nodes.get(type); // Common error - split in its own invariant
|
|
1775
1797
|
|
|
@@ -2231,6 +2253,7 @@ let activeEditor$1;
|
|
|
2231
2253
|
let activeEditorNodes;
|
|
2232
2254
|
let treatAllNodesAsDirty = false;
|
|
2233
2255
|
let activeEditorStateReadOnly = false;
|
|
2256
|
+
let activeMutationListeners;
|
|
2234
2257
|
let activeTextDirection = null;
|
|
2235
2258
|
let activeDirtyElements;
|
|
2236
2259
|
let activeDirtyLeaves;
|
|
@@ -2259,7 +2282,7 @@ function destroyNode(key, parentDOM) {
|
|
|
2259
2282
|
}
|
|
2260
2283
|
|
|
2261
2284
|
if (node !== undefined) {
|
|
2262
|
-
setMutatedNode(mutatedNodes, activeEditorNodes, node, 'destroyed');
|
|
2285
|
+
setMutatedNode(mutatedNodes, activeEditorNodes, activeMutationListeners, node, 'destroyed');
|
|
2263
2286
|
}
|
|
2264
2287
|
}
|
|
2265
2288
|
|
|
@@ -2397,7 +2420,7 @@ function createNode(key, parentDOM, insertDOM) {
|
|
|
2397
2420
|
Object.freeze(node);
|
|
2398
2421
|
}
|
|
2399
2422
|
|
|
2400
|
-
setMutatedNode(mutatedNodes, activeEditorNodes, node, 'created');
|
|
2423
|
+
setMutatedNode(mutatedNodes, activeEditorNodes, activeMutationListeners, node, 'created');
|
|
2401
2424
|
return dom;
|
|
2402
2425
|
}
|
|
2403
2426
|
|
|
@@ -2604,6 +2627,10 @@ function reconcileNode(key, parentDOM) {
|
|
|
2604
2627
|
}
|
|
2605
2628
|
|
|
2606
2629
|
return dom;
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
if (prevNode !== nextNode && isDirty) {
|
|
2633
|
+
setMutatedNode(mutatedNodes, activeEditorNodes, activeMutationListeners, nextNode, 'updated');
|
|
2607
2634
|
} // Update node. If it returns true, we need to unmount and re-create the node
|
|
2608
2635
|
|
|
2609
2636
|
|
|
@@ -2788,6 +2815,7 @@ function reconcileRoot(prevEditorState, nextEditorState, editor, dirtyType, dirt
|
|
|
2788
2815
|
activeEditor$1 = editor;
|
|
2789
2816
|
activeEditorConfig = editor._config;
|
|
2790
2817
|
activeEditorNodes = editor._nodes;
|
|
2818
|
+
activeMutationListeners = activeEditor$1._listeners.mutation;
|
|
2791
2819
|
activeDirtyElements = dirtyElements;
|
|
2792
2820
|
activeDirtyLeaves = dirtyLeaves;
|
|
2793
2821
|
activePrevNodeMap = prevEditorState._nodeMap;
|
|
@@ -3666,6 +3694,7 @@ function $flushMutations(editor, mutations, observer) {
|
|
|
3666
3694
|
|
|
3667
3695
|
const currentEditorState = editor._editorState;
|
|
3668
3696
|
let shouldRevertSelection = false;
|
|
3697
|
+
let possibleTextForFirefoxPaste = '';
|
|
3669
3698
|
|
|
3670
3699
|
for (let i = 0; i < mutations.length; i++) {
|
|
3671
3700
|
const mutation = mutations[i];
|
|
@@ -3696,7 +3725,15 @@ function $flushMutations(editor, mutations, observer) {
|
|
|
3696
3725
|
const node = getNodeFromDOMNode(addedDOM);
|
|
3697
3726
|
const parentDOM = addedDOM.parentNode;
|
|
3698
3727
|
|
|
3699
|
-
if (parentDOM != null && node === null) {
|
|
3728
|
+
if (parentDOM != null && node === null && (addedDOM.nodeName !== 'BR' || !isManagedLineBreak(addedDOM, parentDOM, editor))) {
|
|
3729
|
+
if (IS_FIREFOX) {
|
|
3730
|
+
const possibleText = addedDOM.innerText || addedDOM.nodeValue;
|
|
3731
|
+
|
|
3732
|
+
if (possibleText) {
|
|
3733
|
+
possibleTextForFirefoxPaste += possibleText;
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
|
|
3700
3737
|
parentDOM.removeChild(addedDOM);
|
|
3701
3738
|
}
|
|
3702
3739
|
}
|
|
@@ -3791,13 +3828,17 @@ function $flushMutations(editor, mutations, observer) {
|
|
|
3791
3828
|
observer.takeRecords();
|
|
3792
3829
|
}
|
|
3793
3830
|
|
|
3794
|
-
|
|
3795
|
-
const selection = $getSelection() || getLastSelection(editor);
|
|
3831
|
+
const selection = $getSelection() || getLastSelection(editor);
|
|
3796
3832
|
|
|
3797
|
-
|
|
3833
|
+
if (selection !== null) {
|
|
3834
|
+
if (shouldRevertSelection) {
|
|
3798
3835
|
selection.dirty = true;
|
|
3799
3836
|
$setSelection(selection);
|
|
3800
3837
|
}
|
|
3838
|
+
|
|
3839
|
+
if (IS_FIREFOX && isFirefoxClipboardEvents()) {
|
|
3840
|
+
selection.insertRawText(possibleTextForFirefoxPaste);
|
|
3841
|
+
}
|
|
3801
3842
|
}
|
|
3802
3843
|
});
|
|
3803
3844
|
} finally {
|
|
@@ -4008,7 +4049,7 @@ class NodeSelection {
|
|
|
4008
4049
|
return this.getNodes();
|
|
4009
4050
|
}
|
|
4010
4051
|
|
|
4011
|
-
insertRawText() {// Do nothing?
|
|
4052
|
+
insertRawText(text) {// Do nothing?
|
|
4012
4053
|
}
|
|
4013
4054
|
|
|
4014
4055
|
insertText() {// Do nothing?
|
|
@@ -4048,7 +4089,9 @@ class GridSelection {
|
|
|
4048
4089
|
constructor(gridKey, anchorCellKey, focusCellKey) {
|
|
4049
4090
|
this.gridKey = gridKey;
|
|
4050
4091
|
this.anchorCellKey = anchorCellKey;
|
|
4092
|
+
this.anchor = $createPoint(anchorCellKey, 0, 'element');
|
|
4051
4093
|
this.focusCellKey = focusCellKey;
|
|
4094
|
+
this.focus = $createPoint(focusCellKey, 0, 'element');
|
|
4052
4095
|
this.dirty = false;
|
|
4053
4096
|
}
|
|
4054
4097
|
|
|
@@ -4071,18 +4114,90 @@ class GridSelection {
|
|
|
4071
4114
|
return new GridSelection(this.gridKey, this.anchorCellKey, this.focusCellKey);
|
|
4072
4115
|
}
|
|
4073
4116
|
|
|
4117
|
+
isCollapsed() {
|
|
4118
|
+
return false;
|
|
4119
|
+
}
|
|
4120
|
+
|
|
4074
4121
|
extract() {
|
|
4075
4122
|
return this.getNodes();
|
|
4076
4123
|
}
|
|
4077
4124
|
|
|
4078
|
-
insertRawText() {// Do nothing?
|
|
4125
|
+
insertRawText(text) {// Do nothing?
|
|
4079
4126
|
}
|
|
4080
4127
|
|
|
4081
4128
|
insertText() {// Do nothing?
|
|
4082
4129
|
}
|
|
4083
4130
|
|
|
4131
|
+
getShape() {
|
|
4132
|
+
const anchorCellNode = $getNodeByKey(this.anchorCellKey);
|
|
4133
|
+
|
|
4134
|
+
if (!anchorCellNode) {
|
|
4135
|
+
throw Error(`getNodes: expected to find AnchorNode`);
|
|
4136
|
+
}
|
|
4137
|
+
|
|
4138
|
+
const anchorCellNodeIndex = anchorCellNode.getIndexWithinParent();
|
|
4139
|
+
const anchorCelRoweIndex = anchorCellNode.getParentOrThrow().getIndexWithinParent();
|
|
4140
|
+
const focusCellNode = $getNodeByKey(this.focusCellKey);
|
|
4141
|
+
|
|
4142
|
+
if (!focusCellNode) {
|
|
4143
|
+
throw Error(`getNodes: expected to find FocusNode`);
|
|
4144
|
+
}
|
|
4145
|
+
|
|
4146
|
+
const focusCellNodeIndex = focusCellNode.getIndexWithinParent();
|
|
4147
|
+
const focusCellRowIndex = focusCellNode.getParentOrThrow().getIndexWithinParent();
|
|
4148
|
+
const startX = Math.min(anchorCellNodeIndex, focusCellNodeIndex);
|
|
4149
|
+
const stopX = Math.max(anchorCellNodeIndex, focusCellNodeIndex);
|
|
4150
|
+
const startY = Math.min(anchorCelRoweIndex, focusCellRowIndex);
|
|
4151
|
+
const stopY = Math.max(anchorCelRoweIndex, focusCellRowIndex);
|
|
4152
|
+
return {
|
|
4153
|
+
fromX: Math.min(startX, stopX),
|
|
4154
|
+
fromY: Math.min(startY, stopY),
|
|
4155
|
+
toX: Math.max(startX, stopX),
|
|
4156
|
+
toY: Math.max(startY, stopY)
|
|
4157
|
+
};
|
|
4158
|
+
}
|
|
4159
|
+
|
|
4084
4160
|
getNodes() {
|
|
4085
|
-
const nodes = [];
|
|
4161
|
+
const nodes = [];
|
|
4162
|
+
const {
|
|
4163
|
+
fromX,
|
|
4164
|
+
fromY,
|
|
4165
|
+
toX,
|
|
4166
|
+
toY
|
|
4167
|
+
} = this.getShape();
|
|
4168
|
+
const gridNode = $getNodeByKey(this.gridKey);
|
|
4169
|
+
|
|
4170
|
+
if (!$isGridNode(gridNode)) {
|
|
4171
|
+
{
|
|
4172
|
+
throw Error(`getNodes: expected to find GridNode`);
|
|
4173
|
+
}
|
|
4174
|
+
}
|
|
4175
|
+
|
|
4176
|
+
const gridRowNodes = gridNode.getChildren();
|
|
4177
|
+
|
|
4178
|
+
for (let r = fromY; r <= toY; r++) {
|
|
4179
|
+
const gridRowNode = gridRowNodes[r];
|
|
4180
|
+
|
|
4181
|
+
if (!$isGridRowNode(gridRowNode)) {
|
|
4182
|
+
{
|
|
4183
|
+
throw Error(`getNodes: expected to find GridRowNode`);
|
|
4184
|
+
}
|
|
4185
|
+
}
|
|
4186
|
+
|
|
4187
|
+
const gridCellNodes = gridRowNode.getChildren();
|
|
4188
|
+
|
|
4189
|
+
for (let c = fromX; c <= toX; c++) {
|
|
4190
|
+
const gridCellNode = gridCellNodes[c];
|
|
4191
|
+
|
|
4192
|
+
if (!$isGridCellNode(gridCellNode)) {
|
|
4193
|
+
{
|
|
4194
|
+
throw Error(`getNodes: expected to find GridCellNode`);
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4197
|
+
|
|
4198
|
+
nodes.push(gridCellNode);
|
|
4199
|
+
}
|
|
4200
|
+
}
|
|
4086
4201
|
|
|
4087
4202
|
return nodes;
|
|
4088
4203
|
}
|
|
@@ -4849,6 +4964,9 @@ class RangeSelection {
|
|
|
4849
4964
|
if ($isElementNode(target) && !$isElementNode(sibling)) {
|
|
4850
4965
|
target.append(sibling);
|
|
4851
4966
|
target = sibling;
|
|
4967
|
+
} else if (!$isElementNode(target) && !$isElementNode(sibling)) {
|
|
4968
|
+
target.insertBefore(sibling);
|
|
4969
|
+
target = sibling;
|
|
4852
4970
|
} else {
|
|
4853
4971
|
if ($isElementNode(sibling) && !sibling.canInsertAfter(target)) {
|
|
4854
4972
|
const prevParentClone = prevParent.constructor.clone(prevParent);
|
|
@@ -5455,7 +5573,7 @@ function internalCreateSelection(editor) {
|
|
|
5455
5573
|
const lastSelection = currentEditorState._selection;
|
|
5456
5574
|
const domSelection = getDOMSelection();
|
|
5457
5575
|
|
|
5458
|
-
if ($isNodeSelection(lastSelection)) {
|
|
5576
|
+
if ($isNodeSelection(lastSelection) || $isGridSelection(lastSelection)) {
|
|
5459
5577
|
return lastSelection.clone();
|
|
5460
5578
|
}
|
|
5461
5579
|
|
|
@@ -6286,7 +6404,7 @@ class RootNode extends ElementNode {
|
|
|
6286
6404
|
}
|
|
6287
6405
|
}
|
|
6288
6406
|
|
|
6289
|
-
insertBefore() {
|
|
6407
|
+
insertBefore(nodeToInsert) {
|
|
6290
6408
|
{
|
|
6291
6409
|
throw Error(`insertBefore: cannot be called on root nodes`);
|
|
6292
6410
|
}
|
|
@@ -6502,7 +6620,12 @@ function $canRemoveText(anchorNode, focusNode) {
|
|
|
6502
6620
|
function onBeforeInput(event, editor) {
|
|
6503
6621
|
const inputType = event.inputType; // We let the browser do its own thing for composition.
|
|
6504
6622
|
|
|
6505
|
-
if (inputType === 'deleteCompositionText' || inputType === 'insertCompositionText'
|
|
6623
|
+
if (inputType === 'deleteCompositionText' || inputType === 'insertCompositionText' || // If we're pasting in FF, we shouldn't get this event
|
|
6624
|
+
// as the `paste` event should have triggered, unless the
|
|
6625
|
+
// user has dom.event.clipboardevents.enabled disabled in
|
|
6626
|
+
// about:config. In that case, we need to process the
|
|
6627
|
+
// pasted content in the DOM mutation phase.
|
|
6628
|
+
IS_FIREFOX && isFirefoxClipboardEvents()) {
|
|
6506
6629
|
return;
|
|
6507
6630
|
}
|
|
6508
6631
|
|
|
@@ -6724,7 +6847,7 @@ function onCompositionStart(event, editor) {
|
|
|
6724
6847
|
});
|
|
6725
6848
|
}
|
|
6726
6849
|
|
|
6727
|
-
function
|
|
6850
|
+
function onCompositionEnd(event, editor) {
|
|
6728
6851
|
editor.update(() => {
|
|
6729
6852
|
const compositionKey = editor._compositionKey;
|
|
6730
6853
|
$setCompositionKey(null); // Handle termination of composition, as it can sometimes
|
|
@@ -6745,20 +6868,6 @@ function onCompositionEndInternal(event, editor) {
|
|
|
6745
6868
|
});
|
|
6746
6869
|
}
|
|
6747
6870
|
|
|
6748
|
-
function onCompositionEnd(event, editor) {
|
|
6749
|
-
if (IS_FIREFOX) {
|
|
6750
|
-
// The order of onInput and onCompositionEnd is different
|
|
6751
|
-
// in FF. Given that onInput will fire after onCompositionEnd
|
|
6752
|
-
// in FF, we need to defer the $logic for onCompositionEnd to
|
|
6753
|
-
// ensure that any possible onInput events fire before.
|
|
6754
|
-
setTimeout(() => {
|
|
6755
|
-
onCompositionEndInternal(event, editor);
|
|
6756
|
-
}, 0);
|
|
6757
|
-
} else {
|
|
6758
|
-
onCompositionEndInternal(event, editor);
|
|
6759
|
-
}
|
|
6760
|
-
}
|
|
6761
|
-
|
|
6762
6871
|
function updateAndroidSoftKeyFlagIfAny(event) {
|
|
6763
6872
|
lastKeyWasMaybeAndroidSoftKey = event.key === 'Unidentified' && event.keyCode === 229;
|
|
6764
6873
|
}
|
|
@@ -8046,7 +8155,7 @@ class BaseLexicalEditor {
|
|
|
8046
8155
|
}
|
|
8047
8156
|
}
|
|
8048
8157
|
|
|
8049
|
-
|
|
8158
|
+
addNodeTransform( // There's no Flow-safe way to preserve the T in Transform<T>, but <T: LexicalNode> in the
|
|
8050
8159
|
// declaration below guarantees these are LexicalNodes.
|
|
8051
8160
|
klass, listener) {
|
|
8052
8161
|
const type = klass.getType();
|
|
@@ -8241,7 +8350,7 @@ class BaseLexicalEditor {
|
|
|
8241
8350
|
*
|
|
8242
8351
|
*
|
|
8243
8352
|
*/
|
|
8244
|
-
const VERSION = '0.1.
|
|
8353
|
+
const VERSION = '0.1.15';
|
|
8245
8354
|
|
|
8246
8355
|
/**
|
|
8247
8356
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
package/Lexical.js.flow
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
type MutationListeners = Map<MutationListener, Class<LexicalNode>>;
|
|
15
|
-
export type NodeMutation = 'created' | 'destroyed';
|
|
15
|
+
export type NodeMutation = 'created' | 'updated' | 'destroyed';
|
|
16
16
|
type UpdateListener = ({
|
|
17
17
|
tags: Set<string>,
|
|
18
18
|
prevEditorState: EditorState,
|
|
@@ -107,7 +107,7 @@ declare export class LexicalEditor {
|
|
|
107
107
|
klass: Class<LexicalNode>,
|
|
108
108
|
listener: MutationListener,
|
|
109
109
|
): () => void;
|
|
110
|
-
|
|
110
|
+
addNodeTransform<T: LexicalNode>(
|
|
111
111
|
klass: Class<T>,
|
|
112
112
|
listener: Transform<T>,
|
|
113
113
|
): () => void;
|
|
@@ -155,17 +155,9 @@ export type EditorThemeClasses = {
|
|
|
155
155
|
image?: EditorThemeClassName,
|
|
156
156
|
list?: {
|
|
157
157
|
ul?: EditorThemeClassName,
|
|
158
|
-
|
|
159
|
-
ul2?: EditorThemeClassName,
|
|
160
|
-
ul3?: EditorThemeClassName,
|
|
161
|
-
ul4?: EditorThemeClassName,
|
|
162
|
-
ul5?: EditorThemeClassName,
|
|
158
|
+
ulDepth?: Array<EditorThemeClassName>,
|
|
163
159
|
ol?: EditorThemeClassName,
|
|
164
|
-
|
|
165
|
-
ol2?: EditorThemeClassName,
|
|
166
|
-
ol3?: EditorThemeClassName,
|
|
167
|
-
ol4?: EditorThemeClassName,
|
|
168
|
-
ol5?: EditorThemeClassName,
|
|
160
|
+
olDepth?: Array<EditorThemeClassName>,
|
|
169
161
|
listitem?: EditorThemeClassName,
|
|
170
162
|
nested?: {
|
|
171
163
|
list?: EditorThemeClassName,
|
|
@@ -175,7 +167,7 @@ export type EditorThemeClasses = {
|
|
|
175
167
|
table?: EditorThemeClassName,
|
|
176
168
|
tableRow?: EditorThemeClassName,
|
|
177
169
|
tableCell?: EditorThemeClassName,
|
|
178
|
-
|
|
170
|
+
tableCellHeader?: EditorThemeClassName,
|
|
179
171
|
link?: EditorThemeClassName,
|
|
180
172
|
quote?: EditorThemeClassName,
|
|
181
173
|
code?: EditorThemeClassName,
|
|
@@ -387,33 +379,33 @@ interface BaseSelection {
|
|
|
387
379
|
insertRawText(text: string): void;
|
|
388
380
|
is(selection: null | RangeSelection | NodeSelection | GridSelection): boolean;
|
|
389
381
|
}
|
|
390
|
-
|
|
382
|
+
export type GridSelectionShape = {
|
|
383
|
+
fromX: number,
|
|
384
|
+
fromY: number,
|
|
385
|
+
toX: number,
|
|
386
|
+
toY: number,
|
|
387
|
+
};
|
|
391
388
|
declare export class GridSelection implements BaseSelection {
|
|
392
389
|
gridKey: NodeKey;
|
|
393
390
|
anchorCellKey: NodeKey;
|
|
391
|
+
anchor: PointType;
|
|
394
392
|
focusCellKey: NodeKey;
|
|
393
|
+
focus: PointType;
|
|
395
394
|
dirty: boolean;
|
|
396
|
-
|
|
397
395
|
constructor(
|
|
398
396
|
gridKey: NodeKey,
|
|
399
397
|
anchorCellKey: NodeKey,
|
|
400
398
|
focusCellKey: NodeKey,
|
|
401
399
|
): void;
|
|
402
|
-
|
|
403
400
|
is(selection: null | RangeSelection | NodeSelection | GridSelection): boolean;
|
|
404
|
-
|
|
405
401
|
set(gridKey: NodeKey, anchorCellKey: NodeKey, focusCellKey: NodeKey): void;
|
|
406
|
-
|
|
407
402
|
clone(): GridSelection;
|
|
408
|
-
|
|
409
403
|
extract(): Array<LexicalNode>;
|
|
410
|
-
|
|
411
404
|
insertRawText(): void;
|
|
412
|
-
|
|
413
405
|
insertText(): void;
|
|
414
|
-
|
|
406
|
+
isCollapsed(): false;
|
|
407
|
+
getShape(): GridSelectionShape;
|
|
415
408
|
getNodes(): Array<LexicalNode>;
|
|
416
|
-
|
|
417
409
|
getTextContent(): string;
|
|
418
410
|
}
|
|
419
411
|
|