next-data-kit 10.0.0 → 12.0.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/MIGRATION.md CHANGED
@@ -1,8 +1,98 @@
1
- # Migrating from 9.x to 10.0
1
+ # Migrating
2
+
3
+ ## Migrating from 11.x to 12.0
4
+
5
+ 12.0 drops TanStack Table, adds a ready UI that needs no shadcn (`next-data-kit/ui` + `next-data-kit/style.css`), names every export `dataKit…`, nests each column's filter options under `filter`, and sets a table's URL prefix once on the server.
6
+
7
+ ### Steps
8
+
9
+ 1. `npm install next-data-kit@12`, and remove `@tanstack/react-table` if only next-data-kit used it.
10
+ 2. Choose a UI.
11
+ - **shadcn:** set the registry to `https://unpkg.com/next-data-kit@12/registry/r/{name}.json` and run `npx shadcn add @ndk/data-kit`, overwriting only `components/ui/ndk/data-kit/`. Delete 11's `data-kit.tsx`, `hook.tsx`, `view.tsx`, `labels.tsx` and `toolbar.tsx` there: they still import TanStack. Import `DataKit` from `@/components/ui/ndk/data-kit`.
12
+ - **No shadcn:** import `DataKit` from `next-data-kit/ui` and the stylesheet once (with Tailwind: `@import 'next-data-kit/style.css' layer(components);`).
13
+ 3. Rename the server imports: `sourceX` → `dataKitSourceX`, `filterCustom` → `dataKitFilterCustom`, `urlEncode` / `urlDecode` → `dataKitUrlEncode` / `dataKitUrlDecode`.
14
+ 4. Nest each column's filter:
15
+
16
+ ```ts
17
+ // 11
18
+ role: { filter: 'multiSelect', option: ['admin', 'user'] },
19
+ createdAt: { filter: 'dateRange', preset: ['7d'], sort: true },
20
+ team: { field: 'teamId', filter: 'select', hidden: true },
21
+ // 12
22
+ role: { filter: { variant: 'multiSelect', option: ['admin', 'user'] } },
23
+ createdAt: { sort: true, filter: { variant: 'dateRange', preset: ['7d'] } },
24
+ team: { field: 'teamId', filter: { variant: 'select', hidden: true } },
25
+ ```
26
+
27
+ `filterCustom(…)` stays where it was, renamed: `user: { filter: dataKitFilterCustom({ schema, query }) }`. Column keys can't contain `.` any more.
28
+ 5. Several tables on one page: `query({ searchParams, key: 'user' })` → `query({ searchParams, prefix: 'user' })`, and drop `dataKey` from the views (the prefix comes back in the data). A prefix uses `a-z`, `0-9` and `-`.
29
+ 6. Rewrite the columns:
30
+
31
+ ```tsx
32
+ // 11
33
+ const columns: ColumnDef<TDataKitRow<typeof tableUser>>[] = [
34
+ { accessorKey: 'name', header: 'Name', meta: { className: 'font-medium' } },
35
+ { accessorKey: 'role', header: 'Role', cell: ({ row }) => <Badge>{row.original.role}</Badge>, meta: { option: { admin: 'Admin' } } },
36
+ { id: 'status', header: 'Status', meta: { option: { online: 'Online' } } },
37
+ ];
38
+ <DataKit data={data} columns={columns} hidden={['status']} selectable={(user) => user.id !== me} actions={(selection) => …} sizes={[10, 25]} controls={chip} />
39
+ // 12
40
+ <DataKit
41
+ data={data}
42
+ columns={[
43
+ { id: 'name', header: 'Name', className: 'font-medium' },
44
+ { id: 'role', header: 'Role', cell: ({ row }) => <Badge>{row.role}</Badge>, filter: { option: { admin: 'Admin' } } },
45
+ { id: 'status', table: false, filter: { label: 'Status', option: { online: 'Online' } } },
46
+ ]}
47
+ selection={{ enabled: ({ row }) => row.id !== me, action: (selection) => … }}
48
+ pagination={{ size: [10, 25] }}
49
+ toolbar={{ control: chip }}
50
+ />
51
+ ```
52
+
53
+ Columns are typed from `data`, so the `ColumnDef<…>` annotation goes. A column whose `cell` read a computed value (`accessorFn`) only needs its `id` and `cell`.
54
+ 7. Your own layouts: `useDataKitTable` now comes from `next-data-kit/ui` and returns plain data: `table.row` (`item.row` is the row) replaces `table.getRowModel().rows` (`row.original`), `table.kit` replaces `table.options.meta.dataKit`, and `columns` is optional. `DataKitTableView` is now `DataKitTable`. Remove `'use no memo'` from your own components.
55
+ 8. `kit.set.page(n)` → `kit.set.page.number(n)` and `kit.set.size(n)` → `kit.set.page.size(n)`.
56
+ 9. Labels: import `DataKitLabelsProvider` from `next-data-kit/ui`. `filter.all` and `date.pick` are gone; `filter.find`, `date.from`, `date.to`, `date.format` and `pagination.label` are new.
57
+ 10. Types: `TDataKitRow` / `TDataKitDataOf` → `TDataKitTableRow` / `TDataKitTableData` (also exported from `next-data-kit`). `data.meta.column[key]` is now `{ sort, filter?: { variant, option?, preset?, hidden } }`.
58
+
59
+ URLs don't change.
60
+
61
+ ## Migrating from 10.x to 11.0
62
+
63
+ 11.0 declares a table as columns instead of per-filter zod/query pairs, plugs in any data source, and renders it with one `DataKit` component on TanStack Table 8.
64
+
65
+ ### Steps
66
+
67
+ 1. `npm install next-data-kit@11` (needs zod 4, React 19).
68
+ 2. Refresh the components: `npx shadcn add @ndk/data-kit`, overwriting only `components/ui/ndk/data-kit/`. Delete the old `root.tsx`, `table.tsx`, `filter.tsx` and `selection.tsx` there.
69
+ 3. Rewrite each `dataKitDefine` as a `dataKit`:
70
+ - `adapter: adapterMongoose({ model })` → `source: sourceMongoose({ model })`; a custom adapter function → `sourceDefine({ ...sourceMongooseQuery, list })` or `{ list }`, which gets `{ filter, sort, page: { offset, limit, count } }` and returns `{ rows, total }`.
71
+ - Each `filter: { key: { schema, query } }` → `column: { key: { filter: variant, option? } }`. Keep `query` on the column only when the variant's own condition isn't the one you need; use `filterCustom({ schema, query })` for a filter with no toolbar control.
72
+ - `filterSearch({ field })` → `search: [...]` (add columns for those fields, with `field` when the database path differs).
73
+ - `sort: { field, default }` → `sort: true` on each sortable column, and `sort: 'field.desc'` at the top.
74
+ - `page.size` and `scope` stay; `item: (props) => …props.document…` → `row: (props) => …props.row…`.
75
+ 4. In pages, `kit.query({ input: kit.parse({ searchParams }) })` → `table.query({ searchParams })`. Server actions keep `{ input }`; validate with `table.schema`.
76
+ 5. In views, replace `DataKitRoot` + parts with `<DataKit data={data} columns={…} />`. Columns become TanStack `ColumnDef`s (`head` → `header`, `cell: ({ item })` → `cell: ({ row }) => row.original…`, `className` → `meta: { className }`), and the column `id` / `accessorKey` must match the server column key for sorting and filter labels. `DataKitSelection` → `actions`; per-part labels → one `DataKitLabelsProvider`.
77
+ 6. URLs change: filter values are variant-encoded (`role=a,b`, `age=18-30`, `createdAt=7d`) and sort is `column.direction`. Old links fall back to the defaults.
78
+
79
+ ### Renames
80
+
81
+ | 10.x | 11.0 |
82
+ |---|---|
83
+ | `dataKitDefine` | `dataKit` |
84
+ | `adapterMongoose`, `adapterMemory` | `sourceMongoose`, `sourceMemory` |
85
+ | `filterSearch` | `search` option |
86
+ | `kit.parse` | removed (`query({ searchParams })`) |
87
+ | `items`, `item()` | `rows`, `row()` |
88
+ | `TDataKitResult` | `TDataKitData` (+ `TDataKitRow`, `TDataKitDataOf`) |
89
+ | `DataKitRoot`, `DataKitTable`, `DataKitFilter`, `DataKitSelection`, `useDataKitRoot` | `DataKit`, `useDataKitTable`, `DataKitToolbar`, `DataKitTableView`, `DataKitPagination`, `DataKitInfinite`, `DataKitLabelsProvider` |
90
+
91
+ ## Migrating from 9.x to 10.0
2
92
 
3
93
  10.0 is a rewrite. Tables are declared once on the server with only the filters and sorts you allow; the UI moves into your project as a shadcn registry item; the package ships no CSS and no Radix.
4
94
 
5
- ## What changes
95
+ ### What changes
6
96
 
7
97
  | 9.x | 10.0 |
8
98
  |---|---|
@@ -33,7 +123,7 @@
33
123
  | peers: Radix, `cva`, `lucide-react`, zod 3 | peers: `react` 19, `react-dom` 19, `zod` 4, optional `mongoose` |
34
124
  | CommonJS build | ESM only |
35
125
 
36
- ## Steps
126
+ ### Steps
37
127
 
38
128
  1. `npm install next-data-kit@10` and remove `@radix-ui/*`, `class-variance-authority` and `react-intersection-observer` if only next-data-kit used them.
39
129
  2. Add `"@ndk": "https://unpkg.com/next-data-kit@10/registry/r/{name}.json"` to `registries` in `components.json`, then `npx shadcn add @ndk/data-kit`.