@zonsh/ui 0.2.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.
Files changed (200) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/accordion.js +1 -1
  4. package/dist/components/alert-dialog.js +1 -1
  5. package/dist/components/ascii-field.d.ts +1 -1
  6. package/dist/components/ascii-field.js +2 -1
  7. package/dist/components/bottom-nav.d.ts +86 -0
  8. package/dist/components/bottom-nav.js +175 -0
  9. package/dist/components/breadcrumb.d.ts +9 -0
  10. package/dist/components/breadcrumb.js +6 -1
  11. package/dist/components/button-group.d.ts +1 -1
  12. package/dist/components/button-group.js +2 -2
  13. package/dist/components/button.js +1 -1
  14. package/dist/components/calendar.d.ts +1 -1
  15. package/dist/components/calendar.js +18 -3
  16. package/dist/components/carousel.d.ts +22 -3
  17. package/dist/components/carousel.js +25 -7
  18. package/dist/components/chart.d.ts +20 -0
  19. package/dist/components/chart.js +52 -3
  20. package/dist/components/code-block.d.ts +20 -10
  21. package/dist/components/code-block.js +54 -12
  22. package/dist/components/collapsible.js +3 -3
  23. package/dist/components/color-picker.d.ts +30 -8
  24. package/dist/components/color-picker.js +48 -27
  25. package/dist/components/combobox.d.ts +21 -3
  26. package/dist/components/combobox.js +79 -7
  27. package/dist/components/command.d.ts +23 -3
  28. package/dist/components/command.js +63 -18
  29. package/dist/components/conversation.d.ts +10 -1
  30. package/dist/components/conversation.js +24 -7
  31. package/dist/components/copy-button.d.ts +15 -6
  32. package/dist/components/copy-button.js +27 -10
  33. package/dist/components/data-table.d.ts +66 -6
  34. package/dist/components/data-table.js +376 -23
  35. package/dist/components/date-picker.d.ts +73 -4
  36. package/dist/components/date-picker.js +138 -7
  37. package/dist/components/dialog.d.ts +10 -1
  38. package/dist/components/dialog.js +6 -3
  39. package/dist/components/drawer.d.ts +10 -1
  40. package/dist/components/drawer.js +6 -3
  41. package/dist/components/feature-list.js +2 -2
  42. package/dist/components/field.d.ts +27 -8
  43. package/dist/components/field.js +49 -4
  44. package/dist/components/file-drop.d.ts +26 -4
  45. package/dist/components/file-drop.js +125 -64
  46. package/dist/components/filter-bar.d.ts +50 -3
  47. package/dist/components/filter-bar.js +71 -33
  48. package/dist/components/form.d.ts +4 -2
  49. package/dist/components/form.js +24 -2
  50. package/dist/components/graph.d.ts +41 -0
  51. package/dist/components/graph.js +106 -50
  52. package/dist/components/illustration.js +51 -4
  53. package/dist/components/input-group.d.ts +18 -7
  54. package/dist/components/input-group.js +41 -19
  55. package/dist/components/input.d.ts +2 -2
  56. package/dist/components/input.js +3 -3
  57. package/dist/components/kbd.d.ts +17 -0
  58. package/dist/components/kbd.js +8 -1
  59. package/dist/components/layout.d.ts +2 -1
  60. package/dist/components/layout.js +55 -11
  61. package/dist/components/lightbox.d.ts +100 -0
  62. package/dist/components/lightbox.js +457 -0
  63. package/dist/components/locale.d.ts +44 -0
  64. package/dist/components/locale.js +37 -0
  65. package/dist/components/logo.js +1 -1
  66. package/dist/components/menu.js +3 -1
  67. package/dist/components/menubar.js +60 -13
  68. package/dist/components/message.d.ts +3 -3
  69. package/dist/components/message.js +12 -8
  70. package/dist/components/meter.js +3 -1
  71. package/dist/components/money-input.d.ts +80 -0
  72. package/dist/components/money-input.js +253 -0
  73. package/dist/components/navigation-menu.js +4 -2
  74. package/dist/components/number-field.d.ts +21 -2
  75. package/dist/components/number-field.js +53 -28
  76. package/dist/components/otp-field.d.ts +14 -1
  77. package/dist/components/otp-field.js +10 -2
  78. package/dist/components/pagination.d.ts +13 -7
  79. package/dist/components/pagination.js +18 -7
  80. package/dist/components/pdf-viewer.d.ts +67 -2
  81. package/dist/components/pdf-viewer.js +88 -21
  82. package/dist/components/phone-input.d.ts +79 -0
  83. package/dist/components/phone-input.js +282 -0
  84. package/dist/components/popover.js +1 -1
  85. package/dist/components/progress.js +3 -1
  86. package/dist/components/prompt-input.d.ts +34 -9
  87. package/dist/components/prompt-input.js +37 -17
  88. package/dist/components/radio-group.js +7 -2
  89. package/dist/components/rating.d.ts +73 -0
  90. package/dist/components/rating.js +124 -0
  91. package/dist/components/reasoning.d.ts +16 -1
  92. package/dist/components/reasoning.js +10 -7
  93. package/dist/components/resizable.d.ts +10 -1
  94. package/dist/components/resizable.js +4 -1
  95. package/dist/components/response.d.ts +17 -5
  96. package/dist/components/response.js +58 -18
  97. package/dist/components/scroll-area.d.ts +1 -1
  98. package/dist/components/select.js +14 -3
  99. package/dist/components/separator.js +1 -1
  100. package/dist/components/sidebar.d.ts +20 -4
  101. package/dist/components/sidebar.js +70 -35
  102. package/dist/components/site-header.d.ts +46 -12
  103. package/dist/components/site-header.js +78 -19
  104. package/dist/components/skeleton.d.ts +1 -1
  105. package/dist/components/skeleton.js +1 -1
  106. package/dist/components/slider.js +3 -1
  107. package/dist/components/sortable.d.ts +178 -0
  108. package/dist/components/sortable.js +1282 -0
  109. package/dist/components/sources.d.ts +17 -2
  110. package/dist/components/sources.js +11 -4
  111. package/dist/components/spinner.d.ts +13 -1
  112. package/dist/components/spinner.js +5 -2
  113. package/dist/components/stat.d.ts +91 -0
  114. package/dist/components/stat.js +141 -0
  115. package/dist/components/stepper.d.ts +71 -0
  116. package/dist/components/stepper.js +101 -0
  117. package/dist/components/switch.d.ts +2 -2
  118. package/dist/components/switch.js +2 -2
  119. package/dist/components/table.d.ts +13 -3
  120. package/dist/components/table.js +231 -41
  121. package/dist/components/tabs.js +8 -4
  122. package/dist/components/tags-input.d.ts +18 -2
  123. package/dist/components/tags-input.js +66 -34
  124. package/dist/components/theme.d.ts +16 -2
  125. package/dist/components/theme.js +34 -8
  126. package/dist/components/time-field.d.ts +24 -4
  127. package/dist/components/time-field.js +32 -9
  128. package/dist/components/timeline.d.ts +18 -2
  129. package/dist/components/timeline.js +13 -4
  130. package/dist/components/tippy.d.ts +48 -0
  131. package/dist/components/tippy.js +648 -0
  132. package/dist/components/toast.d.ts +18 -2
  133. package/dist/components/toast.js +12 -3
  134. package/dist/components/toggle-group.js +1 -0
  135. package/dist/components/tool-call.d.ts +19 -8
  136. package/dist/components/tool-call.js +23 -7
  137. package/dist/components/toolbar.d.ts +1 -1
  138. package/dist/components/toolbar.js +10 -2
  139. package/dist/components/tooltip.d.ts +4 -2
  140. package/dist/components/tooltip.js +10 -4
  141. package/dist/components/tour.d.ts +127 -0
  142. package/dist/components/tour.js +673 -0
  143. package/dist/components/tree.js +45 -9
  144. package/dist/components/video-player.d.ts +10 -2
  145. package/dist/components/video-player.js +134 -38
  146. package/dist/illustration.d.ts +2 -0
  147. package/dist/illustration.js +7 -0
  148. package/dist/index.d.ts +11 -3
  149. package/dist/index.js +11 -3
  150. package/dist/lib/code-highlight.d.ts +3 -16
  151. package/dist/lib/code-highlight.js +160 -10
  152. package/dist/lib/code-theme.js +3 -3
  153. package/dist/lib/digit-roll.js +8 -8
  154. package/dist/lib/field-errors.d.ts +28 -0
  155. package/dist/lib/field-errors.js +24 -0
  156. package/dist/lib/field-value.d.ts +13 -0
  157. package/dist/lib/field-value.js +44 -0
  158. package/dist/lib/glide.d.ts +5 -4
  159. package/dist/lib/glide.js +5 -4
  160. package/dist/lib/graph-layout.js +11 -2
  161. package/dist/lib/money.d.ts +73 -0
  162. package/dist/lib/money.js +343 -0
  163. package/dist/lib/phone-countries.d.ts +1 -0
  164. package/dist/lib/phone-countries.js +281 -0
  165. package/dist/lib/phone.d.ts +90 -0
  166. package/dist/lib/phone.js +286 -0
  167. package/dist/lib/platform.d.ts +8 -3
  168. package/dist/lib/platform.js +13 -6
  169. package/dist/lib/row-index.d.ts +15 -0
  170. package/dist/lib/row-index.js +136 -0
  171. package/dist/lib/table-fit.d.ts +3 -2
  172. package/dist/lib/table-fit.js +52 -23
  173. package/dist/lib/theme-script.d.ts +15 -2
  174. package/dist/lib/theme-script.js +23 -3
  175. package/dist/lib/tippy/pixels.d.ts +47 -0
  176. package/dist/lib/tippy/pixels.js +187 -0
  177. package/dist/lib/tippy/sprite.d.ts +86 -0
  178. package/dist/lib/tippy/sprite.js +753 -0
  179. package/dist/messages/de.d.ts +12 -0
  180. package/dist/messages/de.js +326 -0
  181. package/dist/styles/expressive.css +60 -26
  182. package/dist/styles/index.css +11 -2
  183. package/dist/styles/material.css +47 -23
  184. package/dist/styles/parts/ai.css +4 -2
  185. package/dist/styles/parts/controls.css +85 -32
  186. package/dist/styles/parts/data.css +33 -5
  187. package/dist/styles/parts/feedback.css +110 -13
  188. package/dist/styles/parts/foundations.css +1 -1
  189. package/dist/styles/parts/navigation.css +230 -5
  190. package/dist/styles/parts/overlays.css +98 -11
  191. package/dist/styles/parts/pdf.css +13 -7
  192. package/dist/styles/tokens.css +28 -4
  193. package/dist/vite.d.ts +0 -50
  194. package/dist/vite.js +0 -100
  195. package/package.json +28 -33
  196. package/dist/components/code-highlight.d.ts +0 -13
  197. package/dist/components/code-highlight.js +0 -107
  198. package/dist/components/whiteboard.d.ts +0 -80
  199. package/dist/components/whiteboard.js +0 -389
  200. package/dist/styles/parts/whiteboard.css +0 -855
@@ -1,16 +1,36 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { columnFilteringFeature, columnGroupingFeature, columnVisibilityFeature, createColumnHelper, createFilteredRowModel, createGroupedRowModel, createPaginatedRowModel, createSortedRowModel, filterFn_includesString, functionalUpdate, globalFilteringFeature, metaHelper, rowPaginationFeature, rowSelectionFeature, rowSortingFeature, sortFn_alphanumeric, sortFn_basic, sortFn_datetime, sortFn_text, tableFeatures, useTable, } from "@tanstack/react-table";
3
+ import { columnFilteringFeature, columnGroupingFeature, columnVisibilityFeature, constructRow, createColumnHelper, createFilteredRowModel, createGroupedRowModel, createPaginatedRowModel, createSortedRowModel, filterFn_includesString, functionalUpdate, globalFilteringFeature, metaHelper, rowPaginationFeature, rowSelectionFeature, rowSortingFeature, sortFn_alphanumeric, sortFn_basic, sortFn_datetime, sortFn_text, tableFeatures, useTable, } from "@tanstack/react-table";
4
4
  import { ArrowDownIcon, ArrowUpIcon, ChevronLeftIcon, ChevronRightIcon, ChevronsUpDownIcon, Columns3Icon, SearchIcon, } from "lucide-react";
5
5
  import * as React from "react";
6
6
  import { cn } from "../lib/cn.js";
7
+ import { columnRanks, matching, searchLines, sortedOrder } from "../lib/row-index.js";
7
8
  import { widestRows } from "../lib/table-fit.js";
8
9
  import { Button } from "./button.js";
9
10
  import { Checkbox } from "./checkbox.js";
10
11
  import { Input } from "./input.js";
12
+ import { useLocale, useMessages } from "./locale.js";
11
13
  import { Menu, MenuCheckboxItem, MenuContent, MenuGroup, MenuGroupLabel, MenuTrigger } from "./menu.js";
12
14
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
15
+ import { Skeleton } from "./skeleton.js";
13
16
  import { Table, TableBody, TableCaption, TableCell, TableGroup, TableGroupHeader, TableHead, TableHeader, TableRow, TableVirtualBody, } from "./table.js";
17
+ const defaultMessages = {
18
+ search: "Search…",
19
+ columns: "Columns",
20
+ showColumns: "Show columns",
21
+ selectAll: "Select all rows",
22
+ selectPage: "Select all rows on this page",
23
+ selectRow: "Select row",
24
+ empty: "No results.",
25
+ loadError: "Couldn't load the rows.",
26
+ retry: "Try again",
27
+ selected: (count, total) => `${count} of ${total} selected`,
28
+ groupCount: (rows, groups) => `${rows} ${rows === 1 ? "row" : "rows"} in ${groups} ${groups === 1 ? "group" : "groups"}`,
29
+ rowsPerPage: "Rows",
30
+ range: (first, last, total) => `${first}–${last} of ${total}`,
31
+ previous: "Previous page",
32
+ next: "Next page",
33
+ };
14
34
  /**
15
35
  * The TanStack Table v9 features `DataTable` registers: global and column filtering, sorting,
16
36
  * column visibility, row selection, grouping and pagination, all processed on the client.
@@ -85,6 +105,31 @@ function sortByValue(collator, rowA, rowB, columnId) {
85
105
  return collator.compare(String(a), String(b));
86
106
  return sortFn_basic(rowA, rowB, columnId);
87
107
  }
108
+ /** Every column with data in `columns` (groups opened), by id — the ids and values TanStack gives them. */
109
+ function leafReaders(columns) {
110
+ const out = new Map();
111
+ const walk = (defs) => {
112
+ for (const def of defs) {
113
+ const d = def;
114
+ if (d.columns)
115
+ walk(d.columns);
116
+ const key = d.accessorKey === undefined ? undefined : String(d.accessorKey);
117
+ const id = d.id ?? key?.replaceAll(".", "_") ?? (typeof d.header === "string" ? d.header : undefined);
118
+ const read = d.accessorFn ??
119
+ (key === undefined
120
+ ? undefined
121
+ : key.includes(".")
122
+ ? (row) => key
123
+ .split(".")
124
+ .reduce((value, part) => value?.[part], row)
125
+ : (row) => row[key]);
126
+ if (id && read)
127
+ out.set(id, { id, def, read });
128
+ }
129
+ };
130
+ walk(columns);
131
+ return out;
132
+ }
88
133
  /* ── Header ────────────────────────────────────────────────────────────────── */
89
134
  function columnLabel(column) {
90
135
  const header = column.columnDef.header;
@@ -99,6 +144,18 @@ function SortIcon({ direction }) {
99
144
  }
100
145
  /** More rows than this could show at once: the table renders only those in view. */
101
146
  const VIRTUAL_FROM = 100;
147
+ /**
148
+ * From this many rows (not grouped), the table sorts, searches and pages them itself, with one
149
+ * number per row, and TanStack builds a row only for those drawn: a million rows sort in a fraction
150
+ * of a second, in a fraction of the memory.
151
+ */
152
+ const LARGE_FROM = 50_000;
153
+ /** Rows a server table asks for at a time. */
154
+ const CHUNK = 100;
155
+ const NO_ROWS = [];
156
+ /** From this many rows, a search waits for typing to pause (SEARCH_WAIT ms). */
157
+ const SEARCH_WAIT_FROM = 20_000;
158
+ const SEARCH_WAIT = 250;
102
159
  const rowKeyOf = (row) => row.id;
103
160
  /**
104
161
  * DataTable — a `Table` with the controls people expect from a data grid: sortable mono
@@ -111,8 +168,23 @@ const rowKeyOf = (row) => row.id;
111
168
  * break: reaching for it for a handful of rows. Under ~10 rows with nothing to sort, use a
112
169
  * plain `Table`.
113
170
  */
114
- export function DataTable({ columns, data, searchKey, searchPlaceholder = "Search…", searchable = true, pageSize = 10, pageSizeOptions = [10, 20, 50], selectable, onRowSelectionChange, getRowId, columnToggle = true, dense = false, variant = "card", fit = false, initialSorting = [], locale, initialColumnVisibility = {}, emptyMessage = "No results.", toolbar, caption, label, groupBy, groupSummary, stickyGroupHeaders = false, tableContainerProps, virtualize, className, ...props }) {
115
- const grouped = groupBy != null;
171
+ export function DataTable({ columns, data = NO_ROWS, fetchRows, searchKey, searchPlaceholder: searchPlaceholderProp, searchable = true, pageSize = 10, pageSizeOptions = [10, 20, 50], selectable, onRowSelectionChange, getRowId, columnToggle = true, dense = false, variant = "card", fit = false, initialSorting = [], locale: localeProp, initialColumnVisibility = {}, emptyMessage: emptyMessageProp, labels, toolbar, caption, label, groupBy, groupSummary, stickyGroupHeaders = false, tableContainerProps, virtualize, className, ...props }) {
172
+ const text = useMessages("dataTable", defaultMessages, labels);
173
+ // The header's checkbox reads its name here: the columns are built once, not at every render.
174
+ const textRef = React.useRef(text);
175
+ textRef.current = text;
176
+ const providedLocale = useLocale();
177
+ const locale = localeProp ?? providedLocale;
178
+ const searchPlaceholder = searchPlaceholderProp ?? text.search;
179
+ const emptyMessage = emptyMessageProp === undefined ? text.empty : emptyMessageProp;
180
+ const server = fetchRows != null;
181
+ if (process.env.NODE_ENV !== "production" && server && groupBy != null)
182
+ console.warn("DataTable: `groupBy` is not available with `fetchRows`; the rows are not grouped.");
183
+ const grouped = groupBy != null && !server;
184
+ // Rows the table sorts, searches and pages itself (many of them), or that come from a server:
185
+ // TanStack only knows the columns and builds rows for those drawn.
186
+ const large = !server && !grouped && data.length >= LARGE_FROM;
187
+ const outside = server || large;
116
188
  const withSelection = selectable ?? onRowSelectionChange != null;
117
189
  const size = dense ? "sm" : "default";
118
190
  const searchId = React.useId();
@@ -132,6 +204,8 @@ export function DataTable({ columns, data, searchKey, searchPlaceholder = "Searc
132
204
  return next;
133
205
  });
134
206
  const groupedAnchor = React.useRef(null);
207
+ /** Selection in the large and server modes, set at each render for the checkbox column. */
208
+ const outsideSelect = React.useRef(null);
135
209
  const groupedRange = React.useRef(() => null);
136
210
  // Every column's sort, in the locale's order. It reads the collator as it runs: TanStack copies the
137
211
  // default column into a column only when it builds it.
@@ -147,12 +221,16 @@ export function DataTable({ columns, data, searchKey, searchPlaceholder = "Searc
147
221
  enableSorting: false,
148
222
  enableHiding: false,
149
223
  enableGlobalFilter: false,
150
- header: ({ table }) => grouped ? (_jsx(Checkbox, { "aria-label": "Select all rows", checked: table.getIsAllRowsSelected(), indeterminate: table.getIsSomeRowsSelected() && !table.getIsAllRowsSelected(), onCheckedChange: (checked) => {
224
+ header: ({ table }) => grouped ? (_jsx(Checkbox, { "aria-label": textRef.current.selectAll, checked: table.getIsAllRowsSelected(), indeterminate: table.getIsSomeRowsSelected() && !table.getIsAllRowsSelected(), onCheckedChange: (checked) => {
151
225
  groupedAnchor.current = null;
152
226
  table.toggleAllRowsSelected(checked);
153
- }, className: "align-middle" })) : (_jsx(Checkbox, { "aria-label": "Select all rows on this page", checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected(), onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked), className: "align-middle" })),
227
+ }, className: "align-middle" })) : outsideSelect.current ? (
228
+ // A server's rows aren't all here to select; many rows are, every one that matches.
229
+ outsideSelect.current.toggleAll ? (_jsx(Checkbox, { "aria-label": textRef.current.selectAll, checked: outsideSelect.current.all, indeterminate: outsideSelect.current.some, onCheckedChange: (checked) => outsideSelect.current?.toggleAll?.(checked), className: "align-middle" })) : null) : (_jsx(Checkbox, { "aria-label": textRef.current.selectPage, checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected(), onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked), className: "align-middle" })),
154
230
  cell: ({ row }) => (_jsx(Checkbox, { "aria-labelledby": selectRowLabelId, checked: row.getIsSelected(), disabled: !row.getCanSelect(), onCheckedChange: (checked, details) => {
155
231
  const shiftKey = details.event?.shiftKey ?? false;
232
+ if (outsideSelect.current)
233
+ return outsideSelect.current.toggle(row, checked, shiftKey);
156
234
  const range = shiftKey && grouped ? groupedRange.current(row.id) : null;
157
235
  groupedAnchor.current = row.id;
158
236
  if (range)
@@ -178,10 +256,143 @@ export function DataTable({ columns, data, searchKey, searchPlaceholder = "Searc
178
256
  }, [columns, withSelection, grouped, fit, selectRowLabelId]);
179
257
  const [rowSelection, setRowSelection] = React.useState({});
180
258
  const [search, setSearch] = React.useState("");
259
+ // What is typed shows at once; with many rows, the search runs once typing pauses, so each key
260
+ // doesn't filter every row again.
261
+ const [typed, setTyped] = React.useState("");
262
+ React.useEffect(() => {
263
+ if (typed === search)
264
+ return;
265
+ if (!server && data.length < SEARCH_WAIT_FROM)
266
+ return setSearch(typed);
267
+ const id = setTimeout(() => setSearch(typed), SEARCH_WAIT);
268
+ return () => clearTimeout(id);
269
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- only a new text starts a search.
270
+ }, [typed]);
271
+ const [sorting, setSorting] = React.useState(initialSorting);
272
+ const [pagination, setPagination] = React.useState({ pageIndex: 0, pageSize });
273
+ /* Many rows: an order of row indices, sorted by each sorted column's ranks, then searched. */
274
+ const readers = React.useMemo(() => (outside ? leafReaders(columns) : new Map()), [outside, columns]);
275
+ const ranks = React.useMemo(() => new Map(), [data, readers, collator]);
276
+ const order = React.useMemo(() => {
277
+ if (!large)
278
+ return null;
279
+ // A column with its own `sortFn` is sorted by it, row against row: slower, but its order.
280
+ const own = sorting.find(({ id }) => typeof readers.get(id)?.def.sortFn === "function");
281
+ if (own) {
282
+ const rowOf = (i) => ({
283
+ id: String(i),
284
+ index: i,
285
+ original: data[i],
286
+ getValue: (columnId) => readers.get(columnId)?.read(data[i], i),
287
+ });
288
+ const order = Uint32Array.from(data, (_, i) => i);
289
+ return order.sort((a, b) => {
290
+ for (const { id, desc } of sorting) {
291
+ const reader = readers.get(id);
292
+ if (!reader)
293
+ continue;
294
+ const fn = reader.def.sortFn;
295
+ const result = typeof fn === "function"
296
+ ? fn(rowOf(a), rowOf(b), id)
297
+ : collator.compare(String(reader.read(data[a], a) ?? ""), String(reader.read(data[b], b) ?? ""));
298
+ if (result)
299
+ return desc ? -result : result;
300
+ }
301
+ return a - b;
302
+ });
303
+ }
304
+ const keys = sorting.flatMap(({ id, desc }) => {
305
+ const reader = readers.get(id);
306
+ if (!reader)
307
+ return [];
308
+ let r = ranks.get(id);
309
+ if (!r)
310
+ ranks.set(id, (r = columnRanks(data.length, (i) => reader.read(data[i], i), collator)));
311
+ return [{ ranks: r, desc }];
312
+ });
313
+ return sortedOrder(data.length, keys);
314
+ }, [large, data, sorting, readers, ranks, collator]);
315
+ // Each row's searchable text, read once, the first time something is searched.
316
+ const lines = React.useRef(null);
317
+ const found = React.useMemo(() => {
318
+ if (!order)
319
+ return null;
320
+ if (!search)
321
+ return order;
322
+ const key = [data, readers, searchKey];
323
+ if (!lines.current || lines.current.key.some((k, i) => k !== key[i])) {
324
+ const sample = data[0];
325
+ const searched = [...readers.values()].filter((reader) => searchKey
326
+ ? reader.id === searchKey
327
+ : reader.def.enableGlobalFilter !== false &&
328
+ sample !== undefined &&
329
+ ["string", "number"].includes(typeof reader.read(sample, 0)));
330
+ lines.current = {
331
+ key,
332
+ lines: searchLines(data.length, searched.map((reader) => (i) => reader.read(data[i], i))),
333
+ };
334
+ }
335
+ return matching(order, lines.current.lines, search);
336
+ }, [order, search, data, readers, searchKey]);
337
+ /* Rows from a server, a CHUNK at a time, cached until the sorting or the search change. */
338
+ const [served, setServed] = React.useState({
339
+ total: null,
340
+ error: null,
341
+ version: 0,
342
+ });
343
+ const queryKey = server ? JSON.stringify([sorting, search, searchKey]) : "";
344
+ const cache = React.useMemo(() => ({ chunks: new Map(), pending: new Map() }),
345
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- a new query starts an empty cache.
346
+ [queryKey, fetchRows]);
347
+ // Cleared as well as aborted: StrictMode's second mount, or a remount, asks for those rows again.
348
+ React.useEffect(() => () => {
349
+ cache.pending.forEach((controller) => controller.abort());
350
+ cache.pending.clear();
351
+ }, [cache]);
352
+ const fetchRef = React.useRef(fetchRows);
353
+ fetchRef.current = fetchRows;
354
+ const lastRange = React.useRef([0, CHUNK]);
355
+ const load = React.useCallback((from, to) => {
356
+ lastRange.current = [from, to];
357
+ const fetcher = fetchRef.current;
358
+ if (!fetcher)
359
+ return;
360
+ // Never past the end of the result, once it is known.
361
+ const end = totalRef.current == null ? to : Math.min(to, totalRef.current);
362
+ for (let c = Math.floor(from / CHUNK); c * CHUNK < Math.max(end, from + 1); c++) {
363
+ if (cache.chunks.has(c) || cache.pending.has(c))
364
+ continue;
365
+ const controller = new AbortController();
366
+ cache.pending.set(c, controller);
367
+ fetcher({
368
+ start: c * CHUNK,
369
+ end: (c + 1) * CHUNK,
370
+ sorting,
371
+ search,
372
+ searchKey,
373
+ signal: controller.signal,
374
+ })
375
+ .then((result) => {
376
+ if (controller.signal.aborted)
377
+ return;
378
+ cache.chunks.set(c, result.rows);
379
+ setServed((old) => ({ total: result.total, error: null, version: old.version + 1 }));
380
+ })
381
+ .catch((error) => {
382
+ if (!controller.signal.aborted)
383
+ setServed((old) => ({ ...old, error, version: old.version + 1 }));
384
+ })
385
+ .finally(() => {
386
+ if (cache.pending.get(c) === controller)
387
+ cache.pending.delete(c);
388
+ });
389
+ }
390
+ }, [cache, sorting, search, searchKey]);
181
391
  // TanStack sorts again only when the sorting or the rows change, so a new locale hands it the rows
182
392
  // as a new array.
183
- const stableData = React.useMemo(() => [...data], [data, collator]);
184
- const grouping = React.useMemo(() => (groupBy ? [groupBy] : []), [groupBy]);
393
+ const stableData = React.useMemo(() => (outside ? NO_ROWS : [...data]), [data, collator, outside]);
394
+ const outsideCount = server ? (served.total ?? 0) : (found?.length ?? 0);
395
+ const grouping = React.useMemo(() => (grouped ? [groupBy] : []), [grouped, groupBy]);
185
396
  const columnFilters = React.useMemo(() => (searchKey && search ? [{ id: searchKey, value: search }] : []), [searchKey, search]);
186
397
  const globalFilter = searchKey ? "" : search;
187
398
  const table = useTable({
@@ -194,21 +405,147 @@ export function DataTable({ columns, data, searchKey, searchPlaceholder = "Searc
194
405
  globalFilterFn: "includesString",
195
406
  enableMultiSort: true,
196
407
  initialState: {
197
- sorting: initialSorting,
198
408
  // The grouping column repeats the group header in every row, so it starts hidden.
199
- columnVisibility: groupBy ? { [groupBy]: false, ...initialColumnVisibility } : initialColumnVisibility,
200
- pagination: { pageIndex: 0, pageSize },
409
+ columnVisibility: grouped ? { [groupBy]: false, ...initialColumnVisibility } : initialColumnVisibility,
201
410
  },
202
411
  groupedColumnMode: false,
203
- state: { rowSelection, globalFilter, columnFilters, grouping },
412
+ // Many rows, or a server's: sorted, searched and paged here (above), not by TanStack.
413
+ manualSorting: outside,
414
+ manualFiltering: outside,
415
+ manualPagination: outside,
416
+ rowCount: outside ? outsideCount : undefined,
417
+ state: { rowSelection, globalFilter, columnFilters, grouping, sorting, pagination },
418
+ onSortingChange: (updater) => setSorting((prev) => functionalUpdate(updater, prev)),
419
+ onPaginationChange: (updater) => setPagination((prev) => functionalUpdate(updater, prev)),
204
420
  onRowSelectionChange: (updater) => setRowSelection((prev) => functionalUpdate(updater, prev)),
205
- onGlobalFilterChange: (updater) => setSearch((prev) => String(functionalUpdate(updater, prev) ?? "")),
421
+ onGlobalFilterChange: (updater) => {
422
+ const next = String(functionalUpdate(updater, search) ?? "");
423
+ setTyped(next);
424
+ setSearch(next);
425
+ },
206
426
  onColumnFiltersChange: (updater) => {
207
427
  const next = functionalUpdate(updater, columnFilters);
208
428
  const value = next.find((filter) => filter.id === searchKey)?.value;
429
+ setTyped(typeof value === "string" ? value : "");
209
430
  setSearch(typeof value === "string" ? value : "");
210
431
  },
211
432
  });
433
+ /* Many rows, or a server's: this page's rows (all of them, in a virtual table) — as data, with
434
+ `undefined` for a server's rows on their way — and TanStack rows built only for those drawn. */
435
+ const pageStart = pagination.pageIndex * pagination.pageSize;
436
+ const pageEnd = pageStart + pagination.pageSize;
437
+ // A server's rows are one array per query and size, filled in where they belong as they arrive,
438
+ // so a virtual body reads each new run without going over all the others.
439
+ const serverRows = React.useMemo(() => {
440
+ if (!server)
441
+ return null;
442
+ const count = served.total == null
443
+ ? Math.min(pagination.pageSize, 10)
444
+ : Math.max(0, Math.min(pageEnd, served.total) - pageStart);
445
+ return { rows: new Array(count), filled: new Set() };
446
+ }, [server, served.total, cache, pageStart, pageEnd, pagination.pageSize]);
447
+ if (serverRows)
448
+ for (const [c, chunk] of cache.chunks) {
449
+ if (serverRows.filled.has(c))
450
+ continue;
451
+ serverRows.filled.add(c);
452
+ chunk.forEach((row, j) => {
453
+ const k = c * CHUNK + j - pageStart;
454
+ if (k >= 0 && k < serverRows.rows.length)
455
+ serverRows.rows[k] = row;
456
+ });
457
+ }
458
+ const outsideRows = React.useMemo(() => found
459
+ ? Array.from(found.subarray(pageStart, Math.min(pageEnd, found.length)), (i) => data[i])
460
+ : (serverRows?.rows ?? NO_ROWS), [found, data, serverRows, pageStart, pageEnd]);
461
+ /** The row's index: in `data` (many rows) or in the server's result. */
462
+ const indexAt = (k) => (found ? found[pageStart + k] : pageStart + k);
463
+ const idAt = (k, original) => {
464
+ const index = indexAt(k);
465
+ return getRowId ? getRowId(original, index) : String(index);
466
+ };
467
+ const built = React.useMemo(() => new Map(), [table, allColumns, data, cache]);
468
+ const positions = React.useRef(new WeakMap());
469
+ /** A server's rows seen so far, by id: what a selection reports. */
470
+ const seen = React.useRef(new Map());
471
+ const rowAt = (k, original) => {
472
+ const id = idAt(k, original);
473
+ let row = built.get(id);
474
+ if (!row || row.original !== original) {
475
+ row = constructRow(table, id, original, indexAt(k), 0);
476
+ built.set(id, row);
477
+ }
478
+ positions.current.set(row, k);
479
+ if (server)
480
+ seen.current.set(id, original);
481
+ return row;
482
+ };
483
+ // A server table loads the page it shows; a virtual one, the rows as they come into view.
484
+ const totalRef = React.useRef(served.total);
485
+ totalRef.current = served.total;
486
+ React.useEffect(() => {
487
+ if (server)
488
+ load(pageStart, Math.min(pageEnd, pageStart + Math.min(pagination.pageSize, CHUNK * 2)));
489
+ }, [server, load, pageStart, pageEnd, pagination.pageSize]);
490
+ // Data indices by id, for reporting a selection of many rows by their data.
491
+ const indexById = React.useRef(null);
492
+ const originalOf = (id) => {
493
+ if (server)
494
+ return seen.current.get(id);
495
+ if (!getRowId)
496
+ return data[Number(id)];
497
+ if (indexById.current?.data !== data)
498
+ indexById.current = { data, ids: new Map(data.map((row, i) => [getRowId(row, i), i])) };
499
+ const i = indexById.current.ids.get(id);
500
+ return i === undefined ? undefined : data[i];
501
+ };
502
+ const selectedIds = Object.keys(rowSelection).filter((id) => rowSelection[id]);
503
+ const anchor = React.useRef(null);
504
+ if (outside && withSelection) {
505
+ const all = !!found &&
506
+ found.length > 0 &&
507
+ selectedIds.length >= found.length &&
508
+ Array.prototype.every.call(found, (i) => rowSelection[getRowId ? getRowId(data[i], i) : String(i)]);
509
+ outsideSelect.current = {
510
+ all,
511
+ some: selectedIds.length > 0 && !all,
512
+ toggleAll: found
513
+ ? (checked) => setRowSelection((old) => {
514
+ const next = { ...old };
515
+ for (const i of found) {
516
+ const id = getRowId ? getRowId(data[i], i) : String(i);
517
+ if (checked)
518
+ next[id] = true;
519
+ else
520
+ delete next[id];
521
+ }
522
+ return next;
523
+ })
524
+ : undefined,
525
+ // Shift-click selects the run of rows from the last one toggled, in the order shown.
526
+ toggle: (row, checked, shiftKey) => {
527
+ const at = positions.current.get(row) ?? -1;
528
+ const from = shiftKey && anchor.current?.rows === outsideRows ? anchor.current.at : at;
529
+ anchor.current = { at, rows: outsideRows };
530
+ setRowSelection((old) => {
531
+ const next = { ...old };
532
+ for (let k = Math.min(from, at); k <= Math.max(from, at); k++) {
533
+ const original = outsideRows[k];
534
+ if (original === undefined)
535
+ continue;
536
+ const id = idAt(k, original);
537
+ if (checked)
538
+ next[id] = true;
539
+ else
540
+ delete next[id];
541
+ }
542
+ return next;
543
+ });
544
+ },
545
+ };
546
+ }
547
+ else
548
+ outsideSelect.current = null;
212
549
  // Report selection changes (not the initial empty selection).
213
550
  const onSelectionRef = React.useRef(onRowSelectionChange);
214
551
  onSelectionRef.current = onRowSelectionChange;
@@ -218,7 +555,12 @@ export function DataTable({ columns, data, searchKey, searchPlaceholder = "Searc
218
555
  firstSelection.current = false;
219
556
  return;
220
557
  }
221
- onSelectionRef.current?.(table.getSelectedRowModel().rows.map((row) => row.original));
558
+ onSelectionRef.current?.(outside
559
+ ? selectedIds.flatMap((id) => {
560
+ const original = originalOf(id);
561
+ return original === undefined ? [] : [original];
562
+ })
563
+ : table.getSelectedRowModel().rows.map((row) => row.original));
222
564
  // eslint-disable-next-line react-hooks/exhaustive-deps
223
565
  }, [rowSelection]);
224
566
  const { pageIndex, pageSize: currentPageSize } = table.state.pagination;
@@ -246,28 +588,34 @@ export function DataTable({ columns, data, searchKey, searchPlaceholder = "Searc
246
588
  visibleColumns.find((column) => column.id !== "select"))?.id
247
589
  : undefined;
248
590
  const hideableColumns = table.getAllLeafColumns().filter((column) => column.getCanHide());
249
- const selectedCount = withSelection ? Object.values(rowSelection).filter(Boolean).length : 0;
591
+ const selectedCount = withSelection ? selectedIds.length : 0;
250
592
  const pageSizes = pageSizeOptions.includes(currentPageSize)
251
593
  ? pageSizeOptions
252
594
  : [...pageSizeOptions, currentPageSize].sort((a, b) => a - b);
253
595
  // Decided by how many rows could show, not by how many match the search, so a search never
254
596
  // switches it on and off.
255
- const virtual = virtualize ?? (grouped ? data.length : Math.min(currentPageSize, data.length)) > VIRTUAL_FROM;
597
+ const virtual = virtualize ??
598
+ (grouped ? data.length : Math.min(currentPageSize, outside ? outsideCount : data.length)) > VIRTUAL_FROM;
256
599
  // The rows that size the columns of a virtual table: the longest values of all the data, so the
257
600
  // columns hold still while it scrolls, sorts and is searched.
258
601
  const visibleIds = visibleColumns.map((column) => column.id).join("\n");
259
602
  const sizeRows = React.useMemo(() => {
260
- if (!virtual)
603
+ if (!virtual || outside)
261
604
  return undefined;
262
605
  const all = table.getCoreRowModel().rows;
263
606
  const ids = visibleIds.split("\n").filter((id) => table.getColumn(id)?.accessorFn);
264
607
  return widestRows(all, (row) => ids.map((id) => row.getValue(id))).map((i) => all[i]);
265
608
  // eslint-disable-next-line react-hooks/exhaustive-deps -- `data` and `visibleIds` stand for the rows and columns.
266
- }, [virtual, data, visibleIds]);
609
+ }, [virtual, outside, data, visibleIds]);
267
610
  const renderRow = (row) => (_jsx(TableRow, { "data-selected": row.getIsSelected() ? "" : undefined, "data-state": row.getIsSelected() ? "selected" : undefined, children: row.getVisibleCells().map((cell) => {
268
611
  const meta = cell.column.columnDef.meta;
269
612
  return (_jsx(TableCell, { numeric: meta?.numeric, className: meta?.className, children: _jsx(table.FlexRender, { cell: cell }) }, cell.id));
270
613
  }) }, row.id));
614
+ /** A row on its way from the server: a placeholder bar in each cell. */
615
+ const loadingRow = (k) => (_jsx(TableRow, { "data-slot": "data-table-loading", "aria-busy": "true", children: visibleColumns.map((column) => (_jsx(TableCell, { children: _jsx(Skeleton, { className: "h-3.5 w-3/5 max-w-40 rounded-checkbox" }) }, column.id))) }, `loading-${k}`));
616
+ const renderOutside = (original, k) => original === undefined ? loadingRow(k) : renderRow(rowAt(k, original));
617
+ const outsideKey = (original, k) => original === undefined ? `loading-${k}` : idAt(k, original);
618
+ const empty = outside ? outsideRows.length === 0 : !rows.length;
271
619
  const groupHeader = (group) => {
272
620
  const groupCell = groupBy ? group.getAllCellsByColumnId()[groupBy] : undefined;
273
621
  return (_jsx(TableGroupHeader, { colSpan: visibleColumnCount, count: group.subRows.length, sticky: stickyGroupHeaders, summary: groupSummary?.({
@@ -275,12 +623,12 @@ export function DataTable({ columns, data, searchKey, searchPlaceholder = "Searc
275
623
  rows: group.subRows.map((row) => row.original),
276
624
  }), children: groupCell ? _jsx(table.FlexRender, { cell: groupCell }) : String(group.groupingValue) }));
277
625
  };
278
- return (_jsxs("div", { "data-slot": "data-table", "data-dense": dense ? "" : undefined, "data-variant": variant, className: cn("flex w-full min-w-0 flex-col", dense ? "gap-3" : "gap-4", className), ...props, children: [withSelection ? (_jsx("span", { id: selectRowLabelId, hidden: true, children: "Select row" })) : null, searchable || columnToggle || toolbar ? (_jsxs("div", { "data-slot": "data-table-toolbar", "data-collapse-row": "", className: cn("flex flex-wrap items-center gap-2", variant === "plain" && "px-6"), children: [searchable ? (_jsxs("div", { "data-slot": "data-table-search",
626
+ return (_jsxs("div", { "data-slot": "data-table", "data-dense": dense ? "" : undefined, "aria-busy": (server && cache.pending.size > 0) || undefined, "data-variant": variant, className: cn("flex w-full min-w-0 flex-col", dense ? "gap-3" : "gap-4", className), ...props, children: [withSelection ? (_jsx("span", { id: selectRowLabelId, hidden: true, children: text.selectRow })) : null, searchable || columnToggle || toolbar ? (_jsxs("div", { "data-slot": "data-table-toolbar", "data-collapse-row": "", className: cn("flex flex-wrap items-center gap-2", variant === "plain" && "px-6"), children: [searchable ? (_jsxs("div", { "data-slot": "data-table-search",
279
627
  // Its real minimum, for the collapse row (data.css lets it lend room while a fold runs).
280
- className: "relative w-full max-w-72 min-w-40 flex-1 [--collapse-min:10rem]", children: [_jsx("label", { htmlFor: searchId, className: "sr-only", children: searchPlaceholder.replace(/…$/, "") }), _jsx(SearchIcon, { "aria-hidden": true, className: cn("pointer-events-none absolute top-1/2 size-4 -translate-y-1/2 text-muted-foreground", dense ? "start-2.5" : "start-3") }), _jsx(Input, { id: searchId, type: "search", size: size, value: search, placeholder: searchPlaceholder, onChange: (event) => {
281
- setSearch(event.currentTarget.value);
628
+ className: "relative w-full max-w-72 min-w-40 flex-1 [--collapse-min:10rem]", children: [_jsx("label", { htmlFor: searchId, className: "sr-only", children: searchPlaceholder.replace(/\s*…$/, "") }), _jsx(SearchIcon, { "aria-hidden": true, className: cn("pointer-events-none absolute top-1/2 size-4 -translate-y-1/2 text-muted-foreground", dense ? "start-2.5" : "start-3") }), _jsx(Input, { id: searchId, type: "search", size: size, value: typed, placeholder: searchPlaceholder, onChange: (event) => {
629
+ setTyped(event.currentTarget.value);
282
630
  table.setPageIndex(0);
283
- }, className: dense ? "ps-8" : "ps-9" })] })) : null, _jsxs("div", { className: "ms-auto flex items-center gap-2", children: [toolbar, columnToggle && hideableColumns.length > 0 ? (_jsxs(Menu, { children: [_jsxs(MenuTrigger, { render: _jsx(Button, { variant: "secondary", size: size, collapsible: true }), children: [_jsx(Columns3Icon, {}), "Columns"] }), _jsx(MenuContent, { align: "end", className: "min-w-48", children: _jsxs(MenuGroup, { children: [_jsx(MenuGroupLabel, { children: "Show columns" }), hideableColumns.map((column) => (_jsx(MenuCheckboxItem, { checked: column.getIsVisible(), onCheckedChange: (checked) => column.toggleVisibility(checked), children: columnLabel(column) }, column.id)))] }) })] })) : null] })] })) : null, _jsxs(Table, { dense: dense, variant: variant, fit: fit, "aria-label": caption ? undefined : label, containerProps: tableContainerProps, children: [caption ? _jsx(TableCaption, { children: caption }) : null, _jsx(TableHeader, { children: table.getHeaderGroups().map((group) => (_jsx(TableRow, { children: group.headers.map((header) => {
631
+ }, className: dense ? "ps-8" : "ps-9" })] })) : null, _jsxs("div", { className: "ms-auto flex items-center gap-2", children: [toolbar, columnToggle && hideableColumns.length > 0 ? (_jsxs(Menu, { children: [_jsxs(MenuTrigger, { render: _jsx(Button, { variant: "secondary", size: size, collapsible: true }), children: [_jsx(Columns3Icon, {}), text.columns] }), _jsx(MenuContent, { align: "end", className: "min-w-48", children: _jsxs(MenuGroup, { children: [_jsx(MenuGroupLabel, { children: text.showColumns }), hideableColumns.map((column) => (_jsx(MenuCheckboxItem, { checked: column.getIsVisible(), onCheckedChange: (checked) => column.toggleVisibility(checked), children: columnLabel(column) }, column.id)))] }) })] })) : null] })] })) : null, _jsxs(Table, { dense: dense, variant: variant, fit: fit, "aria-label": caption ? undefined : label, containerProps: tableContainerProps, children: [caption ? _jsx(TableCaption, { children: caption }) : null, _jsx(TableHeader, { children: table.getHeaderGroups().map((group) => (_jsx(TableRow, { children: group.headers.map((header) => {
284
632
  const column = header.column;
285
633
  const meta = column.columnDef.meta;
286
634
  const sorted = column.getIsSorted();
@@ -288,7 +636,7 @@ export function DataTable({ columns, data, searchKey, searchPlaceholder = "Searc
288
636
  return (_jsx(TableHead, { colSpan: header.colSpan, numeric: meta?.numeric, align: meta?.align, priority: meta?.priority, inline: meta?.inline, minWidth: meta?.minWidth, width: meta?.width, titleColumn: column.id === titleColumnId, "aria-sort": sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : undefined, className: meta?.className, children: header.isPlaceholder ? null : canSort ? (_jsxs("button", { type: "button", "data-slot": "data-table-sort", "data-sorted": sorted || undefined, onClick: column.getToggleSortingHandler(), className: cn("group/sort inline-flex min-h-(--control-h-sm) cursor-pointer items-center gap-1.5 rounded-item material-row px-2 font-mono text-[12px] tracking-[0.18em] uppercase focus-ring select-none", meta?.numeric ? "-me-2 flex-row-reverse" : "-ms-2"), children: [_jsx("span", { className: cn("transition-colors duration-(--duration) ease-(--ease)", sorted
289
637
  ? "text-foreground"
290
638
  : "text-muted-foreground group-hover/sort:text-foreground"), children: _jsx(table.FlexRender, { header: header }) }), _jsx(SortIcon, { direction: sorted })] })) : (_jsx(table.FlexRender, { header: header })) }, header.id));
291
- }) }, group.id))) }), !rows.length ? (_jsx(TableBody, { children: _jsx(TableRow, { "data-slot": "data-table-empty", className: "hover:bg-transparent", children: _jsx(TableCell, { colSpan: visibleColumnCount, className: "h-24 text-center text-sm text-muted-foreground", children: emptyMessage }) }) })) : virtual ? (_jsx(TableVirtualBody, { ...(grouped
639
+ }) }, group.id))) }), empty ? (_jsx(TableBody, { children: _jsx(TableRow, { "data-slot": "data-table-empty", className: "hover:bg-transparent", children: _jsx(TableCell, { colSpan: visibleColumnCount, className: "h-24 text-center text-sm text-muted-foreground", children: emptyMessage }) }) })) : virtual && outside ? (_jsx(TableVirtualBody, { rows: outsideRows, getRowKey: outsideKey, renderRow: renderOutside, scrollResetKey: search, onRangeChange: server ? (from, to) => load(pageStart + from, pageStart + to) : undefined })) : outside ? (_jsx(TableBody, { children: outsideRows.map(renderOutside) })) : virtual ? (_jsx(TableVirtualBody, { ...(grouped
292
640
  ? {
293
641
  groups: rows.map((group) => ({
294
642
  key: group.id,
@@ -298,5 +646,10 @@ export function DataTable({ columns, data, searchKey, searchPlaceholder = "Searc
298
646
  onOpenChange: (open) => setGroupOpen(group.id, open),
299
647
  })),
300
648
  }
301
- : { rows }), getRowKey: rowKeyOf, renderRow: renderRow, sizeRows: sizeRows, scrollResetKey: search })) : grouped ? (rows.map((group) => (_jsxs(TableGroup, { open: !closedGroups.has(group.id), onOpenChange: (open) => setGroupOpen(group.id, open), children: [groupHeader(group), group.subRows.map(renderRow)] }, group.id)))) : (_jsx(TableBody, { children: rows.map(renderRow) }))] }), _jsxs("div", { "data-slot": "data-table-footer", className: cn("flex flex-wrap items-center justify-between gap-x-6 gap-y-3 font-mono text-xs text-muted-foreground tabular-nums", variant === "plain" && "px-6"), children: [_jsx("div", { "aria-live": "polite", children: withSelection ? `${selectedCount} of ${data.length} selected` : null }), grouped ? (_jsxs("span", { "data-slot": "data-table-count", "aria-live": "polite", children: [leafRowCount, " ", leafRowCount === 1 ? "row" : "rows", " in ", rows.length, " ", rows.length === 1 ? "group" : "groups"] })) : (_jsxs("div", { className: "flex flex-wrap items-center gap-x-5 gap-y-2", children: [pageSizes.length > 1 ? (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { id: `${searchId}-rows`, children: "Rows" }), _jsxs(Select, { value: currentPageSize, onValueChange: (value) => value != null && table.setPageSize(Number(value)), items: pageSizes.map((n) => ({ value: n, label: String(n) })), children: [_jsx(SelectTrigger, { size: "sm", "aria-labelledby": `${searchId}-rows`, className: "w-auto min-w-0 gap-2 font-mono tabular-nums", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: pageSizes.map((n) => (_jsx(SelectItem, { value: n, className: "font-mono tabular-nums", children: n }, n))) })] })] })) : null, _jsxs("span", { "data-slot": "data-table-count", "aria-live": "polite", children: [first, "\u2013", last, " of ", total] }), _jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx(Button, { variant: "secondary", size: size, "aria-label": "Previous page", disabled: !table.getCanPreviousPage(), onClick: () => table.previousPage(), className: dense ? "min-w-(--control-h-sm) px-2" : "min-w-(--control-h) px-2.5", children: _jsx(ChevronLeftIcon, { className: "rtl:-scale-x-100" }) }), _jsx(Button, { variant: "secondary", size: size, "aria-label": "Next page", disabled: !table.getCanNextPage(), onClick: () => table.nextPage(), className: dense ? "min-w-(--control-h-sm) px-2" : "min-w-(--control-h) px-2.5", children: _jsx(ChevronRightIcon, { className: "rtl:-scale-x-100" }) })] })] }))] })] }));
649
+ : { rows }), getRowKey: rowKeyOf, renderRow: renderRow, sizeRows: sizeRows, scrollResetKey: search })) : grouped ? (rows.map((group) => (_jsxs(TableGroup, { open: !closedGroups.has(group.id), onOpenChange: (open) => setGroupOpen(group.id, open), children: [groupHeader(group), group.subRows.map(renderRow)] }, group.id)))) : (_jsx(TableBody, { children: rows.map(renderRow) }))] }), _jsxs("div", { "data-slot": "data-table-footer", className: cn("flex flex-wrap items-center justify-between gap-x-6 gap-y-3 font-mono text-xs text-muted-foreground tabular-nums", variant === "plain" && "px-6"), children: [_jsx("div", { "aria-live": "polite", children: server && served.error ? (_jsxs("span", { "data-slot": "data-table-error", className: "flex items-center gap-2", children: [text.loadError, _jsx(Button, { variant: "link", size: "sm", onClick: () => {
650
+ setServed((old) => ({ ...old, error: null }));
651
+ load(...lastRange.current);
652
+ }, children: text.retry })] })) : withSelection ? (text.selected(selectedCount, server ? (served.total ?? 0) : data.length)) : null }), grouped ? (_jsx("span", { "data-slot": "data-table-count", "aria-live": "polite", children: text.groupCount(leafRowCount, rows.length) })) : (_jsxs("div", { className: "flex flex-wrap items-center gap-x-5 gap-y-2", children: [pageSizes.length > 1 ? (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { id: `${searchId}-rows`, children: text.rowsPerPage }), _jsxs(Select, { value: currentPageSize, onValueChange: (value) => value != null && table.setPageSize(Number(value)), items: pageSizes.map((n) => ({ value: n, label: String(n) })), children: [_jsx(SelectTrigger, { size: "sm", "aria-labelledby": `${searchId}-rows`, className: "w-auto min-w-0 gap-2 font-mono tabular-nums", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: pageSizes.map((n) => (_jsx(SelectItem, { value: n, className: "font-mono tabular-nums", children: n }, n))) })] })] })) : null, _jsx("span", { "data-slot": "data-table-count", "aria-live": "polite", children: text.range(first, last, total) }), _jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx(Button, { variant: "secondary", size: size, "aria-label": text.previous, disabled: !table.getCanPreviousPage(),
653
+ // Keeps focus on the button at the first and last page, as Pagination does.
654
+ focusableWhenDisabled: true, onClick: () => table.previousPage(), className: dense ? "min-w-(--control-h-sm) px-2" : "min-w-(--control-h) px-2.5", children: _jsx(ChevronLeftIcon, { className: "rtl:-scale-x-100" }) }), _jsx(Button, { variant: "secondary", size: size, "aria-label": text.next, disabled: !table.getCanNextPage(), focusableWhenDisabled: true, onClick: () => table.nextPage(), className: dense ? "min-w-(--control-h-sm) px-2" : "min-w-(--control-h) px-2.5", children: _jsx(ChevronRightIcon, { className: "rtl:-scale-x-100" }) })] })] }))] })] }));
302
655
  }