import type { ColumnDef, ColumnDefInput, Column, ColumnState, ColumnPinPosition, AggFunc } from '../types/column.types'; import type { GridStore } from './grid-store'; import type { EventBus } from '../event-bus/event-bus'; /** * Recursively normalizes an author-supplied {@link ColumnDefInput} tree into a * fully-typed {@link ColumnDef} tree — filling `colId`, `header` and `type` * defaults on every node (leaves and groups) so downstream consumers, including * the column-group engine, never see missing fields. `colId`s are assigned from * a single running counter so the group tree and the flattened leaf list agree. */ export declare function normalizeColumnTree(input: ReadonlyArray): ColumnDef[]; export declare class ColumnModel { private store; private eventBus; private columns; /** * Snapshot of the column state captured at the last {@link initColumns} call, * so {@link resetColumnState} can restore the original widths, visibility, * pin positions, sort, and order after the user has rearranged the grid. */ private initialColumnStates; /** * Deep-ish clones of each column's definition captured at the last * {@link initColumns} call, keyed by `colId`. Lets {@link resetColumn} restore * a single column's full definition (header, width, pin, flags, aggFunc, …). */ private initialColumnDefs; constructor(store: GridStore, eventBus: EventBus); initColumns(defs: ReadonlyArray): void; getColumn(colId: string): Column | undefined; getAllColumns(): Column[]; getVisibleColumns(): Column[]; setColumnWidth(colId: string, width: number, finished?: boolean): void; /** * Applies several column widths in one operation, clamping each to its * min/max, then emits a single `COLUMNS_STATE_CHANGED`. The batch counterpart * to {@link setColumnWidth}, used by Auto Size All / Fit to Grid so N columns * cost one store update and one render instead of N. * * @param entries - `[colId, width]` pairs to apply. */ setColumnWidths(entries: ReadonlyArray): void; /** * Restores a single column's width to the value captured at the last * {@link initColumns} call (the "Reset Width" action). For a column defined * with `flex`, this seed is overridden by flex re-resolution on the next * render — the caller should also clear any user-fixed width so flex resumes. * * @param colId - Column whose width should be reset. */ resetColumnWidth(colId: string): void; setColumnVisible(colId: string, visible: boolean): void; /** * Pins a column to a panel, or unpins it. * * Pinning is a **move**, not just a flag: the column leaves the block it sat * in and joins the end of the target panel's block. `columns` is reordered to * match, because definition order is what every order-sensitive consumer * walks — `getVisibleColumns()` feeds the header's roving keyboard focus, * range selection, and export column order, none of which read the rendered * panels. Leaving the order alone made those disagree with what the user can * see: after pinning a middle column left from the column menu, Arrow keys in * the header jumped to whatever still sat beside it in the *old* order. * * ### Unpinning puts it back * Because pinning moves the column, its old position has to be remembered or * it is gone: unpinning used to drop the column at the end of the unpinned * block, so pinning the third of twenty columns to glance at it and unpinning * again returned it as the twentieth. The slot it came from is recorded on the * way in (see {@link Column.unpinAnchorColId}) and restored on the way out. * * Drag-to-pin has always reordered (see {@link moveAndPin}); this is the same * operation with the insertion point left implicit. */ setColumnPin(colId: string, pinned: ColumnPinPosition): void; /** * The colId of the visible column immediately *before* `colId`, or `null` when * it is the first one. * * A neighbour rather than an index, because indices go stale the moment any * other column is moved, hidden or pinned — and a column can sit pinned for * the whole time the user spends rearranging the rest of the grid. * * The column *before* rather than after, because it degrades better. When the * remembered neighbour has itself been pinned away in the meantime, "just * after A" still puts the column back on A's side of the grid; "just before C" * collapses to the front of the block and silently swaps the column past * everything that used to precede it. */ private columnBefore; /** * Puts a just-unpinned column back where it was, or as close as the layout * still allows. * * The remembered neighbour may since have been hidden, removed, or pinned * itself, and the result must stay inside the unpinned block either way — * definition order has to keep matching panel order, or the consumers listed * on {@link setColumnPin} start disagreeing with the screen. So the target is * clamped to the block's bounds: a stale anchor degrades to the end of the * unpinned block, which is exactly the old behaviour, rather than to a * corrupt order. * * @returns The from/to indices within the visible-column order, or `null` when * the column is hidden and has no position to move — the same * contract as {@link reorderIntoPanel}, so `moveAndPin` can use * either interchangeably. */ private restoreUnpinned; moveColumn(fromIndex: number, toIndex: number): void; /** * Splices `col` into the block of visible columns that belongs to `newPin`, * rewriting `this.columns` so definition order matches the rendered panel * order. Shared by {@link setColumnPin} and {@link moveAndPin} so the two * entry points into pinning can never drift apart. * * `col.pinned` must already be set to `newPin` — the target block is found by * scanning for the column's new panel siblings. * * @param col - The column to reposition. * @param newPin - Panel it now belongs to. * @param insertBeforeColId - Drop target, or `null` to append to the panel's * end (what a menu "Pin left" means). * @returns The from/to indices within the visible-column order, or `null` * when the column is hidden and therefore has no position to move. */ private reorderIntoPanel; /** Move a column to a different panel (changing its pinned state) and insert it at a specific position. */ moveAndPin(colId: string, newPin: ColumnPinPosition, insertBeforeColId: string | null): void; /** * Sets (or clears) the aggregation function for a column — the function used * to summarize the column's values on group rows when row grouping is active. * Aggregation itself only applies to `number`/`currency` columns (see * `AggregationEngine`); this setter does not enforce that, leaving the menu to * decide where it is offered. * * @param colId - Target column. * @param aggFunc - Aggregation function, or `null` to clear it. */ setColumnAggFunc(colId: string, aggFunc: AggFunc | null): void; /** * Renames a column (its header text). Used by the column menu's "Rename". * * @param colId - Target column. * @param header - New header text; ignored when empty. */ setColumnHeader(colId: string, header: string): void; /** * Inserts a copy of a column immediately after it. The duplicate shares the * source `field` (so it shows the same data) but gets a fresh, unique `colId`. * Used by the column menu's "Duplicate". * * @param colId - Column to duplicate. * @returns The new column's `colId`, or `null` if the source was not found. */ duplicateColumn(colId: string): string | null; /** * Toggles "Freeze Position" — whether the column can be dragged/reordered. * Frozen columns have `draggable === false`. Used by "Freeze Position". * * @param colId - Target column. */ toggleColumnFrozen(colId: string): void; /** * Toggles "Lock Column" — whether the column's cells can be edited. Locked * columns are never editable regardless of {@link ColumnDef.editable}. * * @param colId - Target column. */ toggleColumnLocked(colId: string): void; /** * Restores a single column to the definition captured at {@link initColumns} * (header, width, pin, visibility, sort, flags, aggFunc, …) and moves it back * to its original position. The single-column counterpart to * {@link resetColumnState}. Callers should also clear any user-fixed width in * the style manager so a `flex` column resumes flexing. * * @param colId - Column to reset. */ resetColumn(colId: string): void; setColumnSort(colId: string, order: 'asc' | 'desc' | null): void; /** Clears the sort indicator from every column (the header-arrow counterpart to `SortEngine.clearSort`). */ clearAllSort(): void; autoSizeColumn(colId: string, containerEl: HTMLElement): void; /** * Reorders a block of columns so they sit consecutively starting at * `toIndex` within the visible-column order, preserving their relative order. * Hidden columns keep their positions. The batch equivalent of * {@link moveColumn} (which moves a single column by index). * * @param colIds - Ids of the columns to move, in the order they should end up. * @param toIndex - Target insertion index in the remaining visible columns. */ moveColumns(colIds: string[], toIndex: number): void; /** * Distributes `availableWidth` proportionally across all visible columns so * they exactly fill the given width, clamping each to its `minWidth`/`maxWidth`. * Any rounding remainder is absorbed by the last column (also clamped). * * @param availableWidth - Target total width, in pixels (typically the grid * viewport width). No-op when non-positive. */ sizeColumnsToFit(availableWidth: number): void; /** * Restores every column's width, visibility, pin position, sort, and order to * the snapshot captured at the last {@link initColumns} call — the counterpart * to a user having resized/hidden/reordered columns. */ resetColumnState(): void; applyColumnStates(states: ColumnState[]): void; getColumnStates(): ColumnState[]; private rebuildPinnedSections; private syncColumnOrder; private normalizeColumn; private emitStatesChanged; } //# sourceMappingURL=column-model.d.ts.map