@aloudata/aloudata-design 0.3.2 → 0.3.5

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 (205) hide show
  1. package/es/Breadcrumb/index.d.ts +1 -0
  2. package/es/Button/index.js +3 -2
  3. package/es/Button/style/index.less +135 -126
  4. package/es/Button/style/variables.less +53 -53
  5. package/es/Checkbox/index.d.ts +1 -0
  6. package/es/ConfigProvider/defaultRenderEmpty.d.ts +4 -0
  7. package/es/ConfigProvider/defaultRenderEmpty.js +37 -0
  8. package/es/ConfigProvider/sizeContext.d.ts +9 -0
  9. package/es/ConfigProvider/sizeContext.js +12 -0
  10. package/es/Dropdown/Button.js +3 -2
  11. package/es/Empty/image/Authority.d.ts +1 -0
  12. package/es/Empty/image/Dataspace.d.ts +1 -0
  13. package/es/Empty/image/Search.d.ts +1 -0
  14. package/es/Empty/image/Simple.d.ts +1 -0
  15. package/es/Empty/image/Worksheet.d.ts +1 -0
  16. package/es/Empty/image/empty.d.ts +1 -0
  17. package/es/Icon/icons.json +418 -0
  18. package/es/Input/components/Group/index.d.ts +3 -1
  19. package/es/Input/components/Group/index.js +6 -12
  20. package/es/Input/components/Input/index.d.ts +3 -2
  21. package/es/Input/components/Input/index.js +11 -23
  22. package/es/Input/components/Password/index.js +11 -16
  23. package/es/Input/components/TextArea/index.d.ts +8 -1
  24. package/es/Input/components/TextArea/index.js +8 -1
  25. package/es/Input/style/index.less +180 -102
  26. package/es/InputNumber/index.d.ts +1 -0
  27. package/es/InputNumber/style/index.less +69 -69
  28. package/es/Menu/Divider.d.ts +1 -0
  29. package/es/Modal/index.js +4 -7
  30. package/es/Modal/style/index.less +48 -45
  31. package/es/Navigator/components/Header/index.d.ts +1 -0
  32. package/es/Navigator/components/Menu/index.d.ts +1 -0
  33. package/es/PageHeader/index.d.ts +3 -0
  34. package/es/PageHeader/index.js +3 -0
  35. package/es/PageHeader/style/index.d.ts +2 -0
  36. package/es/PageHeader/style/index.js +2 -0
  37. package/es/PageHeader/style/index.less +1 -0
  38. package/es/Popover/index.d.ts +1 -0
  39. package/es/Radio/components/Group/index.d.ts +6 -0
  40. package/es/Radio/components/Group/index.js +74 -0
  41. package/es/Radio/components/Radio/index.d.ts +3 -0
  42. package/es/Radio/components/Radio/index.js +95 -0
  43. package/es/Radio/index.d.ts +9 -2
  44. package/es/Radio/index.js +5 -3
  45. package/es/Radio/interface/radio.d.ts +24 -0
  46. package/es/Radio/interface/radio.js +1 -0
  47. package/es/Radio/interface/radioGroup.d.ts +42 -0
  48. package/es/Radio/interface/radioGroup.js +1 -0
  49. package/es/Radio/style/index.less +348 -0
  50. package/es/Select/index.js +1 -1
  51. package/es/Select/rc-select/OptionList.js +3 -2
  52. package/es/Select/rc-select/hooks/useOptions.d.ts +1 -1
  53. package/es/Select/style/index.less +50 -49
  54. package/es/Select/style/variables.less +45 -45
  55. package/es/Select/utils/iconUtil.d.ts +2 -2
  56. package/es/Select/utils/iconUtil.js +6 -4
  57. package/es/Steps/components/ProcessIcon/index.d.ts +6 -0
  58. package/es/Steps/components/ProcessIcon/index.js +8 -0
  59. package/es/Steps/components/Step/index.d.ts +20 -0
  60. package/es/Steps/components/Step/index.js +45 -0
  61. package/es/Steps/index.d.ts +36 -2
  62. package/es/Steps/index.js +30 -1
  63. package/es/Steps/matchMedia.mock.d.ts +1 -0
  64. package/es/Steps/matchMedia.mock.js +17 -0
  65. package/es/Steps/style/index.less +251 -0
  66. package/es/Switch/index.d.ts +46 -2
  67. package/es/Switch/index.js +71 -1
  68. package/es/Switch/style/index.less +129 -0
  69. package/es/Table/Table.d.ts +2 -1
  70. package/es/Table/Table.js +223 -330
  71. package/es/Table/components/Empty/index.d.ts +3 -0
  72. package/es/Table/components/Empty/index.js +16 -0
  73. package/es/Table/components/Loading/index.d.ts +3 -0
  74. package/es/Table/components/Loading/index.js +18 -0
  75. package/es/Table/components/TableBodyRowList/index.d.ts +13 -0
  76. package/es/Table/components/TableBodyRowList/index.js +91 -0
  77. package/es/Table/components/TableHead/index.d.ts +23 -0
  78. package/es/Table/components/TableHead/index.js +262 -0
  79. package/es/Table/constant.d.ts +1 -0
  80. package/es/Table/constant.js +1 -0
  81. package/es/Table/hooks/useFrame.d.ts +7 -0
  82. package/es/Table/hooks/useFrame.js +90 -0
  83. package/es/Table/hooks/useTableColumn.d.ts +28 -0
  84. package/es/Table/hooks/useTableColumn.js +53 -0
  85. package/es/Table/interface.d.ts +3 -2
  86. package/es/Table/style/index.less +41 -37
  87. package/es/Table/style/index.less.d.ts +126 -0
  88. package/es/Table/style/variable.less +10 -0
  89. package/es/Table/style/variable.less.d.ts +7 -0
  90. package/es/Table/utils.d.ts +15 -0
  91. package/es/Table/utils.js +131 -0
  92. package/es/Tabs/index.js +3 -2
  93. package/es/Tabs/style/index.less +25 -25
  94. package/es/_utils/hooks/useId.d.ts +4 -0
  95. package/es/_utils/hooks/useId.js +23 -0
  96. package/es/index.d.ts +7 -5
  97. package/es/index.js +2 -1
  98. package/es/locale-provider/index.d.ts +5 -1
  99. package/es/style/index.d.ts +0 -1
  100. package/es/style/index.js +0 -1
  101. package/es/style/index.less +2 -2
  102. package/es/style/themes/default/index.less +30 -30
  103. package/lib/Breadcrumb/index.d.ts +1 -0
  104. package/lib/Button/index.js +5 -3
  105. package/lib/Button/style/index.less +135 -126
  106. package/lib/Button/style/variables.less +53 -53
  107. package/lib/Checkbox/index.d.ts +1 -0
  108. package/lib/ConfigProvider/defaultRenderEmpty.d.ts +4 -0
  109. package/lib/ConfigProvider/defaultRenderEmpty.js +55 -0
  110. package/lib/ConfigProvider/sizeContext.d.ts +9 -0
  111. package/lib/ConfigProvider/sizeContext.js +30 -0
  112. package/lib/Dropdown/Button.js +7 -5
  113. package/lib/Empty/image/Authority.d.ts +1 -0
  114. package/lib/Empty/image/Dataspace.d.ts +1 -0
  115. package/lib/Empty/image/Search.d.ts +1 -0
  116. package/lib/Empty/image/Simple.d.ts +1 -0
  117. package/lib/Empty/image/Worksheet.d.ts +1 -0
  118. package/lib/Empty/image/empty.d.ts +1 -0
  119. package/lib/Icon/icons.json +418 -0
  120. package/lib/Input/components/Group/index.d.ts +3 -1
  121. package/lib/Input/components/Group/index.js +7 -12
  122. package/lib/Input/components/Input/index.d.ts +3 -2
  123. package/lib/Input/components/Input/index.js +13 -23
  124. package/lib/Input/components/Password/index.js +13 -17
  125. package/lib/Input/components/TextArea/index.d.ts +8 -1
  126. package/lib/Input/components/TextArea/index.js +10 -1
  127. package/lib/Input/style/index.less +180 -102
  128. package/lib/InputNumber/index.d.ts +1 -0
  129. package/lib/InputNumber/style/index.less +69 -69
  130. package/lib/Menu/Divider.d.ts +1 -0
  131. package/lib/Modal/index.js +8 -10
  132. package/lib/Modal/style/index.less +48 -45
  133. package/lib/Navigator/components/Header/index.d.ts +1 -0
  134. package/lib/Navigator/components/Menu/index.d.ts +1 -0
  135. package/lib/PageHeader/index.d.ts +3 -0
  136. package/lib/PageHeader/index.js +15 -0
  137. package/lib/PageHeader/style/index.d.ts +2 -0
  138. package/lib/PageHeader/style/index.js +5 -0
  139. package/lib/PageHeader/style/index.less +1 -0
  140. package/lib/Popover/index.d.ts +1 -0
  141. package/lib/Radio/components/Group/index.d.ts +6 -0
  142. package/lib/Radio/components/Group/index.js +95 -0
  143. package/lib/Radio/components/Radio/index.d.ts +3 -0
  144. package/lib/Radio/components/Radio/index.js +115 -0
  145. package/lib/Radio/index.d.ts +9 -2
  146. package/lib/Radio/index.js +5 -3
  147. package/lib/Radio/interface/radio.d.ts +24 -0
  148. package/lib/Radio/interface/radio.js +5 -0
  149. package/lib/Radio/interface/radioGroup.d.ts +42 -0
  150. package/lib/Radio/interface/radioGroup.js +5 -0
  151. package/lib/Radio/style/index.less +348 -0
  152. package/lib/Select/index.js +1 -1
  153. package/lib/Select/rc-select/OptionList.js +7 -5
  154. package/lib/Select/rc-select/hooks/useOptions.d.ts +1 -1
  155. package/lib/Select/style/index.less +50 -49
  156. package/lib/Select/style/variables.less +45 -45
  157. package/lib/Select/utils/iconUtil.d.ts +2 -2
  158. package/lib/Select/utils/iconUtil.js +10 -8
  159. package/lib/Steps/components/ProcessIcon/index.d.ts +6 -0
  160. package/lib/Steps/components/ProcessIcon/index.js +19 -0
  161. package/lib/Steps/components/Step/index.d.ts +20 -0
  162. package/lib/Steps/components/Step/index.js +61 -0
  163. package/lib/Steps/index.d.ts +36 -2
  164. package/lib/Steps/index.js +34 -1
  165. package/lib/Steps/matchMedia.mock.d.ts +1 -0
  166. package/lib/Steps/matchMedia.mock.js +17 -0
  167. package/lib/Steps/style/index.less +251 -0
  168. package/lib/Switch/index.d.ts +46 -2
  169. package/lib/Switch/index.js +78 -1
  170. package/lib/Switch/style/index.less +129 -0
  171. package/lib/Table/Table.d.ts +2 -1
  172. package/lib/Table/Table.js +229 -332
  173. package/lib/Table/components/Empty/index.d.ts +3 -0
  174. package/lib/Table/components/Empty/index.js +28 -0
  175. package/lib/Table/components/Loading/index.d.ts +3 -0
  176. package/lib/Table/components/Loading/index.js +31 -0
  177. package/lib/Table/components/TableBodyRowList/index.d.ts +13 -0
  178. package/lib/Table/components/TableBodyRowList/index.js +110 -0
  179. package/lib/Table/components/TableHead/index.d.ts +23 -0
  180. package/lib/Table/components/TableHead/index.js +286 -0
  181. package/lib/Table/constant.d.ts +1 -0
  182. package/lib/Table/constant.js +1 -0
  183. package/lib/Table/hooks/useFrame.d.ts +7 -0
  184. package/lib/Table/hooks/useFrame.js +98 -0
  185. package/lib/Table/hooks/useTableColumn.d.ts +28 -0
  186. package/lib/Table/hooks/useTableColumn.js +66 -0
  187. package/lib/Table/interface.d.ts +3 -2
  188. package/lib/Table/style/index.less +41 -37
  189. package/lib/Table/style/index.less.d.ts +126 -0
  190. package/lib/Table/style/variable.less +10 -0
  191. package/lib/Table/style/variable.less.d.ts +7 -0
  192. package/lib/Table/utils.d.ts +15 -0
  193. package/lib/Table/utils.js +147 -0
  194. package/lib/Tabs/index.js +5 -3
  195. package/lib/Tabs/style/index.less +25 -25
  196. package/lib/_utils/hooks/useId.d.ts +4 -0
  197. package/lib/_utils/hooks/useId.js +36 -0
  198. package/lib/index.d.ts +7 -5
  199. package/lib/index.js +8 -0
  200. package/lib/locale-provider/index.d.ts +5 -1
  201. package/lib/style/index.d.ts +0 -1
  202. package/lib/style/index.js +0 -2
  203. package/lib/style/index.less +2 -2
  204. package/lib/style/themes/default/index.less +30 -30
  205. package/package.json +2 -1
package/es/Table/Table.js CHANGED
@@ -1,10 +1,3 @@
1
- var _excluded = ["style"],
2
- _excluded2 = ["style"];
3
-
4
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
5
-
6
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
7
-
8
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
2
 
10
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -25,22 +18,22 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
25
18
 
26
19
  /* eslint-disable no-unneeded-ternary */
27
20
  /// <reference types ='./react-table-config' />
28
- import _ from 'lodash';
29
21
  import classnames from 'classnames';
30
- import Descending from '../Icon/icons/SortDescendingLine';
31
- import Ascending from '../Icon/icons/SortAscendingLine';
32
- import LoadingIcon from '../Icon/icons/Loading';
33
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
22
+ import React, { useEffect, useMemo, useRef, useState, useCallback } from 'react';
34
23
  import usePrefixCls from '../_utils/hooks/usePrefixCls';
35
- import InfiniteScroll from 'react-infinite-scroll-component';
36
24
  import ResizeObserver from 'rc-resize-observer';
37
- import Empty from '../Empty';
38
- import { useTable, useBlockLayout, useRowSelect, useSortBy, useResizeColumns } from 'react-table'; // import './style/index';
39
-
40
- var ARRAY_FIRST_INDEX = 0;
41
- var DEFAULT_ROW_WIDTH = 0;
42
- var DEFAULT_BODY_HEIGHT = 0;
43
- var EMPTY_LENGTH = 0; // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ import { useTable, useBlockLayout, useRowSelect, useSortBy, useResizeColumns } from 'react-table';
26
+ import { getColumnsWidthMap, getValidScrollThreshold } from './utils';
27
+ import './style/index';
28
+ import message from '../message';
29
+ import Loading from './components/Loading';
30
+ import Empty from './components/Empty';
31
+ import TableHead from './components/TableHead';
32
+ import TableBodyRowList from './components/TableBodyRowList';
33
+ import { useTimeoutLock } from './hooks/useFrame';
34
+ import StylesVariable from './style/variable.less';
35
+ var SCROLLBAR_SIZE = 15;
36
+ var ZERO = 0;
44
37
 
45
38
  function Table(props, ref) {
46
39
  var _classnames3;
@@ -59,79 +52,78 @@ function Table(props, ref) {
59
52
  allSortDirections = props.sortDirections,
60
53
  _props$onChange = props.onChange,
61
54
  onChange = _props$onChange === void 0 ? function () {} : _props$onChange,
62
- _props$innerScroll = props.innerScroll,
63
- innerScroll = _props$innerScroll === void 0 ? false : _props$innerScroll,
64
55
  _props$scrollThreshol = props.scrollThreshold,
65
56
  scrollThreshold = _props$scrollThreshol === void 0 ? '150px' : _props$scrollThreshol,
66
57
  _props$rowClassName = props.rowClassName,
67
58
  rowClassName = _props$rowClassName === void 0 ? '' : _props$rowClassName,
68
59
  _props$ellipsis = props.ellipsis,
69
60
  ellipsis = _props$ellipsis === void 0 ? true : _props$ellipsis,
70
- rowKey = props.rowKey;
61
+ rowKey = props.rowKey,
62
+ height = props.height;
71
63
 
72
- var _React$useState = React.useState(null),
73
- _React$useState2 = _slicedToArray(_React$useState, 2),
74
- selectedRowId = _React$useState2[0],
75
- setSelectedRowId = _React$useState2[1];
76
-
77
- var tableBodyListRef = useRef(null);
78
- var tableRef = useRef(null);
79
-
80
- var _useState = useState(DEFAULT_BODY_HEIGHT),
64
+ var _useState = useState(ZERO),
81
65
  _useState2 = _slicedToArray(_useState, 2),
82
66
  tableClientWidth = _useState2[0],
83
67
  setTableClientWidth = _useState2[1];
84
68
 
85
- var RANDOM_ID = "INNER_SCROLL_ID_".concat(Math.random());
86
-
87
- var _useState3 = useState(DEFAULT_ROW_WIDTH),
69
+ var _useState3 = useState(ZERO),
88
70
  _useState4 = _slicedToArray(_useState3, 2),
89
- width = _useState4[0],
90
- setWidth = _useState4[1]; // 如果页面整体宽度变化则重新计算
71
+ tableClientHeight = _useState4[0],
72
+ setTableClientHeight = _useState4[1];
73
+
74
+ var prefixCls = usePrefixCls('', 'ald-table');
75
+ var tableRef = useRef(null);
76
+ var tableHeadRef = useRef(null);
77
+ var tableBodyRef = useRef(null);
78
+ var columnsRef = useRef([]);
79
+ var columnsWidthMapRef = useRef();
80
+ var columnsTotalWidthRef = useRef(ZERO);
81
+
82
+ var _useState5 = useState(false),
83
+ _useState6 = _slicedToArray(_useState5, 2),
84
+ loadMoreLoading = _useState6[0],
85
+ setLoadMoreLoading = _useState6[1];
86
+
87
+ var lastOffsetLeftRef = useRef(ZERO);
88
+ var lastOffsetTopRef = useRef(ZERO);
89
+
90
+ var _useTimeoutLock = useTimeoutLock(),
91
+ _useTimeoutLock2 = _slicedToArray(_useTimeoutLock, 2),
92
+ setScrollTarget = _useTimeoutLock2[0],
93
+ getScrollTarget = _useTimeoutLock2[1]; // 记录初始columns, 后续更改不响应
94
+
95
+
96
+ if (columns && columnsRef.current.length === ZERO) {
97
+ columnsRef.current = columns;
98
+ } // 初始化进入时 渲染表格容器宽度
91
99
 
92
100
 
93
101
  useEffect(function () {
94
102
  if (tableRef.current) {
95
103
  setTableClientWidth(tableRef.current.clientWidth);
96
104
  }
97
- }, [width]);
98
- var initialColumnsWidthMap = useMemo(function () {
99
- var map = new Map();
100
-
101
- if (tableClientWidth !== DEFAULT_BODY_HEIGHT) {
102
- var noGivenColumns = 0;
103
- var givenColumnsTotalWidth = 0;
104
- columns.forEach(function (column) {
105
- if (column.width) {
106
- map.set(column.dataIndex, column.width);
107
- givenColumnsTotalWidth += column.width;
108
- } else {
109
- noGivenColumns += 1;
110
- }
111
- });
112
- var averageWidth = (tableClientWidth - givenColumnsTotalWidth) / noGivenColumns;
113
- return {
114
- columnMap: map,
115
- averageWidth: averageWidth
116
- };
117
- }
105
+ }, []); // 转换外部传入的columns
118
106
 
119
- columns.forEach(function (column) {
120
- if (column.width) {
121
- map.set(column.dataIndex, column.width);
122
- }
123
- });
124
- return {
125
- columnMap: map,
126
- averageWidth: DEFAULT_ROW_WIDTH
127
- };
128
- }, [columns, tableClientWidth]);
129
107
  var newColumns = useMemo(function () {
130
- return columns.map(function (column) {
108
+ var _getColumnsWidthMap = getColumnsWidthMap(columnsRef.current, tableClientWidth, columnsWidthMapRef.current),
109
+ columnsWidthMap = _getColumnsWidthMap.columnsWidthMap,
110
+ totalColumnWidth = _getColumnsWidthMap.totalColumnWidth;
111
+
112
+ columnsWidthMapRef.current = columnsWidthMap;
113
+ columnsTotalWidthRef.current = totalColumnWidth;
114
+ return columnsRef.current.map(function (column, index) {
115
+ var _columnsWidthMapRef$c, _columnsWidthMapRef$c2;
116
+
117
+ var key = index.toString(); // 不设置dataIndex同时进行排序 则报错
118
+
119
+ if (!column.dataIndex === undefined && sortable) {
120
+ message.error('不支持未设置dataIndex时进行排序设置');
121
+ }
122
+
131
123
  return _objectSpread(_objectSpread({}, column), {}, {
132
- width: initialColumnsWidthMap.columnMap.get(column.dataIndex) || initialColumnsWidthMap.averageWidth,
124
+ width: (_columnsWidthMapRef$c = columnsWidthMapRef.current) === null || _columnsWidthMapRef$c === void 0 ? void 0 : (_columnsWidthMapRef$c2 = _columnsWidthMapRef$c.get(key)) === null || _columnsWidthMapRef$c2 === void 0 ? void 0 : _columnsWidthMapRef$c2.width,
133
125
  Header: column.title ? column.title : function () {
134
- return null;
126
+ return /*#__PURE__*/React.createElement("span", null, "\xA0");
135
127
  },
136
128
  disableSortBy: !sortable || typeof column.sorter === 'boolean',
137
129
  accessor: column.dataIndex,
@@ -142,51 +134,10 @@ function Table(props, ref) {
142
134
  }
143
135
  });
144
136
  });
145
- }, [columns, sortable, initialColumnsWidthMap]); // 默认排序的对象
137
+ }, [sortable, tableClientWidth]); // 将rowId转为React Table支持的值
138
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
146
139
 
147
- var defaultSortObject = {
148
- id: newColumns[ARRAY_FIRST_INDEX].accessor,
149
- desc: newColumns[ARRAY_FIRST_INDEX].sortOrder && newColumns[ARRAY_FIRST_INDEX].sortOrder === 'descend' ? true : false
150
- }; // 如果支持排序 但是没有默认排序 则默认按第一列倒叙排序
151
-
152
- var getInitialSortDirection = function getInitialSortDirection() {
153
- if (defaultSort && defaultSort.id) {
154
- return defaultSort;
155
- }
156
-
157
- if (sortable) {
158
- return defaultSortObject;
159
- }
160
-
161
- return {
162
- id: '',
163
- desc: false
164
- };
165
- };
166
-
167
- var _React$useState3 = React.useState(getInitialSortDirection()),
168
- _React$useState4 = _slicedToArray(_React$useState3, 2),
169
- sortDirection = _React$useState4[0],
170
- setSortDirection = _React$useState4[1];
171
-
172
- var getInitSortBy = function getInitSortBy() {
173
- if (!(sortDirection === null || sortDirection === void 0 ? void 0 : sortDirection.id)) {
174
- return [];
175
- }
176
-
177
- var sortColumn = newColumns.find(function (column) {
178
- return column.accessor === sortDirection.id;
179
- });
180
-
181
- if (sortColumn === null || sortColumn === void 0 ? void 0 : sortColumn.sorter) {
182
- return [];
183
- }
184
-
185
- return [sortDirection];
186
- }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
187
-
188
-
189
- var getRowIdFn = function getRowIdFn(row, relativeIndex, parent) {
140
+ var transformRowId = function transformRowId(row, relativeIndex, parent) {
190
141
  if (rowKey && parent) {
191
142
  if (typeof rowKey === 'string') {
192
143
  return [rowKey, relativeIndex].join('.');
@@ -198,6 +149,24 @@ function Table(props, ref) {
198
149
  }
199
150
 
200
151
  return relativeIndex.toString();
152
+ }; // 计算初始传递给 React Table的排序字段
153
+
154
+
155
+ var getTableInitSort = function getTableInitSort() {
156
+ if (defaultSort && defaultSort.id) {
157
+ return [defaultSort];
158
+ }
159
+
160
+ var firstColumnSortData = {
161
+ id: newColumns[ZERO].accessor,
162
+ desc: !!(newColumns[ZERO].sortOrder && newColumns[ZERO].sortOrder === 'descend')
163
+ };
164
+
165
+ if (firstColumnSortData.id) {
166
+ return [firstColumnSortData];
167
+ }
168
+
169
+ return [];
201
170
  };
202
171
 
203
172
  var _useTable = useTable({
@@ -205,9 +174,9 @@ function Table(props, ref) {
205
174
  data: data,
206
175
  disableMultiSort: true,
207
176
  disableSortBy: !sortable,
208
- getRowId: getRowIdFn,
177
+ getRowId: transformRowId,
209
178
  initialState: {
210
- sortBy: getInitSortBy()
179
+ sortBy: getTableInitSort()
211
180
  }
212
181
  }, useBlockLayout, useSortBy, useRowSelect, useResizeColumns),
213
182
  getTableProps = _useTable.getTableProps,
@@ -215,259 +184,183 @@ function Table(props, ref) {
215
184
  headerGroups = _useTable.headerGroups,
216
185
  rows = _useTable.rows,
217
186
  prepareRow = _useTable.prepareRow,
218
- setSortBy = _useTable.setSortBy,
219
- totalColumnsWidth = _useTable.totalColumnsWidth;
187
+ setSortBy = _useTable.setSortBy;
220
188
 
221
- var theadRowWidthRef = React.useRef(DEFAULT_ROW_WIDTH);
222
- var prefixCls = usePrefixCls('', 'ald-table');
223
- var onRowClick = useCallback(function (row) {
224
- if (!onRowSelected) {
225
- return;
189
+ var scrollToTop = function scrollToTop() {
190
+ var INITIAL_OFFSET_TOP = 0;
191
+
192
+ if (tableBodyRef && tableBodyRef.current) {
193
+ tableBodyRef.current.scrollTop = INITIAL_OFFSET_TOP;
226
194
  }
195
+ };
227
196
 
228
- setSelectedRowId(row.id);
229
- onRowSelected(row.original);
230
- }, [onRowSelected]); // 排序的方向 倒叙{ id: 'xx', desc: true }、正序{ id: 'xx', desc: false }、无序 { id: '', desc: undefined }
231
- // 获取排序方向以及排序的id
232
-
233
- var getSortBy = function getSortBy(id) {
234
- var sortDirections = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['ascend', 'descend'];
235
- var // 如果传了sortDirections,则使用传入的,否则使用默认的
236
- sortOrder = arguments.length > 2 ? arguments[2] : undefined;
237
- var res = {
238
- id: id,
239
- desc: undefined
197
+ React.useImperativeHandle(ref, function () {
198
+ return {
199
+ backToTop: function backToTop() {
200
+ scrollToTop();
201
+ }
240
202
  };
241
- var isSameCol = sortDirection.id === id;
242
- var descMap = new Map([['ascend', false], ['descend', true]]);
243
- var directions = allSortDirections || sortDirections; // 如果不是同一列 则返回默认排序 或者排序顺序的第一个
244
-
245
- if (!isSameCol) {
246
- if (sortOrder === 'ascend' || sortOrder === 'descend') {
247
- res.desc = descMap.get(sortOrder);
248
- } else {
249
- res.desc = sortOrder ? sortOrder : descMap.get(directions[ARRAY_FIRST_INDEX]);
203
+ });
204
+ var tableHeadNode = /*#__PURE__*/React.createElement(TableHead, {
205
+ canResizeColumn: resizeColumn,
206
+ headerGroups: headerGroups,
207
+ tableContentWidth: columnsTotalWidthRef.current,
208
+ defaultSort: defaultSort,
209
+ sortable: sortable,
210
+ columns: newColumns,
211
+ sortDirections: allSortDirections,
212
+ setSortBy: setSortBy,
213
+ onChange: onChange,
214
+ columnsWidthMapRef: columnsWidthMapRef,
215
+ columnsTotalWidthRef: columnsTotalWidthRef
216
+ });
217
+ var tableRowListNode = /*#__PURE__*/React.createElement(TableBodyRowList, {
218
+ data: data,
219
+ rows: rows,
220
+ prepareRow: prepareRow,
221
+ columnsTotalWidthRef: columnsTotalWidthRef,
222
+ rowClassName: rowClassName,
223
+ ellipsis: ellipsis,
224
+ onRowSelected: onRowSelected
225
+ }); // 渲染没有设置高度的表格
226
+
227
+ var renderTableWithoutHeight = function renderTableWithoutHeight() {
228
+ var renderNoHeightTableBody = function renderNoHeightTableBody() {
229
+ if (loading && !rows.length) {
230
+ return /*#__PURE__*/React.createElement(Loading, null);
250
231
  }
251
232
 
252
- return res;
253
- } // 如果是同一列
254
- // 如果列给了默认的sortOrder则不在变化
233
+ if (!loading && !rows.length) {
234
+ return /*#__PURE__*/React.createElement(Empty, null);
235
+ }
255
236
 
237
+ return /*#__PURE__*/React.createElement("div", {
238
+ className: "".concat(prefixCls, "-list")
239
+ }, tableRowListNode);
240
+ };
256
241
 
257
- if (sortOrder === 'ascend' || sortOrder === 'descend') {
258
- res.desc = descMap.get(sortOrder);
259
- return res;
260
- } // 在所有方向上 往后取一个
242
+ return /*#__PURE__*/React.createElement("div", {
243
+ className: classnames("".concat(prefixCls, "-inner-wrap"))
244
+ }, tableHeadNode, /*#__PURE__*/React.createElement("div", Object.assign({}, getTableBodyProps(), {
245
+ className: classnames("".concat(prefixCls, "-tbody")),
246
+ style: {
247
+ width: columnsTotalWidthRef.current
248
+ }
249
+ }), renderNoHeightTableBody()));
250
+ };
261
251
 
252
+ var forceScroll = useCallback(function (scrollLeftNum, target) {
253
+ if (!target) {
254
+ return;
255
+ }
262
256
 
263
- var lastSortDirection = sortDirection.desc ? 'descend' : 'ascend';
257
+ if (typeof target === 'function') {
258
+ target(scrollLeftNum);
259
+ } else if (target.scrollLeft !== scrollLeftNum) {
260
+ // eslint-disable-next-line no-param-reassign
261
+ target.scrollLeft = scrollLeftNum;
262
+ }
263
+ }, []); // 内部滚动时 纵向的滚动
264
264
 
265
- var index = _.findIndex(directions, function (item) {
266
- return item === lastSortDirection;
267
- });
265
+ var onBodyVerticalScroll = useCallback(function (target) {
266
+ var scrollHeight = target.scrollHeight,
267
+ clientHeight = target.clientHeight,
268
+ scrollTop = target.scrollTop;
269
+ var currentPosToBottomGap = scrollHeight - clientHeight - scrollTop;
270
+ var scrollThresholdValue = getValidScrollThreshold(scrollThreshold, tableClientHeight);
268
271
 
269
- var nextIndex = index + 1;
270
- res.desc = descMap.get(directions[nextIndex]); // 如果没有排序方向,则返回默认排序对象
272
+ if (currentPosToBottomGap < scrollThresholdValue && hasNextPage && !loadMoreLoading) {
273
+ var _loadMore;
271
274
 
272
- if (res.desc === undefined) {
273
- res.id = '';
275
+ setLoadMoreLoading(true);
276
+ (_loadMore = loadMore()) === null || _loadMore === void 0 ? void 0 : _loadMore.then(function () {
277
+ setLoadMoreLoading(false);
278
+ });
274
279
  }
275
280
 
276
- return res;
277
- };
278
-
279
- var getHeaderProps = function getHeaderProps(column) {
280
- // @ts-ignore
281
- var id = column.id,
282
- canSort = column.canSort,
283
- sorter = column.sorter,
284
- sortOrder = column.sortOrder,
285
- sortDirections = column.sortDirections;
286
- var toggleProps = column.getSortByToggleProps(); // 仅在Table设置sortable时,所有列的canSort为true,此时为前端排序
287
-
288
- if (canSort) {
289
- // client sort
290
- return _objectSpread(_objectSpread({}, column.getHeaderProps(_objectSpread({}, toggleProps))), {}, {
291
- onClick: function onClick(e) {
292
- e.stopPropagation();
293
-
294
- if (typeof toggleProps.onClick === 'function') {
295
- var sortBy = getSortBy(id, sortDirections, sortOrder);
296
- setSortBy(sortBy.desc === undefined ? [defaultSortObject] : [sortBy]); // 客户端排序时 需要重新设置排序
297
-
298
- setSortDirection(sortBy);
299
- onChange(sortBy);
300
- }
301
- }
302
- });
303
- } // 当列设置sorter属性时,则为服务端排序
281
+ lastOffsetTopRef.current = scrollTop;
282
+ }, [hasNextPage, loadMore, loadMoreLoading, scrollThreshold, tableClientHeight]); // 内部滚动 对于滚动的处理
304
283
 
284
+ var onBodyScroll = useCallback(function (e) {
285
+ var currentTarget = e.target;
305
286
 
306
- if (sorter) {
307
- // server sort
308
- return _objectSpread(_objectSpread({}, column.getHeaderProps({
309
- style: {
310
- cursor: 'pointer'
311
- }
312
- })), {}, {
313
- onClick: function onClick(e) {
314
- e.stopPropagation();
315
- var sortBy = getSortBy(id, sortDirections, sortOrder);
316
- setSortDirection(sortBy);
317
- onChange(sortBy);
318
- }
319
- });
287
+ if (!currentTarget) {
288
+ return;
320
289
  }
321
290
 
322
- return column.getHeaderProps();
323
- };
324
-
325
- var SortIcons = function SortIcons(_ref2) {
326
- var id = _ref2.id;
327
- var currentSortId = sortDirection.id,
328
- desc = sortDirection.desc;
291
+ var scrollLeftNum = currentTarget.scrollLeft;
292
+ var scrollTopNum = currentTarget.scrollTop; // 纵向滚动
329
293
 
330
- if (id !== currentSortId || !sortable) {
331
- return null;
294
+ if (scrollTopNum !== lastOffsetLeftRef.current) {
295
+ onBodyVerticalScroll(currentTarget);
332
296
  }
333
297
 
334
- return desc ? /*#__PURE__*/React.createElement(Descending, {
335
- className: "".concat(prefixCls, "-sortIcon"),
336
- fill: "currentColor",
337
- size: 12
338
- }) : /*#__PURE__*/React.createElement(Ascending, {
339
- className: "".concat(prefixCls, "-sortIcon"),
340
- fill: "currentColor",
341
- size: 12
342
- });
343
- };
298
+ if (scrollLeftNum === lastOffsetLeftRef.current) {
299
+ return;
300
+ }
344
301
 
345
- var scrollToTop = function scrollToTop() {
346
- var INITIAL_OFFSET_TOP = 0;
302
+ var compareTarget = currentTarget; // 横向滚动
347
303
 
348
- if (tableBodyListRef && tableBodyListRef.current) {
349
- tableBodyListRef.current.scrollTop = INITIAL_OFFSET_TOP;
304
+ if (!getScrollTarget() || getScrollTarget() === compareTarget) {
305
+ setScrollTarget(compareTarget);
306
+ forceScroll(scrollLeftNum, tableBodyRef.current);
307
+ forceScroll(scrollLeftNum, tableHeadRef.current);
308
+ lastOffsetLeftRef.current = scrollLeftNum;
350
309
  }
351
- };
310
+ }, [forceScroll, getScrollTarget, onBodyVerticalScroll, setScrollTarget]);
311
+ useEffect(function () {
312
+ if (!hasNextPage) {
313
+ setLoadMoreLoading(false);
314
+ }
315
+ }, [hasNextPage]); // 渲染有设置高度的表格
352
316
 
353
- React.useImperativeHandle(ref, function () {
354
- return {
355
- backToTop: function backToTop() {
356
- scrollToTop();
317
+ var renderTableWithHeight = function renderTableWithHeight() {
318
+ var renderNoHeightTableBody = function renderNoHeightTableBody() {
319
+ if (loading && !rows.length) {
320
+ return /*#__PURE__*/React.createElement(Loading, null);
357
321
  }
358
- };
359
- });
360
- var LoadingNode = /*#__PURE__*/React.createElement("div", {
361
- className: classnames("".concat(prefixCls, "-loading"))
362
- }, /*#__PURE__*/React.createElement(LoadingIcon, {
363
- size: 16,
364
- fill: "currentColor",
365
- spin: true,
366
- className: classnames("".concat(prefixCls, "-loading-icon"))
367
- }), "Loading");
368
-
369
- var renderTableBody = function renderTableBody() {
370
- if (loading && !rows.length) {
371
- return LoadingNode;
372
- }
373
322
 
374
- if (!loading && !rows.length) {
375
- return /*#__PURE__*/React.createElement("div", {
376
- className: classnames("".concat(prefixCls, "-empty-icon"))
377
- }, /*#__PURE__*/React.createElement(Empty, {
378
- title: "No Data",
379
- size: "large",
380
- image: Empty.PRESENTED_IMAGE_SIMPLE
381
- }));
382
- }
323
+ if (!loading && !rows.length) {
324
+ return /*#__PURE__*/React.createElement(Empty, null);
325
+ }
383
326
 
384
- var renderRowList = function renderRowList() {
385
- return data.map(function (item, index) {
386
- var _classnames;
387
-
388
- var row = rows[index];
389
- prepareRow(row);
390
-
391
- var _row$getRowProps = row.getRowProps(),
392
- rowStyle = _row$getRowProps.style,
393
- rowProps = _objectWithoutProperties(_row$getRowProps, _excluded);
394
-
395
- return /*#__PURE__*/React.createElement("div", Object.assign({}, rowProps, {
396
- style: _objectSpread({}, rowStyle),
397
- className: classnames("".concat(prefixCls, "-row"), (_classnames = {}, _defineProperty(_classnames, "".concat(prefixCls, "-row-selected"), row.id === selectedRowId), _defineProperty(_classnames, rowClassName, rowClassName), _defineProperty(_classnames, "".concat(prefixCls, "-row-ellipsis"), ellipsis), _classnames)),
398
- onClick: function onClick() {
399
- return onRowClick(row);
400
- },
401
- key: row.id
402
- }), row.cells.map(function (cell) {
403
- return /*#__PURE__*/React.createElement("div", Object.assign({}, cell.getCellProps(), {
404
- className: classnames("".concat(prefixCls, "-cell"))
405
- }), /*#__PURE__*/React.createElement(React.Fragment, null, cell.render('Cell')));
406
- }));
407
- });
327
+ return /*#__PURE__*/React.createElement("div", {
328
+ style: {
329
+ overflow: 'overlay',
330
+ overflowX: tableClientWidth + SCROLLBAR_SIZE > columnsTotalWidthRef.current ? 'hidden' : 'unset',
331
+ height: tableClientHeight - StylesVariable.TableHeadRowHeight
332
+ },
333
+ ref: tableBodyRef,
334
+ onScroll: onBodyScroll
335
+ }, tableRowListNode, loadMoreLoading && /*#__PURE__*/React.createElement(Loading, null));
408
336
  };
409
337
 
410
338
  return /*#__PURE__*/React.createElement("div", {
411
- className: classnames("".concat(prefixCls, "-list"), _defineProperty({}, "".concat(prefixCls, "-innerScroll"), innerScroll)),
412
- id: RANDOM_ID,
413
- ref: tableBodyListRef
414
- }, innerScroll ? /*#__PURE__*/React.createElement(InfiniteScroll, {
415
- dataLength: rows.length,
416
- next: loadMore,
417
- hasMore: !!hasNextPage,
418
- loader: LoadingNode,
419
- scrollableTarget: RANDOM_ID,
420
- scrollThreshold: scrollThreshold
421
- }, renderRowList()) : renderRowList());
339
+ className: classnames("".concat(prefixCls, "-inner-wrap"), _defineProperty({}, "".concat(prefixCls, "-innerScroll"), height))
340
+ }, /*#__PURE__*/React.createElement("div", {
341
+ ref: tableHeadRef,
342
+ className: "".concat(prefixCls, "-tableHeadScrollWrap")
343
+ }, tableHeadNode), /*#__PURE__*/React.createElement("div", Object.assign({}, getTableBodyProps(), {
344
+ className: classnames("".concat(prefixCls, "-tbody"), _defineProperty({}, "".concat(prefixCls, "-tbody-innerScroll"), height))
345
+ }), renderNoHeightTableBody()));
422
346
  };
423
347
 
424
348
  return /*#__PURE__*/React.createElement(ResizeObserver, {
425
- onResize: function onResize(_ref3) {
426
- var domWidth = _ref3.width;
427
- setWidth(domWidth);
349
+ onResize: function onResize(_ref2) {
350
+ var clientWidth = _ref2.width,
351
+ clientHeight = _ref2.height;
352
+ setTableClientWidth(clientWidth);
353
+ setTableClientHeight(clientHeight);
428
354
  }
429
355
  }, /*#__PURE__*/React.createElement("div", {
430
356
  className: prefixCls,
431
- ref: tableRef
432
- }, /*#__PURE__*/React.createElement("div", Object.assign({}, getTableProps(), {
433
- className: classnames("".concat(prefixCls, "-table-wrap"), (_classnames3 = {}, _defineProperty(_classnames3, "".concat(prefixCls, "-column-resizable"), resizeColumn), _defineProperty(_classnames3, "".concat(prefixCls, "-init-loading"), data.length === EMPTY_LENGTH && loading), _defineProperty(_classnames3, "".concat(prefixCls, "-empty"), data.length === EMPTY_LENGTH && loading), _classnames3))
434
- }), /*#__PURE__*/React.createElement("div", {
435
- className: "".concat(prefixCls, "-thead")
436
- }, headerGroups.map(function (headerGroup) {
437
- var _headerGroup$getHeade = headerGroup.getHeaderGroupProps(),
438
- style = _headerGroup$getHeade.style,
439
- headerGroupProps = _objectWithoutProperties(_headerGroup$getHeade, _excluded2);
440
-
441
- theadRowWidthRef.current = (style === null || style === void 0 ? void 0 : style.width) || DEFAULT_ROW_WIDTH;
442
- return /*#__PURE__*/React.createElement("div", Object.assign({}, headerGroupProps, {
443
- style: _objectSpread(_objectSpread({}, style), {}, {
444
- width: resizeColumn ? style === null || style === void 0 ? void 0 : style.width : '100%'
445
- }),
446
- className: "".concat(prefixCls, "-row")
447
- }), headerGroup.headers.map(function (column) {
448
- var barPorps = resizeColumn ? column.getResizerProps() : {};
449
- return /*#__PURE__*/React.createElement("div", {
450
- className: classnames(_defineProperty({}, "".concat(prefixCls, "-cell-sorting"), column.id === sortDirection.id), "".concat(prefixCls, "-cell")),
451
- style: getHeaderProps(column).style,
452
- key: column.id
453
- }, /*#__PURE__*/React.createElement("div", Object.assign({
454
- className: "".concat(prefixCls, "-cell-content")
455
- }, getHeaderProps(column), {
456
- style: {
457
- width: '100%'
458
- }
459
- }), /*#__PURE__*/React.createElement(React.Fragment, null, column.render('Header'), /*#__PURE__*/React.createElement(SortIcons, {
460
- id: column.id
461
- }))), /*#__PURE__*/React.createElement("div", Object.assign({}, barPorps, {
462
- className: classnames(_defineProperty({}, "".concat(prefixCls, "-dragBar"), resizeColumn), "".concat(prefixCls, "-bar"))
463
- })));
464
- }));
465
- })), /*#__PURE__*/React.createElement("div", Object.assign({}, getTableBodyProps(), {
466
- className: classnames("".concat(prefixCls, "-tbody"), _defineProperty({}, "".concat(prefixCls, "-innerScroll"), innerScroll)),
357
+ ref: tableRef,
467
358
  style: {
468
- width: totalColumnsWidth
359
+ height: !height ? 'unset' : height
469
360
  }
470
- }), renderTableBody()))));
361
+ }, /*#__PURE__*/React.createElement("div", Object.assign({}, getTableProps(), {
362
+ className: classnames("".concat(prefixCls, "-table-wrap"), (_classnames3 = {}, _defineProperty(_classnames3, "".concat(prefixCls, "-init-loading"), data.length === ZERO && loading), _defineProperty(_classnames3, "".concat(prefixCls, "-empty"), data.length === ZERO && loading), _classnames3))
363
+ }), height ? renderTableWithHeight() : renderTableWithoutHeight())));
471
364
  }
472
365
 
473
366
  export default /*#__PURE__*/React.forwardRef(Table);
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare function LoadingNode(): JSX.Element;
3
+ export default LoadingNode;