import type { RowId } from '../../Core/Data/DataProvider'; import type DataTable from '../../../Data/DataTable'; import type { CellType as DataTableCellType } from '../../../Data/DataTable'; /** * Tree View options. * * Turns hierarchical source data into expandable parent and child rows. To * build the hierarchy from repeated values in flat data, use * {@link RowGroupingOptions | `rowGrouping`} instead. */ export interface TreeViewOptions { /** * Enables tree view processing. It has to be set explicitly, declaring the * remaining tree view options alone does not enable the feature. * * @default false */ enabled?: boolean; /** * Input format definition used to build the tree index. * * When omitted, TreeView auto-detects the standard `parentId` or `path` * columns and prefers `path` when both exist. For custom input * definitions, set `treeView.input.type` explicitly. * * @sample grid-pro/tree-view/parent-id Parent ID tree input * @sample grid-pro/tree-view/input-path Path tree input */ input?: TreeInputOptions; /** * Column ID used as the tree column when rendering expand/collapse UI. */ treeColumn?: string; } /** * Row grouping options. * * Groups flat rows into expandable parent rows by repeated values in the * selected source columns. Group rows are generated by the Grid and rendered * in the `groupColumnId` column. */ export interface RowGroupingOptions { /** * Enables row grouping. It has to be set explicitly, declaring the * remaining row grouping options alone does not enable the feature. * * @sample grid-pro/options/row-grouping Row grouping * @default false */ enabled?: boolean; /** * Source column ID or IDs used as row grouping levels, ordered from the * top level down. * * @sample grid-pro/options/row-grouping Row grouping */ groupBy?: (string | string[]); /** * ID of the generated column rendering group row labels. It must not * collide with a source column ID, because it would shadow that column's * data. * * The generated column is the tree column of the grouped table unless * `treeView.treeColumn` is set. * * @default 'group' */ groupColumnId?: string; /** * Whether the columns listed in `groupBy` are hidden from the rendered * table. * * When `false`, grouped columns stay visible and group rows repeat the * group value of their own and their ancestor levels. * * @default true */ hideGroupByColumns?: boolean; } /** * Context passed to tree aggregator callbacks for a specific row/column. */ export interface TreeViewColumnAggregatorContext { /** * Grid column / source column id that is being aggregated. */ columnId: string; /** * Ordered direct children currently participating in the projected tree. */ childrenIds: RowId[]; /** * Number of direct children currently participating in the projected tree. */ childCount: number; /** * Tree depth of the current row in the projected tree. */ depth: number; /** * Whether the current row has direct children in the projected tree. */ hasChildren: boolean; /** * Row id of the current row. */ rowId: RowId; /** * Source cell value before aggregation is considered. */ sourceValue: DataTableCellType; } /** * Callback deciding which aggregation function should be applied for a row. * * Return a registered Formula processor function name (for example `SUM`), * or a falsy value to skip aggregation for the current row. */ export type TreeViewColumnAggregatorResult = (false | null | string | undefined); /** * Callback deciding which aggregation function should be applied for a row. */ export interface TreeViewColumnAggregatorCallback { (context: TreeViewColumnAggregatorContext): TreeViewColumnAggregatorResult; } /** * Aggregator option accepted by a TreeView column. * * Set it to `false` to skip aggregation for the column, resetting an aggregator * inherited from `columnDefaults`. */ export type TreeViewColumnAggregatorOption = (false | string | TreeViewColumnAggregatorCallback); /** * TreeView column options. * * TODO: Remove deprecated option before releasing next major */ export interface TreeViewColumnOptions { /** * Aggregator used for parent rows in the projected tree. */ aggregator?: TreeViewColumnAggregatorOption; } /** * Tree View options of the local data provider. * * TODO: Remove deprecated option before releasing next major */ export interface DeprecatedTreeViewOptions extends TreeViewOptions { /** * Explicit set of expanded row IDs, or `'all'` to expand all tree rows * initially. */ expandedRowIds?: TreeExpandedRowIds; /** * Enables sticky parent rows. */ stickyParents?: boolean; } /** * Number of initially expanded tree levels, or `'all'` for every level. */ export type TreeExpandedLevels = (number | 'all'); /** * Initial expansion seed for tree rows. * * TODO: Remove deprecated option before releasing next major */ export type TreeExpandedRowIds = RowId[] | 'all'; /** * Tree input options variants supported by TreeView. */ export type TreeInputOptions = (TreeInputParentIdOptions | TreeInputPathOptions); /** * Callback used to split a raw path value into ordered path segments. */ export type TreeInputPathSeparatorCallback = (path: string) => string[]; /** * Path segment separator definition for path-based tree input. */ export type TreeInputPathSeparator = (string | RegExp | TreeInputPathSeparatorCallback); /** * Parent-child relation input based on a parent ID column. */ export interface TreeInputParentIdOptions { /** * Type of the tree input. */ type: 'parentId'; /** * Column ID containing parent row IDs. * * Structural TreeView columns are reserved and rendered readonly. * @default 'parentId' */ parentIdColumn?: string; } /** * Parent-child relation input based on full node paths. */ export interface TreeInputPathOptions { /** * Type of the tree input. */ type: 'path'; /** * Column ID containing full node paths. * * Path values must be unique within the source table. * @default 'path' */ pathColumn?: string; /** * Path segment separator, a RegExp extracting ordered path segments, * or a callback returning ordered path segments. * * @sample grid-pro/tree-view/separator-callback Separator callback * @default '/' */ separator?: TreeInputPathSeparator; /** * Defines how path values are rendered when the path column is used as * the tree column. * * If `true`, renders complete paths. If `false`, renders only * the current path segment (leaf node name). * * @default false */ showFullPath?: boolean; } /** * Canonical tree node record used by TreeView internals. */ export interface TreeNodeRecord { /** * Stable tree node ID. * * For source-backed rows this matches `data.idColumn` or original row * index. For autogenerated path parents this is a synthetic node ID. */ id: RowId; /** * Parent tree node ID, or `null` for roots. */ parentId: RowId | null; /** * Source row index when the node comes from input data. * * Autogenerated path parents do not have a backing source row and keep * this as `null`. */ rowIndex: number | null; isGenerated?: boolean; path?: string; /** * Group values of the node level and all its ancestor levels, ordered as * the configured grouping columns. * * Set for generated group rows only. */ groupValues?: DataTableCellType[]; /** * Ordered direct child tree node IDs. */ childrenIds: RowId[]; } /** * Canonical tree index produced from input data. */ export interface TreeIndexBuildResult { /** * Canonical tree nodes keyed by stable tree node ID. */ nodes: Map; /** * Input-order tree node IDs including autogenerated path parents. */ rowOrder: RowId[]; } /** * Tree metadata for a single visible row in projected order. */ export interface TreeProjectionRowState { childrenIds: RowId[]; id: RowId; parentId: RowId | null; depth: number; hasChildren: boolean; isExpanded: boolean; lastVisibleDescendantId?: RowId; isAncestorOnly?: boolean; } /** * Tree projection state cache for currently projected rows. */ export interface TreeProjectionState { derivedCellColumnIdsByRowId: Map>; /** * Projected tree node IDs in visible/rendered order. * * This remains the TreeView source of truth even when rendered `TableRow` * instances need their `row.id` synchronized later. */ rowIds: RowId[]; /** * Source-backed row indexes for projected nodes. * * Generated tree nodes keep `undefined` entries here. */ rowIndexes: Array; /** * Lookup from projected tree node ID to source row index. */ sourceRowIndexesById: Map; /** * Per-node projection metadata keyed by projected tree node ID. */ rowsById: Map; } /** * Adapter contract for tree input formats. */ export interface TreeInputAdapter { buildIndexFromColumns(table: DataTable, input: TreeInputOptions, idColumn?: string): TreeIndexBuildResult; }