@pretable/core 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # @pretable/core
2
2
 
3
- The headless engine for [pretable](https://pretable.dev/). Drives sort, filter, selection, focus, viewport, and streaming-transaction state for any table-shaped UI.
3
+ The framework-independent indexed row model and UI-state grid for [pretable](https://pretable.dev/).
4
4
 
5
5
  ## When to reach for this
6
6
 
7
7
  Most users want **[`@pretable/react`](../react)** instead. It bundles `@pretable/core` with a React surface that handles rendering, layout, and keyboard interaction.
8
8
 
9
- `@pretable/core` is for users building their own UI from scratch — for example, plain DOM, a non-React framework, or a custom canvas/webgl renderer. Headless usage is supported (the `createGrid` factory returns a fully-typed `PretableGrid` handle), but **dedicated docs, examples, and demos for headless mode are forthcoming**. If headless is what you're after, the type definitions and [`core.api.md`](./core.api.md) are the source of truth today.
9
+ `@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.
10
10
 
11
11
  ## Install
12
12
 
@@ -18,25 +18,38 @@ npm install @pretable/core
18
18
  ## Minimal example
19
19
 
20
20
  ```ts
21
- import { createGrid } from "@pretable/core";
22
-
23
- const grid = createGrid({
24
- columns: [
25
- { id: "name", header: "Name" },
26
- { id: "age", header: "Age", sortable: true },
27
- ],
21
+ import {
22
+ createColumnHelper,
23
+ createGrid,
24
+ createLocalRowModel,
25
+ } from "@pretable/core";
26
+
27
+ type Person = { id: string; name: string; age: number };
28
+ const column = createColumnHelper<Person>();
29
+ const columns = [
30
+ column.accessor("name", { type: "text", header: "Name" }),
31
+ column.accessor("age", { type: "number", header: "Age" }),
32
+ ] as const;
33
+
34
+ const rowModel = createLocalRowModel({
35
+ columns,
28
36
  rows: [
29
37
  { id: "1", name: "Ada", age: 36 },
30
38
  { id: "2", name: "Grace", age: 85 },
31
39
  ],
32
40
  });
33
41
 
34
- grid.subscribe(() => {
35
- const { visibleRows, sort } = grid.getSnapshot();
36
- console.log("rows:", visibleRows.length, "sort:", sort);
42
+ rowModel.subscribe(() => {
43
+ const snapshot = rowModel.getState().snapshot;
44
+ console.log(snapshot.range(0, Math.min(snapshot.visibleRowCount, 100)));
37
45
  });
38
46
 
39
- grid.setSort("age", "desc");
47
+ const grid = createGrid({ rowModel, columns });
48
+ grid.setFocus({ ref: { kind: "data", rowId: "1" }, columnId: "name" });
49
+
50
+ rowModel.applyTransaction({
51
+ update: [{ id: "1", changes: { age: 37 } }],
52
+ });
40
53
  ```
41
54
 
42
55
  ## Full public surface