import { DiagramOptions } from './diagram.js'; import { FindOptions, FindOptionsTyped } from './find.js'; import { IndexPath } from './indexPath.js'; import { InsertOptions, InsertWithPathTrackingOptions } from './insert.js'; import { FlatMapOptions, MapOptions } from './map.js'; import { MoveOptions } from './move.js'; import { BaseOptions, MutationBaseOptions, TraversalContext } from './options.js'; import { ReduceOptions } from './reduce.js'; import { RemoveOptions, RemoveWithPathTrackingOptions } from './remove.js'; import { ReplaceOptions } from './replace.js'; import { SpliceOptions, SpliceWithPathTrackingOptions } from './splice.js'; import { OptionCheck, Prettify } from './types.js'; import { VisitOptions } from './visit.js'; type WithoutBase = Omit>; type MutationOptions = WithoutBase>; type DiagramOptionsWB = WithoutBase>; type DiagramRequiredOptions = { getLabel: DiagramOptionsWB['getLabel']; }; type DiagramOptionalOptions = Omit, keyof DiagramRequiredOptions>; type FindOptionsWB = WithoutBase>; type VisitOptionsWB = WithoutBase>; type InsertOptionsWB = WithoutBase>; type InsertWithPathTrackingOptionsWB = WithoutBase>; type RemoveOptionsWB = WithoutBase>; type RemoveWithPathTrackingOptionsWB = WithoutBase>; type MoveOptionsWB = WithoutBase>; type ReplaceOptionsWB = WithoutBase>; type SpliceOptionsWB = WithoutBase>; type SpliceWithPathTrackingOptionsWB = WithoutBase>; type ApplyableOptions = DiagramRequiredOptions & MutationOptions; interface Overloads { /** * Find a node matching a predicate function. */ find(node: T, predicate: FindOptions['predicate']): T | undefined; find(node: T, options: FindOptionsWB): T | undefined; find(node: T, predicate: FindOptionsTyped['predicate']): S | undefined; find(node: T, options: WithoutBase>): S | undefined; /** * Find all nodes matching a predicate function. */ findAll(node: T, predicate: FindOptions['predicate']): T[]; findAll(node: T, options: FindOptionsWB): T[]; findAll(node: T, predicate: FindOptionsTyped['predicate']): S[]; findAll(node: T, options: WithoutBase>): S[]; /** * Find the `IndexPath` of a node matching a predicate function. */ findPath(node: T, predicate: FindOptions['predicate']): IndexPath | undefined; findPath(node: T, options: FindOptionsWB): IndexPath | undefined; /** * Find the `IndexPath` of all nodes matching a predicate function. */ findAllPaths(node: T, predicate: FindOptions['predicate']): IndexPath[]; findAllPaths(node: T, options: FindOptionsWB): IndexPath[]; /** * Visit each node using preorder DFS traversal. */ visit(node: T, onEnter: NonNullable>['onEnter']): void; /** * Visit each node using DFS traversal. */ visit(node: T, options: VisitOptionsWB): void; } declare class Tree>> { appliedOptions: AppliedOptions; constructor(getChildrenOrBaseOptions: BaseOptions | BaseOptions['getChildren'], appliedOptions: AppliedOptions); _getChildren: BaseOptions['getChildren']; /** * Returns the node's children. * * This is the same as the `getChildren` option passed to `defineTree`, included here for convenience. */ getChildren: (node: T, indexPath: IndexPath, context?: TraversalContext) => T[]; baseOptions: BaseOptions; mergeOptions: >(options: O) => BaseOptions & AppliedOptions & O; withOptions: >>(newOptions: NewOptions) => Tree; /** * Returns a node by its `IndexPath`. * * The first node is implicitly included in the `IndexPath` (i.e. no need to pass a `0` first in every `IndexPath`). */ access: (node: T, indexPath: IndexPath) => T; /** * Returns an array of each node in an `IndexPath`. * * The first node is implicitly included in the `IndexPath` (i.e. no need to pass a `0` first in every `IndexPath`). */ accessPath: (node: T, indexPath: IndexPath) => T[]; /** * Returns a node by its `IndexPath`. * * The first node is implicitly included in the `IndexPath` (i.e. no need to pass a `0` first in every `IndexPath`). */ get: (node: T, indexPath: IndexPath) => T | undefined; /** * Returns the ancestors of a node. */ ancestors: (node: T, indexPath: IndexPath) => T[]; /** * Generate a diagram of the tree, as a string. */ diagram: (node: T, options: DiagramRequiredOptions["getLabel"] | Prettify ? DiagramOptionalOptions | void : OptionCheck> & DiagramOptionalOptions>) => string; find: Overloads['find']; findAll: Overloads['findAll']; findPath: Overloads['findPath']; findAllPaths: Overloads['findAllPaths']; /** * Returns an array of every [IndexPath, Node] pair in the tree. */ entries: (node: T) => [IndexPath, T][]; /** * Returns an array containing the root node and all of its descendants. * * This is analogous to `Array.prototype.flat` for flattening arrays. */ flat: (node: T) => T[]; reduce: (node: T, nextResult: ReduceOptions["nextResult"], initialResult: R) => R; map: (node: T, transform: MapOptions["transform"]) => R; flatMap: (node: T, transform: FlatMapOptions["transform"]) => R; visit: Overloads['visit']; /** * Insert nodes at a given `IndexPath`. */ insert: (node: T, options: Prettify> & Omit, "create">>) => T; /** * Insert nodes at a given `IndexPath`. */ insertWithPathTracking: (node: T, options: Prettify> & Omit, "create">>) => { node: T; paths: (IndexPath | undefined)[]; }; /** * Remove nodes at the given `IndexPath`s. */ remove: (node: T, options: Prettify> & Omit, "create">>) => T; /** * Remove nodes at the given `IndexPath`s. */ removeWithPathTracking: (node: T, options: Prettify> & Omit, "create">>) => { node: T; paths: (IndexPath | undefined)[]; }; /** * Move nodes from one `IndexPath` to another. */ move: (node: T, options: Prettify> & Omit, "create">>) => T; /** * Replace nodes at the given `IndexPath`s with another node. */ splice: (node: T, options: Prettify> & Omit, "create">>) => T; /** * Replace nodes at the given `IndexPath`s with another node. */ spliceWithPathTracking: (node: T, options: Prettify> & Omit, "create">>) => { node: T; paths: (IndexPath | undefined)[]; }; /** * Replace the node at the given `IndexPath` with another */ replace: (node: T, options: Prettify> & Omit, "create">>) => T; } export declare function defineTree(getChildren: BaseOptions | BaseOptions['getChildren']): Tree; export {};