@pretable/core 0.3.2 → 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 +26 -13
- package/dist/index.cjs +8160 -1842
- package/dist/index.d.cts +890 -464
- package/dist/index.d.ts +890 -464
- package/dist/index.mjs +8151 -1843
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @pretable/core
|
|
2
2
|
|
|
3
|
-
The
|
|
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
|
|
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 {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
35
|
-
const
|
|
36
|
-
console.log(
|
|
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
|
|
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
|