@douyinfe/semi-ui 2.1.3 → 2.1.4-alpha.0

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 (752) hide show
  1. package/_base/_story/index.scss +14 -0
  2. package/_base/_story/index.stories.js +118 -0
  3. package/_base/_story/index.stories.tsx +55 -0
  4. package/_base/base.scss +3 -0
  5. package/_base/base.ts +36 -0
  6. package/_base/baseComponent.tsx +78 -0
  7. package/_base/reactUtils.ts +43 -0
  8. package/_portal/_story/portal.stories.js +17 -0
  9. package/_portal/index.tsx +112 -0
  10. package/_test_/utils/dom/index.js +9 -0
  11. package/_test_/utils/function/index.js +1 -0
  12. package/_test_/utils/function/sleep.js +9 -0
  13. package/_test_/utils/index.js +4 -0
  14. package/_test_/utils/table/index.js +310 -0
  15. package/_test_/utils/tooltip/index.js +39 -0
  16. package/_utils/index.ts +157 -0
  17. package/anchor/__test__/anchor.test.js +59 -0
  18. package/anchor/_story/anchor.stories.js +266 -0
  19. package/anchor/_story/anchor.stories.tsx +165 -0
  20. package/anchor/anchor-context.ts +13 -0
  21. package/anchor/index.tsx +296 -0
  22. package/anchor/link.tsx +136 -0
  23. package/autoComplete/__test__/autoComplete.test.js +456 -0
  24. package/autoComplete/_story/CustomTrigger/index.jsx +106 -0
  25. package/autoComplete/_story/autoComplete.stories.js +349 -0
  26. package/autoComplete/_story/autoComplete.stories.tsx +87 -0
  27. package/autoComplete/index.tsx +476 -0
  28. package/avatar/__test__/avatar.test.js +363 -0
  29. package/avatar/__test__/avatarGroup.test.js +193 -0
  30. package/avatar/_story/Demo.tsx +22 -0
  31. package/avatar/_story/avatar.stories.js +191 -0
  32. package/avatar/_story/avatar.stories.tsx +7 -0
  33. package/avatar/avatarGroup.tsx +81 -0
  34. package/avatar/index.tsx +163 -0
  35. package/avatar/interface.ts +51 -0
  36. package/backtop/__test__/backtop.test.js +49 -0
  37. package/backtop/_story/backtop.stories.js +37 -0
  38. package/backtop/_story/backtop.stories.tsx +30 -0
  39. package/backtop/index.tsx +112 -0
  40. package/badge/__test__/badge.test.js +123 -0
  41. package/badge/_story/Demo.tsx +16 -0
  42. package/badge/_story/badge.stories.js +91 -0
  43. package/badge/_story/badge.stories.tsx +8 -0
  44. package/badge/index.tsx +80 -0
  45. package/banner/__test__/banner.test.js +58 -0
  46. package/banner/_story/Demo.tsx +14 -0
  47. package/banner/_story/banner.stories.js +45 -0
  48. package/banner/_story/banner.stories.tsx +8 -0
  49. package/banner/index.tsx +172 -0
  50. package/breadcrumb/__test__/breadcrumb.test.js +219 -0
  51. package/breadcrumb/_story/Demo.tsx +24 -0
  52. package/breadcrumb/_story/breadcrumb.stories.js +317 -0
  53. package/breadcrumb/_story/breadcrumb.stories.tsx +45 -0
  54. package/breadcrumb/bread-context.tsx +13 -0
  55. package/breadcrumb/index.tsx +293 -0
  56. package/breadcrumb/item.tsx +207 -0
  57. package/button/Button.tsx +125 -0
  58. package/button/__test__/button.test.js +49 -0
  59. package/button/_story/Demo.tsx +51 -0
  60. package/button/_story/button.stories.js +280 -0
  61. package/button/_story/button.stories.tsx +10 -0
  62. package/button/buttonGroup.tsx +47 -0
  63. package/button/index.tsx +38 -0
  64. package/button/splitButtonGroup.tsx +27 -0
  65. package/calendar/__test__/calendar.test.js +163 -0
  66. package/calendar/_story/Demo.tsx +20 -0
  67. package/calendar/_story/calendar.stories.js +405 -0
  68. package/calendar/_story/calendar.stories.tsx +5 -0
  69. package/calendar/dayCalendar.tsx +191 -0
  70. package/calendar/dayCol.tsx +156 -0
  71. package/calendar/index.tsx +61 -0
  72. package/calendar/interface.ts +42 -0
  73. package/calendar/monthCalendar.tsx +399 -0
  74. package/calendar/rangeCalendar.tsx +270 -0
  75. package/calendar/timeCol.tsx +64 -0
  76. package/calendar/weekCalendar.tsx +271 -0
  77. package/card/__test__/card.test.js +202 -0
  78. package/card/_story/card.stories.js +555 -0
  79. package/card/_story/card.stories.tsx +100 -0
  80. package/card/cardGroup.tsx +63 -0
  81. package/card/index.tsx +243 -0
  82. package/card/meta.tsx +73 -0
  83. package/cascader/__test__/cascader.test.js +1030 -0
  84. package/cascader/_story/CustomTrigger/index.jsx +63 -0
  85. package/cascader/_story/Demo.tsx +63 -0
  86. package/cascader/_story/cascader.stories.js +1213 -0
  87. package/cascader/_story/cascader.stories.tsx +6 -0
  88. package/cascader/index.tsx +901 -0
  89. package/cascader/item.tsx +301 -0
  90. package/checkbox/__test__/checkbox.test.js +85 -0
  91. package/checkbox/__test__/checkboxGroup.test.js +148 -0
  92. package/checkbox/_story/Demo.tsx +27 -0
  93. package/checkbox/_story/checkbox.stories.js +943 -0
  94. package/checkbox/_story/checkbox.stories.tsx +8 -0
  95. package/checkbox/checkbox.tsx +200 -0
  96. package/checkbox/checkboxGroup.tsx +171 -0
  97. package/checkbox/checkboxInner.tsx +88 -0
  98. package/checkbox/context.ts +14 -0
  99. package/checkbox/index.tsx +19 -0
  100. package/collapse/__test__/collapse.test.js +148 -0
  101. package/collapse/_story/Demo.tsx +28 -0
  102. package/collapse/_story/accordion.stories.js +143 -0
  103. package/collapse/_story/accordion.stories.tsx +8 -0
  104. package/collapse/collapse-context.tsx +18 -0
  105. package/collapse/index.tsx +119 -0
  106. package/collapse/item.tsx +139 -0
  107. package/collapsible/_story/Demo.tsx +41 -0
  108. package/collapsible/_story/Nested/index.js +101 -0
  109. package/collapsible/_story/collapsible.stories.js +588 -0
  110. package/collapsible/_story/collapsible.stories.tsx +7 -0
  111. package/collapsible/index.tsx +156 -0
  112. package/configProvider/_story/ChangeTimeZone/index.js +183 -0
  113. package/configProvider/_story/GetPopupContainer/index.js +194 -0
  114. package/configProvider/_story/RTLDirection/RTLForm.jsx +313 -0
  115. package/configProvider/_story/RTLDirection/RTLTable.jsx +94 -0
  116. package/configProvider/_story/RTLDirection/RTLWrapper.tsx +27 -0
  117. package/configProvider/_story/configProvider.stories.js +30 -0
  118. package/configProvider/context.tsx +14 -0
  119. package/configProvider/index.tsx +48 -0
  120. package/datePicker/__test__/datePicker.test.js +873 -0
  121. package/datePicker/_story/AllTypes/index.js +19 -0
  122. package/datePicker/_story/AutoSwitchDate/index.jsx +14 -0
  123. package/datePicker/_story/Autofocus/index.js +11 -0
  124. package/datePicker/_story/BetterRangePicker/index.jsx +172 -0
  125. package/datePicker/_story/Callbacks/index.jsx +24 -0
  126. package/datePicker/_story/ControlledDemo/index.js +149 -0
  127. package/datePicker/_story/CustomTrigger/index.jsx +36 -0
  128. package/datePicker/_story/Cycled/index.jsx +11 -0
  129. package/datePicker/_story/DateOffset/index.js +83 -0
  130. package/datePicker/_story/DatePickerSlot/index.jsx +83 -0
  131. package/datePicker/_story/DatePickerSlot/index.scss +7 -0
  132. package/datePicker/_story/DatePickerTimeZone/index.jsx +27 -0
  133. package/datePicker/_story/Density/index.jsx +69 -0
  134. package/datePicker/_story/DisabledDate/index.js +189 -0
  135. package/datePicker/_story/ExceptionDemo/index.js +20 -0
  136. package/datePicker/_story/Multiple/index.jsx +24 -0
  137. package/datePicker/_story/NeedConfirm/index.jsx +94 -0
  138. package/datePicker/_story/OnChangeWithDateFirst/index.jsx +37 -0
  139. package/datePicker/_story/OverPopover/index.jsx +22 -0
  140. package/datePicker/_story/RenderDate/index.js +21 -0
  141. package/datePicker/_story/RenderFullDate/index.js +56 -0
  142. package/datePicker/_story/RenderFullDate/index.scss +23 -0
  143. package/datePicker/_story/SyncSwitchMonth/index.js +45 -0
  144. package/datePicker/_story/TimePickerOpts/index.jsx +16 -0
  145. package/datePicker/_story/datePicker.stories.js +636 -0
  146. package/datePicker/_story/datePicker.stories.tsx +230 -0
  147. package/datePicker/dateInput.tsx +358 -0
  148. package/datePicker/datePicker.tsx +647 -0
  149. package/datePicker/footer.tsx +29 -0
  150. package/datePicker/index.tsx +71 -0
  151. package/datePicker/month.tsx +388 -0
  152. package/datePicker/monthsGrid.tsx +615 -0
  153. package/datePicker/navigation.tsx +120 -0
  154. package/datePicker/quickControl.tsx +54 -0
  155. package/datePicker/yearAndMonth.tsx +228 -0
  156. package/descriptions/__test__/descriptions.test.js +167 -0
  157. package/descriptions/_story/Demo.tsx +36 -0
  158. package/descriptions/_story/descriptions.stories.js +95 -0
  159. package/descriptions/_story/descriptions.stories.tsx +6 -0
  160. package/descriptions/descriptions-context.ts +11 -0
  161. package/descriptions/index.tsx +82 -0
  162. package/descriptions/item.tsx +63 -0
  163. package/dist/umd/semi-ui.js +253 -257
  164. package/dist/umd/semi-ui.js.map +1 -1
  165. package/dist/umd/semi-ui.min.js +1 -1
  166. package/dist/umd/semi-ui.min.js.map +1 -1
  167. package/dropdown/__test__/dropdown.test.js +308 -0
  168. package/dropdown/_story/AutoClose/index.js +120 -0
  169. package/dropdown/_story/DisabledItem/index.js +31 -0
  170. package/dropdown/_story/InHoverElements/index.js +25 -0
  171. package/dropdown/_story/InHoverElements/index.scss +16 -0
  172. package/dropdown/_story/MultiDropdown/index.js +34 -0
  173. package/dropdown/_story/WrapAvatar/index.jsx +10 -0
  174. package/dropdown/_story/dropdown.stories.js +331 -0
  175. package/dropdown/_story/dropdown.stories.tsx +28 -0
  176. package/dropdown/_story/inTable/index.js +194 -0
  177. package/dropdown/context.ts +6 -0
  178. package/dropdown/dropdownDivider.tsx +23 -0
  179. package/dropdown/dropdownItem.tsx +104 -0
  180. package/dropdown/dropdownMenu.tsx +28 -0
  181. package/dropdown/dropdownTitle.tsx +36 -0
  182. package/dropdown/index.tsx +239 -0
  183. package/empty/__test__/empty.test.js +63 -0
  184. package/empty/_story/Demo.tsx +10 -0
  185. package/empty/_story/empty.stories.js +53 -0
  186. package/empty/_story/empty.stories.tsx +8 -0
  187. package/empty/index.tsx +127 -0
  188. package/form/__test__/arrayField.test.js +204 -0
  189. package/form/__test__/baseForm/baseForm.test.js +628 -0
  190. package/form/__test__/baseForm/onChange.test.js +144 -0
  191. package/form/__test__/errorMessage.test.js +59 -0
  192. package/form/__test__/field.test.js +426 -0
  193. package/form/__test__/formApi.test.js +422 -0
  194. package/form/__test__/group.test.js +108 -0
  195. package/form/__test__/hoc.test.js +24 -0
  196. package/form/__test__/label.test.js +69 -0
  197. package/form/__test__/section.test.js +49 -0
  198. package/form/__test__/slot.test.js +108 -0
  199. package/form/_story/Debug/bugDemo.jsx +219 -0
  200. package/form/_story/Debug/childDidMount.jsx +30 -0
  201. package/form/_story/Debug/myRadio.jsx +32 -0
  202. package/form/_story/DynamicField/arrayFieldDemo.jsx +320 -0
  203. package/form/_story/DynamicField/nestArrayField.jsx +159 -0
  204. package/form/_story/FieldProps/bigNumberFieldPath.jsx +73 -0
  205. package/form/_story/FieldProps/convert.jsx +100 -0
  206. package/form/_story/FieldProps/fieldRef.jsx +74 -0
  207. package/form/_story/FieldProps/helpAndExtra.jsx +136 -0
  208. package/form/_story/FieldProps/pureField.jsx +0 -0
  209. package/form/_story/FieldProps/rulesUpdateDemo.js +116 -0
  210. package/form/_story/FormApi/arrayDemo.jsx +97 -0
  211. package/form/_story/FormApi/formApiDemo.jsx +82 -0
  212. package/form/_story/FormApi/resetDemo.jsx +41 -0
  213. package/form/_story/FormApi/setValuesDemo.jsx +133 -0
  214. package/form/_story/HOC/displayName.jsx +19 -0
  215. package/form/_story/HOC/withFieldDemo.jsx +216 -0
  216. package/form/_story/Hook/hookDemo.jsx +195 -0
  217. package/form/_story/Layout/layoutDemo.jsx +348 -0
  218. package/form/_story/Layout/modalFormDemo.jsx +94 -0
  219. package/form/_story/Layout/slotDemo.jsx +126 -0
  220. package/form/_story/Performance/performanceDemo.jsx +440 -0
  221. package/form/_story/Performance/selectUseReactNode.jsx +110 -0
  222. package/form/_story/Reference/inform.test.js +110 -0
  223. package/form/_story/Validate/validateDemo.jsx +421 -0
  224. package/form/_story/demo.jsx +397 -0
  225. package/form/_story/form.stories.js +506 -0
  226. package/form/_story/form.stories.tsx +176 -0
  227. package/form/arrayField.tsx +199 -0
  228. package/form/baseForm.tsx +290 -0
  229. package/form/context.tsx +18 -0
  230. package/form/errorMessage.tsx +80 -0
  231. package/form/field.tsx +79 -0
  232. package/form/group.tsx +91 -0
  233. package/form/hoc/withField.tsx +559 -0
  234. package/form/hoc/withFormApi.tsx +11 -0
  235. package/form/hoc/withFormState.tsx +11 -0
  236. package/form/hooks/index.ts +12 -0
  237. package/form/hooks/useArrayFieldState.tsx +9 -0
  238. package/form/hooks/useFieldApi.tsx +21 -0
  239. package/form/hooks/useFieldState.tsx +18 -0
  240. package/form/hooks/useFormApi.tsx +6 -0
  241. package/form/hooks/useFormState.tsx +9 -0
  242. package/form/hooks/useFormUpdater.tsx +6 -0
  243. package/form/hooks/useStateWithGetter.ts +13 -0
  244. package/form/index.tsx +42 -0
  245. package/form/interface.ts +132 -0
  246. package/form/label.tsx +79 -0
  247. package/form/section.tsx +38 -0
  248. package/form/slot.tsx +165 -0
  249. package/getBabelConfig.js +37 -0
  250. package/grid/__test__/calculateGutter.test.js +50 -0
  251. package/grid/_story/demo.scss +23 -0
  252. package/grid/_story/grid.stories.js +290 -0
  253. package/grid/_story/grid.stories.tsx +15 -0
  254. package/grid/col.tsx +133 -0
  255. package/grid/index.tsx +7 -0
  256. package/grid/row.tsx +174 -0
  257. package/gulpfile.js +116 -0
  258. package/iconButton/_story/iconButton.stories.tsx +16 -0
  259. package/iconButton/index.tsx +130 -0
  260. package/icons/_story/Others/add-template-icon.jsx +0 -0
  261. package/icons/_story/Others/add-template-icon.svg +10 -0
  262. package/icons/_story/Others/hangup.svg +3 -0
  263. package/icons/_story/Others/index.js +24 -0
  264. package/icons/_story/Others/xianglin.svg +3 -0
  265. package/icons/_story/icon.stories.js +63 -0
  266. package/icons/_story/icon.stories.tsx +46 -0
  267. package/icons/index.tsx +5 -0
  268. package/index.ts +94 -0
  269. package/input/__test__/input.test.js +245 -0
  270. package/input/__test__/textArea.test.js +119 -0
  271. package/input/_story/Demo.tsx +33 -0
  272. package/input/_story/TextareaDemo.tsx +27 -0
  273. package/input/_story/input.scss +0 -0
  274. package/input/_story/input.stories.js +887 -0
  275. package/input/_story/input.stories.tsx +11 -0
  276. package/input/index.tsx +444 -0
  277. package/input/inputGroup.tsx +119 -0
  278. package/input/textarea.tsx +330 -0
  279. package/inputNumber/__test__/inputNumber.test.js +370 -0
  280. package/inputNumber/_story/input.stories.tsx +17 -0
  281. package/inputNumber/_story/inputNumber.scss +10 -0
  282. package/inputNumber/_story/inputNumber.stories.js +643 -0
  283. package/inputNumber/index.tsx +480 -0
  284. package/layout/Sider.tsx +116 -0
  285. package/layout/__test__/layout.test.js +51 -0
  286. package/layout/_story/layout.stories.js +305 -0
  287. package/layout/_story/layout.stories.tsx +13 -0
  288. package/layout/index.tsx +126 -0
  289. package/layout/layout-context.ts +18 -0
  290. package/lib/cjs/datePicker/dateInput.d.ts +1 -1
  291. package/lib/cjs/datePicker/datePicker.d.ts +1 -1
  292. package/lib/cjs/datePicker/monthsGrid.d.ts +1 -1
  293. package/lib/cjs/radio/radio.d.ts +1 -1
  294. package/lib/cjs/radio/radioGroup.d.ts +1 -1
  295. package/lib/cjs/timePicker/TimePicker.d.ts +2 -2
  296. package/lib/cjs/timePicker/TimeShape.d.ts +1 -1
  297. package/lib/cjs/timePicker/index.d.ts +2 -2
  298. package/lib/cjs/typography/title.d.ts +1 -1
  299. package/lib/cjs/upload/index.d.ts +1 -1
  300. package/lib/es/datePicker/dateInput.d.ts +1 -1
  301. package/lib/es/datePicker/datePicker.d.ts +1 -1
  302. package/lib/es/datePicker/monthsGrid.d.ts +1 -1
  303. package/lib/es/radio/radio.d.ts +1 -1
  304. package/lib/es/radio/radioGroup.d.ts +1 -1
  305. package/lib/es/timePicker/TimePicker.d.ts +2 -2
  306. package/lib/es/timePicker/TimeShape.d.ts +1 -1
  307. package/lib/es/timePicker/index.d.ts +2 -2
  308. package/lib/es/typography/title.d.ts +1 -1
  309. package/lib/es/upload/index.d.ts +1 -1
  310. package/list/__test__/list.test.js +264 -0
  311. package/list/_story/list.stories.js +920 -0
  312. package/list/_story/list.stories.tsx +26 -0
  313. package/list/index.tsx +173 -0
  314. package/list/item.tsx +109 -0
  315. package/list/list-context.ts +15 -0
  316. package/locale/README.md +53 -0
  317. package/locale/_story/locale.stories.js +221 -0
  318. package/locale/_story/locale.stories.tsx +57 -0
  319. package/locale/context.tsx +5 -0
  320. package/locale/interface.ts +152 -0
  321. package/locale/localeConsumer.tsx +58 -0
  322. package/locale/localeProvider.tsx +35 -0
  323. package/locale/source/ar.ts +156 -0
  324. package/locale/source/en_GB.ts +156 -0
  325. package/locale/source/en_US.ts +156 -0
  326. package/locale/source/id_ID.ts +157 -0
  327. package/locale/source/ja_JP.ts +157 -0
  328. package/locale/source/ko_KR.ts +157 -0
  329. package/locale/source/ms_MY.ts +156 -0
  330. package/locale/source/pt_BR.ts +164 -0
  331. package/locale/source/ru_RU.ts +159 -0
  332. package/locale/source/th_TH.ts +160 -0
  333. package/locale/source/tr_TR.ts +156 -0
  334. package/locale/source/vi_VN.ts +159 -0
  335. package/locale/source/zh_CN.ts +157 -0
  336. package/locale/source/zh_TW.ts +157 -0
  337. package/modal/ConfirmModal.tsx +89 -0
  338. package/modal/Modal.tsx +415 -0
  339. package/modal/ModalContent.tsx +276 -0
  340. package/modal/__test__/confirm.test.js +203 -0
  341. package/modal/__test__/modal.test.js +324 -0
  342. package/modal/_story/CollapsibleInModal/index.jsx +100 -0
  343. package/modal/_story/DynamicContext/context.js +8 -0
  344. package/modal/_story/DynamicContext/index.jsx +30 -0
  345. package/modal/_story/modal.stories.js +251 -0
  346. package/modal/_story/modal.stories.tsx +41 -0
  347. package/modal/confirm.tsx +121 -0
  348. package/modal/index.tsx +13 -0
  349. package/modal/useModal/HookModal.tsx +62 -0
  350. package/modal/useModal/index.tsx +72 -0
  351. package/motions/Rotate.tsx +64 -0
  352. package/navigation/CollapseButton.tsx +47 -0
  353. package/navigation/Footer.tsx +72 -0
  354. package/navigation/Header.tsx +80 -0
  355. package/navigation/Item.tsx +274 -0
  356. package/navigation/OpenIconTransition.tsx +57 -0
  357. package/navigation/README.md +10 -0
  358. package/navigation/SubNav.tsx +376 -0
  359. package/navigation/SubNavTransition.tsx +58 -0
  360. package/navigation/__test__/navigation.test.js +274 -0
  361. package/navigation/_story/AutoOpen/index.js +69 -0
  362. package/navigation/_story/ControlledSelectedKeys/index.js +78 -0
  363. package/navigation/_story/DisabledNav/index.js +46 -0
  364. package/navigation/_story/ItemsChange/index.js +41 -0
  365. package/navigation/_story/LinkNav/index.jsx +90 -0
  366. package/navigation/_story/MountUnmount/index.js +57 -0
  367. package/navigation/_story/WithChildren/index.js +119 -0
  368. package/navigation/_story/WithRouter/index.js +111 -0
  369. package/navigation/_story/navigation.stories.js +330 -0
  370. package/navigation/_story/navigation.stories.tsx +101 -0
  371. package/navigation/index.tsx +427 -0
  372. package/navigation/nav-context.ts +9 -0
  373. package/notification/NoticeTransition.tsx +68 -0
  374. package/notification/__test__/notification.test.js +325 -0
  375. package/notification/_story/Demo.tsx +29 -0
  376. package/notification/_story/notification.stories.js +225 -0
  377. package/notification/_story/notification.stories.tsx +6 -0
  378. package/notification/_story/useNotification/context.js +3 -0
  379. package/notification/_story/useNotification/index.jsx +29 -0
  380. package/notification/index.tsx +265 -0
  381. package/notification/notice.tsx +185 -0
  382. package/notification/useNotification/HookNotice.tsx +36 -0
  383. package/notification/useNotification/index.tsx +94 -0
  384. package/overflowList/__test__/overflowList.test.js +31 -0
  385. package/overflowList/_story/Demo.tsx +36 -0
  386. package/overflowList/_story/overflowList.stories.js +356 -0
  387. package/overflowList/_story/overflowList.stories.tsx +7 -0
  388. package/overflowList/index.tsx +279 -0
  389. package/overflowList/intersectionObserver.tsx +93 -0
  390. package/package.json +2 -7
  391. package/pagination/__test__/pagination.test.js +255 -0
  392. package/pagination/_story/pagination.stories.js +148 -0
  393. package/pagination/_story/pagination.stories.tsx +11 -0
  394. package/pagination/index.tsx +450 -0
  395. package/popconfirm/__test__/popconfirm.test.js +131 -0
  396. package/popconfirm/_story/DynamicDisable/index.jsx +25 -0
  397. package/popconfirm/_story/InTable/index.js +75 -0
  398. package/popconfirm/_story/ShowArrow/index.jsx +141 -0
  399. package/popconfirm/_story/TitlePopconfirm/index.js +130 -0
  400. package/popconfirm/_story/TypesConfirm/index.jsx +121 -0
  401. package/popconfirm/_story/popconfirm.stories.js +170 -0
  402. package/popconfirm/_story/popconfirm.stories.tsx +20 -0
  403. package/popconfirm/index.tsx +239 -0
  404. package/popover/Arrow.tsx +66 -0
  405. package/popover/__test__/popover.test.js +52 -0
  406. package/popover/_story/ArrowPointAtCenter/index.jsx +138 -0
  407. package/popover/_story/BtnClose/index.jsx +80 -0
  408. package/popover/_story/NestedPopover/index.js +41 -0
  409. package/popover/_story/PopRight/index.js +25 -0
  410. package/popover/_story/PopRight/index.scss +25 -0
  411. package/popover/_story/SelectInPopover/index.jsx +38 -0
  412. package/popover/_story/popover.stories.js +574 -0
  413. package/popover/_story/popover.stories.tsx +53 -0
  414. package/popover/index.tsx +156 -0
  415. package/progress/__test__/progress.test.js +127 -0
  416. package/progress/_story/progress.stories.js +71 -0
  417. package/progress/_story/progress.stories.tsx +11 -0
  418. package/progress/index.tsx +245 -0
  419. package/radio/__test__/radio.test.jsx +91 -0
  420. package/radio/__test__/radioGroup.test.jsx +164 -0
  421. package/radio/_story/Demo.tsx +34 -0
  422. package/radio/_story/radio.scss +4 -0
  423. package/radio/_story/radio.stories.js +857 -0
  424. package/radio/_story/radio.stories.tsx +7 -0
  425. package/radio/context.ts +25 -0
  426. package/radio/index.tsx +12 -0
  427. package/radio/radio.tsx +244 -0
  428. package/radio/radioGroup.tsx +204 -0
  429. package/radio/radioInner.tsx +130 -0
  430. package/rating/__test__/rating.test.js +265 -0
  431. package/rating/_story/rating.stories.js +97 -0
  432. package/rating/_story/rating.stories.tsx +11 -0
  433. package/rating/index.tsx +283 -0
  434. package/rating/item.tsx +111 -0
  435. package/resizeObserver/index.tsx +115 -0
  436. package/scripts/compileDist.js +52 -0
  437. package/scripts/compileLib.js +13 -0
  438. package/scripts/compileScss.js +25 -0
  439. package/scrollList/__test__/scrollList.test.js +226 -0
  440. package/scrollList/_story/ScrollList/index.js +66 -0
  441. package/scrollList/_story/WheelList/index.js +116 -0
  442. package/scrollList/_story/scrolllist.stories.js +26 -0
  443. package/scrollList/_story/scrolllist.stories.tsx +131 -0
  444. package/scrollList/index.tsx +65 -0
  445. package/scrollList/scrollItem.tsx +509 -0
  446. package/select/__test__/select.test.js +1266 -0
  447. package/select/_story/CustomTrigger/index.jsx +21 -0
  448. package/select/_story/select.scss +51 -0
  449. package/select/_story/select.stories.js +2852 -0
  450. package/select/_story/select.stories.tsx +195 -0
  451. package/select/index.tsx +1121 -0
  452. package/select/option.tsx +157 -0
  453. package/select/optionGroup.tsx +42 -0
  454. package/select/utils.tsx +76 -0
  455. package/select/virtualRow.tsx +13 -0
  456. package/sideSheet/SideSheetContent.tsx +174 -0
  457. package/sideSheet/SideSheetTransition.tsx +104 -0
  458. package/sideSheet/__test__/sideSheet.test.js +319 -0
  459. package/sideSheet/_story/sideSheet.stories.js +379 -0
  460. package/sideSheet/_story/sideSheet.stories.tsx +48 -0
  461. package/sideSheet/index.tsx +268 -0
  462. package/skeleton/__test__/skeleton.test.js +32 -0
  463. package/skeleton/_story/skeleton.stories.js +82 -0
  464. package/skeleton/_story/skeleton.stories.tsx +61 -0
  465. package/skeleton/index.tsx +62 -0
  466. package/skeleton/item.tsx +82 -0
  467. package/slider/__test__/__snapshots__/slider.test.js.snap +5 -0
  468. package/slider/__test__/slider.test.js +155 -0
  469. package/slider/_story/Demo.scss +3 -0
  470. package/slider/_story/Demo.tsx +28 -0
  471. package/slider/_story/slider.stories.js +404 -0
  472. package/slider/_story/slider.stories.tsx +7 -0
  473. package/slider/index.tsx +561 -0
  474. package/space/__test__/space.test.js +99 -0
  475. package/space/_story/space.stories.js +254 -0
  476. package/space/_story/space.stories.tsx +26 -0
  477. package/space/index.tsx +95 -0
  478. package/space/utils.ts +24 -0
  479. package/spin/__test__/spin.test.js +46 -0
  480. package/spin/_story/Demo.tsx +10 -0
  481. package/spin/_story/spin.stories.js +92 -0
  482. package/spin/_story/spin.stories.tsx +6 -0
  483. package/spin/icon.tsx +54 -0
  484. package/spin/index.tsx +131 -0
  485. package/steps/__test__/steps.test.js +372 -0
  486. package/steps/_story/steps.stories.js +306 -0
  487. package/steps/_story/steps.stories.tsx +17 -0
  488. package/steps/basicStep.tsx +130 -0
  489. package/steps/basicSteps.tsx +110 -0
  490. package/steps/context.ts +7 -0
  491. package/steps/fillStep.tsx +113 -0
  492. package/steps/fillSteps.tsx +96 -0
  493. package/steps/index.tsx +69 -0
  494. package/steps/navStep.tsx +63 -0
  495. package/steps/navSteps.tsx +73 -0
  496. package/steps/step.tsx +37 -0
  497. package/switch/__test__/switch.test.js +128 -0
  498. package/switch/_story/switch.stories.js +160 -0
  499. package/switch/_story/switch.stories.tsx +124 -0
  500. package/switch/index.tsx +155 -0
  501. package/table/Body/BaseRow.tsx +361 -0
  502. package/table/Body/ExpandedRow.tsx +155 -0
  503. package/table/Body/SectionRow.tsx +200 -0
  504. package/table/Body/index.tsx +842 -0
  505. package/table/ColGroup.tsx +66 -0
  506. package/table/Column.tsx +17 -0
  507. package/table/ColumnFilter.tsx +203 -0
  508. package/table/ColumnSelection.tsx +88 -0
  509. package/table/ColumnShape.ts +33 -0
  510. package/table/ColumnSorter.tsx +58 -0
  511. package/table/CustomExpandIcon.tsx +95 -0
  512. package/table/HeadTable.tsx +118 -0
  513. package/table/ResizableHeaderCell.tsx +44 -0
  514. package/table/ResizableTable.tsx +176 -0
  515. package/table/Table.tsx +1384 -0
  516. package/table/TableCell.tsx +355 -0
  517. package/table/TableContextProvider.tsx +53 -0
  518. package/table/TableHeader.tsx +183 -0
  519. package/table/TableHeaderRow.tsx +180 -0
  520. package/table/TablePagination.tsx +52 -0
  521. package/table/__test__/table.test.js +1887 -0
  522. package/table/_story/BetterScrollbar.tsx +115 -0
  523. package/table/_story/ChildrenData/index.js +251 -0
  524. package/table/_story/ChildrenDataInnerSelected/index.js +221 -0
  525. package/table/_story/ChildrenDataSelected/index.js +247 -0
  526. package/table/_story/ControlledPagination/index.jsx +232 -0
  527. package/table/_story/ControlledSortOrder/index.jsx +85 -0
  528. package/table/_story/CustomComponents/index.js +101 -0
  529. package/table/_story/CustomExpandIcons/index.js +97 -0
  530. package/table/_story/CustomFilterDropdownItem/index.jsx +98 -0
  531. package/table/_story/DefaultSortOrder.tsx +120 -0
  532. package/table/_story/Demos/columnRender.jsx +131 -0
  533. package/table/_story/Demos/controlledPagination.jsx +125 -0
  534. package/table/_story/Demos/customFilter.jsx +110 -0
  535. package/table/_story/Demos/default.jsx +82 -0
  536. package/table/_story/Demos/dynamic.jsx +594 -0
  537. package/table/_story/Demos/expand.jsx +114 -0
  538. package/table/_story/Demos/filterAndSorter.jsx +102 -0
  539. package/table/_story/Demos/fixed.jsx +117 -0
  540. package/table/_story/Demos/fullRender.jsx +131 -0
  541. package/table/_story/Demos/group.jsx +109 -0
  542. package/table/_story/Demos/headerMerge.jsx +121 -0
  543. package/table/_story/Demos/headerMergeJSX.jsx +83 -0
  544. package/table/_story/Demos/infiniteScroll.jsx +118 -0
  545. package/table/_story/Demos/onRow.jsx +114 -0
  546. package/table/_story/Demos/pagination.jsx +101 -0
  547. package/table/_story/Demos/resizable copy.jsx +102 -0
  548. package/table/_story/Demos/resizable.jsx +183 -0
  549. package/table/_story/Demos/rowSelection.jsx +130 -0
  550. package/table/_story/Demos/sortTree.jsx +218 -0
  551. package/table/_story/Demos/sortable.jsx +183 -0
  552. package/table/_story/Demos/span.jsx +155 -0
  553. package/table/_story/Demos/tree.jsx +109 -0
  554. package/table/_story/Demos/treeSelect.jsx +196 -0
  555. package/table/_story/Demos/virtualized.jsx +103 -0
  556. package/table/_story/Demos/zebra.jsx +124 -0
  557. package/table/_story/DragableTable/index.jsx +156 -0
  558. package/table/_story/DragableTable/index.scss +7 -0
  559. package/table/_story/DynamicFilters/data.json +105 -0
  560. package/table/_story/DynamicFilters/index.js +81 -0
  561. package/table/_story/DynamicTable/index.jsx +569 -0
  562. package/table/_story/EventTable/index.jsx +76 -0
  563. package/table/_story/Expand/index.js +85 -0
  564. package/table/_story/ExpandAllGroupRows/index.jsx +90 -0
  565. package/table/_story/ExpandAllRows/index.jsx +111 -0
  566. package/table/_story/ExpandRowByClick.jsx +77 -0
  567. package/table/_story/FilterWithNewDataTable/index.jsx +108 -0
  568. package/table/_story/FixAllColumnsWithoutWidth.tsx +52 -0
  569. package/table/_story/FixRenderReturnProps.jsx +105 -0
  570. package/table/_story/FixedExpandedRows/index.js +105 -0
  571. package/table/_story/FixedGroups/index.js +80 -0
  572. package/table/_story/FixedTable/index.js +92 -0
  573. package/table/_story/FnTable/index.js +103 -0
  574. package/table/_story/FullRender/index.jsx +135 -0
  575. package/table/_story/GroupedCols/index.jsx +83 -0
  576. package/table/_story/GroupedColsFixed/index.jsx +95 -0
  577. package/table/_story/GroupedColsFixedJSX/index.jsx +122 -0
  578. package/table/_story/GroupedColsFixedVirtualized/index.jsx +107 -0
  579. package/table/_story/GroupedColsFixedVirtualizedGroups/index.jsx +110 -0
  580. package/table/_story/GroupedRows/index.js +83 -0
  581. package/table/_story/GroupedRowsFixed/index.js +81 -0
  582. package/table/_story/InSideSheet/index.jsx +90 -0
  583. package/table/_story/InfiniteScroll/index.js +115 -0
  584. package/table/_story/JSXAsyncData/index.jsx +47 -0
  585. package/table/_story/JSXColumnPropColumn.jsx +57 -0
  586. package/table/_story/JSXColumnsComplex.jsx +174 -0
  587. package/table/_story/JSXColumnsNest.tsx +74 -0
  588. package/table/_story/JSXColumnsSmiple.jsx +53 -0
  589. package/table/_story/JSXFixedTable/index.js +224 -0
  590. package/table/_story/JSXTitles/index.js +55 -0
  591. package/table/_story/LinkedScroll/index.jsx +137 -0
  592. package/table/_story/LinkedScroll/index.scss +0 -0
  593. package/table/_story/MassiveColumns/index.jsx +109 -0
  594. package/table/_story/MassiveColumns/index.scss +9 -0
  595. package/table/_story/ModalTable/index.jsx +228 -0
  596. package/table/_story/PagintaionTable/index.js +123 -0
  597. package/table/_story/Perf/Render/complex.jsx +191 -0
  598. package/table/_story/Perf/Render/context.jsx +72 -0
  599. package/table/_story/Perf/Render/controlledSelection.jsx +103 -0
  600. package/table/_story/Perf/Render/index.jsx +95 -0
  601. package/table/_story/Perf/Render/onRow.jsx +112 -0
  602. package/table/_story/Perf/Render/resizableSelection.jsx +193 -0
  603. package/table/_story/Perf/Virtualized/index.jsx +65 -0
  604. package/table/_story/Perf/index.js +8 -0
  605. package/table/_story/RTL/AlignScrollBar.jsx +17 -0
  606. package/table/_story/RTL/index.js +2 -0
  607. package/table/_story/RenderPagination/index.jsx +161 -0
  608. package/table/_story/ResizableColumns/index.jsx +95 -0
  609. package/table/_story/ResizableColumns/index.scss +30 -0
  610. package/table/_story/ResizableTable/index.jsx +85 -0
  611. package/table/_story/ScrollBar/index.jsx +71 -0
  612. package/table/_story/SelectedRows/index.js +137 -0
  613. package/table/_story/TableSpan/index.jsx +117 -0
  614. package/table/_story/TabsTable/index.jsx +78 -0
  615. package/table/_story/TestClone/index.js +0 -0
  616. package/table/_story/VirtualTableOnCell/index.jsx +84 -0
  617. package/table/_story/VirtualizedDynamicData/index.jsx +111 -0
  618. package/table/_story/VirtualizedGroupedRows/index.jsx +135 -0
  619. package/table/_story/VirtualizedNotFixed/index.js +89 -0
  620. package/table/_story/VritualizedDataSelected/index.js +273 -0
  621. package/table/_story/WarnColumnWithoutDataIndex.tsx +71 -0
  622. package/table/_story/WithSideSheet/index.js +82 -0
  623. package/table/_story/data/big.json +8205 -0
  624. package/table/_story/data/big2.json +42271 -0
  625. package/table/_story/table.stories.js +595 -0
  626. package/table/_story/table.stories.tsx +382 -0
  627. package/table/_story/virtualized/index.js +92 -0
  628. package/table/_story/virtualizedFixed/index.js +131 -0
  629. package/table/getColumns.tsx +34 -0
  630. package/table/index.tsx +44 -0
  631. package/table/interface.ts +320 -0
  632. package/table/table-context.ts +28 -0
  633. package/table/utils.ts +123 -0
  634. package/tabs/TabBar.tsx +248 -0
  635. package/tabs/TabPane.tsx +116 -0
  636. package/tabs/TabPaneTransition.tsx +67 -0
  637. package/tabs/__test__/tabs.test.js +208 -0
  638. package/tabs/_story/Demo.tsx +30 -0
  639. package/tabs/_story/search.jsx +37 -0
  640. package/tabs/_story/tabs.stories.js +797 -0
  641. package/tabs/_story/tabs.stories.tsx +6 -0
  642. package/tabs/index.tsx +300 -0
  643. package/tabs/interface.ts +83 -0
  644. package/tabs/tabs-context.ts +6 -0
  645. package/tag/_story/Demo.tsx +22 -0
  646. package/tag/_story/tag.stories.js +234 -0
  647. package/tag/_story/tag.stories.tsx +6 -0
  648. package/tag/group.tsx +131 -0
  649. package/tag/index.tsx +132 -0
  650. package/tag/interface.ts +48 -0
  651. package/tagInput/__test__/tagInput.test.js +352 -0
  652. package/tagInput/_story/tagInput.stories.js +414 -0
  653. package/tagInput/_story/tagInput.stories.tsx +24 -0
  654. package/tagInput/index.tsx +440 -0
  655. package/timePicker/Combobox.tsx +331 -0
  656. package/timePicker/PanelShape.ts +8 -0
  657. package/timePicker/TimeInput.tsx +205 -0
  658. package/timePicker/TimePicker.tsx +531 -0
  659. package/timePicker/TimeShape.ts +19 -0
  660. package/timePicker/__test__/timePicker.test.js +283 -0
  661. package/timePicker/_story/Callbacks/index.jsx +24 -0
  662. package/timePicker/_story/CustomTrigger/index.jsx +35 -0
  663. package/timePicker/_story/DisabledTime/index.jsx +17 -0
  664. package/timePicker/_story/timepicker.stories.js +264 -0
  665. package/timePicker/_story/timepicker.stories.tsx +18 -0
  666. package/timePicker/index.tsx +47 -0
  667. package/timeline/__test__/timeline.test.js +237 -0
  668. package/timeline/_story/timeline.stories.js +171 -0
  669. package/timeline/_story/timeline.stories.tsx +15 -0
  670. package/timeline/index.tsx +96 -0
  671. package/timeline/item.tsx +76 -0
  672. package/toast/ToastTransition.tsx +43 -0
  673. package/toast/__test__/toast-command-call.test.js +63 -0
  674. package/toast/__test__/toast.test.js +104 -0
  675. package/toast/_story/Demo.tsx +22 -0
  676. package/toast/_story/toast.stories.js +98 -0
  677. package/toast/_story/toast.stories.tsx +7 -0
  678. package/toast/index.tsx +234 -0
  679. package/toast/toast.tsx +148 -0
  680. package/toast/useToast/HookToast.tsx +35 -0
  681. package/toast/useToast/index.tsx +79 -0
  682. package/tooltip/ArrowBoundingShape.ts +8 -0
  683. package/tooltip/TooltipStyledTransition.tsx +30 -0
  684. package/tooltip/TriangleArrow.tsx +12 -0
  685. package/tooltip/TriangleArrowVertical.tsx +12 -0
  686. package/tooltip/__test__/tooltip.test.js +320 -0
  687. package/tooltip/_story/ArrowPointAtCenter/index.jsx +137 -0
  688. package/tooltip/_story/ContainerPosition/index.jsx +15 -0
  689. package/tooltip/_story/ContainerPosition/index.scss +10 -0
  690. package/tooltip/_story/CustomContainer/index.jsx +39 -0
  691. package/tooltip/_story/DangerousHtml/index.js +30 -0
  692. package/tooltip/_story/Edge/index.js +16 -0
  693. package/tooltip/_story/InTable/index.jsx +86 -0
  694. package/tooltip/_story/Safari/autoAdjust.js +23 -0
  695. package/tooltip/_story/ScrollDemo/index.js +65 -0
  696. package/tooltip/_story/story.scss +50 -0
  697. package/tooltip/_story/tooltip.stories.js +690 -0
  698. package/tooltip/_story/tooltip.stories.tsx +54 -0
  699. package/tooltip/index.tsx +646 -0
  700. package/transfer/__test__/transfer.test.js +324 -0
  701. package/transfer/_story/transfer.scss +124 -0
  702. package/transfer/_story/transfer.stories.js +758 -0
  703. package/transfer/_story/transfer.stories.tsx +80 -0
  704. package/transfer/index.tsx +652 -0
  705. package/tree/__test__/autosizer.test.js +102 -0
  706. package/tree/__test__/tree.test.js +842 -0
  707. package/tree/__test__/treeMultiple.test.js +593 -0
  708. package/tree/__test__/treeNodeProps.test.js +192 -0
  709. package/tree/_story/BigData.jsx +58 -0
  710. package/tree/_story/Demo.tsx +72 -0
  711. package/tree/_story/bigDataGen.jsx +98 -0
  712. package/tree/_story/data.js +3 -0
  713. package/tree/_story/tree.stories.js +2172 -0
  714. package/tree/_story/tree.stories.tsx +7 -0
  715. package/tree/autoSizer.tsx +86 -0
  716. package/tree/collapse.tsx +144 -0
  717. package/tree/index.tsx +754 -0
  718. package/tree/interface.ts +141 -0
  719. package/tree/nodeList.tsx +87 -0
  720. package/tree/treeContext.tsx +49 -0
  721. package/tree/treeNode.tsx +401 -0
  722. package/tree/treeUtil.tsx +14 -0
  723. package/treeSelect/__test__/treeMultiple.test.js +676 -0
  724. package/treeSelect/__test__/treeSelect.test.js +783 -0
  725. package/treeSelect/_story/CustomTrigger/index.jsx +47 -0
  726. package/treeSelect/_story/Demo.tsx +83 -0
  727. package/treeSelect/_story/treeSelect.stories.js +1155 -0
  728. package/treeSelect/_story/treeSelect.stories.tsx +7 -0
  729. package/treeSelect/index.tsx +1288 -0
  730. package/trigger/__test__/trigger.test.js +17 -0
  731. package/trigger/index.tsx +45 -0
  732. package/tsconfig.json +32 -0
  733. package/typography/__test__/typography.test.js +74 -0
  734. package/typography/_story/typography.stories.js +629 -0
  735. package/typography/_story/typography.stories.tsx +175 -0
  736. package/typography/base.tsx +628 -0
  737. package/typography/copyable.tsx +135 -0
  738. package/typography/index.tsx +24 -0
  739. package/typography/interface.ts +27 -0
  740. package/typography/paragraph.tsx +77 -0
  741. package/typography/text.tsx +68 -0
  742. package/typography/title.tsx +74 -0
  743. package/typography/typography.tsx +41 -0
  744. package/typography/util.tsx +141 -0
  745. package/upload/__test__/dragUpload.test.js +122 -0
  746. package/upload/__test__/upload.test.js +896 -0
  747. package/upload/_story/upload.stories.js +943 -0
  748. package/upload/_story/upload.stories.tsx +13 -0
  749. package/upload/fileCard.tsx +270 -0
  750. package/upload/index.tsx +538 -0
  751. package/upload/interface.ts +59 -0
  752. package/webpack.config.js +86 -0
@@ -0,0 +1,1384 @@
1
+ /* eslint-disable no-nested-ternary */
2
+ /* eslint-disable prefer-const */
3
+ /* eslint-disable prefer-destructuring */
4
+ /* eslint-disable no-shadow */
5
+ /* eslint-disable no-param-reassign */
6
+ /* eslint-disable max-len */
7
+ /* eslint-disable react/no-did-update-set-state */
8
+ /* eslint-disable eqeqeq */
9
+ /* eslint-disable max-lines-per-function */
10
+ import React, { ReactNode, createRef, isValidElement } from 'react';
11
+ import PropTypes from 'prop-types';
12
+ import classnames from 'classnames';
13
+ import {
14
+ get,
15
+ noop,
16
+ includes,
17
+ find,
18
+ findIndex,
19
+ some,
20
+ debounce,
21
+ flattenDeep,
22
+ each,
23
+ omit,
24
+ isNull,
25
+ difference,
26
+ isFunction,
27
+ isObject
28
+ } from 'lodash';
29
+
30
+ import {
31
+ mergeQueries,
32
+ equalWith,
33
+ mergeColumns,
34
+ isAnyFixedRight,
35
+ assignColumnKeys,
36
+ flattenColumns,
37
+ getAllDisabledRowKeys
38
+ } from '@douyinfe/semi-foundation/table/utils';
39
+ import Store from '@douyinfe/semi-foundation/utils/Store';
40
+ import TableFoundation, { TableAdapter, BasePageData, BaseRowKeyType, BaseHeadWidth } from '@douyinfe/semi-foundation/table/foundation';
41
+ import { TableSelectionCellEvent } from '@douyinfe/semi-foundation/table/tableSelectionCellFoundation';
42
+ import { strings, cssClasses, numbers } from '@douyinfe/semi-foundation/table/constants';
43
+ import '@douyinfe/semi-foundation/table/table.scss';
44
+
45
+ import Spin from '../spin';
46
+ import BaseComponent from '../_base/baseComponent';
47
+ import LocaleConsumer from '../locale/localeConsumer';
48
+ import ColumnShape from './ColumnShape';
49
+ import getColumns from './getColumns';
50
+ import TableContext, { TableContextProps } from './table-context';
51
+ import TableContextProvider from './TableContextProvider';
52
+ import ColumnSelection from './ColumnSelection';
53
+ import TablePagination from './TablePagination';
54
+ import ColumnFilter, { OnSelectData } from './ColumnFilter';
55
+ import ColumnSorter from './ColumnSorter';
56
+ import ExpandedIcon from './CustomExpandIcon';
57
+ import HeadTable, { HeadTableProps } from './HeadTable';
58
+ import BodyTable, { BodyProps } from './Body';
59
+ import { measureScrollbar, logger, cloneDeep, mergeComponents } from './utils';
60
+ import {
61
+ ColumnProps,
62
+ TablePaginationProps,
63
+ BodyScrollEvent,
64
+ BodyScrollPosition,
65
+ ExpandIcon,
66
+ ColumnTitleProps,
67
+ Pagination,
68
+ RenderPagination,
69
+ TableLocale,
70
+ TableProps,
71
+ TableComponents,
72
+ RowSelectionProps,
73
+ Data
74
+ } from './interface';
75
+ import { ArrayElement } from '../_base/base';
76
+
77
+ export type NormalTableProps<RecordType extends Record<string, any> = Data> = Omit<TableProps<RecordType>, 'resizable'>;
78
+
79
+ export interface NormalTableState<RecordType extends Record<string, any> = Data> {
80
+ cachedColumns?: ColumnProps<RecordType>[];
81
+ cachedChildren?: React.ReactNode;
82
+ flattenColumns?: ColumnProps<RecordType>[];
83
+ components?: TableComponents;
84
+ queries?: ColumnProps<RecordType>[];
85
+ dataSource?: RecordType[];
86
+ flattenData?: RecordType[];
87
+ expandedRowKeys?: (string | number)[];
88
+ rowSelection?: TableStateRowSelection<RecordType>;
89
+ pagination?: Pagination;
90
+ groups?: Map<string, RecordType[]>;
91
+ allRowKeys?: (string | number)[];
92
+ disabledRowKeys?: (string | number)[];
93
+ disabledRowKeysSet?: Set<string | number>;
94
+ headWidths?: Array<Array<BaseHeadWidth>>;
95
+ bodyHasScrollBar?: boolean;
96
+ prePropRowSelection?: TableStateRowSelection<RecordType>;
97
+ tableWidth?: number;
98
+ }
99
+
100
+ export type TableStateRowSelection<RecordType extends Record<string, any> = Data> = (RowSelectionProps<RecordType> & { selectedRowKeysSet?: Set<(string | number)> }) | boolean;
101
+
102
+ export interface RenderTableProps<RecordType> extends HeadTableProps, BodyProps {
103
+ filteredColumns: ColumnProps<RecordType>[];
104
+ useFixedHeader: boolean;
105
+ bodyRef: React.MutableRefObject<HTMLDivElement> | ((instance: any) => void);
106
+ rowSelection: TableStateRowSelection<RecordType>;
107
+ bodyHasScrollBar: boolean;
108
+ }
109
+
110
+ class Table<RecordType extends Record<string, any>> extends BaseComponent<NormalTableProps<RecordType>, NormalTableState<RecordType>> {
111
+ static contextType = TableContext;
112
+
113
+ static propTypes = {
114
+ className: PropTypes.string,
115
+ style: PropTypes.object,
116
+ prefixCls: PropTypes.string,
117
+ components: PropTypes.any,
118
+ bordered: PropTypes.bool,
119
+ loading: PropTypes.bool,
120
+ size: PropTypes.oneOf(strings.SIZES),
121
+ tableLayout: PropTypes.oneOf(strings.LAYOUTS),
122
+ columns: PropTypes.arrayOf(PropTypes.shape(ColumnShape)),
123
+ hideExpandedColumn: PropTypes.bool,
124
+ id: PropTypes.string,
125
+ expandIcon: PropTypes.oneOfType([PropTypes.bool, PropTypes.func, PropTypes.node]),
126
+ expandCellFixed: PropTypes.oneOf(strings.FIXED_SET),
127
+ title: PropTypes.oneOfType([PropTypes.string, PropTypes.node, PropTypes.func]),
128
+ onHeaderRow: PropTypes.func,
129
+ showHeader: PropTypes.bool,
130
+ indentSize: PropTypes.number,
131
+ rowKey: PropTypes.oneOfType([PropTypes.func, PropTypes.string, PropTypes.number]),
132
+ onRow: PropTypes.func,
133
+ onExpandedRowsChange: PropTypes.func,
134
+ onExpand: PropTypes.func,
135
+ rowExpandable: PropTypes.func,
136
+ expandedRowRender: PropTypes.func,
137
+ expandedRowKeys: PropTypes.array,
138
+ defaultExpandAllRows: PropTypes.bool,
139
+ expandAllRows: PropTypes.bool,
140
+ defaultExpandAllGroupRows: PropTypes.bool,
141
+ expandAllGroupRows: PropTypes.bool,
142
+ defaultExpandedRowKeys: PropTypes.array,
143
+ pagination: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
144
+ renderPagination: PropTypes.func,
145
+ footer: PropTypes.oneOfType([PropTypes.func, PropTypes.string, PropTypes.node]),
146
+ empty: PropTypes.node,
147
+ dataSource: PropTypes.array,
148
+ childrenRecordName: PropTypes.string, // children data property name
149
+ rowSelection: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
150
+ onChange: PropTypes.func,
151
+ scroll: PropTypes.shape({
152
+ x: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.bool]),
153
+ y: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
154
+ }),
155
+ groupBy: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.func]),
156
+ renderGroupSection: PropTypes.oneOfType([PropTypes.func]),
157
+ onGroupedRow: PropTypes.func,
158
+ clickGroupedRowToExpand: PropTypes.bool,
159
+ virtualized: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
160
+ dropdownPrefixCls: PropTypes.string, // TODO: future api
161
+ expandRowByClick: PropTypes.bool, // TODO: future api
162
+ getVirtualizedListRef: PropTypes.func, // TODO: future api
163
+ };
164
+
165
+ static defaultProps = {
166
+ // rowExpandable: stubTrue,
167
+ tableLayout: '',
168
+ dataSource: [] as [],
169
+ prefixCls: cssClasses.PREFIX,
170
+ rowSelection: null as null,
171
+ className: '',
172
+ childrenRecordName: 'children',
173
+ size: 'default',
174
+ loading: false,
175
+ bordered: false,
176
+ expandCellFixed: false,
177
+ hideExpandedColumn: true,
178
+ showHeader: true,
179
+ indentSize: numbers.DEFAULT_INDENT_WIDTH,
180
+ onChange: noop,
181
+ pagination: true,
182
+ rowKey: 'key',
183
+ defaultExpandedRowKeys: [] as [],
184
+ defaultExpandAllRows: false,
185
+ defaultExpandAllGroupRows: false,
186
+ expandAllRows: false,
187
+ expandAllGroupRows: false,
188
+ onFilterDropdownVisibleChange: noop,
189
+ onExpand: noop,
190
+ onExpandedRowsChange: noop,
191
+ expandRowByClick: false,
192
+ };
193
+
194
+ get adapter(): TableAdapter<RecordType> {
195
+ return {
196
+ ...super.adapter,
197
+ resetScrollY: () => {
198
+ if (this.bodyWrapRef.current) {
199
+ this.bodyWrapRef.current.scrollTop = 0;
200
+ }
201
+ },
202
+ setSelectedRowKeys: selectedRowKeys => {
203
+ this.setState({ rowSelection: {
204
+ ...this.state.rowSelection as Record<string, any>,
205
+ selectedRowKeys: [...selectedRowKeys],
206
+ selectedRowKeysSet: new Set(selectedRowKeys),
207
+ } });
208
+ },
209
+ setDisabledRowKeys: disabledRowKeys => {
210
+ this.setState({ disabledRowKeys, disabledRowKeysSet: new Set(disabledRowKeys) });
211
+ },
212
+ setCurrentPage: currentPage => {
213
+ const { pagination } = this.state;
214
+ if (typeof pagination === 'object') {
215
+ this.setState({ pagination: { ...pagination, currentPage } });
216
+ } else {
217
+ this.setState({ pagination: { currentPage } });
218
+ }
219
+ },
220
+ setPagination: pagination => this.setState({ pagination }),
221
+ setGroups: groups => this.setState({ groups }),
222
+ setDataSource: dataSource => this.setState({ dataSource }),
223
+ setExpandedRowKeys: expandedRowKeys => this.setState({ expandedRowKeys: [...expandedRowKeys] }),
224
+ setQuery: (query = {}) => {
225
+ let queries = [...this.state.queries];
226
+ queries = mergeQueries(query, queries);
227
+ this.setState({ queries });
228
+ },
229
+ // Update queries when filtering or sorting
230
+ setQueries: (queries: ColumnProps<RecordType>[]) => this.setState({ queries }),
231
+ setFlattenData: flattenData => this.setState({ flattenData }),
232
+ setAllRowKeys: allRowKeys => this.setState({ allRowKeys }),
233
+ setHoveredRowKey: hoveredRowKey => {
234
+ this.store.setState({ hoveredRowKey });
235
+ },
236
+ setCachedFilteredSortedDataSource: filteredSortedDataSource => {
237
+ this.cachedFilteredSortedDataSource = filteredSortedDataSource;
238
+ },
239
+ setCachedFilteredSortedRowKeys: filteredSortedRowKeys => {
240
+ this.cachedFilteredSortedRowKeys = filteredSortedRowKeys;
241
+ this.cachedFilteredSortedRowKeysSet = new Set(filteredSortedRowKeys);
242
+ },
243
+ getCurrentPage: () => get(this.state, 'pagination.currentPage', 1),
244
+ getCurrentPageSize: () => get(this.state, 'pagination.pageSize', numbers.DEFAULT_PAGE_SIZE),
245
+ getCachedFilteredSortedDataSource: () => this.cachedFilteredSortedDataSource,
246
+ getCachedFilteredSortedRowKeys: () => this.cachedFilteredSortedRowKeys,
247
+ getCachedFilteredSortedRowKeysSet: () => this.cachedFilteredSortedRowKeysSet,
248
+ notifyFilterDropdownVisibleChange: (visible, dataIndex) =>
249
+ this._invokeColumnFn(dataIndex, 'onFilterDropdownVisibleChange', visible),
250
+ notifyChange: (...args) => this.props.onChange(...args),
251
+ notifyExpand: (...args) => this.props.onExpand(...args),
252
+ notifyExpandedRowsChange: (...args) => this.props.onExpandedRowsChange(...args),
253
+ notifySelect: (...args) => this._invokeRowSelection('onSelect', ...args),
254
+ notifySelectAll: (...args) => this._invokeRowSelection('onSelectAll', ...args),
255
+ notifySelectInvert: (...args) => this._invokeRowSelection('onSelectInvert', ...args),
256
+ notifySelectionChange: (...args) => this._invokeRowSelection('onChange', ...args),
257
+ isAnyColumnFixed: (columns: ColumnProps<RecordType>[]) =>
258
+ some(this.getColumns(columns || this.props.columns, this.props.children), column => Boolean(column.fixed)),
259
+ useFixedHeader: () => {
260
+ const { scroll } = this.props;
261
+
262
+ if (get(scroll, 'y')) {
263
+ return true;
264
+ }
265
+
266
+ return false;
267
+ },
268
+ setHeadWidths: (headWidths: Array<BaseHeadWidth>, index = 0) => {
269
+ if (!equalWith(this.state.headWidths[index], headWidths)) {
270
+ // The map call depends on the last state
271
+ this.setState(state => {
272
+ const newHeadWidths: Array<Array<BaseHeadWidth>> = [...state.headWidths];
273
+ newHeadWidths[index] = [...headWidths];
274
+ return { headWidths: newHeadWidths };
275
+ });
276
+ }
277
+ },
278
+ getHeadWidths: (index = 0) => {
279
+ if (this.state.headWidths.length && typeof index === 'number') {
280
+ const configs = this.state.headWidths[index] || [];
281
+ return configs.map(item => item.width);
282
+ }
283
+ return [];
284
+ },
285
+ // This method is called by row rendering function
286
+ getCellWidths: (flattenedColumns: ColumnProps<RecordType>[], flattenedWidths: BaseHeadWidth[] = null, ignoreScrollBarKey = false): number[] => {
287
+ if (Array.isArray(flattenedColumns) && flattenedColumns.length) {
288
+ flattenedWidths =
289
+ flattenedWidths == null && this.state.headWidths.length ?
290
+ flattenDeep(this.state.headWidths) :
291
+ [];
292
+ if (
293
+ Array.isArray(flattenedWidths) &&
294
+ flattenedWidths.length
295
+ ) {
296
+ return flattenedColumns.reduce((result, column) => {
297
+ const found =
298
+ column.key === strings.DEFAULT_KEY_COLUMN_SCROLLBAR && ignoreScrollBarKey ?
299
+ null :
300
+ find(
301
+ flattenedWidths,
302
+ item => item && item.key != null && item.key === column.key
303
+ );
304
+ if (found) {
305
+ result.push(found.width);
306
+ }
307
+
308
+ return result;
309
+ }, [] as number[]);
310
+ }
311
+ }
312
+ return [];
313
+ },
314
+ mergedRowExpandable: record => {
315
+ const { expandedRowRender, childrenRecordName, rowExpandable } = this.props;
316
+ const children = get(record, childrenRecordName);
317
+ const hasExpandedRowRender = typeof expandedRowRender === 'function';
318
+ const hasRowExpandable = typeof rowExpandable === 'function';
319
+ const hasChildren = Array.isArray(children) && children.length;
320
+ const strictExpandableResult = hasRowExpandable && rowExpandable(record);
321
+ const looseExpandableResult = !hasRowExpandable || strictExpandableResult;
322
+
323
+ return (
324
+ ((hasExpandedRowRender || hasChildren) && looseExpandableResult) ||
325
+ (!(hasExpandedRowRender || hasChildren) && strictExpandableResult)
326
+ );
327
+ },
328
+ isAnyColumnUseFullRender: (columns: ColumnProps<RecordType>[]) =>
329
+ some(columns, column => Boolean(column.useFullRender)),
330
+ getNormalizeColumns: () => this.normalizeColumns,
331
+ getHandleColumns: () => this.handleColumns,
332
+ getMergePagination: () => this.mergePagination,
333
+ setBodyHasScrollbar: bodyHasScrollBar => {
334
+ if (bodyHasScrollBar !== this.state.bodyHasScrollBar) {
335
+ this.setState({ bodyHasScrollBar });
336
+ }
337
+ }
338
+ };
339
+ }
340
+
341
+ bodyWrapRef: React.MutableRefObject<HTMLDivElement>;
342
+ rootWrapRef: React.MutableRefObject<HTMLDivElement>;
343
+ wrapRef: React.MutableRefObject<HTMLDivElement>;
344
+ headerWrapRef: React.MutableRefObject<HTMLDivElement>;
345
+ debouncedWindowResize: () => void;
346
+ cachedFilteredSortedDataSource: RecordType[];
347
+ cachedFilteredSortedRowKeys: BaseRowKeyType[];
348
+ cachedFilteredSortedRowKeysSet: Set<string | number>;
349
+ store: Store;
350
+ lastScrollTop!: number;
351
+ lastScrollLeft!: number;
352
+ scrollPosition!: BodyScrollPosition;
353
+ position!: BodyScrollPosition;
354
+ foundation: TableFoundation<RecordType>;
355
+ constructor(props: NormalTableProps<RecordType>, context: TableContextProps) {
356
+ super(props);
357
+ this.foundation = new TableFoundation<RecordType>(this.adapter);
358
+ // columns cannot be deepClone, otherwise the comparison will be false
359
+ const columns = this.getColumns(props.columns, props.children);
360
+ const cachedflattenColumns = flattenColumns(columns);
361
+ this.state = {
362
+ /**
363
+ * Cached props
364
+ */
365
+ cachedColumns: columns, // update cachedColumns after columns or children change
366
+ cachedChildren: props.children,
367
+ flattenColumns: cachedflattenColumns,
368
+ components: mergeComponents(props.components, props.virtualized), // cached components
369
+
370
+ /**
371
+ * State calculated based on prop
372
+ */
373
+ queries: cloneDeep(cachedflattenColumns), // flatten columns, update when sorting or filtering
374
+ dataSource: [], // data after paging
375
+ flattenData: [],
376
+ expandedRowKeys: [...(props.expandedRowKeys || []), ...(props.defaultExpandedRowKeys || [])], // cached expandedRowKeys
377
+ rowSelection: props.rowSelection ? isObject(props.rowSelection) ? { ...props.rowSelection } : {} : null,
378
+ pagination:
379
+ props.pagination && typeof props.pagination === 'object' ?
380
+ { ...props.pagination } :
381
+ props.pagination || false,
382
+
383
+ /**
384
+ * Internal state
385
+ */
386
+ groups: null,
387
+ allRowKeys: [], // row keys after paging
388
+ disabledRowKeys: [], // disabled row keys after paging
389
+ disabledRowKeysSet: new Set(),
390
+ headWidths: [], // header cell width
391
+ bodyHasScrollBar: false,
392
+ prePropRowSelection: undefined,
393
+ };
394
+
395
+ this.rootWrapRef = createRef();
396
+ this.wrapRef = createRef(); // table's outside wrap
397
+
398
+ this.bodyWrapRef = createRef();
399
+ this.headerWrapRef = createRef();
400
+
401
+ this.store = new Store({
402
+ hoveredRowKey: null,
403
+ });
404
+
405
+ this.setScrollPosition('left');
406
+ this.debouncedWindowResize = debounce(this.handleWindowResize, 150);
407
+
408
+ this.cachedFilteredSortedDataSource = [];
409
+ this.cachedFilteredSortedRowKeys = [];
410
+ this.cachedFilteredSortedRowKeysSet = new Set();
411
+ }
412
+
413
+ static getDerivedStateFromProps(props: NormalTableProps, state: NormalTableState) {
414
+ const willUpdateStates: Partial<NormalTableState> = {};
415
+ const { rowSelection, dataSource, childrenRecordName, rowKey } = props;
416
+ props.columns && props.children && logger.warn('columns should not given by object and children at the same time');
417
+
418
+ if (props.columns && props.columns !== state.cachedColumns) {
419
+ const newFlattenColumns = flattenColumns(props.columns);
420
+ willUpdateStates.flattenColumns = newFlattenColumns;
421
+ willUpdateStates.queries = mergeColumns(state.queries, newFlattenColumns, null, false);
422
+ willUpdateStates.cachedColumns = props.columns;
423
+ willUpdateStates.cachedChildren = null;
424
+ } else if (props.children && props.children !== state.cachedChildren) {
425
+ const newFlattenColumns = flattenColumns(getColumns(props.children));
426
+ const columns = mergeColumns(state.queries, newFlattenColumns, null, false);
427
+ willUpdateStates.flattenColumns = newFlattenColumns;
428
+ willUpdateStates.queries = [...columns];
429
+ willUpdateStates.cachedColumns = [...columns];
430
+ willUpdateStates.cachedChildren = props.children;
431
+ }
432
+
433
+ // Update controlled selection column
434
+ if (rowSelection !== state.prePropRowSelection) {
435
+ let newSelectionStates: TableStateRowSelection = {};
436
+ if (isObject(state.rowSelection)) {
437
+ newSelectionStates = { ...newSelectionStates, ...state.rowSelection };
438
+ }
439
+ if (isObject(rowSelection)) {
440
+ newSelectionStates = { ...newSelectionStates, ...rowSelection };
441
+ }
442
+ const selectedRowKeys = get(rowSelection, 'selectedRowKeys');
443
+ const getCheckboxProps = get(rowSelection, 'getCheckboxProps');
444
+ if (selectedRowKeys && Array.isArray(selectedRowKeys)) {
445
+ newSelectionStates.selectedRowKeysSet = new Set(selectedRowKeys);
446
+ }
447
+ // The return value of getCheckboxProps affects the disabled rows
448
+ if (isFunction(getCheckboxProps)) {
449
+ const disabledRowKeys = getAllDisabledRowKeys({ dataSource, getCheckboxProps, childrenRecordName, rowKey });
450
+ willUpdateStates.disabledRowKeys = disabledRowKeys;
451
+ willUpdateStates.disabledRowKeysSet = new Set(disabledRowKeys);
452
+ }
453
+ willUpdateStates.rowSelection = newSelectionStates;
454
+ willUpdateStates.prePropRowSelection = rowSelection;
455
+ }
456
+ return willUpdateStates;
457
+ }
458
+
459
+ componentDidMount() {
460
+ super.componentDidMount();
461
+
462
+ if (this.adapter.isAnyColumnFixed() || (this.props.showHeader && this.adapter.useFixedHeader())) {
463
+ this.handleWindowResize();
464
+ window.addEventListener('resize', this.debouncedWindowResize);
465
+ }
466
+ }
467
+
468
+ // TODO: Extract the setState operation to the adapter or getDerivedStateFromProps function
469
+ componentDidUpdate(prevProps: NormalTableProps<RecordType>, prevState: NormalTableState<RecordType>) {
470
+ const {
471
+ pagination,
472
+ dataSource,
473
+ expandedRowKeys,
474
+ expandAllRows,
475
+ expandAllGroupRows,
476
+ virtualized,
477
+ components,
478
+ } = this.props;
479
+
480
+ const {
481
+ queries: stateQueries,
482
+ cachedColumns: stateCachedColumns,
483
+ cachedChildren: stateCachedChildren,
484
+ groups: stateGroups,
485
+ } = this.state;
486
+
487
+ /**
488
+ * State related to paging
489
+ *
490
+ * @param dataSource
491
+ * @param groups
492
+ * @param pagination
493
+ * @param disabledRowKeys
494
+ * @param allRowKeys
495
+ * @param queries
496
+ */
497
+ const states: Partial<NormalTableState<RecordType>> = {};
498
+
499
+ this._warnIfNoKey();
500
+
501
+ /**
502
+ * The state that needs to be updated after props changes
503
+ */
504
+
505
+ // Update controlled expand column
506
+ if (Array.isArray(expandedRowKeys) && expandedRowKeys !== prevProps.expandedRowKeys) {
507
+ this.setState({ expandedRowKeys });
508
+ }
509
+
510
+ // Update components
511
+ if (components !== prevProps.components || virtualized !== prevProps.virtualized) {
512
+ this.setState({ components: mergeComponents(components, virtualized) });
513
+ }
514
+
515
+ // Update the default expanded column
516
+ if (
517
+ expandAllRows !== prevProps.expandAllRows ||
518
+ expandAllGroupRows !== prevProps.expandAllGroupRows
519
+ ) {
520
+ this.foundation.initExpandedRowKeys({ groups: stateGroups });
521
+ }
522
+
523
+
524
+ // Update pagination
525
+ if (pagination !== prevProps.pagination) {
526
+ states.pagination = isObject(pagination) ? { ...pagination } : pagination;
527
+ }
528
+
529
+ /**
530
+ * After dataSource is updated || (cachedColumns || cachedChildren updated)
531
+ * 1. Cache filtered sorted data and a collection of data rows, stored in this
532
+ * 2. Update pager and group, stored in state
533
+ */
534
+ if (dataSource !== prevProps.dataSource || stateCachedColumns !== prevState.cachedColumns || stateCachedChildren !== prevState.cachedChildren) {
535
+ // TODO: foundation.getFilteredSortedDataSource has side effects and will be modified to the dataSource reference
536
+ // Temporarily use _dataSource=[...dataSource] for processing
537
+ const _dataSource = [...dataSource];
538
+ const filteredSortedDataSource = this.foundation.getFilteredSortedDataSource(_dataSource, stateQueries);
539
+ this.foundation.setCachedFilteredSortedDataSource(filteredSortedDataSource);
540
+ states.dataSource = filteredSortedDataSource;
541
+
542
+ if (pagination === prevProps.pagination) {
543
+ states.pagination = isObject(pagination) ? { ...pagination } : pagination;
544
+ }
545
+
546
+ if (this.props.groupBy) {
547
+ states.groups = null;
548
+ }
549
+ }
550
+
551
+ if (Object.keys(states).length) {
552
+ const {
553
+ // eslint-disable-next-line @typescript-eslint/no-shadow
554
+ queries: stateQueries = null,
555
+ pagination: statePagination = null,
556
+ dataSource: stateDataSource = null,
557
+ } = states;
558
+ const handledProps: Partial<NormalTableState<RecordType>> = this.foundation.getCurrentPageData(stateDataSource, statePagination as TablePaginationProps, stateQueries);
559
+
560
+ // After the pager is updated, reset allRowKeys of the current page
561
+ this.adapter.setAllRowKeys(handledProps.allRowKeys);
562
+ this.adapter.setDisabledRowKeys(handledProps.disabledRowKeys);
563
+
564
+ if ('dataSource' in states) {
565
+ if (this.props.defaultExpandAllRows && handledProps.groups && handledProps.groups.size ||
566
+ this.props.expandAllRows ||
567
+ this.props.expandAllGroupRows
568
+ ) {
569
+ this.foundation.initExpandedRowKeys(handledProps);
570
+ }
571
+ }
572
+
573
+ // Centrally update paging related state
574
+ const statesKeys: any[] = Object.keys(states);
575
+ for (const k of statesKeys) {
576
+ this.setState({ [k]: handledProps[k] });
577
+ }
578
+ }
579
+
580
+ if (this.adapter.isAnyColumnFixed() || (this.props.showHeader && this.adapter.useFixedHeader())) {
581
+ if (!this.debouncedWindowResize) {
582
+ window.addEventListener('resize', this.debouncedWindowResize);
583
+ }
584
+ }
585
+ }
586
+
587
+ componentWillUnmount() {
588
+ super.componentWillUnmount();
589
+
590
+ if (this.debouncedWindowResize) {
591
+ window.removeEventListener('resize', this.debouncedWindowResize);
592
+ (this.debouncedWindowResize as any).cancel();
593
+ this.debouncedWindowResize = null;
594
+ }
595
+ }
596
+
597
+ // TODO: notify when data don't have key
598
+ _warnIfNoKey = () => {
599
+ if (
600
+ (this.props.rowSelection || this.props.expandedRowRender) &&
601
+ some(this.props.dataSource, record => this.foundation.getRecordKey(record) == null)
602
+ ) {
603
+ logger.error(
604
+ 'You must specify a key for each element in the dataSource or use "rowKey" to specify an attribute name as the primary key!'
605
+ );
606
+ }
607
+ };
608
+
609
+ _invokeRowSelection = (funcName: string, ...args: any[]) => {
610
+ const func = get(this.state, ['rowSelection', funcName]);
611
+
612
+ if (typeof func === 'function') {
613
+ func(...args);
614
+ }
615
+ };
616
+
617
+ _invokeColumnFn = (key: string, funcName: string, ...args: any[]) => {
618
+ if (key && funcName) {
619
+ const column = this.foundation.getQuery(key);
620
+ const func = get(column, funcName, null);
621
+
622
+ if (typeof func === 'function') {
623
+ func(...args);
624
+ }
625
+ }
626
+ };
627
+
628
+ _cacheHeaderRef = (node: HTMLDivElement) => {
629
+ this.headerWrapRef.current = node;
630
+ };
631
+
632
+ getCurrentPageData = () => {
633
+ const pageData = this.foundation.getCurrentPageData();
634
+ const retObj = ['dataSource', 'groups'].reduce((result, key) => {
635
+ if (pageData[key]) {
636
+ result[key] = pageData[key];
637
+ }
638
+ return result;
639
+ }, {});
640
+
641
+ return cloneDeep(retObj);
642
+ };
643
+
644
+ getColumns = (columns: ColumnProps<RecordType>[], children: ReactNode) => (!Array.isArray(columns) || !columns || !columns.length ? getColumns(children) : columns);
645
+
646
+ // @ts-ignore
647
+ getCellWidths = (...args: any[]) => this.foundation.getCellWidths(...args);
648
+ // @ts-ignore
649
+ setHeadWidths = (...args: any[]) => this.foundation.setHeadWidths(...args);
650
+ // @ts-ignore
651
+ getHeadWidths = (...args: any[]) => this.foundation.getHeadWidths(...args);
652
+ // @ts-ignore
653
+ mergedRowExpandable = (...args: any[]) => this.foundation.mergedRowExpandable(...args);
654
+ // @ts-ignore
655
+ setBodyHasScrollbar = (...args: any[]) => this.foundation.setBodyHasScrollbar(...args);
656
+
657
+ handleWheel = (event: React.WheelEvent<HTMLDivElement>) => {
658
+ const { scroll = {} } = this.props;
659
+ if (window.navigator.userAgent.match(/Trident\/7\./) && scroll.y) {
660
+ event.preventDefault();
661
+ const wd = event.deltaY;
662
+ const { target } = event;
663
+ // const { bodyTable, fixedColumnsBodyLeft, fixedColumnsBodyRight } = this;
664
+ const bodyTable = this.bodyWrapRef.current;
665
+
666
+ let scrollTop = 0;
667
+
668
+ if (this.lastScrollTop) {
669
+ scrollTop = this.lastScrollTop + wd;
670
+ } else {
671
+ scrollTop = wd;
672
+ }
673
+
674
+ if (bodyTable && target !== bodyTable) {
675
+ bodyTable.scrollTop = scrollTop;
676
+ }
677
+ }
678
+ };
679
+
680
+ handleBodyScrollLeft = (e: BodyScrollEvent) => {
681
+ if (e.currentTarget !== e.target) {
682
+ return;
683
+ }
684
+ const { target } = e;
685
+ // const { headTable, bodyTable } = this;
686
+ const headTable = this.headerWrapRef.current;
687
+ const bodyTable = this.bodyWrapRef.current;
688
+ if (target.scrollLeft !== this.lastScrollLeft) {
689
+ if (target === bodyTable && headTable) {
690
+ headTable.scrollLeft = target.scrollLeft;
691
+ } else if (target === headTable && bodyTable) {
692
+ bodyTable.scrollLeft = target.scrollLeft;
693
+ }
694
+ this.setScrollPositionClassName();
695
+ }
696
+ // Remember last scrollLeft for scroll direction detecting.
697
+ this.lastScrollLeft = target.scrollLeft;
698
+ };
699
+
700
+ handleWindowResize = () => {
701
+ this.syncTableWidth();
702
+ this.setScrollPositionClassName();
703
+ };
704
+
705
+ handleBodyScrollTop = (e: BodyScrollEvent) => {
706
+ const { target } = e;
707
+ if (e.currentTarget !== target) {
708
+ return;
709
+ }
710
+ const { scroll = {} } = this.props;
711
+ // const { headTable, bodyTable, fixedColumnsBodyLeft, fixedColumnsBodyRight } = this;
712
+ const headTable = this.headerWrapRef.current;
713
+ const bodyTable = this.bodyWrapRef.current;
714
+
715
+ if (target.scrollTop !== this.lastScrollTop && scroll.y && target !== headTable) {
716
+ const { scrollTop } = target;
717
+
718
+ if (bodyTable && target !== bodyTable) {
719
+ bodyTable.scrollTop = scrollTop;
720
+ }
721
+ }
722
+ // Remember last scrollTop for scroll direction detecting.
723
+ this.lastScrollTop = target.scrollTop;
724
+ };
725
+
726
+ handleBodyScroll = (e: BodyScrollEvent) => {
727
+ this.handleBodyScrollLeft(e);
728
+ this.handleBodyScrollTop(e);
729
+ };
730
+
731
+ setScrollPosition = (position: BodyScrollPosition) => {
732
+ const { prefixCls } = this.props;
733
+ const positionAll = [
734
+ `${prefixCls}-scroll-position-both`,
735
+ `${prefixCls}-scroll-position-middle`,
736
+ `${prefixCls}-scroll-position-left`,
737
+ `${prefixCls}-scroll-position-right`,
738
+ ];
739
+ this.scrollPosition = position;
740
+ const tableNode = this.wrapRef.current;
741
+ if (tableNode && tableNode.nodeType) {
742
+ if (position === 'both') {
743
+ const acceptPosition = [`${prefixCls}-scroll-position-left`, `${prefixCls}-scroll-position-right`];
744
+ tableNode.classList.remove(...difference(positionAll, acceptPosition));
745
+ tableNode.classList.add(...acceptPosition);
746
+ } else {
747
+ const acceptPosition = [`${prefixCls}-scroll-position-${position}`];
748
+ tableNode.classList.remove(...difference(positionAll, acceptPosition));
749
+ tableNode.classList.add(...acceptPosition);
750
+ }
751
+ }
752
+ };
753
+
754
+ setScrollPositionClassName = () => {
755
+ const node = this.bodyWrapRef.current;
756
+ if (node && node.children && node.children.length) {
757
+ const scrollToLeft = node.scrollLeft === 0;
758
+ const scrollToRight =
759
+ node.scrollLeft + 1 >=
760
+ node.children[0].getBoundingClientRect().width - node.getBoundingClientRect().width;
761
+ if (scrollToLeft && scrollToRight) {
762
+ this.setScrollPosition('both');
763
+ } else if (scrollToLeft) {
764
+ this.setScrollPosition('left');
765
+ } else if (scrollToRight) {
766
+ this.setScrollPosition('right');
767
+ } else if (this.scrollPosition !== 'middle') {
768
+ this.setScrollPosition('middle');
769
+ }
770
+ }
771
+ };
772
+
773
+ syncTableWidth = () => {
774
+ if (this.rootWrapRef && this.rootWrapRef.current) {
775
+ this.setState({ tableWidth: this.rootWrapRef.current.getBoundingClientRect().width });
776
+ }
777
+ };
778
+
779
+ renderSelection = (record: RecordType = {} as RecordType, inHeader = false): React.ReactNode => {
780
+ const { rowSelection, disabledRowKeysSet } = this.state;
781
+
782
+ if (rowSelection && typeof rowSelection === 'object') {
783
+ const { selectedRowKeys = [], selectedRowKeysSet = new Set(), getCheckboxProps, disabled } = rowSelection;
784
+
785
+ if (inHeader) {
786
+ const columnKey = get(rowSelection, 'key', strings.DEFAULT_KEY_COLUMN_SELECTION);
787
+ const allRowKeys = this.cachedFilteredSortedRowKeys;
788
+ const allRowKeysSet = this.cachedFilteredSortedRowKeysSet;
789
+ const allIsSelected = this.foundation.allIsSelected(selectedRowKeysSet, disabledRowKeysSet, allRowKeys);
790
+ const hasRowSelected = this.foundation.hasRowSelected(selectedRowKeys, allRowKeysSet);
791
+ return (
792
+ <ColumnSelection
793
+ disabled={disabled}
794
+ key={columnKey}
795
+ selected={allIsSelected}
796
+ indeterminate={hasRowSelected && !allIsSelected}
797
+ onChange={(status, e) => {
798
+ this.toggleSelectAllRow(status, e);
799
+ }}
800
+ />
801
+ );
802
+ } else {
803
+ const key = this.foundation.getRecordKey(record);
804
+ const selected = selectedRowKeysSet.has(key);
805
+ const checkboxPropsFn = () => (typeof getCheckboxProps === 'function' ? getCheckboxProps(record) : {});
806
+
807
+ return (
808
+ <ColumnSelection
809
+ getCheckboxProps={checkboxPropsFn}
810
+ selected={selected}
811
+ onChange={(status, e) => this.toggleSelectRow(status, key, e)}
812
+ />
813
+ );
814
+ }
815
+ }
816
+ return null;
817
+ };
818
+
819
+ renderRowSelectionCallback = (text: string, record: RecordType = {} as RecordType) => this.renderSelection(record);
820
+ renderTitleSelectionCallback = () => this.renderSelection(null, true);
821
+
822
+ normalizeSelectionColumn = (props: { rowSelection?: TableStateRowSelection<RecordType>; prefixCls?: string } = {}) => {
823
+ const { rowSelection, prefixCls } = props;
824
+ let column: ColumnProps = {};
825
+ if (rowSelection) {
826
+ const needOmitSelectionKey = ['selectedRowKeys', 'selectedRowKeysSet'];
827
+ column = { key: strings.DEFAULT_KEY_COLUMN_SELECTION };
828
+
829
+ if (isObject(rowSelection)) {
830
+ column = { ...column, ...omit(rowSelection, needOmitSelectionKey) };
831
+ }
832
+
833
+ column.className = classnames(column.className, `${prefixCls}-column-selection`);
834
+
835
+ column.title = this.renderTitleSelectionCallback;
836
+
837
+ column.render = this.renderRowSelectionCallback;
838
+ }
839
+ return column;
840
+ };
841
+
842
+ // If there is a scroll bar, manually construct a column and insert it into the header
843
+ normalizeScrollbarColumn = (props: { scrollbarWidth?: number } = {}): { key: 'column-scrollbar'; width: number; fixed: 'right' } => {
844
+ const { scrollbarWidth = 0 } = props;
845
+
846
+ return {
847
+ key: strings.DEFAULT_KEY_COLUMN_SCROLLBAR as 'column-scrollbar',
848
+ width: scrollbarWidth,
849
+ fixed: 'right',
850
+ };
851
+ };
852
+
853
+ /**
854
+ * render expand icon
855
+ * @param {Object} record
856
+ * @param {Boolean} isNested
857
+ * @param {String} groupKey
858
+ * @returns {ReactNode}
859
+ */
860
+ renderExpandIcon = (record = {}, isNested = false, groupKey: string | number = null) => {
861
+ const { expandedRowKeys } = this.state;
862
+ const { expandIcon } = this.props;
863
+ const key =
864
+ typeof groupKey === 'string' || typeof groupKey === 'number' ?
865
+ groupKey :
866
+ this.foundation.getRecordKey(record as RecordType);
867
+
868
+ return (
869
+ <ExpandedIcon
870
+ key={key}
871
+ componentType={isNested ? 'tree' : 'expand'}
872
+ expanded={includes(expandedRowKeys, key)}
873
+ expandIcon={expandIcon}
874
+ onClick={(expanded, e) => this.handleRowExpanded(expanded, key, e)}
875
+ />
876
+ );
877
+ };
878
+
879
+ // @ts-ignore
880
+ handleRowExpanded = (...args: any[]) => this.foundation.handleRowExpanded(...args);
881
+
882
+ normalizeExpandColumn = (props: { prefixCls?: string; expandCellFixed?: ArrayElement<typeof strings.FIXED_SET>; expandIcon?: ExpandIcon } = {}) => {
883
+ let column: ColumnProps = null;
884
+
885
+ const { prefixCls, expandCellFixed, expandIcon } = props;
886
+
887
+ column = { fixed: expandCellFixed, key: strings.DEFAULT_KEY_COLUMN_EXPAND };
888
+
889
+ column.className = classnames(column.className, `${prefixCls}-column-expand`);
890
+
891
+ column.render =
892
+ expandIcon !== false ?
893
+ (text = '', record, index) =>
894
+ (this.adapter.mergedRowExpandable(record) ? this.renderExpandIcon(record) : null) :
895
+ () => null;
896
+
897
+ return column;
898
+ };
899
+
900
+ /**
901
+ * Add sorting, filtering, and rendering functions to columns, and add column event handling
902
+ * Title support function, passing parameters as {filter: node, sorter: node, selection: node}
903
+ * @param {*} column
904
+ */
905
+ addFnsInColumn = (column: ColumnProps = {}) => {
906
+ if (column && (column.sorter || column.filters || column.useFullRender)) {
907
+ const { dataIndex, title: rawTitle, useFullRender } = column;
908
+ const curQuery = this.foundation.getQuery(dataIndex);
909
+ const titleMap: ColumnTitleProps = {};
910
+ const titleArr = [];
911
+
912
+ // useFullRender adds select buttons to each column
913
+ if (useFullRender) {
914
+ titleMap.selection = this.renderSelection(null, true);
915
+ }
916
+
917
+ const stateSortOrder = get(curQuery, 'sortOrder');
918
+ const defaultSortOrder = get(curQuery, 'defaultSortOrder', false);
919
+ const sortOrder = this.foundation.isSortOrderValid(stateSortOrder) ? stateSortOrder : defaultSortOrder;
920
+ if (typeof column.sorter === 'function' || column.sorter === true) {
921
+ const sorter = (
922
+ <ColumnSorter
923
+ key={strings.DEFAULT_KEY_COLUMN_SORTER}
924
+ sortOrder={sortOrder}
925
+ onClick={e => this.foundation.handleSort(column, e)}
926
+ />
927
+ );
928
+ useFullRender && (titleMap.sorter = sorter);
929
+ titleArr.push(sorter);
930
+ }
931
+
932
+ if ((Array.isArray(column.filters) && column.filters.length) || isValidElement(column.filterDropdown)) {
933
+ const filter = (
934
+ <ColumnFilter
935
+ key={strings.DEFAULT_KEY_COLUMN_FILTER}
936
+ {...curQuery}
937
+ onFilterDropdownVisibleChange={(visible: boolean) => this.foundation.toggleShowFilter(dataIndex, visible)}
938
+ onSelect={(data: OnSelectData) => this.foundation.handleFilterSelect(dataIndex, data)}
939
+ />
940
+ );
941
+ useFullRender && (titleMap.filter = filter);
942
+ titleArr.push(filter);
943
+ }
944
+
945
+ const newTitle =
946
+ typeof rawTitle === 'function' ?
947
+ () => rawTitle(titleMap) :
948
+ titleArr.unshift(
949
+ <React.Fragment key={strings.DEFAULT_KEY_COLUMN_TITLE}>{rawTitle}</React.Fragment>
950
+ ) && titleArr;
951
+
952
+ column = { ...column, title: newTitle };
953
+ }
954
+
955
+ return column;
956
+ };
957
+
958
+ toggleSelectRow = (selected: boolean, realKey: string | number, e: TableSelectionCellEvent) => {
959
+ this.foundation.handleSelectRow(realKey, selected, e);
960
+ };
961
+
962
+ toggleSelectAllRow = (status: boolean, e: TableSelectionCellEvent) => {
963
+ this.foundation.handleSelectAllRow(status, e);
964
+ };
965
+
966
+ /**
967
+ * render pagination
968
+ * @param {object} pagination
969
+ */
970
+ renderPagination = (pagination: TablePaginationProps, propRenderPagination: RenderPagination) => {
971
+ if (!pagination) {
972
+ return null;
973
+ }
974
+
975
+ // use memoized pagination
976
+ const mergedPagination = this.foundation.memoizedPagination(pagination);
977
+
978
+ return (
979
+ <LocaleConsumer componentName="Table">
980
+ {(locale: TableLocale) => {
981
+ const info = this.foundation.formatPaginationInfo(mergedPagination, locale.pageText);
982
+ return <TablePagination info={info} pagination={mergedPagination} renderPagination={propRenderPagination} />;
983
+ }}
984
+ </LocaleConsumer>
985
+ );
986
+ };
987
+
988
+ renderTitle = (props: { title?: ReactNode; prefixCls?: string; dataSource?: any[] } = {}) => {
989
+ let { title } = props;
990
+ const { prefixCls, dataSource } = props;
991
+
992
+ if (typeof title === 'function') {
993
+ title = title(dataSource);
994
+ }
995
+
996
+ return isValidElement(title) || typeof title === 'string' ? (
997
+ <div className={`${prefixCls}-title`}>{title}</div>
998
+ ) : null;
999
+ };
1000
+
1001
+ renderEmpty = (props: { prefixCls?: string; empty?: ReactNode; dataSource?: RecordType[] } = {}) => {
1002
+ const { prefixCls, empty, dataSource } = props;
1003
+ const wrapCls = `${prefixCls}-placeholder`;
1004
+ const isEmpty = this.foundation.isEmpty(dataSource);
1005
+
1006
+ if (!isEmpty) {
1007
+ return null;
1008
+ }
1009
+
1010
+ return (
1011
+ <LocaleConsumer componentName="Table" key={'emptyText'}>
1012
+ {(locale: TableLocale, localeCode: string) => (
1013
+ <div className={wrapCls}>
1014
+ <div className={`${prefixCls}-empty`}>{empty || locale.emptyText}</div>
1015
+ </div>
1016
+ )}
1017
+ </LocaleConsumer>
1018
+ );
1019
+ };
1020
+
1021
+ renderFooter = (props: { footer?: ReactNode; prefixCls?: string; dataSource?: RecordType[] } = {}) => {
1022
+ let { footer } = props;
1023
+ const { prefixCls, dataSource } = props;
1024
+
1025
+ if (typeof footer === 'function') {
1026
+ footer = footer(dataSource);
1027
+ }
1028
+
1029
+ return isValidElement(footer) || typeof footer === 'string' ? (
1030
+ <div className={`${prefixCls}-footer`} key="footer">
1031
+ {footer}
1032
+ </div>
1033
+ ) : null;
1034
+ };
1035
+
1036
+ renderMainTable = (props: any) => {
1037
+ const useFixedHeader = this.adapter.useFixedHeader();
1038
+ const emptySlot = this.renderEmpty(props);
1039
+
1040
+ const table = [
1041
+ this.renderTable({
1042
+ ...props,
1043
+ fixed: false,
1044
+ useFixedHeader,
1045
+ headerRef: this._cacheHeaderRef,
1046
+ bodyRef: this.bodyWrapRef,
1047
+ includeHeader: !useFixedHeader,
1048
+ }),
1049
+ emptySlot,
1050
+ this.renderFooter(props),
1051
+ ];
1052
+
1053
+ return table;
1054
+ };
1055
+
1056
+
1057
+ renderTable = (props: RenderTableProps<RecordType>) => {
1058
+ const {
1059
+ columns,
1060
+ filteredColumns,
1061
+ fixed,
1062
+ useFixedHeader,
1063
+ scroll,
1064
+ prefixCls,
1065
+ anyColumnFixed,
1066
+ includeHeader,
1067
+ showHeader,
1068
+ components,
1069
+ headerRef,
1070
+ bodyRef,
1071
+ rowSelection,
1072
+ dataSource,
1073
+ bodyHasScrollBar,
1074
+ disabledRowKeysSet,
1075
+ } = props;
1076
+ const selectedRowKeysSet = get(rowSelection, 'selectedRowKeysSet', new Set());
1077
+
1078
+ const headTable =
1079
+ fixed || useFixedHeader ? (
1080
+ <HeadTable
1081
+ key="head"
1082
+ anyColumnFixed={anyColumnFixed}
1083
+ ref={headerRef}
1084
+ columns={filteredColumns}
1085
+ prefixCls={prefixCls}
1086
+ fixed={fixed}
1087
+ handleBodyScroll={this.handleBodyScrollLeft}
1088
+ components={components}
1089
+ scroll={scroll}
1090
+ showHeader={showHeader}
1091
+ selectedRowKeysSet={selectedRowKeysSet}
1092
+ dataSource={dataSource}
1093
+ bodyHasScrollBar={bodyHasScrollBar}
1094
+ />
1095
+ ) : null;
1096
+
1097
+ const bodyTable = (
1098
+ <BodyTable
1099
+ {...omit(props, ['rowSelection', 'headWidths']) as any}
1100
+ key="body"
1101
+ ref={bodyRef}
1102
+ columns={filteredColumns}
1103
+ fixed={fixed}
1104
+ prefixCls={prefixCls}
1105
+ handleWheel={this.handleWheel}
1106
+ handleBodyScroll={this.handleBodyScroll}
1107
+ anyColumnFixed={anyColumnFixed}
1108
+ includeHeader={includeHeader}
1109
+ showHeader={showHeader}
1110
+ scroll={scroll}
1111
+ components={components}
1112
+ store={this.store}
1113
+ selectedRowKeysSet={selectedRowKeysSet}
1114
+ disabledRowKeysSet={disabledRowKeysSet}
1115
+ />
1116
+ );
1117
+
1118
+ return [headTable, bodyTable];
1119
+ };
1120
+
1121
+ /**
1122
+ * When columns change, call this function to get the latest withFnsColumns
1123
+ * In addition to changes in columns, these props changes must be recalculated
1124
+ * - hideExpandedColumn
1125
+ * -rowSelection changes from trusy to falsy or rowSelection.hidden changes
1126
+ * -isAnyFixedRight(columns) || get(scroll,'y') changes
1127
+ *
1128
+ * columns变化时,调用此函数获取最新的withFnsColumns
1129
+ * 除了 columns 变化,这些 props 变化也要重新计算
1130
+ * - hideExpandedColumn
1131
+ * - rowSelection 从 trusy 变为 falsy 或 rowSelection.hidden 发生变化
1132
+ * - isAnyFixedRight(columns) || get(scroll, 'y') 发生变化
1133
+ *
1134
+ * @param {Array} queries
1135
+ * @param {Array} cachedColumns
1136
+ * @returns columns after adding extended functions
1137
+ */
1138
+ handleColumns = (queries: ColumnProps<RecordType>[], cachedColumns: ColumnProps<RecordType>[]) => {
1139
+ const { hideExpandedColumn, scroll, prefixCls, expandCellFixed, expandIcon, rowSelection } = this.props;
1140
+ const childrenColumnName = 'children';
1141
+ let columns: ColumnProps<RecordType>[] = cloneDeep(cachedColumns);
1142
+
1143
+ // eslint-disable-next-line @typescript-eslint/no-shadow
1144
+ const addFns = (columns: ColumnProps<RecordType>[] = []) => {
1145
+ if (Array.isArray(columns) && columns.length) {
1146
+ each(columns, (column, index, originColumns) => {
1147
+ const newColumn = this.addFnsInColumn(column);
1148
+ const children = column[childrenColumnName];
1149
+ if (Array.isArray(children) && children.length) {
1150
+ const newChildren = [...children];
1151
+ addFns(newChildren);
1152
+ newColumn[childrenColumnName] = newChildren;
1153
+ }
1154
+ originColumns[index] = newColumn;
1155
+ });
1156
+ }
1157
+ };
1158
+
1159
+ addFns(columns);
1160
+
1161
+ // hideExpandedColumn=false render expand column separately
1162
+ if (!hideExpandedColumn) {
1163
+ const column = this.normalizeExpandColumn({ prefixCls, expandCellFixed, expandIcon });
1164
+
1165
+ const destIndex = findIndex(columns, item => item.key === strings.DEFAULT_KEY_COLUMN_EXPAND);
1166
+ if (column) {
1167
+ if (destIndex > -1) {
1168
+ columns[destIndex] = { ...column, ...columns[destIndex] };
1169
+ } else if (column.fixed === 'right') {
1170
+ columns = [...columns, column];
1171
+ } else {
1172
+ columns = [column, ...columns];
1173
+ }
1174
+ }
1175
+ }
1176
+
1177
+ // selection column
1178
+ if (rowSelection && !get(rowSelection, 'hidden')) {
1179
+ const destIndex = findIndex(columns, item => item.key === strings.DEFAULT_KEY_COLUMN_SELECTION);
1180
+ const column = this.normalizeSelectionColumn({ rowSelection, prefixCls });
1181
+
1182
+ if (destIndex > -1) {
1183
+ columns[destIndex] = { ...column, ...columns[destIndex] };
1184
+ } else if (column.fixed === 'right') {
1185
+ columns = [...columns, column];
1186
+ } else {
1187
+ columns = [column, ...columns];
1188
+ }
1189
+ }
1190
+
1191
+ assignColumnKeys(columns);
1192
+
1193
+ return columns;
1194
+ };
1195
+
1196
+ /**
1197
+ * Convert children to columns object
1198
+ * @param {Array} columns
1199
+ * @param {ReactNode} children
1200
+ * @returns {Array}
1201
+ */
1202
+ normalizeColumns = (columns: ColumnProps<RecordType>[], children: ReactNode) => {
1203
+ const normalColumns = cloneDeep(this.getColumns(columns, children));
1204
+ return normalColumns;
1205
+ };
1206
+
1207
+ /**
1208
+ * Combine pagination and table paging processing functions
1209
+ */
1210
+ mergePagination = (pagination: TablePaginationProps) => {
1211
+ const newPagination = { onChange: this.foundation.setPage, ...pagination };
1212
+ return newPagination;
1213
+ };
1214
+
1215
+ render() {
1216
+ let {
1217
+ scroll,
1218
+ prefixCls,
1219
+ className,
1220
+ style: wrapStyle = {},
1221
+ bordered,
1222
+ id,
1223
+ pagination: propPagination,
1224
+ virtualized,
1225
+ size,
1226
+ renderPagination: propRenderPagination,
1227
+ getVirtualizedListRef,
1228
+ loading,
1229
+ hideExpandedColumn,
1230
+ rowSelection: propRowSelection,
1231
+ ...rest
1232
+ } = this.props;
1233
+
1234
+ let {
1235
+ rowSelection,
1236
+ expandedRowKeys,
1237
+ headWidths,
1238
+ tableWidth,
1239
+ pagination,
1240
+ dataSource,
1241
+ queries,
1242
+ cachedColumns,
1243
+ bodyHasScrollBar,
1244
+ } = this.state;
1245
+
1246
+ wrapStyle = { ...wrapStyle };
1247
+
1248
+ let columns: ColumnProps<RecordType>[];
1249
+ /**
1250
+ * As state.queries will change, the columns should be refreshed as a whole at this time
1251
+ * The scene of changes in queries
1252
+ * 1. Filter
1253
+ * 2. Pagination
1254
+ *
1255
+ * useFullRender needs to be passed to the user selection ReactNode, so columns need to be recalculated every time the selectedRowKeys changes
1256
+ * TODO: In the future, the selection passed to the user can be changed to the function type, allowing the user to execute the function to obtain the real-time status of the selection title
1257
+ *
1258
+ * 由于state.queries会发生变化,此时columns应该整体刷新
1259
+ * queries变化的场景
1260
+ * 1. 筛选
1261
+ * 2. 分页
1262
+ * useFullRender需要传给用户selection ReactNode,因此需要每次selectedRowKeys变化时重新计算columns
1263
+ * TODO: 未来可以将传给用户的selection改为函数类型,让用户执行函数获取selection title的实时状态
1264
+ */
1265
+ if (!this.adapter.isAnyColumnUseFullRender(queries)) {
1266
+ const rowSelectionUpdate: boolean = propRowSelection && !get(propRowSelection, 'hidden');
1267
+ columns = this.foundation.memoizedWithFnsColumns(
1268
+ queries,
1269
+ cachedColumns,
1270
+ rowSelectionUpdate,
1271
+ hideExpandedColumn,
1272
+ // Update the columns after the body scrollbar changes to ensure that the head and body are aligned
1273
+ bodyHasScrollBar
1274
+ );
1275
+ } else {
1276
+ columns = this.handleColumns(queries, cachedColumns);
1277
+ }
1278
+ const filteredColumns: ColumnProps<RecordType>[] = this.foundation.memoizedFilterColumns(columns);
1279
+ const flattenFnsColumns: ColumnProps<RecordType>[] = this.foundation.memoizedFlattenFnsColumns(columns);
1280
+
1281
+ const anyColumnFixed = this.adapter.isAnyColumnFixed(columns);
1282
+
1283
+
1284
+ /**
1285
+ * - If it is the first page break, you need to calculate the current page
1286
+ * - If it is manual paging, call foundation to modify the state
1287
+ *
1288
+ * TODO: After merging issue 1007, you can place it in the constructor to complete
1289
+ * The reason is that #1007 exposes the parameters required by getCurrentPageData in the constructor
1290
+ */
1291
+ if (isNull(dataSource)) {
1292
+ const pageData: BasePageData<RecordType> = this.foundation.getCurrentPageData(this.props.dataSource);
1293
+ dataSource = pageData.dataSource;
1294
+ pagination = pageData.pagination;
1295
+ }
1296
+
1297
+ const props = {
1298
+ ...rest,
1299
+ ...this.state,
1300
+ // props not in rest
1301
+ virtualized,
1302
+ scroll,
1303
+ prefixCls,
1304
+ size,
1305
+ hideExpandedColumn,
1306
+ // renamed state
1307
+ columns,
1308
+ // calculated value
1309
+ anyColumnFixed,
1310
+ rowExpandable: this.mergedRowExpandable,
1311
+ pagination,
1312
+ dataSource,
1313
+ rowSelection,
1314
+ expandedRowKeys,
1315
+ renderExpandIcon: this.renderExpandIcon,
1316
+ filteredColumns,
1317
+ };
1318
+
1319
+ const x = get(scroll, 'x');
1320
+ const y = get(scroll, 'y');
1321
+
1322
+ if (virtualized) {
1323
+ if (typeof wrapStyle.width !== 'number') {
1324
+ wrapStyle.width = x;
1325
+ }
1326
+ }
1327
+
1328
+ const wrapCls = classnames({
1329
+ [`${prefixCls}-${strings.SIZE_SMALL}`]: size === strings.SIZE_SMALL,
1330
+ [`${prefixCls}-${strings.SIZE_MIDDLE}`]: size === strings.SIZE_MIDDLE,
1331
+ [`${prefixCls}-virtualized`]: Boolean(virtualized),
1332
+ [`${prefixCls}-bordered`]: bordered,
1333
+ [`${prefixCls}-fixed-header`]: Boolean(y),
1334
+ [`${prefixCls}-scroll-position-left`]: ['both', 'left'].includes(this.position),
1335
+ [`${prefixCls}-scroll-position-right`]: ['both', 'right'].includes(this.position),
1336
+ });
1337
+
1338
+ // pagination
1339
+ const tablePagination = pagination && propPagination ? this.renderPagination(pagination as TablePaginationProps, propRenderPagination) : null;
1340
+ const paginationPosition = get(propPagination, 'position', 'bottom');
1341
+
1342
+ const tableContextValue: TableContextProps = {
1343
+ ...this.context,
1344
+ headWidths,
1345
+ tableWidth,
1346
+ anyColumnFixed,
1347
+ flattenedColumns: flattenFnsColumns,
1348
+ renderExpandIcon: this.renderExpandIcon,
1349
+ renderSelection: this.renderSelection,
1350
+ setHeadWidths: this.setHeadWidths,
1351
+ getHeadWidths: this.getHeadWidths,
1352
+ getCellWidths: this.getCellWidths,
1353
+ handleRowExpanded: this.handleRowExpanded,
1354
+ getVirtualizedListRef,
1355
+ setBodyHasScrollbar: this.setBodyHasScrollbar,
1356
+ };
1357
+
1358
+ return (
1359
+ <div
1360
+ ref={this.rootWrapRef}
1361
+ className={classnames(className, `${prefixCls}-wrapper`)}
1362
+ style={wrapStyle}
1363
+ id={id}
1364
+ >
1365
+ <TableContextProvider {...tableContextValue}>
1366
+ <Spin spinning={loading} size="large">
1367
+ <div ref={this.wrapRef} className={wrapCls}>
1368
+ <React.Fragment key={'pagination-top'}>
1369
+ {['top', 'both'].includes(paginationPosition) ? tablePagination : null}
1370
+ </React.Fragment>
1371
+ {this.renderTitle({ title: (props as any).title, dataSource: props.dataSource, prefixCls: props.prefixCls })}
1372
+ <div className={`${prefixCls}-container`}>{this.renderMainTable({ ...props })}</div>
1373
+ <React.Fragment key={'pagination-bottom'}>
1374
+ {['bottom', 'both'].includes(paginationPosition) ? tablePagination : null}
1375
+ </React.Fragment>
1376
+ </div>
1377
+ </Spin>
1378
+ </TableContextProvider>
1379
+ </div>
1380
+ );
1381
+ }
1382
+ }
1383
+
1384
+ export default Table;