@dbcdk/react-components 0.0.197 → 0.0.199

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 (68) hide show
  1. package/dist/components/json-viewer/JsonViewer.module.css +53 -0
  2. package/dist/components/json-viewer/JsonViewerShell.cjs +147 -143
  3. package/dist/components/json-viewer/JsonViewerShell.js +149 -145
  4. package/dist/components/line-viewer/LineViewer.cjs +15 -21
  5. package/dist/components/line-viewer/LineViewer.d.ts +1 -1
  6. package/dist/components/line-viewer/LineViewer.js +16 -22
  7. package/dist/components/line-viewer/LineViewer.module.css +58 -3
  8. package/dist/components/page-layout/PageLayout.module.css +1 -1
  9. package/dist/components/scroll-fade/ScrollFade.cjs +42 -0
  10. package/dist/components/scroll-fade/ScrollFade.d.ts +18 -0
  11. package/dist/components/scroll-fade/ScrollFade.js +36 -0
  12. package/dist/components/scroll-fade/ScrollFade.module.css +71 -0
  13. package/dist/components/search-box/SearchBox.cjs +39 -35
  14. package/dist/components/search-box/SearchBox.d.ts +2 -0
  15. package/dist/components/search-box/SearchBox.js +39 -35
  16. package/dist/components/table/Table.cjs +52 -23
  17. package/dist/components/table/Table.d.ts +1 -1
  18. package/dist/components/table/Table.js +53 -24
  19. package/dist/components/table/Table.module.css +4 -0
  20. package/dist/components/table/Table.types.d.ts +27 -0
  21. package/dist/components/table/TanstackTable.cjs +63 -106
  22. package/dist/components/table/TanstackTable.d.ts +5 -0
  23. package/dist/components/table/TanstackTable.js +66 -106
  24. package/dist/components/table/columnLayout.utils.cjs +146 -0
  25. package/dist/components/table/columnLayout.utils.d.ts +44 -0
  26. package/dist/components/table/columnLayout.utils.js +141 -0
  27. package/dist/components/table/components/TableHeader.cjs +3 -1
  28. package/dist/components/table/components/TableHeader.d.ts +2 -1
  29. package/dist/components/table/components/TableHeader.js +3 -1
  30. package/dist/components/table/components/TableHeaderCell.cjs +29 -19
  31. package/dist/components/table/components/TableHeaderCell.d.ts +2 -1
  32. package/dist/components/table/components/TableHeaderCell.js +29 -19
  33. package/dist/components/table/hooks/useClientPagination.cjs +66 -0
  34. package/dist/components/table/hooks/useClientPagination.d.ts +32 -0
  35. package/dist/components/table/hooks/useClientPagination.js +64 -0
  36. package/dist/components/table/hooks/useDistributedLayout.cjs +44 -0
  37. package/dist/components/table/hooks/useDistributedLayout.d.ts +16 -0
  38. package/dist/components/table/hooks/useDistributedLayout.js +42 -0
  39. package/dist/components/table/hooks/useElementWidth.cjs +40 -0
  40. package/dist/components/table/hooks/useElementWidth.d.ts +7 -0
  41. package/dist/components/table/hooks/useElementWidth.js +38 -0
  42. package/dist/components/table/hooks/useResizeHeaderExtras.cjs +87 -0
  43. package/dist/components/table/hooks/useResizeHeaderExtras.d.ts +17 -0
  44. package/dist/components/table/hooks/useResizeHeaderExtras.js +62 -0
  45. package/dist/components/table/hooks/useUiSorting.cjs +18 -0
  46. package/dist/components/table/hooks/useUiSorting.d.ts +3 -0
  47. package/dist/components/table/hooks/useUiSorting.js +16 -0
  48. package/dist/components/table/table.utils.cjs +24 -2
  49. package/dist/components/table/table.utils.d.ts +40 -2
  50. package/dist/components/table/table.utils.js +20 -2
  51. package/dist/components/table/tanstackTable.utils.cjs +33 -97
  52. package/dist/components/table/tanstackTable.utils.d.ts +24 -8
  53. package/dist/components/table/tanstackTable.utils.js +34 -99
  54. package/dist/components/xml-viewer/XmlViewer.cjs +15 -21
  55. package/dist/components/xml-viewer/XmlViewer.d.ts +1 -1
  56. package/dist/components/xml-viewer/XmlViewer.js +16 -22
  57. package/dist/components/xml-viewer/XmlViewer.module.css +58 -3
  58. package/dist/hooks/useScrollOverflow.cjs +71 -0
  59. package/dist/hooks/useScrollOverflow.d.ts +23 -0
  60. package/dist/hooks/useScrollOverflow.js +69 -0
  61. package/dist/hooks/useTableSettings.cjs +2 -1
  62. package/dist/hooks/useTableSettings.d.ts +1 -0
  63. package/dist/hooks/useTableSettings.js +2 -1
  64. package/dist/index.css +1 -0
  65. package/dist/utils/refs.utils.cjs +13 -0
  66. package/dist/utils/refs.utils.d.ts +7 -0
  67. package/dist/utils/refs.utils.js +11 -0
  68. package/package.json +1 -1
@@ -3,14 +3,17 @@ import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import { useMemo, useId, useRef, useState, useLayoutEffect, useCallback } from 'react';
4
4
  import { Pagination } from '../../components/pagination/Pagination';
5
5
  import { useViewportFill } from '../../hooks/useViewportFill';
6
+ import { mergeRefs } from '../../utils/refs.utils';
7
+ import { usesDistributedWidths, distributeColumnWidths, buildColumnTracks } from './columnLayout.utils';
6
8
  import { TableEmptyState } from './components/empty-state/EmptyState';
7
9
  import { TableHeaderSettings } from './components/table-settings/TableHeaderSettings';
8
10
  import { TableBody } from './components/TableBody';
9
11
  import { TableHeader } from './components/TableHeader';
10
12
  import { TableSkeletonBody } from './components/TableSkeletonBody';
13
+ import { useElementWidth } from './hooks/useElementWidth';
11
14
  import { cx } from './table.classes';
12
15
  import styles from './Table.module.css';
13
- import { getVisibleColumns, SELECTION_COLUMN_PX } from './table.utils';
16
+ import { DEFAULT_VIEW_MODE, getVisibleColumns, showsExpandToggle, getActionsReserve, SELECTION_COLUMN_PX } from './table.utils';
14
17
  import { filterColumnsBySettings } from './tableSettings.utils';
15
18
 
16
19
  const DEFAULT_SKELETON_ROWS = 10;
@@ -42,6 +45,7 @@ function Table({
42
45
  headerActions: headerActionsProp,
43
46
  settings,
44
47
  settingsOptions,
48
+ settingsColumns,
45
49
  take,
46
50
  skip,
47
51
  totalItemsCount,
@@ -63,9 +67,9 @@ function Table({
63
67
  onPageChange,
64
68
  ...rest
65
69
  }) {
66
- var _a;
67
- const viewMode = viewModeProp != null ? viewModeProp : settings == null ? void 0 : settings.viewMode;
68
- const striped = (_a = stripedProp != null ? stripedProp : settings == null ? void 0 : settings.striped) != null ? _a : false;
70
+ var _a, _b;
71
+ const viewMode = (_a = viewModeProp != null ? viewModeProp : settings == null ? void 0 : settings.viewMode) != null ? _a : DEFAULT_VIEW_MODE;
72
+ const striped = (_b = stripedProp != null ? stripedProp : settings == null ? void 0 : settings.striped) != null ? _b : false;
69
73
  const settingsVisibleIds = settings == null ? void 0 : settings.visibleColumnIds;
70
74
  const visibleColumns = useMemo(
71
75
  () => (settingsVisibleIds == null ? void 0 : settingsVisibleIds.length) ? filterColumnsBySettings(columns, settingsVisibleIds) : getVisibleColumns(columns),
@@ -73,7 +77,14 @@ function Table({
73
77
  );
74
78
  const headerActions = headerActionsProp != null || settings ? /* @__PURE__ */ jsxs("div", { className: styles.headerActions, children: [
75
79
  headerActionsProp,
76
- settings ? /* @__PURE__ */ jsx(TableHeaderSettings, { settings, options: settingsOptions, columns }) : null
80
+ settings ? /* @__PURE__ */ jsx(
81
+ TableHeaderSettings,
82
+ {
83
+ settings,
84
+ options: settingsOptions,
85
+ columns: settingsColumns != null ? settingsColumns : columns
86
+ }
87
+ ) : null
77
88
  ] }) : null;
78
89
  const toolbarContent = !showHeader && headerActions ? /* @__PURE__ */ jsxs("div", { className: styles.toolbarWithHeaderActions, children: [
79
90
  toolbar,
@@ -81,8 +92,30 @@ function Table({
81
92
  ] }) : toolbar;
82
93
  const selectionInputName = useId();
83
94
  const internalTableRootRef = useRef(null);
84
- const tableRootRefWrapper = useRef(tableRootRef);
85
95
  const hasSelection = Boolean(selectedRows && onRowSelect);
96
+ const hasRowActions = Boolean(getContextMenuItems) || showsExpandToggle(expandableRows, viewMode);
97
+ const hasHeaderActions = headerActionsProp != null || Boolean(settings);
98
+ const { px: actionReservePx, compactHeader: compactHeaderActionReserve } = getActionsReserve({
99
+ hasRowActions,
100
+ hasSettings: Boolean(settings),
101
+ hasOtherHeaderActions: headerActionsProp != null,
102
+ showHeader
103
+ });
104
+ const distributeWidths = useMemo(
105
+ () => tableWidth == null && (usesDistributedWidths(visibleColumns) || showHeader && hasHeaderActions),
106
+ [tableWidth, visibleColumns, showHeader, hasHeaderActions]
107
+ );
108
+ const availableWidth = useElementWidth(internalTableRootRef, distributeWidths);
109
+ const distributedLayout = useMemo(
110
+ () => distributeWidths && availableWidth != null ? distributeColumnWidths({
111
+ tracks: buildColumnTracks(visibleColumns),
112
+ hasSelection,
113
+ hasContextMenu: actionReservePx > 0,
114
+ contextMenuReservePx: actionReservePx,
115
+ availableWidth
116
+ }) : null,
117
+ [distributeWidths, availableWidth, visibleColumns, hasSelection, actionReservePx]
118
+ );
86
119
  const hasPagination = Boolean(onPageChange && (loading || data.length > 0));
87
120
  const paginationRef = useRef(null);
88
121
  const [paginationHeight, setPaginationHeight] = useState(0);
@@ -114,14 +147,10 @@ function Table({
114
147
  });
115
148
  const fillViewportActive = fillViewport && containScrolling;
116
149
  const stickyTop = stickyHeader === "app-header" ? "var(--app-header-height, 60px)" : typeof stickyHeader === "number" ? `${stickyHeader}px` : stickyHeader === void 0 && containScrolling ? "0px" : void 0;
117
- const setTableRootRef = useCallback((node) => {
118
- internalTableRootRef.current = node;
119
- if (typeof tableRootRefWrapper.current === "function") {
120
- tableRootRefWrapper.current(node);
121
- } else if (tableRootRefWrapper.current) {
122
- tableRootRefWrapper.current.current = node;
123
- }
124
- }, []);
150
+ const setTableRootRef = useMemo(
151
+ () => mergeRefs(internalTableRootRef, tableRootRef),
152
+ [tableRootRef]
153
+ );
125
154
  const handlePageChange = useCallback(
126
155
  (e) => {
127
156
  onPageChange == null ? void 0 : onPageChange(e);
@@ -178,9 +207,10 @@ function Table({
178
207
  styles.tableRoot,
179
208
  styles[variant],
180
209
  styles[size],
181
- measuringLayout && styles.measuringLayout,
210
+ (measuringLayout || distributeWidths && !distributedLayout) && styles.measuringLayout,
182
211
  getRowSeverity && styles.severityTable
183
212
  );
213
+ const resolvedTableWidth = tableWidth != null ? tableWidth : distributedLayout == null ? void 0 : distributedLayout.totalWidth;
184
214
  const tableElementClassName = cx(styles.tableElement, striped && "dbc-table--striped");
185
215
  const tableShell = /* @__PURE__ */ jsx("div", { ...rest, className: tableClassName, children: /* @__PURE__ */ jsx(
186
216
  "div",
@@ -194,17 +224,15 @@ function Table({
194
224
  className: tableElementClassName,
195
225
  "aria-rowcount": data.length,
196
226
  "data-show-header": showHeader,
197
- style: tableWidth != null ? { width: tableWidth } : void 0,
227
+ style: resolvedTableWidth != null ? { width: resolvedTableWidth } : void 0,
198
228
  children: [
199
229
  /* @__PURE__ */ jsxs("colgroup", { children: [
200
230
  hasSelection ? /* @__PURE__ */ jsx("col", { style: { width: SELECTION_COLUMN_PX } }) : null,
201
- visibleColumns.map((column) => /* @__PURE__ */ jsx(
202
- "col",
203
- {
204
- style: column.width != null ? { width: column.width } : void 0
205
- },
206
- column.id
207
- ))
231
+ visibleColumns.map((column) => {
232
+ var _a2;
233
+ const width = (_a2 = distributedLayout == null ? void 0 : distributedLayout.widths[column.id]) != null ? _a2 : column.width;
234
+ return /* @__PURE__ */ jsx("col", { style: width != null ? { width } : void 0 }, column.id);
235
+ })
208
236
  ] }),
209
237
  showHeader && /* @__PURE__ */ jsx(
210
238
  TableHeader,
@@ -212,7 +240,7 @@ function Table({
212
240
  columns: visibleColumns,
213
241
  hasSelection,
214
242
  selectionMode,
215
- hasRowContextMenu: Boolean(getContextMenuItems) || expandableRows,
243
+ hasRowContextMenu: hasRowActions,
216
244
  allRowsSelected,
217
245
  onSelectAllRows,
218
246
  sortById,
@@ -220,6 +248,7 @@ function Table({
220
248
  onSortChange,
221
249
  headerExtras,
222
250
  headerActions,
251
+ compactHeaderActionReserve,
223
252
  stickyTop
224
253
  }
225
254
  ),
@@ -379,6 +379,10 @@
379
379
  padding-inline-end: var(--table-row-actions-reserve-inline);
380
380
  }
381
381
 
382
+ .thMainWithHeaderActionsReserve {
383
+ padding-inline-end: calc(var(--component-size-sm) - var(--spacing-sm) + var(--spacing-2xs));
384
+ }
385
+
382
386
  .thMainRight {
383
387
  justify-content: flex-end;
384
388
  }
@@ -6,7 +6,22 @@ export interface ColumnItem<T> {
6
6
  id: string;
7
7
  header: string | (() => ReactNode);
8
8
  accessor?: keyof T;
9
+ /**
10
+ * Column width. When any column sets `minWidth`, `maxWidth` or `weight`,
11
+ * a numeric width pins the column to exactly that many pixels.
12
+ */
9
13
  width?: number | string;
14
+ /**
15
+ * Smallest width in pixels. Setting `minWidth`, `maxWidth` or `weight` on any
16
+ * column makes the table measure its container and distribute the width:
17
+ * each column starts at its minimum (default 80) and grows by `weight`
18
+ * towards `maxWidth`. Columns whose minimums don't fit scroll horizontally.
19
+ */
20
+ minWidth?: number;
21
+ /** Largest width in pixels. See `minWidth`. */
22
+ maxWidth?: number;
23
+ /** Relative share of the leftover width (default 1). See `minWidth`. */
24
+ weight?: number;
10
25
  sortable?: boolean;
11
26
  sortFunction?: (a: T, b: T) => -1 | 0 | 1;
12
27
  render?: (item: T) => ReactNode;
@@ -85,6 +100,12 @@ export type TableProps<T extends Record<string, any>> = Omit<HTMLAttributes<HTML
85
100
  emptyConfig?: any;
86
101
  variant?: TableVariant;
87
102
  size?: 'sm' | 'md';
103
+ /**
104
+ * `'wrapped'` (default) wraps cell text so all content is visible.
105
+ * `'compact'` keeps each row on one line with truncated text, for even row
106
+ * heights; rows can then be expanded with `expandableRows`.
107
+ * Overrides the view mode from `settings`.
108
+ */
88
109
  viewMode?: ViewMode;
89
110
  striped?: boolean;
90
111
  fillViewport?: boolean;
@@ -106,6 +127,12 @@ export type TableProps<T extends Record<string, any>> = Omit<HTMLAttributes<HTML
106
127
  * actions column. Falls back to the toolbar when `showHeader` is false.
107
128
  */
108
129
  headerActions?: ReactNode;
130
+ /**
131
+ * Columns listed in the settings menu. Defaults to `columns`; pass the
132
+ * original definitions when `columns` is derived from them with `hidden`
133
+ * already applied (as TanstackTable does).
134
+ */
135
+ settingsColumns?: ReadonlyArray<ColumnItem<T> | TableSettingsColumn>;
109
136
  /**
110
137
  * Shows a settings menu (stripes, text wrapping, column visibility) in the
111
138
  * header and applies its state to the table. Pass the result of
@@ -4,14 +4,15 @@
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var reactTable = require('@tanstack/react-table');
6
6
  var React = require('react');
7
- var ColumnResizer = require('./components/column-resizer/ColumnResizer');
8
- var TableHeaderSettings = require('./components/table-settings/TableHeaderSettings');
7
+ var useClientPagination = require('./hooks/useClientPagination');
8
+ var useDistributedLayout = require('./hooks/useDistributedLayout');
9
+ var useElementWidth = require('./hooks/useElementWidth');
10
+ var useResizeHeaderExtras = require('./hooks/useResizeHeaderExtras');
11
+ var useUiSorting = require('./hooks/useUiSorting');
9
12
  var Table = require('./Table');
10
13
  var table_utils = require('./table.utils');
11
14
  var tanstackTable_utils = require('./tanstackTable.utils');
12
15
 
13
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
-
15
16
  function _interopNamespace(e) {
16
17
  if (e && e.__esModule) return e;
17
18
  var n = Object.create(null);
@@ -31,9 +32,9 @@ function _interopNamespace(e) {
31
32
  }
32
33
 
33
34
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
34
- var ColumnResizer__default = /*#__PURE__*/_interopDefault(ColumnResizer);
35
35
 
36
36
  function TanstackTable(props) {
37
+ var _a, _b;
37
38
  const {
38
39
  data,
39
40
  dataKey,
@@ -43,6 +44,11 @@ function TanstackTable(props) {
43
44
  optimisticSortingUi = true,
44
45
  visibleColumnIds: visibleColumnIdsProp,
45
46
  manualSorting,
47
+ clientPagination = false,
48
+ take: takeProp,
49
+ skip: skipProp,
50
+ totalItemsCount: totalItemsCountProp,
51
+ onPageChange,
46
52
  viewMode,
47
53
  striped,
48
54
  settings,
@@ -53,37 +59,50 @@ function TanstackTable(props) {
53
59
  ...tableProps
54
60
  } = props;
55
61
  const visibleColumnIds = visibleColumnIdsProp != null ? visibleColumnIdsProp : settings == null ? void 0 : settings.visibleColumnIds;
56
- const isControlledSorting = controlledSorting != null;
57
- const [uiSorting, setUiSorting] = React__namespace.useState(controlledSorting != null ? controlledSorting : []);
58
- React__namespace.useEffect(() => {
59
- if (!isControlledSorting) return;
60
- if (tanstackTable_utils.sortingEqual(uiSorting, controlledSorting)) return;
61
- setUiSorting(controlledSorting);
62
- }, [isControlledSorting, controlledSorting, uiSorting]);
62
+ const [uiSorting, setUiSorting] = useUiSorting.useUiSorting(controlledSorting);
63
+ const pagination = useClientPagination.useClientPagination({
64
+ enabled: clientPagination,
65
+ rowCount: data.length,
66
+ take: takeProp,
67
+ skip: skipProp,
68
+ totalItemsCount: totalItemsCountProp,
69
+ onPageChange
70
+ });
71
+ const { resetPage } = pagination;
63
72
  const columnVisibility = React__namespace.useMemo(
64
73
  () => tanstackTable_utils.buildColumnVisibilityFromVisibleIds(columns, visibleColumnIds),
65
74
  [columns, visibleColumnIds]
66
75
  );
67
76
  const [columnSizing, setColumnSizing] = React__namespace.useState({});
77
+ const neighborResizeRef = React__namespace.useRef(null);
68
78
  const containerRef = React__namespace.useRef(null);
69
- const [availableWidth, setAvailableWidth] = React__namespace.useState(void 0);
79
+ const availableWidth = useElementWidth.useElementWidth(containerRef);
70
80
  const table = reactTable.useReactTable({
71
81
  data,
72
82
  columns,
73
83
  state: {
74
84
  sorting: uiSorting,
75
85
  columnSizing,
76
- columnVisibility
86
+ columnVisibility,
87
+ ...pagination.paginationState ? { pagination: pagination.paginationState } : {}
77
88
  },
78
89
  onSortingChange: (updater) => {
79
90
  const next = typeof updater === "function" ? updater(uiSorting) : updater;
80
91
  if (optimisticSortingUi) setUiSorting(next);
92
+ resetPage();
81
93
  onSortingChange == null ? void 0 : onSortingChange(next);
82
94
  },
83
- onColumnSizingChange: setColumnSizing,
95
+ onColumnSizingChange: (updater) => {
96
+ setColumnSizing((prev) => {
97
+ const next = typeof updater === "function" ? updater(prev) : updater;
98
+ const resize = neighborResizeRef.current;
99
+ return resize && table.getState().columnSizingInfo.isResizingColumn === resize.columnId ? tanstackTable_utils.applyNeighborResize(next, resize) : next;
100
+ });
101
+ },
84
102
  getCoreRowModel: reactTable.getCoreRowModel(),
85
103
  getSortedRowModel: reactTable.getSortedRowModel(),
86
104
  manualSorting: manualSorting != null ? manualSorting : false,
105
+ ...pagination.tableOptions,
87
106
  enableColumnResizing: true,
88
107
  columnResizeMode: "onChange",
89
108
  defaultColumn: {
@@ -92,116 +111,54 @@ function TanstackTable(props) {
92
111
  size: table_utils.DEFAULT_COLUMN_PX
93
112
  }
94
113
  });
95
- React__namespace.useLayoutEffect(() => {
96
- const el = containerRef.current;
97
- if (!el) return;
98
- const updateWidth = () => {
99
- const next = el.clientWidth;
100
- setAvailableWidth(next > 0 ? next : void 0);
101
- };
102
- updateWidth();
103
- if (typeof ResizeObserver === "undefined") {
104
- window.addEventListener("resize", updateWidth);
105
- return () => window.removeEventListener("resize", updateWidth);
106
- }
107
- const observer = new ResizeObserver((entries) => {
108
- var _a, _b, _c;
109
- const entry = entries[0];
110
- if (!entry) {
111
- updateWidth();
112
- return;
113
- }
114
- const contentWidth = (_c = (_b = (_a = entry.contentBoxSize) == null ? void 0 : _a[0]) == null ? void 0 : _b.inlineSize) != null ? _c : entry.contentRect.width;
115
- const next = Math.floor(contentWidth);
116
- setAvailableWidth(next > 0 ? next : void 0);
117
- });
118
- observer.observe(el);
119
- return () => observer.disconnect();
120
- }, []);
121
- const distributedLayout = React__namespace.useMemo(() => {
122
- if (availableWidth == null) return null;
123
- return tanstackTable_utils.buildDistributedColumnWidths({
124
- table,
125
- hasSelection: Boolean(selectedRows && onRowSelect && dataKey),
126
- // Row actions (context menu, expand toggle) and header actions (e.g. the
127
- // settings menu) all reserve space at the end of the last column.
128
- hasContextMenu: Boolean(
129
- tableProps.getContextMenuItems || tableProps.expandableRows || settings || headerActionsProp != null
130
- ),
131
- defaultMinPx: 80,
132
- columnSizing,
133
- availableWidth
134
- });
135
- }, [
114
+ const resolvedViewMode = (_a = viewMode != null ? viewMode : settings == null ? void 0 : settings.viewMode) != null ? _a : table_utils.DEFAULT_VIEW_MODE;
115
+ const { px: actionReservePx } = table_utils.getActionsReserve({
116
+ hasRowActions: Boolean(tableProps.getContextMenuItems) || table_utils.showsExpandToggle(tableProps.expandableRows, resolvedViewMode),
117
+ hasSettings: Boolean(settings),
118
+ hasOtherHeaderActions: headerActionsProp != null,
119
+ showHeader: (_b = tableProps.showHeader) != null ? _b : true
120
+ });
121
+ const { distributedLayout, columnItems } = useDistributedLayout.useDistributedLayout({
136
122
  table,
137
- selectedRows,
138
- onRowSelect,
139
- dataKey,
140
- tableProps.getContextMenuItems,
141
- tableProps.expandableRows,
142
- settings,
143
- headerActionsProp,
123
+ columns,
124
+ columnVisibility,
144
125
  columnSizing,
145
- availableWidth
146
- ]);
126
+ availableWidth,
127
+ hasSelection: Boolean(selectedRows && onRowSelect && dataKey),
128
+ actionReservePx
129
+ });
147
130
  const initialLayoutReady = availableWidth != null;
148
- const resolvedLayout = React__namespace.useMemo(() => {
149
- const next = {};
150
- table.getVisibleLeafColumns().forEach((column) => {
151
- next[column.id] = {
152
- width: distributedLayout == null ? void 0 : distributedLayout.widths[column.id]
153
- };
154
- });
155
- return next;
156
- }, [table, distributedLayout]);
157
- const columnItems = React__namespace.useMemo(
158
- () => tanstackTable_utils.mapDefsToColumnItems(columns, columnVisibility, resolvedLayout),
159
- [columns, columnVisibility, resolvedLayout]
160
- );
161
131
  const visibleData = table.getRowModel().rows.map((r) => r.original);
162
132
  const { sortById, sortDirection } = tanstackTable_utils.getSortPropsFromSorting(uiSorting);
163
133
  const handleSortChange = React__namespace.useCallback(
164
134
  (column, direction) => {
165
135
  const next = direction == null ? [] : [{ id: column.id, desc: direction === "desc" }];
166
136
  if (optimisticSortingUi) setUiSorting(next);
137
+ resetPage();
167
138
  onSortingChange == null ? void 0 : onSortingChange(next);
168
139
  },
169
- [optimisticSortingUi, onSortingChange]
140
+ [optimisticSortingUi, setUiSorting, resetPage, onSortingChange]
170
141
  );
171
- const headerExtras = React__namespace.useCallback(
172
- ({ index }) => {
173
- var _a, _b, _c, _d;
174
- const headerGroups = table.getHeaderGroups();
175
- const leafHeaders = headerGroups.length > 0 ? headerGroups[headerGroups.length - 1].headers : [];
176
- const header = leafHeaders[index];
177
- if (!header) return null;
178
- const canResize = (_c = (_b = (_a = header.column).getCanResize) == null ? void 0 : _b.call(_a)) != null ? _c : false;
179
- const handler = (_d = header.getResizeHandler) == null ? void 0 : _d.call(header);
180
- if (!canResize || !handler) return null;
181
- return /* @__PURE__ */ jsxRuntime.jsx(ColumnResizer__default.default, { id: header.column.id, handler });
182
- },
183
- [table]
184
- );
185
- const headerActions = headerActionsProp != null || settings ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
186
- headerActionsProp,
187
- settings ? /* @__PURE__ */ jsxRuntime.jsx(
188
- TableHeaderSettings.TableHeaderSettings,
189
- {
190
- settings,
191
- options: settingsOptions,
192
- columns
193
- }
194
- ) : null
195
- ] }) : void 0;
142
+ const headerExtras = useResizeHeaderExtras.useResizeHeaderExtras({
143
+ table,
144
+ widths: distributedLayout == null ? void 0 : distributedLayout.widths,
145
+ actionReservePx,
146
+ neighborResizeRef,
147
+ setColumnSizing
148
+ });
196
149
  return /* @__PURE__ */ jsxRuntime.jsx(
197
150
  Table.Table,
198
151
  {
199
152
  ...tableProps,
200
- viewMode: viewMode != null ? viewMode : settings == null ? void 0 : settings.viewMode,
153
+ viewMode: resolvedViewMode,
201
154
  striped: striped != null ? striped : settings == null ? void 0 : settings.striped,
202
- headerActions,
155
+ headerActions: headerActionsProp,
156
+ settings,
157
+ settingsOptions,
158
+ settingsColumns: columns,
203
159
  tableRootRef: containerRef,
204
160
  onSortChange: handleSortChange,
161
+ ...pagination.tableProps,
205
162
  dataKey,
206
163
  data: visibleData,
207
164
  columns: columnItems,
@@ -6,6 +6,11 @@ export type TanstackTableProps<T extends Record<string, any>> = Omit<TableProps<
6
6
  columns: ReadonlyArray<ColumnDef<T, any>>;
7
7
  sorting?: SortingState;
8
8
  manualSorting?: boolean;
9
+ /**
10
+ * Sorts all rows and then shows one page of `take` rows, starting at `skip`.
11
+ * Leave off when `data` is already a single page fetched from a server.
12
+ */
13
+ clientPagination?: boolean;
9
14
  onSortingChange?: (next: SortingState) => void;
10
15
  optimisticSortingUi?: boolean;
11
16
  variant?: TableVariant;