@synerise/ds-table 0.43.7 → 0.44.1

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 (45) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +53 -38
  3. package/dist/Cell/AvatarLabel/AvatarLabel.js +3 -2
  4. package/dist/Cell/AvatarLabel/AvatarLabel.styles.d.ts +3 -1
  5. package/dist/Cell/AvatarLabel/AvatarLabel.styles.js +3 -1
  6. package/dist/Cell/StatusLabel/StatusLabel.types.d.ts +1 -1
  7. package/dist/ColumnSortMenu/SortRenderer.d.ts +2 -1
  8. package/dist/ColumnSortMenu/columnWithSortButtons.d.ts +3 -3
  9. package/dist/ColumnSortMenu/columnWithSortButtons.js +7 -5
  10. package/dist/ColumnSortMenu/useSortState.js +2 -2
  11. package/dist/DefaultTable/DefaultTable.d.ts +1 -1
  12. package/dist/DefaultTable/DefaultTable.js +67 -97
  13. package/dist/GroupTable/GroupTableBody/GroupTableBody.js +9 -8
  14. package/dist/RowSelection/RowSelectionColumn.d.ts +4 -0
  15. package/dist/RowSelection/RowSelectionColumn.js +100 -0
  16. package/dist/RowSelection/RowSelectionColumn.types.d.ts +13 -0
  17. package/dist/{hooks/useRowStar.types.js → RowSelection/RowSelectionColumn.types.js} +0 -0
  18. package/dist/RowSelection/index.d.ts +1 -0
  19. package/dist/RowSelection/index.js +1 -0
  20. package/dist/Table.d.ts +1 -1
  21. package/dist/Table.types.d.ts +5 -2
  22. package/dist/TableHeader/TableSelection.js +33 -19
  23. package/dist/VirtualTable/VirtualTable.d.ts +1 -1
  24. package/dist/VirtualTable/VirtualTable.js +91 -131
  25. package/dist/VirtualTable/VirtualTable.styles.js +1 -1
  26. package/dist/VirtualTable/VirtualTableRow.d.ts +5 -4
  27. package/dist/VirtualTable/VirtualTableRow.js +62 -63
  28. package/dist/hooks/useRowKey/index.d.ts +1 -0
  29. package/dist/hooks/useRowKey/index.js +1 -0
  30. package/dist/hooks/useRowKey/useRowKey.d.ts +7 -0
  31. package/dist/hooks/useRowKey/useRowKey.js +13 -0
  32. package/dist/hooks/useRowStar/index.d.ts +2 -0
  33. package/dist/hooks/useRowStar/index.js +2 -0
  34. package/dist/hooks/useRowStar/useRowStar.d.ts +2 -0
  35. package/dist/hooks/{useRowStar.js → useRowStar/useRowStar.js} +11 -10
  36. package/dist/hooks/useRowStar/useRowStar.types.d.ts +21 -0
  37. package/dist/hooks/useRowStar/useRowStar.types.js +1 -0
  38. package/dist/utils/__specs__/getValueFromPath.spec.d.ts +1 -0
  39. package/dist/utils/getValueFromPath.d.ts +1 -0
  40. package/dist/utils/getValueFromPath.js +7 -0
  41. package/dist/utils/index.d.ts +3 -0
  42. package/dist/utils/index.js +3 -0
  43. package/package.json +21 -20
  44. package/dist/hooks/useRowStar.d.ts +0 -3
  45. package/dist/hooks/useRowStar.types.d.ts +0 -17
@@ -0,0 +1,100 @@
1
+ import * as React from 'react';
2
+ import Tooltip from '@synerise/ds-tooltip';
3
+ import Button from '@synerise/ds-button';
4
+ import { useRowKey } from '../hooks/useRowKey';
5
+ // eslint-disable-next-line import/prefer-default-export
6
+ export function RowSelectionColumn(_ref) {
7
+ var rowKey = _ref.rowKey,
8
+ record = _ref.record,
9
+ limit = _ref.limit,
10
+ independentSelectionExpandedRows = _ref.independentSelectionExpandedRows,
11
+ selectedRowKeys = _ref.selectedRowKeys,
12
+ selectedRecords = _ref.selectedRecords,
13
+ tableLocale = _ref.tableLocale,
14
+ onChange = _ref.onChange;
15
+
16
+ var _useRowKey = useRowKey(rowKey),
17
+ getRowKey = _useRowKey.getRowKey;
18
+
19
+ var recordKey = getRowKey(record);
20
+ var checkedChildren = React.useMemo(function () {
21
+ var _record$children;
22
+
23
+ return ((_record$children = record.children) == null ? void 0 : _record$children.filter(function (child) {
24
+ var childKey = getRowKey(child);
25
+ return childKey && selectedRowKeys.indexOf(childKey) >= 0;
26
+ })) || [];
27
+ }, [getRowKey, record.children, selectedRowKeys]);
28
+ var allChildrenSelected = React.useMemo(function () {
29
+ var _record$children2;
30
+
31
+ return !!((_record$children2 = record.children) != null && _record$children2.every(function (child) {
32
+ var childKey = getRowKey(child);
33
+ return childKey && selectedRowKeys.indexOf(childKey) >= 0;
34
+ }));
35
+ }, [getRowKey, record.children, selectedRowKeys]);
36
+ var isIndeterminate = React.useMemo(function () {
37
+ if (Array.isArray(record.children) && !independentSelectionExpandedRows) {
38
+ var _record$children3;
39
+
40
+ return checkedChildren.length > 0 && checkedChildren.length < (((_record$children3 = record.children) == null ? void 0 : _record$children3.length) || 0);
41
+ }
42
+
43
+ return false;
44
+ }, [checkedChildren.length, independentSelectionExpandedRows, record.children]);
45
+ var isChecked = React.useMemo(function () {
46
+ if (Array.isArray(record.children) && !independentSelectionExpandedRows) {
47
+ return isChecked || allChildrenSelected;
48
+ }
49
+
50
+ return recordKey !== undefined && selectedRowKeys && selectedRowKeys.indexOf(recordKey) >= 0;
51
+ }, [allChildrenSelected, independentSelectionExpandedRows, record.children, recordKey, selectedRowKeys]);
52
+ var handleSelectionChange = React.useCallback(function (isCheckedNext, changedRecord) {
53
+ var selectedRows = selectedRecords;
54
+
55
+ if (isCheckedNext) {
56
+ if (Array.isArray(changedRecord.children) && !independentSelectionExpandedRows) {
57
+ selectedRows = [].concat(selectedRows, changedRecord.children);
58
+ } else {
59
+ selectedRows = [].concat(selectedRows, [changedRecord]);
60
+ }
61
+ } else if (Array.isArray(changedRecord.children) && !independentSelectionExpandedRows) {
62
+ var childrenKeys = changedRecord.children.map(function (child) {
63
+ return getRowKey(child);
64
+ });
65
+ selectedRows = selectedRows.filter(function (child) {
66
+ return childrenKeys.indexOf(getRowKey(child)) < 0;
67
+ });
68
+ } else {
69
+ selectedRows = selectedRows.filter(function (row) {
70
+ return getRowKey(row) !== recordKey;
71
+ });
72
+ }
73
+
74
+ selectedRows = Array.from(new Set(selectedRows));
75
+ onChange && onChange(selectedRows.reduce(function (acc, current) {
76
+ var key = getRowKey(current);
77
+
78
+ if (key !== undefined) {
79
+ return [].concat(acc, [key]);
80
+ }
81
+
82
+ return acc;
83
+ }, []), selectedRows);
84
+ }, [getRowKey, independentSelectionExpandedRows, onChange, recordKey, selectedRecords]);
85
+ return recordKey !== undefined ? /*#__PURE__*/React.createElement(Tooltip, {
86
+ title: tableLocale == null ? void 0 : tableLocale.selectRowTooltip,
87
+ mouseLeaveDelay: 0
88
+ }, /*#__PURE__*/React.createElement(Button.Checkbox, {
89
+ key: "checkbox-" + recordKey,
90
+ checked: isChecked,
91
+ disabled: !isChecked && Boolean(limit !== undefined && limit <= selectedRowKeys.length),
92
+ indeterminate: isIndeterminate,
93
+ onClick: function onClick(e) {
94
+ e.stopPropagation();
95
+ },
96
+ onChange: function onChange(isCheckedNext) {
97
+ return handleSelectionChange(isCheckedNext, record);
98
+ }
99
+ })) : null;
100
+ }
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { TableProps } from 'rc-table/lib/Table';
3
+ import { DSTableProps } from '../Table.types';
4
+ export declare type RowSelectionProps<T> = {
5
+ rowKey: TableProps<T>['rowKey'];
6
+ independentSelectionExpandedRows?: boolean;
7
+ selectedRowKeys: React.ReactText[];
8
+ selectedRecords: T[];
9
+ limit?: number;
10
+ record: T;
11
+ tableLocale: DSTableProps<T>['locale'];
12
+ onChange: (selectedRowKeys: React.ReactText[], selectedRecords: T[]) => void;
13
+ };
@@ -0,0 +1 @@
1
+ export * from './RowSelectionColumn';
@@ -0,0 +1 @@
1
+ export * from './RowSelectionColumn';
package/dist/Table.d.ts CHANGED
@@ -4,7 +4,7 @@ import './style/index.less';
4
4
  import { DSTableProps } from './Table.types';
5
5
  export declare const SELECTION_ALL = "SELECTION_ALL";
6
6
  export declare const SELECTION_INVERT = "SELECTION_INVERT";
7
- declare function DSTable<T extends any>(props: DSTableProps<T>): React.ReactElement;
7
+ declare function DSTable<T extends object>(props: DSTableProps<T>): React.ReactElement;
8
8
  declare namespace DSTable {
9
9
  var SELECTION_ALL: string;
10
10
  var SELECTION_INVERT: string;
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { TableLocale, TableRowSelection } from 'antd/lib/table/interface';
4
4
  import DSTable from './Table';
5
5
  import { GroupType } from './GroupTable/GroupTable.types';
6
- import { RowStar } from './hooks/useRowStar.types';
6
+ import { RowStar } from './hooks/useRowStar';
7
7
  import { SortRender } from './ColumnSortMenu/TitleWithSort';
8
8
  import { ColumnSortOrder, ColumnsSortState } from './ColumnSortMenu/useSortState';
9
9
  export declare type AntTableProps<T> = Omit<TableProps<T>, 'title' | 'subTitle' | 'onSearch' | 'itemsMenu' | 'search' | 'locale' | 'columns'>;
@@ -19,6 +19,7 @@ export declare type RowSelection<T> = Omit<TableRowSelection<T>, 'selections'> &
19
19
  selections?: SelectionItem[];
20
20
  onChange: (selectedRowKeys: React.ReactText[], selectedRows: T[]) => void;
21
21
  limit?: number;
22
+ independentSelectionExpandedRows?: boolean;
22
23
  };
23
24
  export interface Filter {
24
25
  tooltips: {
@@ -39,6 +40,7 @@ export interface Filter {
39
40
  disabled?: boolean;
40
41
  }
41
42
  export declare type RowType<T> = {
43
+ key?: string | number;
42
44
  children?: T[];
43
45
  };
44
46
  export declare type Locale = TableLocale & {
@@ -65,8 +67,9 @@ export declare type Locale = TableLocale & {
65
67
  infiniteScrollBackToTop?: string;
66
68
  };
67
69
  export declare type DSColumnType<T> = Omit<ColumnType<T>, 'fixed'> & {
68
- fixed?: 'left' | 'right' | string;
70
+ fixed?: 'left' | 'right';
69
71
  sortRender?: SortRender<T>;
72
+ childRender?: (value: unknown, row: T, index: number) => React.ReactNode;
70
73
  };
71
74
  declare type AntTableComponentsType<T> = AntTableProps<T>['components'];
72
75
  declare type DSTableComponentsType<T> = AntTableComponentsType<T> & {
@@ -6,30 +6,32 @@ import Tooltip from '@synerise/ds-tooltip';
6
6
  import Icon, { OptionVerticalM } from '@synerise/ds-icon';
7
7
  import * as S from '../Table.styles';
8
8
  import { SELECTION_ALL, SELECTION_INVERT } from '../Table';
9
-
10
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
9
+ import { useRowKey } from '../hooks/useRowKey'; // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
11
10
  // @ts-ignore
11
+
12
12
  function TableSelection(_ref) {
13
13
  var dataSource = _ref.dataSource,
14
14
  selection = _ref.selection,
15
15
  rowKey = _ref.rowKey,
16
16
  locale = _ref.locale;
17
- var getRowKey = React.useCallback(function (row) {
18
- if (typeof rowKey === 'function') return rowKey(row);
19
- if (typeof rowKey === 'string') return row[rowKey];
20
- return undefined;
21
- }, [rowKey]);
17
+
18
+ var _useRowKey = useRowKey(rowKey),
19
+ getRowKey = _useRowKey.getRowKey;
20
+
22
21
  var selectAll = React.useCallback(function () {
23
22
  if (dataSource && selection) {
24
23
  var keys = [];
25
24
  var rows = [];
26
25
  dataSource.forEach(function (record) {
27
- if (record.children !== undefined && Array.isArray(record.children)) {
28
- keys = [].concat(keys, record.children.map(function (child) {
29
- return getRowKey(child);
30
- }));
26
+ if (Array.isArray(record.children)) {
27
+ keys = [].concat(keys, record.children.reduce(function (acc, child) {
28
+ var key = getRowKey(child);
29
+ return key ? [].concat(acc, [key]) : acc;
30
+ }, []));
31
31
  rows = [].concat(rows, record.children);
32
- } else {
32
+ }
33
+
34
+ if (!Array.isArray(record.children) || selection.independentSelectionExpandedRows) {
33
35
  var key = getRowKey(record);
34
36
  keys = key !== undefined ? [].concat(keys, [key]) : [].concat(keys);
35
37
  rows = [].concat(rows, [record]);
@@ -41,19 +43,27 @@ function TableSelection(_ref) {
41
43
  var unselectAll = React.useCallback(function () {
42
44
  if (selection) selection.onChange([], []);
43
45
  }, [selection]);
46
+ var getSelectableChildren = React.useCallback(function (children) {
47
+ return children ? children.filter(function (child) {
48
+ return getRowKey(child) !== undefined;
49
+ }) : [];
50
+ }, [getRowKey]);
44
51
  var selectInvert = React.useCallback(function () {
45
52
  if (dataSource && selection) {
46
53
  var selected = [];
47
54
  dataSource.forEach(function (record) {
48
- var hasChilds = record.children !== undefined && Array.isArray(record.children);
55
+ var hasChildren = Array.isArray(record.children);
56
+ var selectableChildren = hasChildren ? getSelectableChildren(record.children) : false;
49
57
 
50
- if (hasChilds) {
51
- record.children && record.children.forEach(function (child) {
58
+ if (selectableChildren) {
59
+ selectableChildren.forEach(function (child) {
52
60
  if ((selection == null ? void 0 : selection.selectedRowKeys.indexOf(getRowKey(child))) < 0) {
53
61
  selected = [].concat(selected, [child]);
54
62
  }
55
63
  });
56
- } else if ((selection == null ? void 0 : selection.selectedRowKeys.indexOf(getRowKey(record))) < 0) {
64
+ }
65
+
66
+ if ((selection == null ? void 0 : selection.selectedRowKeys.indexOf(getRowKey(record))) < 0 && (!selectableChildren || selection.independentSelectionExpandedRows)) {
57
67
  selected = [].concat(selected, [record]);
58
68
  }
59
69
  });
@@ -61,17 +71,21 @@ function TableSelection(_ref) {
61
71
  return getRowKey(record);
62
72
  }), selected);
63
73
  }
64
- }, [dataSource, selection, getRowKey]);
74
+ }, [dataSource, selection, getRowKey, getSelectableChildren]);
65
75
  var isEmpty = React.useMemo(function () {
66
76
  return dataSource.length === 0;
67
77
  }, [dataSource]);
68
78
  var allSelected = React.useMemo(function () {
69
79
  if (isEmpty) return false;
70
80
  var allRecords = dataSource.reduce(function (count, record) {
71
- return record.children !== undefined ? count + record.children.length : count + 1;
81
+ if (selection != null && selection.independentSelectionExpandedRows) {
82
+ return Array.isArray(record.children) ? count + getSelectableChildren(record.children).length + 1 : count + 1;
83
+ }
84
+
85
+ return Array.isArray(record.children) ? count + getSelectableChildren(record.children).length : count + 1;
72
86
  }, 0);
73
87
  return (selection == null ? void 0 : selection.selectedRowKeys) && allRecords === selection.selectedRowKeys.length;
74
- }, [dataSource, selection, isEmpty]);
88
+ }, [isEmpty, dataSource, selection, getSelectableChildren]);
75
89
  return selection != null && selection.selectedRowKeys ? /*#__PURE__*/React.createElement(S.Selection, {
76
90
  "data-popup-container": true
77
91
  }, /*#__PURE__*/React.createElement(Tooltip, {
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { RowType } from '../Table.types';
3
3
  import { Props } from './VirtualTable.types';
4
4
  export declare const EXPANDED_ROW_PROPERTY = "expandedChild";
5
- declare function VirtualTable<T extends any & RowType<T> & {
5
+ declare function VirtualTable<T extends object & RowType<T> & {
6
6
  [EXPANDED_ROW_PROPERTY]?: boolean;
7
7
  }>(props: Props<T>): React.ReactElement;
8
8
  export default VirtualTable;
@@ -16,17 +16,16 @@ import ResizeObserver from 'rc-resize-observer';
16
16
  import classNames from 'classnames';
17
17
  import { compact } from 'lodash';
18
18
  import { useIntl } from 'react-intl';
19
- import Button from '@synerise/ds-button';
20
- import Tooltip from '@synerise/ds-tooltip';
21
19
  import Scrollbar from '@synerise/ds-scrollbar';
22
20
  import { infiniteLoaderItemHeight } from '../InfiniteScroll/constants';
23
21
  import BackToTopButton from '../InfiniteScroll/BackToTopButton';
24
22
  import DSTable from '../Table';
25
23
  import VirtualTableRow from './VirtualTableRow';
26
24
  import { RelativeContainer } from './VirtualTable.styles';
27
- import useRowStar from '../hooks/useRowStar';
28
- import { useTableLocale } from '../utils/locale';
29
- import { calculatePixels } from '../utils/calculatePixels';
25
+ import { useTableLocale, calculatePixels } from '../utils';
26
+ import { useRowKey } from '../hooks/useRowKey';
27
+ import { useRowStar } from '../hooks/useRowStar/useRowStar';
28
+ import { RowSelectionColumn } from '../RowSelection';
30
29
  export var EXPANDED_ROW_PROPERTY = 'expandedChild';
31
30
  var relativeInlineStyle = {
32
31
  position: 'relative'
@@ -64,8 +63,7 @@ var CustomScrollbar = function CustomScrollbar(containerRef) {
64
63
  maxHeight: style == null ? void 0 : style.height
65
64
  }, children);
66
65
  });
67
- }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
-
66
+ };
69
67
 
70
68
  function VirtualTable(props) {
71
69
  var _props$columns = props.columns,
@@ -102,6 +100,9 @@ function VirtualTable(props) {
102
100
  onListRefChange && onListRefChange(listRef);
103
101
  }, [listRef, onListRefChange]);
104
102
 
103
+ var _useRowKey = useRowKey(rowKey),
104
+ getRowKey = _useRowKey.getRowKey;
105
+
105
106
  var propsForRowStar = _objectSpread({}, props, {
106
107
  rowStar: _objectSpread({}, rowStar, {
107
108
  onClick: function onClick(e) {
@@ -112,119 +113,74 @@ function VirtualTable(props) {
112
113
  }
113
114
  }
114
115
  }),
116
+ getRowKey: getRowKey,
115
117
  locale: tableLocale
116
118
  });
117
119
 
118
120
  var rowStarColumn = getRowStarColumn(propsForRowStar);
119
- var getRowKey = React.useCallback(function (row) {
120
- if (typeof rowKey === 'function') return rowKey(row);
121
- if (typeof rowKey === 'string') return row[rowKey];
122
- return undefined;
123
- }, [rowKey]); // eslint-disable-next-line @typescript-eslint/no-explicit-any
121
+ var selectedRecords = React.useMemo(function () {
122
+ if (selection) {
123
+ var _ref2 = selection,
124
+ selectedRowKeys = _ref2.selectedRowKeys;
125
+ var selectedRows = [];
126
+ dataSource && dataSource.forEach(function (row) {
127
+ var key = getRowKey(row);
128
+
129
+ if (key && selectedRowKeys.indexOf(key) >= 0) {
130
+ selectedRows = [].concat(selectedRows, [row]);
131
+ }
132
+
133
+ if (row.children !== undefined && Array.isArray(row.children)) {
134
+ row.children.forEach(function (child) {
135
+ var childKey = getRowKey(child);
136
+
137
+ if (childKey && selectedRowKeys.indexOf(childKey) >= 0) {
138
+ selectedRows = [].concat(selectedRows, [child]);
139
+ }
140
+ });
141
+ }
142
+ });
143
+ return selectedRows;
144
+ }
145
+
146
+ return [];
147
+ }, [dataSource, getRowKey, selection]);
148
+ var renderRowSelection = React.useCallback(function (key, record) {
149
+ var _ref3 = selection,
150
+ selectedRowKeys = _ref3.selectedRowKeys,
151
+ limit = _ref3.limit,
152
+ independentSelectionExpandedRows = _ref3.independentSelectionExpandedRows,
153
+ onChange = _ref3.onChange;
154
+ return /*#__PURE__*/React.createElement(RowSelectionColumn, {
155
+ rowKey: rowKey,
156
+ record: record,
157
+ limit: limit,
158
+ selectedRowKeys: selectedRowKeys,
159
+ independentSelectionExpandedRows: independentSelectionExpandedRows,
160
+ onChange: onChange,
161
+ selectedRecords: selectedRecords,
162
+ tableLocale: locale
163
+ });
164
+ }, [locale, rowKey, selectedRecords, selection]); // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
165
 
125
166
  var virtualColumns = React.useMemo(function () {
126
167
  return compact([!!selection && {
127
168
  width: 64,
128
169
  key: 'key',
129
170
  dataIndex: 'key',
130
- render: function render(key, record) {
131
- var _record$children, _record$children2, _record$children3;
132
-
133
- var recordKey = getRowKey(record);
134
- var allChildsChecked = // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
135
- Array.isArray(record.children) && // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
136
- ((_record$children = record.children) == null ? void 0 : _record$children.filter(function (child) {
137
- var childKey = getRowKey(child);
138
- return childKey && (selection == null ? void 0 : selection.selectedRowKeys.indexOf(childKey)) < 0;
139
- }).length) === 0;
140
- var checkedChilds = // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
141
- ((_record$children2 = record.children) == null ? void 0 : _record$children2.filter(function (child) {
142
- var childKey = getRowKey(child);
143
- return childKey && (selection == null ? void 0 : selection.selectedRowKeys.indexOf(childKey)) >= 0;
144
- })) || [];
145
- var isIndeterminate = // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
146
- Array.isArray(record.children) && checkedChilds.length > 0 && // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
147
- checkedChilds.length < (((_record$children3 = record.children) == null ? void 0 : _record$children3.length) || 0);
148
- var checked = recordKey !== undefined && selection.selectedRowKeys && selection.selectedRowKeys.indexOf(recordKey) >= 0 || allChildsChecked;
149
- return recordKey !== undefined && /*#__PURE__*/React.createElement(Tooltip, {
150
- title: tableLocale == null ? void 0 : tableLocale.selectRowTooltip,
151
- mouseLeaveDelay: 0
152
- }, /*#__PURE__*/React.createElement(Button.Checkbox, {
153
- key: "checkbox-" + recordKey,
154
- checked: checked,
155
- disabled: !checked && Boolean(selection.limit && selection.limit <= selection.selectedRowKeys.length),
156
- indeterminate: isIndeterminate,
157
- onClick: function onClick(e) {
158
- e.stopPropagation();
159
- },
160
- onChange: function onChange(isChecked) {
161
- var selectedRowKeys = selection.selectedRowKeys,
162
- onChange = selection.onChange;
163
- var selectedRows = [];
164
- dataSource && dataSource.forEach(function (row) {
165
- // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
166
- if (row.children !== undefined && Array.isArray(row.children)) {
167
- // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
168
- row.children.forEach(function (child) {
169
- var k = getRowKey(child);
170
-
171
- if (k && selectedRowKeys.indexOf(k) >= 0) {
172
- selectedRows = [].concat(selectedRows, [child]);
173
- }
174
- });
175
- } else {
176
- var k = getRowKey(row);
177
-
178
- if (k && selectedRowKeys.indexOf(k) >= 0) {
179
- selectedRows = [].concat(selectedRows, [row]);
180
- }
181
- }
182
- });
183
-
184
- if (isChecked) {
185
- // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
186
- if (Array.isArray(record.children)) {
187
- // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
188
- selectedRows = [].concat(selectedRows, record.children);
189
- } else {
190
- selectedRows = [].concat(selectedRows, [record]);
191
- } // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
192
-
193
- } else if (Array.isArray(record.children)) {
194
- // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
195
- var childsKeys = record.children.map(function (child) {
196
- return getRowKey(child);
197
- });
198
- selectedRows = selectedRows.filter(function (child) {
199
- return childsKeys.indexOf(getRowKey(child)) < 0;
200
- });
201
- } else {
202
- selectedRows = selectedRows.filter(function (row) {
203
- return getRowKey(row) !== recordKey;
204
- });
205
- }
206
-
207
- selectedRows = Array.from(new Set(selectedRows));
208
- onChange && onChange(selectedRows.map(function (selected) {
209
- return getRowKey(selected);
210
- }), selectedRows);
211
- }
212
- }));
213
- }
171
+ render: renderRowSelection
214
172
  }, !!rowStar && rowStarColumn].concat(columns));
215
- }, [columns, selection, rowStar, rowStarColumn, getRowKey, dataSource, tableLocale]);
173
+ }, [selection, renderRowSelection, rowStar, rowStarColumn, columns]);
216
174
  var mergedColumns = React.useMemo(function () {
217
- var widthColumnCount = virtualColumns.filter(function (_ref2) {
218
- var width = _ref2.width;
175
+ var widthColumnCount = virtualColumns.filter(function (_ref4) {
176
+ var width = _ref4.width;
219
177
  return !width;
220
178
  }).length;
221
179
  var rowWidth = tableWidth || initialWidth;
222
- var definedWidth = virtualColumns.filter(function (_ref3) {
223
- var width = _ref3.width;
224
- return width;
225
- }).reduce(function (total, _ref4) {
226
- var width = _ref4.width;
227
- return total + width;
180
+ var definedWidth = virtualColumns.reduce(function (total, _ref5) {
181
+ var width = _ref5.width;
182
+ var widthInPx = calculatePixels(width) || 0;
183
+ return total + widthInPx;
228
184
  }, 0);
229
185
  return virtualColumns == null ? void 0 : virtualColumns.map(function (column) {
230
186
  if (column.width) {
@@ -238,9 +194,9 @@ function VirtualTable(props) {
238
194
  });
239
195
  });
240
196
  }, [virtualColumns, tableWidth, initialWidth]);
241
- var listInnerElementType = React.forwardRef(function (_ref5, ref) {
242
- var style = _ref5.style,
243
- rest = _objectWithoutPropertiesLoose(_ref5, _excluded);
197
+ var listInnerElementType = React.forwardRef(function (_ref6, ref) {
198
+ var style = _ref6.style,
199
+ rest = _objectWithoutPropertiesLoose(_ref6, _excluded);
244
200
 
245
201
  return /*#__PURE__*/React.createElement("div", _extends({
246
202
  ref: ref,
@@ -261,16 +217,27 @@ function VirtualTable(props) {
261
217
  var outerElement = React.useMemo(function () {
262
218
  return CustomScrollbar(containerRef);
263
219
  }, [containerRef]);
264
-
265
- var renderBody = function renderBody(rawData, meta, defaultTableProps) {
220
+ var createItemData = React.useCallback(function (data, defaultTableProps) {
221
+ return {
222
+ mergedColumns: mergedColumns,
223
+ selection: selection,
224
+ rowStar: rowStar,
225
+ onRowClick: onRowClick,
226
+ dataSource: data,
227
+ infiniteScroll: infiniteScroll,
228
+ cellHeight: cellHeight,
229
+ defaultTableProps: defaultTableProps
230
+ };
231
+ }, [cellHeight, infiniteScroll, mergedColumns, onRowClick, rowStar, selection]);
232
+ var renderBody = React.useCallback(function (rawData, meta, defaultTableProps) {
266
233
  var _expandable$expandedR;
267
234
 
268
235
  var renderVirtualList = function renderVirtualList(data) {
269
236
  var listHeight = data.length * cellHeight - scroll.y + infiniteLoaderItemHeight;
270
237
 
271
- var handleListScroll = function handleListScroll(_ref6) {
272
- var scrollOffset = _ref6.scrollOffset,
273
- scrollDirection = _ref6.scrollDirection;
238
+ var handleListScroll = function handleListScroll(_ref7) {
239
+ var scrollOffset = _ref7.scrollOffset,
240
+ scrollDirection = _ref7.scrollDirection;
274
241
 
275
242
  if (scrollDirection === 'forward' && scrollOffset >= listHeight && typeof (infiniteScroll == null ? void 0 : infiniteScroll.onScrollEndReach) === 'function') {
276
243
  infiniteScroll.onScrollEndReach();
@@ -281,23 +248,17 @@ function VirtualTable(props) {
281
248
  }
282
249
  };
283
250
 
251
+ var itemData = createItemData(data, defaultTableProps);
284
252
  return /*#__PURE__*/React.createElement(List, {
285
253
  ref: listRef,
254
+ key: "virtual-list",
286
255
  onScroll: handleListScroll,
287
256
  className: "virtual-grid",
288
257
  height: scroll.y,
289
258
  itemCount: data.length,
290
259
  itemSize: cellHeight,
291
260
  width: "100%",
292
- itemData: {
293
- mergedColumns: mergedColumns,
294
- selection: selection,
295
- onRowClick: onRowClick,
296
- dataSource: data,
297
- infiniteScroll: infiniteScroll,
298
- cellHeight: cellHeight,
299
- defaultTableProps: defaultTableProps
300
- },
261
+ itemData: itemData,
301
262
  itemKey: function itemKey(index) {
302
263
  return String(getRowKey(data[index]));
303
264
  },
@@ -313,13 +274,11 @@ function VirtualTable(props) {
313
274
 
314
275
  var key = getRowKey(currentRow);
315
276
 
316
- if (key !== undefined && expandable != null && (_expandable$expandedR2 = expandable.expandedRowKeys) != null && _expandable$expandedR2.includes(key) && // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
317
- Array.isArray(currentRow.children) && // @ts-expect-error: Property 'children' does not exist on type 'T'.ts(2339)
318
- currentRow.children.length) {
319
- return [].concat(result, [currentRow], currentRow.children.map(function (child) {
277
+ if (key !== undefined && expandable != null && (_expandable$expandedR2 = expandable.expandedRowKeys) != null && _expandable$expandedR2.includes(key) && Array.isArray(currentRow.children) && currentRow.children.length) {
278
+ return [].concat(result, [currentRow], currentRow.children.map(function (child, index) {
320
279
  var _objectSpread2;
321
280
 
322
- return _objectSpread({}, child, (_objectSpread2 = {}, _objectSpread2[EXPANDED_ROW_PROPERTY] = true, _objectSpread2));
281
+ return _objectSpread({}, child, (_objectSpread2 = {}, _objectSpread2[EXPANDED_ROW_PROPERTY] = true, _objectSpread2.index = index, _objectSpread2));
323
282
  }));
324
283
  }
325
284
 
@@ -329,8 +288,7 @@ function VirtualTable(props) {
329
288
  }
330
289
 
331
290
  return renderVirtualList(rawData);
332
- };
333
-
291
+ }, [cellHeight, createItemData, expandable, getRowKey, infiniteScroll, listInnerElementType, outerElement, scroll.y]);
334
292
  var columnsSliceStartIndex = Number(!!selection) + Number(!!rowStar);
335
293
  var scrollValue = !dataSource || (dataSource == null ? void 0 : dataSource.length) === 0 ? undefined : props == null ? void 0 : props.scroll;
336
294
  return /*#__PURE__*/React.createElement(RelativeContainer, {
@@ -338,13 +296,15 @@ function VirtualTable(props) {
338
296
  ref: containerRef,
339
297
  style: relativeInlineStyle
340
298
  }, /*#__PURE__*/React.createElement(ResizeObserver, {
341
- onResize: function onResize(_ref7) {
342
- var offsetWidth = _ref7.offsetWidth;
299
+ onResize: function onResize(_ref8) {
300
+ var offsetWidth = _ref8.offsetWidth;
343
301
  setTableWidth(offsetWidth);
344
302
  }
345
303
  }, /*#__PURE__*/React.createElement(DSTable, _extends({}, props, {
346
304
  scroll: scrollValue,
347
305
  className: classNames(className, 'virtual-table', !!infiniteScroll && 'virtual-table-infinite-scroll') // Remove columns which cause header columns indent
306
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
307
+ // @ts-ignore
348
308
  ,
349
309
  columns: mergedColumns.slice(columnsSliceStartIndex),
350
310
  pagination: false,
@@ -27,7 +27,7 @@ export var RowWrapper = styled.div.withConfig({
27
27
  export var ColWrapper = styled.div.withConfig({
28
28
  displayName: "VirtualTablestyles__ColWrapper",
29
29
  componentId: "aehkhc-1"
30
- })(["display:table-cell;vertical-align:middle;min-width:", ";max-width:", ";padding:0 24px;&.virtual-table-cell.ant-table-selection-column{padding:0 8px 0 24px;}&.virtual-table-cell.ds-table-star-column{padding:0 8px 0 24px;& > button{display:flex;}}&.virtual-table-cell.ant-table-selection-column + .virtual-table-cell.ds-table-star-column{padding-left:0;}"], function (props) {
30
+ })(["display:table-cell;vertical-align:middle;width:inherit;min-width:", ";max-width:", ";padding:0 24px;&.virtual-table-cell.ant-table-selection-column{padding:0 8px 0 24px;width:auto;}&.virtual-table-cell.ds-table-star-column{padding:0 8px 0 24px;width:auto;& > button{display:flex;}}&.virtual-table-cell.ant-table-selection-column + .virtual-table-cell.ds-table-star-column{padding-left:0;}"], function (props) {
31
31
  return getColumnMinWidth(props);
32
32
  }, function (props) {
33
33
  return getColumnMaxWidth(props);
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { InfiniteScrollProps } from '../InfiniteScroll/constants';
3
3
  import { RowSelection, DSTableProps } from '../Table.types';
4
+ import { RowStar } from '../hooks/useRowStar';
4
5
  interface Props<T> {
5
6
  data: {
6
7
  dataSource: T[];
@@ -8,13 +9,13 @@ interface Props<T> {
8
9
  infiniteScroll: InfiniteScrollProps;
9
10
  mergedColumns: any[];
10
11
  selection?: RowSelection<T>;
12
+ rowStar?: RowStar<T>;
11
13
  onRowClick?: (row: T) => void;
12
14
  defaultTableProps?: DSTableProps<T>;
13
15
  };
14
16
  index: number;
15
17
  style: React.CSSProperties;
16
18
  }
17
- declare class VirtualTableRow<T> extends React.PureComponent<Props<T>> {
18
- render(): React.ReactNode;
19
- }
20
- export default VirtualTableRow;
19
+ declare function VirtualTableRow<T extends object>({ index, style, data: { mergedColumns, onRowClick, selection, rowStar, dataSource, cellHeight, infiniteScroll, defaultTableProps }, }: Props<T>): React.ReactElement;
20
+ declare const _default: React.MemoExoticComponent<typeof VirtualTableRow>;
21
+ export default _default;