@fuf-stack/megapixels 0.13.5 → 0.14.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 (50) hide show
  1. package/dist/DataTable/index.cjs +8 -0
  2. package/dist/DataTable/index.d.cts +2 -0
  3. package/dist/DataTable/index.d.ts +2 -0
  4. package/dist/DataTable/index.js +2 -0
  5. package/dist/DataTable-CF0oifeL.cjs +1166 -0
  6. package/dist/DataTable-CF0oifeL.cjs.map +1 -0
  7. package/dist/DataTable-Da6WZFKm.js +1145 -0
  8. package/dist/DataTable-Da6WZFKm.js.map +1 -0
  9. package/dist/Filter/index.cjs +1 -1
  10. package/dist/Filter/index.d.cts +1 -1
  11. package/dist/Filter/index.d.ts +1 -1
  12. package/dist/Filter/index.js +1 -1
  13. package/dist/{Filter-faDLPGFC.cjs → Filter-CbApjj6y.cjs} +41 -50
  14. package/dist/Filter-CbApjj6y.cjs.map +1 -0
  15. package/dist/{Filter-BKfVjFPo.js → Filter-DNj4lzj5.js} +35 -23
  16. package/dist/Filter-DNj4lzj5.js.map +1 -0
  17. package/dist/VirtualList/index.cjs +8 -0
  18. package/dist/VirtualList/index.d.cts +2 -0
  19. package/dist/VirtualList/index.d.ts +2 -0
  20. package/dist/VirtualList/index.js +2 -0
  21. package/dist/VirtualList-BALnlyjy.cjs +172 -0
  22. package/dist/VirtualList-BALnlyjy.cjs.map +1 -0
  23. package/dist/VirtualList-DQ4uR-wR.js +153 -0
  24. package/dist/VirtualList-DQ4uR-wR.js.map +1 -0
  25. package/dist/index-BGYzDspd.d.cts +5192 -0
  26. package/dist/index-BGYzDspd.d.cts.map +1 -0
  27. package/dist/index-Crb5hCFD.d.ts +5192 -0
  28. package/dist/index-Crb5hCFD.d.ts.map +1 -0
  29. package/dist/index-D7ZLM0zx.d.cts +1141 -0
  30. package/dist/index-D7ZLM0zx.d.cts.map +1 -0
  31. package/dist/{index-CgoXcO8f.d.cts → index-DCiYTnRL.d.ts} +22 -12
  32. package/dist/{index-E2k5kJ14.d.ts.map → index-DCiYTnRL.d.ts.map} +1 -1
  33. package/dist/{index-E2k5kJ14.d.ts → index-FDKfDW98.d.cts} +21 -11
  34. package/dist/{index-CgoXcO8f.d.cts.map → index-FDKfDW98.d.cts.map} +1 -1
  35. package/dist/index-jFySXsl9.d.ts +1141 -0
  36. package/dist/index-jFySXsl9.d.ts.map +1 -0
  37. package/dist/index.cjs +7 -1
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.cts +4 -2
  40. package/dist/index.d.ts +4 -2
  41. package/dist/index.js +4 -2
  42. package/dist/index.js.map +1 -1
  43. package/dist/rolldown-runtime-D6vf50IK.cjs +28 -0
  44. package/dist/useInfiniteVirtualizer-BK0VroW4.cjs +175 -0
  45. package/dist/useInfiniteVirtualizer-BK0VroW4.cjs.map +1 -0
  46. package/dist/useInfiniteVirtualizer-BSCDrdRi.js +170 -0
  47. package/dist/useInfiniteVirtualizer-BSCDrdRi.js.map +1 -0
  48. package/package.json +15 -4
  49. package/dist/Filter-BKfVjFPo.js.map +0 -1
  50. package/dist/Filter-faDLPGFC.cjs.map +0 -1
@@ -0,0 +1,1166 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
2
+ const require_useInfiniteVirtualizer = require("./useInfiniteVirtualizer-BK0VroW4.cjs");
3
+ let react = require("react");
4
+ let _fuf_stack_pixel_utils = require("@fuf-stack/pixel-utils");
5
+ let _fuf_stack_pixels_ScrollShadow = require("@fuf-stack/pixels/ScrollShadow");
6
+ _fuf_stack_pixels_ScrollShadow = require_rolldown_runtime.__toESM(_fuf_stack_pixels_ScrollShadow, 1);
7
+ let _tanstack_react_table = require("@tanstack/react-table");
8
+ let _fuf_stack_pixels_Button = require("@fuf-stack/pixels/Button");
9
+ _fuf_stack_pixels_Button = require_rolldown_runtime.__toESM(_fuf_stack_pixels_Button, 1);
10
+ let _base_ui_react_checkbox = require("@base-ui/react/checkbox");
11
+ let react_jsx_runtime = require("react/jsx-runtime");
12
+ let _fuf_stack_pixels_Menu = require("@fuf-stack/pixels/Menu");
13
+ _fuf_stack_pixels_Menu = require_rolldown_runtime.__toESM(_fuf_stack_pixels_Menu, 1);
14
+ let react_icons_lu = require("react-icons/lu");
15
+ //#region src/DataTable/Subcomponents/DataTableCheckbox.tsx
16
+ /** Small checkbox wrapper used by DataTable selection UI. */
17
+ const DataTableCheckbox = ({ ariaLabel, checked, className = void 0, checkedIcon = "✓", indeterminate = false, indeterminateIcon = "−", onCheckedChange, testId = void 0 }) => {
18
+ const indicatorIcon = indeterminate ? indeterminateIcon : checkedIcon;
19
+ const resolvedIndicatorIcon = indicatorIcon === false ? null : indicatorIcon;
20
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_checkbox.Checkbox.Root, {
21
+ "aria-label": ariaLabel,
22
+ checked,
23
+ className: className?.checkbox,
24
+ "data-slot": "checkbox",
25
+ "data-testid": testId,
26
+ indeterminate,
27
+ onCheckedChange: (nextChecked) => {
28
+ onCheckedChange(Boolean(nextChecked));
29
+ },
30
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_checkbox.Checkbox.Indicator, {
31
+ className: className?.checkboxIndicator,
32
+ "data-slot": "checkbox-indicator",
33
+ children: resolvedIndicatorIcon
34
+ })
35
+ });
36
+ };
37
+ //#endregion
38
+ //#region src/DataTable/hooks/useDataTableController.tsx
39
+ /** Stable id used for the injected row-selection column. */
40
+ const SELECTION_COLUMN_ID = "__select";
41
+ /** Stable id used for the injected row-expansion column. */
42
+ const EXPANSION_COLUMN_ID = "__expand";
43
+ const SortAscendingIcon = () => {
44
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
45
+ "aria-hidden": "true",
46
+ fill: "none",
47
+ focusable: "false",
48
+ height: "14",
49
+ viewBox: "0 0 16 16",
50
+ width: "14",
51
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
52
+ d: "M8 13V3",
53
+ stroke: "currentColor",
54
+ strokeLinecap: "round",
55
+ strokeLinejoin: "round",
56
+ strokeWidth: "1.75"
57
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
58
+ d: "M4.5 6.5 8 3l3.5 3.5",
59
+ stroke: "currentColor",
60
+ strokeLinecap: "round",
61
+ strokeLinejoin: "round",
62
+ strokeWidth: "1.75"
63
+ })]
64
+ });
65
+ };
66
+ const SortDescendingIcon = () => {
67
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
68
+ "aria-hidden": "true",
69
+ fill: "none",
70
+ focusable: "false",
71
+ height: "14",
72
+ viewBox: "0 0 16 16",
73
+ width: "14",
74
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
75
+ d: "M8 3v10",
76
+ stroke: "currentColor",
77
+ strokeLinecap: "round",
78
+ strokeLinejoin: "round",
79
+ strokeWidth: "1.75"
80
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
81
+ d: "M4.5 9.5 8 13l3.5-3.5",
82
+ stroke: "currentColor",
83
+ strokeLinecap: "round",
84
+ strokeLinejoin: "round",
85
+ strokeWidth: "1.75"
86
+ })]
87
+ });
88
+ };
89
+ const SortUnsortedIcon = () => {
90
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
91
+ "aria-hidden": "true",
92
+ fill: "none",
93
+ focusable: "false",
94
+ height: "14",
95
+ viewBox: "0 0 16 16",
96
+ width: "14",
97
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
98
+ d: "M5 6 8 3l3 3",
99
+ stroke: "currentColor",
100
+ strokeLinecap: "round",
101
+ strokeLinejoin: "round",
102
+ strokeWidth: "1.75"
103
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
104
+ d: "M5 10l3 3 3-3",
105
+ stroke: "currentColor",
106
+ strokeLinecap: "round",
107
+ strokeLinejoin: "round",
108
+ strokeWidth: "1.75"
109
+ })]
110
+ });
111
+ };
112
+ const RowCollapsedIcon = () => {
113
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
114
+ "aria-hidden": "true",
115
+ fill: "none",
116
+ focusable: "false",
117
+ height: "14",
118
+ viewBox: "0 0 16 16",
119
+ width: "14",
120
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
121
+ d: "m6 4 4 4-4 4",
122
+ stroke: "currentColor",
123
+ strokeLinecap: "round",
124
+ strokeLinejoin: "round",
125
+ strokeWidth: "1.75"
126
+ })
127
+ });
128
+ };
129
+ const RowExpandedIcon = () => {
130
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
131
+ "aria-hidden": "true",
132
+ fill: "none",
133
+ focusable: "false",
134
+ height: "14",
135
+ viewBox: "0 0 16 16",
136
+ width: "14",
137
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
138
+ d: "m4 6 4 4 4-4",
139
+ stroke: "currentColor",
140
+ strokeLinecap: "round",
141
+ strokeLinejoin: "round",
142
+ strokeWidth: "1.75"
143
+ })
144
+ });
145
+ };
146
+ /** Builds the optional leading expansion column used by DataTable. */
147
+ const createExpansionColumn = (classNames, icons) => {
148
+ return {
149
+ cell: ({ row }) => {
150
+ const isExpanded = row.getIsExpanded();
151
+ const icon = isExpanded ? icons?.expanded ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RowExpandedIcon, {}) : icons?.collapsed ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RowCollapsedIcon, {});
152
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fuf_stack_pixels_Button.default, {
153
+ ariaLabel: `${isExpanded ? "Collapse" : "Expand"} row ${row.id}`,
154
+ className: classNames.expandButton,
155
+ dataSlot: "expand-button",
156
+ disabled: !row.getCanExpand(),
157
+ onClick: () => {
158
+ row.toggleExpanded();
159
+ },
160
+ size: "sm",
161
+ variant: "light",
162
+ children: icon === false ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
163
+ "aria-hidden": "true",
164
+ className: classNames.expandIcon,
165
+ "data-slot": "expand-icon",
166
+ children: icon
167
+ })
168
+ });
169
+ },
170
+ enableHiding: false,
171
+ enableSorting: false,
172
+ header: void 0,
173
+ id: EXPANSION_COLUMN_ID,
174
+ size: 36
175
+ };
176
+ };
177
+ /** Builds the optional leading selection column used by DataTable. */
178
+ const createSelectionColumn = (classNames, icons) => {
179
+ return {
180
+ cell: ({ row }) => {
181
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTableCheckbox, {
182
+ ariaLabel: `Select row ${row.id}`,
183
+ checked: row.getIsSelected(),
184
+ checkedIcon: icons?.checked,
185
+ className: {
186
+ checkbox: classNames.checkbox,
187
+ checkboxIndicator: classNames.checkboxIndicator
188
+ },
189
+ indeterminateIcon: icons?.indeterminate,
190
+ onCheckedChange: (checked) => {
191
+ row.toggleSelected(checked);
192
+ }
193
+ });
194
+ },
195
+ enableHiding: false,
196
+ enableSorting: false,
197
+ header: ({ table }) => {
198
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTableCheckbox, {
199
+ ariaLabel: "Select all rows on page",
200
+ checked: table.getIsAllPageRowsSelected(),
201
+ checkedIcon: icons?.checked,
202
+ className: {
203
+ checkbox: classNames.checkbox,
204
+ checkboxIndicator: classNames.checkboxIndicator
205
+ },
206
+ indeterminate: !table.getIsAllPageRowsSelected() && table.getIsSomePageRowsSelected(),
207
+ indeterminateIcon: icons?.indeterminate,
208
+ onCheckedChange: (checked) => {
209
+ table.toggleAllPageRowsSelected(checked);
210
+ }
211
+ });
212
+ },
213
+ id: SELECTION_COLUMN_ID,
214
+ size: 36
215
+ };
216
+ };
217
+ /** Maps TanStack sort state to the header indicator glyph. */
218
+ const getSortIndicator = (canSort, sortState, icons = {}) => {
219
+ const ascIcon = icons.asc ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SortAscendingIcon, {});
220
+ const descIcon = icons.desc ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SortDescendingIcon, {});
221
+ const unsortedIcon = icons.unsorted ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SortUnsortedIcon, {});
222
+ if (sortState === "asc") return ascIcon === false ? null : ascIcon;
223
+ if (sortState === "desc") return descIcon === false ? null : descIcon;
224
+ if (canSort) return unsortedIcon === false ? null : unsortedIcon;
225
+ return null;
226
+ };
227
+ /**
228
+ * Central controller hook for DataTable state and TanStack wiring.
229
+ *
230
+ * Keeps stateful table mechanics out of the render component so `DataTable.tsx`
231
+ * can stay focused on structure/markup.
232
+ */
233
+ const useDataTableController = ({ checkboxClassNames, columns, data, enableExpandableRows, enablePagination, enableServerMode = false, enableRowSelection, expansionClassNames, expansionIcons = void 0, getSubRows = void 0, hasExpandableRowContent, pageSizeOptions, selectionIcons = void 0, onSortingChange = void 0 }) => {
234
+ const [sorting, setSorting] = (0, react.useState)([]);
235
+ const [expanded, setExpanded] = (0, react.useState)({});
236
+ const [columnFilters, setColumnFilters] = (0, react.useState)([]);
237
+ const [columnVisibility, setColumnVisibility] = (0, react.useState)({});
238
+ const [rowSelection, setRowSelection] = (0, react.useState)({});
239
+ const [pagination, setPagination] = (0, react.useState)({
240
+ pageIndex: 0,
241
+ pageSize: pageSizeOptions[0] ?? 10
242
+ });
243
+ const tableColumns = (0, react.useMemo)(() => {
244
+ let nextColumns = columns;
245
+ if (enableRowSelection) nextColumns = [createSelectionColumn(checkboxClassNames, selectionIcons), ...nextColumns];
246
+ if (enableExpandableRows) nextColumns = [createExpansionColumn(expansionClassNames, expansionIcons), ...nextColumns];
247
+ return nextColumns;
248
+ }, [
249
+ checkboxClassNames,
250
+ columns,
251
+ enableExpandableRows,
252
+ enableRowSelection,
253
+ expansionClassNames,
254
+ expansionIcons,
255
+ selectionIcons
256
+ ]);
257
+ const handleSortingChange = (nextSorting) => {
258
+ setSorting((previousState) => {
259
+ const resolvedSorting = typeof nextSorting === "function" ? nextSorting(previousState) : nextSorting;
260
+ onSortingChange?.(resolvedSorting);
261
+ return resolvedSorting;
262
+ });
263
+ };
264
+ return {
265
+ table: (0, _tanstack_react_table.useReactTable)({
266
+ columns: tableColumns,
267
+ data,
268
+ defaultColumn: { enableSorting: false },
269
+ enableExpanding: enableExpandableRows,
270
+ enableRowSelection,
271
+ getCoreRowModel: (0, _tanstack_react_table.getCoreRowModel)(),
272
+ getExpandedRowModel: enableExpandableRows ? (0, _tanstack_react_table.getExpandedRowModel)() : void 0,
273
+ getFilteredRowModel: enableServerMode ? void 0 : (0, _tanstack_react_table.getFilteredRowModel)(),
274
+ getPaginationRowModel: enablePagination ? (0, _tanstack_react_table.getPaginationRowModel)() : void 0,
275
+ getRowCanExpand: (row) => {
276
+ return hasExpandableRowContent || row.subRows.length > 0;
277
+ },
278
+ getSubRows,
279
+ getSortedRowModel: enableServerMode ? void 0 : (0, _tanstack_react_table.getSortedRowModel)(),
280
+ manualFiltering: enableServerMode,
281
+ manualSorting: enableServerMode,
282
+ onColumnFiltersChange: setColumnFilters,
283
+ onColumnVisibilityChange: setColumnVisibility,
284
+ onExpandedChange: setExpanded,
285
+ onPaginationChange: setPagination,
286
+ onRowSelectionChange: setRowSelection,
287
+ onSortingChange: handleSortingChange,
288
+ state: {
289
+ columnFilters,
290
+ columnVisibility,
291
+ expanded,
292
+ pagination,
293
+ rowSelection,
294
+ sorting
295
+ }
296
+ }),
297
+ tableColumns
298
+ };
299
+ };
300
+ //#endregion
301
+ //#region src/DataTable/Subcomponents/DataTableCells.tsx
302
+ const getColumnKind = (columnId) => {
303
+ if (columnId === "__expand") return "expansion";
304
+ if (columnId === "__select") return "selection";
305
+ return "data";
306
+ };
307
+ const getCellDataSlot = (columnKind) => {
308
+ if (columnKind === "expansion") return "expansion-cell";
309
+ if (columnKind === "selection") return "selection-cell";
310
+ return "td";
311
+ };
312
+ const getHeaderDataSlot = (columnKind) => {
313
+ if (columnKind === "data") return "th";
314
+ return getCellDataSlot(columnKind);
315
+ };
316
+ const getControlCellContentDataSlot = (columnKind) => {
317
+ if (columnKind === "expansion") return "expansion-cell-content";
318
+ return "selection-cell-content";
319
+ };
320
+ /**
321
+ * Flex sizing for cells in virtualized mode.
322
+ *
323
+ * Because virtual rows are absolutely positioned, we cannot rely on native
324
+ * table layout for column width sync; header/body cells must apply matching
325
+ * explicit sizing rules.
326
+ */
327
+ const getVirtualCellStyle = (columnKind, size) => {
328
+ if (columnKind === "data") return {
329
+ flex: `1 1 ${size}px`,
330
+ minWidth: 0,
331
+ width: size
332
+ };
333
+ return {
334
+ flex: `0 0 ${size}px`,
335
+ width: size
336
+ };
337
+ };
338
+ /** Shared row positioning style for full-width virtual rows. */
339
+ const virtualFullWidthRowStyle = (start) => {
340
+ return {
341
+ display: "flex",
342
+ position: "absolute",
343
+ transform: `translateY(${start}px)`,
344
+ width: "100%"
345
+ };
346
+ };
347
+ /** Shared single-cell style for full-width virtual rows. */
348
+ const virtualFullWidthCellStyle = {
349
+ flex: "1 1 auto",
350
+ width: "100%"
351
+ };
352
+ /**
353
+ * Renders one header cell and encapsulates sortable/non-sortable behavior.
354
+ */
355
+ const DataTableHeaderCell = ({ classNames, header, sortIcons = void 0, virtualized = false }) => {
356
+ const canSort = header.column.getCanSort();
357
+ const columnKind = getColumnKind(header.column.id);
358
+ const isExpansionColumn = columnKind === "expansion";
359
+ const isSelectionColumn = columnKind === "selection";
360
+ const sortState = header.column.getIsSorted();
361
+ const sortIndicator = getSortIndicator(canSort, sortState, sortIcons);
362
+ if (header.isPlaceholder) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
363
+ "aria-label": "Empty column header",
364
+ className: classNames.th,
365
+ "data-slot": getHeaderDataSlot(columnKind)
366
+ }, header.id);
367
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
368
+ className: (0, _fuf_stack_pixel_utils.cn)(classNames.th, isExpansionColumn && classNames.expansionCell, isSelectionColumn && classNames.selectionCell),
369
+ "data-slot": getHeaderDataSlot(columnKind),
370
+ style: virtualized ? {
371
+ alignItems: "center",
372
+ display: "flex",
373
+ ...getVirtualCellStyle(columnKind, header.getSize())
374
+ } : void 0,
375
+ children: canSort ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_fuf_stack_pixels_Button.default, {
376
+ className: classNames.sortButton,
377
+ "data-sortable": canSort,
378
+ dataSlot: "sort-button",
379
+ onClick: () => {
380
+ header.column.toggleSorting(sortState === "asc");
381
+ },
382
+ size: "sm",
383
+ variant: "light",
384
+ children: [(0, _tanstack_react_table.flexRender)(header.column.columnDef.header, header.getContext()), sortIndicator ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
385
+ "aria-hidden": "true",
386
+ className: classNames.sortIcon,
387
+ "data-slot": "sort-icon",
388
+ children: sortIndicator
389
+ }) : null]
390
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
391
+ className: (0, _fuf_stack_pixel_utils.cn)(classNames.nonSortableHeaderContent, isExpansionColumn && classNames.expansionCellContent, isSelectionColumn && classNames.selectionCellContent),
392
+ "data-slot": columnKind === "data" ? "non-sortable-header-content" : getControlCellContentDataSlot(columnKind),
393
+ children: (0, _tanstack_react_table.flexRender)(header.column.columnDef.header, header.getContext())
394
+ })
395
+ }, header.id);
396
+ };
397
+ /**
398
+ * Renders one body cell and hides control-column wrapper details from row loops.
399
+ */
400
+ const DataTableBodyCell = ({ cell, classNames, virtualized = false }) => {
401
+ const columnKind = getColumnKind(cell.column.id);
402
+ const isExpansionColumn = columnKind === "expansion";
403
+ const isSelectionColumn = columnKind === "selection";
404
+ const isControlColumn = columnKind !== "data";
405
+ const cellContent = (0, _tanstack_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext());
406
+ const expansionIndent = isExpansionColumn && cell.row.depth > 0 ? { paddingLeft: `${cell.row.depth * 1.25}rem` } : void 0;
407
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
408
+ className: (0, _fuf_stack_pixel_utils.cn)(classNames.td, isExpansionColumn && classNames.expansionCell, isSelectionColumn && classNames.selectionCell),
409
+ "data-slot": getCellDataSlot(columnKind),
410
+ style: virtualized ? getVirtualCellStyle(columnKind, cell.column.getSize()) : void 0,
411
+ children: isControlColumn ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
412
+ className: (0, _fuf_stack_pixel_utils.cn)(isExpansionColumn && classNames.expansionCellContent, isSelectionColumn && classNames.selectionCellContent),
413
+ "data-slot": getControlCellContentDataSlot(columnKind),
414
+ style: expansionIndent,
415
+ children: cellContent
416
+ }) : cellContent
417
+ }, cell.id);
418
+ };
419
+ //#endregion
420
+ //#region src/DataTable/Subcomponents/DataTableBodyRows.tsx
421
+ /**
422
+ * Standard row renderer used in non-virtualized table mode.
423
+ *
424
+ * It renders:
425
+ * - each data row
426
+ * - an optional sibling expanded-content row that spans all visible columns
427
+ */
428
+ const DataTableBodyRows = ({ classNames, expandableRows = void 0, rows, visibleColumnCount, virtualized = false }) => {
429
+ return rows.map((row) => {
430
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
431
+ className: classNames.tr,
432
+ "data-slot": "tr",
433
+ "data-state": row.getIsSelected() ? "selected" : void 0,
434
+ style: virtualized ? {
435
+ display: "flex",
436
+ width: "100%"
437
+ } : void 0,
438
+ children: row.getVisibleCells().map((cell) => {
439
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTableBodyCell, {
440
+ cell,
441
+ classNames,
442
+ virtualized
443
+ }, cell.id);
444
+ })
445
+ }), expandableRows?.renderContent && row.getIsExpanded() ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
446
+ className: (0, _fuf_stack_pixel_utils.cn)(classNames.tr, classNames.expandedRow),
447
+ "data-slot": "expanded-row",
448
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
449
+ className: classNames.expandedCell,
450
+ colSpan: visibleColumnCount,
451
+ "data-slot": "expanded-cell",
452
+ children: expandableRows.renderContent(row)
453
+ })
454
+ }) : null] }, row.id);
455
+ });
456
+ };
457
+ //#endregion
458
+ //#region src/DataTable/Subcomponents/DataTablePagination.tsx
459
+ const ChevronDownIcon = () => {
460
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
461
+ "aria-hidden": "true",
462
+ fill: "none",
463
+ focusable: "false",
464
+ height: "14",
465
+ viewBox: "0 0 16 16",
466
+ width: "14",
467
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
468
+ d: "m4 6 4 4 4-4",
469
+ stroke: "currentColor",
470
+ strokeLinecap: "round",
471
+ strokeLinejoin: "round",
472
+ strokeWidth: "1.75"
473
+ })
474
+ });
475
+ };
476
+ /** Footer controls for paging, page size, and selected-row summary. */
477
+ const DataTablePagination = ({ classNames, pageSizeOptions, showRowsPerPage, showSelectionSummary, table, testId = void 0 }) => {
478
+ const { pageSize } = table.getState().pagination;
479
+ const selectedRowCount = table.getFilteredSelectedRowModel().rows.length;
480
+ const pageSizeItems = pageSizeOptions.map((size) => {
481
+ return {
482
+ key: String(size),
483
+ textValue: String(size),
484
+ label: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
485
+ className: "flex items-center gap-2",
486
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
487
+ className: "inline-flex w-3 justify-center",
488
+ children: size === pageSize ? "✓" : ""
489
+ }), size]
490
+ })
491
+ };
492
+ });
493
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
494
+ className: classNames.pagination,
495
+ "data-slot": "pagination",
496
+ children: [
497
+ showSelectionSummary && selectedRowCount > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
498
+ className: classNames.selectionSummary,
499
+ "data-slot": "selection-summary",
500
+ children: [
501
+ selectedRowCount,
502
+ " of ",
503
+ table.getFilteredRowModel().rows.length,
504
+ " row(s) selected."
505
+ ]
506
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
507
+ "aria-hidden": "true",
508
+ className: classNames.selectionSummary,
509
+ "data-slot": "selection-summary"
510
+ }),
511
+ showRowsPerPage && pageSizeOptions.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
512
+ className: classNames.pageSizeLabel,
513
+ "data-slot": "page-size-label",
514
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "Rows per page" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_fuf_stack_pixels_Menu.default, {
515
+ ariaLabel: "Rows per page",
516
+ items: pageSizeItems,
517
+ onAction: (key) => {
518
+ table.setPageSize(Number(key));
519
+ },
520
+ placement: "top",
521
+ testId: testId ? `${testId}-page-size` : void 0,
522
+ triggerButtonProps: {
523
+ "aria-label": "Rows per page",
524
+ className: classNames.pageSizeSelect,
525
+ dataSlot: "page-size-select",
526
+ disableRipple: true,
527
+ size: "sm",
528
+ variant: "bordered"
529
+ },
530
+ children: [pageSize, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronDownIcon, {})]
531
+ })]
532
+ }) : null,
533
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
534
+ className: classNames.pageSummary,
535
+ "data-slot": "page-summary",
536
+ children: [
537
+ "Page ",
538
+ table.getState().pagination.pageIndex + 1,
539
+ " of",
540
+ " ",
541
+ Math.max(table.getPageCount(), 1)
542
+ ]
543
+ }),
544
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fuf_stack_pixels_Button.default, {
545
+ className: classNames.paginationButton,
546
+ dataSlot: "pagination-button",
547
+ disabled: !table.getCanPreviousPage(),
548
+ onClick: () => {
549
+ table.previousPage();
550
+ },
551
+ size: "sm",
552
+ testId: testId ? `${testId}-previous-page` : void 0,
553
+ variant: "bordered",
554
+ children: "Previous"
555
+ }),
556
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fuf_stack_pixels_Button.default, {
557
+ className: classNames.paginationButton,
558
+ dataSlot: "pagination-button",
559
+ disabled: !table.getCanNextPage(),
560
+ onClick: () => {
561
+ table.nextPage();
562
+ },
563
+ size: "sm",
564
+ testId: testId ? `${testId}-next-page` : void 0,
565
+ variant: "bordered",
566
+ children: "Next"
567
+ })
568
+ ]
569
+ });
570
+ };
571
+ //#endregion
572
+ //#region src/DataTable/Subcomponents/DataTableViewOptions.tsx
573
+ /**
574
+ * Resolves a human-readable label for a column, preferring its string header
575
+ * over the raw TanStack column id (e.g. "Status" instead of "status").
576
+ */
577
+ const getColumnLabel = (column) => {
578
+ const { header } = column.columnDef;
579
+ return typeof header === "string" ? header : column.id;
580
+ };
581
+ /** Dropdown for toggling table column visibility. */
582
+ const DataTableViewOptions = ({ classNames, table, triggerIcon = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_icons_lu.LuColumns3, {}), visibleIcon = "✓", testId = void 0 }) => {
583
+ const hideableColumns = table.getAllColumns().filter((column) => {
584
+ return column.getCanHide();
585
+ });
586
+ const columnsById = new Map(hideableColumns.map((column) => {
587
+ return [column.id, column];
588
+ }));
589
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_fuf_stack_pixels_Menu.default, {
590
+ items: hideableColumns.map((column) => {
591
+ const columnLabel = getColumnLabel(column);
592
+ return {
593
+ key: column.id,
594
+ className: classNames.viewOptionsItem,
595
+ dataSlot: "view-options-item",
596
+ textValue: columnLabel,
597
+ label: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
598
+ className: "flex items-center gap-2",
599
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
600
+ className: classNames.viewOptionsIndicator,
601
+ "data-slot": "view-options-indicator",
602
+ children: column.getIsVisible() && visibleIcon !== false ? visibleIcon : ""
603
+ }), columnLabel]
604
+ })
605
+ };
606
+ }),
607
+ onAction: (key) => {
608
+ const column = columnsById.get(String(key));
609
+ if (!column) return;
610
+ column.toggleVisibility(!column.getIsVisible());
611
+ },
612
+ testId: testId ? `${testId}-column-visibility-trigger` : void 0,
613
+ triggerButtonProps: {
614
+ "aria-label": "Toggle column visibility",
615
+ className: classNames.viewOptionsTrigger,
616
+ dataSlot: "view-options-trigger",
617
+ disableRipple: true,
618
+ size: "sm",
619
+ variant: "bordered"
620
+ },
621
+ children: [triggerIcon === false ? null : triggerIcon, "Columns"]
622
+ });
623
+ };
624
+ //#endregion
625
+ //#region src/DataTable/hooks/useDataTableVirtualizer.ts
626
+ /**
627
+ * Flattens current table state into virtual render items.
628
+ *
629
+ * Ordering rules:
630
+ * - each loaded row always produces a `row` item
631
+ * - each expanded row optionally produces an adjacent `expanded` item
632
+ * - `total-count` mode appends unloaded `placeholder` items after loaded rows
633
+ * - infinite mode appends a trailing `load-more` sentinel when needed
634
+ */
635
+ const getDataTableVirtualItems = ({ expandableRows, infiniteScroll, rows }) => {
636
+ const nextItems = [];
637
+ rows.forEach((row, rowIndex) => {
638
+ nextItems.push({
639
+ key: `row-${row.id}`,
640
+ kind: "row",
641
+ row
642
+ });
643
+ if (expandableRows?.renderContent && row.getIsExpanded()) nextItems.push({
644
+ key: `expanded-${row.id}`,
645
+ kind: "expanded",
646
+ row
647
+ });
648
+ if (infiniteScroll?.scrollbarMode !== "total-count") return;
649
+ if (!(rowIndex === rows.length - 1)) return;
650
+ const placeholderCount = Math.max(infiniteScroll.pageInfo.totalCount - rows.length, 0);
651
+ for (let placeholderOffset = 0; placeholderOffset < placeholderCount; placeholderOffset += 1) {
652
+ const placeholderIndex = rows.length + placeholderOffset;
653
+ nextItems.push({
654
+ key: `placeholder-${placeholderIndex}`,
655
+ kind: "placeholder",
656
+ rowIndex: placeholderIndex
657
+ });
658
+ }
659
+ });
660
+ if (rows.length === 0 && infiniteScroll?.scrollbarMode === "total-count") {
661
+ const placeholderCount = Math.max(infiniteScroll.pageInfo.totalCount, 0);
662
+ for (let placeholderIndex = 0; placeholderIndex < placeholderCount; placeholderIndex += 1) nextItems.push({
663
+ key: `placeholder-${placeholderIndex}`,
664
+ kind: "placeholder",
665
+ rowIndex: placeholderIndex
666
+ });
667
+ }
668
+ if (Boolean(infiniteScroll && ((infiniteScroll.pageInfo.hasNextPage ?? false) || (infiniteScroll.isFetchingNextPage ?? false) || (infiniteScroll.loadMoreError ?? false)))) nextItems.push({
669
+ key: "load-more",
670
+ kind: "load-more"
671
+ });
672
+ return nextItems;
673
+ };
674
+ /**
675
+ * DataTable-specific adapter around the shared `useInfiniteVirtualizer`.
676
+ *
677
+ * Responsibilities:
678
+ * - flatten table/expanded/placeholder/loading state into virtual items
679
+ * - derive `loadedItemCount` used for duplicate-load guards
680
+ * - translate generic load events back to cursor-based `onLoadMore`
681
+ * - expose a `getItem(virtualItem)` lookup for row rendering
682
+ */
683
+ const useDataTableVirtualizer = ({ expandableRows, infiniteScroll, rows, scrollElementRef, virtualization }) => {
684
+ const virtualRows = (0, react.useMemo)(() => {
685
+ return getDataTableVirtualItems({
686
+ expandableRows,
687
+ infiniteScroll,
688
+ rows
689
+ });
690
+ }, [
691
+ expandableRows,
692
+ infiniteScroll,
693
+ rows
694
+ ]);
695
+ const loadedItemCount = (0, react.useMemo)(() => {
696
+ const loadMoreIndex = virtualRows.findIndex((item) => {
697
+ return item.kind === "load-more";
698
+ });
699
+ if (loadMoreIndex >= 0) return loadMoreIndex;
700
+ const placeholderIndex = virtualRows.findIndex((item) => {
701
+ return item.kind === "placeholder";
702
+ });
703
+ if (placeholderIndex >= 0) return placeholderIndex;
704
+ return virtualRows.length;
705
+ }, [virtualRows]);
706
+ const virtualizer = require_useInfiniteVirtualizer.useInfiniteVirtualizer({
707
+ count: virtualRows.length,
708
+ dynamicRowHeight: virtualization?.dynamicRowHeight ?? Boolean(infiniteScroll),
709
+ enabled: Boolean(virtualization ?? infiniteScroll),
710
+ estimateSize: () => {
711
+ return virtualization?.estimateRowHeight ?? 45;
712
+ },
713
+ hasNextPage: infiniteScroll?.pageInfo.hasNextPage,
714
+ isFetchingNextPage: infiniteScroll?.isFetchingNextPage,
715
+ loadedCount: loadedItemCount,
716
+ loadMoreError: infiniteScroll?.loadMoreError,
717
+ loadMoreThreshold: infiniteScroll?.loadMoreThreshold,
718
+ onLoadMore: infiniteScroll ? () => {
719
+ infiniteScroll.onLoadMore({
720
+ cursor: infiniteScroll.pageInfo.endCursor,
721
+ direction: "forward"
722
+ });
723
+ } : void 0,
724
+ overscan: virtualization?.overscan,
725
+ scrollElementRef,
726
+ shouldLoadMore: ({ loadMoreThreshold, virtualItems }) => {
727
+ if (!infiniteScroll) return false;
728
+ const kindsInRange = new Set(virtualItems.map((item) => {
729
+ return virtualRows[item.index]?.kind;
730
+ }));
731
+ if (kindsInRange.has("placeholder") || kindsInRange.has("load-more")) return true;
732
+ return (virtualItems[virtualItems.length - 1]?.index ?? 0) >= Math.max(loadedItemCount - loadMoreThreshold - 1, 0);
733
+ }
734
+ });
735
+ const getItem = (virtualItem) => {
736
+ return virtualRows[virtualItem.index];
737
+ };
738
+ return {
739
+ getItem,
740
+ items: virtualRows,
741
+ loadedItemCount,
742
+ ...virtualizer
743
+ };
744
+ };
745
+ //#endregion
746
+ //#region src/DataTable/Subcomponents/DataTableVirtualBodyRows.tsx
747
+ /**
748
+ * Virtualized row renderer for DataTable body.
749
+ *
750
+ * It maps virtual items (row/expanded/placeholder/load-more) to absolute
751
+ * positioned `<tr>` elements and delegates load-more retry handling.
752
+ */
753
+ const DataTableVirtualBodyRows = ({ classNames, expandableRows = void 0, infiniteScroll = void 0, loadingMoreContent = "Loading more...", retryContent = "Load next page", rows, scrollElementRef = void 0, virtualized, virtualization = void 0, visibleColumnCount }) => {
754
+ const { getItem, measureElement, retry, totalSize, virtualItems } = useDataTableVirtualizer({
755
+ expandableRows,
756
+ infiniteScroll,
757
+ rows,
758
+ scrollElementRef,
759
+ virtualization
760
+ });
761
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
762
+ style: { height: `${totalSize}px` },
763
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
764
+ "aria-label": "Virtual spacer row",
765
+ colSpan: visibleColumnCount,
766
+ style: { padding: 0 }
767
+ })
768
+ }), virtualItems.map((virtualItem) => {
769
+ const item = getItem(virtualItem);
770
+ if (!item) return null;
771
+ if (item.kind === "row") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
772
+ ref: measureElement,
773
+ className: classNames.tr,
774
+ "data-index": virtualItem.index,
775
+ "data-slot": "tr",
776
+ "data-state": item.row.getIsSelected() ? "selected" : void 0,
777
+ style: {
778
+ display: virtualized ? "flex" : void 0,
779
+ position: "absolute",
780
+ transform: `translateY(${virtualItem.start}px)`,
781
+ width: "100%"
782
+ },
783
+ children: item.row.getVisibleCells().map((cell) => {
784
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTableBodyCell, {
785
+ cell,
786
+ classNames,
787
+ virtualized
788
+ }, cell.id);
789
+ })
790
+ }, item.key);
791
+ if (item.kind === "expanded") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
792
+ ref: measureElement,
793
+ className: (0, _fuf_stack_pixel_utils.cn)(classNames.tr, classNames.expandedRow),
794
+ "data-index": virtualItem.index,
795
+ "data-slot": "expanded-row",
796
+ style: virtualFullWidthRowStyle(virtualItem.start),
797
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
798
+ className: classNames.expandedCell,
799
+ colSpan: visibleColumnCount,
800
+ "data-slot": "expanded-cell",
801
+ style: virtualFullWidthCellStyle,
802
+ children: expandableRows?.renderContent?.(item.row)
803
+ })
804
+ }, item.key);
805
+ if (item.kind === "placeholder") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
806
+ ref: measureElement,
807
+ className: classNames.tr,
808
+ "data-index": virtualItem.index,
809
+ "data-slot": "placeholder-row",
810
+ style: {
811
+ ...virtualFullWidthRowStyle(virtualItem.start),
812
+ height: `${virtualItem.size}px`
813
+ },
814
+ children: rows[0]?.getVisibleCells().map((cell) => {
815
+ const columnKind = getColumnKind(cell.column.id);
816
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
817
+ "aria-label": "Loading placeholder",
818
+ className: classNames.placeholderCell,
819
+ "data-slot": "placeholder-cell",
820
+ style: getVirtualCellStyle(columnKind, cell.column.getSize()),
821
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "block h-3 rounded bg-default-300/50 dark:bg-default-300/20" })
822
+ }, `${item.key}-${cell.column.id}`);
823
+ })
824
+ }, item.key);
825
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
826
+ ref: measureElement,
827
+ className: classNames.tr,
828
+ "data-index": virtualItem.index,
829
+ "data-slot": "loading-more-row",
830
+ style: virtualFullWidthRowStyle(virtualItem.start),
831
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
832
+ className: classNames.loadingMoreCell,
833
+ colSpan: visibleColumnCount,
834
+ "data-slot": "loading-more-cell",
835
+ style: virtualFullWidthCellStyle,
836
+ children: infiniteScroll?.loadMoreError ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fuf_stack_pixels_Button.default, {
837
+ dataSlot: "load-more-retry-button",
838
+ onClick: retry,
839
+ size: "sm",
840
+ variant: "bordered",
841
+ children: retryContent
842
+ }) : loadingMoreContent
843
+ })
844
+ }, item.key);
845
+ })] });
846
+ };
847
+ //#endregion
848
+ //#region src/DataTable/DataTable.tsx
849
+ const dataTableVariants = (0, _fuf_stack_pixel_utils.tv)({ slots: {
850
+ base: "w-full",
851
+ checkbox: "relative inline-flex h-4 w-4 shrink-0 cursor-pointer items-center justify-center rounded border border-divider bg-background align-middle text-foreground",
852
+ checkboxIndicator: "pointer-events-none absolute inset-0 flex items-center justify-center text-[10px] leading-none",
853
+ emptyCell: "h-24 text-center text-default-500",
854
+ expandButton: "h-8 min-w-8 px-0 disabled:cursor-not-allowed data-[disabled=true]:pointer-events-auto data-[disabled=true]:cursor-not-allowed",
855
+ expandIcon: "inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center text-default-500",
856
+ expansionCell: "w-10 px-0 text-center",
857
+ expansionCellContent: "flex justify-center",
858
+ expandedRow: "bg-content1",
859
+ expandedCell: "p-4 text-sm text-default-600",
860
+ searchInput: "h-10 w-full max-w-sm rounded-small border-2 border-default-200 bg-transparent px-3 text-sm text-foreground outline-none transition-colors placeholder:text-default-500 hover:border-default-400 data-[focused=true]:border-focus dark:border-default-100",
861
+ loadingCell: "h-24 text-center text-default-500",
862
+ loadingMoreCell: "flex h-14 items-center justify-center text-default-500",
863
+ nonSortableHeaderContent: "inline-flex items-center",
864
+ pageSizeLabel: "flex items-center gap-2 text-sm text-default-500",
865
+ pageSizeSelect: "min-w-16 justify-between gap-2",
866
+ pageSummary: "text-sm text-default-500",
867
+ pagination: "flex items-center gap-2 py-4",
868
+ paginationButton: "",
869
+ placeholderCell: "h-10 animate-pulse bg-default-100/60 p-3 dark:bg-default-100/10",
870
+ selectionSummary: "mr-auto text-sm text-default-500",
871
+ selectionCell: "w-10 px-0 text-center",
872
+ selectionCellContent: "flex justify-center",
873
+ sortButton: "-ml-2 min-w-0 justify-start gap-1.5 px-2 text-left font-medium text-foreground data-[sortable=true]:cursor-pointer",
874
+ sortIcon: "inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center text-default-400",
875
+ scrollContainer: "overflow-y-auto overflow-x-hidden",
876
+ scrollShadow: "",
877
+ table: "w-full caption-bottom text-sm",
878
+ tableWrapper: "overflow-hidden rounded-md border border-divider",
879
+ tbody: "",
880
+ td: "p-3 align-middle text-foreground",
881
+ th: "h-10 px-3 text-left align-middle font-medium text-foreground",
882
+ thead: "bg-content2",
883
+ toolbar: "flex items-center gap-3 py-4",
884
+ toolbarContent: "flex flex-1 items-center",
885
+ tr: "border-b border-divider last:border-b-0 data-[state=selected]:bg-content2/60",
886
+ viewOptionsIndicator: "mr-2 inline-flex w-3 justify-center",
887
+ viewOptionsItem: "data-highlighted:bg-default-100 dark:data-highlighted:bg-default-100/20 flex cursor-pointer items-center rounded px-2 py-1 text-sm text-foreground outline-none",
888
+ viewOptionsMenu: "z-50 min-w-40 rounded-md border border-divider bg-background p-1 shadow-md",
889
+ viewOptionsPositioner: "outline-none",
890
+ viewOptionsTrigger: "ml-auto gap-2"
891
+ } });
892
+ /**
893
+ * Generic, feature-composable data table built on TanStack Table.
894
+ *
895
+ * Responsibilities:
896
+ * - Renders semantic table markup (`table`, `thead`, `tbody`, `tr`, `th`, `td`).
897
+ * - Wires sorting/search/visibility/selection/pagination state via
898
+ * `useDataTableController`.
899
+ * - Exposes slot-based styling through `dataTableVariants` + `className`.
900
+ * - Supports optional custom toolbar content (e.g. megapixels `Filter`).
901
+ *
902
+ * Feature configuration:
903
+ * - Configure search/visibility/selection/pagination through `features`.
904
+ */
905
+ const DataTable = ({ ariaLabel = "Data table", className = void 0, columns, data, emptyContent = "No results.", features = void 0, icons = void 0, loading = false, loadingContent = "Loading...", testId = void 0, toolbarContent = void 0 }) => {
906
+ const resolvedEnableColumnVisibility = features?.columnVisibility ?? false;
907
+ const resolvedExpandableRows = features?.expandableRows;
908
+ const resolvedEnableExpandableRows = Boolean(resolvedExpandableRows);
909
+ const paginationConfig = typeof features?.pagination === "object" ? features.pagination : void 0;
910
+ const resolvedInfiniteScroll = features?.infiniteScroll;
911
+ const resolvedVirtualization = features?.virtualization;
912
+ const resolvedEnableVirtualization = Boolean(resolvedVirtualization ?? resolvedInfiniteScroll);
913
+ const resolvedEnablePagination = Boolean(features?.pagination && !resolvedInfiniteScroll);
914
+ const resolvedEnableRowSelection = Boolean(features?.rowSelection && !resolvedInfiniteScroll);
915
+ const resolvedPageSizeOptions = paginationConfig?.pageSizeOptions ?? [
916
+ 10,
917
+ 20,
918
+ 50
919
+ ];
920
+ const resolvedShowRowsPerPage = paginationConfig?.showRowsPerPage ?? true;
921
+ const resolvedSearchFields = features?.search?.columns ?? [];
922
+ const virtualConfig = resolvedVirtualization ?? (resolvedInfiniteScroll ? {
923
+ dynamicRowHeight: true,
924
+ maxHeight: 600
925
+ } : void 0);
926
+ const variants = dataTableVariants();
927
+ const scrollContainerRef = (0, react.useRef)(null);
928
+ const handleSortingChange = (0, react.useCallback)((sorting) => {
929
+ if (resolvedInfiniteScroll) scrollContainerRef.current?.scrollTo({ top: 0 });
930
+ resolvedInfiniteScroll?.onSortingChange?.(sorting);
931
+ }, [resolvedInfiniteScroll]);
932
+ const classNames = (0, _fuf_stack_pixel_utils.variantsToClassNames)(variants, className, "base");
933
+ const checkboxClassNames = (0, react.useMemo)(() => {
934
+ return {
935
+ checkbox: classNames.checkbox,
936
+ checkboxIndicator: classNames.checkboxIndicator
937
+ };
938
+ }, [classNames.checkbox, classNames.checkboxIndicator]);
939
+ const expansionClassNames = (0, react.useMemo)(() => {
940
+ return {
941
+ expandButton: classNames.expandButton,
942
+ expandIcon: classNames.expandIcon
943
+ };
944
+ }, [classNames.expandButton, classNames.expandIcon]);
945
+ const { table } = useDataTableController({
946
+ checkboxClassNames,
947
+ columns,
948
+ data,
949
+ enableExpandableRows: resolvedEnableExpandableRows,
950
+ enablePagination: resolvedEnablePagination,
951
+ enableServerMode: Boolean(resolvedInfiniteScroll),
952
+ enableRowSelection: resolvedEnableRowSelection,
953
+ expansionClassNames,
954
+ expansionIcons: icons?.expandableRows,
955
+ getSubRows: resolvedExpandableRows?.getSubRows,
956
+ hasExpandableRowContent: Boolean(resolvedExpandableRows?.renderContent),
957
+ onSortingChange: handleSortingChange,
958
+ pageSizeOptions: resolvedPageSizeOptions,
959
+ selectionIcons: icons?.selection
960
+ });
961
+ const visibleColumnCount = table.getVisibleLeafColumns().length;
962
+ const tableRows = table.getRowModel().rows;
963
+ const showToolbar = resolvedSearchFields.length > 0 || resolvedEnableColumnVisibility || Boolean(toolbarContent);
964
+ const renderHeaderRows = (virtualized) => {
965
+ return table.getHeaderGroups().map((headerGroup) => {
966
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
967
+ className: classNames.tr,
968
+ "data-slot": "tr",
969
+ style: virtualized ? {
970
+ display: "flex",
971
+ width: "100%"
972
+ } : void 0,
973
+ children: headerGroup.headers.map((header) => {
974
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTableHeaderCell, {
975
+ classNames,
976
+ header,
977
+ sortIcons: icons?.sort,
978
+ virtualized
979
+ }, header.id);
980
+ })
981
+ }, headerGroup.id);
982
+ });
983
+ };
984
+ const renderBodyStateRows = () => {
985
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
986
+ className: classNames.tr,
987
+ "data-slot": "tr",
988
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
989
+ className: classNames.loadingCell,
990
+ colSpan: visibleColumnCount,
991
+ "data-slot": "loading-cell",
992
+ children: loadingContent
993
+ })
994
+ }) : null, !loading && tableRows.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
995
+ className: classNames.tr,
996
+ "data-slot": "tr",
997
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
998
+ className: classNames.emptyCell,
999
+ colSpan: visibleColumnCount,
1000
+ "data-slot": "empty-cell",
1001
+ children: emptyContent
1002
+ })
1003
+ }) : null] });
1004
+ };
1005
+ const renderVirtualizedTable = () => {
1006
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("table", {
1007
+ "aria-hidden": loading && tableRows.length === 0 ? "true" : void 0,
1008
+ className: classNames.table,
1009
+ "data-slot": "table",
1010
+ style: { display: "grid" },
1011
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("thead", {
1012
+ className: classNames.thead,
1013
+ "data-slot": "thead",
1014
+ children: renderHeaderRows(true)
1015
+ })
1016
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fuf_stack_pixels_ScrollShadow.default, {
1017
+ ref: scrollContainerRef,
1018
+ className: classNames.scrollShadow ? `${classNames.scrollContainer} ${classNames.scrollShadow}` : classNames.scrollContainer,
1019
+ visibility: resolvedInfiniteScroll?.loadMoreError ? "none" : "auto",
1020
+ dataSlot: "scroll-container",
1021
+ style: { maxHeight: virtualConfig?.maxHeight },
1022
+ size: virtualConfig?.scrollShadowSize ?? 40,
1023
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("table", {
1024
+ "aria-label": ariaLabel,
1025
+ className: classNames.table,
1026
+ "data-slot": "table",
1027
+ style: { display: "grid" },
1028
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tbody", {
1029
+ className: classNames.tbody,
1030
+ "data-slot": "tbody",
1031
+ style: {
1032
+ display: "grid",
1033
+ position: "relative"
1034
+ },
1035
+ children: [loading ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTableVirtualBodyRows, {
1036
+ classNames,
1037
+ expandableRows: resolvedExpandableRows,
1038
+ infiniteScroll: resolvedInfiniteScroll,
1039
+ loadingMoreContent: resolvedInfiniteScroll?.loadingMoreContent,
1040
+ retryContent: resolvedInfiniteScroll?.retryContent,
1041
+ rows: tableRows,
1042
+ scrollElementRef: scrollContainerRef,
1043
+ virtualization: virtualConfig,
1044
+ virtualized: true,
1045
+ visibleColumnCount
1046
+ }), renderBodyStateRows()]
1047
+ })
1048
+ })
1049
+ })] });
1050
+ };
1051
+ const renderStandardTable = () => {
1052
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("table", {
1053
+ "aria-label": ariaLabel,
1054
+ className: classNames.table,
1055
+ "data-slot": "table",
1056
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("thead", {
1057
+ className: classNames.thead,
1058
+ "data-slot": "thead",
1059
+ children: renderHeaderRows(false)
1060
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tbody", {
1061
+ className: classNames.tbody,
1062
+ "data-slot": "tbody",
1063
+ children: [loading ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTableBodyRows, {
1064
+ classNames,
1065
+ expandableRows: resolvedExpandableRows,
1066
+ rows: tableRows,
1067
+ visibleColumnCount
1068
+ }), renderBodyStateRows()]
1069
+ })]
1070
+ });
1071
+ };
1072
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1073
+ className: classNames.base,
1074
+ "data-slot": "base",
1075
+ "data-testid": testId,
1076
+ children: [
1077
+ showToolbar ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1078
+ className: classNames.toolbar,
1079
+ "data-slot": "toolbar",
1080
+ children: [
1081
+ toolbarContent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1082
+ className: classNames.toolbarContent,
1083
+ "data-slot": "toolbar-content",
1084
+ children: toolbarContent
1085
+ }) : null,
1086
+ resolvedSearchFields.map((searchField) => {
1087
+ const searchValue = table.getColumn(searchField.column)?.getFilterValue() ?? "";
1088
+ let searchTestId;
1089
+ if (testId) searchTestId = resolvedSearchFields.length === 1 ? `${testId}-search` : `${testId}-search-${searchField.column}`;
1090
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1091
+ className: classNames.searchInput,
1092
+ "data-focused": Boolean(searchValue),
1093
+ "data-slot": "search-input",
1094
+ "data-testid": searchTestId,
1095
+ onChange: (event) => {
1096
+ const { value } = event.target;
1097
+ table.getColumn(searchField.column)?.setFilterValue(value);
1098
+ if (resolvedInfiniteScroll) {
1099
+ resolvedInfiniteScroll.onSearchChange?.(searchField.column, value);
1100
+ scrollContainerRef.current?.scrollTo({ top: 0 });
1101
+ }
1102
+ },
1103
+ placeholder: searchField.placeholder ?? "Search...",
1104
+ value: searchValue
1105
+ }, searchField.column);
1106
+ }),
1107
+ resolvedEnableColumnVisibility ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTableViewOptions, {
1108
+ classNames: {
1109
+ viewOptionsIndicator: classNames.viewOptionsIndicator,
1110
+ viewOptionsItem: classNames.viewOptionsItem,
1111
+ viewOptionsTrigger: classNames.viewOptionsTrigger
1112
+ },
1113
+ table,
1114
+ testId,
1115
+ triggerIcon: icons?.columnVisibility?.trigger,
1116
+ visibleIcon: icons?.columnVisibility?.visible
1117
+ }) : null
1118
+ ]
1119
+ }) : null,
1120
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1121
+ className: classNames.tableWrapper,
1122
+ "data-slot": "table-wrapper",
1123
+ children: resolvedEnableVirtualization ? renderVirtualizedTable() : renderStandardTable()
1124
+ }),
1125
+ resolvedEnablePagination ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTablePagination, {
1126
+ classNames: {
1127
+ pageSizeLabel: classNames.pageSizeLabel,
1128
+ pageSizeSelect: classNames.pageSizeSelect,
1129
+ pageSummary: classNames.pageSummary,
1130
+ pagination: classNames.pagination,
1131
+ paginationButton: classNames.paginationButton,
1132
+ selectionSummary: classNames.selectionSummary
1133
+ },
1134
+ pageSizeOptions: resolvedPageSizeOptions,
1135
+ showRowsPerPage: resolvedShowRowsPerPage,
1136
+ showSelectionSummary: resolvedEnableRowSelection,
1137
+ table,
1138
+ testId
1139
+ }) : null
1140
+ ]
1141
+ });
1142
+ };
1143
+ //#endregion
1144
+ //#region src/DataTable/index.ts
1145
+ var DataTable_default = DataTable;
1146
+ //#endregion
1147
+ Object.defineProperty(exports, "DataTable", {
1148
+ enumerable: true,
1149
+ get: function() {
1150
+ return DataTable;
1151
+ }
1152
+ });
1153
+ Object.defineProperty(exports, "DataTable_default", {
1154
+ enumerable: true,
1155
+ get: function() {
1156
+ return DataTable_default;
1157
+ }
1158
+ });
1159
+ Object.defineProperty(exports, "dataTableVariants", {
1160
+ enumerable: true,
1161
+ get: function() {
1162
+ return dataTableVariants;
1163
+ }
1164
+ });
1165
+
1166
+ //# sourceMappingURL=DataTable-CF0oifeL.cjs.map