@snack-uikit/table 0.25.15-preview-9a001bce.0 → 0.25.15

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 (29) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +0 -8
  3. package/dist/cjs/components/Table/Table.d.ts +1 -1
  4. package/dist/cjs/components/Table/Table.js +29 -59
  5. package/dist/cjs/components/Table/styles.module.css +0 -4
  6. package/dist/cjs/components/Table/utils.d.ts +0 -10
  7. package/dist/cjs/components/Table/utils.js +0 -19
  8. package/dist/cjs/components/types.d.ts +1 -6
  9. package/dist/esm/components/Table/Table.d.ts +1 -1
  10. package/dist/esm/components/Table/Table.js +18 -38
  11. package/dist/esm/components/Table/styles.module.css +0 -4
  12. package/dist/esm/components/Table/utils.d.ts +0 -10
  13. package/dist/esm/components/Table/utils.js +0 -14
  14. package/dist/esm/components/types.d.ts +1 -6
  15. package/package.json +8 -10
  16. package/src/components/Table/Table.tsx +23 -67
  17. package/src/components/Table/styles.module.scss +0 -6
  18. package/src/components/Table/{utils.tsx → utils.ts} +0 -18
  19. package/src/components/types.ts +1 -10
  20. package/dist/cjs/components/Table/hooks/useRowVirtualizer.d.ts +0 -2
  21. package/dist/cjs/components/Table/hooks/useRowVirtualizer.js +0 -35
  22. package/dist/cjs/helperComponents/Rows/VirtualRow.d.ts +0 -7
  23. package/dist/cjs/helperComponents/Rows/VirtualRow.js +0 -40
  24. package/dist/esm/components/Table/hooks/useRowVirtualizer.d.ts +0 -2
  25. package/dist/esm/components/Table/hooks/useRowVirtualizer.js +0 -14
  26. package/dist/esm/helperComponents/Rows/VirtualRow.d.ts +0 -7
  27. package/dist/esm/helperComponents/Rows/VirtualRow.js +0 -26
  28. package/src/components/Table/hooks/useRowVirtualizer.ts +0 -44
  29. package/src/helperComponents/Rows/VirtualRow.tsx +0 -27
package/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 0.25.15 (2024-12-17)
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/button@0.19.5](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/button/CHANGELOG.md)
10
+ * [@snack-uikit/chips@0.22.4](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/chips/CHANGELOG.md)
11
+ * [@snack-uikit/info-block@0.6.6](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/info-block/CHANGELOG.md)
12
+ * [@snack-uikit/list@0.21.11](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/list/CHANGELOG.md)
13
+ * [@snack-uikit/pagination@0.9.5](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/pagination/CHANGELOG.md)
14
+ * [@snack-uikit/toolbar@0.9.13](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/toolbar/CHANGELOG.md)
15
+
16
+
17
+
18
+
19
+
6
20
  ## 0.25.14 (2024-12-12)
7
21
 
8
22
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -148,10 +148,6 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
148
148
  | scrollContainerRef | `RefObject<HTMLElement>` | - | Ссылка на контейнер, который скроллится |
149
149
  | rowPinning | `Pick<RowPinningState, "top">` | { top: [], } | Определение какие строки должны быть закреплены в таблице |
150
150
  | savedState | `{ id: string; resize?: boolean; }` | - | Конфиг для сохранения состояния в localStorage. <br> Поле id должно быть уникальным для разных таблиц в рамках приложения. <br> Для корректной работы необходимо наличие id в конфиге columnDefinitions |
151
- | onScroll | `(event?: Event) => void` | - | |
152
- | enableRowVirtualization | `boolean` | - | |
153
- | rowVirtualizerOptions | `PartialKeys<VirtualizerOptions<Element, Element>, "observeElementRect" \| "observeElementOffset" \| "scrollToFn">` | - | |
154
- | rowVirtualizerInstanceRef | `MutableRefObject<Virtualizer<Element, Element>>` | - | |
155
151
  ## Table.getStatusColumnDef
156
152
  Вспомогательная функция для создания ячейки со статусом
157
153
  ### Props
@@ -212,10 +208,6 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
212
208
  | scrollContainerRef | `RefObject<HTMLElement>` | - | Ссылка на контейнер, который скроллится |
213
209
  | rowPinning | `Pick<RowPinningState, "top">` | - | Определение какие строки должны быть закреплены в таблице |
214
210
  | savedState | `{ id: string; resize?: boolean; }` | - | Конфиг для сохранения состояния в localStorage. <br> Поле id должно быть уникальным для разных таблиц в рамках приложения. <br> Для корректной работы необходимо наличие id в конфиге columnDefinitions |
215
- | onScroll | `(event?: Event) => void` | - | |
216
- | enableRowVirtualization | `boolean` | - | |
217
- | rowVirtualizerOptions | `PartialKeys<VirtualizerOptions<Element, Element>, "observeElementRect" \| "observeElementOffset" \| "scrollToFn">` | - | |
218
- | rowVirtualizerInstanceRef | `MutableRefObject<Virtualizer<Element, Element>>` | - | |
219
211
  | items | `TData[]` | - | Данные для отрисовки |
220
212
  | total | `number` | 10 | Общее кол-во строк |
221
213
  | limit | `number` | 10 | Кол-во строк на страницу |
@@ -1,6 +1,6 @@
1
1
  import { TableProps } from '../types';
2
2
  /** Компонент таблицы */
3
- export declare function Table<TData extends object>({ data, rowPinning, columnDefinitions, keepPinnedRows, copyPinnedRows, enableSelectPinned, rowSelection: rowSelectionProp, search, sorting: sortingProp, columnFilters, pagination: paginationProp, className, onRowClick, onRefresh, onDelete, pageSize, pageCount, loading, outline, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar, toolbarBefore, toolbarAfter, suppressPagination, manualSorting, manualPagination, manualFiltering, autoResetPageIndex, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, onScroll, enableRowVirtualization, rowVirtualizerOptions, rowVirtualizerInstanceRef, ...rest }: TableProps<TData>): import("react/jsx-runtime").JSX.Element;
3
+ export declare function Table<TData extends object>({ data, rowPinning, columnDefinitions, keepPinnedRows, copyPinnedRows, enableSelectPinned, rowSelection: rowSelectionProp, search, sorting: sortingProp, columnFilters, pagination: paginationProp, className, onRowClick, onRefresh, onDelete, pageSize, pageCount, loading, outline, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar, toolbarBefore, toolbarAfter, suppressPagination, manualSorting, manualPagination, manualFiltering, autoResetPageIndex, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, ...rest }: TableProps<TData>): import("react/jsx-runtime").JSX.Element;
4
4
  export declare namespace Table {
5
5
  var getStatusColumnDef: typeof import("../../helperComponents").getStatusColumnDef;
6
6
  var statusAppearances: Record<string, string>;
@@ -20,25 +20,22 @@ exports.Table = Table;
20
20
  const jsx_runtime_1 = require("react/jsx-runtime");
21
21
  const react_table_1 = require("@tanstack/react-table");
22
22
  const classnames_1 = __importDefault(require("classnames"));
23
- const merge_refs_1 = __importDefault(require("merge-refs"));
24
23
  const react_1 = require("react");
25
24
  const locale_1 = require("@snack-uikit/locale");
26
25
  const scroll_1 = require("@snack-uikit/scroll");
27
26
  const skeleton_1 = require("@snack-uikit/skeleton");
28
27
  const toolbar_1 = require("@snack-uikit/toolbar");
28
+ const truncate_string_1 = require("@snack-uikit/truncate-string");
29
29
  const utils_1 = require("@snack-uikit/utils");
30
30
  const constants_1 = require("../../constants");
31
31
  const helperComponents_1 = require("../../helperComponents");
32
- const VirtualRow_1 = require("../../helperComponents/Rows/VirtualRow");
33
32
  const utils_2 = require("../../utils");
34
33
  const hooks_1 = require("./hooks");
35
34
  const usePageReset_1 = require("./hooks/usePageReset");
36
- const useRowVirtualizer_1 = require("./hooks/useRowVirtualizer");
37
35
  const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
38
36
  const utils_3 = require("./utils");
39
37
  /** Компонент таблицы */
40
38
  function Table(_a) {
41
- var _b, _c;
42
39
  var {
43
40
  data,
44
41
  rowPinning = {
@@ -80,13 +77,9 @@ function Table(_a) {
80
77
  scrollContainerRef,
81
78
  getRowId,
82
79
  enableFuzzySearch,
83
- savedState,
84
- onScroll,
85
- enableRowVirtualization,
86
- rowVirtualizerOptions,
87
- rowVirtualizerInstanceRef
80
+ savedState
88
81
  } = _a,
89
- rest = __rest(_a, ["data", "rowPinning", "columnDefinitions", "keepPinnedRows", "copyPinnedRows", "enableSelectPinned", "rowSelection", "search", "sorting", "columnFilters", "pagination", "className", "onRowClick", "onRefresh", "onDelete", "pageSize", "pageCount", "loading", "outline", "moreActions", "exportSettings", "dataFiltered", "dataError", "noDataState", "noResultsState", "errorDataState", "suppressToolbar", "toolbarBefore", "toolbarAfter", "suppressPagination", "manualSorting", "manualPagination", "manualFiltering", "autoResetPageIndex", "scrollRef", "scrollContainerRef", "getRowId", "enableFuzzySearch", "savedState", "onScroll", "enableRowVirtualization", "rowVirtualizerOptions", "rowVirtualizerInstanceRef"]);
82
+ rest = __rest(_a, ["data", "rowPinning", "columnDefinitions", "keepPinnedRows", "copyPinnedRows", "enableSelectPinned", "rowSelection", "search", "sorting", "columnFilters", "pagination", "className", "onRowClick", "onRefresh", "onDelete", "pageSize", "pageCount", "loading", "outline", "moreActions", "exportSettings", "dataFiltered", "dataError", "noDataState", "noResultsState", "errorDataState", "suppressToolbar", "toolbarBefore", "toolbarAfter", "suppressPagination", "manualSorting", "manualPagination", "manualFiltering", "autoResetPageIndex", "scrollRef", "scrollContainerRef", "getRowId", "enableFuzzySearch", "savedState"]);
90
83
  const {
91
84
  state: globalFilter,
92
85
  onStateChange: onGlobalFilterChange
@@ -108,7 +101,6 @@ function Table(_a) {
108
101
  onStateChange: onPaginationChange
109
102
  } = (0, hooks_1.useStateControl)(paginationProp, defaultPaginationState);
110
103
  const enableSelection = Boolean(rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.enable);
111
- const tableContainerRef = (0, react_1.useRef)(null);
112
104
  const tableColumns = (0, react_1.useMemo)(() => {
113
105
  let cols = columnDefinitions;
114
106
  if (enableSelection) {
@@ -146,7 +138,10 @@ function Table(_a) {
146
138
  enableSorting: false,
147
139
  enableResizing: false,
148
140
  minSize: 40,
149
- cell: utils_3.truncateCell
141
+ cell: cell => (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, {
142
+ text: String(cell.getValue()),
143
+ maxLines: 1
144
+ })
150
145
  },
151
146
  manualSorting,
152
147
  manualPagination,
@@ -169,13 +164,7 @@ function Table(_a) {
169
164
  getPaginationRowModel: (0, react_table_1.getPaginationRowModel)(),
170
165
  getCoreRowModel: (0, react_table_1.getCoreRowModel)(),
171
166
  columnResizeMode: 'onEnd',
172
- keepPinnedRows,
173
- meta: {
174
- tableContainerRef,
175
- rowVirtualizerInstanceRef,
176
- rowVirtualizerOptions,
177
- enableRowVirtualization
178
- }
167
+ keepPinnedRows
179
168
  });
180
169
  const {
181
170
  loadingTable
@@ -215,22 +204,10 @@ function Table(_a) {
215
204
  }, [loading, rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow, table, enableSelectPinned]);
216
205
  const columnSizeVarsRef = (0, react_1.useRef)();
217
206
  const headers = table.getFlatHeaders();
218
- const tableRows = table.getRowModel().rows;
219
- const tableCenterRows = table.getCenterRows();
220
- const tableFilteredRows = table.getFilteredRowModel().rows;
221
- const tableFilteredRowsIds = tableFilteredRows.map(row => row.id);
222
- const topRows = table.getTopRows();
223
- const loadingTableRows = loadingTable.getRowModel().rows;
224
- const tablePagination = table.getState().pagination;
225
- const [isScrollBeenInitialized, setScrollInitialization] = (0, react_1.useState)(false);
226
- const rowVirtualizer = (0, useRowVirtualizer_1.useRowVirtualizer)(table, isScrollBeenInitialized);
227
- const overallVirtualHeight = (_b = rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.getTotalSize()) !== null && _b !== void 0 ? _b : 0;
228
- const cssSizeVars = (0, react_1.useMemo)(() => {
207
+ const columnSizeVars = (0, react_1.useMemo)(() => {
229
208
  var _a;
230
209
  const originalColumnDefs = table._getColumnDefs();
231
- const colSizes = overallVirtualHeight > 0 ? {
232
- height: `${overallVirtualHeight}px`
233
- } : {};
210
+ const colSizes = {};
234
211
  for (let i = 0; i < headers.length; i++) {
235
212
  const header = headers[i];
236
213
  const {
@@ -288,10 +265,17 @@ function Table(_a) {
288
265
  table.getTotalSize() will trigger re-render after double-click size reset
289
266
  */
290
267
  // eslint-disable-next-line react-hooks/exhaustive-deps
291
- }, [table.getState().columnSizingInfo.isResizingColumn, headers, table.getTotalSize(), overallVirtualHeight]);
268
+ }, [table.getState().columnSizingInfo.isResizingColumn, headers, table.getTotalSize()]);
292
269
  (0, react_1.useEffect)(() => {
293
- columnSizeVarsRef.current = cssSizeVars;
294
- }, [cssSizeVars]);
270
+ columnSizeVarsRef.current = columnSizeVars;
271
+ }, [columnSizeVars]);
272
+ const tableRows = table.getRowModel().rows;
273
+ const tableCenterRows = table.getCenterRows();
274
+ const tableFilteredRows = table.getFilteredRowModel().rows;
275
+ const tableFilteredRowsIds = tableFilteredRows.map(row => row.id);
276
+ const topRows = table.getTopRows();
277
+ const loadingTableRows = loadingTable.getRowModel().rows;
278
+ const tablePagination = table.getState().pagination;
295
279
  const filteredTopRows = table.getState().globalFilter ? topRows.filter(tr => tableFilteredRowsIds.includes(tr.id)) : topRows;
296
280
  const centerRows = copyPinnedRows ? tableRows : tableCenterRows;
297
281
  const {
@@ -306,12 +290,6 @@ function Table(_a) {
306
290
  const tempPageSize = (!suppressPagination ? tablePagination === null || tablePagination === void 0 ? void 0 : tablePagination.pageSize : pageSize) + filteredTopRows.length;
307
291
  return !tableRows.length ? Math.min(Math.max(tempPageSize, 5), constants_1.DEFAULT_PAGE_SIZE) : tempPageSize;
308
292
  }, [filteredTopRows.length, pageSize, suppressPagination, tablePagination === null || tablePagination === void 0 ? void 0 : tablePagination.pageSize, tableRows.length]);
309
- const tableCtx = (0, react_1.useMemo)(() => ({
310
- table
311
- }), [table]);
312
- const onInitializeScroll = (0, react_1.useCallback)(() => {
313
- setScrollInitialization(true);
314
- }, []);
315
293
  (0, usePageReset_1.usePageReset)({
316
294
  manualPagination,
317
295
  maximumAvailablePage: pageCount || data.length / pagination.pageSize,
@@ -363,15 +341,15 @@ function Table(_a) {
363
341
  "data-outline": outline || undefined,
364
342
  children: (0, jsx_runtime_1.jsxs)(scroll_1.Scroll, {
365
343
  size: 's',
366
- ref: (0, merge_refs_1.default)(tableContainerRef, scrollContainerRef),
367
344
  className: styles_module_scss_1.default.table,
368
- onScroll: onScroll,
369
- onInitialized: onInitializeScroll,
345
+ ref: scrollContainerRef,
370
346
  children: [(0, jsx_runtime_1.jsx)("div", {
371
347
  className: styles_module_scss_1.default.tableContent,
372
- style: cssSizeVars,
348
+ style: columnSizeVars,
373
349
  children: (0, jsx_runtime_1.jsx)(helperComponents_1.TableContext.Provider, {
374
- value: tableCtx,
350
+ value: {
351
+ table
352
+ },
375
353
  children: loading ? (0, jsx_runtime_1.jsxs)(skeleton_1.SkeletonContextProvider, {
376
354
  loading: true,
377
355
  children: [(0, jsx_runtime_1.jsx)(helperComponents_1.HeaderRow, {}), loadingTableRows.map(row => (0, jsx_runtime_1.jsx)(helperComponents_1.BodyRow, {
@@ -384,18 +362,10 @@ function Table(_a) {
384
362
  row: row,
385
363
  onRowClick: onRowClick
386
364
  }, row.id))
387
- }) : null, ((_c = rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.getVirtualItems()) !== null && _c !== void 0 ? _c : centerRows).map((rowOrVirtualRow, index) => {
388
- const row = (0, utils_3.isVirtualRow)(rowOrVirtualRow) ? centerRows[rowOrVirtualRow.index] : centerRows[index];
389
- return (0, jsx_runtime_1.jsx)(VirtualRow_1.VirtualRow, {
390
- ref: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement,
391
- "data-index": row.index,
392
- virtualRow: (0, utils_3.isVirtualRow)(rowOrVirtualRow) ? rowOrVirtualRow : undefined,
393
- children: (0, jsx_runtime_1.jsx)(helperComponents_1.BodyRow, {
394
- row: row,
395
- onRowClick: onRowClick
396
- })
397
- }, row.id);
398
- }), (0, jsx_runtime_1.jsx)(helperComponents_1.TableEmptyState, {
365
+ }) : null, centerRows.map(row => (0, jsx_runtime_1.jsx)(helperComponents_1.BodyRow, {
366
+ row: row,
367
+ onRowClick: onRowClick
368
+ }, row.id)), (0, jsx_runtime_1.jsx)(helperComponents_1.TableEmptyState, {
399
369
  emptyStates: emptyStates,
400
370
  dataError: dataError,
401
371
  dataFiltered: dataFiltered || Boolean(table.getState().globalFilter),
@@ -1,11 +1,8 @@
1
1
  .table{
2
2
  border-width:var(--border-width-table, 1px);
3
3
  border-radius:var(--radius-table-container, 14px);
4
- will-change:transform;
5
- overflow-anchor:none;
6
4
  position:relative;
7
5
  z-index:0;
8
- contain:paint;
9
6
  overflow:hidden !important;
10
7
  display:flex;
11
8
  box-sizing:border-box;
@@ -29,7 +26,6 @@
29
26
  }
30
27
 
31
28
  .tableContent{
32
- content-visibility:auto;
33
29
  min-width:-moz-max-content;
34
30
  min-width:max-content;
35
31
  }
@@ -1,5 +1,3 @@
1
- import { CellContext } from '@tanstack/react-table';
2
- import { VirtualItem } from '@tanstack/react-virtual';
3
1
  export declare function getCurrentlyConfiguredHeaderWidth(id: string): number;
4
2
  export declare function getColumnStyleVars(id: string): {
5
3
  sizeKey: string;
@@ -16,12 +14,4 @@ type SaveStateToLocalStorageProps = {
16
14
  size: string;
17
15
  };
18
16
  export declare function saveStateToLocalStorage({ id, columnId, size }: SaveStateToLocalStorageProps): void;
19
- /**
20
- * check the key, because index is contained in a common table row
21
- */
22
- export declare function isVirtualRow(row: unknown): row is VirtualItem;
23
- /**
24
- * @description prevent permanent recreation of the function on rerender
25
- */
26
- export declare function truncateCell<TData>(cell: CellContext<TData, unknown>): import("react/jsx-runtime").JSX.Element;
27
17
  export {};
@@ -7,10 +7,6 @@ exports.getCurrentlyConfiguredHeaderWidth = getCurrentlyConfiguredHeaderWidth;
7
7
  exports.getColumnStyleVars = getColumnStyleVars;
8
8
  exports.getInitColumnSizeFromLocalStorage = getInitColumnSizeFromLocalStorage;
9
9
  exports.saveStateToLocalStorage = saveStateToLocalStorage;
10
- exports.isVirtualRow = isVirtualRow;
11
- exports.truncateCell = truncateCell;
12
- const jsx_runtime_1 = require("react/jsx-runtime");
13
- const truncate_string_1 = require("@snack-uikit/truncate-string");
14
10
  const utils_1 = require("@snack-uikit/utils");
15
11
  function getCurrentlyConfiguredHeaderWidth(id) {
16
12
  if ((0, utils_1.isBrowser)()) {
@@ -57,19 +53,4 @@ function saveStateToLocalStorage(_ref2) {
57
53
  localStorage.setItem(id, JSON.stringify(Object.assign(Object.assign({}, savedStateFromStorage || {}), {
58
54
  resizeState: newResizeState
59
55
  })));
60
- }
61
- /**
62
- * check the key, because index is contained in a common table row
63
- */
64
- function isVirtualRow(row) {
65
- return typeof row === 'object' && row != null && 'key' in row;
66
- }
67
- /**
68
- * @description prevent permanent recreation of the function on rerender
69
- */
70
- function truncateCell(cell) {
71
- return (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, {
72
- text: String(cell.getValue()),
73
- maxLines: 1
74
- });
75
56
  }
@@ -1,6 +1,5 @@
1
1
  import { PaginationState, Row, RowPinningState, RowSelectionOptions, RowSelectionState, SortingState } from '@tanstack/react-table';
2
- import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
3
- import { MutableRefObject, ReactNode, RefObject } from 'react';
2
+ import { ReactNode, RefObject } from 'react';
4
3
  import { ToolbarProps } from '@snack-uikit/toolbar';
5
4
  import { WithSupportProps } from '@snack-uikit/utils';
6
5
  import { EmptyStateProps, ExportButtonProps, RowClickHandler } from '../helperComponents';
@@ -130,10 +129,6 @@ export type TableProps<TData extends object> = WithSupportProps<{
130
129
  id: string;
131
130
  resize?: boolean;
132
131
  };
133
- onScroll?: (event?: Event) => void;
134
- enableRowVirtualization?: boolean;
135
- rowVirtualizerOptions?: Parameters<typeof useVirtualizer>[0];
136
- rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<Element, Element> | null>;
137
132
  }>;
138
133
  export type ServerTableProps<TData extends object> = Omit<TableProps<TData>, 'pageSize' | 'pageCount' | 'pagination' | 'search' | 'data'> & {
139
134
  /** Данные для отрисовки */
@@ -1,6 +1,6 @@
1
1
  import { TableProps } from '../types';
2
2
  /** Компонент таблицы */
3
- export declare function Table<TData extends object>({ data, rowPinning, columnDefinitions, keepPinnedRows, copyPinnedRows, enableSelectPinned, rowSelection: rowSelectionProp, search, sorting: sortingProp, columnFilters, pagination: paginationProp, className, onRowClick, onRefresh, onDelete, pageSize, pageCount, loading, outline, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar, toolbarBefore, toolbarAfter, suppressPagination, manualSorting, manualPagination, manualFiltering, autoResetPageIndex, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, onScroll, enableRowVirtualization, rowVirtualizerOptions, rowVirtualizerInstanceRef, ...rest }: TableProps<TData>): import("react/jsx-runtime").JSX.Element;
3
+ export declare function Table<TData extends object>({ data, rowPinning, columnDefinitions, keepPinnedRows, copyPinnedRows, enableSelectPinned, rowSelection: rowSelectionProp, search, sorting: sortingProp, columnFilters, pagination: paginationProp, className, onRowClick, onRefresh, onDelete, pageSize, pageCount, loading, outline, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar, toolbarBefore, toolbarAfter, suppressPagination, manualSorting, manualPagination, manualFiltering, autoResetPageIndex, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, ...rest }: TableProps<TData>): import("react/jsx-runtime").JSX.Element;
4
4
  export declare namespace Table {
5
5
  var getStatusColumnDef: typeof import("../../helperComponents").getStatusColumnDef;
6
6
  var statusAppearances: Record<string, string>;
@@ -12,28 +12,25 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable, } from '@tanstack/react-table';
14
14
  import cn from 'classnames';
15
- import mergeRefs from 'merge-refs';
16
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
15
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
17
16
  import { useLocale } from '@snack-uikit/locale';
18
17
  import { Scroll } from '@snack-uikit/scroll';
19
18
  import { SkeletonContextProvider } from '@snack-uikit/skeleton';
20
19
  import { Toolbar } from '@snack-uikit/toolbar';
20
+ import { TruncateString } from '@snack-uikit/truncate-string';
21
21
  import { extractSupportProps } from '@snack-uikit/utils';
22
22
  import { DEFAULT_PAGE_SIZE } from '../../constants';
23
23
  import { BodyRow, ExportButton, getColumnId, getRowActionsColumnDef, getSelectionCellColumnDef, getStatusColumnDef, HeaderRow, STATUS_APPEARANCE, TableContext, TableEmptyState, TablePagination, useEmptyState, } from '../../helperComponents';
24
- import { VirtualRow } from '../../helperComponents/Rows/VirtualRow';
25
24
  import { fuzzyFilter } from '../../utils';
26
25
  import { useLoadingTable, useStateControl } from './hooks';
27
26
  import { usePageReset } from './hooks/usePageReset';
28
- import { useRowVirtualizer } from './hooks/useRowVirtualizer';
29
27
  import styles from './styles.module.css';
30
- import { getColumnStyleVars, getCurrentlyConfiguredHeaderWidth, getInitColumnSizeFromLocalStorage, isVirtualRow, saveStateToLocalStorage, truncateCell, } from './utils';
28
+ import { getColumnStyleVars, getCurrentlyConfiguredHeaderWidth, getInitColumnSizeFromLocalStorage, saveStateToLocalStorage, } from './utils';
31
29
  /** Компонент таблицы */
32
30
  export function Table(_a) {
33
- var _b, _c;
34
31
  var { data, rowPinning = {
35
32
  top: [],
36
- }, columnDefinitions, keepPinnedRows = false, copyPinnedRows = false, enableSelectPinned = false, rowSelection: rowSelectionProp, search, sorting: sortingProp, columnFilters, pagination: paginationProp, className, onRowClick, onRefresh, onDelete, pageSize = DEFAULT_PAGE_SIZE, pageCount, loading = false, outline = false, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar = false, toolbarBefore, toolbarAfter, suppressPagination = false, manualSorting = false, manualPagination = false, manualFiltering = false, autoResetPageIndex = false, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, onScroll, enableRowVirtualization, rowVirtualizerOptions, rowVirtualizerInstanceRef } = _a, rest = __rest(_a, ["data", "rowPinning", "columnDefinitions", "keepPinnedRows", "copyPinnedRows", "enableSelectPinned", "rowSelection", "search", "sorting", "columnFilters", "pagination", "className", "onRowClick", "onRefresh", "onDelete", "pageSize", "pageCount", "loading", "outline", "moreActions", "exportSettings", "dataFiltered", "dataError", "noDataState", "noResultsState", "errorDataState", "suppressToolbar", "toolbarBefore", "toolbarAfter", "suppressPagination", "manualSorting", "manualPagination", "manualFiltering", "autoResetPageIndex", "scrollRef", "scrollContainerRef", "getRowId", "enableFuzzySearch", "savedState", "onScroll", "enableRowVirtualization", "rowVirtualizerOptions", "rowVirtualizerInstanceRef"]);
33
+ }, columnDefinitions, keepPinnedRows = false, copyPinnedRows = false, enableSelectPinned = false, rowSelection: rowSelectionProp, search, sorting: sortingProp, columnFilters, pagination: paginationProp, className, onRowClick, onRefresh, onDelete, pageSize = DEFAULT_PAGE_SIZE, pageCount, loading = false, outline = false, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar = false, toolbarBefore, toolbarAfter, suppressPagination = false, manualSorting = false, manualPagination = false, manualFiltering = false, autoResetPageIndex = false, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState } = _a, rest = __rest(_a, ["data", "rowPinning", "columnDefinitions", "keepPinnedRows", "copyPinnedRows", "enableSelectPinned", "rowSelection", "search", "sorting", "columnFilters", "pagination", "className", "onRowClick", "onRefresh", "onDelete", "pageSize", "pageCount", "loading", "outline", "moreActions", "exportSettings", "dataFiltered", "dataError", "noDataState", "noResultsState", "errorDataState", "suppressToolbar", "toolbarBefore", "toolbarAfter", "suppressPagination", "manualSorting", "manualPagination", "manualFiltering", "autoResetPageIndex", "scrollRef", "scrollContainerRef", "getRowId", "enableFuzzySearch", "savedState"]);
37
34
  const { state: globalFilter, onStateChange: onGlobalFilterChange } = useStateControl(search, '');
38
35
  const { state: rowSelection, onStateChange: onRowSelectionChange } = useStateControl(rowSelectionProp, {});
39
36
  const defaultPaginationState = useMemo(() => ({
@@ -43,7 +40,6 @@ export function Table(_a) {
43
40
  const { state: sorting, onStateChange: onSortingChange } = useStateControl(sortingProp, []);
44
41
  const { state: pagination, onStateChange: onPaginationChange } = useStateControl(paginationProp, defaultPaginationState);
45
42
  const enableSelection = Boolean(rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.enable);
46
- const tableContainerRef = useRef(null);
47
43
  const tableColumns = useMemo(() => {
48
44
  let cols = columnDefinitions;
49
45
  if (enableSelection) {
@@ -78,7 +74,7 @@ export function Table(_a) {
78
74
  enableSorting: false,
79
75
  enableResizing: false,
80
76
  minSize: 40,
81
- cell: truncateCell,
77
+ cell: (cell) => _jsx(TruncateString, { text: String(cell.getValue()), maxLines: 1 }),
82
78
  },
83
79
  manualSorting,
84
80
  manualPagination,
@@ -102,12 +98,6 @@ export function Table(_a) {
102
98
  getCoreRowModel: getCoreRowModel(),
103
99
  columnResizeMode: 'onEnd',
104
100
  keepPinnedRows,
105
- meta: {
106
- tableContainerRef,
107
- rowVirtualizerInstanceRef,
108
- rowVirtualizerOptions,
109
- enableRowVirtualization,
110
- },
111
101
  });
112
102
  const { loadingTable } = useLoadingTable({
113
103
  pageSize: Math.min(Math.max(pageSize, 5), DEFAULT_PAGE_SIZE),
@@ -145,20 +135,10 @@ export function Table(_a) {
145
135
  }, [loading, rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow, table, enableSelectPinned]);
146
136
  const columnSizeVarsRef = useRef();
147
137
  const headers = table.getFlatHeaders();
148
- const tableRows = table.getRowModel().rows;
149
- const tableCenterRows = table.getCenterRows();
150
- const tableFilteredRows = table.getFilteredRowModel().rows;
151
- const tableFilteredRowsIds = tableFilteredRows.map(row => row.id);
152
- const topRows = table.getTopRows();
153
- const loadingTableRows = loadingTable.getRowModel().rows;
154
- const tablePagination = table.getState().pagination;
155
- const [isScrollBeenInitialized, setScrollInitialization] = useState(false);
156
- const rowVirtualizer = useRowVirtualizer(table, isScrollBeenInitialized);
157
- const overallVirtualHeight = (_b = rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.getTotalSize()) !== null && _b !== void 0 ? _b : 0;
158
- const cssSizeVars = useMemo(() => {
138
+ const columnSizeVars = useMemo(() => {
159
139
  var _a;
160
140
  const originalColumnDefs = table._getColumnDefs();
161
- const colSizes = overallVirtualHeight > 0 ? { height: `${overallVirtualHeight}px` } : {};
141
+ const colSizes = {};
162
142
  for (let i = 0; i < headers.length; i++) {
163
143
  const header = headers[i];
164
144
  const { sizeKey, flexKey } = getColumnStyleVars(header.id);
@@ -207,10 +187,17 @@ export function Table(_a) {
207
187
  table.getTotalSize() will trigger re-render after double-click size reset
208
188
  */
209
189
  // eslint-disable-next-line react-hooks/exhaustive-deps
210
- }, [table.getState().columnSizingInfo.isResizingColumn, headers, table.getTotalSize(), overallVirtualHeight]);
190
+ }, [table.getState().columnSizingInfo.isResizingColumn, headers, table.getTotalSize()]);
211
191
  useEffect(() => {
212
- columnSizeVarsRef.current = cssSizeVars;
213
- }, [cssSizeVars]);
192
+ columnSizeVarsRef.current = columnSizeVars;
193
+ }, [columnSizeVars]);
194
+ const tableRows = table.getRowModel().rows;
195
+ const tableCenterRows = table.getCenterRows();
196
+ const tableFilteredRows = table.getFilteredRowModel().rows;
197
+ const tableFilteredRowsIds = tableFilteredRows.map(row => row.id);
198
+ const topRows = table.getTopRows();
199
+ const loadingTableRows = loadingTable.getRowModel().rows;
200
+ const tablePagination = table.getState().pagination;
214
201
  const filteredTopRows = table.getState().globalFilter
215
202
  ? topRows.filter(tr => tableFilteredRowsIds.includes(tr.id))
216
203
  : topRows;
@@ -221,10 +208,6 @@ export function Table(_a) {
221
208
  const tempPageSize = (!suppressPagination ? tablePagination === null || tablePagination === void 0 ? void 0 : tablePagination.pageSize : pageSize) + filteredTopRows.length;
222
209
  return !tableRows.length ? Math.min(Math.max(tempPageSize, 5), DEFAULT_PAGE_SIZE) : tempPageSize;
223
210
  }, [filteredTopRows.length, pageSize, suppressPagination, tablePagination === null || tablePagination === void 0 ? void 0 : tablePagination.pageSize, tableRows.length]);
224
- const tableCtx = useMemo(() => ({ table }), [table]);
225
- const onInitializeScroll = useCallback(() => {
226
- setScrollInitialization(true);
227
- }, []);
228
211
  usePageReset({
229
212
  manualPagination,
230
213
  maximumAvailablePage: pageCount || data.length / pagination.pageSize,
@@ -239,10 +222,7 @@ export function Table(_a) {
239
222
  onChange: onGlobalFilterChange,
240
223
  loading: search === null || search === void 0 ? void 0 : search.loading,
241
224
  placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) || t('searchPlaceholder'),
242
- }, checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected(), className: styles.toolbar, onRefresh: onRefresh ? handleOnRefresh : undefined, onDelete: enableSelection && onDelete ? handleOnDelete : undefined, onCheck: enableSelection ? handleOnCheck : undefined, outline: outline, selectionMode: (rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow) ? 'multiple' : 'single', before: toolbarBefore, after: toolbarAfter || exportSettings ? (_jsxs(_Fragment, { children: [toolbarAfter, exportSettings && (_jsx(ExportButton, { settings: exportSettings, columnDefinitions: columnDefinitions, data: data, topRows: filteredTopRows, centerRows: centerRows }))] })) : undefined, moreActions: moreActions }), columnFilters && _jsxs("div", { className: styles.filtersWrapper, children: [" ", columnFilters, " "] })] })), _jsx("div", { className: styles.scrollWrapper, "data-outline": outline || undefined, children: _jsxs(Scroll, { size: 's', ref: mergeRefs(tableContainerRef, scrollContainerRef), className: styles.table, onScroll: onScroll, onInitialized: onInitializeScroll, children: [_jsx("div", { className: styles.tableContent, style: cssSizeVars, children: _jsx(TableContext.Provider, { value: tableCtx, children: loading ? (_jsxs(SkeletonContextProvider, { loading: true, children: [_jsx(HeaderRow, {}), loadingTableRows.map(row => (_jsx(BodyRow, { row: row }, row.id)))] })) : (_jsxs(_Fragment, { children: [centerRows.length || filteredTopRows.length ? _jsx(HeaderRow, {}) : null, filteredTopRows.length ? (_jsx("div", { className: styles.topRowWrapper, children: filteredTopRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick }, row.id))) })) : null, ((_c = rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.getVirtualItems()) !== null && _c !== void 0 ? _c : centerRows).map((rowOrVirtualRow, index) => {
243
- const row = isVirtualRow(rowOrVirtualRow) ? centerRows[rowOrVirtualRow.index] : centerRows[index];
244
- return (_jsx(VirtualRow, { ref: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement, "data-index": row.index, virtualRow: isVirtualRow(rowOrVirtualRow) ? rowOrVirtualRow : undefined, children: _jsx(BodyRow, { row: row, onRowClick: onRowClick }) }, row.id));
245
- }), _jsx(TableEmptyState, { emptyStates: emptyStates, dataError: dataError, dataFiltered: dataFiltered || Boolean(table.getState().globalFilter), tableRowsLength: tableRows.length + filteredTopRows.length })] })) }) }), _jsx("div", { className: styles.scrollStub, ref: scrollRef })] }) }), !suppressPagination && (_jsx(TablePagination, { table: table, options: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.options, optionsLabel: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsLabel, pageCount: pageCount, optionsRender: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsRender }))] })) }));
225
+ }, checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected(), className: styles.toolbar, onRefresh: onRefresh ? handleOnRefresh : undefined, onDelete: enableSelection && onDelete ? handleOnDelete : undefined, onCheck: enableSelection ? handleOnCheck : undefined, outline: outline, selectionMode: (rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow) ? 'multiple' : 'single', before: toolbarBefore, after: toolbarAfter || exportSettings ? (_jsxs(_Fragment, { children: [toolbarAfter, exportSettings && (_jsx(ExportButton, { settings: exportSettings, columnDefinitions: columnDefinitions, data: data, topRows: filteredTopRows, centerRows: centerRows }))] })) : undefined, moreActions: moreActions }), columnFilters && _jsxs("div", { className: styles.filtersWrapper, children: [" ", columnFilters, " "] })] })), _jsx("div", { className: styles.scrollWrapper, "data-outline": outline || undefined, children: _jsxs(Scroll, { size: 's', className: styles.table, ref: scrollContainerRef, children: [_jsx("div", { className: styles.tableContent, style: columnSizeVars, children: _jsx(TableContext.Provider, { value: { table }, children: loading ? (_jsxs(SkeletonContextProvider, { loading: true, children: [_jsx(HeaderRow, {}), loadingTableRows.map(row => (_jsx(BodyRow, { row: row }, row.id)))] })) : (_jsxs(_Fragment, { children: [centerRows.length || filteredTopRows.length ? _jsx(HeaderRow, {}) : null, filteredTopRows.length ? (_jsx("div", { className: styles.topRowWrapper, children: filteredTopRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick }, row.id))) })) : null, centerRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick }, row.id))), _jsx(TableEmptyState, { emptyStates: emptyStates, dataError: dataError, dataFiltered: dataFiltered || Boolean(table.getState().globalFilter), tableRowsLength: tableRows.length + filteredTopRows.length })] })) }) }), _jsx("div", { className: styles.scrollStub, ref: scrollRef })] }) }), !suppressPagination && (_jsx(TablePagination, { table: table, options: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.options, optionsLabel: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsLabel, pageCount: pageCount, optionsRender: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsRender }))] })) }));
246
226
  }
247
227
  Table.getStatusColumnDef = getStatusColumnDef;
248
228
  Table.statusAppearances = STATUS_APPEARANCE;
@@ -1,11 +1,8 @@
1
1
  .table{
2
2
  border-width:var(--border-width-table, 1px);
3
3
  border-radius:var(--radius-table-container, 14px);
4
- will-change:transform;
5
- overflow-anchor:none;
6
4
  position:relative;
7
5
  z-index:0;
8
- contain:paint;
9
6
  overflow:hidden !important;
10
7
  display:flex;
11
8
  box-sizing:border-box;
@@ -29,7 +26,6 @@
29
26
  }
30
27
 
31
28
  .tableContent{
32
- content-visibility:auto;
33
29
  min-width:-moz-max-content;
34
30
  min-width:max-content;
35
31
  }
@@ -1,5 +1,3 @@
1
- import { CellContext } from '@tanstack/react-table';
2
- import { VirtualItem } from '@tanstack/react-virtual';
3
1
  export declare function getCurrentlyConfiguredHeaderWidth(id: string): number;
4
2
  export declare function getColumnStyleVars(id: string): {
5
3
  sizeKey: string;
@@ -16,12 +14,4 @@ type SaveStateToLocalStorageProps = {
16
14
  size: string;
17
15
  };
18
16
  export declare function saveStateToLocalStorage({ id, columnId, size }: SaveStateToLocalStorageProps): void;
19
- /**
20
- * check the key, because index is contained in a common table row
21
- */
22
- export declare function isVirtualRow(row: unknown): row is VirtualItem;
23
- /**
24
- * @description prevent permanent recreation of the function on rerender
25
- */
26
- export declare function truncateCell<TData>(cell: CellContext<TData, unknown>): import("react/jsx-runtime").JSX.Element;
27
17
  export {};
@@ -1,5 +1,3 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { TruncateString } from '@snack-uikit/truncate-string';
3
1
  import { isBrowser } from '@snack-uikit/utils';
4
2
  export function getCurrentlyConfiguredHeaderWidth(id) {
5
3
  if (isBrowser()) {
@@ -34,15 +32,3 @@ export function saveStateToLocalStorage({ id, columnId, size }) {
34
32
  newResizeState[`${RESIZED_KEY}-${columnId}`] = size;
35
33
  localStorage.setItem(id, JSON.stringify(Object.assign(Object.assign({}, (savedStateFromStorage || {})), { resizeState: newResizeState })));
36
34
  }
37
- /**
38
- * check the key, because index is contained in a common table row
39
- */
40
- export function isVirtualRow(row) {
41
- return typeof row === 'object' && row != null && 'key' in row;
42
- }
43
- /**
44
- * @description prevent permanent recreation of the function on rerender
45
- */
46
- export function truncateCell(cell) {
47
- return _jsx(TruncateString, { text: String(cell.getValue()), maxLines: 1 });
48
- }
@@ -1,6 +1,5 @@
1
1
  import { PaginationState, Row, RowPinningState, RowSelectionOptions, RowSelectionState, SortingState } from '@tanstack/react-table';
2
- import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
3
- import { MutableRefObject, ReactNode, RefObject } from 'react';
2
+ import { ReactNode, RefObject } from 'react';
4
3
  import { ToolbarProps } from '@snack-uikit/toolbar';
5
4
  import { WithSupportProps } from '@snack-uikit/utils';
6
5
  import { EmptyStateProps, ExportButtonProps, RowClickHandler } from '../helperComponents';
@@ -130,10 +129,6 @@ export type TableProps<TData extends object> = WithSupportProps<{
130
129
  id: string;
131
130
  resize?: boolean;
132
131
  };
133
- onScroll?: (event?: Event) => void;
134
- enableRowVirtualization?: boolean;
135
- rowVirtualizerOptions?: Parameters<typeof useVirtualizer>[0];
136
- rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<Element, Element> | null>;
137
132
  }>;
138
133
  export type ServerTableProps<TData extends object> = Omit<TableProps<TData>, 'pageSize' | 'pageCount' | 'pagination' | 'search' | 'data'> & {
139
134
  /** Данные для отрисовки */
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Table",
7
- "version": "0.25.15-preview-9a001bce.0",
7
+ "version": "0.25.15",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -36,32 +36,30 @@
36
36
  "license": "Apache-2.0",
37
37
  "scripts": {},
38
38
  "dependencies": {
39
- "@snack-uikit/button": "0.19.4",
40
- "@snack-uikit/chips": "0.22.3",
39
+ "@snack-uikit/button": "0.19.5",
40
+ "@snack-uikit/chips": "0.22.4",
41
41
  "@snack-uikit/icon-predefined": "0.7.2",
42
42
  "@snack-uikit/icons": "0.24.1",
43
- "@snack-uikit/info-block": "0.6.5",
44
- "@snack-uikit/list": "0.21.10",
45
- "@snack-uikit/pagination": "0.9.4",
43
+ "@snack-uikit/info-block": "0.6.6",
44
+ "@snack-uikit/list": "0.21.11",
45
+ "@snack-uikit/pagination": "0.9.5",
46
46
  "@snack-uikit/scroll": "0.9.2",
47
47
  "@snack-uikit/skeleton": "0.6.1",
48
48
  "@snack-uikit/toggles": "0.13.2",
49
- "@snack-uikit/toolbar": "0.9.12",
49
+ "@snack-uikit/toolbar": "0.9.13",
50
50
  "@snack-uikit/truncate-string": "0.6.2",
51
51
  "@snack-uikit/typography": "0.8.3",
52
52
  "@snack-uikit/utils": "3.6.0",
53
53
  "@tanstack/match-sorter-utils": "8.11.8",
54
54
  "@tanstack/react-table": "8.12.0",
55
- "@tanstack/react-virtual": "3.10.9",
56
55
  "classnames": "2.5.1",
57
56
  "copy-to-clipboard": "3.3.3",
58
57
  "lodash.debounce": "4.0.8",
59
- "merge-refs": "1.3.0",
60
58
  "uncontrollable": "8.0.4",
61
59
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
62
60
  },
63
61
  "peerDependencies": {
64
62
  "@snack-uikit/locale": "*"
65
63
  },
66
- "gitHead": "65cdde31cadc1bf88bf053786656d0a12c19a1d4"
64
+ "gitHead": "33a6d8bc270bd11dec3e4834f2ba8e97c57d5c15"
67
65
  }
@@ -1,4 +1,5 @@
1
1
  import {
2
+ CellContext,
2
3
  ColumnPinningState,
3
4
  getCoreRowModel,
4
5
  getFilteredRowModel,
@@ -10,13 +11,13 @@ import {
10
11
  useReactTable,
11
12
  } from '@tanstack/react-table';
12
13
  import cn from 'classnames';
13
- import mergeRefs from 'merge-refs';
14
- import { RefObject, useCallback, useEffect, useMemo, useRef, useState } from 'react';
14
+ import { RefObject, useCallback, useEffect, useMemo, useRef } from 'react';
15
15
 
16
16
  import { useLocale } from '@snack-uikit/locale';
17
17
  import { Scroll } from '@snack-uikit/scroll';
18
18
  import { SkeletonContextProvider } from '@snack-uikit/skeleton';
19
19
  import { Toolbar } from '@snack-uikit/toolbar';
20
+ import { TruncateString } from '@snack-uikit/truncate-string';
20
21
  import { extractSupportProps } from '@snack-uikit/utils';
21
22
 
22
23
  import { DEFAULT_PAGE_SIZE } from '../../constants';
@@ -34,21 +35,17 @@ import {
34
35
  TablePagination,
35
36
  useEmptyState,
36
37
  } from '../../helperComponents';
37
- import { VirtualRow } from '../../helperComponents/Rows/VirtualRow';
38
38
  import { ColumnDefinition } from '../../types';
39
39
  import { fuzzyFilter } from '../../utils';
40
40
  import { TableProps } from '../types';
41
41
  import { useLoadingTable, useStateControl } from './hooks';
42
42
  import { usePageReset } from './hooks/usePageReset';
43
- import { useRowVirtualizer } from './hooks/useRowVirtualizer';
44
43
  import styles from './styles.module.scss';
45
44
  import {
46
45
  getColumnStyleVars,
47
46
  getCurrentlyConfiguredHeaderWidth,
48
47
  getInitColumnSizeFromLocalStorage,
49
- isVirtualRow,
50
48
  saveStateToLocalStorage,
51
- truncateCell,
52
49
  } from './utils';
53
50
 
54
51
  /** Компонент таблицы */
@@ -95,11 +92,6 @@ export function Table<TData extends object>({
95
92
  enableFuzzySearch,
96
93
  savedState,
97
94
 
98
- onScroll,
99
- enableRowVirtualization,
100
- rowVirtualizerOptions,
101
- rowVirtualizerInstanceRef,
102
-
103
95
  ...rest
104
96
  }: TableProps<TData>) {
105
97
  const { state: globalFilter, onStateChange: onGlobalFilterChange } = useStateControl<string>(search, '');
@@ -122,7 +114,6 @@ export function Table<TData extends object>({
122
114
  defaultPaginationState,
123
115
  );
124
116
  const enableSelection = Boolean(rowSelectionProp?.enable);
125
- const tableContainerRef = useRef<HTMLElement>(null);
126
117
 
127
118
  const tableColumns: ColumnDefinition<TData>[] = useMemo(() => {
128
119
  let cols: ColumnDefinition<TData>[] = columnDefinitions;
@@ -146,7 +137,6 @@ export function Table<TData extends object>({
146
137
  const table = useReactTable<TData>({
147
138
  data,
148
139
  columns: tableColumns,
149
-
150
140
  state: {
151
141
  columnPinning,
152
142
  globalFilter,
@@ -160,7 +150,7 @@ export function Table<TData extends object>({
160
150
  enableSorting: false,
161
151
  enableResizing: false,
162
152
  minSize: 40,
163
- cell: truncateCell,
153
+ cell: (cell: CellContext<TData, unknown>) => <TruncateString text={String(cell.getValue())} maxLines={1} />,
164
154
  },
165
155
 
166
156
  manualSorting,
@@ -187,13 +177,6 @@ export function Table<TData extends object>({
187
177
  getCoreRowModel: getCoreRowModel(),
188
178
  columnResizeMode: 'onEnd',
189
179
  keepPinnedRows,
190
-
191
- meta: {
192
- tableContainerRef,
193
- rowVirtualizerInstanceRef,
194
- rowVirtualizerOptions,
195
- enableRowVirtualization,
196
- },
197
180
  });
198
181
 
199
182
  const { loadingTable } = useLoadingTable({
@@ -241,21 +224,9 @@ export function Table<TData extends object>({
241
224
  const columnSizeVarsRef = useRef<Record<string, string>>();
242
225
  const headers = table.getFlatHeaders();
243
226
 
244
- const tableRows = table.getRowModel().rows;
245
- const tableCenterRows = table.getCenterRows();
246
- const tableFilteredRows = table.getFilteredRowModel().rows;
247
- const tableFilteredRowsIds = tableFilteredRows.map(row => row.id);
248
- const topRows = table.getTopRows();
249
- const loadingTableRows = loadingTable.getRowModel().rows;
250
- const tablePagination = table.getState().pagination;
251
-
252
- const [isScrollBeenInitialized, setScrollInitialization] = useState(false);
253
- const rowVirtualizer = useRowVirtualizer(table, isScrollBeenInitialized);
254
- const overallVirtualHeight = rowVirtualizer?.getTotalSize() ?? 0;
255
-
256
- const cssSizeVars = useMemo(() => {
227
+ const columnSizeVars = useMemo(() => {
257
228
  const originalColumnDefs = table._getColumnDefs();
258
- const colSizes: Record<string, string> = overallVirtualHeight > 0 ? { height: `${overallVirtualHeight}px` } : {};
229
+ const colSizes: Record<string, string> = {};
259
230
 
260
231
  for (let i = 0; i < headers.length; i++) {
261
232
  const header = headers[i];
@@ -317,11 +288,19 @@ export function Table<TData extends object>({
317
288
  table.getTotalSize() will trigger re-render after double-click size reset
318
289
  */
319
290
  // eslint-disable-next-line react-hooks/exhaustive-deps
320
- }, [table.getState().columnSizingInfo.isResizingColumn, headers, table.getTotalSize(), overallVirtualHeight]);
291
+ }, [table.getState().columnSizingInfo.isResizingColumn, headers, table.getTotalSize()]);
321
292
 
322
293
  useEffect(() => {
323
- columnSizeVarsRef.current = cssSizeVars;
324
- }, [cssSizeVars]);
294
+ columnSizeVarsRef.current = columnSizeVars;
295
+ }, [columnSizeVars]);
296
+
297
+ const tableRows = table.getRowModel().rows;
298
+ const tableCenterRows = table.getCenterRows();
299
+ const tableFilteredRows = table.getFilteredRowModel().rows;
300
+ const tableFilteredRowsIds = tableFilteredRows.map(row => row.id);
301
+ const topRows = table.getTopRows();
302
+ const loadingTableRows = loadingTable.getRowModel().rows;
303
+ const tablePagination = table.getState().pagination;
325
304
 
326
305
  const filteredTopRows = table.getState().globalFilter
327
306
  ? topRows.filter(tr => tableFilteredRowsIds.includes(tr.id))
@@ -337,12 +316,6 @@ export function Table<TData extends object>({
337
316
  return !tableRows.length ? Math.min(Math.max(tempPageSize, 5), DEFAULT_PAGE_SIZE) : tempPageSize;
338
317
  }, [filteredTopRows.length, pageSize, suppressPagination, tablePagination?.pageSize, tableRows.length]);
339
318
 
340
- const tableCtx = useMemo(() => ({ table }), [table]);
341
-
342
- const onInitializeScroll = useCallback(() => {
343
- setScrollInitialization(true);
344
- }, []);
345
-
346
319
  usePageReset({
347
320
  manualPagination,
348
321
  maximumAvailablePage: pageCount || data.length / pagination.pageSize,
@@ -402,15 +375,9 @@ export function Table<TData extends object>({
402
375
  )}
403
376
 
404
377
  <div className={styles.scrollWrapper} data-outline={outline || undefined}>
405
- <Scroll
406
- size='s'
407
- ref={mergeRefs(tableContainerRef, scrollContainerRef)}
408
- className={styles.table}
409
- onScroll={onScroll}
410
- onInitialized={onInitializeScroll}
411
- >
412
- <div className={styles.tableContent} style={cssSizeVars}>
413
- <TableContext.Provider value={tableCtx}>
378
+ <Scroll size='s' className={styles.table} ref={scrollContainerRef}>
379
+ <div className={styles.tableContent} style={columnSizeVars}>
380
+ <TableContext.Provider value={{ table }}>
414
381
  {loading ? (
415
382
  <SkeletonContextProvider loading>
416
383
  <HeaderRow />
@@ -429,20 +396,9 @@ export function Table<TData extends object>({
429
396
  </div>
430
397
  ) : null}
431
398
 
432
- {(rowVirtualizer?.getVirtualItems() ?? centerRows).map((rowOrVirtualRow, index) => {
433
- const row = isVirtualRow(rowOrVirtualRow) ? centerRows[rowOrVirtualRow.index] : centerRows[index];
434
-
435
- return (
436
- <VirtualRow
437
- key={row.id}
438
- ref={rowVirtualizer?.measureElement}
439
- data-index={row.index}
440
- virtualRow={isVirtualRow(rowOrVirtualRow) ? rowOrVirtualRow : undefined}
441
- >
442
- <BodyRow row={row} onRowClick={onRowClick} />
443
- </VirtualRow>
444
- );
445
- })}
399
+ {centerRows.map(row => (
400
+ <BodyRow key={row.id} row={row} onRowClick={onRowClick} />
401
+ ))}
446
402
 
447
403
  <TableEmptyState
448
404
  emptyStates={emptyStates}
@@ -3,15 +3,10 @@
3
3
  .table {
4
4
  @include styles-tokens-table.composite-var(styles-tokens-table.$table-table-container);
5
5
 
6
- will-change: transform;
7
- overflow-anchor: none;
8
-
9
6
  position: relative;
10
7
  /* stylelint-disable-next-line declaration-property-value-allowed-list */
11
8
  z-index: 0;
12
9
 
13
- contain: paint;
14
-
15
10
  /* stylelint-disable-next-line declaration-no-important */
16
11
  overflow: hidden !important;
17
12
  display: flex;
@@ -44,7 +39,6 @@
44
39
  }
45
40
 
46
41
  .tableContent {
47
- content-visibility: auto;
48
42
  min-width: max-content;
49
43
  }
50
44
 
@@ -1,7 +1,3 @@
1
- import { CellContext } from '@tanstack/react-table';
2
- import { VirtualItem } from '@tanstack/react-virtual';
3
-
4
- import { TruncateString } from '@snack-uikit/truncate-string';
5
1
  import { isBrowser } from '@snack-uikit/utils';
6
2
 
7
3
  export function getCurrentlyConfiguredHeaderWidth(id: string): number {
@@ -62,17 +58,3 @@ export function saveStateToLocalStorage({ id, columnId, size }: SaveStateToLocal
62
58
 
63
59
  localStorage.setItem(id, JSON.stringify({ ...(savedStateFromStorage || {}), resizeState: newResizeState }));
64
60
  }
65
-
66
- /**
67
- * check the key, because index is contained in a common table row
68
- */
69
- export function isVirtualRow(row: unknown): row is VirtualItem {
70
- return typeof row === 'object' && row != null && 'key' in row;
71
- }
72
-
73
- /**
74
- * @description prevent permanent recreation of the function on rerender
75
- */
76
- export function truncateCell<TData>(cell: CellContext<TData, unknown>) {
77
- return <TruncateString text={String(cell.getValue())} maxLines={1} />;
78
- }
@@ -6,8 +6,7 @@ import {
6
6
  RowSelectionState,
7
7
  SortingState,
8
8
  } from '@tanstack/react-table';
9
- import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
10
- import { MutableRefObject, ReactNode, RefObject } from 'react';
9
+ import { ReactNode, RefObject } from 'react';
11
10
 
12
11
  import { ToolbarProps } from '@snack-uikit/toolbar';
13
12
  import { WithSupportProps } from '@snack-uikit/utils';
@@ -162,14 +161,6 @@ export type TableProps<TData extends object> = WithSupportProps<{
162
161
  id: string;
163
162
  resize?: boolean;
164
163
  };
165
-
166
- onScroll?: (event?: Event) => void;
167
- // Включение виртуализации для строк
168
- enableRowVirtualization?: boolean;
169
- // Параметры для переопределения настроек виртуализации строк
170
- rowVirtualizerOptions?: Parameters<typeof useVirtualizer>[0];
171
- // Ссылка на экземпляр useRowVirtualizer
172
- rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<Element, Element> | null>;
173
164
  }>;
174
165
 
175
166
  export type ServerTableProps<TData extends object> = Omit<
@@ -1,2 +0,0 @@
1
- import { Table } from '@tanstack/react-table';
2
- export declare function useRowVirtualizer(table: Table<any>, isScrollInitialized: boolean): import("@tanstack/virtual-core").Virtualizer<Element, Element> | undefined;
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useRowVirtualizer = useRowVirtualizer;
7
- const react_virtual_1 = require("@tanstack/react-virtual");
8
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
- function useRowVirtualizer(table, isScrollInitialized) {
10
- const {
11
- getRowModel,
12
- options: {
13
- meta = {}
14
- }
15
- } = table;
16
- const {
17
- rowVirtualizerInstanceRef,
18
- rowVirtualizerOptions,
19
- tableContainerRef,
20
- enableRowVirtualization
21
- } = meta;
22
- const normalRowHeight = 40;
23
- const rowVirtualizer = (0, react_virtual_1.useVirtualizer)(Object.assign({
24
- count: getRowModel().rows.length,
25
- estimateSize: () => normalRowHeight,
26
- getScrollElement: () => isScrollInitialized ? tableContainerRef.current : null,
27
- measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1 ? element => element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height : undefined,
28
- overscan: 28,
29
- enabled: enableRowVirtualization
30
- }, rowVirtualizerOptions));
31
- if (rowVirtualizerInstanceRef && enableRowVirtualization) {
32
- rowVirtualizerInstanceRef.current = rowVirtualizer;
33
- }
34
- return enableRowVirtualization ? rowVirtualizer : undefined;
35
- }
@@ -1,7 +0,0 @@
1
- import { VirtualItem } from '@tanstack/react-virtual';
2
- import { HTMLAttributes } from 'react';
3
- export declare const VirtualRow: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & {
4
- virtualRow?: VirtualItem;
5
- } & {
6
- children?: import("react").ReactNode | undefined;
7
- } & import("react").RefAttributes<HTMLDivElement>>;
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- var __rest = void 0 && (void 0).__rest || function (s, e) {
4
- var t = {};
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
8
- }
9
- return t;
10
- };
11
- Object.defineProperty(exports, "__esModule", {
12
- value: true
13
- });
14
- exports.VirtualRow = void 0;
15
- const jsx_runtime_1 = require("react/jsx-runtime");
16
- const react_1 = require("react");
17
- exports.VirtualRow = (0, react_1.forwardRef)((_a, ref) => {
18
- var {
19
- virtualRow,
20
- children
21
- } = _a,
22
- attributes = __rest(_a, ["virtualRow", "children"]);
23
- if (!virtualRow) {
24
- return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {
25
- children: children
26
- });
27
- }
28
- return (0, jsx_runtime_1.jsx)("div", Object.assign({
29
- ref: ref,
30
- style: {
31
- position: 'absolute',
32
- top: 0,
33
- left: 0,
34
- width: '100%',
35
- transform: `translateY(${virtualRow.start}px)`
36
- }
37
- }, attributes, {
38
- children: children
39
- }));
40
- });
@@ -1,2 +0,0 @@
1
- import { Table } from '@tanstack/react-table';
2
- export declare function useRowVirtualizer(table: Table<any>, isScrollInitialized: boolean): import("@tanstack/virtual-core").Virtualizer<Element, Element> | undefined;
@@ -1,14 +0,0 @@
1
- import { useVirtualizer } from '@tanstack/react-virtual';
2
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
- export function useRowVirtualizer(table, isScrollInitialized) {
4
- const { getRowModel, options: { meta = {} }, } = table;
5
- const { rowVirtualizerInstanceRef, rowVirtualizerOptions, tableContainerRef, enableRowVirtualization } = meta;
6
- const normalRowHeight = 40;
7
- const rowVirtualizer = useVirtualizer(Object.assign({ count: getRowModel().rows.length, estimateSize: () => normalRowHeight, getScrollElement: () => (isScrollInitialized ? tableContainerRef.current : null), measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1
8
- ? element => element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height
9
- : undefined, overscan: 28, enabled: enableRowVirtualization }, rowVirtualizerOptions));
10
- if (rowVirtualizerInstanceRef && enableRowVirtualization) {
11
- rowVirtualizerInstanceRef.current = rowVirtualizer;
12
- }
13
- return enableRowVirtualization ? rowVirtualizer : undefined;
14
- }
@@ -1,7 +0,0 @@
1
- import { VirtualItem } from '@tanstack/react-virtual';
2
- import { HTMLAttributes } from 'react';
3
- export declare const VirtualRow: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & {
4
- virtualRow?: VirtualItem;
5
- } & {
6
- children?: import("react").ReactNode | undefined;
7
- } & import("react").RefAttributes<HTMLDivElement>>;
@@ -1,26 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
13
- import { forwardRef } from 'react';
14
- export const VirtualRow = forwardRef((_a, ref) => {
15
- var { virtualRow, children } = _a, attributes = __rest(_a, ["virtualRow", "children"]);
16
- if (!virtualRow) {
17
- return _jsx(_Fragment, { children: children });
18
- }
19
- return (_jsx("div", Object.assign({ ref: ref, style: {
20
- position: 'absolute',
21
- top: 0,
22
- left: 0,
23
- width: '100%',
24
- transform: `translateY(${virtualRow.start}px)`,
25
- } }, attributes, { children: children })));
26
- });
@@ -1,44 +0,0 @@
1
- import { Table } from '@tanstack/react-table';
2
- import { useVirtualizer } from '@tanstack/react-virtual';
3
- import { MutableRefObject } from 'react';
4
-
5
- import { TableProps } from '../../types';
6
-
7
- type MetaParams = Pick<
8
- TableProps<never>,
9
- 'rowVirtualizerInstanceRef' | 'rowVirtualizerOptions' | 'enableRowVirtualization'
10
- > & {
11
- tableContainerRef: MutableRefObject<HTMLElement | null>;
12
- };
13
-
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- export function useRowVirtualizer(table: Table<any>, isScrollInitialized: boolean) {
16
- const {
17
- getRowModel,
18
- options: { meta = {} },
19
- } = table;
20
-
21
- const { rowVirtualizerInstanceRef, rowVirtualizerOptions, tableContainerRef, enableRowVirtualization } =
22
- meta as MetaParams;
23
-
24
- const normalRowHeight = 40;
25
-
26
- const rowVirtualizer = useVirtualizer({
27
- count: getRowModel().rows.length,
28
- estimateSize: () => normalRowHeight,
29
- getScrollElement: () => (isScrollInitialized ? tableContainerRef.current : null),
30
- measureElement:
31
- typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1
32
- ? element => element?.getBoundingClientRect().height
33
- : undefined,
34
- overscan: 28,
35
- enabled: enableRowVirtualization,
36
- ...rowVirtualizerOptions,
37
- });
38
-
39
- if (rowVirtualizerInstanceRef && enableRowVirtualization) {
40
- rowVirtualizerInstanceRef.current = rowVirtualizer;
41
- }
42
-
43
- return enableRowVirtualization ? rowVirtualizer : undefined;
44
- }
@@ -1,27 +0,0 @@
1
- import { VirtualItem } from '@tanstack/react-virtual';
2
- import { forwardRef, HTMLAttributes, PropsWithChildren } from 'react';
3
-
4
- export const VirtualRow = forwardRef<
5
- HTMLDivElement,
6
- PropsWithChildren<HTMLAttributes<HTMLDivElement> & { virtualRow?: VirtualItem }>
7
- >(({ virtualRow, children, ...attributes }, ref) => {
8
- if (!virtualRow) {
9
- return <>{children}</>;
10
- }
11
-
12
- return (
13
- <div
14
- ref={ref}
15
- style={{
16
- position: 'absolute',
17
- top: 0,
18
- left: 0,
19
- width: '100%',
20
- transform: `translateY(${virtualRow.start}px)`,
21
- }}
22
- {...attributes}
23
- >
24
- {children}
25
- </div>
26
- );
27
- });