amis 1.9.0-beta.12 → 1.9.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/lib/Schema.d.ts +4 -2
  2. package/lib/Schema.js.map +1 -1
  3. package/lib/SchemaRenderer.d.ts +2 -2
  4. package/lib/SchemaRenderer.js +3 -3
  5. package/lib/SchemaRenderer.js.map +2 -2
  6. package/lib/actions/Action.d.ts +8 -6
  7. package/lib/actions/Action.js.map +2 -2
  8. package/lib/actions/AjaxAction.d.ts +10 -7
  9. package/lib/actions/AjaxAction.js +27 -21
  10. package/lib/actions/AjaxAction.js.map +2 -2
  11. package/lib/actions/BreakAction.d.ts +2 -2
  12. package/lib/actions/BreakAction.js.map +1 -1
  13. package/lib/actions/BroadcastAction.d.ts +3 -3
  14. package/lib/actions/BroadcastAction.js +3 -2
  15. package/lib/actions/BroadcastAction.js.map +2 -2
  16. package/lib/actions/CmptAction.d.ts +2 -2
  17. package/lib/actions/CmptAction.js +7 -9
  18. package/lib/actions/CmptAction.js.map +2 -2
  19. package/lib/actions/ContinueAction.d.ts +2 -2
  20. package/lib/actions/ContinueAction.js.map +1 -1
  21. package/lib/actions/CopyAction.d.ts +7 -4
  22. package/lib/actions/CopyAction.js +8 -6
  23. package/lib/actions/CopyAction.js.map +2 -2
  24. package/lib/actions/CustomAction.d.ts +2 -2
  25. package/lib/actions/CustomAction.js.map +1 -1
  26. package/lib/actions/DialogAction.d.ts +14 -8
  27. package/lib/actions/DialogAction.js +6 -6
  28. package/lib/actions/DialogAction.js.map +2 -2
  29. package/lib/actions/DrawerAction.d.ts +3 -3
  30. package/lib/actions/DrawerAction.js.map +1 -1
  31. package/lib/actions/EmailAction.d.ts +10 -7
  32. package/lib/actions/EmailAction.js +4 -5
  33. package/lib/actions/EmailAction.js.map +2 -2
  34. package/lib/actions/LinkAction.d.ts +19 -11
  35. package/lib/actions/LinkAction.js +6 -5
  36. package/lib/actions/LinkAction.js.map +2 -2
  37. package/lib/actions/LoopAction.d.ts +6 -3
  38. package/lib/actions/LoopAction.js +22 -20
  39. package/lib/actions/LoopAction.js.map +2 -2
  40. package/lib/actions/PageAction.d.ts +8 -5
  41. package/lib/actions/PageAction.js +3 -2
  42. package/lib/actions/PageAction.js.map +2 -2
  43. package/lib/actions/ParallelAction.d.ts +2 -2
  44. package/lib/actions/ParallelAction.js.map +1 -1
  45. package/lib/actions/SwitchAction.d.ts +2 -2
  46. package/lib/actions/SwitchAction.js.map +1 -1
  47. package/lib/actions/ToastAction.d.ts +2 -2
  48. package/lib/actions/ToastAction.js +6 -4
  49. package/lib/actions/ToastAction.js.map +2 -2
  50. package/lib/components/Editor.d.ts +84 -84
  51. package/lib/components/InputBox.js +1 -1
  52. package/lib/components/InputBox.js.map +2 -2
  53. package/lib/components/Pagination.d.ts +1175 -0
  54. package/lib/components/Pagination.js +274 -0
  55. package/lib/components/Pagination.js.map +13 -0
  56. package/lib/components/PickerContainer.d.ts +1 -0
  57. package/lib/components/PickerContainer.js +3 -2
  58. package/lib/components/PickerContainer.js.map +2 -2
  59. package/lib/components/Rating.js +11 -9
  60. package/lib/components/Rating.js.map +2 -2
  61. package/lib/components/Select.js +3 -3
  62. package/lib/components/Select.js.map +2 -2
  63. package/lib/components/Tag.d.ts +148 -0
  64. package/lib/components/Tag.js +96 -0
  65. package/lib/components/Tag.js.map +13 -0
  66. package/lib/components/TooltipWrapper.d.ts +25 -21
  67. package/lib/components/TooltipWrapper.js +11 -1
  68. package/lib/components/TooltipWrapper.js.map +2 -2
  69. package/lib/components/TransferDropDown.d.ts +85 -84
  70. package/lib/components/TransferDropDown.js +2 -2
  71. package/lib/components/TransferDropDown.js.map +2 -2
  72. package/lib/components/Tree.d.ts +84 -84
  73. package/lib/components/formula/VariableList.d.ts +1 -0
  74. package/lib/components/formula/VariableList.js.map +2 -2
  75. package/lib/components/icons.js +2 -0
  76. package/lib/components/icons.js.map +2 -2
  77. package/lib/components/index.d.ts +4 -1
  78. package/lib/components/index.js +7 -1
  79. package/lib/components/index.js.map +2 -2
  80. package/lib/components/schema-editor/Array.d.ts +11 -0
  81. package/lib/components/schema-editor/Array.js +66 -0
  82. package/lib/components/schema-editor/Array.js.map +13 -0
  83. package/lib/components/schema-editor/Common.d.ts +29 -0
  84. package/lib/components/schema-editor/Common.js +69 -0
  85. package/lib/components/schema-editor/Common.js.map +13 -0
  86. package/lib/components/schema-editor/Item.d.ts +9 -0
  87. package/lib/components/schema-editor/Item.js +31 -0
  88. package/lib/components/schema-editor/Item.js.map +13 -0
  89. package/lib/components/schema-editor/Object.d.ts +44 -0
  90. package/lib/components/schema-editor/Object.js +191 -0
  91. package/lib/components/schema-editor/Object.js.map +13 -0
  92. package/lib/components/schema-editor/SchemaVariableList.d.ts +316 -0
  93. package/lib/components/schema-editor/SchemaVariableList.js +74 -0
  94. package/lib/components/schema-editor/SchemaVariableList.js.map +13 -0
  95. package/lib/components/schema-editor/SchemaVariableListPicker.d.ts +305 -0
  96. package/lib/components/schema-editor/SchemaVariableListPicker.js +32 -0
  97. package/lib/components/schema-editor/SchemaVariableListPicker.js.map +13 -0
  98. package/lib/components/schema-editor/index.d.ts +520 -0
  99. package/lib/components/schema-editor/index.js +118 -0
  100. package/lib/components/schema-editor/index.js.map +13 -0
  101. package/lib/components/table/Cell.d.ts +930 -0
  102. package/lib/components/table/Cell.js +36 -0
  103. package/lib/components/table/Cell.js.map +13 -0
  104. package/lib/components/table/HeadCellDropDown.d.ts +514 -0
  105. package/lib/components/table/HeadCellDropDown.js +52 -0
  106. package/lib/components/table/HeadCellDropDown.js.map +13 -0
  107. package/lib/components/table/HeadCellFilter.d.ts +771 -0
  108. package/lib/components/table/HeadCellFilter.js +106 -0
  109. package/lib/components/table/HeadCellFilter.js.map +13 -0
  110. package/lib/components/table/HeadCellSelect.d.ts +672 -0
  111. package/lib/components/table/HeadCellSelect.js +46 -0
  112. package/lib/components/table/HeadCellSelect.js.map +13 -0
  113. package/lib/components/table/HeadCellSort.d.ts +498 -0
  114. package/lib/components/table/HeadCellSort.js +67 -0
  115. package/lib/components/table/HeadCellSort.js.map +13 -0
  116. package/lib/components/table/index.d.ts +1355 -0
  117. package/lib/components/table/index.js +1095 -0
  118. package/lib/components/table/index.js.map +13 -0
  119. package/lib/env.d.ts +2 -4
  120. package/lib/env.js.map +2 -2
  121. package/lib/factory.js +0 -95
  122. package/lib/factory.js.map +2 -2
  123. package/lib/icons/dot.js +11 -0
  124. package/lib/index.d.ts +6 -1
  125. package/lib/index.js +9 -2
  126. package/lib/index.js.map +2 -2
  127. package/lib/locale/de-DE.js +18 -1
  128. package/lib/locale/de-DE.js.map +2 -2
  129. package/lib/locale/en-US.js +18 -1
  130. package/lib/locale/en-US.js.map +2 -2
  131. package/lib/locale/zh-CN.js +20 -1
  132. package/lib/locale/zh-CN.js.map +2 -2
  133. package/lib/renderers/Action.js +0 -2
  134. package/lib/renderers/Action.js.map +2 -2
  135. package/lib/renderers/Carousel.d.ts +5 -1
  136. package/lib/renderers/Carousel.js +18 -5
  137. package/lib/renderers/Carousel.js.map +2 -2
  138. package/lib/renderers/Form/ButtonGroupSelect.d.ts +2 -0
  139. package/lib/renderers/Form/ButtonGroupSelect.js +7 -0
  140. package/lib/renderers/Form/ButtonGroupSelect.js.map +2 -2
  141. package/lib/renderers/Form/Checkbox.js +3 -4
  142. package/lib/renderers/Form/Checkbox.js.map +2 -2
  143. package/lib/renderers/Form/Checkboxes.d.ts +2 -1
  144. package/lib/renderers/Form/Checkboxes.js +19 -14
  145. package/lib/renderers/Form/Checkboxes.js.map +2 -2
  146. package/lib/renderers/Form/Combo.js +23 -4
  147. package/lib/renderers/Form/Combo.js.map +2 -2
  148. package/lib/renderers/Form/DiffEditor.d.ts +126 -18
  149. package/lib/renderers/Form/Editor.d.ts +412 -112
  150. package/lib/renderers/Form/Editor.js +10 -1
  151. package/lib/renderers/Form/Editor.js.map +2 -2
  152. package/lib/renderers/Form/InputExcel.js +6 -1
  153. package/lib/renderers/Form/InputExcel.js.map +2 -2
  154. package/lib/renderers/Form/InputFile.js +1 -2
  155. package/lib/renderers/Form/InputFile.js.map +2 -2
  156. package/lib/renderers/Form/InputTree.js +1 -1
  157. package/lib/renderers/Form/InputTree.js.map +2 -2
  158. package/lib/renderers/Form/Item.d.ts +0 -6
  159. package/lib/renderers/Form/JSONSchemaEditor.d.ts +41 -0
  160. package/lib/renderers/Form/JSONSchemaEditor.js +33 -0
  161. package/lib/renderers/Form/JSONSchemaEditor.js.map +13 -0
  162. package/lib/renderers/Form/ListSelect.d.ts +2 -0
  163. package/lib/renderers/Form/ListSelect.js +7 -0
  164. package/lib/renderers/Form/ListSelect.js.map +2 -2
  165. package/lib/renderers/Form/Options.js +1 -0
  166. package/lib/renderers/Form/Options.js.map +2 -2
  167. package/lib/renderers/Form/Select.js +12 -1
  168. package/lib/renderers/Form/Select.js.map +2 -2
  169. package/lib/renderers/Form/TabsTransfer.d.ts +1 -1
  170. package/lib/renderers/Form/TabsTransfer.js +2 -2
  171. package/lib/renderers/Form/TabsTransfer.js.map +2 -2
  172. package/lib/renderers/Form/TreeSelect.d.ts +4 -0
  173. package/lib/renderers/Form/TreeSelect.js +2 -2
  174. package/lib/renderers/Form/TreeSelect.js.map +2 -2
  175. package/lib/renderers/Form/wrapControl.js +10 -5
  176. package/lib/renderers/Form/wrapControl.js.map +2 -2
  177. package/lib/renderers/Pagination.d.ts +49 -30
  178. package/lib/renderers/Pagination.js +3 -132
  179. package/lib/renderers/Pagination.js.map +2 -2
  180. package/lib/renderers/Table/HeadCellSearchDropdown.js +0 -1
  181. package/lib/renderers/Table/HeadCellSearchDropdown.js.map +2 -2
  182. package/lib/renderers/Table-v2/HeadCellSearchDropdown.d.ts +29 -0
  183. package/lib/renderers/Table-v2/HeadCellSearchDropdown.js +158 -0
  184. package/lib/renderers/Table-v2/HeadCellSearchDropdown.js.map +13 -0
  185. package/lib/renderers/Table-v2/TableCell.d.ts +6 -0
  186. package/lib/renderers/Table-v2/TableCell.js +28 -0
  187. package/lib/renderers/Table-v2/TableCell.js.map +13 -0
  188. package/lib/renderers/Table-v2/index.d.ts +256 -0
  189. package/lib/renderers/Table-v2/index.js +548 -0
  190. package/lib/renderers/Table-v2/index.js.map +13 -0
  191. package/lib/renderers/Tabs.js +1 -1
  192. package/lib/renderers/Tabs.js.map +2 -2
  193. package/lib/renderers/Tag.d.ts +66 -0
  194. package/lib/renderers/Tag.js +53 -0
  195. package/lib/renderers/Tag.js.map +13 -0
  196. package/lib/renderers/Wizard.js +3 -3
  197. package/lib/renderers/Wizard.js.map +2 -2
  198. package/lib/schemaExtend.js +24 -30
  199. package/lib/schemaExtend.js.map +2 -2
  200. package/lib/store/combo.d.ts +140 -20
  201. package/lib/store/form.d.ts +56 -8
  202. package/lib/store/formItem.d.ts +3 -1
  203. package/lib/store/formItem.js +3 -1
  204. package/lib/store/formItem.js.map +2 -2
  205. package/lib/store/index.js +2 -0
  206. package/lib/store/index.js.map +2 -2
  207. package/lib/store/table-v2.d.ts +308 -0
  208. package/lib/store/table-v2.js +452 -0
  209. package/lib/store/table-v2.js.map +13 -0
  210. package/lib/store/table.d.ts +112 -16
  211. package/lib/store/table.js +1 -1
  212. package/lib/store/table.js.map +2 -2
  213. package/lib/themes/ang-ie11.css +1686 -120
  214. package/lib/themes/ang.css +1807 -208
  215. package/lib/themes/ang.css.map +1 -1
  216. package/lib/themes/antd-ie11.css +1667 -101
  217. package/lib/themes/antd.css +1789 -201
  218. package/lib/themes/antd.css.map +1 -1
  219. package/lib/themes/cxd-ie11.css +1662 -97
  220. package/lib/themes/cxd.css +1983 -394
  221. package/lib/themes/cxd.css.map +1 -1
  222. package/lib/themes/dark-ie11.css +1667 -101
  223. package/lib/themes/dark.css +1789 -201
  224. package/lib/themes/dark.css.map +1 -1
  225. package/lib/themes/default-ie11.css +1662 -97
  226. package/lib/themes/default.css +1983 -394
  227. package/lib/themes/default.css.map +1 -1
  228. package/lib/utils/DataSchema.d.ts +25 -0
  229. package/lib/utils/DataSchema.js +104 -0
  230. package/lib/utils/DataSchema.js.map +13 -0
  231. package/lib/utils/DataScope.d.ts +23 -0
  232. package/lib/utils/DataScope.js +140 -0
  233. package/lib/utils/DataScope.js.map +13 -0
  234. package/lib/utils/handleAction.js +1 -1
  235. package/lib/utils/handleAction.js.map +2 -2
  236. package/lib/utils/renderer-event.d.ts +8 -2
  237. package/lib/utils/renderer-event.js +102 -1
  238. package/lib/utils/renderer-event.js.map +2 -2
  239. package/package.json +3 -2
  240. package/schema.json +1476 -469
  241. package/scss/_properties.scss +69 -0
  242. package/scss/components/_button.scss +37 -39
  243. package/scss/components/_context-menu.scss +3 -18
  244. package/scss/components/_json-schema-editor.scss +126 -0
  245. package/scss/components/_pagination.scss +104 -23
  246. package/scss/components/_result-box.scss +2 -2
  247. package/scss/components/_table-v2.scss +912 -0
  248. package/scss/components/_tag.scss +177 -0
  249. package/scss/components/form/_selection.scss +1 -14
  250. package/scss/components/form/_text.scss +1 -1
  251. package/scss/themes/_antd-variables.scss +0 -13
  252. package/scss/themes/_common.scss +3 -0
  253. package/scss/themes/_cxd-variables.scss +7 -17
  254. package/scss/themes/_dark-variables.scss +0 -13
  255. package/scss/themes/cxd.scss +1 -1
  256. package/sdk/ang-ie11.css +2240 -227
  257. package/sdk/ang.css +2905 -859
  258. package/sdk/antd-ie11.css +2233 -220
  259. package/sdk/antd.css +2905 -870
  260. package/sdk/barcode.js +51 -51
  261. package/sdk/charts.js +14 -14
  262. package/sdk/codemirror.js +7 -7
  263. package/sdk/color-picker.js +65 -65
  264. package/sdk/cropperjs.js +2 -2
  265. package/sdk/cxd-ie11.css +2223 -211
  266. package/sdk/cxd.css +2911 -875
  267. package/sdk/dark-ie11.css +2233 -220
  268. package/sdk/dark.css +2905 -870
  269. package/sdk/exceljs.js +1 -1
  270. package/sdk/locale/de-DE.js +18 -1
  271. package/sdk/markdown.js +69 -69
  272. package/sdk/papaparse.js +1 -1
  273. package/sdk/renderers/Form/CityDB.js +1 -1
  274. package/sdk/rest.js +16 -16
  275. package/sdk/rich-text.js +62 -62
  276. package/sdk/sdk-ie11.css +2223 -211
  277. package/sdk/sdk.css +2911 -875
  278. package/sdk/sdk.js +1326 -1270
  279. package/sdk/thirds/hls.js/hls.js +1 -1
  280. package/sdk/thirds/mpegts.js/mpegts.js +1 -1
  281. package/sdk/tinymce.js +57 -57
  282. package/src/Schema.ts +7 -0
  283. package/src/SchemaRenderer.tsx +4 -5
  284. package/src/actions/Action.ts +7 -6
  285. package/src/actions/AjaxAction.ts +33 -24
  286. package/src/actions/BreakAction.ts +2 -2
  287. package/src/actions/BroadcastAction.ts +6 -5
  288. package/src/actions/CmptAction.ts +5 -6
  289. package/src/actions/ContinueAction.ts +2 -2
  290. package/src/actions/CopyAction.ts +14 -8
  291. package/src/actions/CustomAction.ts +2 -2
  292. package/src/actions/DialogAction.ts +16 -10
  293. package/src/actions/DrawerAction.ts +3 -3
  294. package/src/actions/EmailAction.ts +12 -12
  295. package/src/actions/LinkAction.ts +34 -14
  296. package/src/actions/LoopAction.ts +13 -8
  297. package/src/actions/PageAction.ts +9 -6
  298. package/src/actions/ParallelAction.ts +2 -2
  299. package/src/actions/SwitchAction.ts +2 -2
  300. package/src/actions/ToastAction.ts +9 -5
  301. package/src/components/InputBox.tsx +1 -0
  302. package/src/components/Pagination.tsx +446 -0
  303. package/src/components/PickerContainer.tsx +8 -5
  304. package/src/components/Rating.tsx +16 -9
  305. package/src/components/Select.tsx +3 -3
  306. package/src/components/Tag.tsx +179 -0
  307. package/src/components/TooltipWrapper.tsx +14 -1
  308. package/src/components/TransferDropDown.tsx +3 -0
  309. package/src/components/formula/VariableList.tsx +1 -0
  310. package/src/components/icons.tsx +2 -0
  311. package/src/components/index.tsx +7 -1
  312. package/src/components/schema-editor/Array.tsx +95 -0
  313. package/src/components/schema-editor/Common.tsx +138 -0
  314. package/src/components/schema-editor/Item.tsx +36 -0
  315. package/src/components/schema-editor/Object.tsx +299 -0
  316. package/src/components/schema-editor/SchemaVariableList.tsx +97 -0
  317. package/src/components/schema-editor/SchemaVariableListPicker.tsx +66 -0
  318. package/src/components/schema-editor/index.tsx +211 -0
  319. package/src/components/table/Cell.tsx +70 -0
  320. package/src/components/table/HeadCellDropDown.tsx +115 -0
  321. package/src/components/table/HeadCellFilter.tsx +193 -0
  322. package/src/components/table/HeadCellSelect.tsx +86 -0
  323. package/src/components/table/HeadCellSort.tsx +102 -0
  324. package/src/components/table/index.tsx +1681 -0
  325. package/src/env.tsx +7 -14
  326. package/src/factory.tsx +3 -106
  327. package/src/icons/dot.svg +11 -0
  328. package/src/index.tsx +8 -1
  329. package/src/locale/de-DE.ts +18 -1
  330. package/src/locale/en-US.ts +18 -1
  331. package/src/locale/zh-CN.ts +20 -1
  332. package/src/renderers/Action.tsx +1 -1
  333. package/src/renderers/Carousel.tsx +21 -6
  334. package/src/renderers/Form/ButtonGroupSelect.tsx +10 -1
  335. package/src/renderers/Form/Checkbox.tsx +4 -4
  336. package/src/renderers/Form/Checkboxes.tsx +31 -25
  337. package/src/renderers/Form/Combo.tsx +20 -4
  338. package/src/renderers/Form/Editor.tsx +15 -1
  339. package/src/renderers/Form/InputExcel.tsx +6 -1
  340. package/src/renderers/Form/InputFile.tsx +1 -2
  341. package/src/renderers/Form/InputTree.tsx +1 -1
  342. package/src/renderers/Form/JSONSchemaEditor.tsx +67 -0
  343. package/src/renderers/Form/ListSelect.tsx +9 -1
  344. package/src/renderers/Form/Options.tsx +1 -1
  345. package/src/renderers/Form/Select.tsx +7 -0
  346. package/src/renderers/Form/TabsTransfer.tsx +2 -2
  347. package/src/renderers/Form/TreeSelect.tsx +8 -1
  348. package/src/renderers/Form/wrapControl.tsx +11 -5
  349. package/src/renderers/Pagination.tsx +65 -253
  350. package/src/renderers/Table/HeadCellSearchDropdown.tsx +0 -1
  351. package/src/renderers/Table-v2/HeadCellSearchDropdown.tsx +244 -0
  352. package/src/renderers/Table-v2/TableCell.tsx +19 -0
  353. package/src/renderers/Table-v2/index.tsx +1140 -0
  354. package/src/renderers/Tabs.tsx +1 -1
  355. package/src/renderers/Tag.tsx +128 -0
  356. package/src/renderers/Wizard.tsx +3 -3
  357. package/src/schemaExtend.ts +24 -28
  358. package/src/store/formItem.ts +5 -1
  359. package/src/store/index.ts +2 -0
  360. package/src/store/table-v2.ts +646 -0
  361. package/src/store/table.ts +1 -1
  362. package/src/utils/DataSchema.ts +131 -0
  363. package/src/utils/DataScope.ts +190 -0
  364. package/src/utils/handleAction.ts +1 -1
  365. package/src/utils/renderer-event.ts +113 -2
@@ -0,0 +1,1095 @@
1
+ "use strict";
2
+ /**
3
+ * @file Table
4
+ * @author fex
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Table = void 0;
8
+ var tslib_1 = require("tslib");
9
+ var react_1 = (0, tslib_1.__importDefault)(require("react"));
10
+ var react_dom_1 = require("react-dom");
11
+ var findLastIndex_1 = (0, tslib_1.__importDefault)(require("lodash/findLastIndex"));
12
+ var find_1 = (0, tslib_1.__importDefault)(require("lodash/find"));
13
+ var isEqual_1 = (0, tslib_1.__importDefault)(require("lodash/isEqual"));
14
+ var filter_1 = (0, tslib_1.__importDefault)(require("lodash/filter"));
15
+ var intersection_1 = (0, tslib_1.__importDefault)(require("lodash/intersection"));
16
+ var cloneDeep_1 = (0, tslib_1.__importDefault)(require("lodash/cloneDeep"));
17
+ var sortablejs_1 = (0, tslib_1.__importDefault)(require("sortablejs"));
18
+ var theme_1 = require("../../theme");
19
+ var locale_1 = require("../../locale");
20
+ var helper_1 = require("../../utils/helper");
21
+ var icons_1 = require("../icons");
22
+ var Checkbox_1 = (0, tslib_1.__importDefault)(require("../Checkbox"));
23
+ var Spinner_1 = (0, tslib_1.__importDefault)(require("../Spinner"));
24
+ var HeadCellSort_1 = (0, tslib_1.__importDefault)(require("./HeadCellSort"));
25
+ var HeadCellFilter_1 = (0, tslib_1.__importDefault)(require("./HeadCellFilter"));
26
+ var HeadCellSelect_1 = (0, tslib_1.__importDefault)(require("./HeadCellSelect"));
27
+ var Cell_1 = (0, tslib_1.__importDefault)(require("./Cell"));
28
+ function getMaxLevelThRowSpan(columns) {
29
+ var maxLevel = 0;
30
+ Array.isArray(columns) && columns.forEach(function (c) {
31
+ var level = getThRowSpan(c);
32
+ if (maxLevel < level) {
33
+ maxLevel = level;
34
+ }
35
+ });
36
+ return maxLevel;
37
+ }
38
+ function getThRowSpan(column) {
39
+ if (!column.children || (column.children && !column.children.length)) {
40
+ return 1;
41
+ }
42
+ return 1 + getMaxLevelThRowSpan(column.children);
43
+ }
44
+ function getThColSpan(column) {
45
+ if (!column.children || (column.children && !column.children.length)) {
46
+ return 1;
47
+ }
48
+ var childrenLength = 0;
49
+ column.children.forEach(function (item) { return childrenLength += getThColSpan(item); });
50
+ return childrenLength;
51
+ }
52
+ function buildColumns(columns, thColumns, tdColumns, depth, id, fixed) {
53
+ if (columns === void 0) { columns = []; }
54
+ if (tdColumns === void 0) { tdColumns = []; }
55
+ if (depth === void 0) { depth = 0; }
56
+ var maxLevel = getMaxLevelThRowSpan(columns);
57
+ // 在处理表头时,如果父级column设置了fixed属性,那么所有children保持一致
58
+ Array.isArray(columns) && columns.forEach(function (column) {
59
+ var groupId = id || (0, helper_1.guid)();
60
+ var childMaxLevel = 0;
61
+ if (column.children) {
62
+ childMaxLevel = getMaxLevelThRowSpan(column.children);
63
+ }
64
+ var newColumn = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, column), { rowSpan: childMaxLevel ? 1 : maxLevel - childMaxLevel + depth, colSpan: getThColSpan(column), groupId: groupId, depth: depth });
65
+ var tdColumn = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, column), { groupId: groupId });
66
+ if (fixed) {
67
+ newColumn.fixed = fixed;
68
+ tdColumn.fixed = fixed;
69
+ }
70
+ if (!thColumns[depth]) {
71
+ thColumns[depth] = [];
72
+ }
73
+ thColumns[depth].push(newColumn);
74
+ if (column.children && column.children.length > 0) {
75
+ buildColumns(column.children, thColumns, tdColumns, depth + 1, groupId, column.fixed);
76
+ }
77
+ else {
78
+ var children = tdColumn.children, rest = (0, tslib_1.__rest)(tdColumn, ["children"]);
79
+ tdColumns.push(rest);
80
+ }
81
+ });
82
+ }
83
+ function isFixedLeftColumn(fixed) {
84
+ return fixed === true || fixed === 'left';
85
+ }
86
+ function isFixedRightColumn(fixed) {
87
+ return fixed === 'right';
88
+ }
89
+ function getPreviousLeftWidth(doms, index, columns) {
90
+ var width = 0;
91
+ for (var i = 0; i < index; i++) {
92
+ if (columns && columns[i] && isFixedLeftColumn(columns[i].fixed)) {
93
+ var dom = doms[i];
94
+ width += dom.offsetWidth;
95
+ }
96
+ }
97
+ return width;
98
+ }
99
+ function getAfterRightWidth(doms, index, columns) {
100
+ var width = 0;
101
+ for (var i = doms.length - 0; i > index; i--) {
102
+ if (columns && columns[i] && isFixedRightColumn(columns[i].fixed)) {
103
+ var dom = doms[i];
104
+ width += dom.offsetWidth;
105
+ }
106
+ }
107
+ return width;
108
+ }
109
+ function hasFixedColumn(columns) {
110
+ return (0, find_1.default)(columns, function (column) { return column.fixed; });
111
+ }
112
+ function getSummaryColumns(summary) {
113
+ if (!summary) {
114
+ return [];
115
+ }
116
+ var last = [];
117
+ var first = [];
118
+ summary.forEach(function (item) {
119
+ if ((0, helper_1.isObject)(item)) {
120
+ first.push(item);
121
+ }
122
+ else if (Array.isArray(item)) {
123
+ last.push(item);
124
+ }
125
+ });
126
+ return (0, tslib_1.__spreadArray)([first], last, true);
127
+ }
128
+ var DefaultCellWidth = 40;
129
+ var Table = /** @class */ (function (_super) {
130
+ (0, tslib_1.__extends)(Table, _super);
131
+ function Table(props) {
132
+ var _a;
133
+ var _this = _super.call(this, props) || this;
134
+ _this.tableDom = react_1.default.createRef();
135
+ _this.theadDom = react_1.default.createRef();
136
+ _this.tbodyDom = react_1.default.createRef();
137
+ _this.contentDom = react_1.default.createRef();
138
+ _this.headerDom = react_1.default.createRef();
139
+ _this.bodyDom = react_1.default.createRef();
140
+ _this.tfootDom = react_1.default.createRef();
141
+ _this.footDom = react_1.default.createRef();
142
+ _this.selectedRows = props.rowSelection
143
+ ? _this.getSelectedRows(props.dataSource, (_a = props.rowSelection) === null || _a === void 0 ? void 0 : _a.selectedRowKeys)
144
+ : [];
145
+ _this.state = {
146
+ selectedRowKeys: props.rowSelection
147
+ ? (props.rowSelection.selectedRowKeys.map(function (key) { return key; }) || []) : [],
148
+ dataSource: props.dataSource || [],
149
+ expandedRowKeys: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (props.expandable ? (props.expandable.expandedRowKeys || []) : []), true), props.expandable ? (props.expandable.defaultExpandedRowKeys || []) : [], true),
150
+ colWidths: []
151
+ };
152
+ _this.onTableContentScroll = _this.onTableContentScroll.bind(_this);
153
+ _this.getPopOverContainer = _this.getPopOverContainer.bind(_this);
154
+ return _this;
155
+ }
156
+ Table.prototype.getPopOverContainer = function () {
157
+ return (0, react_dom_1.findDOMNode)(this);
158
+ };
159
+ Table.prototype.getColWidths = function () {
160
+ var _a, _b;
161
+ var childrens = ((_b = (_a = this.tbodyDom.current) === null || _a === void 0 ? void 0 : _a.children[0]) === null || _b === void 0 ? void 0 : _b.children) || [];
162
+ var colWidths = new Array(childrens ? childrens.length : 0);
163
+ for (var i = 0; i < childrens.length; i++) {
164
+ var child = childrens[i];
165
+ colWidths[i] = child ? child.offsetWidth : null;
166
+ }
167
+ ;
168
+ return colWidths;
169
+ };
170
+ Table.prototype.getSelectedRows = function (dataSource, selectedRowKeys) {
171
+ var _this = this;
172
+ var selectedRows = [];
173
+ dataSource.forEach(function (data) {
174
+ if ((0, find_1.default)(selectedRowKeys, function (key) { return key === data[_this.getRowSelectionKeyField()]; })) {
175
+ selectedRows.push(data);
176
+ }
177
+ });
178
+ return selectedRows;
179
+ };
180
+ Table.prototype.updateTableBodyFixed = function () {
181
+ var tbodyDom = this.tbodyDom && this.tbodyDom.current;
182
+ var tdColumns = (0, tslib_1.__spreadArray)([], this.tdColumns, true);
183
+ this.updateTbodyFixedRow(tbodyDom, tdColumns);
184
+ this.updateHeadSummaryFixedRow(tbodyDom);
185
+ };
186
+ Table.prototype.updateColWidths = function () {
187
+ var _this = this;
188
+ this.setState({ colWidths: this.getColWidths() }, function () {
189
+ if (hasFixedColumn(_this.props.columns)) {
190
+ var theadDom = _this.theadDom && _this.theadDom.current;
191
+ var thColumns = _this.thColumns;
192
+ _this.updateTheadFixedRow(theadDom, thColumns);
193
+ _this.updateTableBodyFixed();
194
+ }
195
+ });
196
+ };
197
+ Table.prototype.componentDidMount = function () {
198
+ var _this = this;
199
+ var _a, _b;
200
+ if (this.props.loading) {
201
+ return;
202
+ }
203
+ if (hasFixedColumn(this.props.columns)) {
204
+ var headerDom = this.headerDom && this.headerDom.current;
205
+ if (headerDom) {
206
+ var headerBody = headerDom.getElementsByTagName('tbody');
207
+ headerBody && headerBody[0] && this.updateHeadSummaryFixedRow(headerBody[0]);
208
+ }
209
+ var tfootDom = this.tfootDom && this.tfootDom.current;
210
+ tfootDom && this.updateFootSummaryFixedRow(tfootDom);
211
+ }
212
+ var current = null;
213
+ if (this.contentDom && this.contentDom.current) {
214
+ current = this.contentDom.current;
215
+ current.addEventListener('scroll', this.onTableContentScroll.bind(this));
216
+ }
217
+ else {
218
+ current = (_a = this.headerDom) === null || _a === void 0 ? void 0 : _a.current;
219
+ // overflow设置为hidden的情况
220
+ var hiddenDomRefs = [this.headerDom, this.footDom];
221
+ hiddenDomRefs.forEach(function (ref) {
222
+ return ref && ref.current
223
+ && ref.current.addEventListener('wheel', _this.onWheel.bind(_this));
224
+ });
225
+ // 横向同步滚动
226
+ var scrollDomRefs = [this.bodyDom];
227
+ scrollDomRefs.forEach(function (ref) {
228
+ return ref && ref.current
229
+ && ref.current.addEventListener('scroll', _this.onTableScroll.bind(_this));
230
+ });
231
+ }
232
+ current && this.updateTableDom(current);
233
+ if (this.props.draggable) {
234
+ this.initDragging();
235
+ }
236
+ if (this.props.resizable) {
237
+ (_b = this.theadDom.current) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseup', this.onResizeMouseUp.bind(this));
238
+ }
239
+ this.updateStickyHeader();
240
+ this.updateColWidths();
241
+ };
242
+ Table.prototype.componentDidUpdate = function (prevProps, prevState) {
243
+ var _this = this;
244
+ var _a, _b, _c, _d;
245
+ // 数据源发生了变化
246
+ if (!(0, isEqual_1.default)(prevProps.dataSource, this.props.dataSource)) {
247
+ this.setState({ dataSource: (0, tslib_1.__spreadArray)([], this.props.dataSource, true) }, function () { return _this.updateColWidths(); }); // 异步加载数据需求再更新一次
248
+ }
249
+ // 选择项发生了变化触发
250
+ if (!(0, isEqual_1.default)(prevState.selectedRowKeys, this.state.selectedRowKeys)) {
251
+ // 更新保存的已选择行数据
252
+ this.selectedRows = this.getSelectedRows(this.state.dataSource, this.state.selectedRowKeys);
253
+ var rowSelection = this.props.rowSelection;
254
+ rowSelection && rowSelection.onChange
255
+ && rowSelection.onChange(this.state.selectedRowKeys, this.selectedRows);
256
+ this.setState({ selectedRowKeys: this.state.selectedRowKeys.filter(function (key, i, a) { return a.indexOf(key) === i; }) });
257
+ }
258
+ // 外部传入的选择项发生了变化
259
+ if (!(0, isEqual_1.default)((_a = prevProps.rowSelection) === null || _a === void 0 ? void 0 : _a.selectedRowKeys, (_b = this.props.rowSelection) === null || _b === void 0 ? void 0 : _b.selectedRowKeys)) {
260
+ if (this.props.rowSelection) {
261
+ this.setState({ selectedRowKeys: this.props.rowSelection.selectedRowKeys });
262
+ this.selectedRows = this.getSelectedRows(this.state.dataSource, this.state.selectedRowKeys);
263
+ }
264
+ }
265
+ // 外部传入的展开项发生了变化
266
+ if (!(0, isEqual_1.default)((_c = prevProps === null || prevProps === void 0 ? void 0 : prevProps.expandable) === null || _c === void 0 ? void 0 : _c.expandedRowKeys, (_d = this.props.expandable) === null || _d === void 0 ? void 0 : _d.expandedRowKeys)) {
267
+ if (this.props.expandable) {
268
+ this.setState({ expandedRowKeys: this.props.expandable.expandedRowKeys || [] });
269
+ }
270
+ }
271
+ // 展开行变化时触发
272
+ if (!(0, isEqual_1.default)(prevState.expandedRowKeys, this.state.expandedRowKeys)) {
273
+ if (this.props.expandable) {
274
+ var _e = this.props.expandable, onExpandedRowsChange = _e.onExpandedRowsChange, keyField_1 = _e.keyField;
275
+ var expandedRows_1 = [];
276
+ this.state.dataSource.forEach(function (item) {
277
+ if ((0, find_1.default)(_this.state.expandedRowKeys, function (key) { return key == item[keyField_1 || 'key']; })) {
278
+ expandedRows_1.push(item);
279
+ }
280
+ });
281
+ onExpandedRowsChange && onExpandedRowsChange(expandedRows_1);
282
+ }
283
+ }
284
+ // sticky属性发生了变化
285
+ if (prevProps.sticky !== this.props.sticky) {
286
+ this.updateStickyHeader();
287
+ }
288
+ };
289
+ Table.prototype.componentWillUnmount = function () {
290
+ var _this = this;
291
+ this.contentDom && this.contentDom.current
292
+ && this.contentDom.current.removeEventListener('scroll', this.onTableContentScroll.bind(this));
293
+ var hiddenDomRefs = [this.headerDom, this.footDom];
294
+ hiddenDomRefs.forEach(function (ref) {
295
+ return ref && ref.current
296
+ && ref.current.removeEventListener('wheel', _this.onWheel.bind(_this));
297
+ });
298
+ var scrollDomRefs = [this.bodyDom];
299
+ scrollDomRefs.forEach(function (ref) {
300
+ return ref && ref.current
301
+ && ref.current.removeEventListener('scroll', _this.onTableScroll.bind(_this));
302
+ });
303
+ this.destroyDragging();
304
+ };
305
+ Table.prototype.exchange = function (fromIndex, toIndex, item) {
306
+ var _a = this.props, scroll = _a.scroll, headSummary = _a.headSummary, onDrag = _a.onDrag;
307
+ // 如果有头部总结行 fromIndex就会+1
308
+ if ((!scroll || scroll && !scroll.y) && headSummary) {
309
+ fromIndex = fromIndex - 1;
310
+ }
311
+ var index = toIndex - fromIndex;
312
+ var levels = item.getAttribute('row-levels');
313
+ var rowIndex = +item.getAttribute('row-index');
314
+ var dataSource = (0, cloneDeep_1.default)(this.state.dataSource);
315
+ var levelsArray = levels ? levels.split(',') : [];
316
+ var childrenColumnName = this.getChildrenColumnName();
317
+ var data = dataSource;
318
+ var i = 0;
319
+ while (i < levelsArray.length) {
320
+ data = data[levelsArray[i]][childrenColumnName];
321
+ i++;
322
+ }
323
+ if (data && data.length > 0) {
324
+ var row = (0, cloneDeep_1.default)(data[rowIndex]);
325
+ data.splice(rowIndex, 1);
326
+ data.splice(rowIndex + index, 0, row);
327
+ }
328
+ // 先通过事件把最新的排序数据提供出去
329
+ // Sortable修改了dom 数据排序后再通过state更新 会有问题
330
+ onDrag && onDrag(dataSource);
331
+ };
332
+ Table.prototype.initDragging = function () {
333
+ var _this = this;
334
+ var cx = this.props.classnames;
335
+ this.sortable = new sortablejs_1.default(this.tbodyDom.current, {
336
+ group: 'table',
337
+ animation: 150,
338
+ handle: ".".concat(cx('Table-dragCell')),
339
+ ghostClass: 'is-dragging',
340
+ onMove: function (e) {
341
+ var dragged = e.dragged;
342
+ var related = e.related;
343
+ if (related && related.classList.contains("".concat(cx('Table-summary-row')))) {
344
+ return false;
345
+ }
346
+ var draggedLevels = dragged.getAttribute('row-levels');
347
+ var relatedLevels = related.getAttribute('row-levels');
348
+ // 嵌套展示 不属于同一层的 不允许拖动
349
+ // 否则涉及到试图的更新,比如子元素都被拖完了
350
+ if (draggedLevels !== relatedLevels) {
351
+ return false;
352
+ }
353
+ return true;
354
+ },
355
+ onEnd: function (e) {
356
+ // 没有移动
357
+ if (e.newIndex === e.oldIndex) {
358
+ return;
359
+ }
360
+ _this.exchange(e.oldIndex, e.newIndex, e.item);
361
+ }
362
+ });
363
+ };
364
+ Table.prototype.destroyDragging = function () {
365
+ this.sortable && this.sortable.destroy();
366
+ };
367
+ Table.prototype.updateStickyHeader = function () {
368
+ var _this = this;
369
+ var _a, _b;
370
+ if (this.props.sticky) {
371
+ // 如果设置了sticky 如果父元素设置了overflow: auto top值还需要考虑padding值
372
+ var parent_1 = (_b = (_a = this.headerDom) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.parentElement;
373
+ setTimeout(function () {
374
+ while (parent_1 && window.getComputedStyle(parent_1, null).getPropertyValue('overflow') !== 'auto') {
375
+ parent_1 = parent_1.parentElement;
376
+ }
377
+ if (parent_1 && window.getComputedStyle(parent_1, null).getPropertyValue('overflow') === 'auto') {
378
+ var paddingTop = window.getComputedStyle(parent_1, null).getPropertyValue('padding-top');
379
+ if (paddingTop && _this.headerDom && _this.headerDom.current) {
380
+ _this.headerDom.current.style.top = '-' + paddingTop;
381
+ }
382
+ }
383
+ });
384
+ }
385
+ };
386
+ // 更新一个tr下的td的left和class
387
+ Table.prototype.updateFixedRow = function (row, columns) {
388
+ var _a, _b, _c;
389
+ var cx = this.props.classnames;
390
+ var children = row.children;
391
+ for (var i = 0; i < children.length; i++) {
392
+ var dom = children[i];
393
+ var fixed = columns[i] ? (columns[i].fixed || '') : '';
394
+ if (isFixedLeftColumn(fixed)) {
395
+ dom.style.left = i > 0 ? getPreviousLeftWidth(children, i, columns) + 'px' : '0';
396
+ }
397
+ else if (isFixedRightColumn(fixed)) {
398
+ dom.style.right = i < children.length - 1
399
+ ? getAfterRightWidth(children, i, columns) + 'px' : '0';
400
+ }
401
+ }
402
+ // 最后一个左fixed的添加样式
403
+ var leftIndex = (0, findLastIndex_1.default)(columns, function (column) { return isFixedLeftColumn(column.fixed); });
404
+ if (leftIndex > -1) {
405
+ (_a = children[leftIndex]) === null || _a === void 0 ? void 0 : _a.classList.add(cx('Table-cell-fix-left-last'));
406
+ }
407
+ // 第一个右fixed的添加样式
408
+ var rightIndex = columns.findIndex(function (column) { return isFixedRightColumn(column.fixed); });
409
+ if (rightIndex > -1) {
410
+ (_b = children[rightIndex]) === null || _b === void 0 ? void 0 : _b.classList.add(cx('Table-cell-fix-right-first'));
411
+ if (rightIndex > 0) {
412
+ (_c = children[rightIndex - 1]) === null || _c === void 0 ? void 0 : _c.classList.add(cx('Table-cell-fix-right-first-prev'));
413
+ }
414
+ }
415
+ };
416
+ // 在可选、可展开、可拖拽的情况下,补充column,方便fix处理
417
+ Table.prototype.prependColumns = function (columns) {
418
+ var _a = this.props, rowSelection = _a.rowSelection, expandable = _a.expandable, draggable = _a.draggable;
419
+ if (draggable) {
420
+ columns.unshift({});
421
+ }
422
+ else {
423
+ if (expandable) {
424
+ columns.unshift(expandable);
425
+ }
426
+ if (rowSelection) {
427
+ columns.unshift(rowSelection);
428
+ }
429
+ }
430
+ };
431
+ Table.prototype.updateTheadFixedRow = function (thead, columns) {
432
+ var children = thead.children;
433
+ for (var i = 0; i < children.length; i++) {
434
+ var cols = (0, tslib_1.__spreadArray)([], columns[i], true);
435
+ if (i === 0) {
436
+ this.prependColumns(cols);
437
+ }
438
+ this.updateFixedRow(children[i], cols);
439
+ }
440
+ };
441
+ Table.prototype.updateTbodyFixedRow = function (tbody, columns) {
442
+ var cx = this.props.classnames;
443
+ var children = (0, filter_1.default)(tbody.children, function (child) { return !child.classList.contains(cx('Table-summary-row'))
444
+ && !child.classList.contains(cx('Table-empty-row')); });
445
+ this.prependColumns(columns);
446
+ for (var i = 0; i < children.length; i++) {
447
+ this.updateFixedRow(children[i], columns);
448
+ }
449
+ };
450
+ Table.prototype.updateSummaryFixedRow = function (children, columns) {
451
+ for (var i = 0; i < children.length; i++) {
452
+ this.updateFixedRow(children[i], columns[i]);
453
+ }
454
+ };
455
+ Table.prototype.updateFootSummaryFixedRow = function (tfoot) {
456
+ var footSummary = this.props.footSummary;
457
+ if (Array.isArray(footSummary)) {
458
+ var columns = getSummaryColumns(footSummary);
459
+ this.updateSummaryFixedRow(tfoot.children, columns);
460
+ }
461
+ };
462
+ Table.prototype.updateHeadSummaryFixedRow = function (tbody) {
463
+ var _a = this.props, headSummary = _a.headSummary, cx = _a.classnames;
464
+ if (Array.isArray(headSummary)) {
465
+ var columns = getSummaryColumns(headSummary);
466
+ var children = (0, filter_1.default)(tbody.children, function (child) { return child.classList.contains(cx('Table-summary-row')); });
467
+ this.updateSummaryFixedRow(children, columns);
468
+ }
469
+ };
470
+ Table.prototype.renderColGroup = function (colWidths) {
471
+ var _a = this.props, rowSelection = _a.rowSelection, cx = _a.classnames, expandable = _a.expandable, draggable = _a.draggable;
472
+ var tdColumns = this.tdColumns;
473
+ var isExpandable = this.isExpandableTable();
474
+ var extraCount = this.getExtraColumnCount();
475
+ return (react_1.default.createElement("colgroup", null,
476
+ draggable
477
+ ? react_1.default.createElement("col", { className: cx('Table-drag-col'), style: { width: DefaultCellWidth + 'px' } }) : null,
478
+ !draggable && rowSelection
479
+ ? react_1.default.createElement("col", { className: cx('Table-selection-col'), style: { width: (rowSelection.columnWidth || DefaultCellWidth) + 'px' } }) : null,
480
+ !draggable && isExpandable ? react_1.default.createElement("col", { className: cx('Table-expand-col'), style: { width: ((expandable === null || expandable === void 0 ? void 0 : expandable.columnWidth) || DefaultCellWidth) + 'px' } }) : null,
481
+ tdColumns.map(function (data, index) {
482
+ var width = colWidths ? colWidths[index + extraCount] : data.width;
483
+ return react_1.default.createElement("col", { key: index, style: { width: typeof width === 'number' ? width + 'px' : width }, className: data.className ? cx("Table-colgroup-".concat(data.className)) : '' });
484
+ })));
485
+ };
486
+ Table.prototype.onResizeMouseDown = function (event, key) {
487
+ // 点击记录起始坐标
488
+ this.resizeStart = event.clientX;
489
+ // 记录点击的列名
490
+ this.resizeKey = key;
491
+ event && event.stopPropagation();
492
+ };
493
+ Table.prototype.onResizeMouseUp = function (event) {
494
+ var _this = this;
495
+ var _a;
496
+ // 点击了调整列宽
497
+ if (this.resizeStart && this.resizeKey) {
498
+ // 计算横向移动距离
499
+ var distance = event.clientX - this.resizeStart;
500
+ var tdColumns = (0, tslib_1.__spreadArray)([], this.tdColumns, true);
501
+ var index = tdColumns.findIndex(function (c) { return c.key === _this.resizeKey; })
502
+ + this.getExtraColumnCount();
503
+ var colGroup = (_a = this.tableDom.current) === null || _a === void 0 ? void 0 : _a.getElementsByTagName('colgroup')[0];
504
+ var currentWidth = 0;
505
+ if (colGroup && colGroup.children[index]) {
506
+ var child = colGroup.children[index];
507
+ currentWidth = child.offsetWidth;
508
+ }
509
+ var newWidth = 0;
510
+ if (colGroup) {
511
+ var maxDistance = 0; // 最多可以移动的距离
512
+ // 调宽列
513
+ if (distance > 0) {
514
+ for (var i = 0; i < colGroup.children.length; i++) {
515
+ var child = colGroup.children[i];
516
+ // 自适应列 保证有一个最小宽度
517
+ // 如果都设置了固定宽度 那一个都拖不动
518
+ if (!this.tdColumns[i].width) {
519
+ maxDistance += child.offsetWidth - DefaultCellWidth;
520
+ }
521
+ }
522
+ if (colGroup.children[index]) {
523
+ var child = colGroup.children[index];
524
+ newWidth = currentWidth + Math.min(distance, maxDistance);
525
+ child.style.width = newWidth + 'px';
526
+ }
527
+ }
528
+ else { // 缩短列
529
+ var autoColumns = [];
530
+ for (var i = 0; i < colGroup.children.length; i++) {
531
+ var child = colGroup.children[i];
532
+ // 自适应列 保证有一个最小宽度
533
+ // 如果都设置了固定宽度 那一个都拖不动
534
+ if (!this.tdColumns[i].width) {
535
+ autoColumns.push(child);
536
+ }
537
+ }
538
+ maxDistance = DefaultCellWidth - currentWidth;
539
+ if (colGroup.children[index]) {
540
+ var child = colGroup.children[index];
541
+ newWidth = currentWidth + Math.max(distance, maxDistance);
542
+ child.style.width = newWidth + 'px';
543
+ }
544
+ var gap_1 = Math.abs(Math.max(distance, maxDistance)) / autoColumns.length;
545
+ autoColumns.forEach(function (c) {
546
+ c.style.width = c.offsetWidth + gap_1 + 'px';
547
+ });
548
+ }
549
+ }
550
+ var column = (0, find_1.default)(tdColumns, function (c) { return c.key === _this.resizeKey; });
551
+ // 只有通过配置设置过的宽度保存到tdColumns
552
+ // 自动分配的不保存
553
+ // 这样可以一直调整了
554
+ if (column && column.width && newWidth) {
555
+ column.width = newWidth;
556
+ }
557
+ this.tdColumns = tdColumns;
558
+ this.resizeStart = 0;
559
+ this.resizeKey = '';
560
+ }
561
+ event && event.stopPropagation();
562
+ };
563
+ Table.prototype.renderTHead = function () {
564
+ var _this = this;
565
+ var _a = this.props, rowSelection = _a.rowSelection, dataSource = _a.dataSource, cx = _a.classnames, onSort = _a.onSort, expandable = _a.expandable, draggable = _a.draggable, resizable = _a.resizable;
566
+ var thColumns = this.thColumns;
567
+ // 获取一行最多th个数
568
+ var maxCount = 0;
569
+ thColumns.forEach(function (columns) {
570
+ if (columns.length > maxCount) {
571
+ maxCount = columns.length;
572
+ }
573
+ });
574
+ var keyField = this.getRowSelectionKeyField();
575
+ var dataList = rowSelection && rowSelection.getCheckboxProps
576
+ ? this.state.dataSource.filter(function (data, index) {
577
+ var props = rowSelection.getCheckboxProps(data, index);
578
+ return !props.disabled;
579
+ }) : this.state.dataSource;
580
+ var isExpandable = this.isExpandableTable();
581
+ var allRowKeys = [];
582
+ var allRows = [];
583
+ dataList.forEach(function (data) {
584
+ allRowKeys.push(data[keyField]);
585
+ allRows.push(data);
586
+ if (!expandable && _this.hasChildrenRow(data)) {
587
+ allRowKeys = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], allRowKeys, true), _this.getDataChildrenKeys(data), true);
588
+ data[_this.getChildrenColumnName()].forEach(function (item) { return allRows.push(item); });
589
+ }
590
+ });
591
+ return (react_1.default.createElement("thead", { ref: this.theadDom, className: cx('Table-thead') }, thColumns.map(function (data, index) {
592
+ return react_1.default.createElement("tr", { key: 'th-cell-' + index },
593
+ draggable && index === 0 ? react_1.default.createElement(Cell_1.default, { wrapperComponent: "th", rowSpan: thColumns.length, className: cx('Table-dragCell') }) : null,
594
+ !draggable && rowSelection && index === 0
595
+ ? react_1.default.createElement(Cell_1.default, { wrapperComponent: "th", rowSpan: thColumns.length, fixed: rowSelection.fixed ? 'left' : '', className: cx('Table-checkCell') }, rowSelection.type !== 'radio'
596
+ ? [react_1.default.createElement(Checkbox_1.default, { key: "checkAll", partial: _this.state.selectedRowKeys.length > 0
597
+ && _this.state.selectedRowKeys.length < allRowKeys.length, checked: _this.state.selectedRowKeys.length > 0, onChange: function (value) {
598
+ var changeRows;
599
+ if (value) {
600
+ changeRows = dataList.filter(function (data) { return !_this.hasCheckedRows(data); });
601
+ }
602
+ else {
603
+ changeRows = _this.selectedRows;
604
+ }
605
+ var selectedRows = value ? allRows : [];
606
+ _this.setState({
607
+ selectedRowKeys: value ? allRowKeys : []
608
+ });
609
+ rowSelection.onSelectAll
610
+ && rowSelection.onSelectAll(value, selectedRows, changeRows);
611
+ } }), rowSelection.selections && rowSelection.selections.length > 0
612
+ ? react_1.default.createElement(HeadCellSelect_1.default, { key: "checkSelection", keys: allRowKeys, selections: rowSelection.selections, popOverContainer: _this.getPopOverContainer }) : null] : null) : null,
613
+ !draggable && isExpandable && index === 0
614
+ ? react_1.default.createElement(Cell_1.default, { wrapperComponent: "th", rowSpan: thColumns.length, fixed: expandable && expandable.fixed ? 'left' : '', className: cx('Table-row-expand-icon-cell') }) : null,
615
+ data.map(function (item, i) {
616
+ var sort = null;
617
+ if (item.sorter) {
618
+ sort = (react_1.default.createElement(HeadCellSort_1.default, { column: item, onSort: onSort ? onSort : function (payload) {
619
+ if (typeof item.sorter === 'function') {
620
+ if (payload.orderBy) {
621
+ var sortList = (0, tslib_1.__spreadArray)([], _this.state.dataSource, true);
622
+ _this.setState({ dataSource: sortList.sort(item.sorter) });
623
+ }
624
+ else {
625
+ _this.setState({ dataSource: (0, tslib_1.__spreadArray)([], dataSource, true) });
626
+ }
627
+ }
628
+ } }));
629
+ }
630
+ var filter = null;
631
+ if (item.filterDropdown) {
632
+ filter = item.filterDropdown;
633
+ }
634
+ else if (item.filters && item.filters.length > 0) {
635
+ filter = (react_1.default.createElement(HeadCellFilter_1.default, { column: item, popOverContainer: _this.getPopOverContainer }));
636
+ }
637
+ var children = react_1.default.createElement("span", null,
638
+ sort,
639
+ filter,
640
+ resizable ? react_1.default.createElement("i", { className: cx('Table-thead-resizable'), onMouseDown: function (e) { return _this.onResizeMouseDown(e, item.key); } }) : null);
641
+ return react_1.default.createElement(Cell_1.default, { wrapperComponent: "th", rowSpan: item.rowSpan, colSpan: item.colSpan, key: 'cell' + (item.key || i), fixed: item.fixed === true ? 'left' : item.fixed, className: cx({
642
+ 'Table-cell-last': i === maxCount - 1 && i === data.length - 1
643
+ }), groupId: item.groupId, depth: item.depth }, typeof item.title === 'function' ? item.title(children) : item.title);
644
+ }));
645
+ })));
646
+ };
647
+ Table.prototype.onRowClick = function (event, record, rowIndex) {
648
+ var _a = this.props, rowSelection = _a.rowSelection, onRow = _a.onRow;
649
+ if (rowSelection && rowSelection.type && rowSelection.rowClick) {
650
+ var defaultKey_1 = this.getRowSelectionKeyField();
651
+ var isSelected = !!(0, find_1.default)(this.state.selectedRowKeys, function (key) { return key === record[defaultKey_1]; });
652
+ this.selectedSingleRow(!isSelected, record);
653
+ }
654
+ if (record && onRow) {
655
+ onRow.onRowClick && onRow.onRowClick(event, record, rowIndex);
656
+ }
657
+ };
658
+ Table.prototype.onRowMouseEnter = function (event, record, rowIndex) {
659
+ var _a = this.props, cx = _a.classnames, onRow = _a.onRow;
660
+ var parent = event.target;
661
+ while (parent && parent.tagName !== 'TR') {
662
+ parent = parent.parentElement;
663
+ }
664
+ if (parent && !parent.classList.contains(cx('Table-row-disabled'))) {
665
+ for (var i = 0; i < parent.children.length; i++) {
666
+ var td = parent.children[i];
667
+ td.classList.add(cx('Table-cell-row-hover')); // 保证有列fixed的时候样式一致
668
+ }
669
+ }
670
+ if (record && onRow) {
671
+ onRow.onRowMouseEnter && onRow.onRowMouseEnter(event, record, rowIndex);
672
+ }
673
+ };
674
+ Table.prototype.onRowMouseLeave = function (event, record, rowIndex) {
675
+ var _a = this.props, cx = _a.classnames, onRow = _a.onRow;
676
+ var parent = event.target;
677
+ while (parent && parent.tagName !== 'TR') {
678
+ parent = parent.parentElement;
679
+ }
680
+ if (parent) {
681
+ for (var i = 0; i < parent.children.length; i++) {
682
+ var td = parent.children[i];
683
+ td.classList.remove(cx('Table-cell-row-hover'));
684
+ }
685
+ }
686
+ if (record && onRow) {
687
+ onRow.onRowMouseLeave && onRow.onRowMouseLeave(event, record, rowIndex);
688
+ }
689
+ };
690
+ Table.prototype.onExpandRow = function (data) {
691
+ var expandedRowKeys = this.state.expandedRowKeys;
692
+ var expandable = this.props.expandable;
693
+ var key = data[this.getExpandableKeyField()];
694
+ this.setState({ expandedRowKeys: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], expandedRowKeys, true), [key], false) });
695
+ (expandable === null || expandable === void 0 ? void 0 : expandable.onExpand) && (expandable === null || expandable === void 0 ? void 0 : expandable.onExpand(true, data));
696
+ };
697
+ Table.prototype.onCollapseRow = function (data) {
698
+ var expandedRowKeys = this.state.expandedRowKeys;
699
+ var expandable = this.props.expandable;
700
+ var key = data[this.getExpandableKeyField()];
701
+ // 还是得模糊匹配 否则'3'、3匹配不上
702
+ this.setState({ expandedRowKeys: expandedRowKeys.filter(function (k) { return k != key; }) });
703
+ (expandable === null || expandable === void 0 ? void 0 : expandable.onExpand) && (expandable === null || expandable === void 0 ? void 0 : expandable.onExpand(false, data));
704
+ };
705
+ Table.prototype.getChildrenColumnName = function () {
706
+ var childrenColumnName = this.props.childrenColumnName;
707
+ return childrenColumnName || 'children';
708
+ };
709
+ Table.prototype.getRowSelectionKeyField = function () {
710
+ var rowSelection = this.props.rowSelection;
711
+ return rowSelection ? (rowSelection.keyField || 'key') : '';
712
+ };
713
+ Table.prototype.getExpandableKeyField = function () {
714
+ var _a = this.props, expandable = _a.expandable, keyField = _a.keyField;
715
+ return (expandable === null || expandable === void 0 ? void 0 : expandable.keyField) || keyField || 'key';
716
+ };
717
+ Table.prototype.hasChildrenRow = function (data) {
718
+ var key = this.getChildrenColumnName();
719
+ return data[key]
720
+ && Array.isArray(data[key]) && data[key].length > 0;
721
+ };
722
+ // 展开和嵌套不能共存
723
+ Table.prototype.isExpandableRow = function (data, rowIndex) {
724
+ var expandable = this.props.expandable;
725
+ return expandable && expandable.rowExpandable
726
+ && expandable.rowExpandable(data, rowIndex);
727
+ };
728
+ // 获取当前行数据所有子行的key值
729
+ Table.prototype.getDataChildrenKeys = function (data) {
730
+ var _this = this;
731
+ var keys = [];
732
+ if (this.hasChildrenRow(data)) {
733
+ var key = this.getChildrenColumnName();
734
+ data[key].forEach(function (item) {
735
+ return keys = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], keys, true), _this.getDataChildrenKeys(item), true), [
736
+ item[_this.getRowSelectionKeyField()]
737
+ ], false);
738
+ });
739
+ }
740
+ return keys;
741
+ };
742
+ Table.prototype.hasCheckedRows = function (data) {
743
+ var selectedRowKeys = this.state.selectedRowKeys;
744
+ var childrenKeys = this.getDataChildrenKeys(data);
745
+ return (0, intersection_1.default)(selectedRowKeys, (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], childrenKeys, true), [
746
+ data[this.getRowSelectionKeyField()]
747
+ ], false)).length > 0;
748
+ };
749
+ Table.prototype.hasCheckedChildrenRows = function (data) {
750
+ var selectedRowKeys = this.state.selectedRowKeys;
751
+ var childrenKeys = this.getDataChildrenKeys(data);
752
+ var length = (0, intersection_1.default)(selectedRowKeys, childrenKeys).length;
753
+ return length > 0;
754
+ };
755
+ Table.prototype.getExpandedIcons = function (isExpanded, record) {
756
+ var cx = this.props.classnames;
757
+ return isExpanded
758
+ ? react_1.default.createElement("i", { className: cx('Table-expandBtn', 'is-active'), onClick: this.onCollapseRow.bind(this, record) },
759
+ react_1.default.createElement(icons_1.Icon, { icon: "right-arrow-bold", className: "icon" }))
760
+ : react_1.default.createElement("i", { className: cx('Table-expandBtn'), onClick: this.onExpandRow.bind(this, record) },
761
+ react_1.default.createElement(icons_1.Icon, { icon: "right-arrow-bold", className: "icon" }));
762
+ };
763
+ Table.prototype.selectedSingleRow = function (value, data) {
764
+ var _this = this;
765
+ var rowSelection = this.props.rowSelection;
766
+ var defaultKey = this.getRowSelectionKeyField();
767
+ var isRadio = rowSelection && rowSelection.type === 'radio';
768
+ var callback = function () {
769
+ rowSelection && rowSelection.onSelect
770
+ && rowSelection.onSelect(data, value, _this.selectedRows, _this.state.selectedRowKeys);
771
+ };
772
+ if (value) {
773
+ if (isRadio) {
774
+ this.setState({
775
+ selectedRowKeys: [data[defaultKey]]
776
+ }, callback);
777
+ }
778
+ else {
779
+ this.setState(function (prevState) { return ({
780
+ selectedRowKeys: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], prevState.selectedRowKeys, true), [
781
+ data[defaultKey]
782
+ ], false), _this.getDataChildrenKeys(data), true).filter(function (key, i, a) { return a.indexOf(key) === i; })
783
+ }); }, callback);
784
+ }
785
+ }
786
+ else {
787
+ if (!isRadio) {
788
+ this.setState({
789
+ selectedRowKeys: this.state.selectedRowKeys.filter(function (key) {
790
+ return !(0, tslib_1.__spreadArray)([data[defaultKey]], _this.getDataChildrenKeys(data), true).includes(key);
791
+ })
792
+ }, callback);
793
+ }
794
+ }
795
+ };
796
+ Table.prototype.renderRow = function (data, rowIndex, levels) {
797
+ var _this = this;
798
+ var _a = this.props, cx = _a.classnames, rowSelection = _a.rowSelection, expandable = _a.expandable, draggable = _a.draggable, indentSize = _a.indentSize, rowClassName = _a.rowClassName, lineHeight = _a.lineHeight // 是否设置了固定行高
799
+ ;
800
+ var tdColumns = this.tdColumns;
801
+ var isExpandable = this.isExpandableTable();
802
+ var defaultKey = this.getRowSelectionKeyField();
803
+ var colCount = this.getExtraColumnCount();
804
+ // 当前行是否可展开
805
+ var isExpandableRow = this.isExpandableRow(data, rowIndex);
806
+ // 当前行是否有children
807
+ var hasChildrenRow = this.hasChildrenRow(data);
808
+ var isExpanded = !!(0, find_1.default)(this.state.expandedRowKeys, function (key) { return key == data[_this.getExpandableKeyField()]; }); // == 匹配 否则'3'、3匹配不上
809
+ // 设置缩进效果
810
+ var indentDom = levels.length > 0 ? react_1.default.createElement("span", { className: cx('Table-row-indent', "indent-level-".concat(levels.length)), style: { paddingLeft: (indentSize * levels.length) + 'px' } }) : null;
811
+ var cells = tdColumns.map(function (item, i) {
812
+ var _a;
813
+ var render = item.render && typeof item.render === 'function'
814
+ ? item.render(data[item.key], data, rowIndex, i) : null;
815
+ var props = { rowSpan: 1, colSpan: 1 };
816
+ var children = render;
817
+ if (render && (0, helper_1.isObject)(render)) {
818
+ props = render.props;
819
+ children = render.children;
820
+ // 如果合并行 且有展开行,那么合并行不生效
821
+ if (props.rowSpan > 1 && isExpandableRow && hasChildrenRow) {
822
+ props.rowSpan === 1;
823
+ }
824
+ }
825
+ return props.rowSpan === 0 || props.colSpan === 0 ? null : react_1.default.createElement(Cell_1.default, (0, tslib_1.__assign)({ key: i }, props, { fixed: item.fixed === true ? 'left' : item.fixed, column: item, groupId: item.groupId }),
826
+ react_1.default.createElement("div", { className: cx('Table-cell-wrapper', (_a = {},
827
+ _a[cx('Table-cell-wrapper-prefix')] = i === 0
828
+ && (!!indentDom || levels.length === 0 && hasChildrenRow),
829
+ _a[cx("Table-cell-height-".concat(lineHeight))] = !!lineHeight,
830
+ _a)) },
831
+ i === 0 && levels.length > 0 ? indentDom : null,
832
+ i === 0 && hasChildrenRow
833
+ ? _this.getExpandedIcons(isExpanded, data) : null,
834
+ render
835
+ ? children
836
+ : data[item.key]));
837
+ });
838
+ var rowClassNameClass = rowClassName && typeof rowClassName === 'function'
839
+ ? rowClassName(data, rowIndex) : '';
840
+ // 可展开和嵌套不能同时支持
841
+ // 设置了expandable 数据源里有children也就不生效了
842
+ // 拖拽排序 可选、可展开都先不支持了,可以支持嵌套展示
843
+ var checkboxProps = rowSelection && rowSelection.getCheckboxProps
844
+ ? rowSelection.getCheckboxProps(data, rowIndex) : {};
845
+ var expandedRowClassName = expandable && expandable.expandedRowClassName
846
+ && typeof expandable.expandedRowClassName === 'function'
847
+ ? expandable.expandedRowClassName(data, rowIndex) : '';
848
+ var dataKey = this.getChildrenColumnName();
849
+ var children = !draggable && isExpandableRow && isExpanded
850
+ ? react_1.default.createElement("tr", { key: "expanded", className: cx('Table-expanded-row', expandedRowClassName) },
851
+ react_1.default.createElement(Cell_1.default, { colSpan: tdColumns.length + colCount }, expandable && expandable.expandedRowRender
852
+ && typeof expandable.expandedRowRender === 'function'
853
+ ? expandable.expandedRowRender(data, rowIndex) : null)) : (this.hasChildrenRow(data) && isExpanded ? data[dataKey].map(function (item, index) {
854
+ return _this.renderRow(item, index, (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], levels, true), [rowIndex], false));
855
+ }) : null);
856
+ var isChecked = !!(0, find_1.default)(this.state.selectedRowKeys, function (key) { return key === data[defaultKey]; });
857
+ var hasChildrenChecked = this.hasCheckedChildrenRows(data);
858
+ return [react_1.default.createElement("tr", { key: rowIndex, "row-index": rowIndex, "row-levels": levels.join(','), className: cx('Table-row', "Table-row-level-".concat(levels.length), rowClassNameClass, {
859
+ 'Table-row-disabled': !!checkboxProps.disabled
860
+ }), onMouseEnter: function (e) { return _this.onRowMouseEnter(e, data, rowIndex); }, onMouseLeave: function (e) { return _this.onRowMouseLeave(e, data, rowIndex); }, onClick: function (e) { return _this.onRowClick(e, data, rowIndex); } },
861
+ draggable ? react_1.default.createElement(Cell_1.default, { className: cx('Table-dragCell') },
862
+ react_1.default.createElement(icons_1.Icon, { icon: "drag-bar", className: "icon" })) : null,
863
+ !draggable && rowSelection
864
+ ? (react_1.default.createElement(Cell_1.default, { fixed: rowSelection.fixed ? 'left' : '', className: cx('Table-checkCell') },
865
+ react_1.default.createElement(Checkbox_1.default, (0, tslib_1.__assign)({ name: 'Table-checkbox', type: rowSelection.type || 'checkbox', partial: hasChildrenChecked && !isChecked, checked: hasChildrenChecked || isChecked, onChange: function (value, shift) {
866
+ if (!(rowSelection && rowSelection.rowClick)) {
867
+ _this.selectedSingleRow(value, data);
868
+ }
869
+ event && event.stopPropagation();
870
+ } }, checkboxProps)))) : null,
871
+ !draggable && isExpandable ? react_1.default.createElement(Cell_1.default, { fixed: expandable && expandable.fixed ? 'left' : '', className: cx('Table-cell-expand-icon-cell') }, isExpandableRow || hasChildrenRow
872
+ ? this.getExpandedIcons(isExpanded, data) : null) : null,
873
+ cells), children];
874
+ };
875
+ Table.prototype.renderTBody = function () {
876
+ var _this = this;
877
+ var _a = this.props, cx = _a.classnames, headSummary = _a.headSummary, scroll = _a.scroll, placeholder = _a.placeholder, sticky = _a.sticky;
878
+ var tdColumns = this.tdColumns;
879
+ var hasScrollY = scroll && scroll.y;
880
+ var colCount = this.getExtraColumnCount();
881
+ return (react_1.default.createElement("tbody", { ref: this.tbodyDom, className: cx('Table-tbody') },
882
+ !hasScrollY && !sticky && headSummary
883
+ ? this.renderSummaryRow(headSummary) : null,
884
+ !this.state.dataSource.length
885
+ ? react_1.default.createElement("tr", { className: cx('Table-row', 'Table-empty-row') },
886
+ react_1.default.createElement(Cell_1.default, { colSpan: tdColumns.length + colCount },
887
+ react_1.default.createElement("div", { className: cx('Table-empty') }, typeof placeholder === 'function' ? placeholder() : placeholder)))
888
+ : this.state.dataSource.map(function (data, index) {
889
+ return _this.renderRow(data, index, []);
890
+ })));
891
+ };
892
+ Table.prototype.isExpandableTable = function () {
893
+ var expandable = this.props.expandable;
894
+ // 设置了expandable 优先级更高
895
+ // 就不支持默认嵌套了
896
+ return !!expandable;
897
+ };
898
+ Table.prototype.isNestedTable = function () {
899
+ var _this = this;
900
+ var dataSource = this.props.dataSource;
901
+ return !!(0, find_1.default)(dataSource, function (item) { return _this.hasChildrenRow(item); });
902
+ };
903
+ Table.prototype.getExtraColumnCount = function () {
904
+ var _a = this.props, draggable = _a.draggable, rowSelection = _a.rowSelection;
905
+ var count = 0;
906
+ if (draggable) {
907
+ count++;
908
+ }
909
+ else {
910
+ if (this.isExpandableTable()) {
911
+ count++;
912
+ }
913
+ if (rowSelection) {
914
+ count++;
915
+ }
916
+ }
917
+ return count;
918
+ };
919
+ Table.prototype.renderSummaryRow = function (summary) {
920
+ var _this = this;
921
+ var _a = this.props, cx = _a.classnames, dataSource = _a.dataSource;
922
+ var cells = [];
923
+ var trs = [];
924
+ var colCount = this.getExtraColumnCount();
925
+ (Array.isArray(summary) ? summary.forEach(function (s, index) {
926
+ Array.isArray(s) ? trs.push(react_1.default.createElement("tr", { onMouseEnter: function (e) { return _this.onRowMouseEnter(e); }, onMouseLeave: function (e) { return _this.onRowMouseLeave(e); }, key: 'summary-tr-' + index, className: cx('Table-summary-row') }, s.map(function (d, i) {
927
+ // 将操作列自动添加到第一列,用户的colSpan只需要关心实际的列数
928
+ var colSpan = i === 0 ? (d.colSpan || 1) + colCount : d.colSpan;
929
+ return react_1.default.createElement(Cell_1.default, { key: 'summary-tr-cell-' + i, fixed: d.fixed, colSpan: colSpan }, typeof d.render === 'function' ? d.render(dataSource) : d.render);
930
+ }))) : cells.push(react_1.default.createElement(Cell_1.default, { key: 'summary-cell-' + index, fixed: s.fixed, colSpan: cells.length === 0 ? ((s.colSpan || 1) + colCount) : s.colSpan }, typeof s.render === 'function' ? s.render(dataSource) : s.render));
931
+ }) : null);
932
+ return (summary ? (typeof summary === 'function'
933
+ ? summary(dataSource) : (0, tslib_1.__spreadArray)([cells.length > 0 ? react_1.default.createElement("tr", { onMouseEnter: function (e) { return _this.onRowMouseEnter(e); }, onMouseLeave: function (e) { return _this.onRowMouseLeave(e); }, key: "summary-row", className: cx('Table-summary-row') }, cells) : null], trs, true)) : null);
934
+ };
935
+ Table.prototype.renderTFoot = function () {
936
+ var _a = this.props, cx = _a.classnames, footSummary = _a.footSummary;
937
+ return (react_1.default.createElement("tfoot", { ref: this.tfootDom, className: cx('Table-summary') }, this.renderSummaryRow(footSummary)));
938
+ };
939
+ Table.prototype.updateTableDom = function (dom) {
940
+ var cx = this.props.classnames;
941
+ var scrollLeft = dom.scrollLeft, scrollWidth = dom.scrollWidth, offsetWidth = dom.offsetWidth;
942
+ var table = this.tableDom.current;
943
+ var leftCalss = cx('Table-ping-left');
944
+ if (scrollLeft > 0) {
945
+ table === null || table === void 0 ? void 0 : table.classList.add(leftCalss);
946
+ }
947
+ else {
948
+ table === null || table === void 0 ? void 0 : table.classList.remove(leftCalss);
949
+ }
950
+ var rightClass = cx('Table-ping-right');
951
+ if (scrollLeft + offsetWidth < scrollWidth) {
952
+ table === null || table === void 0 ? void 0 : table.classList.add(rightClass);
953
+ }
954
+ else {
955
+ table === null || table === void 0 ? void 0 : table.classList.remove(rightClass);
956
+ }
957
+ };
958
+ Table.prototype.onTableContentScroll = function (event) {
959
+ this.updateTableDom(event.target);
960
+ };
961
+ Table.prototype.onWheel = function (event) {
962
+ var _a = event, currentTarget = _a.currentTarget, deltaX = _a.deltaX;
963
+ if (deltaX) {
964
+ this.onTableScroll({
965
+ target: currentTarget,
966
+ scrollLeft: currentTarget.scrollLeft + deltaX
967
+ });
968
+ event.preventDefault();
969
+ }
970
+ };
971
+ Table.prototype.onTableScroll = function (event) {
972
+ var scrollDomRefs = [
973
+ this.headerDom,
974
+ this.bodyDom,
975
+ this.footDom
976
+ ];
977
+ var target = event.target, scrollLeft = event.scrollLeft;
978
+ scrollDomRefs.forEach(function (ref) {
979
+ var current = ref && ref.current;
980
+ if (current && current !== target) {
981
+ current.scrollLeft = (scrollLeft || target.scrollLeft);
982
+ }
983
+ });
984
+ this.updateTableDom(target);
985
+ };
986
+ Table.prototype.renderLoading = function () {
987
+ var _a = this.props, cx = _a.classnames, loading = _a.loading;
988
+ return react_1.default.createElement("div", { className: cx('Table-loading') }, typeof loading === 'boolean' ? react_1.default.createElement(Spinner_1.default, null) : loading);
989
+ };
990
+ Table.prototype.renderTable = function () {
991
+ var _a = this.props, scroll = _a.scroll, footSummary = _a.footSummary, loading = _a.loading, showHeader = _a.showHeader, cx = _a.classnames;
992
+ // 设置了横向滚动轴 则table的table-layout为fixed
993
+ var hasScrollX = scroll && scroll.x;
994
+ return (react_1.default.createElement("div", { ref: this.contentDom, className: cx('Table-content'), style: hasScrollX ? { overflow: 'auto hidden' } : {} },
995
+ react_1.default.createElement("table", { style: hasScrollX
996
+ ? { width: scroll.x + 'px', tableLayout: 'fixed' }
997
+ : { tableLayout: 'auto' }, className: cx('Table-table') },
998
+ this.renderColGroup(),
999
+ showHeader ? this.renderTHead() : null,
1000
+ !loading ? this.renderTBody() : null,
1001
+ !loading && footSummary ? this.renderTFoot() : null),
1002
+ loading ? this.renderLoading() : null));
1003
+ };
1004
+ Table.prototype.renderScrollTableHeader = function () {
1005
+ var _a;
1006
+ var _b = this.props, scroll = _b.scroll, headSummary = _b.headSummary, sticky = _b.sticky, showHeader = _b.showHeader, cx = _b.classnames;
1007
+ var style = { overflow: 'hidden' };
1008
+ if (!!sticky) {
1009
+ Object.assign(style, { top: 0 });
1010
+ }
1011
+ var tableStyle = {};
1012
+ if (scroll && (scroll.y || scroll.x)) {
1013
+ Object.assign(tableStyle, {
1014
+ width: (scroll && scroll.x ? (scroll.x + 'px') : '100%'),
1015
+ tableLayout: 'fixed'
1016
+ });
1017
+ }
1018
+ return (react_1.default.createElement("div", { ref: this.headerDom, className: cx('Table-header', (_a = {},
1019
+ _a[cx('Table-sticky-holder')] = !!sticky,
1020
+ _a)), style: style },
1021
+ react_1.default.createElement("table", { className: cx('Table-table'), style: tableStyle },
1022
+ this.renderColGroup(this.state.colWidths),
1023
+ showHeader ? this.renderTHead() : null,
1024
+ headSummary ? react_1.default.createElement("tbody", null, this.renderSummaryRow(headSummary)) : null)));
1025
+ };
1026
+ Table.prototype.renderScrollTableBody = function () {
1027
+ var _a = this.props, scroll = _a.scroll, cx = _a.classnames;
1028
+ var style = {};
1029
+ var tableStyle = {};
1030
+ if (scroll && (scroll.y || scroll.x)) {
1031
+ Object.assign(style, {
1032
+ overflow: 'auto scroll',
1033
+ maxHeight: scroll.y
1034
+ });
1035
+ Object.assign(tableStyle, {
1036
+ width: scroll && scroll.x ? (scroll.x + 'px') : '100%',
1037
+ tableLayout: 'fixed'
1038
+ });
1039
+ }
1040
+ return (react_1.default.createElement("div", { ref: this.bodyDom, className: cx('Table-body'), style: style },
1041
+ react_1.default.createElement("table", { className: cx('Table-table'), style: tableStyle },
1042
+ this.renderColGroup(),
1043
+ this.renderTBody())));
1044
+ };
1045
+ Table.prototype.renderScrollTableFoot = function () {
1046
+ var _a = this.props, scroll = _a.scroll, cx = _a.classnames;
1047
+ return (react_1.default.createElement("div", { ref: this.footDom, className: cx('Table-summary'), style: { overflow: 'hidden' } },
1048
+ react_1.default.createElement("table", { className: cx('Table-table'), style: { width: ((scroll === null || scroll === void 0 ? void 0 : scroll.x) + 'px') || '100%', tableLayout: 'fixed' } }, this.renderTFoot())));
1049
+ };
1050
+ Table.prototype.renderScrollTable = function () {
1051
+ var _a = this.props, footSummary = _a.footSummary, loading = _a.loading, cx = _a.classnames;
1052
+ return (react_1.default.createElement("div", { className: cx('Table-container') },
1053
+ this.renderScrollTableHeader(),
1054
+ !loading ? this.renderScrollTableBody() : null,
1055
+ !loading && footSummary ? this.renderScrollTableFoot() : null,
1056
+ loading ? this.renderLoading() : null));
1057
+ };
1058
+ Table.prototype.render = function () {
1059
+ var _a;
1060
+ var _b = this.props, title = _b.title, footer = _b.footer, className = _b.className, scroll = _b.scroll, size = _b.size, bordered = _b.bordered, resizable = _b.resizable, columns = _b.columns, sticky = _b.sticky, cx = _b.classnames;
1061
+ // 过滤掉设置了breakpoint属性的列
1062
+ var filterColumns = columns.filter(function (item) { return !item.breakpoint ||
1063
+ !(0, helper_1.isBreakpoint)(item.breakpoint); });
1064
+ this.thColumns = [];
1065
+ this.tdColumns = [];
1066
+ buildColumns(filterColumns, this.thColumns, this.tdColumns);
1067
+ // 是否设置了纵向滚动
1068
+ var hasScrollY = scroll && scroll.y;
1069
+ // 是否设置了横向滚动
1070
+ var hasScrollX = scroll && scroll.x;
1071
+ return (react_1.default.createElement("div", { ref: this.tableDom, className: cx('Table-v2', className, (_a = {},
1072
+ _a[cx('Table-scroll-horizontal')] = hasScrollX,
1073
+ _a[cx("Table-".concat(size))] = size,
1074
+ _a[cx('Table-bordered')] = bordered,
1075
+ _a[cx('Table-resizable')] = resizable,
1076
+ _a)) },
1077
+ title ? react_1.default.createElement("div", { className: cx('Table-title') }, typeof title === 'function' ? title() : title) : null,
1078
+ hasScrollY || sticky ? this.renderScrollTable()
1079
+ : react_1.default.createElement("div", { className: cx('Table-container') }, this.renderTable()),
1080
+ footer ? react_1.default.createElement("div", { className: cx('Table-footer') }, typeof footer === 'function' ? footer() : footer) : null));
1081
+ };
1082
+ Table.defaultProps = {
1083
+ title: '',
1084
+ className: '',
1085
+ dataSource: [],
1086
+ columns: [],
1087
+ indentSize: 15,
1088
+ placeholder: '暂无数据',
1089
+ showHeader: true
1090
+ };
1091
+ return Table;
1092
+ }(react_1.default.PureComponent));
1093
+ exports.Table = Table;
1094
+ exports.default = (0, theme_1.themeable)((0, locale_1.localeable)(Table));
1095
+ //# sourceMappingURL=./components/table/index.js.map