next-data-kit 10.0.0 → 11.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 +35 -3
- package/README.md +360 -94
- package/dist/chunk-5D747NEB.js +12 -0
- package/dist/chunk-5D747NEB.js.map +1 -0
- package/dist/index.d.ts +53 -22
- package/dist/index.js +44 -33
- package/dist/index.js.map +1 -1
- package/dist/server/drizzle.d.ts +11 -0
- package/dist/server/drizzle.js +39 -0
- package/dist/server/drizzle.js.map +1 -0
- package/dist/server.d.ts +227 -74
- package/dist/server.js +247 -71
- package/dist/server.js.map +1 -1
- package/dist/source--l-z9HHB.d.ts +60 -0
- package/package.json +31 -9
- package/registry/r/data-kit.json +35 -19
- package/registry/r/registry.json +58 -9
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-data-kit",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
|
+
"description": "Server-driven data tables for React: one server definition, one component. Declarative filters, pluggable sources (Mongoose, Prisma, Drizzle, REST, your own) and a TanStack Table + shadcn UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
"./server": {
|
|
12
12
|
"types": "./dist/server.d.ts",
|
|
13
13
|
"default": "./dist/server.js"
|
|
14
|
+
},
|
|
15
|
+
"./server/drizzle": {
|
|
16
|
+
"types": "./dist/server/drizzle.d.ts",
|
|
17
|
+
"default": "./dist/server/drizzle.js"
|
|
14
18
|
}
|
|
15
19
|
},
|
|
16
20
|
"files": [
|
|
@@ -38,17 +42,21 @@
|
|
|
38
42
|
"url": "git+https://github.com/muhgholy/next-data-kit.git"
|
|
39
43
|
},
|
|
40
44
|
"keywords": [
|
|
41
|
-
"
|
|
45
|
+
"data-provider",
|
|
42
46
|
"data-table",
|
|
43
|
-
"
|
|
47
|
+
"drizzle",
|
|
44
48
|
"filtering",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
49
|
+
"mongodb",
|
|
50
|
+
"mongoose",
|
|
47
51
|
"nextjs",
|
|
52
|
+
"pagination",
|
|
53
|
+
"prisma",
|
|
54
|
+
"react",
|
|
48
55
|
"server-components",
|
|
49
56
|
"shadcn",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
57
|
+
"sorting",
|
|
58
|
+
"table",
|
|
59
|
+
"tanstack-table"
|
|
52
60
|
],
|
|
53
61
|
"author": "muhgholy",
|
|
54
62
|
"license": "MIT",
|
|
@@ -57,26 +65,33 @@
|
|
|
57
65
|
},
|
|
58
66
|
"homepage": "https://github.com/muhgholy/next-data-kit#readme",
|
|
59
67
|
"peerDependencies": {
|
|
68
|
+
"drizzle-orm": ">=0.36.0 <1.0.0",
|
|
60
69
|
"mongoose": ">=8.0.0 <10.0.0",
|
|
61
70
|
"react": "^19.0.0",
|
|
62
71
|
"react-dom": "^19.0.0",
|
|
63
72
|
"zod": "^4.0.0"
|
|
64
73
|
},
|
|
65
74
|
"peerDependenciesMeta": {
|
|
75
|
+
"drizzle-orm": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
66
78
|
"mongoose": {
|
|
67
79
|
"optional": true
|
|
68
80
|
}
|
|
69
81
|
},
|
|
70
82
|
"devDependencies": {
|
|
71
83
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
84
|
+
"@electric-sql/pglite": "^0.6.0",
|
|
72
85
|
"@eslint/js": "^9.39.2",
|
|
73
86
|
"@semantic-release/changelog": "^6.0.3",
|
|
74
87
|
"@semantic-release/exec": "^7.1.0",
|
|
75
88
|
"@semantic-release/git": "^10.0.1",
|
|
76
89
|
"@size-limit/preset-small-lib": "^14.3.0",
|
|
90
|
+
"@tanstack/react-table": "^8.21.3",
|
|
77
91
|
"@types/node": "^22.10.2",
|
|
78
92
|
"@types/react": "^19.0.1",
|
|
79
93
|
"@vitest/coverage-v8": "^3.2.4",
|
|
94
|
+
"drizzle-orm": "^0.45.4",
|
|
80
95
|
"eslint": "^9.17.0",
|
|
81
96
|
"mongoose": "^9.0.2",
|
|
82
97
|
"publint": "^0.3.25",
|
|
@@ -96,10 +111,17 @@
|
|
|
96
111
|
},
|
|
97
112
|
{
|
|
98
113
|
"path": "dist/server.js",
|
|
99
|
-
"limit": "
|
|
114
|
+
"limit": "6 kB",
|
|
100
115
|
"ignore": [
|
|
101
116
|
"zod"
|
|
102
117
|
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"path": "dist/server/drizzle.js",
|
|
121
|
+
"limit": "3 kB",
|
|
122
|
+
"ignore": [
|
|
123
|
+
"drizzle-orm"
|
|
124
|
+
]
|
|
103
125
|
}
|
|
104
126
|
],
|
|
105
127
|
"publishConfig": {
|
package/registry/r/data-kit.json
CHANGED
|
@@ -2,54 +2,70 @@
|
|
|
2
2
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
3
|
"name": "data-kit",
|
|
4
4
|
"title": "Data Kit",
|
|
5
|
-
"description": "Table
|
|
5
|
+
"description": "A server-driven data table on TanStack Table: auto-built filters, sortable headers, selection, pagination and infinite scroll, using your own shadcn components.",
|
|
6
6
|
"dependencies": [
|
|
7
|
-
"next-data-kit@^
|
|
7
|
+
"next-data-kit@^11.0.0",
|
|
8
|
+
"@tanstack/react-table@^8.21.0",
|
|
8
9
|
"lucide-react"
|
|
9
10
|
],
|
|
10
11
|
"registryDependencies": [
|
|
12
|
+
"badge",
|
|
11
13
|
"button",
|
|
14
|
+
"calendar",
|
|
12
15
|
"checkbox",
|
|
16
|
+
"command",
|
|
13
17
|
"input",
|
|
14
|
-
"label",
|
|
15
18
|
"pagination",
|
|
19
|
+
"popover",
|
|
16
20
|
"select",
|
|
17
21
|
"table"
|
|
18
22
|
],
|
|
19
23
|
"files": [
|
|
20
24
|
{
|
|
21
|
-
"path": "registry/data-kit/
|
|
22
|
-
"content": "'use client';\n\nimport {
|
|
25
|
+
"path": "registry/data-kit/data-kit.tsx",
|
|
26
|
+
"content": "'use client';\n// ** TanStack Table keeps one mutable table object, so React Compiler would skip re-renders: opt this file out\n'use no memo';\n\nimport type { ReactNode } from 'react';\nimport type { ColumnDef } from '@tanstack/react-table';\nimport type { TDataKitData } from 'next-data-kit';\nimport { DataKitActionBar } from '@/components/ui/ndk/data-kit/action-bar';\nimport { useDataKitTable } from '@/components/ui/ndk/data-kit/hook';\nimport { DataKitLabelsProvider, type TDataKitLabelsPartial } from '@/components/ui/ndk/data-kit/labels';\nimport { DataKitPagination } from '@/components/ui/ndk/data-kit/pagination';\nimport { DataKitToolbar } from '@/components/ui/ndk/data-kit/toolbar';\nimport { DataKitTableView } from '@/components/ui/ndk/data-kit/view';\n\n// ** The whole table in one component: toolbar from the server's columns, sortable table, bulk-action bar, pagination\n// ** For your own layout, use useDataKitTable with DataKitToolbar / DataKitTableView / DataKitPagination / DataKitInfinite\nexport const DataKit = <TRow extends { id: string }>(\n\tprops: Readonly<{\n\t\tdata: TDataKitData<TRow>;\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tcolumns: ColumnDef<TRow, any>[];\n\t\tsource?: Parameters<typeof useDataKitTable<TRow>>[0]['source'];\n\t\tdataKey?: string;\n\t\trefetch?: { intervalMs: number };\n\t\tselectable?: boolean | ((row: TRow) => boolean);\n\t\t// ** Column ids kept out of the table (filter-only columns that just name a filter)\n\t\thidden?: string[];\n\t\t// ** Bulk actions for the selected rows, in a bar that floats at the bottom while any are selected\n\t\tactions?: (props: Readonly<{ rows: TRow[]; clear: () => void }>) => ReactNode;\n\t\trow?: { onClick?: (props: Readonly<{ row: TRow }>) => void };\n\t\ttoolbar?: boolean;\n\t\t// ** Your own controls at the end of the toolbar (a chip, an export button); falsy renders nothing\n\t\tcontrols?: ReactNode;\n\t\tpagination?: boolean;\n\t\tsizes?: number[];\n\t\tlabels?: TDataKitLabelsPartial;\n\t\tclassName?: string;\n\t}>,\n) => {\n\t// ** Deconstruct Props\n\tconst { data, columns, source, dataKey, refetch, selectable, hidden, actions, row, toolbar = true, controls, pagination = true, sizes, labels, className } = props;\n\n\tconst table = useDataKitTable({ data, columns, source, dataKey, refetch, hidden, selectable: selectable ?? Boolean(actions) });\n\tconst kit = table.options.meta!.dataKit!;\n\tconst selected = table.getSelectedRowModel().rows.map((item) => item.original);\n\n\tconst body = (\n\t\t<div data-slot=\"data-kit\" className={className ?? 'flex flex-col gap-3'}>\n\t\t\t{toolbar && <DataKitToolbar table={table}>{controls}</DataKitToolbar>}\n\t\t\t<DataKitTableView table={table} row={row} />\n\t\t\t{pagination && <DataKitPagination table={table} sizes={sizes} />}\n\t\t\t{actions && <DataKitActionBar table={table}>{actions({ rows: selected, clear: kit.selection.clear })}</DataKitActionBar>}\n\t\t</div>\n\t);\n\n\treturn labels ? <DataKitLabelsProvider labels={labels}>{body}</DataKitLabelsProvider> : body;\n};\n",
|
|
23
27
|
"type": "registry:ui",
|
|
24
|
-
"target": "@ui/ndk/data-kit/
|
|
28
|
+
"target": "@ui/ndk/data-kit/data-kit.tsx"
|
|
25
29
|
},
|
|
26
30
|
{
|
|
27
|
-
"path": "registry/data-kit/
|
|
28
|
-
"content": "'use client';\n
|
|
31
|
+
"path": "registry/data-kit/action-bar.tsx",
|
|
32
|
+
"content": "'use client';\n// ** TanStack Table keeps one mutable table object, so React Compiler would skip re-renders: opt this file out\n'use no memo';\n\nimport { useEffect, useState, type ReactNode } from 'react';\nimport { createPortal } from 'react-dom';\nimport type { Table } from '@tanstack/react-table';\nimport { XIcon } from 'lucide-react';\nimport { Button } from '@/components/ui/button';\nimport { useDataKitLabels } from '@/components/ui/ndk/data-kit/labels';\n\n// ** Floats at the bottom of the screen while rows are selected, so actions stay in reach however far you scroll\n// ** A labelled toolbar in a portal (no parent overflow or z-index can clip it); the count is announced politely; Escape clears\nexport const DataKitActionBar = <TRow,>(props: Readonly<{ table: Table<TRow>; children: ReactNode }>) => {\n\t// ** Deconstruct Props\n\tconst { table, children } = props;\n\n\tconst kit = table.options.meta!.dataKit!;\n\tconst labels = useDataKitLabels();\n\tconst count = kit.selection.ids.length;\n\t// ** The portal needs document, so it only renders after mount (selection only exists in the browser anyway)\n\tconst [mounted, setMounted] = useState(false);\n\tuseEffect(() => setMounted(true), []);\n\n\tuseEffect(() => {\n\t\tif (!count) return;\n\t\tconst listener = (event: KeyboardEvent) => event.key === 'Escape' && kit.selection.clear();\n\t\twindow.addEventListener('keydown', listener);\n\t\treturn () => window.removeEventListener('keydown', listener);\n\t});\n\n\tif (!mounted || !count) return null;\n\n\treturn createPortal(\n\t\t<div\n\t\t\trole=\"toolbar\"\n\t\t\taria-label={labels.selection.label}\n\t\t\tdata-slot=\"data-kit-action-bar\"\n\t\t\tclassName=\"fixed inset-x-0 bottom-6 z-50 mx-auto flex w-fit max-w-[calc(100vw-2rem)] flex-wrap items-center gap-2 rounded-xl border bg-background p-1.5 shadow-lg ring-1 ring-foreground/5 animate-in fade-in-0 slide-in-from-bottom-4\"\n\t\t>\n\t\t\t<div className=\"flex h-8 items-center gap-1 rounded-lg border border-dashed pr-1 pl-3 text-sm\">\n\t\t\t\t<span aria-live=\"polite\" className=\"font-medium tabular-nums whitespace-nowrap\">\n\t\t\t\t\t{labels.selection.selected(count)}\n\t\t\t\t</span>\n\t\t\t\t<Button variant=\"ghost\" size=\"icon-sm\" aria-label={labels.selection.clear} onClick={kit.selection.clear}>\n\t\t\t\t\t<XIcon />\n\t\t\t\t</Button>\n\t\t\t</div>\n\t\t\t<div aria-hidden className=\"h-5 w-px bg-border\" />\n\t\t\t<div className=\"flex flex-wrap items-center gap-1.5\">{children}</div>\n\t\t</div>,\n\t\tdocument.body,\n\t);\n};\n",
|
|
29
33
|
"type": "registry:ui",
|
|
30
|
-
"target": "@ui/ndk/data-kit/
|
|
34
|
+
"target": "@ui/ndk/data-kit/action-bar.tsx"
|
|
31
35
|
},
|
|
32
36
|
{
|
|
33
|
-
"path": "registry/data-kit/
|
|
34
|
-
"content": "'use client';\n
|
|
37
|
+
"path": "registry/data-kit/hook.tsx",
|
|
38
|
+
"content": "'use client';\n// ** TanStack Table keeps one mutable table object, so React Compiler would skip re-renders: opt this file out\n'use no memo';\n\nimport { getCoreRowModel, useReactTable, type ColumnDef, type RowData } from '@tanstack/react-table';\nimport { useRouter } from 'next/navigation';\nimport { useDataKit, type TDataKitData } from 'next-data-kit';\n\ndeclare module '@tanstack/react-table' {\n\t// ** The data kit rides on the TanStack table, so every part only needs `table`\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tinterface TableMeta<TData extends RowData> {\n\t\tdataKit?: ReturnType<typeof useDataKit<{ id: string }>>;\n\t}\n\t// ** label: the toolbar's name for this column's filter · option: labels for its select values · className: on the column's header and cells\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tinterface ColumnMeta<TData extends RowData, TValue> {\n\t\tlabel?: string;\n\t\toption?: Record<string, string>;\n\t\tclassName?: string;\n\t}\n}\n\n// ** A TanStack table driven by the server: sorting, paging and selection write the URL (router.push), and the page renders the next `data`\n// ** Pass `source={{ fetch }}` (your authed action) for infinite scroll or client-only fetching\nexport const useDataKitTable = <TRow extends { id: string }>(\n\tprops: Readonly<{\n\t\tdata: TDataKitData<TRow>;\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tcolumns: ColumnDef<TRow, any>[];\n\t\tsource?: Parameters<typeof useDataKit<TRow>>[0]['source'];\n\t\tdataKey?: string;\n\t\tappend?: boolean;\n\t\trefetch?: { intervalMs: number };\n\t\t// ** true, or a rule per row (e.g. \"not yourself\")\n\t\tselectable?: boolean | ((row: TRow) => boolean);\n\t\t// ** Column ids kept out of the table, e.g. a column that only names a filter (its label and option labels)\n\t\thidden?: string[];\n\t}>,\n) => {\n\t// ** Deconstruct Props\n\tconst { data, columns, source, dataKey, append, refetch, selectable, hidden } = props;\n\n\tconst router = useRouter();\n\tconst kit = useDataKit({ data, source: source ?? { navigate: (url) => router.push(url, { scroll: false }), refresh: () => router.refresh() }, key: dataKey, append, refetch });\n\n\treturn useReactTable({\n\t\tdata: kit.rows,\n\t\t// ** A column sorts only when the server allows it; its id is the server's column key (accessorKey by default)\n\t\tcolumns: columns.map((column) => {\n\t\t\tconst id = column.id ?? ('accessorKey' in column ? String(column.accessorKey) : undefined);\n\t\t\treturn { ...column, enableSorting: Boolean(id && kit.meta.column[id]?.sort) };\n\t\t}),\n\t\tgetCoreRowModel: getCoreRowModel(),\n\t\tgetRowId: (row) => row.id,\n\t\tmanualPagination: true,\n\t\tmanualSorting: true,\n\t\tmanualFiltering: true,\n\t\tenableMultiSort: false,\n\t\tpageCount: kit.page.count ?? -1,\n\t\tinitialState: { columnVisibility: Object.fromEntries((hidden ?? []).map((id) => [id, false])) },\n\t\tenableRowSelection: typeof selectable === 'function' ? (row) => selectable(row.original) : Boolean(selectable),\n\t\tstate: {\n\t\t\tsorting: kit.sort.map((sort) => ({ id: sort.column, desc: sort.direction === 'desc' })),\n\t\t\tpagination: { pageIndex: kit.page.number - 1, pageSize: kit.page.size },\n\t\t\trowSelection: Object.fromEntries(kit.selection.ids.map((id) => [id, true])),\n\t\t},\n\t\tonSortingChange: (updater) => {\n\t\t\tconst next = typeof updater === 'function' ? updater(kit.sort.map((sort) => ({ id: sort.column, desc: sort.direction === 'desc' }))) : updater;\n\t\t\tkit.set.sort(next.map((sort) => ({ column: sort.id, direction: sort.desc ? 'desc' : 'asc' })));\n\t\t},\n\t\tonPaginationChange: (updater) => {\n\t\t\tconst next = typeof updater === 'function' ? updater({ pageIndex: kit.page.number - 1, pageSize: kit.page.size }) : updater;\n\t\t\tif (next.pageSize !== kit.page.size) kit.set.size(next.pageSize);\n\t\t\telse kit.set.page(next.pageIndex + 1);\n\t\t},\n\t\t// ** Functional, so quick clicks in a row each build on the last one instead of a stale render\n\t\tonRowSelectionChange: (updater) =>\n\t\t\tkit.selection.set((ids) => {\n\t\t\t\tconst next = typeof updater === 'function' ? updater(Object.fromEntries(ids.map((id) => [id, true]))) : updater;\n\t\t\t\treturn Object.keys(next).filter((id) => next[id]);\n\t\t\t}),\n\t\tmeta: { dataKit: kit as unknown as ReturnType<typeof useDataKit<{ id: string }>> },\n\t});\n};\n",
|
|
35
39
|
"type": "registry:ui",
|
|
36
|
-
"target": "@ui/ndk/data-kit/
|
|
40
|
+
"target": "@ui/ndk/data-kit/hook.tsx"
|
|
37
41
|
},
|
|
38
42
|
{
|
|
39
|
-
"path": "registry/data-kit/
|
|
40
|
-
"content": "'use client';\n\nimport {
|
|
43
|
+
"path": "registry/data-kit/labels.tsx",
|
|
44
|
+
"content": "'use client';\n\nimport { createContext, useContext, type ReactNode } from 'react';\n\n// ** Every string the parts show, in English; set your translations once with <DataKitLabelsProvider>\nexport const dataKitLabels = {\n\tsearch: { placeholder: 'Search…' },\n\tfilter: { all: 'All', yes: 'Yes', no: 'No', min: 'Min', max: 'Max', reset: 'Reset', clear: 'Clear filter', empty: 'No options', selected: (count: number) => `${count} selected` },\n\tdate: { pick: 'Pick dates', preset: (value: string) => `Last ${value.slice(0, -1)} ${value.endsWith('h') ? 'hours' : 'days'}` },\n\ttable: { empty: 'No results.', all: 'Select all', row: 'Select row' },\n\tpagination: {\n\t\tprevious: 'Previous',\n\t\tnext: 'Next',\n\t\tsize: (size: number) => `${size} / page`,\n\t\tsummary: (props: Readonly<{ number: number; count: number | null; total: number | null }>) => (props.count === null ? `Page ${props.number}` : `Page ${props.number} of ${props.count} · ${props.total} total`),\n\t},\n\tselection: { label: 'Actions for the selected rows', selected: (count: number) => `${count} selected`, clear: 'Clear selection' },\n\tinfinite: { loading: 'Loading…', end: \"That's everything\" },\n};\n\ntype TDataKitLabels = typeof dataKitLabels;\nexport type TDataKitLabelsPartial = { [TKey in keyof TDataKitLabels]?: Partial<TDataKitLabels[TKey]> };\n\nconst DataKitLabelsContext = createContext<TDataKitLabels>(dataKitLabels);\n\n// ** Merged part by part over the defaults (and over an outer provider), so a partial set is enough\nexport const DataKitLabelsProvider = (props: Readonly<{ labels: TDataKitLabelsPartial; children: ReactNode }>) => {\n\t// ** Deconstruct Props\n\tconst { labels, children } = props;\n\n\tconst outer = useContext(DataKitLabelsContext);\n\tconst merged = Object.fromEntries(Object.entries(outer).map(([part, value]) => [part, { ...value, ...labels[part as keyof TDataKitLabels] }])) as TDataKitLabels;\n\n\treturn <DataKitLabelsContext.Provider value={merged}>{children}</DataKitLabelsContext.Provider>;\n};\n\nexport const useDataKitLabels = () => useContext(DataKitLabelsContext);\n",
|
|
41
45
|
"type": "registry:ui",
|
|
42
|
-
"target": "@ui/ndk/data-kit/
|
|
46
|
+
"target": "@ui/ndk/data-kit/labels.tsx"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"path": "registry/data-kit/toolbar.tsx",
|
|
50
|
+
"content": "'use client';\n// ** TanStack Table keeps one mutable table object, so React Compiler would skip re-renders: opt this file out\n'use no memo';\n\nimport { useEffect, useState, type ReactNode } from 'react';\nimport type { Table } from '@tanstack/react-table';\nimport { CheckIcon, PlusCircleIcon, XCircleIcon, XIcon } from 'lucide-react';\nimport type { TDataKitColumnMeta } from 'next-data-kit';\nimport { Badge } from '@/components/ui/badge';\nimport { Button, buttonVariants } from '@/components/ui/button';\nimport { Calendar } from '@/components/ui/calendar';\nimport { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@/components/ui/command';\nimport { Input } from '@/components/ui/input';\nimport { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';\nimport { useDataKitLabels } from '@/components/ui/ndk/data-kit/labels';\nimport { cn } from '@/lib/utils';\n\n// ** Typing waits before it filters; a value changed elsewhere (reset, back) shows up in the input\nconst FilterTyped = (props: Readonly<{ value: string; onChange: (value: string) => void; children: (props: Readonly<{ text: string; setText: (text: string) => void }>) => ReactNode }>) => {\n\t// ** Deconstruct Props\n\tconst { value, onChange, children } = props;\n\n\tconst [text, setText] = useState(value);\n\tuseEffect(() => setText(value), [value]);\n\tuseEffect(() => {\n\t\tif (text === value) return;\n\t\tconst timeout = setTimeout(() => onChange(text.trim()), 300);\n\t\treturn () => clearTimeout(timeout);\n\t}, [text]);\n\n\treturn children({ text, setText });\n};\n\n// ** The shadcn data-table look: a dashed button with the filter's name, and what's picked as badges after a divider\n// ** Once active the border turns solid and the ⊕ becomes an ⓧ that clears just this filter, without opening it\nconst FilterButton = (props: Readonly<{ label: string; picked: string[]; selected: (count: number) => string; clear: { label: string; onClick: () => void }; children: ReactNode }>) => {\n\t// ** Deconstruct Props\n\tconst { label, picked, selected, clear, children } = props;\n\n\treturn (\n\t\t<Popover>\n\t\t\t<PopoverTrigger className={cn(buttonVariants({ variant: 'outline', size: 'sm' }), 'h-8', !picked.length && 'border-dashed')}>\n\t\t\t\t{picked.length ? (\n\t\t\t\t\t// ** A span, not a button: it sits inside the trigger button, so it stops the click before the popover sees it\n\t\t\t\t\t<span\n\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\ttabIndex={0}\n\t\t\t\t\t\taria-label={`${clear.label}: ${label}`}\n\t\t\t\t\t\tclassName=\"-ml-0.5 rounded-full opacity-60 outline-none hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring/50\"\n\t\t\t\t\t\tonPointerDown={(event) => event.stopPropagation()}\n\t\t\t\t\t\tonClick={(event) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\t\tclear.onClick();\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonKeyDown={(event) => {\n\t\t\t\t\t\t\tif (event.key !== 'Enter' && event.key !== ' ') return;\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\t\tclear.onClick();\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t<XCircleIcon className=\"size-4\" />\n\t\t\t\t\t</span>\n\t\t\t\t) : (\n\t\t\t\t\t<PlusCircleIcon data-icon=\"inline-start\" />\n\t\t\t\t)}\n\t\t\t\t{label}\n\t\t\t\t{picked.length > 0 && (\n\t\t\t\t\t<span className=\"ml-1 flex items-center gap-1 border-l pl-2\">\n\t\t\t\t\t\t{picked.length > 2 ? (\n\t\t\t\t\t\t\t<Badge variant=\"secondary\" className=\"rounded-sm px-1 font-normal\">\n\t\t\t\t\t\t\t\t{selected(picked.length)}\n\t\t\t\t\t\t\t</Badge>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\tpicked.map((item) => (\n\t\t\t\t\t\t\t\t<Badge key={item} variant=\"secondary\" className=\"rounded-sm px-1 font-normal\">\n\t\t\t\t\t\t\t\t\t{item}\n\t\t\t\t\t\t\t\t</Badge>\n\t\t\t\t\t\t\t))\n\t\t\t\t\t\t)}\n\t\t\t\t\t</span>\n\t\t\t\t)}\n\t\t\t</PopoverTrigger>\n\t\t\t<PopoverContent align=\"start\" className=\"w-auto p-0\">\n\t\t\t\t{children}\n\t\t\t</PopoverContent>\n\t\t</Popover>\n\t);\n};\n\n// ** The filters the server declared, built from data.meta: search box, then one control per visible column, then a reset\n// ** `children` adds your own controls at the end of the row\nexport const DataKitToolbar = <TRow,>(props: Readonly<{ table: Table<TRow>; children?: ReactNode }>) => {\n\t// ** Deconstruct Props\n\tconst { table, children } = props;\n\n\tconst kit = table.options.meta!.dataKit!;\n\tconst labels = useDataKitLabels();\n\tconst filtered = Object.keys(kit.filter).length > 0 || Boolean(kit.search);\n\n\treturn (\n\t\t<div data-slot=\"data-kit-toolbar\" className=\"flex flex-wrap items-center gap-2\">\n\t\t\t{kit.meta.search && (\n\t\t\t\t<FilterTyped value={kit.search} onChange={(value) => kit.set.search(value)}>\n\t\t\t\t\t{(typed) => <Input type=\"search\" value={typed.text} placeholder={labels.search.placeholder} onChange={(event) => typed.setText(event.target.value)} className=\"h-8 w-48 lg:w-64\" />}\n\t\t\t\t</FilterTyped>\n\t\t\t)}\n\t\t\t{Object.entries(kit.meta.column)\n\t\t\t\t.filter((entry): entry is [string, TDataKitColumnMeta & { filter: Exclude<TDataKitColumnMeta['filter'], 'custom' | undefined> }] => Boolean(entry[1].filter && entry[1].filter !== 'custom' && !entry[1].hidden))\n\t\t\t\t// ** Active filters first (in declared order), so what narrows the table reads left to right; keyed, so moving keeps focus\n\t\t\t\t.sort((a, b) => Number(b[0] in kit.filter) - Number(a[0] in kit.filter))\n\t\t\t\t.map(([key, meta]) => {\n\t\t\t\t\tconst column = table.getAllLeafColumns().find((column) => column.id === key);\n\t\t\t\t\tconst label = column?.columnDef.meta?.label ?? (typeof column?.columnDef.header === 'string' ? column.columnDef.header : key);\n\t\t\t\t\tconst option = (value: string) => column?.columnDef.meta?.option?.[value] ?? value;\n\t\t\t\t\tconst value = kit.filter[key] ?? '';\n\t\t\t\t\tconst set = (next: string | undefined) => kit.set.filter({ [key]: next });\n\n\t\t\t\t\tif (meta.filter === 'text' || meta.filter === 'number')\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<FilterTyped key={key} value={value} onChange={set}>\n\t\t\t\t\t\t\t\t{(typed) => <Input aria-label={label} type={meta.filter === 'number' ? 'number' : 'search'} value={typed.text} placeholder={label} onChange={(event) => typed.setText(event.target.value)} className=\"h-8 w-36\" />}\n\t\t\t\t\t\t\t</FilterTyped>\n\t\t\t\t\t\t);\n\n\t\t\t\t\t// ** select, multiSelect and boolean share one list: single choices replace, multiSelect toggles\n\t\t\t\t\tif (meta.filter === 'select' || meta.filter === 'multiSelect' || meta.filter === 'boolean') {\n\t\t\t\t\t\tconst choices = meta.filter === 'boolean' ? [{ value: 'true', label: labels.filter.yes }, { value: 'false', label: labels.filter.no }] : (meta.option ?? []).map((item) => ({ value: item, label: option(item) }));\n\t\t\t\t\t\tconst picked = value ? (meta.filter === 'multiSelect' ? value.split(',') : [value]) : [];\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<FilterButton key={key} label={label} picked={picked.map((item) => choices.find((choice) => choice.value === item)?.label ?? item)} selected={labels.filter.selected} clear={{ label: labels.filter.clear, onClick: () => set(undefined) }}>\n\t\t\t\t\t\t\t\t<Command>\n\t\t\t\t\t\t\t\t\t{choices.length > 7 && <CommandInput placeholder={label} />}\n\t\t\t\t\t\t\t\t\t<CommandList>\n\t\t\t\t\t\t\t\t\t\t<CommandEmpty>{labels.filter.empty}</CommandEmpty>\n\t\t\t\t\t\t\t\t\t\t<CommandGroup>\n\t\t\t\t\t\t\t\t\t\t\t{choices.map((choice) => {\n\t\t\t\t\t\t\t\t\t\t\t\tconst active = picked.includes(choice.value);\n\t\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t\t<CommandItem\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey={choice.value}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tvalue={choice.label}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tonSelect={() => set(meta.filter === 'multiSelect' ? (active ? picked.filter((item) => item !== choice.value) : [...picked, choice.value]).join(',') || undefined : active ? undefined : choice.value)}\n\t\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span className={cn('flex size-4 items-center justify-center rounded-sm border border-primary', active ? 'bg-primary text-primary-foreground' : 'opacity-50 [&_svg]:invisible')}>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<CheckIcon className=\"size-3\" />\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{choice.label}\n\t\t\t\t\t\t\t\t\t\t\t\t\t</CommandItem>\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\t</CommandGroup>\n\t\t\t\t\t\t\t\t\t</CommandList>\n\t\t\t\t\t\t\t\t</Command>\n\t\t\t\t\t\t\t</FilterButton>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (meta.filter === 'range') {\n\t\t\t\t\t\tconst [min = '', max = ''] = value.split('-');\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<FilterButton key={key} label={label} picked={value ? [`${min || '…'}–${max || '…'}`] : []} selected={labels.filter.selected} clear={{ label: labels.filter.clear, onClick: () => set(undefined) }}>\n\t\t\t\t\t\t\t\t<FilterTyped value={value} onChange={(next) => set(next === '-' ? undefined : next)}>\n\t\t\t\t\t\t\t\t\t{(typed) => {\n\t\t\t\t\t\t\t\t\t\tconst [from = '', to = ''] = typed.text.split('-');\n\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t<div className=\"flex items-center gap-2 p-3\">\n\t\t\t\t\t\t\t\t\t\t\t\t<Input type=\"number\" min={0} value={from} placeholder={labels.filter.min} onChange={(event) => typed.setText(`${event.target.value}-${to}`)} className=\"h-8 w-24\" />\n\t\t\t\t\t\t\t\t\t\t\t\t<span className=\"text-muted-foreground\">–</span>\n\t\t\t\t\t\t\t\t\t\t\t\t<Input type=\"number\" min={0} value={to} placeholder={labels.filter.max} onChange={(event) => typed.setText(`${from}-${event.target.value}`)} className=\"h-8 w-24\" />\n\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t</FilterTyped>\n\t\t\t\t\t\t\t</FilterButton>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\t// ** date / dateRange: the browser sends its own day boundaries as ms, so the server never guesses a time zone\n\t\t\t\t\tconst [from, to] = /^\\d+-\\d+$/.test(value) ? value.split('-').map((part) => new Date(Number(part))) : [];\n\t\t\t\t\tconst day = (date: Date, end?: boolean) => new Date(date.getFullYear(), date.getMonth(), date.getDate(), end ? 23 : 0, end ? 59 : 0, end ? 59 : 0, end ? 999 : 0).getTime();\n\t\t\t\t\tconst shown = meta.preset?.includes(value) ? labels.date.preset(value) : from ? `${from.toLocaleDateString()}${to && meta.filter === 'dateRange' && to.toDateString() !== from.toDateString() ? ` – ${to.toLocaleDateString()}` : ''}` : undefined;\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<FilterButton key={key} label={label} picked={shown ? [shown] : []} selected={labels.filter.selected} clear={{ label: labels.filter.clear, onClick: () => set(undefined) }}>\n\t\t\t\t\t\t\t<div className=\"flex\">\n\t\t\t\t\t\t\t\t{meta.preset && (\n\t\t\t\t\t\t\t\t\t<div className=\"flex flex-col gap-1 border-r p-2\">\n\t\t\t\t\t\t\t\t\t\t{meta.preset.map((preset) => (\n\t\t\t\t\t\t\t\t\t\t\t<Button key={preset} variant={value === preset ? 'secondary' : 'ghost'} size=\"sm\" className=\"justify-start\" onClick={() => set(value === preset ? undefined : preset)}>\n\t\t\t\t\t\t\t\t\t\t\t\t{labels.date.preset(preset)}\n\t\t\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t{meta.filter === 'date' ? (\n\t\t\t\t\t\t\t\t\t<Calendar mode=\"single\" selected={from} onSelect={(date) => set(date ? `${day(date)}-${day(date, true)}` : undefined)} />\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t<Calendar mode=\"range\" numberOfMonths={2} selected={from ? { from, to } : undefined} onSelect={(range) => set(range?.from ? `${day(range.from)}-${day(range.to ?? range.from, true)}` : undefined)} />\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</FilterButton>\n\t\t\t\t\t);\n\t\t\t\t})}\n\t\t\t{filtered && (\n\t\t\t\t<Button variant=\"ghost\" size=\"sm\" className=\"h-8\" onClick={() => kit.reset()}>\n\t\t\t\t\t{labels.filter.reset}\n\t\t\t\t\t<XIcon data-icon=\"inline-end\" />\n\t\t\t\t</Button>\n\t\t\t)}\n\t\t\t{children}\n\t\t</div>\n\t);\n};\n",
|
|
51
|
+
"type": "registry:ui",
|
|
52
|
+
"target": "@ui/ndk/data-kit/toolbar.tsx"
|
|
43
53
|
},
|
|
44
54
|
{
|
|
45
|
-
"path": "registry/data-kit/
|
|
46
|
-
"content": "'use client';\n\nimport type {
|
|
55
|
+
"path": "registry/data-kit/view.tsx",
|
|
56
|
+
"content": "'use client';\n// ** TanStack Table keeps one mutable table object, so React Compiler would skip re-renders: opt this file out\n'use no memo';\n\nimport { flexRender, type Table as TTable } from '@tanstack/react-table';\nimport { ArrowDownIcon, ArrowUpIcon, ChevronsUpDownIcon } from 'lucide-react';\nimport { Checkbox } from '@/components/ui/checkbox';\nimport { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';\nimport { useDataKitLabels } from '@/components/ui/ndk/data-kit/labels';\n\n// ** The rows as a table: sortable headers (asc → desc → off, with aria-sort), a selection column when rows are selectable, an empty state\nexport const DataKitTableView = <TRow,>(props: Readonly<{ table: TTable<TRow>; row?: { onClick?: (props: Readonly<{ row: TRow }>) => void } }>) => {\n\t// ** Deconstruct Props\n\tconst { table, row } = props;\n\n\tconst labels = useDataKitLabels();\n\tconst kit = table.options.meta?.dataKit;\n\tconst isPending = kit?.state.isPending;\n\tconst selectable = Boolean(table.options.enableRowSelection);\n\n\treturn (\n\t\t<Table aria-busy={isPending} className={isPending ? 'opacity-60 transition-opacity' : 'transition-opacity'}>\n\t\t\t<TableHeader>\n\t\t\t\t{table.getHeaderGroups().map((group) => (\n\t\t\t\t\t<TableRow key={group.id}>\n\t\t\t\t\t\t{selectable && (\n\t\t\t\t\t\t\t<TableHead className=\"w-8\">\n\t\t\t\t\t\t\t\t<Checkbox aria-label={labels.table.all} checked={table.getIsAllPageRowsSelected()} onCheckedChange={(checked) => table.toggleAllPageRowsSelected(Boolean(checked))} />\n\t\t\t\t\t\t\t</TableHead>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{group.headers.map((header) => {\n\t\t\t\t\t\t\tconst sorted = header.column.getIsSorted();\n\t\t\t\t\t\t\tconst content = header.isPlaceholder ? null : flexRender(header.column.columnDef.header ?? header.column.columnDef.meta?.label ?? header.column.id, header.getContext());\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<TableHead key={header.id} className={header.column.columnDef.meta?.className} aria-sort={!header.column.getCanSort() ? undefined : sorted === 'asc' ? 'ascending' : sorted === 'desc' ? 'descending' : 'none'}>\n\t\t\t\t\t\t\t\t\t{header.column.getCanSort() ? (\n\t\t\t\t\t\t\t\t\t\t// ** A plain button that inherits the header's own type, so sortable and plain headers line up\n\t\t\t\t\t\t\t\t\t\t<button type=\"button\" className=\"inline-flex items-center gap-1 rounded-sm outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\" onClick={() => {\n\t\t\t\t\t\t\t\t\t\t\t\t// ** asc → desc → off; the default column goes desc ⇄ asc, since \"off\" would only land back on it\n\t\t\t\t\t\t\t\t\t\t\t\tconst isDefault = kit?.meta.sort.some((sort) => sort.column === header.column.id);\n\t\t\t\t\t\t\t\t\t\t\t\tconst next = sorted === false ? 'asc' : sorted === 'asc' ? 'desc' : isDefault ? 'asc' : undefined;\n\t\t\t\t\t\t\t\t\t\t\t\tkit?.set.sort(next ? [{ column: header.column.id, direction: next }] : []);\n\t\t\t\t\t\t\t\t\t\t\t}}>\n\t\t\t\t\t\t\t\t\t\t\t{content}\n\t\t\t\t\t\t\t\t\t\t\t{sorted === 'asc' ? <ArrowUpIcon className=\"size-3.5\" /> : sorted === 'desc' ? <ArrowDownIcon className=\"size-3.5\" /> : <ChevronsUpDownIcon className=\"size-3.5 opacity-40\" />}\n\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\tcontent\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t</TableHead>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t})}\n\t\t\t\t\t</TableRow>\n\t\t\t\t))}\n\t\t\t</TableHeader>\n\t\t\t<TableBody>\n\t\t\t\t{table.getRowModel().rows.length === 0 ? (\n\t\t\t\t\t<TableRow>\n\t\t\t\t\t\t<TableCell colSpan={table.getVisibleLeafColumns().length + (selectable ? 1 : 0)} className=\"h-24 text-center text-muted-foreground\">\n\t\t\t\t\t\t\t{labels.table.empty}\n\t\t\t\t\t\t</TableCell>\n\t\t\t\t\t</TableRow>\n\t\t\t\t) : (\n\t\t\t\t\ttable.getRowModel().rows.map((item) => (\n\t\t\t\t\t\t<TableRow\n\t\t\t\t\t\t\tkey={item.id}\n\t\t\t\t\t\t\tdata-state={item.getIsSelected() ? 'selected' : undefined}\n\t\t\t\t\t\t\tclassName={row?.onClick ? 'cursor-pointer' : undefined}\n\t\t\t\t\t\t\tonClick={row?.onClick ? () => row.onClick!({ row: item.original }) : undefined}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{selectable && (\n\t\t\t\t\t\t\t\t<TableCell onClick={(event) => event.stopPropagation()}>\n\t\t\t\t\t\t\t\t\t<Checkbox aria-label={labels.table.row} checked={item.getIsSelected()} disabled={!item.getCanSelect()} onCheckedChange={(checked) => item.toggleSelected(Boolean(checked))} />\n\t\t\t\t\t\t\t\t</TableCell>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t{item.getVisibleCells().map((cell) => (\n\t\t\t\t\t\t\t\t<TableCell key={cell.id} className={cell.column.columnDef.meta?.className}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>\n\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t</TableRow>\n\t\t\t\t\t))\n\t\t\t\t)}\n\t\t\t</TableBody>\n\t\t</Table>\n\t);\n};\n",
|
|
47
57
|
"type": "registry:ui",
|
|
48
|
-
"target": "@ui/ndk/data-kit/
|
|
58
|
+
"target": "@ui/ndk/data-kit/view.tsx"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"path": "registry/data-kit/pagination.tsx",
|
|
62
|
+
"content": "'use client';\n// ** TanStack Table keeps one mutable table object, so React Compiler would skip re-renders: opt this file out\n'use no memo';\n\nimport { Fragment, type MouseEvent } from 'react';\nimport type { Table } from '@tanstack/react-table';\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport { urlEncode } from 'next-data-kit';\nimport { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from '@/components/ui/pagination';\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';\nimport { useDataKitLabels } from '@/components/ui/ndk/data-kit/labels';\n\n// ** 1 … 4 5 6 … 20 as real links (new tab works; a plain click changes page in place). Without a count: previous / next only\nexport const DataKitPagination = <TRow,>(props: Readonly<{ table: Table<TRow>; sizes?: number[] }>) => {\n\t// ** Deconstruct Props\n\tconst { table, sizes } = props;\n\n\tconst kit = table.options.meta!.dataKit!;\n\tconst labels = useDataKitLabels();\n\tconst pathname = usePathname();\n\tconst searchParams = useSearchParams();\n\tconst { number, count, next } = kit.page;\n\t// ** First, last and the two around the current page; a gap of more than one becomes an ellipsis\n\tconst pages = count === null ? [] : [...new Set([1, number - 1, number, number + 1, count])].filter((page) => page >= 1 && page <= count).sort((a, b) => a - b);\n\n\t// ** Disabled links get no href, so they can't be focused or opened\n\tconst link = (page: number, enabled: boolean) => ({\n\t\thref: enabled ? `${pathname}?${urlEncode({ input: { ...kit.input, page: { number: page, size: kit.page.size } }, key: kit.key, search: searchParams.toString() })}` : undefined,\n\t\t'aria-disabled': !enabled || undefined,\n\t\tclassName: !enabled || kit.state.isPending ? 'pointer-events-none opacity-50' : undefined,\n\t\tonClick: (event: MouseEvent<HTMLAnchorElement>) => {\n\t\t\tif (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;\n\t\t\tevent.preventDefault();\n\t\t\ttable.setPageIndex(page - 1);\n\t\t},\n\t});\n\n\treturn (\n\t\t<div data-slot=\"data-kit-pagination\" className=\"flex w-full flex-wrap items-center justify-between gap-2 text-sm text-muted-foreground\">\n\t\t\t<span>{labels.pagination.summary({ number, count, total: kit.total })}</span>\n\t\t\t<div className=\"flex items-center gap-2\">\n\t\t\t\t{sizes && (\n\t\t\t\t\t<Select value={String(kit.page.size)} onValueChange={(size) => table.setPageSize(Number(size))}>\n\t\t\t\t\t\t<SelectTrigger className=\"w-28\">\n\t\t\t\t\t\t\t<SelectValue>{labels.pagination.size(kit.page.size)}</SelectValue>\n\t\t\t\t\t\t</SelectTrigger>\n\t\t\t\t\t\t<SelectContent>\n\t\t\t\t\t\t\t{[...new Set([...sizes, kit.page.size])]\n\t\t\t\t\t\t\t\t.sort((a, b) => a - b)\n\t\t\t\t\t\t\t\t.map((size) => (\n\t\t\t\t\t\t\t\t\t<SelectItem key={size} value={String(size)}>\n\t\t\t\t\t\t\t\t\t\t{labels.pagination.size(size)}\n\t\t\t\t\t\t\t\t\t</SelectItem>\n\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t</SelectContent>\n\t\t\t\t\t</Select>\n\t\t\t\t)}\n\t\t\t\t<Pagination className=\"mx-0 w-auto\">\n\t\t\t\t\t<PaginationContent>\n\t\t\t\t\t\t<PaginationItem>\n\t\t\t\t\t\t\t<PaginationPrevious text={labels.pagination.previous} {...link(number - 1, number > 1)} />\n\t\t\t\t\t\t</PaginationItem>\n\t\t\t\t\t\t{pages.map((page, index) => (\n\t\t\t\t\t\t\t<Fragment key={page}>\n\t\t\t\t\t\t\t\t{index > 0 && page - pages[index - 1]! > 1 && (\n\t\t\t\t\t\t\t\t\t<PaginationItem>\n\t\t\t\t\t\t\t\t\t\t<PaginationEllipsis />\n\t\t\t\t\t\t\t\t\t</PaginationItem>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t<PaginationItem>\n\t\t\t\t\t\t\t\t\t<PaginationLink isActive={page === number} {...link(page, true)}>\n\t\t\t\t\t\t\t\t\t\t{page}\n\t\t\t\t\t\t\t\t\t</PaginationLink>\n\t\t\t\t\t\t\t\t</PaginationItem>\n\t\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t\t))}\n\t\t\t\t\t\t<PaginationItem>\n\t\t\t\t\t\t\t<PaginationNext text={labels.pagination.next} {...link(number + 1, next)} />\n\t\t\t\t\t\t</PaginationItem>\n\t\t\t\t\t</PaginationContent>\n\t\t\t\t</Pagination>\n\t\t\t</div>\n\t\t</div>\n\t);\n};\n",
|
|
63
|
+
"type": "registry:ui",
|
|
64
|
+
"target": "@ui/ndk/data-kit/pagination.tsx"
|
|
49
65
|
},
|
|
50
66
|
{
|
|
51
67
|
"path": "registry/data-kit/infinite.tsx",
|
|
52
|
-
"content": "'use client';\n\nimport { useEffect, useRef } from 'react';\nimport {
|
|
68
|
+
"content": "'use client';\n// ** TanStack Table keeps one mutable table object, so React Compiler would skip re-renders: opt this file out\n'use no memo';\n\nimport { useEffect, useRef } from 'react';\nimport type { Table } from '@tanstack/react-table';\nimport { useDataKitLabels } from '@/components/ui/ndk/data-kit/labels';\n\n// ** Put under your list (useDataKitTable with `append` and `source={{ fetch }}`): loads the next page when it scrolls into view\nexport const DataKitInfinite = <TRow,>(props: Readonly<{ table: Table<TRow> }>) => {\n\t// ** Deconstruct Props\n\tconst { table } = props;\n\n\tconst kit = table.options.meta!.dataKit!;\n\tconst labels = useDataKitLabels();\n\tconst sentinel = useRef<HTMLDivElement>(null);\n\n\tuseEffect(() => {\n\t\tif (!sentinel.current || !kit.page.next || kit.state.isPending) return;\n\t\tconst observer = new IntersectionObserver((entries) => entries[0]?.isIntersecting && kit.set.page(kit.page.number + 1));\n\t\tobserver.observe(sentinel.current);\n\t\treturn () => observer.disconnect();\n\t});\n\n\treturn (\n\t\t<div ref={sentinel} data-slot=\"data-kit-infinite\" className=\"py-4 text-center text-xs text-muted-foreground\">\n\t\t\t{kit.state.isPending ? labels.infinite.loading : !kit.page.next && kit.rows.length > 0 ? labels.infinite.end : null}\n\t\t</div>\n\t);\n};\n",
|
|
53
69
|
"type": "registry:ui",
|
|
54
70
|
"target": "@ui/ndk/data-kit/infinite.tsx"
|
|
55
71
|
}
|
package/registry/r/registry.json
CHANGED
|
@@ -7,16 +7,65 @@
|
|
|
7
7
|
"name": "data-kit",
|
|
8
8
|
"type": "registry:ui",
|
|
9
9
|
"title": "Data Kit",
|
|
10
|
-
"description": "Table
|
|
11
|
-
"dependencies": [
|
|
12
|
-
|
|
10
|
+
"description": "A server-driven data table on TanStack Table: auto-built filters, sortable headers, selection, pagination and infinite scroll, using your own shadcn components.",
|
|
11
|
+
"dependencies": [
|
|
12
|
+
"next-data-kit@^11.0.0",
|
|
13
|
+
"@tanstack/react-table@^8.21.0",
|
|
14
|
+
"lucide-react"
|
|
15
|
+
],
|
|
16
|
+
"registryDependencies": [
|
|
17
|
+
"badge",
|
|
18
|
+
"button",
|
|
19
|
+
"calendar",
|
|
20
|
+
"checkbox",
|
|
21
|
+
"command",
|
|
22
|
+
"input",
|
|
23
|
+
"pagination",
|
|
24
|
+
"popover",
|
|
25
|
+
"select",
|
|
26
|
+
"table"
|
|
27
|
+
],
|
|
13
28
|
"files": [
|
|
14
|
-
{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{
|
|
29
|
+
{
|
|
30
|
+
"path": "registry/data-kit/data-kit.tsx",
|
|
31
|
+
"type": "registry:ui",
|
|
32
|
+
"target": "@ui/ndk/data-kit/data-kit.tsx"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"path": "registry/data-kit/action-bar.tsx",
|
|
36
|
+
"type": "registry:ui",
|
|
37
|
+
"target": "@ui/ndk/data-kit/action-bar.tsx"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"path": "registry/data-kit/hook.tsx",
|
|
41
|
+
"type": "registry:ui",
|
|
42
|
+
"target": "@ui/ndk/data-kit/hook.tsx"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"path": "registry/data-kit/labels.tsx",
|
|
46
|
+
"type": "registry:ui",
|
|
47
|
+
"target": "@ui/ndk/data-kit/labels.tsx"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"path": "registry/data-kit/toolbar.tsx",
|
|
51
|
+
"type": "registry:ui",
|
|
52
|
+
"target": "@ui/ndk/data-kit/toolbar.tsx"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"path": "registry/data-kit/view.tsx",
|
|
56
|
+
"type": "registry:ui",
|
|
57
|
+
"target": "@ui/ndk/data-kit/view.tsx"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "registry/data-kit/pagination.tsx",
|
|
61
|
+
"type": "registry:ui",
|
|
62
|
+
"target": "@ui/ndk/data-kit/pagination.tsx"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"path": "registry/data-kit/infinite.tsx",
|
|
66
|
+
"type": "registry:ui",
|
|
67
|
+
"target": "@ui/ndk/data-kit/infinite.tsx"
|
|
68
|
+
}
|
|
20
69
|
]
|
|
21
70
|
}
|
|
22
71
|
]
|