import { CollectionComposer } from '@refinitiv-ui/utils/collection.js'; import type { TreeDataItem } from '../helpers/types'; import { TreeNode } from './tree-node.js'; export declare enum CheckedState { CHECKED = 1, UNCHECKED = 0, INDETERMINATE = -1 } export declare enum TreeManagerMode { /** * Maintains relationship states across children and parents. */ RELATIONAL = 1, /** * Items are independent of each other and do not maintain relationship states. */ INDEPENDENT = 0 } export declare class TreeManager { private _composer; /** * Collection composer used for managing the data */ get composer(): CollectionComposer; /** * Mode (algorithm) the tree manage is using */ private mode; /** * Last selected item timestamp */ private lastSelectedAt?; /** Cache map of TreeNode improving performance */ private treeNodeCache; /** * Most of the time, there is no need to create a new instance of Tree Manager manually. * Use the existing instance in components instead. * @param input Items or CollectionComposer to be managed. * @param mode A mode describing how items are managed either relationally or independently. */ constructor(input: T[] | CollectionComposer, mode?: TreeManagerMode); /** * Returns all items as an array of `TreeNode`. * @returns Array of `TreeNode` representing all items */ getTreeNodes(): TreeNode[]; /** * Returns a `TreeNode` of the original data item. * If the item doesn't exist, returns `null`. * @param item Original data item * @returns `TreeNode` of the original data item or `null` */ getTreeNode(item: T): TreeNode | null; /** * Is the manager maintaining parent/child relationships */ private get manageRelationships(); /** * Returns all items in the tree */ private get items(); /** * Returns all items with children */ private get parentItems(); /** * Returns all selected items. * When managing relationships, this excludes groups/parents from the result. */ get checkedItems(): readonly T[]; /** * Compare items function order by sequential selected timestamp */ protected get orderBySelectedAt(): (itemA: T, itemB: T) => number; /** * Returns items which their selected state can be changed. * Hidden, disabled or readonly items are not included. */ get editableItems(): readonly T[]; /** * Internal query for getting visible items/nodes * @param items Data item collection * @param result Resulting array of visible items * @returns Collection of visible items */ private getEditableItems; /** * Returns currently displayed items. * Hidden and children of unexpanded items are not included. */ get visibleItems(): readonly T[]; /** * Internal query for getting visible items/nodes * @param items Data item collection * @param result Resulting array of visible items * @returns Collection of visible items */ private getVisibleItems; /** * Is the item hidden? * @param item Original data item * @returns `True` if the item is hidden */ private isItemHidden; /** * Is the item checked? * @param item Original data item * @returns `True` if the item is checked */ private isItemChecked; /** * Is the item checked indeterminately? * @param item Original data item * @returns `True` if the item has managed relationships and contains checked descendants */ private isItemCheckedIndeterminate; /** * Determines whether the item is unchecked and can be changed to a checked state. * @param item Original data item * @returns True if the item can be changed to 'checked'. */ private canCheckItem; /** * Determines whether the item is checked and can be changed to an unchecked state. * @param item Original data item * @returns True if the item can be changed to 'unchecked'. */ private canUncheckItem; /** * Makes an item visible * @param item Original data item * @returns {void} */ private showItem; /** * Hides an item from the visible collection * @param item Original data item * @returns {void} */ private hideItem; /** * Forces a modification event, so that the renderer can update. * @param item Item of which to find path * @returns {void} */ private forceUpdateOnPath; /** * TODO: find a way to keep `noRelation` of Tree & Tree Select component in-sync * Sets the mode (algorithm) the manager should use * @hidden Mode updating doesn't sync back up Tree component. * @param mode Tree manager mode * @returns {void} */ setMode(mode: TreeManagerMode): void; /** * Requests the item to be rerendered manually. * Typically, this is not required. The render is triggered automatically when item's properties are updated. * @param item Original data item * @returns {void} */ updateItem(item: T): void; /** * Shows the item. * @hidden `hidden` usage in filterItems of Tree & Tree Select component conflicts with this API * @param item Original data item * @returns `True` if the item is newly included */ includeItem(item: T): boolean; /** * Hides the item. * @hidden `hidden` usage in filterItems of Tree & Tree Select component conflicts with this API * @param item Original data item * @returns `True` if the item is newly excluded */ excludeItem(item: T): boolean; /** * Returns whether the selected state of item can be changed or not. * @param item Original data item * @returns `True` if the item is not disabled or readonly */ isItemCheckable(item: T): boolean; /** * Returns the current expanded state of the item. * @param item Original data item * @returns `True` if the item is currently expanded so its children are visible. */ isItemExpanded(item: T): boolean; /** * Returns whether the item contains any children or not. * @param item Original data item * @returns `True` if the item has children */ isItemParent(item: T): boolean; /** * Returns whether the item has a parent or not. * @param item Original data item * @returns `True` if the item has a parent */ isItemChild(item: T): boolean; /** * Return checked state of the item. * @param item Original data item * @returns item checked state: CHECKED (1), UNCHECKED (0), INDETERMINATE (-1) */ getItemCheckedState(item: T): CheckedState; /** * Returns all ancestors of the item. * @param item Original data item * @returns An array of ancestors */ getItemAncestors(item: T): readonly T[]; /** * Returns all descendants of the item. * @param item Original data item * @param depth Depth of descendants to get. If it's `undefined`, get all descendants. * @returns An array of descendants */ getItemDescendants(item: T, depth?: number): readonly T[]; /** * Returns the parent of the item, if it has one. * @param item Original data item * @returns Item parent or `null` */ getItemParent(item: T): T | null; /** * Returns the children of the item as an array. * @param item Original data item * @returns An array of children */ getItemChildren(item: T): readonly T[]; /** * Expands the item to show its children. * @param item Original data item * @returns {void} */ expandItem(item: T): void; /** * Collapses the item to hide its children. * @param item Original data item * @returns {void} */ collapseItem(item: T): void; /** * Expands all items. * @returns {void} */ expandAllItems(): void; /** * Collapses all items. * @returns {void} */ collapseAllItems(): void; /** * Selects the item. * @param item Original data item * @returns `True` if the item is modified */ checkItem(item: T): boolean; private _checkItem; /** * Deselects the item. * @param item Original data item * @returns `True` if the item is modified */ uncheckItem(item: T): boolean; private _uncheckItem; /** * Toggle the selected state of the item. * @param item Original data item * @returns `true` if the item is modified successfully. */ toggleItem(item: T): boolean; /** * Selects all items. * @returns {void} */ checkAllItems(): void; /** * Deselects all items. * @returns {void} */ uncheckAllItems(): void; }