/** @packageDocumentation * @module Tree */ import { immerable } from "immer"; import { PropertyRecord } from "@bentley/ui-abstract"; import { CheckBoxState } from "@bentley/ui-core"; import { DelayLoadedTreeNodeItem, ImmediatelyLoadedTreeNodeItem, TreeNodeItem } from "../TreeDataProvider"; import { SparseArray } from "./internal/SparseTree"; /** * Immutable data structure that describes tree node. * @public */ export interface TreeModelNode { readonly id: string; readonly parentId: string | undefined; readonly depth: number; readonly isLoading?: boolean; readonly numChildren: number | undefined; readonly description: string | undefined; readonly isExpanded: boolean; readonly label: PropertyRecord; readonly isSelected: boolean; /** Specifies that node is in editing mode. It holds callbacks that are used by node editor. */ readonly editingInfo?: TreeModelNodeEditingInfo; readonly checkbox: CheckBoxInfo; readonly item: TreeNodeItem; } /** * Immutable data structure that describes checkbox info. * @public */ export interface CheckBoxInfo { readonly state: CheckBoxState; readonly tooltip?: string; readonly isDisabled: boolean; readonly isVisible: boolean; } /** * Mutable data structure that describes tree node. * @public */ export interface MutableTreeModelNode extends TreeModelNode { isLoading: boolean; description: string; isExpanded: boolean; label: PropertyRecord; isSelected: boolean; /** Specifies that node is in editing mode. It holds callbacks that are used by node editor. */ editingInfo?: TreeModelNodeEditingInfo; checkbox: MutableCheckBoxInfo; item: TreeNodeItem; } /** * Data structure that holds callbacks used for tree node editing. * @public */ export interface TreeModelNodeEditingInfo { onCommit: (node: TreeModelNode, newValue: string) => void; onCancel: () => void; } /** * Mutable data structure that describes checkbox info. * @public */ export interface MutableCheckBoxInfo extends CheckBoxInfo { state: CheckBoxState; tooltip?: string; isDisabled: boolean; isVisible: boolean; } /** * Data structure that describes tree node placeholder. * @public */ export interface TreeModelNodePlaceholder { readonly childIndex: number; readonly depth: number; readonly parentId?: string; } /** * Data structure that describes tree root node. * @public */ export interface TreeModelRootNode { readonly depth: -1; readonly id: undefined; readonly numChildren: number | undefined; } /** * Data structure that describes input used to create tree node. * @public */ export interface TreeModelNodeInput { readonly description?: string; readonly isExpanded: boolean; readonly id: string; readonly item: TreeNodeItem; readonly label: PropertyRecord; readonly isLoading: boolean; readonly numChildren?: number; readonly isSelected: boolean; } /** * Type definition of all tree model nodes. * @public */ export declare type TreeModelNodeType = TreeModelNode | TreeModelNodePlaceholder | TreeModelRootNode; /** * Checks if object is [[TreeModelNode]] * @public */ export declare function isTreeModelNode(obj: TreeModelNodeType | undefined): obj is TreeModelNode; /** * Checks if object is [[TreeModelNodePlaceholder]] * @public */ export declare function isTreeModelNodePlaceholder(obj: TreeModelNodeType | undefined): obj is TreeModelNodePlaceholder; /** * Checks if object is [[TreeModelRootNode]] * @public */ export declare function isTreeModelRootNode(obj: TreeModelNodeType | undefined): obj is TreeModelRootNode; /** * Type definition of tree node item data. * @public */ export declare type TreeNodeItemData = ImmediatelyLoadedTreeNodeItem & DelayLoadedTreeNodeItem; /** * Data structure that describes set of visible tree nodes as a flat list. * @public */ export interface VisibleTreeNodes extends Iterable { getNumNodes(): number; getAtIndex(index: number): TreeModelNode | TreeModelNodePlaceholder | undefined; getModel(): TreeModel; getNumRootNodes(): number | undefined; getIndexOfNode(nodeId: string): number; } /** * Data structure that describes tree model. * @public */ export interface TreeModel { getRootNode(): TreeModelRootNode; getNode(id: string): TreeModelNode | undefined; getNode(parentId: string | undefined, childIndex: number): TreeModelNode | TreeModelNodePlaceholder | undefined; getNode(nodeId: string | undefined, childIndex?: number): TreeModelNode | TreeModelNodePlaceholder | TreeModelRootNode | undefined; getChildren(parentId: string | undefined): SparseArray | undefined; getChildOffset(parentId: string | undefined, childId: string): number | undefined; iterateTreeModelNodes(parentId?: string): IterableIterator; } /** * Mutable tree model which holds nodes and allows adding or removing them. * @public */ export declare class MutableTreeModel implements TreeModel { [immerable]: boolean; private _tree; private _rootNode; /** Returns root node of a tree. This node is not visible and is there to allow having multiple visible root nodes. */ getRootNode(): TreeModelRootNode; /** Returns tree node or placeholder for node that is not loaded yet. * @returns node, node placeholder or undefined if node is not found in model. */ getNode(id: string): MutableTreeModelNode | undefined; getNode(parentId: string | undefined, childIndex: number): MutableTreeModelNode | TreeModelNodePlaceholder | undefined; /** Returns children for specific parent. * @param parentId id of parent node. * @returns children of parent node or root nodes if undefined is passed as parent id. */ getChildren(parentId: string | undefined): SparseArray | undefined; /** Returns children offset in children array for specific parent. */ getChildOffset(parentId: string | undefined, childId: string): number | undefined; /** * Sets children for parent node starting from the specific offset. * If offset overlaps with already added nodes, the overlapping nodes are overwritten. */ setChildren(parentId: string | undefined, nodeInputs: TreeModelNodeInput[], offset: number): void; /** * Inserts child in the specified position. * If offset is higher then current length of children array, the length is increased. */ insertChild(parentId: string | undefined, childNodeInput: TreeModelNodeInput, offset: number): void; /** * Changes the id of target node. * @returns `true` on success, `false` otherwise. */ changeNodeId(currentId: string, newId: string): boolean; /** * Transfers node along with its children to a new location. Fails if destination has undefined child count. * @param sourceNodeId Node that is being moved. * @param targetParentId Node that will receive a new child. * @param targetIndex Insertion location among target's *current* children. * @returns `true` on success, `false` otherwise. */ moveNode(sourceNodeId: string, targetParentId: string | undefined, targetIndex: number): boolean; private areNodesRelated; /** * Sets the number of child nodes a parent is expected to contain. All child nodes of this parent will be subsequently * removed. */ setNumChildren(parentId: string | undefined, numChildren: number | undefined): void; /** Removes children specified by id. * @param parentId id of the parent node. * @param child child node id or index that should be removed. */ removeChild(parentId: string | undefined, child: string | number): void; /** Removes all children for parent specified by id. * @param parentId id of parent node or undefined to remove root nodes. */ clearChildren(parentId: string | undefined): void; /** Generates flat list of visible nodes in the tree model. */ computeVisibleNodes(): VisibleTreeNodes; /** Iterates over all nodes present in the tree model. */ iterateTreeModelNodes(parentId?: string): IterableIterator; private static setNumChildrenForNode; private static createTreeModelNode; private static getVisibleDescendants; } //# sourceMappingURL=TreeModel.d.ts.map