import { ID } from "../../types/index.mjs"; import { ContextTrinity } from "../createTrinity/index.mjs"; import { RegistryContext } from "../createRegistry/index.mjs"; import { ServerDataTableAdapter, ServerDataTableAdapterOptions } from "../createDataTable/adapters/server.mjs"; import { DataTableColumnTicket, DataTableColumnTicketInput, DataTableContext, DataTableOptions } from "../createDataTable/index.mjs"; import { ActiveCell, CellEditing, CellEditingOptions, CellEditingRegistry, EditableColumn } from "./editing.mjs"; import { ColumnLayout, GridColumnDef, PinPosition, PinnedRegion, ResolvedColumn } from "./layout.mjs"; import { RowSpanningOptions, SpanEntry } from "./spanning.mjs"; import "./adapters/index.mjs"; import { ComputedRef, MaybeRefOrGetter, Ref } from "vue"; //#region src/composables/createDataGrid/index.d.ts /** * Column registration shape for `createDataGrid`. Extends the data-table * column ticket input with grid-specific layout, editing, and spanning config. * * The extra fields ride on the column ticket — `createRegistry` preserves them * via `{ ...registration }` — so layout/editing/spanning read config straight * off the registered ticket. Nested `children` config rides inline on the * parent ticket, mirroring `DataTableColumnTicketInput`. * * @template T Row value type. * * @example * ```ts * const grid = createDataGrid() * * grid.columns.onboard([ * { id: 'name', sortable: true, size: 40, pinned: 'left' }, * { id: 'price', editable: true, validate: v => Number(v) >= 0 || 'must be positive' }, * ]) * ``` */ interface DataGridColumnTicketInput extends DataTableColumnTicketInput { /** Width as a percentage (0–100). Unset columns share remaining space equally. */ size?: number; /** Minimum width as a percentage. @default 2 */ minSize?: number; /** Maximum width as a percentage. @default 100 */ maxSize?: number; /** Pin position. @default false */ pinned?: PinPosition; /** Allow resizing. @default true */ resizable?: boolean; /** Allow reordering. @default true */ reorderable?: boolean; /** Whether cells in this column can be edited. A function gates per-row. */ editable?: boolean | ((item: T) => boolean); /** Validate an edited value; return `true` to accept or a string error to reject. */ validate?: (value: unknown, item?: T) => string | true; /** Row span for a cell in this column. */ span?: (item: T) => number; /** Header-group children (recursive). Children are NOT separately registered. */ children?: readonly DataGridColumnTicketInput[]; } /** * Output ticket returned by `grid.columns.register` / `grid.columns.onboard`. * * Combines the standard registry ticket fields (`index`, `valueIsIndex`, * `unregister`) with the column-shape fields from {@link DataGridColumnTicketInput}. * * @template T Row value type. */ type DataGridColumnTicket = DataTableColumnTicket & DataGridColumnTicketInput; /** * Factory options for {@link createDataGrid}. Extends {@link DataTableOptions} * with cell-editing, row-spanning, and row-order-preservation config. * * @template T Row value type. * * @example * ```ts * const grid = createDataGrid({ * editing: { onEdit (row, column, value, item) { persist(item.id, column, value) } }, * rowSpanning: (item, column) => column === 'group' ? 3 : 1, * preserveRowOrder: true, * }) * ``` */ interface DataGridOptions extends DataTableOptions { editing?: { onEdit?: (row: ID, column: string, value: unknown, item: T) => void; }; preserveRowOrder?: MaybeRefOrGetter; rowSpanning?: (item: T, column: string) => number; } /** * The reactive grid instance returned by {@link createDataGrid}. Spreads the * inherited {@link DataTableContext} surface and adds `layout`, `rows`, * `editing`, `spans`, `orderedItems`, and `rank`. Does not override parent * `sortedItems` (PHILOSOPHY §2.6). * * @template T Row value type. * * @example * ```ts * const grid = createDataGrid() * * grid.layout.pin('name', 'left') * grid.rows.move(id, 0) * grid.editing.edit(1, 'email') * grid.spans.value.get(id)?.get('group') * grid.orderedItems.value * grid.rank(source) * ``` */ interface DataGridContext extends DataTableContext { /** * Column registry, widened to the grid column ticket shape. Covariant * override of the inherited {@link DataTableContext.columns} (PHILOSOPHY * §2.6): every grid-added column field (`size`, `pinned`, `editable`, * `validate`, `span`, `minSize`, `maxSize`, `resizable`, `reorderable`) is * optional, so the widened input still satisfies the base `register` / * `onboard` signatures and runtime behavior is unchanged. */ columns: RegistryContext, DataGridColumnTicket>; /** * Full filter+sort+row-order list before pagination. When row order is * not dirty this is `sortedItems`. Rank a source array with `rank()` * so `rows.move()` reorders the DOM. * * @example * ```ts * grid.rows.move(id, 0) * grid.orderedItems.value[0] * ``` */ orderedItems: Readonly>; /** * Rank a source array by `orderedItems`. v-for this so rows register; * missing ranks stay in source order. Ranks by `orderedItems` (not * `sortedItems`) so `rows.move()` is visible. * * @example * ```ts * grid.rows.move(id, 0) * grid.rank(source)[0] * ``` */ rank: (source: readonly U[]) => U[]; layout: ColumnLayout; rows: { order: Readonly>; move: (id: ID, toIndex: number) => void; reset: () => void; }; editing: CellEditing; spans: ComputedRef>>; } interface DataGridContextOptions extends DataGridOptions { namespace?: string; } /** * Creates a data grid instance with layout, editing, row ordering, and spanning * layered on top of the createDataTable pipeline. * * Rows live on the inherited registry surface — register them with * `grid.onboard(rows.map(value => ({ id: value.id, value })))` or * `grid.register({ id, value })`. * * @param options Data grid options * @returns Data grid context * * @example * ```ts * const grid = createDataGrid({ pagination: { page: 1 } }) * * grid.columns.onboard([ * { id: 'name', sortable: true }, * { id: 'progress', editable: true, validate: v => Number(v) >= 0 || 'must be positive' }, * ]) * * grid.onboard(rows.map(value => ({ id: value.id, value }))) * grid.layout.pin('name', 'left') * grid.rows.move(rowId, 0) * grid.editing.edit(row.id, 'progress') * ``` */ declare function createDataGrid(_options?: DataGridOptions): DataGridContext; /** * Creates a data grid context with dependency injection support. * * @param options Data grid context options including namespace * @returns A trinity tuple: [useDataGridContext, provideDataGridContext, defaultContext] * * @example * ```ts * const [useDataGrid, provideDataGrid, grid] = createDataGridContext({ * namespace: 'v0:projects', * }) * * grid.columns.onboard(columns) * grid.onboard(rows.map(value => ({ id: value.id, value }))) * provideDataGrid() * const ctx = useDataGrid() * ``` */ declare function createDataGridContext(_options?: DataGridContextOptions): ContextTrinity>; /** * Returns the current data grid context from dependency injection. * * @param namespace The namespace for the data grid context. @default 'v0:data-grid' * @returns The current data grid context * * @example * ```ts * const grid = useDataGrid() * * grid.layout.pin('id', 'left') * grid.rows.reset() * ``` */ declare function useDataGrid(namespace?: string): DataGridContext; //#endregion export { type ActiveCell, type CellEditing, type CellEditingOptions, type CellEditingRegistry, type ColumnLayout, DataGridColumnTicket, DataGridColumnTicketInput, DataGridContext, DataGridContextOptions, DataGridOptions, type EditableColumn, type GridColumnDef, type PinPosition, type PinnedRegion, type ResolvedColumn, type RowSpanningOptions, ServerDataTableAdapter as ServerGridAdapter, type ServerDataTableAdapterOptions as ServerGridAdapterOptions, type SpanEntry, createDataGrid, createDataGridContext, useDataGrid };