@pretable/core
v0.10.0
Published
Framework-agnostic grid state primitives for Pretable.
Readme
@pretable/core
The framework-independent indexed row model and UI-state grid for pretable.
When to reach for this
Most users want @pretable/react instead. It bundles @pretable/core with a React surface that handles rendering, layout, and keyboard interaction.
@pretable/core is for users building their own renderer, or for producers that need explicit row-model ownership. createLocalRowModel owns rows and query state. createGrid optionally layers focus, selection, editing, viewport, and visual column state over that model.
Install
npm install @pretable/core
# or pnpm add @pretable/core, yarn add @pretable/coreMinimal example
import {
createColumnHelper,
createGrid,
createLocalRowModel,
} from "@pretable/core";
type Person = { id: string; name: string; age: number };
const column = createColumnHelper<Person>();
const columns = [
column.accessor("name", { type: "text", header: "Name" }),
column.accessor("age", { type: "number", header: "Age" }),
] as const;
const rowModel = createLocalRowModel({
columns,
rows: [
{ id: "1", name: "Ada", age: 36 },
{ id: "2", name: "Grace", age: 85 },
],
});
rowModel.subscribe(() => {
const snapshot = rowModel.getState().snapshot;
console.log(snapshot.range(0, Math.min(snapshot.visibleRowCount, 100)));
});
const grid = createGrid({ rowModel, columns });
grid.setFocus({ ref: { kind: "data", rowId: "1" }, columnId: "name" });
rowModel.applyTransaction({
update: [{ id: "1", changes: { age: 37 } }],
});Full public surface
See core.api.md for every exported type, interface, and function with their full signatures. The file is generated by API Extractor and committed to the repo; CI fails if it drifts.
License
MIT — see LICENSE.
