UNPKG

ag-grid-community

Version:

Advanced Data Grid / Data Table supporting Javascript / Typescript / React / Angular / Vue

81 lines (80 loc) 5.42 kB
import type { NamedBean } from '../../context/bean'; import { BeanStub } from '../../context/beanStub'; import type { ColDef } from '../../entities/colDef'; import type { UserColumnPropertyKey, UserColumnState } from '../../interfaces/gridState'; /** One column's user-owned layer entry. `properties` holds the definition the user configured; a * `removed` entry is a tombstone for a `columnDefs`-declared column the user deleted. */ interface UserColumnEntry { properties?: ColDef; /** The user created this column, rather than changing one the developer declared. */ created?: boolean; parentGroupId?: string | null; removed?: boolean; } /** Owns the user-column layer: columns created at runtime (e.g. through the Calculated Column dialog), * property overrides on `columnDefs`-declared columns, and tombstones for ones the user removed. The * layer is merged where developer `columnDefs` enter the column tree build, so every other service sees * ordinary column definitions and needs no knowledge of grid state. * * Entries are the record of what the user changed — nothing is derived by diffing definitions, and no * marker is stamped on the column. Only serialisable definition properties belong here: properties owned * by other state sections (width, hide, pinned, sort, …) stay with those sections. * @internal AG_GRID_INTERNAL - Not for public use. Can change / be removed at any time. */ export declare class UserColumnService extends BeanStub implements NamedBean { beanName: "userColumnSvc"; private readonly entries; /** Owners' enabled checks. An entry only reaches the built columns while an owner is active, so a * disabled feature (or an unregistered module) preserves state without acting on it. */ private readonly owners; /** Union of the properties the registered owners' UI can produce, or `null` while none have registered. */ private ownedProperties; /** `colModel.colDefs` the declared lookup was built from; a new array rebuilds it. */ private declaredDefsSource; private declaredDefs; /** Registers a feature that builds user columns, along with its enabled check and the definition * properties its UI lets a user configure. Incoming state is filtered to the registered properties, so * the layer stays a record of user choices rather than a second route into `columnDefs`. */ registerOwner(isEnabled: () => boolean, ownedProperties: readonly UserColumnPropertyKey[]): void; isActive(): boolean; /** The definition the developer declared for `colId`, untouched by any entry. The built column cannot * serve: after the first rebuild its `userProvidedColDef` is the declaration with the entry already * merged in, and a tombstoned column is not built at all. */ getDeclaredDef(colId: string): ColDef | undefined; isDeclared(colId: string): boolean; getEntry(colId: string): UserColumnEntry | undefined; forEachEntry(callback: (entry: UserColumnEntry, colId: string) => void): void; hasEntries(): boolean; /** Records a column the user created, along with the group it belongs to. */ setCreatedColumn(colId: string, properties: ColDef, parentGroupId: string | null): void; /** Records the properties the user changed on a `columnDefs`-declared column. Placement is left alone: * the declared column stays where the developer put it. */ setOverride(colId: string, properties: ColDef): void; /** Tombstones a `columnDefs`-declared column so it stays removed across restores; a created column is * simply dropped, as nothing would resurrect it. */ removeColumn(colId: string, declared: boolean): void; /** Drops a column's entry, reverting it to whatever `columnDefs` declares. */ clearColumn(colId: string): void; /** Drops the whole layer, returning whether it held anything. */ clear(): boolean; /** Build hook for `columnDefs`-declared columns: `null` when the user removed the column (never * built), the merged definition when the user overrode properties, else `undefined`. * * Matching happens on the declared key, before the build allocates a suffixed id for duplicates, so * entries for several definitions sharing a `field` follow declaration order rather than the ids they * end up with. */ overrideFor(def: ColDef): ColDef | null | undefined; getState(): UserColumnState[] | undefined; /** Replaces the layer with `states`. Returns whether anything changed, so the caller can skip the * column tree rebuild when a re-applied state is identical. */ setState(states: UserColumnState[] | undefined): boolean; /** Converts a state entry's properties into a definition, keeping only what a registered owner's UI can * produce with a serialisable value. `UserColumnProperty` already refuses anything else at compile * time, so what reaches here is untyped state — a stored payload or hand-written JavaScript — and is * dropped silently rather than merged into the column. * * With no owner registered the properties pass through untouched: there is nothing to validate against, * the entries never reach the built columns, and they must re-save unchanged so a state saved on a * grid that has the feature is not lossy on one that does not. */ private acceptProperties; } export {};