/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict */ import type { EditorState, LexicalEditor, LexicalNode, ElementNode, NodeCaret, CaretDirection, SiblingCaret, RootMode, SplitAtPointCaretNextOptions, PointCaret, StateConfig, ValueOrUpdater } from 'lexical'; declare export function addClassNamesToElement( element: HTMLElement, ...classNames: Array ): void; declare export function removeClassNamesFromElement( element: HTMLElement, ...classNames: Array ): void; declare export function isMimeType( file: File, acceptableMimeTypes: Array, ): boolean; declare export function mediaFileReader( files: Array, acceptableMimeTypes: Array, ): Promise>>; export type DFSNode = $ReadOnly<{ depth: number, node: LexicalNode, }>; declare export function $dfs( startNode?: LexicalNode, endNode?: LexicalNode, ): Array; type DFSIterator = { next: () => IteratorResult; @@iterator: () => DFSIterator; }; declare export function $dfsIterator( startNode?: LexicalNode, endNode?: LexicalNode, ): DFSIterator; declare export function $getNextSiblingOrParentSibling( node: LexicalNode, ): null | [LexicalNode, number]; declare export function $getDepth(node: null | LexicalNode): number; declare export function $getNextRightPreorderNode( startingNode: LexicalNode, ): LexicalNode | null; declare export function $getNearestNodeOfType( node: LexicalNode, klass: Class, ): T | null; export type DOMNodeToLexicalConversion = (element: Node) => LexicalNode; export type DOMNodeToLexicalConversionMap = { [string]: DOMNodeToLexicalConversion, }; declare export function $findMatchingParent( startingNode: LexicalNode, findFn: (LexicalNode) => boolean, ): LexicalNode | null; type Func = () => void; declare export function mergeRegister(...func: Array): () => void; declare export function markSelection( editor: LexicalEditor, onReposition?: (node: Array) => void, ): () => void; declare export function positionNodeOnRange( editor: LexicalEditor, range: Range, onReposition: (node: Array) => void, ): () => void; declare export function selectionAlwaysOnDisplay( editor: LexicalEditor, ): () => void; declare export function $getNearestBlockElementAncestorOrThrow( startNode: LexicalNode, ): ElementNode; declare export function registerNestedElementResolver( editor: LexicalEditor, targetNode: Class, cloneNode: (from: N) => N, handleOverlap: (from: N, to: N) => void, ): () => void; declare export function unstable_convertLegacyJSONEditorState( editor: LexicalEditor, maybeStringifiedEditorState: string, ): EditorState; declare export function $restoreEditorState( editor: LexicalEditor, editorState: EditorState, ): void; declare export function $insertNodeToNearestRoot(node: T): T; declare export function $insertNodeToNearestRootAtCaret(node: T, caret: PointCaret, options?: SplitAtPointCaretNextOptions): T; declare export function $wrapNodeInElement( node: LexicalNode, createElementNode: () => ElementNode, ): ElementNode; declare export function objectKlassEquals( object: mixed, objectClass: Class, ): boolean; declare export function $filter( nodes: Array, filterFn: (node: LexicalNode) => null | T, ): Array; declare export function $insertFirst(parent: ElementNode, node: LexicalNode): void; declare export function $splitNode( node: ElementNode, offset: number, ): [ElementNode | null, ElementNode]; declare export function calculateZoomLevel(element: Element | null): number; declare export function $isEditorIsNestedEditor(editor: LexicalEditor): boolean; declare export function $unwrapAndFilterDescendants( root: ElementNode, $predicate: (node: LexicalNode) => boolean, ): boolean; declare export function $firstToLastIterator(node: ElementNode): Iterable; declare export function $lastToFirstIterator(node: ElementNode): Iterable; declare export function $unwrapNode(node: ElementNode): void; declare export function $getAdjacentCaret( caret: null | NodeCaret, ): null | SiblingCaret; declare export function $reverseDfs( startNode?: LexicalNode, endNode?: LexicalNode, ): Array; declare export function $reverseDfsIterator( startNode?: LexicalNode, endNode?: LexicalNode, ): Iterable; declare export function $descendantsMatching( children: LexicalNode[], $predicate: (node: LexicalNode) => node is T, ): T[]; declare export function $descendantsMatching( children: LexicalNode[], $predicate: (node: LexicalNode) => boolean, ): LexicalNode[]; declare export function $getAdjacentSiblingOrParentSiblingCaret< D: CaretDirection, >( startCaret: NodeCaret, rootMode?: RootMode, ): null | [NodeCaret, number]; export type StateConfigWrapper = { +stateConfig: StateConfig; +$get: (node: T) => V; +$set: ( node: T, valueOrUpdater: ValueOrUpdater, ) => T; /** `[$get, $set]` */ +accessors: $ReadOnly<[$get: StateConfigWrapper['$get'], $set: StateConfigWrapper['$set']]>; /** * `() => function () { return $get(this) }` * * Should be called with an explicit `this` type parameter. * * @example * ```ts * class MyNode { * // … * myGetter = myWrapper.makeGetterMethod(); * } * ``` */ makeGetterMethod(): (this: T) => V; /** * `() => function (valueOrUpdater) { return $set(this, valueOrUpdater) }` * * Must be called with an explicit `this` type parameter. * * @example * ```ts * class MyNode { * // … * mySetter = myWrapper.makeSetterMethod(); * } * ``` */ makeSetterMethod(): ( this: T, valueOrUpdater: ValueOrUpdater, ) => T; }; declare export function makeStateWrapper( stateConfig: StateConfig, ): StateConfigWrapper;