# Core API signatures

API catalog generated from the exported TypeScript GridEngine type. Use the package guide for behavior/examples and match the selected documentation version to your installed packages. Coordinates are zero-based visible indices unless a contract states otherwise.

[Package guide](../packages/core/README.md) · [Version policy](versions.md)

## Data and lifecycle

### subscribe

```ts
subscribe: (subscriber: { readonly onEvent?: (event: GridEvent) => void; readonly onInvalidate?: (change: GridInvalidation) => void; }) => () => void
```

Register independent event/invalidation observers. Returns an unsubscribe function; callbacks observe committed state and cannot perform nested mutations. Registration requires a live engine.

### takeObserverErrors

```ts
takeObserverErrors: () => unknown[]
```

Drain the bounded observer error queue without changing data or history. Observer failures do not roll back committed commands.

### captureRowIdentity

```ts
captureRowIdentity: () => readonly RowId[]
```

Capture source row IDs before an external structural change. This explicit operation scans every source row; call refreshData with the captured IDs afterward.

### resetData

```ts
resetData: () => DataResetResult
```

Adopt the current row count as a new flat-data epoch without scanning IDs or creating a row map. Clear selection/cut, all undo/redo, row sizes/visibility/locks/merges/outlines and runtime formats. Preserve column schema/geometry/locks, table lock and application permissions. Reject local projections/tree/grouping or invalid dimensions before discarding state. Host owns source query/revision changes and must settle editing, bulk work and uncertain writes first.

### refreshRows

```ts
refreshRows: (startRow: number, endRow: number) => RowRefreshResult
```

Available in 0.4.0: refresh an inclusive source-row window without scanning other source IDs or clearing all history. Requires unchanged count, a flat default-height view and no row metadata/format history. Validate window IDs first; discard entire undo/redo batches whose in-window IDs changed, clear intersecting non-single-cell selections and stale active identity, cancel cut, then emit data:rows with the drop/selection result. Matching IDs retain normal value-conflict preflight. Host must report every changed/evicted window and keep query/revision/schema stable; this is not a query/total reset or remote loader.

### refreshData

```ts
refreshData: (previousRowIds?: readonly RowId[] | "values") => void
```

Reconcile external source changes and clear history/pending cut. Values mode requires unchanged IDs/order/count; an ID snapshot enables remapping; without IDs row-dependent metadata is dropped.

### sourceRowCount

```ts
sourceRowCount: number
```

Number of source rows, before local filtering or collapsed groups. This differs from the visible rowCount.

### getRowId

```ts
getRowId: (row: number) => RowId
```

Resolve a visible row to its stable source ID. Invalid row indices are rejected by the source/mapping contract.

### columns

```ts
columns: readonly Readonly<{ permissions?: CellPermissionPolicy; defaultValue?: unknown; key: string; title: string; editable?: boolean; parse?: (text: string) => unknown; validate?: (value: unknown) => string | undefined; invalidInput?: "reject" | "allow"; }>[]
```

Frozen snapshots of the current column definitions in current display order. Application callbacks remain trusted code.

### rowCount

```ts
rowCount: number
```

Visible row count after local view and collapsed-group projection; use sourceRowCount for the unprojected count.

### getValue

```ts
getValue: (row: number, key: string) => unknown
```

Read a raw value using a visible row and column key. No parsing/formatting occurs; missing or unloaded values may be undefined according to the source contract.

### editCell

```ts
editCell: (row: number, col: number, text: string) => void
```

Editor-style text command: resolve visible coordinates, require editable/writable, parse and validate before committing. Supports setValue or atomic setValues.

### updateCells

```ts
updateCells: (updates: readonly CellUpdate[]) => void
```

Typed-value updates: resolve visible rows, validate and require writable, without editor parsing or editable checks. Duplicate cells use the last value. Multi-cell changes require atomic setValues.

### updateCellsAsync

```ts
updateCellsAsync: (updates: readonly CellUpdate[], options: GridBulkOptions) => Promise<void>
```

Cooperative typed batch preparation with host scheduling, cancellation and optional external revision guard. One final synchronous atomic write; other engine mutations are blocked while pending.

### replaceText

```ts
replaceText: (search: string, replacement: string, options?: { readonly scope?: "view" | "selection"; readonly caseSensitive?: boolean; }) => Readonly<{ changedCells: number; matches: number; }>
```

Available in 0.2.0: bounded literal replacement of string values in the view or selection. Requires editable/writable and validation; one atomic undo command. It is not a regular-expression API.

### destroy

```ts
destroy: () => void
```

Idempotently release engine-owned observers, history and selection. The host still owns source destruction/transport. Data/layout commands and clipboard operations reject after destruction; undo/redo return false. Do not use retained read getters as a live engine after disposal.

## Selection and clipboard

### getSelection

```ts
getSelection: () => CellSelection | null
```

Current visible active cell, or null. It is not a source-coordinate address; use getRowSourceIndex when needed.

### getSelectionRange

```ts
getSelectionRange: () => SelectionRange | null
```

Current active visible range, or null. Other retained selection ranges are available through getSelectionRanges.

### getSelectionRanges

```ts
getSelectionRanges: () => SelectionRange[]
```

Visible selection ranges including retained ranges. Projection can split source ranges into multiple visible fragments; serialization has explicit fragment limits.

### select

```ts
select: (row: number, col: number, extend?: boolean) => boolean
```

Select a visible cell, or extend from the anchor when extend is true. Selectable policy can veto; returns whether selection changed.

### selectRange

```ts
selectRange: (range: SelectionRange, mode?: "replace" | "add" | "extend") => boolean
```

Select an inclusive visible rectangle with replace/add/extend semantics. Validate bounds, policies and projected fragmentation before changing selection.

### clearSelection

```ts
clearSelection: () => void
```

Clear active/retained selection and anchor, with selection invalidation/events when changed. Does not change values or create a value-history command.

### cutSelectionBlocks

```ts
cutSelectionBlocks: () => string
```

Stage a same-engine cut and return structured clipboard text. Data is not deleted until a successful matching paste commit.

### cancelCut

```ts
cancelCut: () => void
```

Cancel the staged cut without modifying data. It is harmless when no cut exists, including after disposal. Host clipboard ownership remains separate.

### pasteCutSelectionBlocks

```ts
pasteCutSelectionBlocks: (text: string) => void
```

Move a matching staged cut to the selected destination after complete validation/permissions/conflict preflight. A failed operation preserves source values.

### copySelectionBlocks

```ts
copySelectionBlocks: () => string
```

Return versioned structured clipboard text including supported formatting through copy permissions. Values use string clipboard encoding; fragment/cell/text limits apply.

### pasteSelectionBlocks

```ts
pasteSelectionBlocks: (text: string, options?: PasteOptions) => void
```

Decode structured clipboard text and atomically preflight values/formats. PasteOptions supports all/values/formats, transpose and skipEmpty; format-only bypasses parsers/value writes and checks format permission. Clipboard strings never execute callbacks.

### copySelection

```ts
copySelection: () => string
```

Return packed TSV through copy permissions. Core does not access the operating-system clipboard; cell/fragment/text limits apply.

### paste

```ts
paste: (text: string, options?: PasteOptions) => void
```

Parse TSV/editor text and atomically preflight destinations, parsing, permissions and validation. PasteOptions supports all/values/formats, transpose and skipEmpty; TSV carries no formats. Empty means an empty clipboard string, not whitespace.

### pasteAsync

```ts
pasteAsync: (text: string, bulk: GridBulkOptions, options?: PasteOptions) => Promise<void>
```

Cooperative TSV parsing/preflight with the same paste options, limits and permissions. One atomic commit/history entry. Structured clipboard operations remain synchronous.

## History

### undo

```ts
undo: () => boolean
```

Replay the most recent command under current identity/value/permission checks. Return false when no command exists; conflicts can reject without changing history/data.

### redo

```ts
redo: () => boolean
```

Replay a previously undone command under current identity/value/permission checks. A new committed command clears redo; refresh clears both stacks.

### undoAsync

```ts
undoAsync: (options: GridBulkOptions) => Promise<boolean>
```

Cooperatively preflight value history, then replay atomically. Other history kinds and final commit remain synchronous; cancellation retains the entry.

### redoAsync

```ts
redoAsync: (options: GridBulkOptions) => Promise<boolean>
```

Cooperatively preflight value redo, then replay atomically. Current identity, values and authority are rechecked before commit.

### canUndo

```ts
canUndo: () => boolean
```

Whether a live engine has an undo entry. This is not a guarantee that current policies/identities/values will permit replay.

### canRedo

```ts
canRedo: () => boolean
```

Whether a live engine has a redo entry. Replay still checks current policies and conflicts.

## Views and persistence

### setTree

```ts
setTree: (next: LocalTreeOptions | null) => void
```

Available in 0.4.0: validate a complete local parent-ID forest, retain filter matches and ancestors, and sort siblings. Reject invalid IDs, parents, cycles, depth above 4096 and incompatible grouping/row layout/history before installing. Null clears tree; no source writes.

### tree

```ts
tree: Readonly<LocalTreeOptions> | null
```

Frozen current parent-column criteria, or null. Tree projection is separate from LocalViewOptions and remote queries.

### getTreeRowMetadata

```ts
getTreeRowMetadata: (row: number) => LocalTreeRow | null
```

Frozen metadata for a visible real tree record: sourceIndex, rowId, parentId, 1-based level, retained hasChildren and expanded. Null outside tree mode. No synthetic row ID.

### setTreeExpanded

```ts
setTreeExpanded: (rowId: RowId, expanded: boolean) => void
```

Expand/collapse a visible branch by its real typed row ID, outside data undo. Reduce selection to its active visible cell or affected parent if hidden; discard hidden ranges. Unknown branches reject; unchanged expansion is a no-op.

### exportTreeState

```ts
exportTreeState: () => TreeState
```

Frozen version-1 parent-column criteria and typed collapsed IDs. Contains no dataset provenance, records, permissions or history; the host selects the matching complete dataset.

### restoreTreeState

```ts
restoreTreeState: (state: unknown) => void
```

Validate unknown version-1 state, schema, layout and collapsed IDs against the current forest before replacing tree projection atomically. Clears selection; does not restore source data or authority.

### setGrouping

```ts
setGrouping: (next: LocalGroupingOptions | null) => void
```

Available in 0.4.0: filter complete local records, group by one scalar key and optionally sum finite numeric values; sort leaves within each group. Reject incompatible row layout/history before installing. Null clears grouping. No source writes.

### exportGroupingState

```ts
exportGroupingState: () => GroupingState
```

Frozen version-1 criteria/collapsed-key view snapshot, separate from legacy GridState/GridConfiguration. Contains no data, authorization or history; apply only to a matching host-owned dataset.

### restoreGroupingState

```ts
restoreGroupingState: (state: unknown) => void
```

Validate unknown version-1 grouping state and schema/layout before installing atomically. Typed collapsed keys survive local filters. Does not restore source data or permissions.

### grouping

```ts
grouping: Readonly<LocalGroupingOptions> | null
```

Frozen current local grouping criteria, or null. Grouping is separate from LocalViewOptions and server queries.

### getRowMetadata

```ts
getRowMetadata: (row: number) => GridRowMetadata
```

Discriminated group/leaf metadata for a visible row. Only leaves have real sourceIndex and rowId; group metadata contains key, count, sums, retained source indices and expanded state. Legacy getRowId/getRowSourceIndex reject group rows.

### focusGroup

```ts
focusGroup: (row: number) => boolean
```

Focus a group header and clear all data selection/cut targets. Returns false for a leaf. Group focus is separate from CellSelection.

### getFocusedGroup

```ts
getFocusedGroup: () => number
```

Visible index of the focused group header, or -1. No synthetic CellSelection or RowId is created.

### setDataGroupExpanded

```ts
setDataGroupExpanded: (key: GroupKey, expanded: boolean) => void
```

Expand/collapse a typed visible group key without changing source values, aggregates or data history. Clears leaf selection and focuses the header.

### exportState

```ts
exportState: () => GridState
```

Export versioned domain UI state and selection/metadata. Excludes source data, callback policies, transport and history; identity capture can scan source rows.

### restoreState

```ts
restoreState: (state: unknown) => void
```

Stage and validate unknown saved state, including current layout/structure/lock/format policies, before committing. Application callbacks/policies are never supplied by saved state.

### setView

```ts
setView: (next: LocalViewOptions) => void
```

Set a core-owned local sort/filter view; this scans local source data and is not a server query. Preserve stable source identities; clear projected views before structural commands.

### setViewAsync

```ts
setViewAsync: (next: LocalViewOptions, options: GridBulkOptions) => Promise<void>
```

Cooperative local filtering and stable merge sort with the same ordering as setView. Installs the completed projection once; server queries belong to the data source.

### view

```ts
view: Readonly<LocalViewOptions>
```

Current immutable local sort/filter criteria. This does not represent a remote query or an arbitrary host projection.

### exportConfiguration

```ts
exportConfiguration: () => GridConfiguration
```

Export JSON-safe column order/widths, frozen counts and local view. Excludes data, callbacks, selection and undo history.

## Structure and groups

### getMergedCells

```ts
getMergedCells: () => readonly Readonly<{ startRow: number; endRow: number; startColumn: number; endColumn: number; }>[]
```

Return merge spans in source row coordinates. Use getMerge for a visible-cell lookup; merged metadata is separate from cell values.

### getMerge

```ts
getMerge: (row: number, col: number) => Readonly<{ startRow: number; endRow: number; startColumn: number; endColumn: number; }> | null
```

Find the merge containing a visible cell and return its visible bounds, or null. Source metadata uses getMergedCells.

### canMerge

```ts
canMerge: (range: SelectionRange) => boolean
```

Preflight an inclusive visible merge range against bounds, existing merges, projected view, feature flags and layout policies. No mutation occurs.

### mergeCells

```ts
mergeCells: (range: SelectionRange) => void
```

Create a permitted rectangular merge without combining or deleting raw values. Validate before changing metadata; participates in layout history.

### unmergeCells

```ts
unmergeCells: (range: SelectionRange) => void
```

Remove merges intersecting the requested visible range, subject to current layout policy. Underlying values are retained.

### getRowGroups

```ts
getRowGroups: () => readonly Readonly<{ id: string; startRow: number; endRow: number; collapsed: boolean; }>[]
```

Return nested manual row-group metadata in source coordinates. These are not computed group-by aggregations.

### groupRows

```ts
groupRows: (start: number, end: number) => string
```

Create a manual source-row group from inclusive source indices, subject to grouping/layout rules. Projected views must be cleared for this structural layout operation.

### ungroupRows

```ts
ungroupRows: (id: string) => void
```

Remove a manual group by ID under layout policy. This does not delete source rows.

### setGroupCollapsed

```ts
setGroupCollapsed: (id: string, collapsed: boolean) => void
```

Collapse/expand a manual group by ID, changing visible projection while preserving source rows. Current layout policy applies.

### insertColumns

```ts
insertColumns: (index: number, added: readonly Column[]) => void
```

Insert definitions before a current column index under structural policy; keys must be unique and the source must support initializing added fields.

### deleteColumns

```ts
deleteColumns: (indices: readonly number[]) => void
```

Remove specified current column indices under structural policy and remap related metadata. The source retains its row fields for history/restoration.

### insertRows

```ts
insertRows: (index: number, rows: readonly DataRow[]) => void
```

Insert DataRow snapshots before a source row index under structural policy. Requires atomic source splices and valid unique IDs; projected views must be cleared.

### deleteRows

```ts
deleteRows: (indices: readonly number[]) => void
```

Delete selected source row indices under structural policy, preserving full shallow row snapshots for undo. Requires source row snapshots/splices.

### moveRows

```ts
moveRows: (indices: readonly number[], beforeIndex: number) => void
```

Move source row indices before a source insertion position, preserving their relative order. Requires structural policy/source support and no projected view.

### moveColumns

```ts
moveColumns: (indices: readonly number[], beforeIndex: number) => void
```

Move current column indices before an insertion position, preserving their relative order and remapping metadata under structural policy.

## Permissions and formatting

### getCellPermission

```ts
getCellPermission: (row: number, col: number) => CellPermission
```

Resolve policy capabilities for a visible cell, including current locks and explicit false vetoes. writable does not prove that the source exposes a setter; canEdit checks setter support. Server authorization remains host-owned.

### getFormat

```ts
getFormat: (row: number, col: number) => Readonly<CellFormat>
```

Resolve supported formatting for a visible cell using sparse table/row/column/cell metadata. Raw source values are unchanged.

### canFormat

```ts
canFormat: (targets: readonly CellFormatTarget[]) => boolean
```

Preflight visible format targets against bounds and formatting policy. Format permission is independent of value writable permission.

### format

```ts
format: (targets: readonly CellFormatTarget[], patch: CellFormatPatch | null) => void
```

Apply or remove supported formatting on visible targets after complete validation/policy checks. Participates in formatting history; does not change source values.

### isLocked

```ts
isLocked: (target: CellLockTarget) => boolean
```

Check the requested visible table/row/column/cell lock target. Lock metadata is a client capability constraint, not backend authorization.

### canManageLocks

```ts
canManageLocks: () => boolean
```

Whether lock management is enabled for the engine. Target validation and command lifecycle still apply when changing locks.

### setLocked

```ts
setLocked: (target: CellLockTarget, locked: boolean) => void
```

Set or clear a validated visible lock target when lock changes are allowed. Value commands and history replay resolve current effective locks.

## Layout and browser controls

### frozenRows

```ts
frozenRows: number
```

Visible frozen leading row count after projection/group collapse, derived from the source frozen prefix.

### frozenColumns

```ts
frozenColumns: number
```

Current frozen leading column count. Freeze boundaries must fit the current structure.

### getViewport

```ts
getViewport: (viewport: ViewportOptions) => Readonly<{ hitTest(x: number, y: number): { row: number; col: number; } | null; cellRect(row: number, col: number): Readonly<{ x: number; y: number; width: number; height: number; clip: Readonly<{ x: number; y: number; width: number; height: number; }>; }>; width: number; height: number; scrollLeft: number; scrollTop: number; frozenWidth: number; frozenHeight: number; regions: readonly ViewportRegion[]; }>
```

Compute numeric scroll/frozen pane ranges, cell geometry and hit-testing for the visible layout. It does not load remote pages or prove renderer frame rate.

### canChangeLayout

```ts
canChangeLayout: (request: LayoutRequest) => boolean
```

Preflight a source-coordinate layout request against feature flags and current layout policy. A permission probe is not a committed command.

### getRowSourceIndex

```ts
getRowSourceIndex: (row: number) => number
```

Map a visible row index to its source row index. Use this explicitly at host/source boundaries; do not pass visible indices directly to a projected source.

### rows

```ts
rows: Readonly<{ size: (i: number) => number; position: (i: number) => number; indexAt: (offset: number) => number; range: (offset: number, extent: number) => { start: number; end: number; }; }>
```

Read-only visible-row size/position/indexAt/range geometry. Sparse overrides do not allocate metadata for every source row.

### columnsLayout

```ts
columnsLayout: Readonly<{ size: (index: number) => number; position: (index: number) => number; indexAt: (offset: number) => number; range: (offset: number, extent: number) => { start: number; end: number; }; }>
```

Read-only current column size/position/indexAt/range geometry. Numeric viewport boundaries are end-exclusive; selection rectangles are inclusive.

### canChangeStructure

```ts
canChangeStructure: (request: Readonly<StructureRequest>) => boolean
```

Preflight a source-coordinate structural request against current view, source support, locks and policy. No mutation occurs.

### isRowHeightManual

```ts
isRowHeightManual: (index: number) => boolean
```

Whether a visible row has an explicit manual height override. Automatic measurement does not mark a row as manually resized.

### measureRowHeight

```ts
measureRowHeight: (index: number, size: number) => void
```

Apply a finite positive measured height to a visible row through layout policy, without adding a manual resize history entry.

### canEdit

```ts
canEdit: (row: number, col: number) => boolean
```

Preflight edit capability for a visible cell, including source setter support and effective editable/writable permission. Actual parsing/validation can still reject an edit.

### canPaste

```ts
canPaste: () => boolean
```

Whether current selection/source permissions permit paste in principle. Payload shape, bounds, parsing and validation are checked by the actual paste command.

### addSelection

```ts
addSelection: (row: number, col: number) => boolean
```

Retain the existing selection and add a visible active cell. Subject to selectable policy and range/fragment limits.

### toggleSelection

```ts
toggleSelection: (row: number, col: number) => boolean
```

Toggle a visible cell or its entire merged span. Subtract selected cells from every overlapping rectangle; add unselected cells. Invalid coordinates, denied policies and the 128-source-range limit preserve prior state.

### setFrozen

```ts
setFrozen: (rows: number, columns: number) => void
```

Set the requested visible leading row/column counts after validation/layout policy; collapsed groups map the row prefix to source coordinates. Participates in layout history; collapsed groups cannot cross a frozen boundary.

### setRowsHidden

```ts
setRowsHidden: (indices: readonly number[], hidden: boolean) => void
```

Hide/show specified visible rows under table lock and canChangeVisibility policy. Retain underlying data, stored size and identity; clear selection/cut and record one undo command.

### setColumnsHidden

```ts
setColumnsHidden: (indices: readonly number[], hidden: boolean) => void
```

Hide/show current column indices under table lock and visibility policy; retain fields, widths and metadata. History replay rechecks the policy.

### getHiddenRows

```ts
getHiddenRows: () => readonly number[]
```

Return hidden rows mapped into the current projection. Rows excluded by filters or collapsed groups are omitted; saved state retains source hidden indices.

### getHiddenColumns

```ts
getHiddenColumns: () => readonly number[]
```

Return sorted hidden column indices in current display order.

### isRowHidden

```ts
isRowHidden: (index: number) => boolean
```

Check the hidden flag at a visible row; invalid indices reject. Hidden is separate from filter/group projection.

### isColumnHidden

```ts
isColumnHidden: (index: number) => boolean
```

Check the hidden flag at a current column; invalid indices reject. Hiding is layout, not data authorization.

### setColumnWidth

```ts
setColumnWidth: (index: number, size: number) => void
```

Set a finite positive current column width under layout policy, with sparse geometry and undo/redo.

### setRowHeight

```ts
setRowHeight: (index: number, size: number) => void
```

Set a finite positive visible row height under layout policy, mark it manual and record layout history.

## Construction options

Call createGridEngine with GridEngineOptions. Required fields are marked; options are read at construction unless the package guide specifies a runtime setter.

| Field | Required | Type |
| --- | --- | --- |
| tree | No | `LocalTreeOptions \| undefined` |
| grouping | No | `LocalGroupingOptions \| undefined` |
| historyLimits | No | `GridHistoryLimits \| undefined` |
| onObserverError | No | `((error: unknown) => void) \| undefined` |
| allowMerging | No | `boolean \| undefined` |
| allowRowGrouping | No | `boolean \| undefined` |
| canChangeVisibility | No | `((request: Readonly<{ axis: "row" \| "column"; indices: readonly number[]; hidden: boolean; }>) => boolean) \| undefined` |
| canChangeLayout | No | `((request: Readonly<LayoutRequest>) => boolean) \| undefined` |
| columns | Yes | `readonly Column[]` |
| view | No | `LocalViewOptions \| undefined` |
| canChangeStructure | No | `((request: Readonly<StructureRequest>) => boolean) \| undefined` |
| dataSource | Yes | `DataSource` |
| permissions | No | `Partial<CellPermission> \| undefined` |
| resolveCellPermission | No | `CellPermissionResolver \| undefined` |
| onEvent | No | `((event: GridEvent) => void) \| undefined` |
| rowHeight | No | `number \| undefined` |
| columnWidth | No | `number \| undefined` |
| columnWidths | No | `Readonly<Record<string, number>> \| undefined` |
| allowLockChanges | No | `boolean \| undefined` |
| frozenRows | No | `number \| undefined` |
| frozenColumns | No | `number \| undefined` |
| onInvalidate | No | `((change: GridInvalidation) => void) \| undefined` |

## Public exports and source interfaces

The root and headless alias expose the same API. Source interfaces use their own row indices, not an engine visible projection. The table lists every public export, including types; declarations and the package guide define their contracts. createAsyncDataSource and createLiveDataSource remain read-only; createPagedRemoteDataSource adds explicit writable paging.

| Export | Kind | Defined in | Contract |
| --- | --- | --- | --- |
| createGridEngine | Runtime | engine.ts | Create the headless domain instance from application-owned columns/source/policies. See the member contracts and construction options above. |
| LocalTreeOptions | Type | tree.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| LocalTreeRow | Type | tree.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| TreeState | Type | tree.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GridEngine | Type | engine.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GridEngineOptions | Type | engine.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GridInvalidation | Type | engine.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| LocalGroupingOptions | Type | grouping.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GroupKey | Type | grouping.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GroupDisplayRow | Type | grouping.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GroupingState | Type | grouping.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GridRowMetadata | Type | grouping.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GridBulkOptions | Type | bulk.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GridBulkProgress | Type | bulk.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GridHistoryLimits | Type | history-budget.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| LocalDataSource | Runtime | data-source.ts | Shallow immutable local row snapshots with unique string/finite-number IDs, synchronous atomic batches and sequential atomic splices. Nested objects remain host-owned. |
| LocalDataView | Runtime | data-source.ts | A fixed local projection using stable ties and nullish-last sorting. Delegated writes map view indices to underlying source indices; reconstruct the view to reapply criteria. |
| createAsyncDataSource | Runtime | async-data-source.ts | Read-only synchronous cache with explicit asynchronous page/range loading. The host owns load scheduling, AbortController creation, engine refresh and dataset revision consistency. |
| createLiveDataSource | Runtime | live-data-source.ts | Read-only bounded local cache of a host stream. Start with a matching snapshot; receive consecutive sequences, coalesce pending cells and flush explicitly. Gaps/disconnect require resync. |
| createRemoteDataSource | Runtime | remote-data-source.ts | Bounded optimistic JSON snapshot cache with synchronous atomic drafts and explicit async commit/resync. Host server must provide atomic revision checks and mutation ID deduplication. Lost ACK retains an immutable retry; conflict requires explicit resolution. |
| createPagedRemoteDataSource | Runtime | paged-remote-data-source.ts | Create a bounded writable page cache with stable-ID drafts, server-owned query/revision, dirty-cohort receipts, exact uncertain retry and whole-cache invalidation after accepted writes. Load only required pages; reconcile engine identity/history after cache changes. |
| PagedRemoteDataSourceOptions | Type | paged-remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| PagedRemoteWriteResult | Type | paged-remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| PagedRemoteMutationCheckpoint | Type | paged-remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| PagedRemoteDraftSnapshot | Type | paged-remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RemoteDataSourceOptions | Type | remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RemoteSnapshot | Type | remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RemoteDelta | Type | remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RemoteChange | Type | remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RemoteMutation | Type | remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RemoteMutationCheckpoint | Type | remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RemoteWriteResult | Type | remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RemoteStatus | Type | remote-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| LiveUpdate | Type | live-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| LiveSnapshot | Type | live-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| AsyncDataSourceOptions | Type | async-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| PageState | Type | async-data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| DataSource | Type | data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| CellUpdate | Type | data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RowId | Type | data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| LocalViewOptions | Type | data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| DataRow | Type | data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RowSplice | Type | data-source.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| Column | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| CellSelection | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| SelectionRange | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| CellLockTarget | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| CellFormatTarget | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| CellFormat | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| CellFormatPatch | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| NumberFormat | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| PasteOptions | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| CellPermission | Type | permissions.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| CellPermissionPolicy | Type | permissions.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| CellPermissionResolver | Type | permissions.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GridEvent | Type | events.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GridChangeSource | Type | events.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RowRefreshResult | Type | events.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| DataResetResult | Type | events.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| ViewportOptions | Type | panes.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| ViewportLayout | Type | panes.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| ViewportRegion | Type | panes.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| ViewportRect | Type | panes.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| reorderedIndices | Runtime | structure.ts | Validate move indices/insertion position and return a new index order preserving relative order. It does not mutate rows, permissions or history. |
| StructureRequest | Type | structure.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| gridClipboardType | Runtime | clipboard.ts | MIME identifier for the internal versioned structured clipboard format. TSV remains the external plain-text fallback. |
| encodeBlocks | Runtime | clipboard.ts | Validate clipboard block shape/limits and serialize string values plus supported formatting to the versioned wire payload. This is not an arbitrary object codec. |
| decodeBlocks | Runtime | clipboard.ts | Parse unknown structured clipboard text and validate schema, dimensions, supported formatting and budgets before use. It does not write to a source. |
| blocksToTsv | Runtime | clipboard.ts | Pack structured string blocks into TSV. Core command wrappers additionally enforce effective copy permissions; direct helper calls have no engine authorization context. |
| ClipboardBlock | Type | clipboard.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| RowGroup | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| LayoutRequest | Type | types.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| restoreGridConfiguration | Runtime | configuration.ts | Validate unknown versioned configuration against application column definitions and row count; return construction options. Saved input cannot supply executable callbacks/policies. |
| GridConfiguration | Type | configuration.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |
| GridState | Type | state.ts | Compile-time contract; see the exported type definitions below or engine construction/member signatures. |

### LocalDataSource source members

Use source indices here; engine selection/value APIs use visible indices.

```ts
getRowCount: () => number
getRowId: (index: number) => RowId
getValue: (index: number, columnKey: string) => unknown
setValue: (index: number, columnKey: string, value: unknown) => void
setValues: (updates: readonly CellUpdate[]) => void
addColumns: (keys: readonly string[], defaults?: Readonly<Record<string, unknown>>) => void
getRow: (index: number) => DataRow
spliceRows: (splices: readonly RowSplice[]) => void
```

| Source member | Behavior |
| --- | --- |
| getRowCount | Synchronous row count of this source/view. Engine projection is a separate layer. |
| getRowId | Read the ID using this source/view index. Async positional identity belongs to one query; the host must manage dataset revisions. |
| getValue | Read a raw shallow value using this source/view index and key. Missing fields return undefined; async unloaded rows also return undefined, so inspect page state separately. |
| setValue | Remote: stage one optimistic value only while ready. Local atomic single-value replacement, or an optional delegated view setter when the underlying source supports it. No engine permissions/history are applied by direct source writes. |
| setValues | Remote: bounded atomic optimistic JSON-safe staging only while ready. Local atomic batch, or an optional mapped view batch when the underlying source supports it. Direct source changes require engine refresh and remain outside engine history. |
| addColumns | Validate new keys and initialize missing fields atomically while preserving existing fields/defaults. Direct use is outside engine history. |
| getRow | Return a shallow row snapshot including hidden fields; nested values are caller-owned. |
| spliceRows | Apply sequential row splices atomically with unique valid IDs and shallow snapshots. Capture engine IDs before external structure changes. |

### LocalDataView source members

Use source indices here; engine selection/value APIs use visible indices. This view fixes a projection at construction; rebuild it to reapply criteria.

```ts
setValue?: ((index: number, key: string, value: unknown) => void) | undefined
setValues?: ((updates: readonly CellUpdate[]) => void) | undefined
getSourceIndex: (index: number) => number
getRowCount: () => number
getRowId: (index: number) => RowId
getValue: (index: number, columnKey: string) => unknown
```

| Source member | Behavior |
| --- | --- |
| setValue | Remote: stage one optimistic value only while ready. Local atomic single-value replacement, or an optional delegated view setter when the underlying source supports it. No engine permissions/history are applied by direct source writes. |
| setValues | Remote: bounded atomic optimistic JSON-safe staging only while ready. Local atomic batch, or an optional mapped view batch when the underlying source supports it. Direct source changes require engine refresh and remain outside engine history. |
| getSourceIndex | Map a fixed LocalDataView index to the underlying source index. Rebuild the view after changes requiring new sorting/filtering. |
| getRowCount | Synchronous row count of this source/view. Engine projection is a separate layer. |
| getRowId | Read the ID using this source/view index. Async positional identity belongs to one query; the host must manage dataset revisions. |
| getValue | Read a raw shallow value using this source/view index and key. Missing fields return undefined; async unloaded rows also return undefined, so inspect page state separately. |

### createAsyncDataSource source members

Use source indices here; engine selection/value APIs use visible indices.

```ts
pageSize: number
maxConcurrentLoads: number
maxPendingLoads: number
query: Readonly<LocalViewOptions>
setQuery: (next: LocalViewOptions, rowCount?: number) => void
loadPage: (offset: number) => Promise<void>
loadRange: (start: number, end: number) => Promise<void>
getPageState: (offset: number) => PageState | null
subscribe: (listener: (state: PageState) => void) => () => void
takeObserverErrors: () => unknown[]
cancel: () => void
reset: (rowCount?: number) => void
destroy: () => void
getRowCount: () => number
getRow?: ((index: number) => DataRow) | undefined
addColumns?: ((keys: readonly string[], defaults?: Readonly<Record<string, unknown>>) => void) | undefined
spliceRows?: ((splices: readonly RowSplice[]) => void) | undefined
getRowId: (index: number) => RowId
getValue: (index: number, columnKey: string) => unknown
setValue?: ((index: number, columnKey: string, value: unknown) => void) | undefined
setValues?: ((updates: readonly CellUpdate[]) => void) | undefined
```

| Source member | Behavior |
| --- | --- |
| pageSize | Validated positive page length fixed at construction; loadPage offsets must be aligned. |
| maxConcurrentLoads | Maximum active loader calls; a canceled loader must settle so its active slot can be released. |
| maxPendingLoads | Maximum active plus queued loads. Duplicate pages share a promise; admission failures occur before scheduling extra work. |
| query | Immutable captured server criteria. Each load receives the snapshot for its generation; this is not local sorting of cached rows. |
| setQuery | Validate new criteria/count, clear cache/statuses and cancel the previous generation. The host must reconcile the engine and identity after a query change. |
| loadPage | Load one aligned nonnegative offset with deduplication/FIFO concurrency. Validate result dimensions; errors reject, canceled/stale results do not repopulate cache. |
| loadRange | Load inclusive source indices start through end. The requested pages must fit the cache and pending capacity before admission. |
| getPageState | Return state for a page offset or null; error/ready bookkeeping is bounded and eviction can remove it. This is not a per-cell loaded-state API. |
| subscribe | Observe page state changes; returns unsubscribe. Observer exceptions are isolated in a bounded queue; engine refresh is host-owned. |
| takeObserverErrors | Drain up to the last ten isolated page observer errors. This does not retry failed loads. |
| cancel | Invalidate the request generation and signal pending controllers without clearing completed cache/count. Safe cleanup after disposal; loaders must settle/timeout. |
| reset | Async: clear cache/statuses and cancel generation, retaining query with the supplied count. Live: change stream, clear pending changes and mark stale; retain old data until a matching snapshot. |
| destroy | Idempotent disposal of owned cache/queues/observers. Data access and active loads require a live source; cleanup/status probes follow their specific contract. The host owns external transport resources. |
| getRowCount | Synchronous row count of this source/view. Engine projection is a separate layer. |
| getRow | Optional DataSource compatibility slot; not implemented by this read-only factory and undefined at runtime. |
| addColumns | Optional DataSource compatibility slot; not implemented by this read-only factory and undefined at runtime. |
| spliceRows | Optional DataSource compatibility slot; not implemented by this read-only factory and undefined at runtime. |
| getRowId | Read the ID using this source/view index. Async positional identity belongs to one query; the host must manage dataset revisions. |
| getValue | Read a raw shallow value using this source/view index and key. Missing fields return undefined; async unloaded rows also return undefined, so inspect page state separately. |
| setValue | Optional DataSource compatibility slot; not implemented by this read-only factory and undefined at runtime. |
| setValues | Optional DataSource compatibility slot; not implemented by this read-only factory and undefined at runtime. |

### createLiveDataSource source members

Use source indices here; engine selection/value APIs use visible indices.

```ts
streamId: string
sequence: number
stale: boolean
pendingCellCount: number
reset: (next: string) => void
disconnect: () => void
replaceSnapshot: (snapshot: LiveSnapshot) => boolean
receive: (message: LiveUpdate) => boolean
flush: () => number
destroy: () => void
getRowCount: () => number
getRow?: ((index: number) => DataRow) | undefined
addColumns?: ((keys: readonly string[], defaults?: Readonly<Record<string, unknown>>) => void) | undefined
spliceRows?: ((splices: readonly RowSplice[]) => void) | undefined
getRowId: (index: number) => RowId
getValue: (index: number, columnKey: string) => unknown
setValue?: ((index: number, columnKey: string, value: unknown) => void) | undefined
setValues?: ((updates: readonly CellUpdate[]) => void) | undefined
```

| Source member | Behavior |
| --- | --- |
| streamId | Current host stream identifier; messages/snapshots for another stream are ignored. |
| sequence | Latest accepted sequence, including buffered updates not yet flushed. It is not a saved backend revision. |
| stale | Whether a fresh snapshot is required. Read-only retained values can still exist while stale; do not treat them as current. |
| pendingCellCount | Number of unique buffered destination cells after bounded coalescing; not the count of received messages. |
| reset | Async: clear cache/statuses and cancel generation, retaining query with the supplied count. Live: change stream, clear pending changes and mark stale; retain old data until a matching snapshot. |
| disconnect | Remote: abort/invalidate the active generation but retain drafts and uncertain mutation for exact retry. Live: mark the live source stale and discard buffered updates; does not itself reconnect transport or remove retained rows. |
| replaceSnapshot | Validate a matching-stream snapshot with bounded rows, unique IDs and configured fields, then atomically replace the local cache. Reject older/wrong-stream snapshots without installing them. |
| receive | Accept only matching-stream consecutive sequences when not stale; coalesce cells without writing them yet. Gaps, invalid destinations or capacity overflow mark stale and clear pending changes. |
| flush | Apply buffered live changes atomically and return the number of unique updated cells. Returns zero while stale; the host refreshes the engine after flushing. |
| destroy | Idempotent disposal of owned cache/queues/observers. Data access and active loads require a live source; cleanup/status probes follow their specific contract. The host owns external transport resources. |
| getRowCount | Synchronous row count of this source/view. Engine projection is a separate layer. |
| getRow | Optional DataSource compatibility slot; not implemented by this read-only factory and undefined at runtime. |
| addColumns | Optional DataSource compatibility slot; not implemented by this read-only factory and undefined at runtime. |
| spliceRows | Optional DataSource compatibility slot; not implemented by this read-only factory and undefined at runtime. |
| getRowId | Read the ID using this source/view index. Async positional identity belongs to one query; the host must manage dataset revisions. |
| getValue | Read a raw shallow value using this source/view index and key. Missing fields return undefined; async unloaded rows also return undefined, so inspect page state separately. |
| setValue | Optional DataSource compatibility slot; not implemented by this read-only factory and undefined at runtime. |
| setValues | Optional DataSource compatibility slot; not implemented by this read-only factory and undefined at runtime. |

### createRemoteDataSource source members

Use source indices here; engine selection/value APIs use visible indices.

```ts
getRowCount: () => number
getRowId: (row: number) => RowId
getValue: (row: number, key: string) => unknown
setValues: (updates: readonly CellUpdate[]) => void
setValue: (rowIndex: number, columnKey: string, value: unknown) => void
status: RemoteStatus
revision: string | null
pendingCellCount: number
lastError: unknown
getPendingChanges: () => readonly RemoteChange[]
conflict: RemoteSnapshot | null
commit: () => Promise<void>
exportMutation: () => RemoteMutationCheckpoint
restoreMutation: (input: unknown) => void
resync: (discardPending?: boolean) => Promise<void>
reconnect: () => Promise<void>
disconnect: () => void
acceptServer: () => void
subscribe: (listener: (status: RemoteStatus) => void) => () => void
takeObserverErrors: () => unknown[]
destroy: () => void
```

| Source member | Behavior |
| --- | --- |
| getRowCount | Synchronous row count of this source/view. Engine projection is a separate layer. |
| getRowId | Read the ID using this source/view index. Async positional identity belongs to one query; the host must manage dataset revisions. |
| getValue | Read a raw shallow value using this source/view index and key. Missing fields return undefined; async unloaded rows also return undefined, so inspect page state separately. |
| setValues | Remote: bounded atomic optimistic JSON-safe staging only while ready. Local atomic batch, or an optional mapped view batch when the underlying source supports it. Direct source changes require engine refresh and remain outside engine history. |
| setValue | Remote: stage one optimistic value only while ready. Local atomic single-value replacement, or an optional delegated view setter when the underlying source supports it. No engine permissions/history are applied by direct source writes. |
| status | Remote lifecycle: disconnected/loading/ready/committing/conflict/destroyed. Only ready permits drafts; pending uncertain writes block new edits. |
| revision | Remote authoritative snapshot revision; optimistic drafts do not advance it. |
| pendingCellCount | Number of unique buffered destination cells after bounded coalescing; not the count of received messages. |
| lastError | Most recent remote load/transport/validation rejection; a valid installed snapshot clears it. |
| getPendingChanges | Return frozen remote draft entries keyed by stable row ID and column key. Preserve these before explicitly accepting a conflicting server snapshot. |
| conflict | Validated remote server snapshot on conflict, or null. Draft values remain in the cache until explicit adoption. |
| commit | Commit one immutable mutation against expectedRevision. Bounded remote concurrent calls share the promise; paged concurrent calls reject. Lost responses retain the exact request for retry. Acceptance clears drafts; paged acceptance invalidates pages without fetching them. Rejection retains correctable drafts; conflict blocks editing. |
| exportMutation | Available in 0.3.0: export an immutable in-flight/uncertain request checkpoint. Bounded sources include their original snapshot/schema; paged sources add query/total/stable positions around the dirty-cohort writer. Preserve the exact mutation ID/payload; conflicts require their own resolution. |
| restoreMutation | Available in 0.3.0: validate a checkpoint into a new source and atomically restore optimistic rows plus the exact disconnected request. Paged query/schema/positions/cohort must match; no server load/write or new mutation ID. Retry through commit; storage is not authorization. |
| resync | Load a fresh bounded remote snapshot. Unsent drafts require explicit discardPending=true; an uncertain mutation cannot be discarded. Capture engine identity first and refresh afterward. |
| reconnect | Remote resync without discarding drafts; retry an uncertain commit first. Transport reconnection itself belongs to the host. |
| disconnect | Remote: abort/invalidate the active generation but retain drafts and uncertain mutation for exact retry. Live: mark the live source stale and discard buffered updates; does not itself reconnect transport or remove retained rows. |
| acceptServer | Explicitly adopt a validated conflicting remote snapshot and discard its drafts. Host refreshes engine and may reapply selected saved drafts through validation. |
| subscribe | Observe page state changes; returns unsubscribe. Observer exceptions are isolated in a bounded queue; engine refresh is host-owned. |
| takeObserverErrors | Drain up to the last ten isolated page observer errors. This does not retry failed loads. |
| destroy | Idempotent disposal of owned cache/queues/observers. Data access and active loads require a live source; cleanup/status probes follow their specific contract. The host owns external transport resources. |

### createPagedRemoteDataSource source members

Use source indices here; engine selection/value APIs use visible indices.

```ts
query: Readonly<LocalViewOptions>
revision: string | null
status: RemoteStatus
lastError: unknown
conflict: RemoteSnapshot | null
pendingCellCount: number
getRowId: (index: number) => RowId
getValue: (index: number, key: string) => unknown
setValues: (updates: readonly CellUpdate[]) => void
setValue: (rowIndex: number, columnKey: string, value: unknown) => void
commit: () => Promise<void>
exportDrafts: () => PagedRemoteDraftSnapshot
restoreDrafts: (input: unknown) => Promise<void>
exportMutation: () => PagedRemoteMutationCheckpoint
restoreMutation: (input: unknown) => void
getPendingChanges: () => readonly Readonly<{ rowId: RowId; columnKey: string; previous: unknown; value: unknown; }>[]
setQuery: (next: LocalViewOptions, total?: number) => void
reset: (total?: number) => void
cancel: () => void
discardPending: () => void
acceptServer: () => void
destroy: () => void
pageSize: number
maxConcurrentLoads: number
maxPendingLoads: number
loadPage: (offset: number) => Promise<void>
loadRange: (start: number, end: number) => Promise<void>
getPageState: (offset: number) => PageState | null
subscribe: (listener: (state: PageState) => void) => () => void
takeObserverErrors: () => unknown[]
getRowCount: () => number
getRow?: ((index: number) => DataRow) | undefined
addColumns?: ((keys: readonly string[], defaults?: Readonly<Record<string, unknown>>) => void) | undefined
spliceRows?: ((splices: readonly RowSplice[]) => void) | undefined
```

| Source member | Behavior |
| --- | --- |
| query | Immutable captured server criteria. Each load receives the snapshot for its generation; this is not local sorting of cached rows. |
| revision | Remote authoritative snapshot revision; optimistic drafts do not advance it. |
| status | Remote lifecycle: disconnected/loading/ready/committing/conflict/destroyed. Only ready permits drafts; pending uncertain writes block new edits. |
| lastError | Most recent remote load/transport/validation rejection; a valid installed snapshot clears it. |
| conflict | Validated remote server snapshot on conflict, or null. Draft values remain in the cache until explicit adoption. |
| pendingCellCount | Number of unique buffered destination cells after bounded coalescing; not the count of received messages. |
| getRowId | Read the ID using this source/view index. Async positional identity belongs to one query; the host must manage dataset revisions. |
| getValue | Read a raw shallow value using this source/view index and key. Missing fields return undefined; async unloaded rows also return undefined, so inspect page state separately. |
| setValues | Remote: bounded atomic optimistic JSON-safe staging only while ready. Local atomic batch, or an optional mapped view batch when the underlying source supports it. Direct source changes require engine refresh and remain outside engine history. |
| setValue | Remote: stage one optimistic value only while ready. Local atomic single-value replacement, or an optional delegated view setter when the underlying source supports it. No engine permissions/history are applied by direct source writes. |
| commit | Commit one immutable mutation against expectedRevision. Bounded remote concurrent calls share the promise; paged concurrent calls reject. Lost responses retain the exact request for retry. Acceptance clears drafts; paged acceptance invalidates pages without fetching them. Rejection retains correctable drafts; conflict blocks editing. |
| exportDrafts | Available in 0.3.0: export a bounded immutable JSON v1 checkpoint of unsent/rejected paged drafts with dataset/revision/query/schema/total and previous values. Requires a loaded idle source; uncertain writes/conflicts must be resolved first. Host owns storage and privacy. |
| restoreDrafts | Available in 0.3.0: validate an unknown checkpoint into an empty paged source, load affected pages sequentially and check revision/total/identity/previous values before atomically installing drafts. No server writes or undo history. Failure/cancel/destroy installs no drafts; host reapplies current permissions/validation and remounts the engine. |
| exportMutation | Available in 0.3.0: export an immutable in-flight/uncertain request checkpoint. Bounded sources include their original snapshot/schema; paged sources add query/total/stable positions around the dirty-cohort writer. Preserve the exact mutation ID/payload; conflicts require their own resolution. |
| restoreMutation | Available in 0.3.0: validate a checkpoint into a new source and atomically restore optimistic rows plus the exact disconnected request. Paged query/schema/positions/cohort must match; no server load/write or new mutation ID. Retry through commit; storage is not authorization. |
| getPendingChanges | Return frozen remote draft entries keyed by stable row ID and column key. Preserve these before explicitly accepting a conflicting server snapshot. |
| setQuery | Validate new criteria/count, clear cache/statuses and cancel the previous generation. The host must reconcile the engine and identity after a query change. |
| reset | Async: clear cache/statuses and cancel generation, retaining query with the supplied count. Live: change stream, clear pending changes and mark stale; retain old data until a matching snapshot. |
| cancel | Invalidate the request generation and signal pending controllers without clearing completed cache/count. Safe cleanup after disposal; loaders must settle/timeout. |
| discardPending | Paged remote: discard only unsent or rejected drafts and invalidate cached pages. An uncertain or conflicting mutation must be resolved first. |
| acceptServer | Explicitly adopt a validated conflicting remote snapshot and discard its drafts. Host refreshes engine and may reapply selected saved drafts through validation. |
| destroy | Idempotent disposal of owned cache/queues/observers. Data access and active loads require a live source; cleanup/status probes follow their specific contract. The host owns external transport resources. |
| pageSize | Validated positive page length fixed at construction; loadPage offsets must be aligned. |
| maxConcurrentLoads | Maximum active loader calls; a canceled loader must settle so its active slot can be released. |
| maxPendingLoads | Maximum active plus queued loads. Duplicate pages share a promise; admission failures occur before scheduling extra work. |
| loadPage | Load one aligned nonnegative offset with deduplication/FIFO concurrency. Validate result dimensions; errors reject, canceled/stale results do not repopulate cache. |
| loadRange | Load inclusive source indices start through end. The requested pages must fit the cache and pending capacity before admission. |
| getPageState | Return state for a page offset or null; error/ready bookkeeping is bounded and eviction can remove it. This is not a per-cell loaded-state API. |
| subscribe | Observe page state changes; returns unsubscribe. Observer exceptions are isolated in a bounded queue; engine refresh is host-owned. |
| takeObserverErrors | Drain up to the last ten isolated page observer errors. This does not retry failed loads. |
| getRowCount | Synchronous row count of this source/view. Engine projection is a separate layer. |
| getRow | Return a shallow row snapshot including hidden fields; nested values are caller-owned. |
| addColumns | Validate new keys and initialize missing fields atomically while preserving existing fields/defaults. Direct use is outside engine history. |
| spliceRows | Apply sequential row splices atomically with unique valid IDs and shallow snapshots. Capture engine IDs before external structure changes. |

## Exported type definitions

These declaration excerpts describe compile-time contracts, not executable examples or runtime validators. GridEngine members and GridEngineOptions are catalogued above. Unknown persisted/clipboard input still requires its validation API; never trust a TypeScript assertion as validation.

### Type LocalTreeOptions

```ts
export interface LocalTreeOptions {
  readonly parentColumnKey: string;
}
```

### Type LocalTreeRow

```ts
export interface LocalTreeRow {
  readonly sourceIndex: number;
  readonly rowId: RowId;
  readonly parentId: RowId | null;
  readonly level: number;
  readonly hasChildren: boolean;
  readonly expanded: boolean;
}
```

### Type TreeState

```ts
export interface TreeState {
  readonly version: 1;
  readonly tree: Readonly<LocalTreeOptions> | null;
  readonly collapsedIds: readonly RowId[];
}
```

### Type GridInvalidation

```ts
export type GridInvalidation =
  | { readonly type: 'reset' }
  | { readonly type: 'rows'; readonly startRow: number; readonly endRow: number }
  | { readonly type: 'cells'; readonly cells: readonly { readonly rowIndex: number; readonly columnKey: string }[] }
  | { readonly type: 'selection'; readonly changed: boolean; readonly rangeChanged: boolean }
  | { readonly type: 'layout' }
  | { readonly type: 'structure'; readonly rowMap: readonly number[]; readonly columnMap: readonly number[] };
```

### Type LocalGroupingOptions

```ts
export interface LocalGroupingOptions {
  readonly columnKey: string;
  readonly sumColumns?: readonly string[];
}
```

### Type GroupKey

```ts
export type GroupKey = string | number | boolean | null;
```

### Type GroupDisplayRow

```ts
export interface GroupDisplayRow extends LocalGroup {
  readonly kind: 'group';
  readonly expanded: boolean;
}
```

### Type GroupingState

```ts
export interface GroupingState {
  readonly version: 1;
  readonly grouping: Readonly<LocalGroupingOptions> | null;
  readonly collapsedKeys: readonly GroupKey[];
}
```

### Type GridRowMetadata

```ts
export type GridRowMetadata =
  | GroupDisplayRow
  | Readonly<{
      kind: 'leaf';
      sourceIndex: number;
      rowId: RowId;
    }>;
```

### Type GridBulkOptions

```ts
export interface GridBulkOptions {
  /** Host scheduler, for example a browser task yield. Must eventually settle. */
  readonly yieldControl: () => Promise<void>;
  readonly signal?: { readonly aborted: boolean };
  readonly onProgress?: (progress: GridBulkProgress) => void;
  /** Must change on external data, schema or permission changes during the operation. */
  readonly getRevision?: () => string;
  /** Optional off-thread TSV decoder. Results are validated before paste. */
  readonly tsvDecoder?: {
    decodeTsv(text: string, signal?: { readonly aborted: boolean }): Promise<unknown>;
  };
}
```

### Type GridBulkProgress

```ts
export interface GridBulkProgress {
  readonly phase: 'parse' | 'prepare' | 'validate' | 'sort';
  readonly completed: number;
  readonly total: number;
}
```

### Type GridHistoryLimits

```ts
export interface GridHistoryLimits {
  readonly maxCommands?: number;
  /** Retained value/format change records, not an estimate of JavaScript heap bytes. */
  readonly maxValueCells?: number;
}
```

### Type PagedRemoteDataSourceOptions

```ts
export interface PagedRemoteDataSourceOptions<S> extends Pick<
  AsyncDataSourceOptions<S>,
  'rowCount' | 'pageSize' | 'maxPages' | 'maxConcurrentLoads' | 'maxPendingLoads' | 'query' | 'createAbortController'
> {
  readonly datasetId: string;
  readonly columnKeys: readonly string[];
  readonly maxPendingCells?: number;
  readonly createMutationId: () => string;
  readonly load: (request: {
    readonly offset: number;
    readonly limit: number;
    readonly signal: S;
    readonly query: Readonly<LocalViewOptions>;
    readonly expectedRevision: string | null;
  }) => Promise<RemoteSnapshot & { readonly total: number }>;
  /** Receipts contain only the dirty-row cohort. Every accepted write invalidates the page cache. */
  readonly write: (
    mutation: RemoteMutation,
    signal: S,
    query: Readonly<LocalViewOptions>,
  ) => Promise<PagedRemoteWriteResult>;
  readonly persistMutation?: (checkpoint: PagedRemoteMutationCheckpoint) => void | Promise<void>;
}
```

### Type PagedRemoteWriteResult

```ts
export type PagedRemoteWriteResult = RemoteWriteResult & { readonly total: number };
```

### Type PagedRemoteMutationCheckpoint

```ts
export interface PagedRemoteMutationCheckpoint {
  readonly version: 1;
  readonly query: Readonly<LocalViewOptions>;
  readonly total: number;
  readonly positions: readonly { readonly rowIndex: number; readonly rowId: RowId }[];
  readonly writer: RemoteMutationCheckpoint;
}
```

### Type PagedRemoteDraftSnapshot

```ts
export interface PagedRemoteDraftSnapshot {
  readonly version: 1;
  readonly datasetId: string;
  readonly revision: string;
  readonly query: Readonly<LocalViewOptions>;
  readonly columnKeys: readonly string[];
  readonly total: number;
  readonly changes: readonly {
    readonly rowIndex: number;
    readonly rowId: RowId;
    readonly columnKey: string;
    readonly previous: unknown;
    readonly value: unknown;
  }[];
}
```

### Type RemoteDataSourceOptions

```ts
export interface RemoteDataSourceOptions<S> {
  readonly datasetId: string;
  readonly columnKeys: readonly string[];
  readonly maxRows?: number;
  readonly maxPendingCells?: number;
  readonly createAbortController: () => { readonly signal: S; abort(): void };
  /** Unique for the lifetime of the server's idempotency records. */
  readonly createMutationId: () => string;
  readonly load: (signal: S) => Promise<RemoteSnapshot>;
  /** Server must check the revision and apply the complete batch atomically, deduplicated by mutationId. */
  readonly write: (mutation: RemoteMutation, signal: S) => Promise<RemoteWriteResult>;
  /** Complete host-owned durable storage before transport. Retried with the same immutable mutation. */
  readonly persistMutation?: (checkpoint: RemoteMutationCheckpoint) => void | Promise<void>;
}
```

### Type RemoteSnapshot

```ts
export interface RemoteSnapshot {
  readonly datasetId: string;
  readonly revision: string;
  readonly rows: readonly DataRow[];
}
```

### Type RemoteDelta

```ts
export interface RemoteDelta {
  readonly datasetId: string;
  readonly baseRevision: string;
  readonly revision: string;
  /** Canonical values for every submitted cell and any server-side effects; row order is unchanged. */
  readonly cells: readonly { readonly rowId: RowId; readonly columnKey: string; readonly value: unknown }[];
}
```

### Type RemoteChange

```ts
export interface RemoteChange {
  readonly rowId: RowId;
  readonly columnKey: string;
  readonly previous: unknown;
  readonly value: unknown;
}
```

### Type RemoteMutation

```ts
export interface RemoteMutation {
  readonly datasetId: string;
  readonly mutationId: string;
  readonly expectedRevision: string;
  readonly changes: readonly RemoteChange[];
}
```

### Type RemoteMutationCheckpoint

```ts
export interface RemoteMutationCheckpoint {
  readonly version: 1;
  readonly columnKeys: readonly string[];
  readonly snapshot: RemoteSnapshot;
  readonly mutation: RemoteMutation;
}
```

### Type RemoteWriteResult

```ts
export type RemoteWriteResult =
  | { readonly mutationId: string; readonly status: 'accepted' | 'conflict'; readonly snapshot: RemoteSnapshot }
  | { readonly mutationId: string; readonly status: 'accepted'; readonly delta: RemoteDelta }
  | { readonly datasetId: string; readonly mutationId: string; readonly status: 'rejected'; readonly message: string };
```

### Type RemoteStatus

```ts
export type RemoteStatus = 'disconnected' | 'loading' | 'ready' | 'committing' | 'conflict' | 'destroyed';
```

### Type LiveUpdate

```ts
export interface LiveUpdate {
  readonly streamId: string;
  readonly sequence: number;
  readonly changes: readonly { readonly rowId: RowId; readonly columnKey: string; readonly value: unknown }[];
}
```

### Type LiveSnapshot

```ts
export interface LiveSnapshot {
  readonly streamId: string;
  readonly sequence: number;
  readonly rows: readonly DataRow[];
}
```

### Type AsyncDataSourceOptions

```ts
export interface AsyncDataSourceOptions<S> {
  readonly rowCount?: number;
  readonly pageSize?: number;
  readonly maxPages?: number;
  readonly maxConcurrentLoads?: number;
  readonly maxPendingLoads?: number;
  readonly query?: LocalViewOptions;
  readonly createAbortController: () => { readonly signal: S; abort(): void };
  readonly load: (request: {
    readonly offset: number;
    readonly limit: number;
    readonly signal: S;
    readonly query: Readonly<LocalViewOptions>;
  }) => Promise<{ readonly rows: readonly Readonly<Record<string, unknown>>[]; readonly total: number }>;
  /** Stable positional identity within one server query; query changes invalidate identity. */
  readonly getRowId?: (index: number, loadedRow?: Readonly<Record<string, unknown>>) => RowId;
}
```

### Type PageState

```ts
export interface PageState {
  readonly offset: number;
  readonly status: 'loading' | 'ready' | 'error';
  readonly error?: unknown;
}
```

### Type DataSource

```ts
export interface DataSource {
  getRowCount(): number;
  /** Full shallow row snapshot, including fields outside the visible columns. */
  getRow?(index: number): DataRow;
  /** Initialize missing fields atomically; existing hidden column values are retained. */
  addColumns?(keys: readonly string[], defaults?: Readonly<Record<string, unknown>>): void;
  /** Apply sequential splices atomically, preserving unique row IDs. */
  spliceRows?(splices: readonly RowSplice[]): void;
  getRowId(index: number): RowId;
  getValue(index: number, columnKey: string): unknown;
  setValue?(index: number, columnKey: string, value: unknown): void;
  /** Synchronous, atomic: either all writes succeed or none do. */
  setValues?(updates: readonly CellUpdate[]): void;
}
```

### Type CellUpdate

```ts
export interface CellUpdate {
  rowIndex: number;
  columnKey: string;
  value: unknown;
}
```

### Type RowId

```ts
export type RowId = string | number;
```

### Type LocalViewOptions

```ts
export interface LocalViewOptions {
  readonly sort?: { readonly columnKey: string; readonly direction: 'asc' | 'desc' };
  readonly sorts?: readonly { readonly columnKey: string; readonly direction: 'asc' | 'desc' }[];
  readonly filters?: readonly {
    readonly columnKey: string;
    readonly query: string;
    readonly operator?: 'contains' | 'equals' | 'not-empty' | 'empty';
  }[];
}
```

### Type DataRow

```ts
export interface DataRow {
  readonly id: RowId;
  readonly values: Readonly<Record<string, unknown>>;
}
```

### Type RowSplice

```ts
export interface RowSplice {
  readonly index: number;
  readonly deleteCount: number;
  readonly rows: readonly DataRow[];
}
```

### Type Column

```ts
export interface Column {
  defaultValue?: unknown;
  key: string;
  title: string;
  editable?: boolean;
  permissions?: CellPermissionPolicy;
  parse?: (text: string) => unknown;
  validate?: (value: unknown) => string | undefined;
  invalidInput?: 'reject' | 'allow';
}
```

### Type CellSelection

```ts
export interface CellSelection {
  rowIndex: number;
  rowId: RowId;
  columnIndex: number;
  columnKey: string;
}
```

### Type SelectionRange

```ts
export interface SelectionRange {
  startRow: number;
  endRow: number;
  startColumn: number;
  endColumn: number;
}
```

### Type CellLockTarget

```ts
export type CellLockTarget =
  | { readonly scope: 'table' }
  | { readonly scope: 'row'; readonly rowIndex: number }
  | { readonly scope: 'column'; readonly columnIndex: number }
  | { readonly scope: 'cell'; readonly rowIndex: number; readonly columnIndex: number };
```

### Type CellFormatTarget

```ts
export type CellFormatTarget = CellLockTarget | { readonly scope: 'range'; readonly range: Readonly<SelectionRange> };
```

### Type CellFormat

```ts
export interface CellFormat {
  readonly background?: string;
  readonly textColor?: string;
  readonly contentFormat?: 'plain' | 'html' | 'markdown';
  readonly fontWeight?: 'normal' | 'bold';
  readonly fontStyle?: 'normal' | 'italic';
  readonly numberFormat?: NumberFormat;
}
```

### Type CellFormatPatch

```ts
export interface CellFormatPatch {
  readonly background?: string | null;
  readonly textColor?: string | null;
  readonly contentFormat?: 'plain' | 'html' | 'markdown' | null;
  readonly fontWeight?: 'normal' | 'bold' | null;
  readonly fontStyle?: 'normal' | 'italic' | null;
  readonly numberFormat?: NumberFormat | null;
}
```

### Type NumberFormat

```ts
export type NumberFormat = 'decimal' | 'integer' | 'percent' | 'currency';
```

### Type PasteOptions

```ts
export interface PasteOptions {
  readonly mode?: 'all' | 'values' | 'formats';
  readonly transpose?: boolean;
  readonly skipEmpty?: boolean;
}
```

### Type CellPermission

```ts
export interface CellPermission {
  readonly editable: boolean;
  readonly selectable: boolean;
  readonly copyable: boolean;
  readonly pasteable: boolean;
  readonly writable: boolean;
  readonly formatting: boolean;
}
```

### Type CellPermissionPolicy

```ts
export type CellPermissionPolicy = Partial<CellPermission>;
```

### Type CellPermissionResolver

```ts
export type CellPermissionResolver = (cell: Readonly<CellSelection>) => CellPermissionPolicy | undefined;
```

### Type GridEvent

```ts
export type GridEvent =
  | ({ readonly type: 'data:reset' } & DataResetResult)
  | ({ readonly type: 'data:rows' } & RowRefreshResult)
  | {
      readonly type: 'visibility:change';
      readonly axis: 'row' | 'column';
      readonly indices: readonly number[];
      readonly hidden: boolean;
      readonly source: 'api' | 'undo' | 'redo';
    }
  | {
      readonly type: 'data:refresh';
      readonly previousRowCount: number;
      readonly rowCount: number;
      readonly identitiesReconciled: boolean;
    }
  | { readonly type: 'state:restore' }
  | { readonly type: 'merge:change' | 'group:change'; readonly source: 'api' | 'undo' | 'redo' }
  | {
      readonly type: 'view:change';
      readonly view: Readonly<LocalViewOptions>;
      readonly rowCount: number;
      readonly sourceRowCount: number;
    }
  | {
      readonly type: 'structure:change';
      readonly source: 'api' | 'undo' | 'redo';
      readonly request: Readonly<StructureRequest>;
      readonly rowCount: number;
      readonly columnKeys: readonly string[];
    }
  | {
      readonly type: 'cell:change';
      readonly source: GridChangeSource;
      readonly changes: readonly Readonly<CellUpdate & { rowId: RowId; previous: unknown }>[];
    }
  | {
      readonly type: 'selection:change';
      readonly selection: Readonly<CellSelection> | null;
      readonly range: Readonly<SelectionRange> | null;
      readonly ranges: readonly Readonly<SelectionRange>[];
    }
  | {
      readonly type: 'format:change';
      readonly source: 'api' | 'paste' | 'undo' | 'redo';
      readonly changes: readonly {
        readonly target: Readonly<CellFormatTarget>;
        readonly previous: Readonly<CellFormatPatch> | null;
        readonly value: Readonly<CellFormatPatch> | null;
      }[];
    }
  | { readonly type: 'lock:change'; readonly target: Readonly<CellLockTarget>; readonly locked: boolean }
  | {
      readonly type: 'freeze:change';
      readonly previousRows: number;
      readonly previousColumns: number;
      readonly rows: number;
      readonly columns: number;
    }
  | {
      readonly type: 'column:resize' | 'row:resize';
      readonly index: number;
      readonly previous: number;
      readonly size: number;
    };
```

### Type GridChangeSource

```ts
export type GridChangeSource = 'api' | 'edit' | 'paste' | 'undo' | 'redo';
```

### Type RowRefreshResult

```ts
export interface RowRefreshResult {
  readonly startRow: number;
  readonly endRow: number;
  readonly droppedHistoryEntries: number;
  readonly selectionCleared: boolean;
  readonly cutCancelled: boolean;
}
```

### Type DataResetResult

```ts
export interface DataResetResult {
  readonly previousRowCount: number;
  readonly rowCount: number;
  readonly droppedHistoryEntries: number;
  readonly selectionCleared: boolean;
  readonly cutCancelled: boolean;
}
```

### Type ViewportOptions

```ts
export interface ViewportOptions {
  width: number;
  height: number;
  scrollLeft: number;
  scrollTop: number;
}
```

### Type ViewportLayout

```ts
export type ViewportLayout = ReturnType<typeof createViewport>;
```

### Type ViewportRegion

```ts
export interface ViewportRegion {
  readonly clip: ViewportRect;
  readonly rows: Readonly<{ start: number; end: number }>;
  readonly columns: Readonly<{ start: number; end: number }>;
  readonly offsetX: number;
  readonly offsetY: number;
}
```

### Type ViewportRect

```ts
export interface ViewportRect {
  readonly x: number;
  readonly y: number;
  readonly width: number;
  readonly height: number;
}
```

### Type StructureRequest

```ts
export interface StructureRequest {
  readonly columns?: readonly Column[];
  readonly order?: readonly number[];
  readonly axis: 'row' | 'column';
  readonly kind: 'insert' | 'delete' | 'move';
  readonly indices: readonly number[];
  readonly beforeIndex: number;
  readonly count: number;
}
```

### Type ClipboardBlock

```ts
export interface ClipboardBlock {
  readonly row: number;
  readonly column: number;
  readonly values: readonly (readonly string[])[];
  readonly formats?: readonly (readonly CellFormat[])[];
}
```

### Type RowGroup

```ts
export interface RowGroup {
  readonly id: string;
  readonly startRow: number;
  readonly endRow: number;
  readonly collapsed: boolean;
}
```

### Type LayoutRequest

```ts
export type LayoutRequest =
  | { readonly kind: 'merge' | 'unmerge'; readonly range: Readonly<SelectionRange> }
  | { readonly kind: 'group' | 'ungroup' | 'collapse' | 'expand'; readonly group: Readonly<RowGroup> };
```

### Type GridConfiguration

```ts
export interface GridConfiguration {
  readonly version: 1;
  readonly columns: readonly { readonly key: string; readonly width: number }[];
  readonly frozenRows: number;
  readonly frozenColumns: number;
  readonly view: LocalViewOptions;
}
```

### Type GridState

```ts
export interface GridState {
  readonly version: 1;
  readonly configuration: GridConfiguration;
  readonly rowIds: readonly RowId[];
  readonly rowHeights: readonly (readonly [number, number])[];
  readonly manualRows: readonly number[];
  readonly hiddenRows?: readonly number[];
  readonly hiddenColumns?: readonly number[];
  readonly ranges: readonly SelectionRange[];
  readonly selection: Readonly<CellSelection> | null;
  readonly anchor: Readonly<CellSelection> | null;
  readonly activeParts?: number;
  readonly displayAnchor?: Readonly<{ row: number; col: number }> | null;
  readonly merges: readonly SelectionRange[];
  readonly groups: readonly RowGroup[];
  readonly locks: readonly CellLockTarget[];
  readonly formats: readonly { readonly target: CellFormatTarget; readonly patch: CellFormatPatch }[];
}
```
