import { EventEmitter } from '../event/event-emitter.js'; import { CollectionItem } from './collection-item.js'; /** * Manages boolean states of a data collection, * toggling various item options in the most performant way possible. */ export declare class CollectionComposer extends EventEmitter { /** * The original data which is * passed into the constructor. */ private readonly data; private depths; /** * Scheduler used to emit events. */ private emitter; /** * Emits a modification event when * something has changed in the collection * @returns {void} */ private emitModification; /** * Current key index to use for creating item keys. */ private key; /** * Items keys used for modifications. * Composite keys are created, using item key + property name. */ private keys; /** * Storage location for property changes. */ private modifications; /** * Initialisation timestamp */ private timestamp; /** * Storage location for change timestamps. */ private timestamps; /** * Collection of locked items */ private vault; constructor(data: T[] | CollectionComposer); /** * Returns the top level items only. * To get nested levels, use `getItemChildren()`. */ private get topLevelItems(); /** * Collection of all items. * @returns Collection of data items */ private get items(); private _items?; /** * Returns the size of the collection. * Nested structures will include all descendants. */ get size(): number; /** * Updates item timestamp and emits a modification event * @param item Original data item * @returns {void} */ private registerItemModification; /** * Clones a composer instance, * copying data over into the current instance. * @param composer Composer to clone * @returns Copy of the original composer's data object */ private clone; /** * Returns the modification key for the item * @param item Original data item * @returns Unique item key */ private getItemKey; /** * Returns the modification key for the item property * @param item Original data item * @param property Property name * @returns Unique item property key */ private getItemPropertyKey; /** * Checks to see if the item is included in the composer * @param item Original data item to check * @returns True, if the item is valid. */ private isValidItem; /** * Checks to see if the item isn't included in the composer * @param item Original data item to check * @returns True, if the item is invalid. */ private isInvalidItem; /** * Gets the index range of the item. * This includes the indexes of all descendants. * @param item Original data item * @returns Start and end index range of item and descendants */ private getItemIndexRange; /** * Add a new item at a specified index with a specified depth * @param item Data item to add * @param index Index to place the item * @param [depth=0] Depth of the item * @returns {void} */ private addItemAtIndex; /** * Removes an item at a specific index * @param index Index to remove from the collection * @returns {void} */ private removeItemAtIndex; /** * Add new item to the main collection * @param item New data item * @return {void} */ addItem(item: T): void; /** * Add new item to the main collection at a specific index * @param item New data item * @param index Index location to add the item * @return {void} */ addItem(item: T, index: number): void; /** * Add new item to a parent collection * @param item New data item * @param parent Parent to add the item to * @return {void} */ addItem(item: T, parent: T): void; /** * Add new item to a parent collection at a specific index * @param item New data item * @param parent Parent to add the item to * @param index Index location to add the item * @return {void} */ addItem(item: T, parent: T, index: number): void; /** * Removes a data item from the composer * @param item Data item to remove * @returns {void} */ removeItem(item: T): void; /** * Locks the item in the vault. * This prevents any future modifications. * @param item Original data item * @returns Whether the item was added or not */ lockItem(item: T): boolean; /** * Unlocks the item from the vault. * This enables any future modifications. * @param item Original data item * @returns Whether the item was removed or not */ unlockItem(item: T): boolean; /** * Determines if the item is locked. * @param item Original data item * @returns Locked state */ isItemLocked(item: T): boolean; /** * Determines if the item has children * and is therefore a parent item. * @param item Original data item * @returns Whether the item is a parent or not */ isItemParent(item: T): boolean; /** * Determines if the item has a parent * and is therefore a child item. * @param item Original data item * @returns Whether the item is a child or not */ isItemChild(item: T): boolean; /** * Gets the property value of an item * @param item Original data item * @param property Property name to get the value of * @returns Value of the property */ getItemPropertyValue(item: T, property: K): T[K]; /** * Sets the property value of an item * @param item Original data item * @param property Property name to set the value of * @param value New value of the property * @returns {void} */ setItemPropertyValue(item: T, property: K, value: T[K]): void; /** * Gets the nested depth of the item. * @param item Original data item * @returns Depth of item */ getItemDepth(item: T): number; /** * Gets the timestamp of when the item was last updated. * If no updates have occurred, the timestamp of composer creation is returned instead. * @param item Original data item * @returns Item timestamp */ getItemTimestamp(item: T): number; /** * Updates the item timestamp, * causing an item modification without changing any properties. * @param item Original data item * @returns Latest item timestamp */ updateItemTimestamp(item: T): number; /** * Gets all items with a matching property value * @param property Property name * @param value Value to compare against * @param [depth=0] Depth of nested data to include * @returns Matched items */ queryItemsByPropertyValue(property: K, value: T[K], depth?: number): readonly T[]; /** * Query items, return results which are matched * against the comparison engine. * @param engine Comparison engine for matching results * @param [depth=0] Depth of nested data to include * @returns Matched items */ queryItems(engine: (item: T, composer: CollectionComposer) => boolean, depth?: number): readonly T[]; /** * Gets the item parent, if available. * @param item Original data item * @returns The parent data item, or, `null`. */ getItemParent(item: T): T | null; /** * Gets the list of item ancestors. * @param item Original data item * @returns Array of data items in the order of shallowest to deepest */ getItemAncestors(item: T): readonly T[]; /** * Gets the list of item siblings. * @param item Original data item * @returns Array of sibling data items */ getItemSiblings(item: T): readonly T[]; /** * Gets the list of item children. * @param item Original data item * @returns Array of child data items */ getItemChildren(item: T): readonly T[]; /** * Gets the list of item descendants. * @param item Original data item * @param [depth=Infinity] Depth of nested data to include * @returns Array of data items in the order of shallowest to deepest */ getItemDescendants(item: T, depth?: number): readonly T[]; }