import { IEventSystem } from "../../ts-common/events"; import { DataCollection } from "./datacollection"; import { DataCallback, DataEvents, IDataCollection, IDataItem, ITreeCollection, IFilterCallback, IFilterMode, IFilterComplexMode, ITreeFilterConfig, DataDriver, ISortMode, IDataDriver, IUpdateObject, ISortConfig } from "./types"; import { Id } from "../../ts-common/types"; export declare function addToOrder(store: any, obj: object, parent: Id, index: number): void; export declare class TreeCollection extends DataCollection implements ITreeCollection { protected _children: { [id: string]: T[]; }; protected _root: Id; protected _initChildren: { [id: string]: T[]; }; constructor(config?: any, events?: IEventSystem); add(newItem: IDataItem, index?: number, parent?: Id): Id; add(newItem: IDataItem[], index?: number, parent?: Id): Id[]; getRoot(): Id; getParent(id: Id, asObj?: boolean): Id; getItems(id: Id): T[]; getLength(id?: Id): number; removeAll(id?: Id): void; update(id: Id, newItem: IUpdateObject, silent?: boolean): void; getIndex(id: Id): number; /** * Sorts the tree, reordering the items within each parent independently. * The rules are combined the same way as in {@link DataCollection.sort}, but unlike it this * method has no lazy-loading guard and reorders whatever is currently in the tree. * @param rule - The sorting rule. Omit to reset the sorting. * @param config - Options that control how the rule is combined with the already applied ones. * @param ignore - Internal. Reorders the data without recording the rule in the sorting state * and without firing the `change` event. A call that resets the sorting still clears the state. * Defaults to `false`. */ sort(rule?: ISortMode, config?: ISortConfig, ignore?: boolean): void; /** * Filters the tree, keeping the matched items together with their parent chain. * By default every item at every nesting level is matched; `config.type` narrows that * to a single level or to leaf items only. Rules are stored and combined the same way as in * {@link DataCollection.filter}, but a rule without `compare` is matched differently: the field * value has to contain `match` ignoring case, rather than be loosely equal to it, and a rule * with an empty `match` is skipped instead of filtering everything out. * @param rule - A single rule, a set of rules combined with AND, or a predicate. Omit to reset filtering. * @param config - Options that control which items the rule is matched against and how it is stored. * @param silent - Whether to suppress the `filter` event. Defaults to `false`. * @returns The id the filter is stored under, or `undefined` if no rule was passed. * @example * ```ts * // match every item at any level * collection.filter({ by: "status", match: "done" }); * * // match leaf items only * collection.filter({ by: "status", match: "done" }, { type: "leafs" }); * ``` */ filter(rule?: IFilterMode | IFilterComplexMode | IFilterCallback, config?: ITreeFilterConfig, silent?: boolean): string; /** * Restores the original order of the tree, dropping the sorting and every filter, * permanent ones included. */ restoreOrder(): void; copy(id: Id, index: number, target?: IDataCollection | ITreeCollection, targetId?: Id): Id; copy(id: Id[], index: number, target?: IDataCollection | ITreeCollection, targetId?: Id): Id[]; move(id: Id, index: number, target?: ITreeCollection | IDataCollection, targetId?: Id): Id; move(id: Id[], index: number, target?: ITreeCollection | IDataCollection, targetId?: Id): Id[]; forEach(callback: DataCallback, parent?: Id, level?: number): void; eachChild(id: Id, callback: DataCallback, direct?: boolean, checkItem?: (item: IDataItem) => boolean): void; getNearId(id: Id): Id; loadItems(id: Id, driver?: IDataDriver | DataDriver): void; refreshItems(id: Id, driver?: IDataDriver | DataDriver): void; eachParent(id: Id, callback: DataCallback, self?: boolean): void; haveItems(id: Id): boolean; canCopy(id: Id, target: Id): boolean; serialize(driver?: DataDriver, checkItem?: (item: any) => any): any; getId(index: number, parent?: Id): Id; map(callback: DataCallback, parent?: Id, direct?: boolean): any[]; getRawData(from: number, to: number, order?: T[], mode?: number, parent?: Id): T[]; protected flatten(input: T[]): T[]; protected _add({ newItem, index, parent, order, batch, }: { newItem: IDataItem; batch: IDataItem[]; index: number; parent: Id; order?: number; }): Id; protected _setParent(item: IDataItem, parent: Id): void; protected _copy(id: Id, index: number, target?: IDataCollection | ITreeCollection, targetId?: Id, key?: number): Id; protected _move(id: Id, index: number, target?: ITreeCollection | IDataCollection, targetId?: Id, key?: number): Id; protected _moveItem(id: any, targetId: any, index: any): void; protected _reset(config: { id?: Id; grouping: any; }): void; protected _removeCore(id: Id): void; private _removeFromParentList; private _removeChildren; private _removeFromOrders; protected _addToOrder(_order: any, obj: any, index: number): void; protected _parse_data(data: any, parent?: Id): void; protected _parseItem(item: any): void; private _recursiveFilter; private _serialize; /** * Narrows the tree by a single rule, keeping the parent chain of every matched item * and remembering the unfiltered tree on first use. * @param rule - The rule to apply. A missing or empty rule is a no-op. * @param config - Options that control which items the rule is matched against. * @throws If the rule is neither a predicate nor a valid field/value pair. * @internal */ private _applyFilter; /** * Unwraps the stored filters into their bare rules, keeping them keyed by filter id. * Unlike {@link DataCollection._normalizeFilters} it does not turn the rules into predicates: * {@link TreeCollection._applyFilter} needs the original rule to walk the tree, and it needs the * id to look the matching config up. * @param filters - The stored filters. * @returns The bare rules, keyed by filter id. * @internal */ protected _normalizeFilters(filters: any): any; protected _checkFilterRule(rule: IFilterMode | IFilterComplexMode | IFilterCallback): boolean; /** * Drops the sorting rules and rebuilds the tree in the order it had before sorting. * If filtering was applied on top of the sorting, it is reapplied to the restored tree. * @internal */ protected _resetSorting(): void; /** * Reorders the children of every parent by all currently stored sorting rules. * @internal */ protected _applySorters(): void; }