lexical 0.2.9 → 0.3.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.d.ts +144 -93
- package/Lexical.dev.js +4160 -4045
- package/Lexical.js.flow +122 -83
- package/Lexical.prod.js +170 -167
- package/package.json +1 -1
package/Lexical.js.flow
CHANGED
|
@@ -18,7 +18,7 @@ declare export var CLICK_COMMAND: LexicalCommand<MouseEvent>;
|
|
|
18
18
|
declare export var DELETE_CHARACTER_COMMAND: LexicalCommand<boolean>;
|
|
19
19
|
declare export var INSERT_LINE_BREAK_COMMAND: LexicalCommand<boolean>;
|
|
20
20
|
declare export var INSERT_PARAGRAPH_COMMAND: LexicalCommand<void>;
|
|
21
|
-
declare export var
|
|
21
|
+
declare export var CONTROLLED_TEXT_INSERTION_COMMAND: LexicalCommand<string>;
|
|
22
22
|
declare export var PASTE_COMMAND: LexicalCommand<ClipboardEvent>;
|
|
23
23
|
declare export var REMOVE_TEXT_COMMAND: LexicalCommand<void>;
|
|
24
24
|
declare export var DELETE_WORD_COMMAND: LexicalCommand<boolean>;
|
|
@@ -42,6 +42,7 @@ declare export var OUTDENT_CONTENT_COMMAND: LexicalCommand<void>;
|
|
|
42
42
|
declare export var DROP_COMMAND: LexicalCommand<DragEvent>;
|
|
43
43
|
declare export var FORMAT_ELEMENT_COMMAND: LexicalCommand<ElementFormatType>;
|
|
44
44
|
declare export var DRAGSTART_COMMAND: LexicalCommand<DragEvent>;
|
|
45
|
+
declare export var DRAGOVER_COMMAND: LexicalCommand<DragEvent>;
|
|
45
46
|
declare export var DRAGEND_COMMAND: LexicalCommand<DragEvent>;
|
|
46
47
|
declare export var COPY_COMMAND: LexicalCommand<ClipboardEvent>;
|
|
47
48
|
declare export var CUT_COMMAND: LexicalCommand<ClipboardEvent>;
|
|
@@ -163,14 +164,16 @@ declare export class LexicalEditor {
|
|
|
163
164
|
getElementByKey(key: NodeKey): null | HTMLElement;
|
|
164
165
|
getEditorState(): EditorState;
|
|
165
166
|
setEditorState(editorState: EditorState, options?: EditorSetOptions): void;
|
|
166
|
-
parseEditorState(
|
|
167
|
-
maybeStringifiedEditorState: string |
|
|
167
|
+
parseEditorState<SerializedNode>(
|
|
168
|
+
maybeStringifiedEditorState: string | SerializedEditorState<SerializedNode>,
|
|
169
|
+
updateFn?: () => void,
|
|
168
170
|
): EditorState;
|
|
169
171
|
update(updateFn: () => void, options?: EditorUpdateOptions): boolean;
|
|
170
172
|
focus(callbackFn?: () => void): void;
|
|
171
173
|
blur(): void;
|
|
172
174
|
isReadOnly(): boolean;
|
|
173
175
|
setReadOnly(readOnly: boolean): void;
|
|
176
|
+
toJSON(): SerializedEditor<>;
|
|
174
177
|
}
|
|
175
178
|
type EditorUpdateOptions = {
|
|
176
179
|
onUpdate?: () => void,
|
|
@@ -233,7 +236,6 @@ export type EditorThemeClasses = {
|
|
|
233
236
|
[string]: EditorThemeClassName | {[string]: EditorThemeClassName},
|
|
234
237
|
};
|
|
235
238
|
export type EditorConfig = {
|
|
236
|
-
namespace: string,
|
|
237
239
|
theme: EditorThemeClasses,
|
|
238
240
|
disableEvents?: boolean,
|
|
239
241
|
};
|
|
@@ -246,7 +248,6 @@ export const COMMAND_PRIORITY_CRITICAL = 4;
|
|
|
246
248
|
|
|
247
249
|
export type IntentionallyMarkedAsDirtyElement = boolean;
|
|
248
250
|
declare export function createEditor(editorConfig?: {
|
|
249
|
-
namespace?: string,
|
|
250
251
|
editorState?: EditorState,
|
|
251
252
|
theme?: EditorThemeClasses,
|
|
252
253
|
parentEditor?: LexicalEditor,
|
|
@@ -259,25 +260,6 @@ declare export function createEditor(editorConfig?: {
|
|
|
259
260
|
/**
|
|
260
261
|
* LexicalEditorState
|
|
261
262
|
*/
|
|
262
|
-
export type ParsedEditorState = {
|
|
263
|
-
_selection: null | {
|
|
264
|
-
anchor: {
|
|
265
|
-
key: string,
|
|
266
|
-
offset: number,
|
|
267
|
-
type: 'text' | 'element',
|
|
268
|
-
},
|
|
269
|
-
focus: {
|
|
270
|
-
key: string,
|
|
271
|
-
offset: number,
|
|
272
|
-
type: 'text' | 'element',
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
_nodeMap: Array<[NodeKey, ParsedNode]>,
|
|
276
|
-
};
|
|
277
|
-
type JSONEditorState = {
|
|
278
|
-
_nodeMap: Array<[NodeKey, LexicalNode]>,
|
|
279
|
-
_selection: null | ParsedSelection,
|
|
280
|
-
};
|
|
281
263
|
|
|
282
264
|
export interface EditorState {
|
|
283
265
|
_nodeMap: NodeMap;
|
|
@@ -290,7 +272,7 @@ export interface EditorState {
|
|
|
290
272
|
): void;
|
|
291
273
|
isEmpty(): boolean;
|
|
292
274
|
read<V>(callbackFn: () => V): V;
|
|
293
|
-
toJSON(
|
|
275
|
+
toJSON<SerializedNode>(): SerializedEditorState<SerializedNode>;
|
|
294
276
|
clone(
|
|
295
277
|
selection?: RangeSelection | NodeSelection | GridSelection | null,
|
|
296
278
|
): EditorState;
|
|
@@ -335,22 +317,23 @@ declare export class LexicalNode {
|
|
|
335
317
|
static importDOM(): DOMConversionMap | null;
|
|
336
318
|
constructor(key?: NodeKey): void;
|
|
337
319
|
exportDOM(editor: LexicalEditor): DOMExportOutput;
|
|
320
|
+
exportJSON(): SerializedLexicalNode;
|
|
338
321
|
getType(): string;
|
|
339
322
|
isAttached(): boolean;
|
|
340
323
|
isSelected(): boolean;
|
|
341
324
|
getKey(): NodeKey;
|
|
342
325
|
getIndexWithinParent(): number;
|
|
343
|
-
getParent():
|
|
344
|
-
getParentOrThrow():
|
|
345
|
-
getTopLevelElement():
|
|
326
|
+
getParent<T: ElementNode>(): T | null;
|
|
327
|
+
getParentOrThrow<T: ElementNode>(): T;
|
|
328
|
+
getTopLevelElement(): ElementNode | null;
|
|
346
329
|
getTopLevelElementOrThrow(): ElementNode;
|
|
347
|
-
getParents(): Array<
|
|
330
|
+
getParents<T: ElementNode>(): Array<T>;
|
|
348
331
|
getParentKeys(): Array<NodeKey>;
|
|
349
|
-
getPreviousSibling():
|
|
350
|
-
getPreviousSiblings(): Array<
|
|
351
|
-
getNextSibling():
|
|
352
|
-
getNextSiblings(): Array<
|
|
353
|
-
getCommonAncestor(node: LexicalNode):
|
|
332
|
+
getPreviousSibling<T: LexicalNode>(): T | null;
|
|
333
|
+
getPreviousSiblings<T: LexicalNode>(): Array<T>;
|
|
334
|
+
getNextSibling<T: LexicalNode>(): T | null;
|
|
335
|
+
getNextSiblings<T: LexicalNode>(): Array<T>;
|
|
336
|
+
getCommonAncestor<T: ElementNode>(node: LexicalNode): T | null;
|
|
354
337
|
is(object: ?LexicalNode): boolean;
|
|
355
338
|
isBefore(targetNode: LexicalNode): boolean;
|
|
356
339
|
isParentOf(targetNode: LexicalNode): boolean;
|
|
@@ -376,40 +359,12 @@ declare export class LexicalNode {
|
|
|
376
359
|
replace<N: LexicalNode>(replaceWith: N): N;
|
|
377
360
|
insertAfter(nodeToInsert: LexicalNode): LexicalNode;
|
|
378
361
|
insertBefore(nodeToInsert: LexicalNode): LexicalNode;
|
|
379
|
-
selectPrevious(anchorOffset?: number, focusOffset?: number):
|
|
380
|
-
selectNext(anchorOffset?: number, focusOffset?: number):
|
|
362
|
+
selectPrevious(anchorOffset?: number, focusOffset?: number): RangeSelection;
|
|
363
|
+
selectNext(anchorOffset?: number, focusOffset?: number): RangeSelection;
|
|
381
364
|
markDirty(): void;
|
|
382
365
|
}
|
|
383
366
|
export type NodeMap = Map<NodeKey, LexicalNode>;
|
|
384
367
|
|
|
385
|
-
/**
|
|
386
|
-
* LexicalParsing
|
|
387
|
-
*/
|
|
388
|
-
|
|
389
|
-
export type ParsedNode = {
|
|
390
|
-
__key: NodeKey,
|
|
391
|
-
__type: string,
|
|
392
|
-
__parent: null | NodeKey,
|
|
393
|
-
...
|
|
394
|
-
};
|
|
395
|
-
export type ParsedNodeMap = Map<NodeKey, ParsedNode>;
|
|
396
|
-
declare export function $createNodeFromParse(
|
|
397
|
-
parsedNode: ParsedNode,
|
|
398
|
-
parsedNodeMap: ParsedNodeMap,
|
|
399
|
-
): LexicalNode;
|
|
400
|
-
type ParsedSelection = {
|
|
401
|
-
anchor: {
|
|
402
|
-
key: NodeKey,
|
|
403
|
-
offset: number,
|
|
404
|
-
type: 'text' | 'element',
|
|
405
|
-
},
|
|
406
|
-
focus: {
|
|
407
|
-
key: NodeKey,
|
|
408
|
-
offset: number,
|
|
409
|
-
type: 'text' | 'element',
|
|
410
|
-
},
|
|
411
|
-
};
|
|
412
|
-
|
|
413
368
|
/**
|
|
414
369
|
* LexicalSelection
|
|
415
370
|
*/
|
|
@@ -630,6 +585,9 @@ declare export class TextNode extends LexicalNode {
|
|
|
630
585
|
toggleDirectionless(): this;
|
|
631
586
|
toggleUnmergeable(): this;
|
|
632
587
|
setMode(type: TextModeType): this;
|
|
588
|
+
setDetail(detail: number): this;
|
|
589
|
+
getDetail(): number;
|
|
590
|
+
getMode(): TextModeType;
|
|
633
591
|
setTextContent(text: string): TextNode;
|
|
634
592
|
select(_anchorOffset?: number, _focusOffset?: number): RangeSelection;
|
|
635
593
|
spliceText(
|
|
@@ -643,6 +601,8 @@ declare export class TextNode extends LexicalNode {
|
|
|
643
601
|
splitText(...splitOffsets: Array<number>): Array<TextNode>;
|
|
644
602
|
mergeWithSibling(target: TextNode): TextNode;
|
|
645
603
|
isTextEntity(): boolean;
|
|
604
|
+
static importJSON(serializedTextNode: SerializedTextNode): TextNode;
|
|
605
|
+
exportJSON(): SerializedTextNode;
|
|
646
606
|
}
|
|
647
607
|
declare export function $createTextNode(text?: string): TextNode;
|
|
648
608
|
declare export function $isTextNode(
|
|
@@ -660,6 +620,10 @@ declare export class LineBreakNode extends LexicalNode {
|
|
|
660
620
|
getTextContent(): '\n';
|
|
661
621
|
createDOM(): HTMLElement;
|
|
662
622
|
updateDOM(): false;
|
|
623
|
+
static importJSON(
|
|
624
|
+
serializedLineBreakNode: SerializedLineBreakNode,
|
|
625
|
+
): LineBreakNode;
|
|
626
|
+
exportJSON(): SerializedLexicalNode;
|
|
663
627
|
}
|
|
664
628
|
declare export function $createLineBreakNode(): LineBreakNode;
|
|
665
629
|
declare export function $isLineBreakNode(
|
|
@@ -679,10 +643,10 @@ declare export class RootNode extends ElementNode {
|
|
|
679
643
|
select(): RangeSelection;
|
|
680
644
|
remove(): void;
|
|
681
645
|
replace<N: LexicalNode>(node: N): N;
|
|
682
|
-
insertBefore():
|
|
683
|
-
insertAfter(
|
|
646
|
+
insertBefore<T: LexicalNode>(nodeToInsert: T): T;
|
|
647
|
+
insertAfter<T: LexicalNode>(nodeToInsert: T): T;
|
|
684
648
|
updateDOM(prevNode: RootNode, dom: HTMLElement): false;
|
|
685
|
-
append(...nodesToAppend: Array<LexicalNode>):
|
|
649
|
+
append(...nodesToAppend: Array<LexicalNode>): this;
|
|
686
650
|
canBeEmpty(): false;
|
|
687
651
|
}
|
|
688
652
|
declare export function $isRootNode(
|
|
@@ -692,7 +656,7 @@ declare export function $isRootNode(
|
|
|
692
656
|
/**
|
|
693
657
|
* LexicalElementNode
|
|
694
658
|
*/
|
|
695
|
-
export type ElementFormatType = 'left' | 'center' | 'right' | 'justify';
|
|
659
|
+
export type ElementFormatType = 'left' | 'center' | 'right' | 'justify' | '';
|
|
696
660
|
declare export class ElementNode extends LexicalNode {
|
|
697
661
|
__children: Array<NodeKey>;
|
|
698
662
|
__format: number;
|
|
@@ -700,28 +664,30 @@ declare export class ElementNode extends LexicalNode {
|
|
|
700
664
|
__dir: 'ltr' | 'rtl' | null;
|
|
701
665
|
constructor(key?: NodeKey): void;
|
|
702
666
|
getFormat(): number;
|
|
667
|
+
getFormatType(): ElementFormatType;
|
|
703
668
|
getIndent(): number;
|
|
704
|
-
getChildren(): Array<
|
|
669
|
+
getChildren<T: LexicalNode>(): Array<T>;
|
|
670
|
+
getChildren<T: Array<LexicalNode>>(): T;
|
|
705
671
|
getChildrenKeys(): Array<NodeKey>;
|
|
706
672
|
getChildrenSize(): number;
|
|
707
673
|
isEmpty(): boolean;
|
|
708
674
|
isDirty(): boolean;
|
|
709
675
|
getAllTextNodes(includeInert?: boolean): Array<TextNode>;
|
|
710
|
-
getFirstDescendant(): null |
|
|
711
|
-
getLastDescendant(): null |
|
|
712
|
-
getDescendantByIndex(index: number):
|
|
676
|
+
getFirstDescendant<T: LexicalNode>(): null | T;
|
|
677
|
+
getLastDescendant<T: LexicalNode>(): null | T;
|
|
678
|
+
getDescendantByIndex<T: LexicalNode>(index: number): null | T;
|
|
713
679
|
getFirstChild<T: LexicalNode>(): null | T;
|
|
714
680
|
getFirstChildOrThrow<T: LexicalNode>(): T;
|
|
715
|
-
getLastChild(): null |
|
|
716
|
-
getChildAtIndex(index: number): null |
|
|
681
|
+
getLastChild<T: LexicalNode>(): null | T;
|
|
682
|
+
getChildAtIndex<T: LexicalNode>(index: number): null | T;
|
|
717
683
|
getTextContent(includeInert?: boolean, includeDirectionless?: false): string;
|
|
718
684
|
getDirection(): 'ltr' | 'rtl' | null;
|
|
719
685
|
hasFormat(type: ElementFormatType): boolean;
|
|
720
686
|
select(_anchorOffset?: number, _focusOffset?: number): RangeSelection;
|
|
721
687
|
selectStart(): RangeSelection;
|
|
722
688
|
selectEnd(): RangeSelection;
|
|
723
|
-
clear():
|
|
724
|
-
append(...nodesToAppend: Array<LexicalNode>):
|
|
689
|
+
clear(): this;
|
|
690
|
+
append(...nodesToAppend: Array<LexicalNode>): this;
|
|
725
691
|
setDirection(direction: 'ltr' | 'rtl' | null): this;
|
|
726
692
|
setFormat(type: ElementFormatType): this;
|
|
727
693
|
setIndent(indentLevel: number): this;
|
|
@@ -747,7 +713,8 @@ declare export class ElementNode extends LexicalNode {
|
|
|
747
713
|
start: number,
|
|
748
714
|
deleteCount: number,
|
|
749
715
|
nodesToInsert: Array<LexicalNode>,
|
|
750
|
-
):
|
|
716
|
+
): this;
|
|
717
|
+
exportJSON(): SerializedElementNode;
|
|
751
718
|
}
|
|
752
719
|
declare export function $isElementNode(
|
|
753
720
|
node: ?LexicalNode,
|
|
@@ -778,6 +745,10 @@ declare export class ParagraphNode extends ElementNode {
|
|
|
778
745
|
updateDOM(prevNode: ParagraphNode, dom: HTMLElement): boolean;
|
|
779
746
|
insertNewAfter(): ParagraphNode;
|
|
780
747
|
collapseAtStart(): boolean;
|
|
748
|
+
static importJSON(
|
|
749
|
+
serializedParagraphNode: SerializedParagraphNode,
|
|
750
|
+
): ParagraphNode;
|
|
751
|
+
exportJSON(): SerializedElementNode;
|
|
781
752
|
}
|
|
782
753
|
declare export function $createParagraphNode(): ParagraphNode;
|
|
783
754
|
declare export function $isParagraphNode(
|
|
@@ -809,6 +780,8 @@ declare export function $isGridCellNode(
|
|
|
809
780
|
/**
|
|
810
781
|
* LexicalUtils
|
|
811
782
|
*/
|
|
783
|
+
declare export function $hasUpdateTag(tag: string): boolean;
|
|
784
|
+
declare export function $addUpdateTag(tag: string): void;
|
|
812
785
|
declare export function $getNearestNodeFromDOMNode(
|
|
813
786
|
startingDOM: Node,
|
|
814
787
|
): LexicalNode | null;
|
|
@@ -831,14 +804,80 @@ declare export function $getDecoratorNode(
|
|
|
831
804
|
isBackward: boolean,
|
|
832
805
|
): null | LexicalNode;
|
|
833
806
|
|
|
834
|
-
|
|
835
|
-
export type EventHandler = (
|
|
836
|
-
// $FlowFixMe: not sure how to handle this generic properly
|
|
837
|
-
event: Object,
|
|
838
|
-
editor: LexicalEditor,
|
|
839
|
-
) => void;
|
|
807
|
+
export type EventHandler = (event: Event, editor: LexicalEditor) => void;
|
|
840
808
|
|
|
841
809
|
/**
|
|
842
810
|
* LexicalVersion
|
|
843
811
|
*/
|
|
844
812
|
declare export var VERSION: string;
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Serialization/Deserialization
|
|
816
|
+
* */
|
|
817
|
+
|
|
818
|
+
type InternalSerializedNode = {
|
|
819
|
+
children?: Array<InternalSerializedNode>,
|
|
820
|
+
type: string,
|
|
821
|
+
version: number,
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
declare export function $parseSerializedNode(
|
|
825
|
+
serializedNode: InternalSerializedNode,
|
|
826
|
+
): LexicalNode;
|
|
827
|
+
|
|
828
|
+
export type SerializedLexicalNode = {
|
|
829
|
+
type: string,
|
|
830
|
+
version: number,
|
|
831
|
+
...
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
export type SerializedTextNode = {
|
|
835
|
+
...SerializedLexicalNode,
|
|
836
|
+
detail: number,
|
|
837
|
+
format: number,
|
|
838
|
+
mode: TextModeType,
|
|
839
|
+
style: string,
|
|
840
|
+
text: string,
|
|
841
|
+
...
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
export type SerializedElementNode = {
|
|
845
|
+
...SerializedLexicalNode,
|
|
846
|
+
children: Array<SerializedLexicalNode>,
|
|
847
|
+
direction: 'ltr' | 'rtl' | null,
|
|
848
|
+
format: ElementFormatType,
|
|
849
|
+
indent: number,
|
|
850
|
+
...
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
export type SerializedParagraphNode = {
|
|
854
|
+
...SerializedElementNode,
|
|
855
|
+
type: 'paragraph',
|
|
856
|
+
...
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
export type SerializedLineBreakNode = {
|
|
860
|
+
...SerializedLexicalNode,
|
|
861
|
+
type: 'linebreak',
|
|
862
|
+
...
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
export type SerializedRootNode = {
|
|
866
|
+
...SerializedElementNode,
|
|
867
|
+
type: 'root',
|
|
868
|
+
...
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
export type SerializedGridCellNode = {
|
|
872
|
+
...SerializedElementNode,
|
|
873
|
+
colSpan: number,
|
|
874
|
+
...
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
export interface SerializedEditorState<SerializedNode> {
|
|
878
|
+
root: SerializedRootNode<SerializedNode>;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
export type SerializedEditor<SerializedNode> = {
|
|
882
|
+
editorState: SerializedEditorState<SerializedNode>,
|
|
883
|
+
};
|