lexical 0.2.4 → 0.2.7

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;
@@ -486,6 +488,7 @@ export declare class RangeSelection {
486
488
  insertNodes(nodes: Array<LexicalNode>, selectStart?: boolean): boolean;
487
489
  insertParagraph(): void;
488
490
  insertLineBreak(selectStart?: boolean): void;
491
+ getCharacterOffsets(): [number, number];
489
492
  extract(): Array<LexicalNode>;
490
493
  modify(
491
494
  alter: 'move' | 'extend',
@@ -517,7 +520,6 @@ type ElementPointType = {
517
520
  isBefore: (arg0: PointType) => boolean;
518
521
  getNode: () => ElementNode;
519
522
  set: (key: NodeKey, offset: number, type: 'text' | 'element') => void;
520
- getCharacterOffset: () => number;
521
523
  isAtNodeEnd: () => boolean;
522
524
  };
523
525
  export type Point = PointType;
@@ -530,7 +532,6 @@ declare class _Point {
530
532
  constructor(key: NodeKey, offset: number, type: 'text' | 'element');
531
533
  is(point: PointType): boolean;
532
534
  isBefore(b: PointType): boolean;
533
- getCharacterOffset(): number;
534
535
  getNode(): LexicalNode;
535
536
  set(key: NodeKey, offset: number, type: 'text' | 'element'): void;
536
537
  }
@@ -564,6 +565,7 @@ export type TextFormatType =
564
565
  | 'subscript'
565
566
  | 'superscript';
566
567
  type TextModeType = 'normal' | 'token' | 'segmented' | 'inert';
568
+
567
569
  export declare class TextNode extends LexicalNode {
568
570
  __text: string;
569
571
  __format: number;
@@ -575,6 +577,7 @@ export declare class TextNode extends LexicalNode {
575
577
  constructor(text: string, key?: NodeKey);
576
578
  getFormat(): number;
577
579
  getStyle(): string;
580
+ isComposing(): boolean;
578
581
  isToken(): boolean;
579
582
  isSegmented(): boolean;
580
583
  isInert(): boolean;
@@ -585,14 +588,12 @@ export declare class TextNode extends LexicalNode {
585
588
  getTextContent(includeInert?: boolean, includeDirectionless?: false): string;
586
589
  getFormatFlags(type: TextFormatType, alignWithFormat: null | number): number;
587
590
  // $FlowFixMe
588
- createDOM<EditorContext extends Record<string, any>>(
589
- config: EditorConfig<EditorContext>,
590
- ): HTMLElement;
591
+ createDOM(config: EditorConfig): HTMLElement;
591
592
  // $FlowFixMe
592
- updateDOM<EditorContext extends Record<string, any>>(
593
+ updateDOM(
593
594
  prevNode: TextNode,
594
595
  dom: HTMLElement,
595
- config: EditorConfig<EditorContext>,
596
+ config: EditorConfig,
596
597
  ): boolean;
597
598
  selectionTransform(
598
599
  prevSelection: null | RangeSelection | NodeSelection | GridSelection,
@@ -619,7 +620,7 @@ export declare class TextNode extends LexicalNode {
619
620
  }
620
621
  export function $createTextNode(text?: string): TextNode;
621
622
  export function $isTextNode(
622
- node: LexicalNode | null | undefined,
623
+ node: TextNode | LexicalNode | null | undefined,
623
624
  ): node is TextNode;
624
625
 
625
626
  /**
@@ -698,11 +699,17 @@ export declare class ElementNode extends LexicalNode {
698
699
  setIndent(indentLevel: number): ElementNode;
699
700
  insertNewAfter(selection: RangeSelection): null | LexicalNode;
700
701
  canInsertTab(): boolean;
702
+ canIndent(): boolean;
701
703
  collapseAtStart(selection: RangeSelection): boolean;
702
- excludeFromCopy(): boolean;
704
+ excludeFromCopy(destination: 'clone' | 'html'): boolean;
703
705
  canExtractContents(): boolean;
704
706
  canReplaceWith(replacement: LexicalNode): boolean;
705
707
  canInsertAfter(node: LexicalNode): boolean;
708
+ extractWithChild(
709
+ child: LexicalNode,
710
+ selection: RangeSelection | NodeSelection | GridSelection,
711
+ destination: 'clone' | 'html',
712
+ ): boolean;
706
713
  canBeEmpty(): boolean;
707
714
  canInsertTextBefore(): boolean;
708
715
  canInsertTextAfter(): boolean;
@@ -731,21 +738,6 @@ export function $isDecoratorNode(
731
738
  node: LexicalNode | null | undefined,
732
739
  ): node is DecoratorNode<unknown>;
733
740
 
734
- /**
735
- * LexicalHorizontalRuleNode
736
- */
737
- export declare class HorizontalRuleNode extends LexicalNode {
738
- static getType(): string;
739
- static clone(node: HorizontalRuleNode): HorizontalRuleNode;
740
- constructor(key?: NodeKey);
741
- createDOM(): HTMLElement;
742
- updateDOM(): false;
743
- }
744
- export function $createHorizontalRuleNode(): HorizontalRuleNode;
745
- export function $isHorizontalRuleNode(
746
- node: LexicalNode | null | undefined,
747
- ): boolean;
748
-
749
741
  /**
750
742
  * LexicalParagraphNode
751
743
  */
@@ -753,7 +745,7 @@ export declare class ParagraphNode extends ElementNode {
753
745
  getType(): string;
754
746
  clone(node: ParagraphNode): ParagraphNode;
755
747
  constructor(key?: NodeKey);
756
- createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
748
+ createDOM(config: EditorConfig): HTMLElement;
757
749
  updateDOM(prevNode: ParagraphNode, dom: HTMLElement): boolean;
758
750
  insertNewAfter(): ParagraphNode;
759
751
  collapseAtStart(): boolean;
@@ -786,7 +778,9 @@ export function $getNearestNodeFromDOMNode(
786
778
  ): LexicalNode | null;
787
779
  export function $getNodeByKey<N extends LexicalNode>(key: NodeKey): N | null;
788
780
  export function $getRoot(): RootNode;
789
- export function $isLeafNode(node: LexicalNode | null | undefined): boolean;
781
+ export function $isLeafNode(
782
+ node: LexicalNode | null | undefined,
783
+ ): node is TextNode | LineBreakNode | DecoratorNode<unknown>;
790
784
  export function $setCompositionKey(compositionKey: null | NodeKey): void;
791
785
  export function $setSelection(
792
786
  selection: null | RangeSelection | NodeSelection | GridSelection,