lexical 0.2.3 → 0.2.6

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 CHANGED
@@ -32,6 +32,7 @@ export var KEY_ARROW_LEFT_COMMAND: LexicalCommand<KeyboardEvent>;
32
32
  export var KEY_ARROW_UP_COMMAND: LexicalCommand<KeyboardEvent>;
33
33
  export var KEY_ARROW_DOWN_COMMAND: LexicalCommand<KeyboardEvent>;
34
34
  export var KEY_ENTER_COMMAND: LexicalCommand<KeyboardEvent | null>;
35
+ export var KEY_SPACE_COMMAND: LexicalCommand<KeyboardEvent>;
35
36
  export var KEY_BACKSPACE_COMMAND: LexicalCommand<KeyboardEvent>;
36
37
  export var KEY_ESCAPE_COMMAND: LexicalCommand<KeyboardEvent>;
37
38
  export var KEY_DELETE_COMMAND: LexicalCommand<KeyboardEvent>;
@@ -42,6 +43,7 @@ export var OUTDENT_CONTENT_COMMAND: LexicalCommand<void>;
42
43
  export var DROP_COMMAND: LexicalCommand<DragEvent>;
43
44
  export var FORMAT_ELEMENT_COMMAND: LexicalCommand<ElementFormatType>;
44
45
  export var DRAGSTART_COMMAND: LexicalCommand<DragEvent>;
46
+ export var DRAGEND_COMMAND: LexicalCommand<DragEvent>;
45
47
  export var COPY_COMMAND: LexicalCommand<ClipboardEvent>;
46
48
  export var CUT_COMMAND: LexicalCommand<ClipboardEvent>;
47
49
  export var CLEAR_EDITOR_COMMAND: LexicalCommand<void>;
@@ -62,7 +64,7 @@ export declare function createCommand<T>(): LexicalCommand<T>;
62
64
  */
63
65
  type ErrorHandler = (error: Error) => void;
64
66
  type MutationListeners = Map<MutationListener, Class<LexicalNode>>;
65
- export type NodeMutation = 'created' | 'destroyed';
67
+ export type NodeMutation = 'created' | 'updated' | 'destroyed';
66
68
  type UpdateListener = (arg0: {
67
69
  tags: Set<string>;
68
70
  prevEditorState: EditorState;
@@ -116,7 +118,7 @@ export declare class LexicalEditor {
116
118
  _onError: ErrorHandler;
117
119
  _decorators: Record<NodeKey, unknown>;
118
120
  _pendingDecorators: null | Record<NodeKey, unknown>;
119
- _config: EditorConfig<{}>;
121
+ _config: EditorConfig;
120
122
  _dirtyType: 0 | 1 | 2;
121
123
  _cloneNotNeeded: Set<NodeKey>;
122
124
  _dirtyLeaves: Set<NodeKey>;
@@ -145,7 +147,7 @@ export declare class LexicalEditor {
145
147
  klass: Class<T>,
146
148
  listener: Transform<T>,
147
149
  ): () => void;
148
- dispatchCommand<P>(type: string, payload: P): boolean;
150
+ dispatchCommand<P>(type: LexicalCommand<P>, payload: P): boolean;
149
151
  hasNodes(nodes: Array<Class<LexicalNode>>): boolean;
150
152
  getDecorators<X>(): Record<NodeKey, X>;
151
153
  getRootElement(): null | HTMLElement;
@@ -153,7 +155,9 @@ export declare class LexicalEditor {
153
155
  getElementByKey(key: NodeKey): null | HTMLElement;
154
156
  getEditorState(): EditorState;
155
157
  setEditorState(editorState: EditorState, options?: EditorSetOptions): void;
156
- parseEditorState(stringifiedEditorState: string): EditorState;
158
+ parseEditorState(
159
+ maybeStringifiedEditorState: string | ParsedEditorState,
160
+ ): EditorState;
157
161
  update(updateFn: () => void, options?: EditorUpdateOptions): boolean;
158
162
  focus(callbackFn?: () => void): void;
159
163
  blur(): void;
@@ -177,21 +181,23 @@ type TextNodeThemeClasses = {
177
181
  underlineStrikethrough?: EditorThemeClassName;
178
182
  italic?: EditorThemeClassName;
179
183
  code?: EditorThemeClassName;
184
+ subscript?: EditorThemeClassName;
185
+ superscript?: EditorThemeClassName;
180
186
  };
181
187
  export type EditorThemeClasses = {
182
188
  ltr?: EditorThemeClassName;
183
189
  rtl?: EditorThemeClassName;
184
- root?: EditorThemeClassName;
185
190
  text?: TextNodeThemeClasses;
186
191
  paragraph?: EditorThemeClassName;
187
192
  image?: EditorThemeClassName;
188
- //@ts-expect-error
189
193
  list?: {
190
194
  ul?: EditorThemeClassName;
191
195
  ulDepth?: Array<EditorThemeClassName>;
192
196
  ol?: EditorThemeClassName;
193
197
  olDepth?: Array<EditorThemeClassName>;
194
198
  listitem?: EditorThemeClassName;
199
+ listitemChecked?: EditorThemeClassName;
200
+ listitemUnchecked?: EditorThemeClassName;
195
201
  nested?: {
196
202
  list?: EditorThemeClassName;
197
203
  listitem?: EditorThemeClassName;
@@ -201,6 +207,8 @@ export type EditorThemeClasses = {
201
207
  tableRow?: EditorThemeClassName;
202
208
  tableCell?: EditorThemeClassName;
203
209
  tableCellHeader?: EditorThemeClassName;
210
+ mark?: EditorThemeClassName;
211
+ markOverlap?: EditorThemeClassName;
204
212
  link?: EditorThemeClassName;
205
213
  quote?: EditorThemeClassName;
206
214
  code?: EditorThemeClassName;
@@ -214,12 +222,18 @@ export type EditorThemeClasses = {
214
222
  h5?: EditorThemeClassName;
215
223
  };
216
224
  // Handle other generic values
217
- [key: string]: EditorThemeClassName | Record<string, EditorThemeClassName>;
225
+ [key: string]:
226
+ | EditorThemeClassName
227
+ | Record<
228
+ string,
229
+ | EditorThemeClassName
230
+ | Array<EditorThemeClassName>
231
+ | Record<string, EditorThemeClassName>
232
+ >;
218
233
  };
219
- export type EditorConfig<EditorContext> = {
234
+ export type EditorConfig = {
220
235
  namespace: string;
221
236
  theme: EditorThemeClasses;
222
- context: EditorContext;
223
237
  disableEvents?: boolean;
224
238
  };
225
239
  export type CommandListenerPriority = 0 | 1 | 2 | 3 | 4;
@@ -229,11 +243,10 @@ export const COMMAND_PRIORITY_NORMAL = 2;
229
243
  export const COMMAND_PRIORITY_HIGH = 3;
230
244
  export const COMMAND_PRIORITY_CRITICAL = 4;
231
245
  export type IntentionallyMarkedAsDirtyElement = boolean;
232
- export function createEditor<EditorContext>(editorConfig?: {
246
+ export function createEditor(editorConfig?: {
233
247
  namespace?: string;
234
248
  editorState?: EditorState;
235
249
  theme?: EditorThemeClasses;
236
- context?: EditorContext;
237
250
  parentEditor?: LexicalEditor;
238
251
  nodes?: Array<Class<LexicalNode>>;
239
252
  onError: (error: Error) => void;
@@ -293,8 +306,8 @@ export type DOMConversionFn = (
293
306
  ) => DOMConversionOutput;
294
307
  export type DOMChildConversion = (
295
308
  lexicalNode: LexicalNode,
296
- parentLexicalNode: LexicalNode | null,
297
- ) => LexicalNode | void | null;
309
+ parentLexicalNode: LexicalNode | null | undefined,
310
+ ) => LexicalNode | null;
298
311
  export type DOMConversionMap = Record<
299
312
  NodeName,
300
313
  (node: Node) => DOMConversion | null
@@ -339,7 +352,6 @@ export declare class LexicalNode {
339
352
  isParentOf(targetNode: LexicalNode): boolean;
340
353
  getNodesBetween(targetNode: LexicalNode): Array<LexicalNode>;
341
354
  isDirty(): boolean;
342
- isComposing(): boolean;
343
355
  // $FlowFixMe
344
356
  getLatest<T extends LexicalNode>(): T;
345
357
  // $FlowFixMe
@@ -350,17 +362,8 @@ export declare class LexicalNode {
350
362
  includeDirectionless?: false,
351
363
  ): number;
352
364
  exportDOM(editor: LexicalEditor): DOMExportOutput;
353
- // $FlowFixMe
354
- createDOM<EditorContext extends Record<string, any>>(
355
- config: EditorConfig<EditorContext>,
356
- editor: LexicalEditor,
357
- ): HTMLElement;
358
- // $FlowFixMe
359
- updateDOM<EditorContext extends Record<string, any>>( // $FlowFixMe
360
- prevNode: any,
361
- dom: HTMLElement,
362
- config: EditorConfig<EditorContext>,
363
- ): boolean;
365
+ createDOM(config: EditorConfig, editor: LexicalEditor): HTMLElement;
366
+ updateDOM(prevNode: any, dom: HTMLElement, config: EditorConfig): boolean;
364
367
  remove(preserveEmptyParent?: boolean): void;
365
368
  replace<N extends LexicalNode>(replaceWith: N): N;
366
369
  insertAfter(nodeToInsert: LexicalNode): LexicalNode;
@@ -417,15 +420,14 @@ export type GridSelectionShape = {
417
420
  };
418
421
  export declare class GridSelection {
419
422
  gridKey: NodeKey;
420
- anchorCellKey: NodeKey;
421
423
  anchor: PointType;
422
- focusCellKey: NodeKey;
423
424
  focus: PointType;
424
425
  dirty: boolean;
425
- constructor(gridKey: NodeKey, anchorCellKey: NodeKey, focusCellKey: NodeKey);
426
+ constructor(gridKey: NodeKey, anchor: PointType, focus: PointType);
426
427
  is(selection: null | RangeSelection | NodeSelection | GridSelection): boolean;
427
428
  set(gridKey: NodeKey, anchorCellKey: NodeKey, focusCellKey: NodeKey): void;
428
429
  clone(): GridSelection;
430
+ getCharacterOffsets(): [number, number];
429
431
  extract(): Array<LexicalNode>;
430
432
  isCollapsed(): boolean;
431
433
  isBackward(): boolean;
@@ -435,7 +437,9 @@ export declare class GridSelection {
435
437
  getNodes(): Array<LexicalNode>;
436
438
  getTextContent(): string;
437
439
  }
438
- export function $isGridSelection(x: unknown | null | undefined): boolean;
440
+ export function $isGridSelection(
441
+ x: unknown | null | undefined,
442
+ ): x is GridSelection;
439
443
  export declare class NodeSelection {
440
444
  _nodes: Set<NodeKey>;
441
445
  dirty: boolean;
@@ -452,7 +456,9 @@ export declare class NodeSelection {
452
456
  getNodes(): Array<LexicalNode>;
453
457
  getTextContent(): string;
454
458
  }
455
- export function $isNodeSelection(x: unknown | null | undefined): boolean;
459
+ export function $isNodeSelection(
460
+ x: unknown | null | undefined,
461
+ ): x is NodeSelection;
456
462
  export declare class RangeSelection {
457
463
  anchor: PointType;
458
464
  focus: PointType;
@@ -482,6 +488,7 @@ export declare class RangeSelection {
482
488
  insertNodes(nodes: Array<LexicalNode>, selectStart?: boolean): boolean;
483
489
  insertParagraph(): void;
484
490
  insertLineBreak(selectStart?: boolean): void;
491
+ getCharacterOffsets(): [number, number];
485
492
  extract(): Array<LexicalNode>;
486
493
  modify(
487
494
  alter: 'move' | 'extend',
@@ -513,7 +520,6 @@ type ElementPointType = {
513
520
  isBefore: (arg0: PointType) => boolean;
514
521
  getNode: () => ElementNode;
515
522
  set: (key: NodeKey, offset: number, type: 'text' | 'element') => void;
516
- getCharacterOffset: () => number;
517
523
  isAtNodeEnd: () => boolean;
518
524
  };
519
525
  export type Point = PointType;
@@ -526,7 +532,6 @@ declare class _Point {
526
532
  constructor(key: NodeKey, offset: number, type: 'text' | 'element');
527
533
  is(point: PointType): boolean;
528
534
  isBefore(b: PointType): boolean;
529
- getCharacterOffset(): number;
530
535
  getNode(): LexicalNode;
531
536
  set(key: NodeKey, offset: number, type: 'text' | 'element'): void;
532
537
  }
@@ -534,7 +539,9 @@ declare class _Point {
534
539
  export function $createRangeSelection(): RangeSelection;
535
540
  export function $createNodeSelection(): NodeSelection;
536
541
  export function $createGridSelection(): GridSelection;
537
- export function $isRangeSelection(x: unknown | null | undefined): boolean;
542
+ export function $isRangeSelection(
543
+ x: unknown | null | undefined,
544
+ ): x is RangeSelection;
538
545
  export function $getSelection():
539
546
  | null
540
547
  | RangeSelection
@@ -558,6 +565,7 @@ export type TextFormatType =
558
565
  | 'subscript'
559
566
  | 'superscript';
560
567
  type TextModeType = 'normal' | 'token' | 'segmented' | 'inert';
568
+
561
569
  export declare class TextNode extends LexicalNode {
562
570
  __text: string;
563
571
  __format: number;
@@ -569,6 +577,7 @@ export declare class TextNode extends LexicalNode {
569
577
  constructor(text: string, key?: NodeKey);
570
578
  getFormat(): number;
571
579
  getStyle(): string;
580
+ isComposing(): boolean;
572
581
  isToken(): boolean;
573
582
  isSegmented(): boolean;
574
583
  isInert(): boolean;
@@ -579,14 +588,12 @@ export declare class TextNode extends LexicalNode {
579
588
  getTextContent(includeInert?: boolean, includeDirectionless?: false): string;
580
589
  getFormatFlags(type: TextFormatType, alignWithFormat: null | number): number;
581
590
  // $FlowFixMe
582
- createDOM<EditorContext extends Record<string, any>>(
583
- config: EditorConfig<EditorContext>,
584
- ): HTMLElement;
591
+ createDOM(config: EditorConfig): HTMLElement;
585
592
  // $FlowFixMe
586
- updateDOM<EditorContext extends Record<string, any>>(
593
+ updateDOM(
587
594
  prevNode: TextNode,
588
595
  dom: HTMLElement,
589
- config: EditorConfig<EditorContext>,
596
+ config: EditorConfig,
590
597
  ): boolean;
591
598
  selectionTransform(
592
599
  prevSelection: null | RangeSelection | NodeSelection | GridSelection,
@@ -612,7 +619,9 @@ export declare class TextNode extends LexicalNode {
612
619
  mergeWithSibling(target: TextNode): TextNode;
613
620
  }
614
621
  export function $createTextNode(text?: string): TextNode;
615
- export function $isTextNode(node: LexicalNode | null | undefined): boolean;
622
+ export function $isTextNode(
623
+ node: TextNode | LexicalNode | null | undefined,
624
+ ): node is TextNode;
616
625
 
617
626
  /**
618
627
  * LexicalLineBreakNode
@@ -626,7 +635,9 @@ export declare class LineBreakNode extends LexicalNode {
626
635
  updateDOM(): false;
627
636
  }
628
637
  export function $createLineBreakNode(): LineBreakNode;
629
- export function $isLineBreakNode(node: LexicalNode | null | undefined): boolean;
638
+ export function $isLineBreakNode(
639
+ node: LexicalNode | null | undefined,
640
+ ): node is LineBreakNode;
630
641
 
631
642
  /**
632
643
  * LexicalRootNode
@@ -646,7 +657,9 @@ export declare class RootNode extends ElementNode {
646
657
  append(...nodesToAppend: Array<LexicalNode>): ElementNode;
647
658
  canBeEmpty(): false;
648
659
  }
649
- export function $isRootNode(node: LexicalNode | null | undefined): boolean;
660
+ export function $isRootNode(
661
+ node: LexicalNode | null | undefined,
662
+ ): node is RootNode;
650
663
 
651
664
  /**
652
665
  * LexicalElementNode
@@ -686,11 +699,17 @@ export declare class ElementNode extends LexicalNode {
686
699
  setIndent(indentLevel: number): ElementNode;
687
700
  insertNewAfter(selection: RangeSelection): null | LexicalNode;
688
701
  canInsertTab(): boolean;
702
+ canIndent(): boolean;
689
703
  collapseAtStart(selection: RangeSelection): boolean;
690
- excludeFromCopy(): boolean;
704
+ excludeFromCopy(destination: 'clone' | 'html'): boolean;
691
705
  canExtractContents(): boolean;
692
706
  canReplaceWith(replacement: LexicalNode): boolean;
693
707
  canInsertAfter(node: LexicalNode): boolean;
708
+ extractWithChild(
709
+ child: LexicalNode,
710
+ selection: RangeSelection | NodeSelection | GridSelection,
711
+ destination: 'clone' | 'html',
712
+ ): boolean;
694
713
  canBeEmpty(): boolean;
695
714
  canInsertTextBefore(): boolean;
696
715
  canInsertTextAfter(): boolean;
@@ -702,7 +721,9 @@ export declare class ElementNode extends LexicalNode {
702
721
  nodesToInsert: Array<LexicalNode>,
703
722
  ): ElementNode;
704
723
  }
705
- export function $isElementNode(node: LexicalNode | null | undefined): boolean;
724
+ export function $isElementNode(
725
+ node: LexicalNode | null | undefined,
726
+ ): node is ElementNode;
706
727
 
707
728
  /**
708
729
  * LexicalDecoratorNode
@@ -711,23 +732,11 @@ export declare class DecoratorNode<X> extends LexicalNode {
711
732
  constructor(key?: NodeKey);
712
733
  decorate(editor: LexicalEditor): X;
713
734
  isIsolated(): boolean;
735
+ isTopLevel(): boolean;
714
736
  }
715
- export function $isDecoratorNode(node: LexicalNode | null | undefined): boolean;
716
-
717
- /**
718
- * LexicalHorizontalRuleNode
719
- */
720
- export declare class HorizontalRuleNode extends LexicalNode {
721
- static getType(): string;
722
- static clone(node: HorizontalRuleNode): HorizontalRuleNode;
723
- constructor(key?: NodeKey);
724
- createDOM(): HTMLElement;
725
- updateDOM(): false;
726
- }
727
- export function $createHorizontalRuleNode(): HorizontalRuleNode;
728
- export function $isHorizontalRuleNode(
737
+ export function $isDecoratorNode(
729
738
  node: LexicalNode | null | undefined,
730
- ): boolean;
739
+ ): node is DecoratorNode<unknown>;
731
740
 
732
741
  /**
733
742
  * LexicalParagraphNode
@@ -736,22 +745,30 @@ export declare class ParagraphNode extends ElementNode {
736
745
  getType(): string;
737
746
  clone(node: ParagraphNode): ParagraphNode;
738
747
  constructor(key?: NodeKey);
739
- createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
748
+ createDOM(config: EditorConfig): HTMLElement;
740
749
  updateDOM(prevNode: ParagraphNode, dom: HTMLElement): boolean;
741
750
  insertNewAfter(): ParagraphNode;
742
751
  collapseAtStart(): boolean;
743
752
  }
744
753
  export function $createParagraphNode(): ParagraphNode;
745
- export function $isParagraphNode(node: LexicalNode | null | undefined): boolean;
754
+ export function $isParagraphNode(
755
+ node: LexicalNode | null | undefined,
756
+ ): node is ParagraphNode;
746
757
  export declare class GridNode extends ElementNode {}
747
- export function $isGridNode(node: LexicalNode | null | undefined): boolean;
758
+ export function $isGridNode(
759
+ node: LexicalNode | null | undefined,
760
+ ): node is GridNode;
748
761
  export declare class GridRowNode extends ElementNode {}
749
- export function $isGridRowNode(node: LexicalNode | null | undefined): boolean;
762
+ export function $isGridRowNode(
763
+ node: LexicalNode | null | undefined,
764
+ ): node is GridRowNode;
750
765
  export declare class GridCellNode extends ElementNode {
751
766
  __colSpan: number;
752
767
  constructor(colSpan: number, key?: NodeKey);
753
768
  }
754
- export function $isGridCellNode(node: LexicalNode | null | undefined): boolean;
769
+ export function $isGridCellNode(
770
+ node: LexicalNode | null | undefined,
771
+ ): node is GridCellNode;
755
772
 
756
773
  /**
757
774
  * LexicalUtils
@@ -761,7 +778,9 @@ export function $getNearestNodeFromDOMNode(
761
778
  ): LexicalNode | null;
762
779
  export function $getNodeByKey<N extends LexicalNode>(key: NodeKey): N | null;
763
780
  export function $getRoot(): RootNode;
764
- export function $isLeafNode(node: LexicalNode | null | undefined): boolean;
781
+ export function $isLeafNode(
782
+ node: LexicalNode | null | undefined,
783
+ ): node is TextNode | LineBreakNode | DecoratorNode<unknown>;
765
784
  export function $setCompositionKey(compositionKey: null | NodeKey): void;
766
785
  export function $setSelection(
767
786
  selection: null | RangeSelection | NodeSelection | GridSelection,