import type DataTable from '../../../../Data/DataTable'; import type Grid from '../../../Core/Grid'; import type { RowId } from '../../../Core/Data/DataProvider'; import type { TreeProjectionState } from '../TreeViewTypes'; import type { ResolvedTreeViewOptions } from '../TreeViewOptionsNormalizer'; /** * Infrastructure controller for TreeView projection state. * * Validates tree input options, builds a canonical relation index and projects * queried tables into tree order before pagination. */ declare class TreeProjectionController { private readonly grid; private readonly aggregationResolver; private indexCache?; private projectionStateCache?; private expansionStateSeedKey?; private resolvedOptions?; private rowGroupingIgnoredWarned?; private cacheSource?; constructor(grid: Grid); /** * Synchronizes internal state from current Grid options and provider. */ sync(): void; /** * Returns resolved TreeView options for the current source table. */ get options(): ResolvedTreeViewOptions | undefined; /** * Warns once when row grouping is ignored, because tree view is enabled at * the same time. * * @param isIgnored * Whether row grouping is currently ignored. */ private syncRowGroupingIgnoredWarning; /** * Returns metadata for currently projected rows. */ getProjectionState(): TreeProjectionState | undefined; /** * Returns whether a source column participates in TreeView aggregation. * * @param columnId * Source column id. */ hasColumnAggregation(columnId: string): boolean; /** * Returns source column ids hidden from the projected table. */ getHiddenSourceColumnIds(): string[] | undefined; /** * Returns whether a projected cell is currently derived from aggregation. * * @param rowId * Row id of the projected row. * * @param columnId * Grid / source column id. */ isCellDerived(rowId: RowId | undefined, columnId: string): boolean; /** * Returns whether a projected row is auto-generated by TreeView. * * @param rowId * Row id of the projected row. */ isGeneratedRow(rowId: RowId | undefined): boolean; /** * Toggles expansion state for a row in current projection. * * @param rowId * Row ID to toggle. * * @param redraw * Whether to redraw rows after state change. * * @param originalEvent * Browser event that initiated the toggle. * * @returns * Promise resolving to `true` when state changed, otherwise `false`. */ toggleRow(rowId: RowId, redraw?: boolean, originalEvent?: TreeRowToggleTriggerEvent): Promise; /** * Expands all currently expandable tree rows. * * @param redraw * Whether to redraw rows after state change. * * @returns * Promise resolving to `true` when state changed, otherwise `false`. */ expandAll(redraw?: boolean): Promise; /** * Collapses all currently expandable tree rows. * * @param redraw * Whether to redraw rows after state change. * * @returns * Promise resolving to `true` when state changed, otherwise `false`. */ collapseAll(redraw?: boolean): Promise; /** * Projects a queried table into TreeView row order and visibility. * * @param table * Table after sort/filter and before pagination. * * The input table is expected to be after sort/filter, but before * pagination. If TreeView is disabled, unchanged table is returned. */ projectTable(table: DataTable): DataTable; /** * Destroys controller state. */ destroy(): void; /** * Clears cached index, projection state, and source metadata. */ private clearCache; /** * Marks rows as dirty and schedules redraw after projection state updates. * * @param redraw * Whether to redraw rows immediately. */ private requestRowsRedraw; /** * Ensures row metadata record exists for a row. * * @param rowId * Row ID. * * @returns * Row metadata record. */ private ensureRowMetaRecord; /** * Removes empty row metadata records. * * @param rowId * Row ID. */ private cleanupRowMeta; /** * Clears TreeView metadata state for all rows. */ private clearTreeRowMetaState; /** * Sets explicit expanded state for a row. * * @param rowId * Row ID. * * @param expanded * Whether row should be explicitly expanded. * * @returns * `true` when state changed. */ private setRowMetaExpanded; /** * Returns data options with TreeView extension for local provider. */ private getDataOptions; /** * Builds canonical tree index for currently selected input type. * * @param table * Source table. * * @param input * Normalized input configuration. * * @param idColumn * Column ID containing stable row IDs, when configured. * * @returns * Canonical tree index. */ private buildIndexFromInput; /** * Synchronizes expansion state for tree nodes with children. * * Re-initializes state when expansion seed changes, otherwise prunes * entries that are no longer expandable. */ private syncExpandedRowIdsState; /** * Returns whether a tree node is initially expanded by its depth. * * @param nodeId * Tree node ID. * * @param nodeDepths * Cache of already resolved node depths. */ private isExpandedByLevel; /** * Resolves the depth of a tree node in the source tree index. * * @param nodeId * Tree node ID. * * @param nodeDepths * Cache of already resolved node depths. */ private getNodeDepth; /** * Computes projected row order and per-row tree metadata for visible rows. * * @param table * Queried table after sort/filter and before pagination. * * @param idColumn * Column containing row IDs, when configured. * * @returns * Projection state describing visible rows in tree order. */ private projectToVisibleState; /** * Applies tree-local sorting when active sort columns depend on * aggregation, which becomes available only during TreeView projection. * * @param table * Queried table after filtering/sorting and before pagination. * * @param rootIds * Root ids in the projected logical tree. * * @param childrenByParent * Direct children ids keyed by parent id. * * @param rowIndexById * Source row indexes keyed by row id. * * @param rowsById * Logical projected tree row states. * * @param idColumn * Column containing stable row IDs, when configured. */ private sortProjectedTreeNodes; /** * Returns whether sorting the column depends on projected tree values. * * @param sourceColumnId * Source column id. */ private requiresProjectedTreeSort; /** * Resolves output column IDs for the projected table. * * @param sourceColumnIds * Source column IDs from the queried table. * * @returns * Column IDs to include in the projected table. */ private getProjectedColumnIds; /** * Builds a projected table by reordering all columns to projected indexes. * * @param table * Input queried table. * * @param projectionState * Projection state for table rebuild. * * @param aggregateColumnIds * Source column ids that should be aggregated in the projected table. * * @param projectedColumnIds * Column ids included in the projected table. * * @param idColumn * Column containing stable row IDs, when configured. * * @returns * Cloned table with projected column values and row index references. */ private createProjectedTable; /** * Returns source column ids configured for TreeView aggregation. * * @param columnIds * Source column ids available in the queried table. */ private getAggregateColumnIds; /** * Resolves a cell value for the projected logical tree before aggregation. * * @param columnId * Source column id. * * @param rowId * Row id in the projected logical tree. * * @param table * Queried table after filtering/sorting and before pagination. * * @param projectionState * Current projected tree state. * * @param idColumn * Column containing stable row IDs, when configured. */ private resolveProjectedCellValue; /** * Resolves aggregator option for a source column id. * * @param sourceColumnId * Source column id. */ private getColumnAggregatorOption; /** * Returns whether a source column is the generated grouping display column. * * @param sourceColumnId * Source column id. */ isGroupingDisplayColumn(sourceColumnId: string): boolean; /** * Returns whether a source column is reserved for TreeView structure. * * @param sourceColumnId * Source column id. */ isTreeSpecialColumn(sourceColumnId: string): boolean; /** * Resolves column value for an auto-generated tree path row. * * @param columnId * Target column ID. * * @param rowId * Generated row ID. * * @param idColumn * Column containing stable row IDs, when configured. * * @returns * Cell value for generated row, or `null` for unsupported columns. */ private getGeneratedCellValue; /** * Resolves cell value for an injected ancestor row from the source table. * * @param columnId * Target column ID. * * @param rowId * Ancestor row ID. * * @returns * Cell value from the source table, or `null` when unavailable. */ private getSourceTableCellValue; } /** * Browser event that triggered a tree row toggle. */ export type TreeRowToggleTriggerEvent = KeyboardEvent | MouseEvent; /** * Shared event payload for tree row toggle events. */ interface TreeRowToggleEvent { /** * Browser event that initiated the toggle, when available. */ originalEvent?: TreeRowToggleTriggerEvent; /** * Row ID for the toggled tree row. */ rowId: RowId; } /** * Event payload fired before a tree row toggle. */ export interface BeforeTreeRowToggleEvent extends TreeRowToggleEvent { /** * Expanded state requested by the toggle. */ expanded: boolean; /** * Whether the toggle was canceled. */ defaultPrevented?: boolean; /** * Prevents the tree row toggle. */ preventDefault: () => void; } /** * Event payload fired after a tree row toggle. */ export interface AfterTreeRowToggleEvent extends TreeRowToggleEvent { /** * Expanded state after the toggle. */ expanded: boolean; } export default TreeProjectionController;