import { ID } from "../../types/index.mjs"; import { MaybeRefOrGetter, ShallowReactive, ShallowRef } from "vue"; //#region src/composables/createDataGrid/editing.d.ts interface EditableColumn { readonly id: string; readonly editable?: boolean | ((item: T) => boolean); readonly validate?: (value: unknown, item?: T) => string | true; } /** * Minimal structural type of the row registry surface that * `createCellEditing` subscribes to for pruning stale state. * * Compatible with the registry returned by `createDataTable` / spread onto * `createDataGrid`. The `on` / `off` channel is needed — handlers subscribe at * setup and unsubscribe on scope dispose, so a registry that outlives the * editing instance does not accumulate listeners. The payload arrives as * `unknown` and is narrowed inside the handler. */ interface CellEditingRegistry { on: (event: string, listener: (data: unknown) => void) => void; off: (event: string, listener: (data: unknown) => void) => void; } interface CellEditingOptions { /** * Editable columns, read reactively. Accepts a ref or getter so the column * set can change after construction — e.g. a grid that derives editables * from a live column registry. Resolved via `toValue` on every `edit` / * `commit`, so newly-onboarded editable columns are picked up without * re-creating the editing instance. */ columns: MaybeRefOrGetter[]>; onEdit?: (row: ID, column: string, value: unknown) => void; lookup?: (row: ID) => T | undefined; registry?: CellEditingRegistry; } interface ActiveCell { row: ID; column: string; } /** * Cell editing state and controls returned by {@link createCellEditing}. * * @example * ```ts * grid.editing.edit(1, 'email') * grid.editing.commit('x@y.z') * * grid.editing.active.value // { row: 1, column: 'email' } | null * grid.editing.error.value // 'Invalid email' | null * grid.editing.dirty // Map> (ShallowReactive) * ``` */ interface CellEditing { active: Readonly>; edit: (row: ID, column: string) => void; commit: (value: unknown) => void; cancel: () => void; error: Readonly>; /** * Map of rows that have staged (uncommitted) cell values. The outer key * is the row id; the inner Map is column id → staged value. Empty * entries are not pre-created — consumers that want to stage a value * insert their own per-row Map (or use the dirty Map's `set`). * * `dirty` is a consumer-managed staging area for uncommitted values; * `commit(value)` commits its explicit `value` argument and merely deletes * the matching staged entry — it does not read or auto-flush staged values. */ dirty: Readonly>>>; } //#endregion export { ActiveCell, CellEditing, CellEditingOptions, CellEditingRegistry, EditableColumn };