import type { ReactiveControllerHost, TemplateResult } from 'lit'; import type ApexGridCell from '../components/cell.js'; import type { ApexGrid } from '../components/grid.js'; import type ApexGridHeader from '../components/header.js'; import type ApexGridRow from '../components/row.js'; import type { SortComparer } from '../operations/sort/types.js'; export type NavigationState = 'previous' | 'current'; export type GridHost = ReactiveControllerHost & ApexGrid; /** * Helper type for resolving keys of type T. */ export type Keys = keyof T; /** * Helper type for resolving types of type T. */ export type BasePropertyType = Keys> = T[K]; /** * Helper type for resolving types of type T. */ export type PropertyType = Keys> = K extends Keys ? BasePropertyType : never; /** * The data type — or, for the declarative built-ins (`'select'`, `'rating'`, * `'date'`, `'image'`), the presentation type — for the current column. * * @remarks * - `'string'` / `'number'` are the primitive data types. They drive the * default filter operands, the default editor, and the default sort * comparison. * - `'boolean'` stores `true` / `false`. In display mode the grid renders * a check-mark icon for `true` and a dimmed mark for `false`. In edit * mode the default editor is a native checkbox. * - `'select'` is a presentation type for columns that store one of a fixed * set of values. Supply the available options via * {@link BaseColumnConfiguration.options}. The cell renders the matching * option's label in display mode and a native `` in edit mode. Accepts `Date` * instances, ISO strings, or millisecond timestamps as input and commits * back in the same shape. Configure the display format via * {@link BaseColumnConfiguration.format} (`'short' | 'medium' | 'long' | * 'full'`, default `'medium'`). * - `'image'` renders the value as an `` source. Use * {@link BaseColumnConfiguration.shape} to pick between `'square'` * (default) and `'circle'`. The cell's default text editor is used for * editing the URL string when `editable: true` is set. * * The remaining types are premium presentation renderers over primitive * values; for sorting / filtering they behave as their underlying value type: * - `'currency'` formats a number via `Intl.NumberFormat` (tabular, right * aligned). Configure with {@link BaseColumnConfiguration.currency} / * {@link BaseColumnConfiguration.locale}. Editable via a number input. * - `'avatar'` renders the value's first letter in a tinted circle (hue is * derived from the value, stable per row). * - `'badge'` renders the value as a colored pill. Pick the look with * {@link BaseColumnConfiguration.badgeVariant}. * - `'progress'` renders a number (0..`max`, default `max` 100) as a health * bar; the fill color tiers at ≥80 / ≥65 / below. * - `'sparkline'` renders a `number[]` as an inline trend chart with an * optional delta label ({@link BaseColumnConfiguration.showDelta}). * - `'status'` renders a pill with a leading dot. The state is taken from * {@link BaseColumnConfiguration.statusVariant} or inferred from the value. */ export type DataType = 'number' | 'string' | 'boolean' | 'select' | 'rating' | 'date' | 'image' | 'currency' | 'avatar' | 'badge' | 'progress' | 'sparkline' | 'status'; /** Visual variant for a `type: 'badge'` pill. */ export type BadgeVariant = 'gold' | 'brand' | 'neutral' | 'muted'; /** State for a `type: 'status'` badge. */ export type StatusVariant = 'active' | 'trial' | 'churn'; /** * Display format presets for `'date'` columns. Map to * `Intl.DateTimeFormatOptions.dateStyle`. */ export type ColumnDateFormat = 'short' | 'medium' | 'long' | 'full'; /** * An entry in a `'select'` column's `options` list. Bare values use * `String(value)` as their display label; the explicit form lets you give * a value a separate display label. */ export type ColumnSelectOption = V | { value: V; label?: string; }; /** * Configures the sort behavior for the grid. */ export interface GridSortConfiguration { /** * Whether multiple sorting is enabled. */ multiple: boolean; /** * Whether tri-state sorting is enabled. */ triState: boolean; } /** * Extended sort configuration for a column. */ export interface BaseColumnSortConfiguration = Keys> { /** * Whether the sort operations will be case sensitive. */ caseSensitive?: boolean; /** * Custom comparer function for sort operations for this column. */ comparer?: SortComparer; } /** * See {@link BaseColumnSortConfiguration} for the full documentation. */ export type ColumnSortConfiguration = Keys> = K extends Keys ? BaseColumnSortConfiguration : never; /** * Extended filter configuration for a column. */ export interface ColumnFilterConfiguration { /** * Whether the filter operations will be case sensitive. */ caseSensitive?: boolean; } /** * Pin position for a column. * * @remarks * `'start'` pins the column to the leading edge of the grid (inline-start); * `'end'` pins it to the trailing edge. `null` or `undefined` means the column * is part of the scrollable region. */ export type PinPosition = 'start' | 'end' | null; /** Configuration object for grid columns. */ export interface BaseColumnConfiguration = Keys> { /** * The field for from the data the this column will reference. */ key: K; /** * The type of data this column will reference. * * Affects the default filter operands if the column is with filtering enabled. * * @remarks * If not passed, `string` is assumed to be the default type. * */ type?: DataType; /** * Optional text to display in the column header. By default, the column key is used * to render the header text. */ headerText?: string; /** * Width for the current column. * * Accepts most CSS units for controlling width. * * @remarks * If not passed, the column will try to size itself based on the number of other * columns and the total width of the grid. * */ width?: string; /** * Whether the column is hidden or not. */ hidden?: boolean; /** * Whether this column is included when exporting via * {@link ApexGrid.exportToCSV} (or the enterprise grid's XLSX export). * * @remarks * Defaults to `true`. Set to `false` to omit a column from generated files * (useful for action columns, derived UI, or sensitive fields). The * grid-rendered selection checkbox column is never exported regardless of * this flag. */ exportable?: boolean; /** * Pin the column to a side of the grid. * * @remarks * Pinned columns stay fixed during horizontal scroll. Use `'start'` (left in LTR, * right in RTL) for the leading edge or `'end'` for the trailing edge. The grid * renders columns in the order: `'start'`-pinned, unpinned, `'end'`-pinned, while * preserving the original array order inside each group. The `columns` array * itself is not mutated. */ pinned?: PinPosition; /** * Whether this column can be reordered via drag-and-drop or the * {@link ApexGrid.moveColumn} API. * * @remarks * Has no effect unless the grid's `columnReordering` flag is `true`. When * unset, columns inherit the grid-wide flag. Reordering is constrained to the * column's own pinning group — start-pinned columns can only swap with other * start-pinned columns, and likewise for end-pinned and unpinned. */ reorderable?: boolean; /** * Whether the the column can be resized or not. */ resizable?: boolean; /** * Whether the column can be sorted or not. */ sort?: ColumnSortConfiguration | boolean; /** * Whether filter operation can be applied on the column or not. */ filter?: ColumnFilterConfiguration | boolean; /** * Header template callback. */ headerTemplate?: (params: ApexHeaderContext) => TemplateResult | unknown; /** * Cell template callback. */ cellTemplate?: (params: ApexCellContext) => TemplateResult | unknown; /** * Whether values in this column can be edited inline. * * @remarks * Has no effect unless the grid's `editing.enabled` is `true`. The default * editor is chosen from the column's `type` (`'string'` → text input, * `'number'` → number input, `'boolean'` → checkbox). Supply * {@link BaseColumnConfiguration.editorTemplate} for full control. */ editable?: boolean; /** * Custom editor template invoked while this column's cell is in edit mode. * * @remarks * The callback receives an {@link ApexEditorContext} that includes the cell * value plus `commit` / `cancel` helpers. Returning a focusable element is * recommended so keyboard handoff works. */ editorTemplate?: (params: ApexEditorContext) => TemplateResult | unknown; /** * Option list for columns with `type: 'select'`. * * @remarks * Each entry is either a bare value or an explicit `{ value, label }` pair. * The cell renders the matching option's `label` in display mode and a * native `