import type { HotInstance } from '../../../core/types'; import type { NestedRows } from '../nestedRows'; type ReadTreeResult = number | { result: unknown; end: boolean; }; export interface RowObject { __children?: RowObject[]; [key: string]: unknown; } interface NodeInfo { parent: RowObject | null; row: number; level: number; } interface CacheStructure { levels: RowObject[][]; levelCount: number; rows: RowObject[]; nodeInfo: WeakMap; } /** * Class responsible for making data operations. * * @private */ declare class DataManager { /** * Main Handsontable instance reference. * * @type {object} */ hot: HotInstance; /** * Reference to the source data object. * * @type {Handsontable.CellValue[][]|Handsontable.RowObject[]} */ data: RowObject[] | null; /** * Reference to the NestedRows plugin. * * @type {object} */ plugin: NestedRows; /** * Map of row object parents. * * @type {WeakMap} */ parentReference: WeakMap; /** * Nested structure cache. * * @type {object} */ cache: CacheStructure; /** * Initializes the data manager with references to the NestedRows plugin and the Handsontable instance. */ constructor(nestedRowsPlugin: NestedRows, hotInstance: HotInstance); /** * Set the data for the manager. * * @param {Handsontable.CellValue[][]|Handsontable.RowObject[]} data Data for the manager. */ setData(data: RowObject[]): void; /** * Get the data cached in the manager. * * @returns {Handsontable.CellValue[][]|Handsontable.RowObject[]} */ getData(): RowObject[] | null; /** * Load the "raw" source data, without NestedRows' modifications. * * @returns {Handsontable.CellValue[][]|Handsontable.RowObject[]} */ getRawSourceData(): unknown[] | object[]; /** * Update the Data Manager with new data and refresh cache. * * @param {Handsontable.CellValue[][]|Handsontable.RowObject[]} data Data for the manager. */ updateWithData(data: RowObject[]): void; /** * Rewrite the nested structure cache. * * @private */ rewriteCache(): void; /** * Cache a data node. * * @private * @param {object} node Node to cache. * @param {number} level Level of the node. * @param {object} parent Parent of the node. */ cacheNode(node: RowObject, level: number, parent: RowObject | null): void; /** * Get the date for the provided visual row number. * * @param {number} row Row index. * @returns {object} */ getDataObject(row: number): RowObject | null | undefined; /** * Read the row tree in search for a specific row index or row object. * * @private * @param {object} parent The initial parent object. * @param {number} readCount Number of read nodes. * @param {number} neededIndex The row index we search for. * @param {object} neededObject The row object we search for. * @returns {number|object} */ readTreeNodes(parent: RowObject | null, readCount: ReadTreeResult, neededIndex: number, neededObject: Record): ReadTreeResult; /** * Mock a parent node. * * @private * @returns {*} */ mockParent(): RowObject; /** * Mock a data node. * * @private * @returns {{}} */ mockNode(): RowObject; /** * Get the row index for the provided row object. * * @param {object} rowObj The row object. * @returns {number} Row index. */ getRowIndex(rowObj: unknown): number | null; /** * Get the index of the provided row index/row object within its parent. * * @param {number|object} row Row index / row object. * @returns {number} */ getRowIndexWithinParent(row: number | RowObject): number; /** * Count all rows (including all parents and children). * * @returns {number} */ countAllRows(): number; /** * Count children of the provided parent. * * @param {object|number} parent Parent node. * @returns {number} Children count. */ countChildren(parent: RowObject | number): number; /** * Get the parent of the row at the provided index. * * @param {number|object} row Physical row index. * @returns {object} */ getRowParent(row: number | RowObject): RowObject | null; /** * Get the parent of the provided row object. * * @private * @param {object} rowObject The row object (tree node). * @returns {object|null} */ getRowObjectParent(rowObject: unknown): RowObject | null; /** * Get the nesting level for the row with the provided row index. * * @param {number} row Row index. * @returns {number|null} Row level or null, when row doesn't exist. */ getRowLevel(row: number | RowObject): number | null; /** * Get the nesting level for the row with the provided row index. * * @private * @param {object} rowObject Row object. * @returns {number} Row level. */ getRowObjectLevel(rowObject: unknown): number | null; /** * Check if the provided row/row element has children. * * @param {number|object} row Row number or row element. * @returns {boolean} */ hasChildren(row: number | RowObject): boolean; /** * Returns `true` if the row at the provided index has a parent. * * @param {number} index Row index. * @returns {boolean} `true` if the row at the provided index has a parent, `false` otherwise. */ isChild(index: number): boolean; /** * Get child at a provided index from the parent element. * * @param {object} parent The parent row object. * @param {number} index Index of the child element to be retrieved. * @returns {object|null} The child element or `null` if the child doesn't exist. */ getChild(parent: RowObject, index: number): RowObject | null; /** * Return `true` of the row at the provided index is located at the topmost level. * * @param {number} index Row index. * @returns {boolean} `true` of the row at the provided index is located at the topmost level, `false` otherwise. */ isRowHighestLevel(index: number): boolean; /** * Return `true` if the provided row index / row object represents a parent in the nested structure. * * @param {number|object} row Row index / row object. * @returns {boolean} `true` if the row is a parent, `false` otherwise. */ isParent(row: number | RowObject): boolean; /** * Add a child to the provided parent. It's optional to add a row object as the "element". * * @param {object} parent The parent row object. * @param {object} [element] The element to add as a child. */ addChild(parent: RowObject, element?: RowObject): void; /** * Add a child node to the provided parent at a specified index. * * @param {object} parent Parent node. * @param {number} index Index to insert the child element at. * @param {object} [element] Element (node) to insert. */ addChildAtIndex(parent: RowObject | null, index: number, element: RowObject | null): void; /** * Add a sibling element at the specified index. * * @param {number} index New element sibling's index. * @param {('above'|'below')} where Direction in which the sibling is to be created. */ addSibling(index: number, where?: string): void; /** * Detach the provided element from its parent and add it right after it. * * @param {object|Array} elements Row object or an array of selected coordinates. * @param {boolean} [forceRender=true] If true (default), it triggers render after finished. */ detachFromParent(elements: RowObject | number[], forceRender?: boolean): void; /** * Filter the data by the `logicRows` array. * * @private * @param {number} index Index of the first row to remove. * @param {number} amount Number of elements to remove. * @param {Array} logicRows Array of indexes to remove. */ filterData(index: number, amount: number, logicRows: number[]): void; /** * Used to splice the source data. Needed to properly modify the nested structure, which wouldn't work with the * default script. * * @private * @param {number} index Physical index of the element at the splice beginning. * @param {number} amount Number of elements to be removed. * @param {object[]} elements Array of row objects to add. */ spliceData(index: number, amount: number, elements: RowObject[] | null): void; /** * Update the `__children` key of the upmost parent of the provided row object. * * @private * @param {object} rowElement Row object. */ syncRowWithRawSource(rowElement: RowObject): void; /** * Move a single row. * * @param {number} fromIndex Index of the row to be moved. * @param {number} toIndex Index of the destination. * @param {boolean} moveToCollapsed `true` if moving a row to a collapsed parent. * @param {boolean} moveToLastChild `true` if moving a row to be a last child of the new parent. */ /** * */ moveRow(fromIndex: number, toIndex: number, moveToCollapsed: boolean, moveToLastChild: boolean): void; /** * Translate the visual row index to the physical index, taking into consideration the state of collapsed rows. * * @private * @param {number} row Row index. * @returns {number} */ translateTrimmedRow(row: number): number; /** * Translate the physical row index to the visual index, taking into consideration the state of collapsed rows. * * @private * @param {number} row Row index. * @returns {number} */ untranslateTrimmedRow(row: number): number; } export default DataManager;