lexical 0.2.2 → 0.2.5
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 +71 -60
- package/Lexical.dev.js +653 -195
- package/Lexical.js.flow +30 -45
- package/Lexical.prod.js +164 -157
- package/package.json +1 -1
package/Lexical.d.ts
CHANGED
|
@@ -36,11 +36,13 @@ export var KEY_BACKSPACE_COMMAND: LexicalCommand<KeyboardEvent>;
|
|
|
36
36
|
export var KEY_ESCAPE_COMMAND: LexicalCommand<KeyboardEvent>;
|
|
37
37
|
export var KEY_DELETE_COMMAND: LexicalCommand<KeyboardEvent>;
|
|
38
38
|
export var KEY_TAB_COMMAND: LexicalCommand<KeyboardEvent>;
|
|
39
|
+
export var KEY_MODIFIER_COMMAND: LexicalCommand<KeyboardEvent>;
|
|
39
40
|
export var INDENT_CONTENT_COMMAND: LexicalCommand<void>;
|
|
40
41
|
export var OUTDENT_CONTENT_COMMAND: LexicalCommand<void>;
|
|
41
42
|
export var DROP_COMMAND: LexicalCommand<DragEvent>;
|
|
42
43
|
export var FORMAT_ELEMENT_COMMAND: LexicalCommand<ElementFormatType>;
|
|
43
44
|
export var DRAGSTART_COMMAND: LexicalCommand<DragEvent>;
|
|
45
|
+
export var DRAGEND_COMMAND: LexicalCommand<DragEvent>;
|
|
44
46
|
export var COPY_COMMAND: LexicalCommand<ClipboardEvent>;
|
|
45
47
|
export var CUT_COMMAND: LexicalCommand<ClipboardEvent>;
|
|
46
48
|
export var CLEAR_EDITOR_COMMAND: LexicalCommand<void>;
|
|
@@ -115,7 +117,7 @@ export declare class LexicalEditor {
|
|
|
115
117
|
_onError: ErrorHandler;
|
|
116
118
|
_decorators: Record<NodeKey, unknown>;
|
|
117
119
|
_pendingDecorators: null | Record<NodeKey, unknown>;
|
|
118
|
-
_config: EditorConfig
|
|
120
|
+
_config: EditorConfig;
|
|
119
121
|
_dirtyType: 0 | 1 | 2;
|
|
120
122
|
_cloneNotNeeded: Set<NodeKey>;
|
|
121
123
|
_dirtyLeaves: Set<NodeKey>;
|
|
@@ -144,7 +146,7 @@ export declare class LexicalEditor {
|
|
|
144
146
|
klass: Class<T>,
|
|
145
147
|
listener: Transform<T>,
|
|
146
148
|
): () => void;
|
|
147
|
-
dispatchCommand(type: string, payload: P): boolean;
|
|
149
|
+
dispatchCommand<P>(type: string, payload: P): boolean;
|
|
148
150
|
hasNodes(nodes: Array<Class<LexicalNode>>): boolean;
|
|
149
151
|
getDecorators<X>(): Record<NodeKey, X>;
|
|
150
152
|
getRootElement(): null | HTMLElement;
|
|
@@ -184,7 +186,6 @@ export type EditorThemeClasses = {
|
|
|
184
186
|
text?: TextNodeThemeClasses;
|
|
185
187
|
paragraph?: EditorThemeClassName;
|
|
186
188
|
image?: EditorThemeClassName;
|
|
187
|
-
//@ts-expect-error
|
|
188
189
|
list?: {
|
|
189
190
|
ul?: EditorThemeClassName;
|
|
190
191
|
ulDepth?: Array<EditorThemeClassName>;
|
|
@@ -213,12 +214,18 @@ export type EditorThemeClasses = {
|
|
|
213
214
|
h5?: EditorThemeClassName;
|
|
214
215
|
};
|
|
215
216
|
// Handle other generic values
|
|
216
|
-
[key: string]:
|
|
217
|
+
[key: string]:
|
|
218
|
+
| EditorThemeClassName
|
|
219
|
+
| Record<
|
|
220
|
+
string,
|
|
221
|
+
| EditorThemeClassName
|
|
222
|
+
| Array<EditorThemeClassName>
|
|
223
|
+
| Record<string, EditorThemeClassName>
|
|
224
|
+
>;
|
|
217
225
|
};
|
|
218
|
-
export type EditorConfig
|
|
226
|
+
export type EditorConfig = {
|
|
219
227
|
namespace: string;
|
|
220
228
|
theme: EditorThemeClasses;
|
|
221
|
-
context: EditorContext;
|
|
222
229
|
disableEvents?: boolean;
|
|
223
230
|
};
|
|
224
231
|
export type CommandListenerPriority = 0 | 1 | 2 | 3 | 4;
|
|
@@ -228,11 +235,10 @@ export const COMMAND_PRIORITY_NORMAL = 2;
|
|
|
228
235
|
export const COMMAND_PRIORITY_HIGH = 3;
|
|
229
236
|
export const COMMAND_PRIORITY_CRITICAL = 4;
|
|
230
237
|
export type IntentionallyMarkedAsDirtyElement = boolean;
|
|
231
|
-
export function createEditor
|
|
238
|
+
export function createEditor(editorConfig?: {
|
|
232
239
|
namespace?: string;
|
|
233
240
|
editorState?: EditorState;
|
|
234
241
|
theme?: EditorThemeClasses;
|
|
235
|
-
context?: EditorContext;
|
|
236
242
|
parentEditor?: LexicalEditor;
|
|
237
243
|
nodes?: Array<Class<LexicalNode>>;
|
|
238
244
|
onError: (error: Error) => void;
|
|
@@ -292,8 +298,8 @@ export type DOMConversionFn = (
|
|
|
292
298
|
) => DOMConversionOutput;
|
|
293
299
|
export type DOMChildConversion = (
|
|
294
300
|
lexicalNode: LexicalNode,
|
|
295
|
-
parentLexicalNode:
|
|
296
|
-
) =>
|
|
301
|
+
parentLexicalNode: LexicalNode | null,
|
|
302
|
+
) => LexicalNode | void | null;
|
|
297
303
|
export type DOMConversionMap = Record<
|
|
298
304
|
NodeName,
|
|
299
305
|
(node: Node) => DOMConversion | null
|
|
@@ -305,7 +311,7 @@ export type DOMConversionOutput = {
|
|
|
305
311
|
node: LexicalNode | null;
|
|
306
312
|
};
|
|
307
313
|
export type DOMExportOutput = {
|
|
308
|
-
after?: (generatedElement:
|
|
314
|
+
after?: (generatedElement: HTMLElement | null) => HTMLElement | null;
|
|
309
315
|
element: HTMLElement | null;
|
|
310
316
|
};
|
|
311
317
|
export type NodeKey = string;
|
|
@@ -349,18 +355,9 @@ export declare class LexicalNode {
|
|
|
349
355
|
includeDirectionless?: false,
|
|
350
356
|
): number;
|
|
351
357
|
exportDOM(editor: LexicalEditor): DOMExportOutput;
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
editor: LexicalEditor,
|
|
356
|
-
): HTMLElement;
|
|
357
|
-
// $FlowFixMe
|
|
358
|
-
updateDOM<EditorContext extends Record<string, any>>( // $FlowFixMe
|
|
359
|
-
prevNode: any,
|
|
360
|
-
dom: HTMLElement,
|
|
361
|
-
config: EditorConfig<EditorContext>,
|
|
362
|
-
): boolean;
|
|
363
|
-
remove(): void;
|
|
358
|
+
createDOM(config: EditorConfig, editor: LexicalEditor): HTMLElement;
|
|
359
|
+
updateDOM(prevNode: any, dom: HTMLElement, config: EditorConfig): boolean;
|
|
360
|
+
remove(preserveEmptyParent?: boolean): void;
|
|
364
361
|
replace<N extends LexicalNode>(replaceWith: N): N;
|
|
365
362
|
insertAfter(nodeToInsert: LexicalNode): LexicalNode;
|
|
366
363
|
insertBefore(nodeToInsert: LexicalNode): LexicalNode;
|
|
@@ -416,15 +413,14 @@ export type GridSelectionShape = {
|
|
|
416
413
|
};
|
|
417
414
|
export declare class GridSelection {
|
|
418
415
|
gridKey: NodeKey;
|
|
419
|
-
anchorCellKey: NodeKey;
|
|
420
416
|
anchor: PointType;
|
|
421
|
-
focusCellKey: NodeKey;
|
|
422
417
|
focus: PointType;
|
|
423
418
|
dirty: boolean;
|
|
424
|
-
constructor(gridKey: NodeKey,
|
|
419
|
+
constructor(gridKey: NodeKey, anchor: PointType, focus: PointType);
|
|
425
420
|
is(selection: null | RangeSelection | NodeSelection | GridSelection): boolean;
|
|
426
421
|
set(gridKey: NodeKey, anchorCellKey: NodeKey, focusCellKey: NodeKey): void;
|
|
427
422
|
clone(): GridSelection;
|
|
423
|
+
getCharacterOffsets(): [number, number];
|
|
428
424
|
extract(): Array<LexicalNode>;
|
|
429
425
|
isCollapsed(): boolean;
|
|
430
426
|
isBackward(): boolean;
|
|
@@ -434,7 +430,9 @@ export declare class GridSelection {
|
|
|
434
430
|
getNodes(): Array<LexicalNode>;
|
|
435
431
|
getTextContent(): string;
|
|
436
432
|
}
|
|
437
|
-
export function $isGridSelection(
|
|
433
|
+
export function $isGridSelection(
|
|
434
|
+
x: unknown | null | undefined,
|
|
435
|
+
): x is GridSelection;
|
|
438
436
|
export declare class NodeSelection {
|
|
439
437
|
_nodes: Set<NodeKey>;
|
|
440
438
|
dirty: boolean;
|
|
@@ -451,7 +449,9 @@ export declare class NodeSelection {
|
|
|
451
449
|
getNodes(): Array<LexicalNode>;
|
|
452
450
|
getTextContent(): string;
|
|
453
451
|
}
|
|
454
|
-
export function $isNodeSelection(
|
|
452
|
+
export function $isNodeSelection(
|
|
453
|
+
x: unknown | null | undefined,
|
|
454
|
+
): x is NodeSelection;
|
|
455
455
|
export declare class RangeSelection {
|
|
456
456
|
anchor: PointType;
|
|
457
457
|
focus: PointType;
|
|
@@ -481,6 +481,7 @@ export declare class RangeSelection {
|
|
|
481
481
|
insertNodes(nodes: Array<LexicalNode>, selectStart?: boolean): boolean;
|
|
482
482
|
insertParagraph(): void;
|
|
483
483
|
insertLineBreak(selectStart?: boolean): void;
|
|
484
|
+
getCharacterOffsets(): [number, number];
|
|
484
485
|
extract(): Array<LexicalNode>;
|
|
485
486
|
modify(
|
|
486
487
|
alter: 'move' | 'extend',
|
|
@@ -512,7 +513,6 @@ type ElementPointType = {
|
|
|
512
513
|
isBefore: (arg0: PointType) => boolean;
|
|
513
514
|
getNode: () => ElementNode;
|
|
514
515
|
set: (key: NodeKey, offset: number, type: 'text' | 'element') => void;
|
|
515
|
-
getCharacterOffset: () => number;
|
|
516
516
|
isAtNodeEnd: () => boolean;
|
|
517
517
|
};
|
|
518
518
|
export type Point = PointType;
|
|
@@ -525,7 +525,6 @@ declare class _Point {
|
|
|
525
525
|
constructor(key: NodeKey, offset: number, type: 'text' | 'element');
|
|
526
526
|
is(point: PointType): boolean;
|
|
527
527
|
isBefore(b: PointType): boolean;
|
|
528
|
-
getCharacterOffset(): number;
|
|
529
528
|
getNode(): LexicalNode;
|
|
530
529
|
set(key: NodeKey, offset: number, type: 'text' | 'element'): void;
|
|
531
530
|
}
|
|
@@ -533,7 +532,9 @@ declare class _Point {
|
|
|
533
532
|
export function $createRangeSelection(): RangeSelection;
|
|
534
533
|
export function $createNodeSelection(): NodeSelection;
|
|
535
534
|
export function $createGridSelection(): GridSelection;
|
|
536
|
-
export function $isRangeSelection(
|
|
535
|
+
export function $isRangeSelection(
|
|
536
|
+
x: unknown | null | undefined,
|
|
537
|
+
): x is RangeSelection;
|
|
537
538
|
export function $getSelection():
|
|
538
539
|
| null
|
|
539
540
|
| RangeSelection
|
|
@@ -557,15 +558,22 @@ export type TextFormatType =
|
|
|
557
558
|
| 'subscript'
|
|
558
559
|
| 'superscript';
|
|
559
560
|
type TextModeType = 'normal' | 'token' | 'segmented' | 'inert';
|
|
561
|
+
export type TextMark = {end: null | number; id: string; start: null | number};
|
|
562
|
+
|
|
563
|
+
export type TextMarks = Array<TextMark>;
|
|
560
564
|
export declare class TextNode extends LexicalNode {
|
|
561
565
|
__text: string;
|
|
562
566
|
__format: number;
|
|
563
567
|
__style: string;
|
|
564
568
|
__mode: 0 | 1 | 2 | 3;
|
|
565
569
|
__detail: number;
|
|
570
|
+
__marks: null | TextMarks;
|
|
566
571
|
static getType(): string;
|
|
567
572
|
static clone(node: any): TextNode;
|
|
568
573
|
constructor(text: string, key?: NodeKey);
|
|
574
|
+
getMark(id: string): null | TextMark;
|
|
575
|
+
setMark(id: string, start: null | number, end: null | number): void;
|
|
576
|
+
deleteMark(id: string): void;
|
|
569
577
|
getFormat(): number;
|
|
570
578
|
getStyle(): string;
|
|
571
579
|
isToken(): boolean;
|
|
@@ -578,14 +586,12 @@ export declare class TextNode extends LexicalNode {
|
|
|
578
586
|
getTextContent(includeInert?: boolean, includeDirectionless?: false): string;
|
|
579
587
|
getFormatFlags(type: TextFormatType, alignWithFormat: null | number): number;
|
|
580
588
|
// $FlowFixMe
|
|
581
|
-
createDOM
|
|
582
|
-
config: EditorConfig<EditorContext>,
|
|
583
|
-
): HTMLElement;
|
|
589
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
584
590
|
// $FlowFixMe
|
|
585
|
-
updateDOM
|
|
591
|
+
updateDOM(
|
|
586
592
|
prevNode: TextNode,
|
|
587
593
|
dom: HTMLElement,
|
|
588
|
-
config: EditorConfig
|
|
594
|
+
config: EditorConfig,
|
|
589
595
|
): boolean;
|
|
590
596
|
selectionTransform(
|
|
591
597
|
prevSelection: null | RangeSelection | NodeSelection | GridSelection,
|
|
@@ -611,7 +617,9 @@ export declare class TextNode extends LexicalNode {
|
|
|
611
617
|
mergeWithSibling(target: TextNode): TextNode;
|
|
612
618
|
}
|
|
613
619
|
export function $createTextNode(text?: string): TextNode;
|
|
614
|
-
export function $isTextNode(
|
|
620
|
+
export function $isTextNode(
|
|
621
|
+
node: LexicalNode | null | undefined,
|
|
622
|
+
): node is TextNode;
|
|
615
623
|
|
|
616
624
|
/**
|
|
617
625
|
* LexicalLineBreakNode
|
|
@@ -625,7 +633,9 @@ export declare class LineBreakNode extends LexicalNode {
|
|
|
625
633
|
updateDOM(): false;
|
|
626
634
|
}
|
|
627
635
|
export function $createLineBreakNode(): LineBreakNode;
|
|
628
|
-
export function $isLineBreakNode(
|
|
636
|
+
export function $isLineBreakNode(
|
|
637
|
+
node: LexicalNode | null | undefined,
|
|
638
|
+
): node is LineBreakNode;
|
|
629
639
|
|
|
630
640
|
/**
|
|
631
641
|
* LexicalRootNode
|
|
@@ -645,7 +655,9 @@ export declare class RootNode extends ElementNode {
|
|
|
645
655
|
append(...nodesToAppend: Array<LexicalNode>): ElementNode;
|
|
646
656
|
canBeEmpty(): false;
|
|
647
657
|
}
|
|
648
|
-
export function $isRootNode(
|
|
658
|
+
export function $isRootNode(
|
|
659
|
+
node: LexicalNode | null | undefined,
|
|
660
|
+
): node is RootNode;
|
|
649
661
|
|
|
650
662
|
/**
|
|
651
663
|
* LexicalElementNode
|
|
@@ -685,6 +697,7 @@ export declare class ElementNode extends LexicalNode {
|
|
|
685
697
|
setIndent(indentLevel: number): ElementNode;
|
|
686
698
|
insertNewAfter(selection: RangeSelection): null | LexicalNode;
|
|
687
699
|
canInsertTab(): boolean;
|
|
700
|
+
canIndent(): boolean;
|
|
688
701
|
collapseAtStart(selection: RangeSelection): boolean;
|
|
689
702
|
excludeFromCopy(): boolean;
|
|
690
703
|
canExtractContents(): boolean;
|
|
@@ -701,7 +714,9 @@ export declare class ElementNode extends LexicalNode {
|
|
|
701
714
|
nodesToInsert: Array<LexicalNode>,
|
|
702
715
|
): ElementNode;
|
|
703
716
|
}
|
|
704
|
-
export function $isElementNode(
|
|
717
|
+
export function $isElementNode(
|
|
718
|
+
node: LexicalNode | null | undefined,
|
|
719
|
+
): node is ElementNode;
|
|
705
720
|
|
|
706
721
|
/**
|
|
707
722
|
* LexicalDecoratorNode
|
|
@@ -710,23 +725,11 @@ export declare class DecoratorNode<X> extends LexicalNode {
|
|
|
710
725
|
constructor(key?: NodeKey);
|
|
711
726
|
decorate(editor: LexicalEditor): X;
|
|
712
727
|
isIsolated(): boolean;
|
|
728
|
+
isTopLevel(): boolean;
|
|
713
729
|
}
|
|
714
|
-
export function $isDecoratorNode(
|
|
715
|
-
|
|
716
|
-
/**
|
|
717
|
-
* LexicalHorizontalRuleNode
|
|
718
|
-
*/
|
|
719
|
-
export declare class HorizontalRuleNode extends LexicalNode {
|
|
720
|
-
static getType(): string;
|
|
721
|
-
static clone(node: HorizontalRuleNode): HorizontalRuleNode;
|
|
722
|
-
constructor(key?: NodeKey);
|
|
723
|
-
createDOM(): HTMLElement;
|
|
724
|
-
updateDOM(): false;
|
|
725
|
-
}
|
|
726
|
-
export function $createHorizontalRuleNode(): HorizontalRuleNode;
|
|
727
|
-
export function $isHorizontalRuleNode(
|
|
730
|
+
export function $isDecoratorNode(
|
|
728
731
|
node: LexicalNode | null | undefined,
|
|
729
|
-
):
|
|
732
|
+
): node is DecoratorNode<unknown>;
|
|
730
733
|
|
|
731
734
|
/**
|
|
732
735
|
* LexicalParagraphNode
|
|
@@ -735,22 +738,30 @@ export declare class ParagraphNode extends ElementNode {
|
|
|
735
738
|
getType(): string;
|
|
736
739
|
clone(node: ParagraphNode): ParagraphNode;
|
|
737
740
|
constructor(key?: NodeKey);
|
|
738
|
-
createDOM
|
|
741
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
739
742
|
updateDOM(prevNode: ParagraphNode, dom: HTMLElement): boolean;
|
|
740
743
|
insertNewAfter(): ParagraphNode;
|
|
741
744
|
collapseAtStart(): boolean;
|
|
742
745
|
}
|
|
743
746
|
export function $createParagraphNode(): ParagraphNode;
|
|
744
|
-
export function $isParagraphNode(
|
|
747
|
+
export function $isParagraphNode(
|
|
748
|
+
node: LexicalNode | null | undefined,
|
|
749
|
+
): node is ParagraphNode;
|
|
745
750
|
export declare class GridNode extends ElementNode {}
|
|
746
|
-
export function $isGridNode(
|
|
751
|
+
export function $isGridNode(
|
|
752
|
+
node: LexicalNode | null | undefined,
|
|
753
|
+
): node is GridNode;
|
|
747
754
|
export declare class GridRowNode extends ElementNode {}
|
|
748
|
-
export function $isGridRowNode(
|
|
755
|
+
export function $isGridRowNode(
|
|
756
|
+
node: LexicalNode | null | undefined,
|
|
757
|
+
): node is GridRowNode;
|
|
749
758
|
export declare class GridCellNode extends ElementNode {
|
|
750
759
|
__colSpan: number;
|
|
751
760
|
constructor(colSpan: number, key?: NodeKey);
|
|
752
761
|
}
|
|
753
|
-
export function $isGridCellNode(
|
|
762
|
+
export function $isGridCellNode(
|
|
763
|
+
node: LexicalNode | null | undefined,
|
|
764
|
+
): node is GridCellNode;
|
|
754
765
|
|
|
755
766
|
/**
|
|
756
767
|
* LexicalUtils
|