@qn-pandora/pandora-component 5.1.1 → 5.1.2

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 (244) hide show
  1. package/README.md +36 -36
  2. package/es/components/AutoComplete/style.css +17 -17
  3. package/es/components/AutoComplete/style.less +8 -8
  4. package/es/components/Breadcrumb/style.less +9 -9
  5. package/es/components/Button/style.css +69 -69
  6. package/es/components/Button/style.less +51 -51
  7. package/es/components/Card/RowExtra/style.less +8 -8
  8. package/es/components/Card/SearchInput/style.less +8 -8
  9. package/es/components/Card/style.css +11 -11
  10. package/es/components/Card/style.less +11 -11
  11. package/es/components/CheckTransformList/style.css +19 -19
  12. package/es/components/CheckTransformList/style.less +35 -35
  13. package/es/components/Checkbox/index.js +9 -1
  14. package/es/components/Checkbox/style.less +5 -5
  15. package/es/components/CheckboxList/style.css +5 -5
  16. package/es/components/CheckboxList/style.less +11 -11
  17. package/es/components/Collapse/style.css +1 -1
  18. package/es/components/Collapse/style.less +58 -58
  19. package/es/components/CollapsiblePanel/style.less +63 -63
  20. package/es/components/DateTimePicker/Base/index.d.ts +3 -0
  21. package/es/components/DateTimePicker/Base/index.js +51 -6
  22. package/es/components/DateTimePicker/Base/style.css +67 -61
  23. package/es/components/DateTimePicker/Base/style.less +167 -160
  24. package/es/components/DateTimePicker/BaseMobile/Absolute/style.less +35 -35
  25. package/es/components/DateTimePicker/BaseMobile/style.less +32 -32
  26. package/es/components/DateTimePicker/Collapse/Panel/style.less +26 -26
  27. package/es/components/DateTimePicker/DisplayInput/index.js +3 -1
  28. package/es/components/DateTimePicker/DisplayInput/style.css +14 -14
  29. package/es/components/DateTimePicker/DisplayInput/style.less +9 -9
  30. package/es/components/DateTimePicker/constants.d.ts +9 -3
  31. package/es/components/DateTimePicker/constants.js +1 -0
  32. package/es/components/DateTimePicker/style.less +19 -19
  33. package/es/components/DateTimePicker/time.d.ts +1 -0
  34. package/es/components/DateTimePicker/time.js +1 -0
  35. package/es/components/DateTimePicker/transform.js +4 -2
  36. package/es/components/Descriptions/style.less +16 -16
  37. package/es/components/Drawer/CloseIcon/style.less +8 -8
  38. package/es/components/Drawer/index.d.ts +1 -1
  39. package/es/components/Drawer/style.less +69 -69
  40. package/es/components/FileResumable/index.js +2 -3
  41. package/es/components/FileResumable/style.css +8 -8
  42. package/es/components/FileResumable/style.less +94 -94
  43. package/es/components/FlameGraph/customTooltip.d.ts +22 -0
  44. package/es/components/FlameGraph/customTooltip.js +91 -0
  45. package/es/components/FlameGraph/index.d.ts +16 -0
  46. package/es/components/FlameGraph/index.js +96 -0
  47. package/es/components/FlameGraph/style.css +8 -0
  48. package/es/components/FlameGraph/style.less +14 -0
  49. package/es/components/Input/style.css +14 -14
  50. package/es/components/Input/style.less +12 -12
  51. package/es/components/KeyValuePair/style.less +25 -25
  52. package/es/components/Menu/Option.d.ts +1 -1
  53. package/es/components/Menu/Option.js +12 -4
  54. package/es/components/Menu/style.css +23 -23
  55. package/es/components/Menu/style.less +18 -18
  56. package/es/components/Modal/style.css +1 -1
  57. package/es/components/Modal/style.less +30 -30
  58. package/es/components/NameExplainTooltip/style.css +1 -1
  59. package/es/components/NameExplainTooltip/style.less +10 -10
  60. package/es/components/NameLimiter/style.less +19 -19
  61. package/es/components/OptionList/InlineOptionList/style.css +1 -1
  62. package/es/components/OptionList/InlineOptionList/style.less +16 -16
  63. package/es/components/OptionList/OptionItem/style.css +2 -2
  64. package/es/components/OptionList/OptionItem/style.less +25 -25
  65. package/es/components/OptionList/PopoverOptionList/style.css +3 -3
  66. package/es/components/OptionList/PopoverOptionList/style.less +30 -30
  67. package/es/components/OptionList/style.css +6 -6
  68. package/es/components/OptionList/style.less +3 -3
  69. package/es/components/RadioGroup/style.css +32 -32
  70. package/es/components/RadioGroup/style.less +41 -41
  71. package/es/components/RangeInput/style.css +29 -29
  72. package/es/components/RangeInput/style.less +37 -37
  73. package/es/components/RemarkName/style.less +2 -2
  74. package/es/components/Selector/style.css +17 -17
  75. package/es/components/Selector/style.less +99 -99
  76. package/es/components/Spin/style.css +2 -2
  77. package/es/components/Spin/style.less +26 -26
  78. package/es/components/Steps/ControlButton/style.less +5 -5
  79. package/es/components/Steps/style.css +16 -16
  80. package/es/components/Steps/style.less +48 -48
  81. package/es/components/Table/ColumnSetting/index.d.ts +1 -0
  82. package/es/components/Table/ColumnSetting/index.js +19 -14
  83. package/es/components/Table/ColumnSetting/style.less +50 -50
  84. package/es/components/Table/ColumnTag/style.css +4 -4
  85. package/es/components/Table/ColumnTag/style.less +40 -40
  86. package/es/components/Table/EmptyText.d.ts +7 -0
  87. package/es/components/Table/EmptyText.js +22 -0
  88. package/es/components/Table/ResizableTitle/style.less +25 -25
  89. package/es/components/Table/index.d.ts +11 -83
  90. package/es/components/Table/index.js +113 -286
  91. package/es/components/Table/style.css +54 -44
  92. package/es/components/Table/style.less +364 -345
  93. package/es/components/Table/type.d.ts +63 -0
  94. package/es/components/Table/type.js +5 -0
  95. package/es/components/Table/util.d.ts +58 -0
  96. package/es/components/Table/util.js +218 -0
  97. package/es/components/Tabs/style.css +10 -10
  98. package/es/components/Tabs/style.less +33 -33
  99. package/es/components/TagList/Tag/style.css +5 -5
  100. package/es/components/TagList/Tag/style.less +72 -72
  101. package/es/components/TagList/TagSwitch/style.css +1 -1
  102. package/es/components/TagList/TagSwitch/style.less +28 -28
  103. package/es/components/TagList/style.css +6 -6
  104. package/es/components/TagList/style.less +28 -28
  105. package/es/components/Timeline/TimelineItem/style.css +1 -1
  106. package/es/components/Timeline/TimelineItem/style.less +49 -49
  107. package/es/components/Timeline/style.less +23 -23
  108. package/es/components/TopologyChart/style.less +14 -14
  109. package/es/components/Transfer/List/style.less +19 -19
  110. package/es/components/Transfer/ListBody/style.less +18 -18
  111. package/es/components/Transfer/style.less +14 -14
  112. package/es/components/TreeSelector/style.css +21 -21
  113. package/es/components/TreeSelector/style.less +56 -56
  114. package/es/constants/language/datetime/en.js +4 -2
  115. package/es/constants/language/datetime/type.d.ts +4 -2
  116. package/es/constants/language/datetime/zh.js +4 -2
  117. package/es/index.css +6268 -6244
  118. package/es/index.d.ts +1 -0
  119. package/es/index.js +1 -0
  120. package/es/index.less +56 -55
  121. package/es/style/mixin.less +45 -45
  122. package/es/style/theme.less +416 -416
  123. package/lib/components/AutoComplete/style.css +17 -17
  124. package/lib/components/AutoComplete/style.less +8 -8
  125. package/lib/components/Breadcrumb/style.less +9 -9
  126. package/lib/components/Button/style.css +69 -69
  127. package/lib/components/Button/style.less +51 -51
  128. package/lib/components/Card/RowExtra/style.less +8 -8
  129. package/lib/components/Card/SearchInput/style.less +8 -8
  130. package/lib/components/Card/style.css +11 -11
  131. package/lib/components/Card/style.less +11 -11
  132. package/lib/components/CheckTransformList/style.css +19 -19
  133. package/lib/components/CheckTransformList/style.less +35 -35
  134. package/lib/components/Checkbox/index.js +9 -1
  135. package/lib/components/Checkbox/style.less +5 -5
  136. package/lib/components/CheckboxList/style.css +5 -5
  137. package/lib/components/CheckboxList/style.less +11 -11
  138. package/lib/components/Collapse/style.css +1 -1
  139. package/lib/components/Collapse/style.less +58 -58
  140. package/lib/components/CollapsiblePanel/style.less +63 -63
  141. package/lib/components/DateTimePicker/Base/index.d.ts +3 -0
  142. package/lib/components/DateTimePicker/Base/index.js +51 -6
  143. package/lib/components/DateTimePicker/Base/style.css +67 -61
  144. package/lib/components/DateTimePicker/Base/style.less +167 -160
  145. package/lib/components/DateTimePicker/BaseMobile/Absolute/style.less +35 -35
  146. package/lib/components/DateTimePicker/BaseMobile/style.less +32 -32
  147. package/lib/components/DateTimePicker/Collapse/Panel/style.less +26 -26
  148. package/lib/components/DateTimePicker/DisplayInput/index.js +3 -1
  149. package/lib/components/DateTimePicker/DisplayInput/style.css +14 -14
  150. package/lib/components/DateTimePicker/DisplayInput/style.less +9 -9
  151. package/lib/components/DateTimePicker/constants.d.ts +9 -3
  152. package/lib/components/DateTimePicker/constants.js +1 -0
  153. package/lib/components/DateTimePicker/style.less +19 -19
  154. package/lib/components/DateTimePicker/time.d.ts +1 -0
  155. package/lib/components/DateTimePicker/time.js +1 -0
  156. package/lib/components/DateTimePicker/transform.js +4 -2
  157. package/lib/components/Descriptions/style.less +16 -16
  158. package/lib/components/Drawer/CloseIcon/style.less +8 -8
  159. package/lib/components/Drawer/index.d.ts +1 -1
  160. package/lib/components/Drawer/style.less +69 -69
  161. package/lib/components/FileResumable/index.js +2 -3
  162. package/lib/components/FileResumable/style.css +8 -8
  163. package/lib/components/FileResumable/style.less +94 -94
  164. package/lib/components/FlameGraph/customTooltip.d.ts +22 -0
  165. package/lib/components/FlameGraph/customTooltip.js +114 -0
  166. package/lib/components/FlameGraph/index.d.ts +16 -0
  167. package/lib/components/FlameGraph/index.js +117 -0
  168. package/lib/components/FlameGraph/style.css +8 -0
  169. package/lib/components/FlameGraph/style.less +14 -0
  170. package/lib/components/Input/style.css +14 -14
  171. package/lib/components/Input/style.less +12 -12
  172. package/lib/components/KeyValuePair/style.less +25 -25
  173. package/lib/components/Menu/Option.d.ts +1 -1
  174. package/lib/components/Menu/Option.js +17 -25
  175. package/lib/components/Menu/style.css +23 -23
  176. package/lib/components/Menu/style.less +18 -18
  177. package/lib/components/Modal/style.css +1 -1
  178. package/lib/components/Modal/style.less +30 -30
  179. package/lib/components/NameExplainTooltip/style.css +1 -1
  180. package/lib/components/NameExplainTooltip/style.less +10 -10
  181. package/lib/components/NameLimiter/style.less +19 -19
  182. package/lib/components/OptionList/InlineOptionList/style.css +1 -1
  183. package/lib/components/OptionList/InlineOptionList/style.less +16 -16
  184. package/lib/components/OptionList/OptionItem/style.css +2 -2
  185. package/lib/components/OptionList/OptionItem/style.less +25 -25
  186. package/lib/components/OptionList/PopoverOptionList/style.css +3 -3
  187. package/lib/components/OptionList/PopoverOptionList/style.less +30 -30
  188. package/lib/components/OptionList/style.css +6 -6
  189. package/lib/components/OptionList/style.less +3 -3
  190. package/lib/components/RadioGroup/style.css +32 -32
  191. package/lib/components/RadioGroup/style.less +41 -41
  192. package/lib/components/RangeInput/style.css +29 -29
  193. package/lib/components/RangeInput/style.less +37 -37
  194. package/lib/components/RemarkName/style.less +2 -2
  195. package/lib/components/Selector/style.css +17 -17
  196. package/lib/components/Selector/style.less +99 -99
  197. package/lib/components/Spin/style.css +2 -2
  198. package/lib/components/Spin/style.less +26 -26
  199. package/lib/components/Steps/ControlButton/style.less +5 -5
  200. package/lib/components/Steps/style.css +16 -16
  201. package/lib/components/Steps/style.less +48 -48
  202. package/lib/components/Table/ColumnSetting/index.d.ts +1 -0
  203. package/lib/components/Table/ColumnSetting/index.js +19 -14
  204. package/lib/components/Table/ColumnSetting/style.less +50 -50
  205. package/lib/components/Table/ColumnTag/style.css +4 -4
  206. package/lib/components/Table/ColumnTag/style.less +40 -40
  207. package/lib/components/Table/EmptyText.d.ts +7 -0
  208. package/lib/components/Table/EmptyText.js +27 -0
  209. package/lib/components/Table/ResizableTitle/style.less +25 -25
  210. package/lib/components/Table/index.d.ts +11 -83
  211. package/lib/components/Table/index.js +117 -288
  212. package/lib/components/Table/style.css +54 -44
  213. package/lib/components/Table/style.less +364 -345
  214. package/lib/components/Table/type.d.ts +63 -0
  215. package/lib/components/Table/type.js +8 -0
  216. package/lib/components/Table/util.d.ts +58 -0
  217. package/lib/components/Table/util.js +227 -0
  218. package/lib/components/Tabs/style.css +10 -10
  219. package/lib/components/Tabs/style.less +33 -33
  220. package/lib/components/TagList/Tag/style.css +5 -5
  221. package/lib/components/TagList/Tag/style.less +72 -72
  222. package/lib/components/TagList/TagSwitch/style.css +1 -1
  223. package/lib/components/TagList/TagSwitch/style.less +28 -28
  224. package/lib/components/TagList/style.css +6 -6
  225. package/lib/components/TagList/style.less +28 -28
  226. package/lib/components/Timeline/TimelineItem/style.css +1 -1
  227. package/lib/components/Timeline/TimelineItem/style.less +49 -49
  228. package/lib/components/Timeline/style.less +23 -23
  229. package/lib/components/TopologyChart/style.less +14 -14
  230. package/lib/components/Transfer/List/style.less +19 -19
  231. package/lib/components/Transfer/ListBody/style.less +18 -18
  232. package/lib/components/Transfer/style.less +14 -14
  233. package/lib/components/TreeSelector/style.css +21 -21
  234. package/lib/components/TreeSelector/style.less +56 -56
  235. package/lib/constants/language/datetime/en.js +4 -2
  236. package/lib/constants/language/datetime/type.d.ts +4 -2
  237. package/lib/constants/language/datetime/zh.js +4 -2
  238. package/lib/index.css +4726 -4702
  239. package/lib/index.d.ts +1 -0
  240. package/lib/index.js +3 -1
  241. package/lib/index.less +56 -55
  242. package/lib/style/mixin.less +45 -45
  243. package/lib/style/theme.less +416 -416
  244. package/package.json +7 -4
@@ -66,11 +66,10 @@ import * as React from 'react';
66
66
  import classnames from 'classnames';
67
67
  import { observer } from 'mobx-react';
68
68
  import { observable, action, computed } from 'mobx';
69
- import { size, xor, union, unionBy, differenceBy, get, isEqual, includes, isNumber, isArray } from 'lodash';
69
+ import { size, xor, union, unionBy, differenceBy, get, isEqual, includes, isNumber, isUndefined } from 'lodash';
70
70
  import { Table as AntTable, Checkbox } from 'antd';
71
71
  import { ConfigContext } from 'antd/es/config-provider';
72
72
  import { toaster as toasterStore } from '@qn-pandora/app-sdk';
73
- import { EmptyIcon } from '@qn-pandora/pandora-component-icons';
74
73
  import bind from '../../utils/bind';
75
74
  import { formatString } from '../../utils/language';
76
75
  import { SDK_PREFIX } from '../../constants/style';
@@ -78,11 +77,15 @@ import { TableLocale } from '../../constants/language/table/type';
78
77
  import { ColumnTag } from './ColumnTag/ColumnTag';
79
78
  import ColumnSetting from './ColumnSetting';
80
79
  import ResizableTitle from './ResizableTitle';
81
- export var ETableSettingType;
82
- (function (ETableSettingType) {
83
- ETableSettingType["SORT"] = "sort";
84
- ETableSettingType["RESIZE"] = "resize";
85
- })(ETableSettingType || (ETableSettingType = {}));
80
+ import EmptyText from './EmptyText';
81
+ import { addEmptyColumn, getSortAndHiddenKeys, getSortedCoulmns, getColumnKeys, getResizeColumns, getLocalSettings } from './util';
82
+ import { ETableSettingType } from './type';
83
+ export * from './type';
84
+ /**
85
+ * 表格提供自定义多选, 通过 rowSelection对象的selectedRowKeys和onChange来控制多选的状态
86
+ * 需要注意的是, 当在外部进行增删改或者外部需要控制选择状态时, 例如删除之后清空全选状态, 需要受控
87
+ * 传入selectedRowKeys值。
88
+ */
86
89
  /**
87
90
  * pandora2.0风格的表格
88
91
  */
@@ -111,30 +114,34 @@ var Table = /** @class */ (function (_super) {
111
114
  (lastRowSelection &&
112
115
  !isEqual(lastRowSelection.selectedRowKeys, rowSelection.selectedRowKeys)))) {
113
116
  var selectedRowKeys_1 = rowSelection.selectedRowKeys || [];
114
- var dataSource = nextProps.dataSource;
115
- var selectedRowKeysOfCurrentPage_1 = (dataSource || [])
116
- .map(this.getRowKey)
117
- .filter(function (item) { return selectedRowKeys_1.includes(item); });
118
- var selectedRowsOfCurrentPage = (dataSource || []).filter(function (item, index) {
119
- return selectedRowKeysOfCurrentPage_1.indexOf(_this.getRowKey(item, index)) > -1;
117
+ var _a = nextProps.dataSource, dataSource = _a === void 0 ? [] : _a;
118
+ var selectedRowKeysOfCurrentPage_1 = [];
119
+ var selectedRowsOfCurrentPage_1 = [];
120
+ dataSource.forEach(function (item, index) {
121
+ var rowKey = _this.getRowKey(item, index);
122
+ if (selectedRowKeys_1.includes(rowKey)) {
123
+ selectedRowKeysOfCurrentPage_1.push(rowKey);
124
+ selectedRowsOfCurrentPage_1.push(item);
125
+ }
120
126
  });
121
127
  // 数据源变化时重新设置多选框是否为全选状态或部分选中状态
122
- this.setCheckboxStatus(selectedRowKeysOfCurrentPage_1, nextProps.dataSource);
128
+ this.setCheckboxStatus(selectedRowsOfCurrentPage_1, size(nextProps.dataSource));
123
129
  // 更新外部组件rowSelection状态
124
130
  // this.onRowSelectionChange(selectedRowKeys, selectedRowsOfCurrentPage)
125
131
  if (rowSelection && rowSelection.onChange) {
126
132
  rowSelection.onChange(union(selectedRowKeysOfCurrentPage_1, selectedRowKeys_1), selectedRows && rowKey
127
- ? unionBy(selectedRowsOfCurrentPage, selectedRows, rowKey)
128
- : selectedRowsOfCurrentPage, { type: 'single' });
133
+ ? unionBy(selectedRowsOfCurrentPage_1, selectedRows, rowKey)
134
+ : selectedRowsOfCurrentPage_1, { type: 'single' });
129
135
  }
130
136
  }
137
+ // 更新隐藏的key
131
138
  if (!isEqual(nextProps.hiddenColumns, this.props.hiddenColumns)) {
132
139
  this.setHiddenColumn(nextProps.hiddenColumns);
133
140
  }
134
141
  if (nextProps.columns !== this.props.columns) {
135
142
  if ((nextProps.scroll && nextProps.draggable === true) ||
136
143
  nextProps.draggable === ETableSettingType.RESIZE) {
137
- this.updateSettingConfig(nextProps.columns);
144
+ this.updateSettingFields(nextProps.columns, this.settingFields, nextProps.hiddenColumns || []);
138
145
  this.setColumns(this.getResizeColumns(nextProps.columns));
139
146
  }
140
147
  else {
@@ -149,8 +156,7 @@ var Table = /** @class */ (function (_super) {
149
156
  };
150
157
  Object.defineProperty(Table.prototype, "selectedRowKeys", {
151
158
  get: function () {
152
- var rowSelection = this.props.rowSelection;
153
- return (rowSelection && rowSelection.selectedRowKeys) || [];
159
+ return get(this.props.rowSelection, 'selectedRowKeys', []);
154
160
  },
155
161
  enumerable: false,
156
162
  configurable: true
@@ -186,161 +192,79 @@ var Table = /** @class */ (function (_super) {
186
192
  enumerable: false,
187
193
  configurable: true
188
194
  });
189
- Object.defineProperty(Table.prototype, "emptyTextComp", {
190
- get: function () {
191
- var emptyText = this.props.emptyText;
192
- if (!emptyText) {
193
- return (React.createElement("div", { className: SDK_PREFIX + "-table-empty" },
194
- React.createElement("div", { className: SDK_PREFIX + "-table-empty-icon" },
195
- React.createElement(EmptyIcon, null)),
196
- React.createElement("div", { className: SDK_PREFIX + "-table-empty-text" }, formatString(TableLocale.empty, this.context.locale))));
197
- }
198
- if (typeof emptyText === 'string' || typeof emptyText === 'number') {
199
- return (React.createElement("div", { className: SDK_PREFIX + "-table-empty" },
200
- React.createElement("div", { className: SDK_PREFIX + "-table-empty-icon" },
201
- React.createElement(EmptyIcon, null)),
202
- React.createElement("div", { className: SDK_PREFIX + "-table-empty-text" }, emptyText)));
203
- }
204
- return emptyText;
205
- },
206
- enumerable: false,
207
- configurable: true
208
- });
209
195
  Object.defineProperty(Table.prototype, "columnsSettingOptions", {
210
196
  // 列设置 options
211
197
  get: function () {
212
198
  var options = [];
213
199
  var _a = this.props.columns, columns = _a === void 0 ? [] : _a;
214
- columns.forEach(function (col) {
215
- if (col.key && col.key.toString().length > 0) {
200
+ // sortKeys 来保证数据的准确性
201
+ this.sortConfig.sortKeys.forEach(function (key) {
202
+ var target = columns.find(function (col) { var _a; return ((_a = col.key) === null || _a === void 0 ? void 0 : _a.toString()) === key; });
203
+ if (target && target.key) {
216
204
  options.push({
217
- label: col.colTitle || col.title,
218
- value: col.key.toString()
205
+ label: target.colTitle || target.title,
206
+ value: target.key.toString()
219
207
  });
220
208
  }
221
209
  });
222
- // sortKeys 来保证数据的准确性
223
- return this.sortConfig.sortKeys
224
- .map(function (key) { return options.find(function (option) { return option.value === key; }); })
225
- .filter(function (f) { return !!f; });
210
+ return options;
226
211
  },
227
212
  enumerable: false,
228
213
  configurable: true
229
214
  });
230
215
  Object.defineProperty(Table.prototype, "columnKeys", {
231
216
  get: function () {
232
- var _a = this.props.columns, columns = _a === void 0 ? [] : _a;
233
- var allKeys = [];
234
- var unconfigableKeys = [];
235
- var resetKeys = [];
236
- columns.forEach(function (col) {
237
- if (col.key) {
238
- // 不可配置,或者列固定的列,(在这里统称不可配置的列)
239
- if (col.configurable === false || col.fixed) {
240
- unconfigableKeys.push(col.key.toString());
241
- }
242
- else {
243
- resetKeys.push(col.key.toString());
244
- }
245
- allKeys.push(col.key.toString());
246
- }
247
- });
248
- return {
249
- allKeys: allKeys,
250
- unconfigableKeys: unconfigableKeys,
251
- resetKeys: resetKeys
252
- };
217
+ return getColumnKeys(this.props.columns || []);
253
218
  },
254
219
  enumerable: false,
255
220
  configurable: true
256
221
  });
257
222
  Object.defineProperty(Table.prototype, "resizable", {
258
223
  get: function () {
259
- var _a, _b;
260
- return ((((_a = this.props) === null || _a === void 0 ? void 0 : _a.draggable) === true ||
261
- ((_b = this.props) === null || _b === void 0 ? void 0 : _b.draggable) === ETableSettingType.RESIZE) &&
262
- this.props.scroll);
224
+ var _a = this.props, draggable = _a.draggable, scroll = _a.scroll;
225
+ return !!((draggable === true || draggable === ETableSettingType.RESIZE) &&
226
+ scroll);
263
227
  },
264
228
  enumerable: false,
265
229
  configurable: true
266
230
  });
267
231
  Object.defineProperty(Table.prototype, "sortable", {
268
232
  get: function () {
269
- var _a, _b;
270
- return (((_a = this.props) === null || _a === void 0 ? void 0 : _a.draggable) === true ||
271
- ((_b = this.props) === null || _b === void 0 ? void 0 : _b.draggable) === ETableSettingType.SORT);
233
+ var draggable = this.props.draggable;
234
+ return draggable === true || draggable === ETableSettingType.SORT;
272
235
  },
273
236
  enumerable: false,
274
237
  configurable: true
275
238
  });
276
239
  Object.defineProperty(Table.prototype, "showSetting", {
240
+ // 是否支持列设置按钮
277
241
  get: function () {
278
- // showColumnSetting 需要同 draggable 配合使用, 如果设置不显示列设置按钮, 则不需要显示,其他时候只有 draggable = sort 或者 draggable === true时才显示,
242
+ // showColumnSetting 需要同 draggable 配合使用
243
+ // 1、showColumnSetting = false, 不显示
244
+ // 2、draggable = sort 或者 draggable === true时才显示
245
+ // 3、draggable === resize 且 showColumnSetting = true时才显示(resize模式下必须显示设置showColumnSetting=true,才会显示列设置按钮)
279
246
  var _a = this.props, showColumnSetting = _a.showColumnSetting, draggable = _a.draggable;
280
247
  if (showColumnSetting === false)
281
248
  return false;
282
249
  if (draggable === ETableSettingType.SORT || draggable === true)
283
250
  return true;
251
+ if (draggable === ETableSettingType.RESIZE && showColumnSetting === true) {
252
+ return true;
253
+ }
284
254
  return false;
285
255
  },
286
256
  enumerable: false,
287
257
  configurable: true
288
258
  });
289
- Table.prototype.updateSettingConfig = function (columns) {
290
- this.updateSettingFields(columns, this.settingFields);
291
- };
292
259
  Table.prototype.initSettingConfig = function () {
293
- var saveSettingKey = this.props.saveSettingKey;
294
- var settingFields = [];
295
- if (saveSettingKey) {
296
- try {
297
- var settingStr = localStorage.getItem(saveSettingKey);
298
- var settingConfig = !!settingStr && JSON.parse(settingStr);
299
- if (isArray(settingConfig)) {
300
- settingFields = settingConfig;
301
- }
302
- }
303
- catch (error) {
304
- throw new Error("parse " + saveSettingKey + " error: " + error + ", please check the data format");
305
- }
306
- }
307
- this.updateSettingFields(this.props.columns, settingFields);
260
+ var _a = this.props, saveSettingKey = _a.saveSettingKey, columns = _a.columns, _b = _a.hiddenColumns, hiddenColumns = _b === void 0 ? [] : _b;
261
+ var settingFields = getLocalSettings(saveSettingKey);
262
+ this.updateSettingFields(columns, settingFields, hiddenColumns);
308
263
  };
309
- Table.prototype.updateSettingFields = function (columns, settingFields) {
310
- var _a = this.props.hiddenColumns, hiddenColumns = _a === void 0 ? [] : _a;
311
- var sortableColumns = [];
312
- var hideKeys = [];
313
- // 已配置的列和实际的对不上
314
- // 可能新增或者删除列的情况
315
- // 已配置列
316
- // 旧类型数据为对象类型,未配置
317
- settingFields.map(function (field) {
318
- var find = columns.find(function (column) { var _a; return ((_a = column) === null || _a === void 0 ? void 0 : _a.dataIndex) === field.field; });
319
- if (find) {
320
- if (field.hide) {
321
- hideKeys.push(field.field);
322
- }
323
- else {
324
- sortableColumns.push(field);
325
- }
326
- }
327
- });
328
- // 未配置过的列
329
- columns
330
- .filter(function (f) { return !settingFields.find(function (field) { return field.field === f.dataIndex; }); })
331
- .map(function (column) {
332
- if (column.dataIndex) {
333
- // 不是列固定,并且可配置,才可以展示拖拽
334
- if (!(column.fixed || column.configurable === false)) {
335
- sortableColumns.push({
336
- field: column.dataIndex.toString(),
337
- fixed: column.fixed
338
- });
339
- }
340
- }
341
- });
264
+ Table.prototype.updateSettingFields = function (columns, settingFields, hiddenColumns) {
265
+ var _a = getSortAndHiddenKeys(columns, settingFields, hiddenColumns), sortableColumns = _a.sortableColumns, resultHiddenColumns = _a.hiddenColumns;
342
266
  this.setSortKeys(sortableColumns.map(function (t) { return t.field; }));
343
- this.setHiddenColumn(__spread(new Set(__spread(hiddenColumns, hideKeys))));
267
+ this.setHiddenColumn(resultHiddenColumns);
344
268
  this.setSettingFields(sortableColumns);
345
269
  };
346
270
  // 隐藏key
@@ -352,75 +276,46 @@ var Table = /** @class */ (function (_super) {
352
276
  return toasterStore.warning(formatString(TableLocale.hide_column_tooltip, this.context.locale));
353
277
  }
354
278
  var newSettingFields = this.settingFields.map(function (field) {
355
- if (includes(keys, field.field)) {
356
- return __assign(__assign({}, field), { hide: true });
357
- }
358
- return __assign(__assign({}, field), { hide: false });
279
+ return __assign(__assign({}, field), { hide: includes(keys, field.field) });
359
280
  });
360
281
  this.setHiddenColumn(keys);
361
282
  this.setSettingFields(newSettingFields);
362
283
  (_b = (_a = this.props).onHiddenColumnsChange) === null || _b === void 0 ? void 0 : _b.call(_a, keys);
363
284
  };
364
- Table.prototype.getSortedColumns = function () {
365
- var hiddenColumn = this.hiddenColumn || [];
366
- var fixedRightColumn = [];
367
- var fixedLeftColumn = [];
368
- var selectedCols = [];
369
- var unconfigurableCols = [];
370
- var source = this.columns || [];
371
- source.forEach(function (column) {
372
- if (column.fixed === 'left' || column.fixed === true) {
373
- fixedLeftColumn.push(column);
374
- }
375
- else if (column.fixed === 'right') {
376
- fixedRightColumn.push(column);
377
- }
378
- else if (column.configurable === false) {
379
- unconfigurableCols.push(column);
380
- }
381
- else if (!includes(hiddenColumn, column.key)) {
382
- selectedCols.push(column);
383
- }
384
- });
385
- // 顺序应该是: 左固定列、不可配置列、排序列、右固定列
386
- return __spread(fixedLeftColumn, unconfigurableCols, (this.sortable ? this.sortCoulmns(selectedCols) : selectedCols), fixedRightColumn);
387
- };
388
- // 如果支持拖拽,在屏幕宽度大于table总的列宽的时候,添加一个空白列,宽度auto.
389
- // 空白列添加到右固定列的前面
390
- Table.prototype.transfromColumns = function (columns, needEmptyColumn) {
391
- if (!this.resizable || needEmptyColumn === false)
392
- return columns;
393
- var cols = __spread(columns);
394
- var firstFixedRightIndex = cols.findIndex(function (item) { return get(item, 'fixed') === 'right'; });
395
- var column = {
396
- title: '',
397
- dataIndex: '__empty__',
398
- key: '__empty__'
399
- };
400
- if (firstFixedRightIndex === -1) {
401
- cols.push(column);
402
- }
403
- else {
404
- cols.splice(firstFixedRightIndex, 0, column);
405
- }
406
- return cols;
407
- };
408
285
  Table.prototype.getColumns = function () {
286
+ // 注意: 如果没有传columns, 可能渲染的是table 的children ,无需在处理columns
287
+ /**
288
+ * <Table>
289
+ * <Table.Column title="name" dataIndex="name"></Table.Column>
290
+ * <Table.Column title="age" dataIndex="name"></Table.Column>
291
+ * </Table>
292
+ */
293
+ if (isUndefined(this.columns))
294
+ return this.columns;
409
295
  var _a = this.props, columnSettingOverlayClass = _a.columnSettingOverlayClass, needEmptyColumn = _a.needEmptyColumn;
410
- // 如果不显示列设置按钮,直接返回columns
296
+ // 显示列设置按钮,默认就会开启列隐藏功能
297
+ // 1、看是否支持排序, 排序 + 列隐藏, 排序用 sort 函数就行(sort 函数具有列隐藏的能力)
298
+ // 2、看是否 resize, resize + 列隐藏 可能需要添加空白列 addEmptyColumn
299
+ var allCols = __spread(this.columns);
411
300
  if (!this.showSetting) {
412
- return this.transfromColumns(this.columns, needEmptyColumn);
301
+ // 如果不显示列设置按钮, 那么排序功能不支持
302
+ if (this.resizable) {
303
+ allCols = addEmptyColumn(allCols, this.hiddenColumn, this.resizable && needEmptyColumn);
304
+ }
305
+ return allCols;
306
+ }
307
+ if (this.sortable) {
308
+ allCols = getSortedCoulmns(allCols, this.sortConfig.sortKeys || [], this.hiddenColumn || []);
413
309
  }
414
- // 获取到列设置的options
415
- var columnsSettingOptions = this.columnsSettingOptions;
416
- // 列排序或者列隐藏
417
- var allCols = this.getSortedColumns();
418
- this.transfromColumns(allCols, needEmptyColumn);
310
+ if (this.resizable) {
311
+ allCols = addEmptyColumn(allCols, this.hiddenColumn, this.resizable && needEmptyColumn);
312
+ }
313
+ // 需要添加设置按钮
419
314
  var length = allCols.length;
420
315
  if (length > 0) {
421
316
  var title = (React.createElement("span", { className: SDK_PREFIX + "-last-column-title" },
422
317
  React.createElement("span", { className: SDK_PREFIX + "-last-column-setting" },
423
- React.createElement(ColumnSetting, { options: columnsSettingOptions, hiddenKeys: this.hiddenColumn, onHiddenKeysChange: this.handleHideColumnsChange, onMove: this.setSortKeys, overlayClass: columnSettingOverlayClass }))));
318
+ React.createElement(ColumnSetting, { options: this.columnsSettingOptions, hiddenKeys: this.hiddenColumn, onHiddenKeysChange: this.handleHideColumnsChange, onMove: this.setSortKeys, overlayClass: columnSettingOverlayClass, sortable: this.sortable }))));
424
319
  allCols.push({
425
320
  title: title,
426
321
  dataIndex: '__setting__',
@@ -434,14 +329,9 @@ var Table = /** @class */ (function (_super) {
434
329
  Table.prototype.getRowKey = function (row, index) {
435
330
  var rowKey = this.props.rowKey;
436
331
  if (typeof rowKey === 'function') {
437
- return rowKey(row, index);
332
+ return rowKey(row, index).toString();
438
333
  }
439
- return rowKey ? row[rowKey] : index;
440
- };
441
- Table.prototype.sortCoulmns = function (columns) {
442
- return this.sortConfig.sortKeys
443
- .map(function (key) { return columns.find(function (column) { return column.dataIndex === key; }); })
444
- .filter(function (f) { return !!f; });
334
+ return rowKey && typeof rowKey == 'string' ? get(row, rowKey) : index;
445
335
  };
446
336
  Table.prototype.setIndeterminate = function (indeterminate) {
447
337
  this.indeterminate = indeterminate;
@@ -473,18 +363,17 @@ var Table = /** @class */ (function (_super) {
473
363
  this.settingFields = columns;
474
364
  };
475
365
  // 设置全选checkout的状态
476
- Table.prototype.setCheckboxStatus = function (selectedRowsOfCurrentPage, dataSource) {
366
+ Table.prototype.setCheckboxStatus = function (selectedRowsOfCurrentPage, dataSourceLength) {
477
367
  if (selectedRowsOfCurrentPage === void 0) { selectedRowsOfCurrentPage = []; }
478
- if (dataSource === void 0) { dataSource = []; }
479
368
  this.setIndeterminate(!!selectedRowsOfCurrentPage.length &&
480
- selectedRowsOfCurrentPage.length < size(dataSource));
369
+ selectedRowsOfCurrentPage.length < dataSourceLength);
481
370
  this.setCheckAll(!!selectedRowsOfCurrentPage.length &&
482
- selectedRowsOfCurrentPage.length === size(dataSource));
371
+ selectedRowsOfCurrentPage.length === dataSourceLength);
483
372
  };
484
373
  Table.prototype.handleSelectionChange = function (selectedRowKeys, selectedRowsOfCurrentPage, info) {
485
374
  var dataSource = this.props.dataSource;
486
375
  // 更新CheckBox状态
487
- this.setCheckboxStatus(selectedRowsOfCurrentPage, dataSource);
376
+ this.setCheckboxStatus(selectedRowsOfCurrentPage, size(dataSource));
488
377
  // 更新外部组件rowSelection状态
489
378
  this.onRowSelectionChange(selectedRowKeys, selectedRowsOfCurrentPage, info);
490
379
  };
@@ -516,9 +405,8 @@ var Table = /** @class */ (function (_super) {
516
405
  });
517
406
  };
518
407
  Table.prototype.handleBatchOptionClick = function (option) {
519
- if (option.onClick) {
520
- option.onClick(this.selectedRowKeys);
521
- }
408
+ var _a;
409
+ (_a = option.onClick) === null || _a === void 0 ? void 0 : _a.call(option, this.selectedRowKeys);
522
410
  };
523
411
  Table.prototype.getRowClassName = function (record, index, indent) {
524
412
  var rowClassName = this.props.rowClassName;
@@ -543,87 +431,56 @@ var Table = /** @class */ (function (_super) {
543
431
  return noneSelected || disabled;
544
432
  };
545
433
  Table.prototype.handleResize = function (col, size, oldColumn) {
546
- console.log('handleResize', col, size);
547
434
  var newColumns = __spread(oldColumn);
435
+ var sizeMap = {};
548
436
  newColumns.forEach(function (item) {
437
+ // 更新宽度
549
438
  if (get(item, 'dataIndex') === col.dataIndex) {
550
439
  item.width = size.width;
551
440
  }
441
+ // 更新sizeMap
442
+ if (item.dataIndex && isNumber(item.width) && !isNaN(item.width)) {
443
+ sizeMap[item.dataIndex] = item.width;
444
+ }
552
445
  });
553
- var sizeMap = {};
554
446
  var setttingFields = this.settingFields;
555
- newColumns.forEach(function (element) {
556
- if (element.dataIndex &&
557
- isNumber(element.width) &&
558
- !isNaN(element.width)) {
559
- sizeMap[element.dataIndex] = element.width;
447
+ setttingFields.forEach(function (field) {
448
+ if (sizeMap[field.field]) {
449
+ field.width = sizeMap[field.field];
560
450
  }
561
451
  });
562
452
  if (this.props.onSettingChange) {
563
- setttingFields.forEach(function (field) {
564
- if (sizeMap[field.field]) {
565
- field.width = sizeMap[field.field];
566
- }
567
- });
568
453
  this.props.onSettingChange(setttingFields);
569
454
  }
570
455
  else if (this.resizable && this.props.saveSettingKey) {
571
- setttingFields.forEach(function (field) {
572
- if (sizeMap[field.field]) {
573
- field.width = sizeMap[field.field];
574
- }
575
- });
576
456
  this.setSettingFields(setttingFields);
577
457
  }
578
458
  this.setColumns(newColumns);
579
459
  };
580
460
  Table.prototype.getResizeColumns = function (columns) {
581
- var _this = this;
582
- var fields = this.settingFields;
583
- if ((fields === null || fields === void 0 ? void 0 : fields.length) && isArray(fields)) {
584
- columns = columns === null || columns === void 0 ? void 0 : columns.map(function (col) {
585
- var _a;
586
- var dataIndex = get(col, 'dataIndex');
587
- var width = (_a = fields === null || fields === void 0 ? void 0 : fields.find(function (f) { return f.field === dataIndex; })) === null || _a === void 0 ? void 0 : _a.width;
588
- return isNumber(width) ? __assign(__assign({}, col), { width: width }) : col;
589
- });
590
- }
591
- var transformColumns = columns === null || columns === void 0 ? void 0 : columns.map(function (it, index) {
592
- if (get(it, 'resizable') && _this.resizable) {
593
- return __assign(__assign({}, it), { ellipsis: {
594
- showTitle: true
595
- }, onHeaderCell: function (col) {
596
- var _a;
597
- return ({
598
- width: col.width,
599
- // !传入newColumn,而不传入column是因为需要拿到有onHeaderCell的值,外面collumn的变化内部监听不到
600
- onResize: function (_, _a) {
601
- var size = _a.size;
602
- _this.handleResize(col, size, transformColumns);
603
- },
604
- isLastColumn: index === ((_a = (columns || [])) === null || _a === void 0 ? void 0 : _a.length) - 1
605
- });
606
- } });
607
- }
608
- return it;
609
- });
610
- return transformColumns;
461
+ return getResizeColumns(columns || [], this.settingFields, this.resizable, this.handleResize);
611
462
  };
612
463
  Table.prototype.componentDidMount = function () {
613
464
  var _a;
465
+ var _b = this.props, columns = _b.columns, saveSettingKey = _b.saveSettingKey, _c = _b.hiddenColumns, hiddenColumns = _c === void 0 ? [] : _c;
466
+ var settingFields = getLocalSettings(saveSettingKey);
614
467
  if (this.showSetting) {
615
- this.initSettingConfig();
468
+ this.updateSettingFields(columns, settingFields, hiddenColumns);
469
+ }
470
+ else {
471
+ this.setSettingFields(settingFields);
616
472
  }
617
- this.setColumns(this.resizable && ((_a = this.settingFields) === null || _a === void 0 ? void 0 : _a.length)
618
- ? this.getResizeColumns(this.props.columns)
619
- : this.props.columns);
473
+ var transformColumns = this.resizable && ((_a = this.settingFields) === null || _a === void 0 ? void 0 : _a.length)
474
+ ? this.getResizeColumns(columns)
475
+ : columns;
476
+ this.setColumns(transformColumns);
620
477
  };
621
478
  Table.prototype.render = function () {
622
479
  var _a, _b;
623
480
  var _this = this;
624
481
  var _c = this.props, className = _c.className, batchOptions = _c.batchOptions, scroll = _c.scroll, locale = _c.locale, emptyText = _c.emptyText, columns = _c.columns, components = _c.components, draggable = _c.draggable, restProps = __rest(_c, ["className", "batchOptions", "scroll", "locale", "emptyText", "columns", "components", "draggable"]);
625
482
  return (React.createElement("div", null,
626
- React.createElement(AntTable, __assign({ scroll: scroll, locale: __assign({ emptyText: this.emptyTextComp }, locale), columns: this.getColumns() }, restProps, { className: classnames(SDK_PREFIX + "-table-wrapper", (_a = {}, _a[SDK_PREFIX + "-table-scrollX"] = get(scroll, 'x'), _a), (_b = {}, _b[SDK_PREFIX + "-table-scrollY"] = get(scroll, 'y'), _b), className),
483
+ React.createElement(AntTable, __assign({ scroll: scroll, locale: __assign({ emptyText: (React.createElement(EmptyText, { locale: this.context.locale, emptyText: emptyText })) }, locale), columns: this.getColumns() }, restProps, { className: classnames(SDK_PREFIX + "-table-wrapper", (_a = {}, _a[SDK_PREFIX + "-table-scrollX"] = get(scroll, 'x'), _a), (_b = {}, _b[SDK_PREFIX + "-table-scrollY"] = get(scroll, 'y'), _b), className),
627
484
  // 涉及到权限
628
485
  // getCheckboxProps只能放到tableBatchWrapper里,因为selectedRowKeys在那个组件计算
629
486
  rowSelection: batchOptions && this.props.rowSelection
@@ -669,7 +526,7 @@ var Table = /** @class */ (function (_super) {
669
526
  ], Table.prototype, "hiddenColumn", void 0);
670
527
  __decorate([
671
528
  observable.ref,
672
- __metadata("design:type", Array)
529
+ __metadata("design:type", Object)
673
530
  ], Table.prototype, "columns", void 0);
674
531
  __decorate([
675
532
  observable.ref,
@@ -681,7 +538,7 @@ var Table = /** @class */ (function (_super) {
681
538
  ], Table.prototype, "settingFields", void 0);
682
539
  __decorate([
683
540
  computed,
684
- __metadata("design:type", Object),
541
+ __metadata("design:type", Array),
685
542
  __metadata("design:paramtypes", [])
686
543
  ], Table.prototype, "selectedRowKeys", null);
687
544
  __decorate([
@@ -699,11 +556,6 @@ var Table = /** @class */ (function (_super) {
699
556
  __metadata("design:type", Object),
700
557
  __metadata("design:paramtypes", [])
701
558
  ], Table.prototype, "keysOfCurrentPage", null);
702
- __decorate([
703
- computed,
704
- __metadata("design:type", Object),
705
- __metadata("design:paramtypes", [])
706
- ], Table.prototype, "emptyTextComp", null);
707
559
  __decorate([
708
560
  computed,
709
561
  __metadata("design:type", Object),
@@ -729,13 +581,6 @@ var Table = /** @class */ (function (_super) {
729
581
  __metadata("design:type", Object),
730
582
  __metadata("design:paramtypes", [])
731
583
  ], Table.prototype, "showSetting", null);
732
- __decorate([
733
- bind,
734
- action,
735
- __metadata("design:type", Function),
736
- __metadata("design:paramtypes", [Array]),
737
- __metadata("design:returntype", void 0)
738
- ], Table.prototype, "updateSettingConfig", null);
739
584
  __decorate([
740
585
  bind,
741
586
  action,
@@ -747,7 +592,7 @@ var Table = /** @class */ (function (_super) {
747
592
  bind,
748
593
  action,
749
594
  __metadata("design:type", Function),
750
- __metadata("design:paramtypes", [Array, Array]),
595
+ __metadata("design:paramtypes", [Array, Array, Array]),
751
596
  __metadata("design:returntype", void 0)
752
597
  ], Table.prototype, "updateSettingFields", null);
753
598
  __decorate([
@@ -756,18 +601,6 @@ var Table = /** @class */ (function (_super) {
756
601
  __metadata("design:paramtypes", [Array]),
757
602
  __metadata("design:returntype", void 0)
758
603
  ], Table.prototype, "handleHideColumnsChange", null);
759
- __decorate([
760
- bind,
761
- __metadata("design:type", Function),
762
- __metadata("design:paramtypes", []),
763
- __metadata("design:returntype", void 0)
764
- ], Table.prototype, "getSortedColumns", null);
765
- __decorate([
766
- bind,
767
- __metadata("design:type", Function),
768
- __metadata("design:paramtypes", [Array, Boolean]),
769
- __metadata("design:returntype", void 0)
770
- ], Table.prototype, "transfromColumns", null);
771
604
  __decorate([
772
605
  bind,
773
606
  __metadata("design:type", Function),
@@ -780,12 +613,6 @@ var Table = /** @class */ (function (_super) {
780
613
  __metadata("design:paramtypes", [Object, Number]),
781
614
  __metadata("design:returntype", void 0)
782
615
  ], Table.prototype, "getRowKey", null);
783
- __decorate([
784
- bind,
785
- __metadata("design:type", Function),
786
- __metadata("design:paramtypes", [Array]),
787
- __metadata("design:returntype", void 0)
788
- ], Table.prototype, "sortCoulmns", null);
789
616
  __decorate([
790
617
  bind,
791
618
  action,
@@ -811,7 +638,7 @@ var Table = /** @class */ (function (_super) {
811
638
  bind,
812
639
  action,
813
640
  __metadata("design:type", Function),
814
- __metadata("design:paramtypes", [Array]),
641
+ __metadata("design:paramtypes", [Object]),
815
642
  __metadata("design:returntype", void 0)
816
643
  ], Table.prototype, "setColumns", null);
817
644
  __decorate([
@@ -831,7 +658,7 @@ var Table = /** @class */ (function (_super) {
831
658
  __decorate([
832
659
  bind,
833
660
  __metadata("design:type", Function),
834
- __metadata("design:paramtypes", [Array, Array]),
661
+ __metadata("design:paramtypes", [Array, Number]),
835
662
  __metadata("design:returntype", void 0)
836
663
  ], Table.prototype, "setCheckboxStatus", null);
837
664
  __decorate([