@qsxy/element-plus-react 1.0.2 → 2.0.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 (636) hide show
  1. package/dist/Affix/Affix.d.ts +4 -0
  2. package/dist/Affix/Affix.js +301 -0
  3. package/dist/Affix/index.d.ts +2 -0
  4. package/dist/Affix/index.js +1 -0
  5. package/dist/Affix/typings.d.ts +50 -0
  6. package/dist/Affix/typings.js +1 -0
  7. package/dist/Alert/Alert.d.ts +7 -0
  8. package/dist/Alert/Alert.js +98 -0
  9. package/dist/Alert/index.d.ts +2 -0
  10. package/dist/Alert/index.js +1 -0
  11. package/dist/Alert/typings.d.ts +45 -0
  12. package/dist/Alert/typings.js +1 -0
  13. package/dist/Anchor/Anchor.d.ts +6 -0
  14. package/dist/Anchor/Anchor.js +258 -0
  15. package/dist/Anchor/AnchorLink.d.ts +4 -0
  16. package/dist/Anchor/AnchorLink.js +77 -0
  17. package/dist/Anchor/element.d.ts +4 -0
  18. package/dist/Anchor/element.js +17 -0
  19. package/dist/Anchor/index.d.ts +3 -0
  20. package/dist/Anchor/index.js +2 -0
  21. package/dist/Anchor/typings.d.ts +101 -0
  22. package/dist/Anchor/typings.js +1 -0
  23. package/dist/Backtop/Backtop.d.ts +7 -0
  24. package/dist/Backtop/Backtop.js +153 -0
  25. package/dist/Backtop/index.d.ts +2 -0
  26. package/dist/Backtop/index.js +1 -0
  27. package/dist/Backtop/typings.d.ts +31 -0
  28. package/dist/Backtop/typings.js +1 -0
  29. package/dist/Button/Button.d.ts +2 -11
  30. package/dist/Button/Button.js +2 -6
  31. package/dist/Button/index.d.ts +1 -1
  32. package/dist/Calendar/Calendar.js +12 -8
  33. package/dist/Calendar/YearRangePanel.js +1 -1
  34. package/dist/Card/Card.js +5 -3
  35. package/dist/Carousel/typings.d.ts +1 -1
  36. package/dist/Cascader/Cascader.d.ts +3 -3
  37. package/dist/Cascader/Cascader.js +238 -166
  38. package/dist/Cascader/CascaderContext.d.ts +9 -3
  39. package/dist/Cascader/CascaderContext.js +3 -1
  40. package/dist/Cascader/CascaderDropdown.d.ts +4 -3
  41. package/dist/Cascader/CascaderDropdown.js +21 -10
  42. package/dist/Cascader/CascaderMenu.d.ts +2 -2
  43. package/dist/Cascader/CascaderMenu.js +56 -14
  44. package/dist/Cascader/CascaderPanel.d.ts +4 -0
  45. package/dist/Cascader/CascaderPanel.js +11 -0
  46. package/dist/Cascader/index.d.ts +4 -1
  47. package/dist/Cascader/index.js +2 -1
  48. package/dist/Cascader/typings.d.ts +45 -31
  49. package/dist/Cascader/useCascader.d.ts +14 -27
  50. package/dist/Cascader/useCascader.js +153 -59
  51. package/dist/Checkbox/Checkbox.js +3 -2
  52. package/dist/CheckboxGroup/CheckboxGroup.d.ts +11 -1
  53. package/dist/CheckboxGroup/CheckboxGroup.js +78 -19
  54. package/dist/Collapse/Collapse.d.ts +3 -3
  55. package/dist/Collapse/Collapse.js +71 -16
  56. package/dist/Collapse/CollapseContext.d.ts +3 -6
  57. package/dist/Collapse/CollapseContext.js +2 -4
  58. package/dist/Collapse/CollapseItem.d.ts +3 -3
  59. package/dist/Collapse/CollapseItem.js +93 -51
  60. package/dist/Collapse/CollapseTransition.js +11 -7
  61. package/dist/Collapse/index.d.ts +1 -1
  62. package/dist/Collapse/typings.d.ts +20 -5
  63. package/dist/ColorPicker/typings.d.ts +1 -1
  64. package/dist/ConfigProvider/ConfigProvider.js +2 -24
  65. package/dist/ConfigProvider/ConfigProviderContext.js +1 -1
  66. package/dist/ConfigProvider/typings.d.ts +1 -1
  67. package/dist/Container/Main.d.ts +1 -1
  68. package/dist/Container/typings.d.ts +1 -1
  69. package/dist/Countdown/Countdown.d.ts +4 -0
  70. package/dist/Countdown/Countdown.js +121 -0
  71. package/dist/Countdown/index.d.ts +2 -0
  72. package/dist/Countdown/index.js +1 -0
  73. package/dist/Countdown/typings.d.ts +52 -0
  74. package/dist/Countdown/typings.js +1 -0
  75. package/dist/Countdown/util.d.ts +14 -0
  76. package/dist/Countdown/util.js +58 -0
  77. package/dist/DatePicker/DatePicker.js +9 -6
  78. package/dist/DatePicker/DateRangePicker.js +7 -6
  79. package/dist/DatePicker/typings.d.ts +0 -13
  80. package/dist/DateTimePicker/DateTimePicker.js +29 -19
  81. package/dist/Dialog/Dialog.d.ts +2 -13
  82. package/dist/Dialog/Dialog.js +143 -160
  83. package/dist/Dialog/DialogBody.js +3 -38
  84. package/dist/Dialog/DialogContext.d.ts +0 -7
  85. package/dist/Dialog/DialogContext.js +1 -5
  86. package/dist/Dialog/DialogHeader.js +2 -2
  87. package/dist/Dialog/typings.d.ts +43 -28
  88. package/dist/Dialog/useDraggable.d.ts +2 -1
  89. package/dist/Dialog/useDraggable.js +34 -9
  90. package/dist/Drawer/Drawer.d.ts +2 -13
  91. package/dist/Drawer/Drawer.js +115 -137
  92. package/dist/Drawer/DrawerBody.js +7 -8
  93. package/dist/Drawer/DrawerFooter.js +7 -7
  94. package/dist/Drawer/DrawerHeader.js +11 -8
  95. package/dist/Drawer/typings.d.ts +22 -6
  96. package/dist/Dropdown/Dropdown.js +5 -3
  97. package/dist/Dropdown/typings.d.ts +2 -1
  98. package/dist/Empty/Empty.js +16 -4
  99. package/dist/Form/Form.d.ts +4 -21
  100. package/dist/Form/Form.js +53 -25
  101. package/dist/Form/FormItem.d.ts +4 -52
  102. package/dist/Form/FormItem.js +633 -650
  103. package/dist/Form/FormItemContext.d.ts +10 -1
  104. package/dist/Form/FormItemContext.js +9 -1
  105. package/dist/Form/FormLabelWrap.d.ts +8 -0
  106. package/dist/Form/FormLabelWrap.js +103 -0
  107. package/dist/Form/{FieldContext.d.ts → InternalFormContext.d.ts} +2 -2
  108. package/dist/Form/{FieldContext.js → InternalFormContext.js} +5 -2
  109. package/dist/Form/List.d.ts +3 -3
  110. package/dist/Form/List.js +4 -4
  111. package/dist/Form/index.d.ts +4 -2
  112. package/dist/Form/index.js +4 -1
  113. package/dist/Form/typings.d.ts +61 -9
  114. package/dist/Form/typings.js +15 -1
  115. package/dist/Form/useForm.js +3 -3
  116. package/dist/Form/useWatch.js +1 -1
  117. package/dist/Input/Input.d.ts +2 -14
  118. package/dist/Input/Input.js +187 -140
  119. package/dist/Input/InputGroup.js +1 -1
  120. package/dist/Input/InputRange.js +7 -11
  121. package/dist/Input/TextArea.d.ts +1 -1
  122. package/dist/Input/TextArea.js +85 -30
  123. package/dist/Input/index.d.ts +1 -0
  124. package/dist/Input/index.js +2 -1
  125. package/dist/Input/typings.d.ts +38 -19
  126. package/dist/Input/utils.d.ts +1 -0
  127. package/dist/Input/utils.js +5 -1
  128. package/dist/InputNumber/InputNumber.js +408 -147
  129. package/dist/InputNumber/typings.d.ts +15 -5
  130. package/dist/Loading/Loading.js +5 -2
  131. package/dist/Menu/Menu.js +26 -2
  132. package/dist/Menu/MenuItem.js +4 -2
  133. package/dist/Menu/SubMenu.js +2 -2
  134. package/dist/Menu/SubMenuCollapseTransition.js +14 -9
  135. package/dist/Menu/typings.d.ts +5 -14
  136. package/dist/Message/Message.js +51 -23
  137. package/dist/Message/index.js +13 -13
  138. package/dist/Message/typings.d.ts +8 -5
  139. package/dist/MessageBox/MessageBox.js +75 -57
  140. package/dist/MessageBox/index.d.ts +2 -1
  141. package/dist/MessageBox/index.js +4 -2
  142. package/dist/MessageBox/typings.d.ts +3 -1
  143. package/dist/Notification/Notification.js +26 -19
  144. package/dist/Notification/typings.d.ts +1 -1
  145. package/dist/PageHeader/PageHeader.d.ts +8 -0
  146. package/dist/PageHeader/PageHeader.js +91 -0
  147. package/dist/PageHeader/index.d.ts +2 -0
  148. package/dist/PageHeader/index.js +1 -0
  149. package/dist/PageHeader/typings.d.ts +34 -0
  150. package/dist/PageHeader/typings.js +1 -0
  151. package/dist/Pagination/typings.d.ts +1 -1
  152. package/dist/Popover/Popover.js +7 -7
  153. package/dist/Popover/typings.d.ts +3 -3
  154. package/dist/Popper/Popper.js +49 -28
  155. package/dist/Popper/popperOptions.js +1 -0
  156. package/dist/Popper/typings.d.ts +2 -0
  157. package/dist/Radio/Radio.d.ts +2 -12
  158. package/dist/Radio/Radio.js +2 -6
  159. package/dist/Radio/RadioButton.d.ts +1 -1
  160. package/dist/Radio/RadioButton.js +4 -4
  161. package/dist/Radio/index.d.ts +1 -0
  162. package/dist/Radio/index.js +2 -1
  163. package/dist/Radio/typings.d.ts +1 -1
  164. package/dist/RadioGroup/RadioGroup.js +44 -16
  165. package/dist/RadioGroup/typings.d.ts +10 -0
  166. package/dist/Segmented/Segmented.d.ts +4 -0
  167. package/dist/Segmented/Segmented.js +208 -0
  168. package/dist/Segmented/index.d.ts +2 -0
  169. package/dist/Segmented/index.js +1 -0
  170. package/dist/Segmented/typings.d.ts +20 -0
  171. package/dist/Segmented/typings.js +5 -0
  172. package/dist/Select/SelectContext.d.ts +2 -1
  173. package/dist/Select/SelectContext.js +2 -1
  174. package/dist/Select/SelectCore.js +64 -15
  175. package/dist/Select/SelectDropdown.js +23 -15
  176. package/dist/Select/index.d.ts +1 -1
  177. package/dist/Select/typings.d.ts +26 -17
  178. package/dist/Select/useSelect.d.ts +35 -18
  179. package/dist/Select/useSelect.js +88 -33
  180. package/dist/Skeleton/typings.d.ts +1 -1
  181. package/dist/Slider/Button.d.ts +4 -0
  182. package/dist/Slider/Button.js +96 -0
  183. package/dist/Slider/Marker.d.ts +4 -0
  184. package/dist/Slider/Marker.js +31 -0
  185. package/dist/Slider/Slider.d.ts +4 -0
  186. package/dist/Slider/Slider.js +263 -0
  187. package/dist/Slider/SliderContext.d.ts +3 -0
  188. package/dist/Slider/SliderContext.js +2 -0
  189. package/dist/Slider/hooks/index.d.ts +5 -0
  190. package/dist/Slider/hooks/index.js +5 -0
  191. package/dist/Slider/hooks/useLifecycle.d.ts +5 -0
  192. package/dist/Slider/hooks/useLifecycle.js +50 -0
  193. package/dist/Slider/hooks/useMarks.d.ts +2 -0
  194. package/dist/Slider/hooks/useMarks.js +49 -0
  195. package/dist/Slider/hooks/useSlider.d.ts +38 -0
  196. package/dist/Slider/hooks/useSlider.js +227 -0
  197. package/dist/Slider/hooks/useSliderButton.d.ts +28 -0
  198. package/dist/Slider/hooks/useSliderButton.js +454 -0
  199. package/dist/Slider/hooks/useStops.d.ts +6 -0
  200. package/dist/Slider/hooks/useStops.js +47 -0
  201. package/dist/Slider/hooks/useWatch.d.ts +3 -0
  202. package/dist/Slider/hooks/useWatch.js +119 -0
  203. package/dist/Slider/index.d.ts +2 -0
  204. package/dist/Slider/index.js +1 -0
  205. package/dist/Slider/style/css.d.ts +1 -0
  206. package/dist/Slider/style/css.js +1 -0
  207. package/dist/Slider/style/index.d.ts +1 -0
  208. package/dist/Slider/style/index.js +1 -0
  209. package/dist/Slider/typings.d.ts +122 -0
  210. package/dist/Slider/typings.js +1 -0
  211. package/dist/Space/Space.d.ts +4 -0
  212. package/dist/Space/Space.js +125 -0
  213. package/dist/Space/SpaceItem.d.ts +7 -0
  214. package/dist/Space/SpaceItem.js +14 -0
  215. package/dist/Space/index.d.ts +3 -0
  216. package/dist/Space/index.js +2 -0
  217. package/dist/Space/typings.d.ts +26 -0
  218. package/dist/Space/typings.js +1 -0
  219. package/dist/Space/useSpace.d.ts +7 -0
  220. package/dist/Space/useSpace.js +105 -0
  221. package/dist/Statistic/Statistic.d.ts +4 -0
  222. package/dist/Statistic/Statistic.js +91 -0
  223. package/dist/Statistic/index.d.ts +2 -0
  224. package/dist/Statistic/index.js +1 -0
  225. package/dist/Statistic/typings.d.ts +28 -0
  226. package/dist/Statistic/typings.js +1 -0
  227. package/dist/Steps/Step.d.ts +4 -0
  228. package/dist/Steps/Step.js +247 -0
  229. package/dist/Steps/Steps.d.ts +5 -0
  230. package/dist/Steps/Steps.js +116 -0
  231. package/dist/Steps/index.d.ts +3 -0
  232. package/dist/Steps/index.js +2 -0
  233. package/dist/Steps/typings.d.ts +119 -0
  234. package/dist/Steps/typings.js +1 -0
  235. package/dist/Switch/Switch.js +2 -2
  236. package/dist/Switch/typings.d.ts +0 -1
  237. package/dist/Table/Table.js +17 -14
  238. package/dist/Table/TableBody.js +4 -4
  239. package/dist/Table/TableCell.js +53 -28
  240. package/dist/Table/TableColumn.d.ts +2 -2
  241. package/dist/Table/TableHeader.js +2 -2
  242. package/dist/Table/TableHeaderCell.js +2 -2
  243. package/dist/Table/hooks/useResize.js +0 -2
  244. package/dist/Table/hooks/useTable.d.ts +1 -1
  245. package/dist/Table/hooks/useTable.js +15 -10
  246. package/dist/Table/typings.d.ts +28 -12
  247. package/dist/Table/util.d.ts +1 -1
  248. package/dist/Table/util.js +8 -65
  249. package/dist/TableV2/index.d.ts +10 -0
  250. package/dist/TableV2/index.js +7 -0
  251. package/dist/TableV2/src/auto-resizer.d.ts +14 -0
  252. package/dist/TableV2/src/auto-resizer.js +1 -0
  253. package/dist/TableV2/src/cell.d.ts +21 -0
  254. package/dist/TableV2/src/cell.js +1 -0
  255. package/dist/TableV2/src/components/auto-resizer.d.ts +4 -0
  256. package/dist/TableV2/src/components/auto-resizer.js +32 -0
  257. package/dist/TableV2/src/components/cell.d.ts +4 -0
  258. package/dist/TableV2/src/components/cell.js +22 -0
  259. package/dist/TableV2/src/components/expand-icon.d.ts +12 -0
  260. package/dist/TableV2/src/components/expand-icon.js +29 -0
  261. package/dist/TableV2/src/components/header-cell.d.ts +4 -0
  262. package/dist/TableV2/src/components/header-cell.js +23 -0
  263. package/dist/TableV2/src/components/header-row.d.ts +17 -0
  264. package/dist/TableV2/src/components/header-row.js +41 -0
  265. package/dist/TableV2/src/components/header.d.ts +20 -0
  266. package/dist/TableV2/src/components/header.js +103 -0
  267. package/dist/TableV2/src/components/index.d.ts +10 -0
  268. package/dist/TableV2/src/components/index.js +7 -0
  269. package/dist/TableV2/src/components/row.d.ts +19 -0
  270. package/dist/TableV2/src/components/row.js +206 -0
  271. package/dist/TableV2/src/components/sort-icon.d.ts +9 -0
  272. package/dist/TableV2/src/components/sort-icon.js +14 -0
  273. package/dist/TableV2/src/composables/index.d.ts +6 -0
  274. package/dist/TableV2/src/composables/index.js +6 -0
  275. package/dist/TableV2/src/composables/use-auto-resize.d.ts +7 -0
  276. package/dist/TableV2/src/composables/use-auto-resize.js +55 -0
  277. package/dist/TableV2/src/composables/use-columns.d.ts +21 -0
  278. package/dist/TableV2/src/composables/use-columns.js +119 -0
  279. package/dist/TableV2/src/composables/use-data.d.ts +15 -0
  280. package/dist/TableV2/src/composables/use-data.js +62 -0
  281. package/dist/TableV2/src/composables/use-row.d.ts +34 -0
  282. package/dist/TableV2/src/composables/use-row.js +191 -0
  283. package/dist/TableV2/src/composables/use-scrollbar.d.ts +25 -0
  284. package/dist/TableV2/src/composables/use-scrollbar.js +117 -0
  285. package/dist/TableV2/src/composables/use-styles.d.ts +23 -0
  286. package/dist/TableV2/src/composables/use-styles.js +90 -0
  287. package/dist/TableV2/src/composables/utils.d.ts +3 -0
  288. package/dist/TableV2/src/composables/utils.js +29 -0
  289. package/dist/TableV2/src/constants.d.ts +18 -0
  290. package/dist/{Tree/Indent.js → TableV2/src/constants.js} +18 -21
  291. package/dist/TableV2/src/grid.d.ts +52 -0
  292. package/dist/TableV2/src/grid.js +1 -0
  293. package/dist/TableV2/src/header-cell.d.ts +13 -0
  294. package/dist/TableV2/src/header-cell.js +1 -0
  295. package/dist/TableV2/src/header-row.d.ts +10 -0
  296. package/dist/TableV2/src/header-row.js +1 -0
  297. package/dist/TableV2/src/header.d.ts +15 -0
  298. package/dist/TableV2/src/header.js +1 -0
  299. package/dist/TableV2/src/private.d.ts +1 -0
  300. package/dist/TableV2/src/private.js +1 -0
  301. package/dist/TableV2/src/renderers/cell.d.ts +14 -0
  302. package/dist/TableV2/src/renderers/cell.js +120 -0
  303. package/dist/TableV2/src/renderers/empty.d.ts +7 -0
  304. package/dist/TableV2/src/renderers/empty.js +11 -0
  305. package/dist/TableV2/src/renderers/footer.d.ts +7 -0
  306. package/dist/TableV2/src/renderers/footer.js +9 -0
  307. package/dist/TableV2/src/renderers/header-cell.d.ts +13 -0
  308. package/dist/TableV2/src/renderers/header-cell.js +92 -0
  309. package/dist/TableV2/src/renderers/header.d.ts +9 -0
  310. package/dist/TableV2/src/renderers/header.js +39 -0
  311. package/dist/TableV2/src/renderers/left-table.d.ts +32 -0
  312. package/dist/TableV2/src/renderers/left-table.js +15 -0
  313. package/dist/TableV2/src/renderers/main-table.d.ts +31 -0
  314. package/dist/TableV2/src/renderers/main-table.js +12 -0
  315. package/dist/TableV2/src/renderers/overlay.d.ts +3 -0
  316. package/dist/TableV2/src/renderers/overlay.js +9 -0
  317. package/dist/TableV2/src/renderers/right-table.d.ts +31 -0
  318. package/dist/TableV2/src/renderers/right-table.js +15 -0
  319. package/dist/TableV2/src/renderers/row.d.ts +11 -0
  320. package/dist/TableV2/src/renderers/row.js +96 -0
  321. package/dist/TableV2/src/row.d.ts +51 -0
  322. package/dist/TableV2/src/row.js +1 -0
  323. package/dist/TableV2/src/table-grid.d.ts +43 -0
  324. package/dist/TableV2/src/table-grid.js +283 -0
  325. package/dist/TableV2/src/table-v2.d.ts +31 -0
  326. package/dist/TableV2/src/table-v2.js +311 -0
  327. package/dist/TableV2/src/table.d.ts +196 -0
  328. package/dist/TableV2/src/table.js +1 -0
  329. package/dist/TableV2/src/tokens.d.ts +11 -0
  330. package/dist/TableV2/src/tokens.js +6 -0
  331. package/dist/TableV2/src/types.d.ts +94 -0
  332. package/dist/TableV2/src/types.js +1 -0
  333. package/dist/TableV2/src/use-table.d.ts +48 -0
  334. package/dist/TableV2/src/use-table.js +197 -0
  335. package/dist/TableV2/src/utils.d.ts +5 -0
  336. package/dist/TableV2/src/utils.js +47 -0
  337. package/dist/Tabs/Tabs.js +1 -1
  338. package/dist/Tabs/typings.d.ts +1 -3
  339. package/dist/Tag/Tag.js +1 -1
  340. package/dist/Tag/typings.d.ts +1 -1
  341. package/dist/Text/Text.d.ts +4 -0
  342. package/dist/Text/Text.js +84 -0
  343. package/dist/Text/index.d.ts +2 -0
  344. package/dist/Text/index.js +1 -0
  345. package/dist/Text/typings.d.ts +15 -0
  346. package/dist/Text/typings.js +1 -0
  347. package/dist/TimePicker/TimePicker.js +6 -7
  348. package/dist/TimePicker/TimePickerPanel.js +12 -2
  349. package/dist/TimePicker/TimePickerRange.js +19 -8
  350. package/dist/Tooltip/Tooltip.js +31 -8
  351. package/dist/Tooltip/typings.d.ts +4 -0
  352. package/dist/Tour/Content.d.ts +9 -0
  353. package/dist/Tour/Content.js +81 -0
  354. package/dist/Tour/Mask.d.ts +12 -0
  355. package/dist/Tour/Mask.js +100 -0
  356. package/dist/Tour/Step.d.ts +7 -0
  357. package/dist/Tour/Step.js +119 -0
  358. package/dist/Tour/Tour.d.ts +6 -0
  359. package/dist/Tour/Tour.js +237 -0
  360. package/dist/Tour/context.d.ts +4 -0
  361. package/dist/Tour/context.js +9 -0
  362. package/dist/Tour/helper.d.ts +39 -0
  363. package/dist/Tour/helper.js +286 -0
  364. package/dist/Tour/index.d.ts +3 -0
  365. package/dist/Tour/index.js +2 -0
  366. package/dist/Tour/typings.d.ts +318 -0
  367. package/dist/Tour/typings.js +38 -0
  368. package/dist/Transfer/List.js +58 -59
  369. package/dist/Transfer/ListItem.d.ts +2 -2
  370. package/dist/Transfer/Transfer.d.ts +2 -2
  371. package/dist/Transfer/Transfer.js +84 -70
  372. package/dist/Transfer/index.d.ts +1 -1
  373. package/dist/Transfer/operation.js +8 -10
  374. package/dist/Transfer/typings/index.d.ts +49 -38
  375. package/dist/Transfer/typings/list.d.ts +11 -11
  376. package/dist/Transfer/typings/listBody.d.ts +2 -2
  377. package/dist/Transition/Transition.d.ts +1 -0
  378. package/dist/Transition/Transition.js +8 -7
  379. package/dist/Tree/CollapseTransition.d.ts +7 -0
  380. package/dist/Tree/CollapseTransition.js +60 -0
  381. package/dist/Tree/Tree.d.ts +3 -140
  382. package/dist/Tree/Tree.js +351 -77
  383. package/dist/Tree/TreeContext.d.ts +9 -0
  384. package/dist/Tree/TreeContext.js +14 -0
  385. package/dist/Tree/TreeNode.d.ts +5 -3
  386. package/dist/Tree/TreeNode.js +321 -331
  387. package/dist/Tree/TreeNodeContent.d.ts +9 -0
  388. package/dist/Tree/TreeNodeContent.js +22 -0
  389. package/dist/Tree/index.d.ts +3 -8
  390. package/dist/Tree/index.js +1 -4
  391. package/dist/Tree/model/node.d.ts +62 -0
  392. package/dist/Tree/model/node.js +601 -0
  393. package/dist/Tree/model/tree-store.d.ts +52 -0
  394. package/dist/Tree/model/tree-store.js +510 -0
  395. package/dist/Tree/model/useDragNode.d.ts +30 -0
  396. package/dist/Tree/model/useDragNode.js +293 -0
  397. package/dist/Tree/model/useKeydown.d.ts +0 -0
  398. package/dist/Tree/model/useKeydown.js +104 -0
  399. package/dist/Tree/model/useNodeExpandEventBroadcast.d.ts +15 -0
  400. package/dist/Tree/model/useNodeExpandEventBroadcast.js +54 -0
  401. package/dist/Tree/model/util.d.ts +7 -0
  402. package/dist/Tree/model/util.js +24 -0
  403. package/dist/Tree/typings.d.ts +227 -114
  404. package/dist/TreeSelect/TreeSelect.d.ts +2 -10
  405. package/dist/TreeSelect/TreeSelect.js +90 -566
  406. package/dist/TreeSelect/TreeSelectOption.d.ts +6 -0
  407. package/dist/TreeSelect/TreeSelectOption.js +62 -0
  408. package/dist/TreeSelect/Utils.d.ts +10 -3
  409. package/dist/TreeSelect/Utils.js +37 -19
  410. package/dist/TreeSelect/cacheOptions.d.ts +9 -0
  411. package/dist/TreeSelect/cacheOptions.js +22 -0
  412. package/dist/TreeSelect/index.d.ts +0 -1
  413. package/dist/TreeSelect/typings.d.ts +11 -63
  414. package/dist/TreeSelect/useSelect.d.ts +78 -0
  415. package/dist/TreeSelect/useSelect.js +104 -0
  416. package/dist/TreeSelect/useTree.d.ts +125 -0
  417. package/dist/TreeSelect/useTree.js +285 -0
  418. package/dist/Upload/UploadContent.js +3 -1
  419. package/dist/Upload/ajax.js +3 -0
  420. package/dist/Upload/typings.d.ts +5 -1
  421. package/dist/Util/PopupManager.js +1 -1
  422. package/dist/Util/aria.d.ts +1 -1
  423. package/dist/Util/aria.js +12 -12
  424. package/dist/Util/base.d.ts +36 -6
  425. package/dist/Util/base.js +180 -13
  426. package/dist/Util/easings.d.ts +1 -0
  427. package/dist/Util/easings.js +8 -0
  428. package/dist/Util/error.d.ts +3 -0
  429. package/dist/Util/error.js +39 -0
  430. package/dist/Util/icons.d.ts +2 -0
  431. package/dist/Util/icons.js +15 -0
  432. package/dist/Util/index.d.ts +6 -2
  433. package/dist/Util/index.js +6 -2
  434. package/dist/Util/position.d.ts +9 -0
  435. package/dist/Util/position.js +53 -0
  436. package/dist/Util/raf.d.ts +4 -0
  437. package/dist/Util/raf.js +10 -0
  438. package/dist/Util/scroll.d.ts +9 -0
  439. package/dist/Util/scroll.js +72 -0
  440. package/dist/Util/throttleByRaf.d.ts +4 -0
  441. package/dist/Util/throttleByRaf.js +21 -0
  442. package/dist/VirtualList/builders/build-grid.d.ts +5 -0
  443. package/dist/VirtualList/builders/build-grid.js +561 -0
  444. package/dist/VirtualList/builders/build-list.d.ts +7 -0
  445. package/dist/VirtualList/builders/build-list.js +408 -0
  446. package/dist/VirtualList/components/dynamic-size-grid.d.ts +15 -0
  447. package/dist/VirtualList/components/dynamic-size-grid.js +242 -0
  448. package/dist/VirtualList/components/dynamic-size-list.d.ts +7 -0
  449. package/dist/VirtualList/components/dynamic-size-list.js +186 -0
  450. package/dist/VirtualList/components/fixed-size-grid.d.ts +4 -0
  451. package/dist/VirtualList/components/fixed-size-grid.js +161 -0
  452. package/dist/VirtualList/components/fixed-size-list.d.ts +7 -0
  453. package/dist/VirtualList/components/fixed-size-list.js +103 -0
  454. package/dist/VirtualList/components/scrollbar.d.ts +5 -0
  455. package/dist/VirtualList/components/scrollbar.js +272 -0
  456. package/dist/VirtualList/defaults.d.ts +26 -0
  457. package/dist/VirtualList/defaults.js +24 -0
  458. package/dist/VirtualList/hooks/use-cache.d.ts +1 -0
  459. package/dist/VirtualList/hooks/use-cache.js +16 -0
  460. package/dist/VirtualList/hooks/use-grid-touch.d.ts +8 -0
  461. package/dist/VirtualList/hooks/use-grid-touch.js +58 -0
  462. package/dist/VirtualList/hooks/use-grid-wheel.d.ts +12 -0
  463. package/dist/VirtualList/hooks/use-grid-wheel.js +48 -0
  464. package/dist/VirtualList/hooks/use-wheel.d.ts +12 -0
  465. package/dist/VirtualList/hooks/use-wheel.js +41 -0
  466. package/dist/VirtualList/index.d.ts +9 -0
  467. package/dist/VirtualList/index.js +6 -0
  468. package/dist/VirtualList/props.d.ts +95 -0
  469. package/dist/VirtualList/props.js +42 -0
  470. package/dist/VirtualList/types.d.ts +151 -0
  471. package/dist/VirtualList/types.js +1 -0
  472. package/dist/VirtualList/utils.d.ts +11 -0
  473. package/dist/VirtualList/utils.js +56 -0
  474. package/dist/Watermark/Watermark.d.ts +4 -0
  475. package/dist/Watermark/Watermark.js +257 -0
  476. package/dist/Watermark/helper.d.ts +50 -0
  477. package/dist/Watermark/helper.js +253 -0
  478. package/dist/Watermark/index.d.ts +2 -0
  479. package/dist/Watermark/index.js +1 -0
  480. package/dist/Watermark/typings.d.ts +93 -0
  481. package/dist/Watermark/typings.js +1 -0
  482. package/dist/config/Constants.d.ts +3 -0
  483. package/dist/config/Constants.js +8 -0
  484. package/dist/hooks/index.d.ts +2 -0
  485. package/dist/hooks/index.js +1 -0
  486. package/dist/hooks/popperPropsUtils.js +1 -1
  487. package/dist/hooks/treePropsUtils.d.ts +3 -3
  488. package/dist/hooks/treePropsUtils.js +2 -2
  489. package/dist/hooks/useClassNames.d.ts +1 -0
  490. package/dist/hooks/useClickOutside.js +25 -9
  491. package/dist/hooks/useCommonProps.d.ts +4 -0
  492. package/dist/hooks/useCommonProps.js +12 -3
  493. package/dist/hooks/useConfigProvider.d.ts +27 -0
  494. package/dist/hooks/useConfigProvider.js +78 -0
  495. package/dist/hooks/useLockscreen.d.ts +6 -0
  496. package/dist/hooks/useLockscreen.js +45 -0
  497. package/dist/hooks/useResizeObserver.d.ts +1 -1
  498. package/dist/hooks/useResizeObserver.js +7 -7
  499. package/dist/index.css +1 -1
  500. package/dist/index.d.ts +50 -22
  501. package/dist/index.js +27 -10
  502. package/dist/locale/en.d.ts +4 -1
  503. package/dist/locale/en.js +4 -1
  504. package/dist/locale/zhCn.d.ts +4 -1
  505. package/dist/locale/zhCn.js +4 -1
  506. package/package.json +5 -3
  507. package/theme-chalk/affix.scss +7 -0
  508. package/theme-chalk/alert.scss +115 -0
  509. package/theme-chalk/anchor-link.scss +45 -0
  510. package/theme-chalk/anchor.scss +93 -0
  511. package/theme-chalk/aside.scss +8 -8
  512. package/theme-chalk/backtop.scss +29 -0
  513. package/theme-chalk/breadcrumb-item.scss +58 -0
  514. package/theme-chalk/breadcrumb.scss +5 -61
  515. package/theme-chalk/button-group.scss +80 -80
  516. package/theme-chalk/button.scss +304 -304
  517. package/theme-chalk/calendar/date-table.scss +164 -164
  518. package/theme-chalk/cascader-panel.scss +57 -82
  519. package/theme-chalk/cascader.scss +206 -160
  520. package/theme-chalk/checkbox.scss +38 -0
  521. package/theme-chalk/collapse-item.scss +72 -0
  522. package/theme-chalk/collapse.scss +21 -76
  523. package/theme-chalk/color/index.scss +20 -20
  524. package/theme-chalk/common/popup.scss +47 -0
  525. package/theme-chalk/common/transition.scss +142 -142
  526. package/theme-chalk/common/var.scss +62 -6
  527. package/theme-chalk/container.scss +14 -14
  528. package/theme-chalk/dark/css-vars.scss +39 -39
  529. package/theme-chalk/dark/var.scss +225 -225
  530. package/theme-chalk/date-picker.scss +12 -12
  531. package/theme-chalk/dialog.scss +145 -137
  532. package/theme-chalk/drawer.scss +252 -246
  533. package/theme-chalk/footer.scss +12 -12
  534. package/theme-chalk/form-item.scss +437 -0
  535. package/theme-chalk/form.scss +23 -361
  536. package/theme-chalk/header.scss +12 -12
  537. package/theme-chalk/index.scss +21 -1
  538. package/theme-chalk/input/input-range.scss +2 -1
  539. package/theme-chalk/input/input.scss +458 -424
  540. package/theme-chalk/input-number.scss +82 -75
  541. package/theme-chalk/link.scss +87 -87
  542. package/theme-chalk/main.scss +14 -14
  543. package/theme-chalk/menu.scss +353 -353
  544. package/theme-chalk/message-box.scss +160 -133
  545. package/theme-chalk/message.scss +54 -128
  546. package/theme-chalk/mixins/_button.scss +224 -224
  547. package/theme-chalk/mixins/_col.scss +33 -33
  548. package/theme-chalk/mixins/_var.scss +67 -67
  549. package/theme-chalk/mixins/config.scss +5 -5
  550. package/theme-chalk/mixins/function.scss +99 -99
  551. package/theme-chalk/mixins/mixins.scss +237 -240
  552. package/theme-chalk/mixins/utils.scss +39 -39
  553. package/theme-chalk/notification.scss +96 -143
  554. package/theme-chalk/overlay.scss +17 -0
  555. package/theme-chalk/page-header.scss +60 -0
  556. package/theme-chalk/popper.scss +104 -104
  557. package/theme-chalk/radio-button.scss +169 -169
  558. package/theme-chalk/radio.scss +3 -3
  559. package/theme-chalk/segmented.scss +186 -0
  560. package/theme-chalk/select/index.scss +278 -272
  561. package/theme-chalk/slider.scss +212 -0
  562. package/theme-chalk/space.scss +20 -0
  563. package/theme-chalk/statistic.scss +35 -0
  564. package/theme-chalk/step.scss +320 -0
  565. package/theme-chalk/steps.scss +22 -0
  566. package/theme-chalk/switch.scss +300 -300
  567. package/theme-chalk/table-v2.scss +237 -0
  568. package/theme-chalk/table.scss +461 -482
  569. package/theme-chalk/tag.scss +181 -181
  570. package/theme-chalk/text.scss +48 -0
  571. package/theme-chalk/time-range-picker.scss +1 -1
  572. package/theme-chalk/tooltip.scss +2 -2
  573. package/theme-chalk/tour.scss +170 -0
  574. package/theme-chalk/transfer.scss +38 -12
  575. package/theme-chalk/transition.scss +34 -4
  576. package/theme-chalk/tree-select.scss +35 -19
  577. package/theme-chalk/tree.scss +136 -0
  578. package/theme-chalk/var.scss +83 -83
  579. package/theme-chalk/virtual-list.scss +40 -0
  580. package/dist/Input/Input.1.d.ts +0 -16
  581. package/dist/Input/Input.1.js +0 -376
  582. package/dist/Tree/DirectoryTree.d.ts +0 -15
  583. package/dist/Tree/DirectoryTree.js +0 -183
  584. package/dist/Tree/DropIndicator.d.ts +0 -8
  585. package/dist/Tree/DropIndicator.js +0 -34
  586. package/dist/Tree/Indent.d.ts +0 -9
  587. package/dist/Tree/MotionTreeNode.d.ts +0 -14
  588. package/dist/Tree/MotionTreeNode.js +0 -125
  589. package/dist/Tree/NodeList.d.ts +0 -50
  590. package/dist/Tree/NodeList.js +0 -301
  591. package/dist/Tree/RCTree.d.ts +0 -248
  592. package/dist/Tree/RCTree.js +0 -1216
  593. package/dist/Tree/contextTypes.d.ts +0 -69
  594. package/dist/Tree/contextTypes.js +0 -9
  595. package/dist/Tree/typings.tsx--bak +0 -245
  596. package/dist/Tree/useUnmount.d.ts +0 -5
  597. package/dist/Tree/useUnmount.js +0 -34
  598. package/dist/Tree/util.d.ts +0 -51
  599. package/dist/Tree/util.js +0 -303
  600. package/dist/Tree/utils/conductUtil.d.ts +0 -17
  601. package/dist/Tree/utils/conductUtil.js +0 -209
  602. package/dist/Tree/utils/dictUtil.d.ts +0 -13
  603. package/dist/Tree/utils/dictUtil.js +0 -75
  604. package/dist/Tree/utils/diffUtil.d.ts +0 -7
  605. package/dist/Tree/utils/diffUtil.js +0 -48
  606. package/dist/Tree/utils/dropIndicator.d.ts +0 -11
  607. package/dist/Tree/utils/dropIndicator.js +0 -36
  608. package/dist/Tree/utils/iconUtil.d.ts +0 -5
  609. package/dist/Tree/utils/iconUtil.js +0 -62
  610. package/dist/Tree/utils/keyUtil.d.ts +0 -2
  611. package/dist/Tree/utils/keyUtil.js +0 -3
  612. package/dist/Tree/utils/motion.d.ts +0 -10
  613. package/dist/Tree/utils/motion.js +0 -54
  614. package/dist/Tree/utils/pickAttrs.d.ts +0 -11
  615. package/dist/Tree/utils/pickAttrs.js +0 -51
  616. package/dist/Tree/utils/treeUtil.d.ts +0 -86
  617. package/dist/Tree/utils/treeUtil.js +0 -364
  618. package/theme-chalk/button/_mixins.scss +0 -317
  619. package/theme-chalk/button/button-group.scss +0 -83
  620. package/theme-chalk/button/button.scss +0 -382
  621. package/theme-chalk/button/index.scss +0 -2
  622. package/theme-chalk/button--bak/_mixins.scss +0 -317
  623. package/theme-chalk/button--bak/button-group.scss +0 -83
  624. package/theme-chalk/button--bak/button.scss +0 -382
  625. package/theme-chalk/button--bak/index.scss +0 -2
  626. package/theme-chalk/calendar/date-table.scss--bak +0 -156
  627. package/theme-chalk/input/input.scss--bak +0 -578
  628. package/theme-chalk/link.scss--bak +0 -99
  629. package/theme-chalk/popper.scss--bak +0 -86
  630. package/theme-chalk/radio-button.scss--bak +0 -128
  631. package/theme-chalk/select/index.scss--bak +0 -247
  632. package/theme-chalk/switch.scss--bak +0 -273
  633. package/theme-chalk/tag.scss--bak +0 -203
  634. package/theme-chalk/tree/_directory.scss +0 -73
  635. package/theme-chalk/tree/_tree.scss +0 -401
  636. package/theme-chalk/tree/index.scss +0 -2
@@ -1,45 +1,43 @@
1
- var _excluded = ["name", "rules"];
2
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
3
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["name", "rules"];
3
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
4
4
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
5
5
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
6
6
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
7
7
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
8
8
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
9
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
14
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
10
17
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
18
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
19
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
20
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
21
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
15
22
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
16
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
18
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
19
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
20
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
21
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
22
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
23
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
24
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
25
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
26
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
28
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ import { useMount, useUnmount } from 'ahooks';
29
24
  import classNames from 'classnames';
30
25
  import head from 'lodash/head';
31
- import React, { Children, cloneElement, createRef, isValidElement, memo, useContext } from 'react';
26
+ import React, { Children, cloneElement, isValidElement, memo, useCallback, useContext, useMemo, useRef, useState } from 'react';
32
27
  import Icon from "../Icon/Icon";
33
28
  import Tooltip from "../Tooltip/Tooltip";
34
29
  import Transition from "../Transition/Transition";
35
- import { addUnit, isNotEmpty, warning } from "../Util";
36
- import FieldContext, { HOOK_MARK } from "./FieldContext";
30
+ import { addUnit, isNotEmpty, mergeDefaultProps, warning } from "../Util";
31
+ import useClassNames from "../hooks/useClassNames";
32
+ import { useForceUpdate } from "../hooks/useForceUpdate";
33
+ import FormContext from "./FormContext";
37
34
  import { FormItemContext } from "./FormItemContext";
38
- import { b, e, m } from "./utils/classUtil";
35
+ import FormLabelWrap from "./FormLabelWrap";
36
+ import FieldContext, { HOOK_MARK } from "./InternalFormContext";
39
37
  import get from "./utils/get";
40
38
  import { toArray } from "./utils/typeUtil";
41
39
  import { validateRules } from "./utils/validateUtil";
42
- import { containsNamePath, defaultGetValueFromEvent, getNamePath, getValue } from "./utils/valueUtil";
40
+ import { containsNamePath, defaultGetValueFromEvent, getNamePath as getNameArray, getValue as getValueFromName } from "./utils/valueUtil";
43
41
  var EMPTY_ERRORS = [];
44
42
  function requireUpdate(shouldUpdate, prev, next, prevValue, nextValue, info) {
45
43
  if (typeof shouldUpdate === 'function') {
@@ -49,664 +47,651 @@ function requireUpdate(shouldUpdate, prev, next, prevValue, nextValue, info) {
49
47
  }
50
48
  return prevValue !== nextValue;
51
49
  }
52
-
53
- // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
54
- // We use Class instead of Hooks here since it will cost much code by using Hooks.
55
- var Field = /*#__PURE__*/function (_React$Component) {
56
- _inherits(Field, _React$Component);
57
- var _super = _createSuper(Field);
58
- // ============================== Subscriptions ==============================
59
- function Field(props) {
60
- var _this;
61
- _classCallCheck(this, Field);
62
- _this = _super.call(this, props);
63
-
64
- // Register on init
65
- _defineProperty(_assertThisInitialized(_this), "state", {
66
- resetCount: 0
67
- });
68
- _defineProperty(_assertThisInitialized(_this), "cancelRegisterFunc", null);
69
- _defineProperty(_assertThisInitialized(_this), "mounted", false);
70
- /**
71
- * Follow state should not management in State since it will async update by
72
- * This makes first render of form can not get correct state value.
73
- */
74
- _defineProperty(_assertThisInitialized(_this), "touched", false);
75
- /**
76
- * Mark when touched & validated. Currently only used for `dependencies`.
77
- * Note that we do not think field with `initialValue` is dirty
78
- * but this will be by `isFieldDirty` func.
79
- */
80
- _defineProperty(_assertThisInitialized(_this), "dirty", false);
81
- _defineProperty(_assertThisInitialized(_this), "validatePromise", null);
82
- _defineProperty(_assertThisInitialized(_this), "prevValidating", void 0);
83
- _defineProperty(_assertThisInitialized(_this), "errors", EMPTY_ERRORS);
84
- _defineProperty(_assertThisInitialized(_this), "warnings", EMPTY_ERRORS);
85
- _defineProperty(_assertThisInitialized(_this), "warningRef", void 0);
86
- _defineProperty(_assertThisInitialized(_this), "errorRef", void 0);
87
- _defineProperty(_assertThisInitialized(_this), "containerRef", void 0);
88
- _defineProperty(_assertThisInitialized(_this), "cancelRegister", function () {
89
- var _this$props = _this.props,
90
- preserve = _this$props.preserve,
91
- isListField = _this$props.isListField,
92
- name = _this$props.name;
93
- if (_this.cancelRegisterFunc) {
94
- _this.cancelRegisterFunc(isListField, preserve, getNamePath(name));
50
+ function Field(props) {
51
+ var _this = this;
52
+ props = mergeDefaultProps({
53
+ dependencies: [],
54
+ rules: [],
55
+ validateFirst: false,
56
+ colon: false,
57
+ trigger: 'onChange',
58
+ valuePropName: 'value',
59
+ labelStyle: {}
60
+ }, props);
61
+ var _props = props,
62
+ shouldUpdate = _props.shouldUpdate,
63
+ dependencies = _props.dependencies,
64
+ onReset = _props.onReset,
65
+ onMetaChange = _props.onMetaChange,
66
+ preserve = _props.preserve,
67
+ isListField = _props.isListField,
68
+ isList = _props.isList,
69
+ validateFirst = _props.validateFirst,
70
+ messageVariables = _props.messageVariables,
71
+ trigger = _props.trigger,
72
+ validateTrigger = _props.validateTrigger,
73
+ getValueFromEvent = _props.getValueFromEvent,
74
+ normalize = _props.normalize,
75
+ valuePropName = _props.valuePropName,
76
+ getValueProps = _props.getValueProps,
77
+ children = _props.children,
78
+ label = _props.label,
79
+ className = _props.className,
80
+ style = _props.style,
81
+ noStyle = _props.noStyle,
82
+ labelStyle = _props.labelStyle,
83
+ colon = _props.colon,
84
+ size = _props.size,
85
+ help = _props.help,
86
+ pure = _props.pure,
87
+ validateState = _props.validateState,
88
+ errorStyle = _props.errorStyle,
89
+ warningStyle = _props.warningStyle;
90
+ var fieldContext = useContext(FieldContext);
91
+ var name = useMemo(function () {
92
+ return props.name !== undefined ? getNameArray(props.name) : undefined;
93
+ }, [props.name]);
94
+ var _useClassNames = useClassNames('form-item'),
95
+ b = _useClassNames.b,
96
+ e = _useClassNames.e,
97
+ m = _useClassNames.m,
98
+ is = _useClassNames.is;
99
+ var key = 'keep';
100
+ if (!isListField) {
101
+ key = "_".concat((name || []).join('_'));
102
+ }
103
+ if (process.env.NODE_ENV !== 'production' && preserve === false && isListField && name.length <= 1) {
104
+ warning(false, '`preserve` should not apply on ElFormList fields.');
105
+ }
106
+ var formRules = useMemo(function () {
107
+ var _fieldContext$rules;
108
+ return (name === null || name === void 0 ? void 0 : name.length) > 0 ? get((_fieldContext$rules = fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.rules) !== null && _fieldContext$rules !== void 0 ? _fieldContext$rules : {}, name) : undefined;
109
+ }, [name, fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.rules]);
110
+ var rules = useMemo(function () {
111
+ return [].concat(_toConsumableArray(formRules || []), _toConsumableArray(props.rules || []));
112
+ }, [formRules, props.rules]);
113
+ var _useState = useState(0),
114
+ _useState2 = _slicedToArray(_useState, 2),
115
+ resetCount = _useState2[0],
116
+ setResetCount = _useState2[1];
117
+ var _useState3 = useState(0),
118
+ _useState4 = _slicedToArray(_useState3, 2),
119
+ computedWidth = _useState4[0],
120
+ setComputedWidth = _useState4[1];
121
+ var oldWidthRef = useRef(0);
122
+ var mountedRef = useRef(false);
123
+ /**
124
+ * Follow state should not management in State since it will async update by
125
+ * This makes first render of form can not get correct state value.
126
+ */
127
+ var touchedRef = useRef(false);
128
+ /**
129
+ * Mark when touched & validated. Currently only used for `dependencies`.
130
+ * Note that we do not think field with `initialValue` is dirty
131
+ * but this will be by `isFieldDirty` func.
132
+ */
133
+ var dirtyRef = useRef(false);
134
+ var validatePromiseRef = useRef(null);
135
+ var errorsRef = useRef(EMPTY_ERRORS);
136
+ var warningsRef = useRef(EMPTY_ERRORS);
137
+ var cancelRegisterFuncRef = useRef(null);
138
+ var warningRef = useRef(null);
139
+ var errorRef = useRef(null);
140
+ var containerRef = useRef(null);
141
+ var _useForceUpdate = useForceUpdate(),
142
+ forceUpdate = _useForceUpdate.forceUpdate;
143
+ var reRender = useCallback(function () {
144
+ if (!mountedRef.current) {
145
+ return;
146
+ }
147
+ forceUpdate();
148
+ }, [forceUpdate]);
149
+ var getNamePath = useCallback(function () {
150
+ var _fieldContext$prefixN = fieldContext.prefixName,
151
+ prefixName = _fieldContext$prefixN === void 0 ? [] : _fieldContext$prefixN;
152
+ return name !== undefined ? [].concat(_toConsumableArray(prefixName), _toConsumableArray(name)) : [];
153
+ }, [fieldContext, name]);
154
+ var getRules = useCallback(function () {
155
+ return rules.map(function (rule) {
156
+ if (typeof rule === 'function') {
157
+ return rule(fieldContext);
95
158
  }
96
- _this.cancelRegisterFunc = null;
159
+ return rule;
97
160
  });
98
- // ================================== Utils ==================================
99
- _defineProperty(_assertThisInitialized(_this), "getNamePath", function () {
100
- var _this$props2 = _this.props,
101
- name = _this$props2.name,
102
- fieldContext = _this$props2.fieldContext;
103
- var _fieldContext$prefixN = fieldContext.prefixName,
104
- prefixName = _fieldContext$prefixN === void 0 ? [] : _fieldContext$prefixN;
105
- return name !== undefined ? [].concat(_toConsumableArray(prefixName), _toConsumableArray(name)) : [];
161
+ }, [rules, fieldContext]);
162
+ var refresh = useCallback(function () {
163
+ if (!mountedRef.current) {
164
+ return;
165
+ }
166
+ setResetCount(function (prev) {
167
+ return prev + 1;
106
168
  });
107
- _defineProperty(_assertThisInitialized(_this), "getRules", function () {
108
- var _this$props3 = _this.props,
109
- _this$props3$rules = _this$props3.rules,
110
- rules = _this$props3$rules === void 0 ? [] : _this$props3$rules,
111
- fieldContext = _this$props3.fieldContext;
112
- return rules.map(function (rule) {
113
- if (typeof rule === 'function') {
114
- return rule(fieldContext);
115
- }
116
- return rule;
117
- });
169
+ }, []);
170
+ var triggerMetaEvent = useCallback(function (destroy) {
171
+ onMetaChange === null || onMetaChange === void 0 || onMetaChange(_objectSpread(_objectSpread({}, _this.getMeta()), {}, {
172
+ destroy: destroy
173
+ }));
174
+ }, [onMetaChange]);
175
+ var cancelRegister = useCallback(function () {
176
+ if (cancelRegisterFuncRef.current) {
177
+ cancelRegisterFuncRef.current(isListField, preserve, getNameArray(name));
178
+ }
179
+ cancelRegisterFuncRef.current = null;
180
+ }, [isListField, preserve, name]);
181
+ var getValue = useCallback(function (store) {
182
+ var getFieldsValue = fieldContext.getFieldsValue;
183
+ return getValueFromName(store || getFieldsValue(true), getNamePath());
184
+ }, [fieldContext, getNamePath]);
185
+ var isFieldValidating = useCallback(function () {
186
+ return !!validatePromiseRef.current;
187
+ }, []);
188
+ var isFieldTouched = useCallback(function () {
189
+ return touchedRef.current;
190
+ }, []);
191
+ var isFieldDirty = useCallback(function () {
192
+ if (dirtyRef.current || props.initialValue !== undefined) {
193
+ return true;
194
+ }
195
+ var _fieldContext$getInte = fieldContext.getInternalHooks(HOOK_MARK),
196
+ getInitialValue = _fieldContext$getInte.getInitialValue;
197
+ if (getInitialValue(getNamePath()) !== undefined) {
198
+ return true;
199
+ }
200
+ return false;
201
+ }, [fieldContext, getNamePath, props.initialValue]);
202
+ var getErrors = useCallback(function () {
203
+ return errorsRef.current;
204
+ }, []);
205
+ var getWarnings = useCallback(function () {
206
+ return warningsRef.current;
207
+ }, []);
208
+ var getMeta = useCallback(function () {
209
+ return {
210
+ touched: touchedRef.current,
211
+ validating: isFieldValidating(),
212
+ errors: errorsRef.current,
213
+ warnings: warningsRef.current,
214
+ name: getNamePath()
215
+ };
216
+ }, [isFieldValidating, getNamePath]);
217
+ var onClear = useCallback(function () {
218
+ var _children$props, _children$props$onCle;
219
+ touchedRef.current = true;
220
+ var _fieldContext$getInte2 = fieldContext.getInternalHooks(HOOK_MARK),
221
+ dispatch = _fieldContext$getInte2.dispatch;
222
+ dispatch({
223
+ type: 'updateValue',
224
+ namePath: getNamePath(),
225
+ value: ''
118
226
  });
119
- _defineProperty(_assertThisInitialized(_this), "refresh", function () {
120
- if (!_this.mounted) {
121
- return;
122
- }
227
+ // @ts-ignore
228
+ children === null || children === void 0 || (_children$props = children.props) === null || _children$props === void 0 || (_children$props$onCle = _children$props.onClear) === null || _children$props$onCle === void 0 || _children$props$onCle.call(_children$props);
229
+ }, [fieldContext, getNamePath, children]);
230
+ var getControlled = useCallback(function () {
231
+ var childProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
232
+ var mergedValidateTrigger = validateTrigger !== undefined ? validateTrigger : fieldContext.validateTrigger;
233
+ var namePath = getNamePath();
234
+ var _fieldContext$getInte3 = fieldContext.getInternalHooks(HOOK_MARK),
235
+ dispatch = _fieldContext$getInte3.dispatch;
236
+ var value = getValue();
237
+ var mergedGetValueProps = getValueProps || function (val) {
238
+ return _defineProperty({}, valuePropName, val);
239
+ };
123
240
 
124
- /**
125
- * Clean up current node.
126
- */
127
- _this.setState(function (_ref) {
128
- var resetCount = _ref.resetCount;
129
- return {
130
- resetCount: resetCount + 1
131
- };
132
- });
241
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
242
+ var originTriggerFunc = childProps[trigger];
243
+ var control = _objectSpread(_objectSpread(_objectSpread({}, childProps), mergedGetValueProps(value)), {}, {
244
+ error: errorsRef.current.length > 0,
245
+ warning: warningsRef.current.length > 0,
246
+ onClear: onClear
133
247
  });
134
- _defineProperty(_assertThisInitialized(_this), "triggerMetaEvent", function (destroy) {
135
- var onMetaChange = _this.props.onMetaChange;
136
- onMetaChange === null || onMetaChange === void 0 || onMetaChange(_objectSpread(_objectSpread({}, _this.getMeta()), {}, {
137
- destroy: destroy
138
- }));
139
- });
140
- // ========================= Field Entity Interfaces =========================
141
- // Trigger by store update. Check if need update the component
142
- _defineProperty(_assertThisInitialized(_this), "onStoreChange", function (prevStore, namePathList, info) {
143
- var _this$props4 = _this.props,
144
- shouldUpdate = _this$props4.shouldUpdate,
145
- _this$props4$dependen = _this$props4.dependencies,
146
- dependencies = _this$props4$dependen === void 0 ? [] : _this$props4$dependen,
147
- onReset = _this$props4.onReset;
148
- var store = info.store;
149
- var namePath = _this.getNamePath();
150
- var prevValue = _this.getValue(prevStore);
151
- var curValue = _this.getValue(store);
152
- var namePathMatch = namePathList && containsNamePath(namePathList, namePath);
153
-
154
- // `setFieldsValue` is a quick access to update related status
155
- if (info.type === 'valueUpdate' && info.source === 'external' && prevValue !== curValue) {
156
- _this.touched = true;
157
- _this.dirty = true;
158
- _this.validatePromise = null;
159
- _this.errors = EMPTY_ERRORS;
160
- _this.warnings = EMPTY_ERRORS;
161
- _this.triggerMetaEvent();
248
+ control[trigger] = function () {
249
+ touchedRef.current = true;
250
+ dirtyRef.current = true;
251
+ triggerMetaEvent();
252
+ var newValue;
253
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
254
+ args[_key] = arguments[_key];
162
255
  }
163
- switch (info.type) {
164
- case 'reset':
165
- if (!namePathList || namePathMatch) {
166
- // Clean up state
167
- _this.touched = false;
168
- _this.dirty = false;
169
- _this.validatePromise = null;
170
- _this.errors = EMPTY_ERRORS;
171
- _this.warnings = EMPTY_ERRORS;
172
- _this.triggerMetaEvent();
173
- onReset === null || onReset === void 0 || onReset();
174
- _this.refresh();
175
- return;
176
- }
177
- break;
178
-
179
- /**
180
- * In case field with `preserve = false` nest deps like:
181
- * - A = 1 => show B
182
- * - B = 1 => show C
183
- * - Reset A, need clean B, C
184
- */
185
- case 'remove':
186
- {
187
- if (shouldUpdate) {
188
- _this.reRender();
189
- return;
190
- }
191
- break;
192
- }
193
- case 'setField':
194
- {
195
- if (namePathMatch) {
196
- var data = info.data;
197
- if ('touched' in data) {
198
- _this.touched = data.touched;
199
- }
200
- if ('validating' in data && !('originRCField' in data)) {
201
- _this.validatePromise = data.validating ? Promise.resolve([]) : null;
202
- }
203
- if ('errors' in data) {
204
- _this.errors = data.errors || EMPTY_ERRORS;
205
- }
206
- if ('warnings' in data) {
207
- _this.warnings = data.warnings || EMPTY_ERRORS;
208
- }
209
- _this.dirty = true;
210
- _this.triggerMetaEvent();
211
- _this.reRender();
212
- return;
213
- }
214
-
215
- // Handle update by `setField` with `shouldUpdate`
216
- if (shouldUpdate && !namePath.length && requireUpdate(shouldUpdate, prevStore, store, prevValue, curValue, info)) {
217
- _this.reRender();
218
- return;
219
- }
220
- break;
221
- }
222
- case 'dependenciesUpdate':
223
- {
224
- //
225
- /**
226
- * Trigger when marked `dependencies` updated. Related fields will all update
227
- */
228
- var dependencyList = dependencies.map(getNamePath);
229
- // No need for `namePathMath` check and `shouldUpdate` check, since `valueUpdate` will be
230
- // emitted earlier and they will work there
231
- // If set it may cause unnecessary twice rerendering
232
- if (dependencyList.some(function (dependency) {
233
- return containsNamePath(info.relatedFields, dependency);
234
- })) {
235
- _this.reRender();
236
- return;
237
- }
238
- break;
239
- }
240
- default:
241
- // 1. If `namePath` exists in `namePathList`, means it's related value and should update
242
- // For example <List name="list"><Field name={['list', 0]}/>
243
- // If `namePathList` is [['list']] (List value update), Field should be updated
244
- // If `namePathList` is [['list', 0]] (Field value update), List shouldn't be updated
245
- // 2.
246
- // 2.1 If `dependencies` is set, `name` is not set and `shouldUpdate` is not set,
247
- // don't use `shouldUpdate`. `dependencies` is view as a shortcut if `shouldUpdate`
248
- // is not provided
249
- // 2.2 If `shouldUpdate` provided, use customize logic to update the field
250
- // else to check if value changed
251
- if (namePathMatch || (!dependencies.length || namePath.length || shouldUpdate) && requireUpdate(shouldUpdate, prevStore, store, prevValue, curValue, info)) {
252
- _this.reRender();
253
- return;
254
- }
255
- break;
256
+ if (getValueFromEvent) {
257
+ newValue = getValueFromEvent.apply(void 0, args);
258
+ } else {
259
+ newValue = defaultGetValueFromEvent.apply(void 0, [valuePropName].concat(args));
256
260
  }
257
- if (shouldUpdate === true) {
258
- _this.reRender();
261
+ if (normalize) {
262
+ newValue = normalize(newValue, value, fieldContext.getFieldsValue(true));
259
263
  }
260
- });
261
- _defineProperty(_assertThisInitialized(_this), "validateRules", function (options) {
262
- // We should fixed namePath & value to avoid developer change then by form function
263
- var namePath = _this.getNamePath();
264
- var currentValue = _this.getValue();
265
-
266
- // Force change to async to avoid rule OOD under renderProps field
267
- var rootPromise = Promise.resolve().then(function () {
268
- if (!_this.mounted) {
269
- return [];
264
+ dispatch({
265
+ type: 'updateValue',
266
+ namePath: namePath,
267
+ value: newValue
268
+ });
269
+ if (originTriggerFunc) {
270
+ originTriggerFunc.apply(void 0, args);
271
+ }
272
+ };
273
+ var validateTriggerList = toArray(mergedValidateTrigger || []);
274
+ validateTriggerList.forEach(function (triggerName) {
275
+ var originTrigger = control[triggerName];
276
+ control[triggerName] = function () {
277
+ if (originTrigger) {
278
+ originTrigger.apply(void 0, arguments);
270
279
  }
271
- var _this$props5 = _this.props,
272
- _this$props5$validate = _this$props5.validateFirst,
273
- validateFirst = _this$props5$validate === void 0 ? false : _this$props5$validate,
274
- messageVariables = _this$props5.messageVariables;
275
- var _ref2 = options || {},
276
- triggerName = _ref2.triggerName;
277
- var filteredRules = _this.getRules();
278
- if (triggerName) {
279
- filteredRules = filteredRules.filter(function (rule) {
280
- return rule;
281
- }).filter(function (rule) {
282
- var validateTrigger = rule.validateTrigger;
283
- if (!validateTrigger) {
284
- return true;
285
- }
286
- var triggerList = toArray(validateTrigger);
287
- return triggerList.includes(triggerName);
280
+ // We dispatch validate to root,
281
+ // since it will update related data with other field with same name
282
+ if (rules && rules.length) {
283
+ dispatch({
284
+ type: 'validateField',
285
+ namePath: namePath,
286
+ triggerName: triggerName
288
287
  });
289
288
  }
290
- var promise = validateRules(namePath, currentValue, filteredRules, options, validateFirst, messageVariables);
291
- promise.catch(function (e) {
292
- return e;
293
- }).then(function () {
294
- var ruleErrors = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : EMPTY_ERRORS;
295
- if (_this.validatePromise === rootPromise) {
296
- var _ruleErrors$forEach;
297
- _this.validatePromise = null;
298
-
299
- // Get errors & warnings
300
- var nextErrors = [];
301
- var nextWarnings = [];
302
- (_ruleErrors$forEach = ruleErrors.forEach) === null || _ruleErrors$forEach === void 0 || _ruleErrors$forEach.call(ruleErrors, function (_ref3) {
303
- var warningOnly = _ref3.rule.warningOnly,
304
- _ref3$errors = _ref3.errors,
305
- errors = _ref3$errors === void 0 ? EMPTY_ERRORS : _ref3$errors;
306
- if (warningOnly) {
307
- nextWarnings.push.apply(nextWarnings, _toConsumableArray(errors));
308
- } else {
309
- nextErrors.push.apply(nextErrors, _toConsumableArray(errors));
310
- }
311
- });
312
- _this.errors = nextErrors;
313
- _this.warnings = nextWarnings;
314
- _this.triggerMetaEvent();
315
- _this.reRender();
316
- }
317
- });
318
- return promise;
319
- });
320
- _this.validatePromise = rootPromise;
321
- _this.dirty = true;
322
- _this.errors = EMPTY_ERRORS;
323
- _this.warnings = EMPTY_ERRORS;
324
- _this.triggerMetaEvent();
325
-
326
- // Force trigger re-render since we need sync renderProps with new meta
327
- _this.reRender();
328
- return rootPromise;
329
- });
330
- _defineProperty(_assertThisInitialized(_this), "isFieldValidating", function () {
331
- return !!_this.validatePromise;
332
- });
333
- _defineProperty(_assertThisInitialized(_this), "isFieldTouched", function () {
334
- return _this.touched;
335
- });
336
- _defineProperty(_assertThisInitialized(_this), "isFieldDirty", function () {
337
- // Touched or validate or has initialValue
338
- if (_this.dirty || _this.props.initialValue !== undefined) {
339
- return true;
340
- }
341
-
342
- // Form set initialValue
343
- var fieldContext = _this.props.fieldContext;
344
- var _fieldContext$getInte = fieldContext.getInternalHooks(HOOK_MARK),
345
- getInitialValue = _fieldContext$getInte.getInitialValue;
346
- if (getInitialValue(_this.getNamePath()) !== undefined) {
347
- return true;
348
- }
349
- return false;
350
- });
351
- _defineProperty(_assertThisInitialized(_this), "getErrors", function () {
352
- return _this.errors;
353
- });
354
- _defineProperty(_assertThisInitialized(_this), "getWarnings", function () {
355
- return _this.warnings;
356
- });
357
- _defineProperty(_assertThisInitialized(_this), "isListField", function () {
358
- return _this.props.isListField;
359
- });
360
- _defineProperty(_assertThisInitialized(_this), "isList", function () {
361
- return _this.props.isList;
362
- });
363
- _defineProperty(_assertThisInitialized(_this), "isPreserve", function () {
364
- return _this.props.preserve;
365
- });
366
- // ============================= Child Component =============================
367
- _defineProperty(_assertThisInitialized(_this), "getMeta", function () {
368
- // Make error & validating in cache to save perf
369
- _this.prevValidating = _this.isFieldValidating();
370
- var meta = {
371
- touched: _this.isFieldTouched(),
372
- validating: _this.prevValidating,
373
- errors: _this.errors,
374
- warnings: _this.warnings,
375
- name: _this.getNamePath()
376
289
  };
377
- return meta;
378
290
  });
379
- // Only return validate child node. If invalidate, will do nothing about field.
380
- _defineProperty(_assertThisInitialized(_this), "getOnlyChild", function (children) {
381
- // Support render props
382
- if (typeof children === 'function') {
383
- var _meta = _this.getMeta();
384
- return _objectSpread(_objectSpread({}, _this.getOnlyChild(children(_this.getControlled(), _meta, _this.props.fieldContext))), {}, {
385
- isFunction: true
386
- });
387
- }
388
-
389
- // Filed element only
390
- var childList = Children.toArray(children);
391
- if (childList.length !== 1 || ! /*#__PURE__*/isValidElement(childList[0])) {
392
- // @ts-ignore
393
- return {
394
- child: childList,
395
- isFunction: false
396
- };
397
- }
398
-
291
+ return control;
292
+ }, [validateTrigger, fieldContext, getNamePath, getValue, getValueProps, valuePropName, trigger, onClear, triggerMetaEvent, getValueFromEvent, normalize, rules]);
293
+ var getOnlyChild = useCallback(function (childs) {
294
+ if (typeof childs === 'function') {
295
+ var _meta = getMeta();
296
+ return _objectSpread(_objectSpread({}, getOnlyChild(childs(getControlled(), _meta, fieldContext))), {}, {
297
+ isFunction: true
298
+ });
299
+ }
300
+ var childList = Children.toArray(childs);
301
+ if (childList.length !== 1 || ! /*#__PURE__*/isValidElement(childList[0])) {
399
302
  // @ts-ignore
400
303
  return {
401
- child: childList[0],
304
+ child: childList,
402
305
  isFunction: false
403
306
  };
404
- });
405
- // ============================== Field Control ==============================
406
- _defineProperty(_assertThisInitialized(_this), "getValue", function (store) {
407
- var getFieldsValue = _this.props.fieldContext.getFieldsValue;
408
- var namePath = _this.getNamePath();
409
- return getValue(store || getFieldsValue(true), namePath);
410
- });
411
- _defineProperty(_assertThisInitialized(_this), "getControlled", function () {
412
- var childProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
413
- var _this$props6 = _this.props,
414
- trigger = _this$props6.trigger,
415
- validateTrigger = _this$props6.validateTrigger,
416
- getValueFromEvent = _this$props6.getValueFromEvent,
417
- normalize = _this$props6.normalize,
418
- valuePropName = _this$props6.valuePropName,
419
- getValueProps = _this$props6.getValueProps,
420
- fieldContext = _this$props6.fieldContext;
421
- var mergedValidateTrigger = validateTrigger !== undefined ? validateTrigger : fieldContext.validateTrigger;
422
- var namePath = _this.getNamePath();
423
- var getInternalHooks = fieldContext.getInternalHooks,
424
- getFieldsValue = fieldContext.getFieldsValue;
425
- var _getInternalHooks = getInternalHooks(HOOK_MARK),
426
- dispatch = _getInternalHooks.dispatch;
427
- var value = _this.getValue();
428
- var mergedGetValueProps = getValueProps || function (val) {
429
- return _defineProperty({}, valuePropName, val);
430
- };
307
+ }
308
+
309
+ // @ts-ignore
310
+ return {
311
+ child: childList[0],
312
+ isFunction: false
313
+ };
314
+ }, [getMeta, getControlled, fieldContext]);
315
+ var validateRulesFunc = useCallback(function (options) {
316
+ // We should fixed namePath & value to avoid developer change then by form function
317
+ var namePath = getNamePath();
318
+ var currentValue = getValue();
431
319
 
432
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
433
- var originTriggerFunc = childProps[trigger];
434
- var control = _objectSpread(_objectSpread(_objectSpread({}, childProps), mergedGetValueProps(value)), {}, {
435
- error: _this.errors.length > 0,
436
- warning: _this.warnings.length > 0,
437
- onClear: _this.onClear
320
+ // Force change to async to avoid rule OOD under renderProps field
321
+ var rootPromise = Promise.resolve().then(function () {
322
+ if (!mountedRef.current) {
323
+ return [];
324
+ }
325
+ var _ref2 = options || {},
326
+ triggerName = _ref2.triggerName;
327
+ var filteredRules = getRules();
328
+ if (triggerName) {
329
+ filteredRules = filteredRules.filter(function (rule) {
330
+ return rule;
331
+ }).filter(function (rule) {
332
+ var ruleValidateTrigger = rule.validateTrigger;
333
+ if (!ruleValidateTrigger) {
334
+ return true;
335
+ }
336
+ var triggerList = toArray(ruleValidateTrigger);
337
+ return triggerList.includes(triggerName);
338
+ });
339
+ }
340
+ var promise = validateRules(namePath, currentValue, filteredRules, options, validateFirst, messageVariables);
341
+ promise.catch(function (error) {
342
+ return error;
343
+ }).then(function () {
344
+ var ruleErrors = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : EMPTY_ERRORS;
345
+ if (validatePromiseRef.current === rootPromise) {
346
+ var _ruleErrors$forEach;
347
+ validatePromiseRef.current = null;
348
+
349
+ // Get errors & warnings
350
+ var nextErrors = [];
351
+ var nextWarnings = [];
352
+ (_ruleErrors$forEach = ruleErrors.forEach) === null || _ruleErrors$forEach === void 0 || _ruleErrors$forEach.call(ruleErrors, function (_ref3) {
353
+ var warningOnly = _ref3.rule.warningOnly,
354
+ _ref3$errors = _ref3.errors,
355
+ errors = _ref3$errors === void 0 ? EMPTY_ERRORS : _ref3$errors;
356
+ if (warningOnly) {
357
+ nextWarnings.push.apply(nextWarnings, _toConsumableArray(errors));
358
+ } else {
359
+ nextErrors.push.apply(nextErrors, _toConsumableArray(errors));
360
+ }
361
+ });
362
+ errorsRef.current = nextErrors;
363
+ warningsRef.current = nextWarnings;
364
+ triggerMetaEvent();
365
+ reRender();
366
+ }
438
367
  });
368
+ return promise;
369
+ });
370
+ validatePromiseRef.current = rootPromise;
371
+ dirtyRef.current = true;
372
+ errorsRef.current = EMPTY_ERRORS;
373
+ warningsRef.current = EMPTY_ERRORS;
374
+ triggerMetaEvent();
375
+ // Force trigger re-render since we need sync renderProps with new meta
376
+ reRender();
377
+ return rootPromise;
378
+ }, [getNamePath, getValue, getRules, validateFirst, messageVariables, triggerMetaEvent, reRender]);
379
+ var onStoreChange = useCallback(function (prevStore, namePathList, info) {
380
+ var store = info.store;
381
+ var namePath = getNamePath();
382
+ var prevValue = getValue(prevStore);
383
+ var curValue = getValue(store);
384
+ var namePathMatch = namePathList && containsNamePath(namePathList, namePath);
385
+ if (info.type === 'valueUpdate' && info.source === 'external' && prevValue !== curValue) {
386
+ touchedRef.current = true;
387
+ dirtyRef.current = true;
388
+ validatePromiseRef.current = null;
389
+ errorsRef.current = EMPTY_ERRORS;
390
+ warningsRef.current = EMPTY_ERRORS;
391
+ triggerMetaEvent();
392
+ }
393
+ switch (info.type) {
394
+ case 'reset':
395
+ if (!namePathList || namePathMatch) {
396
+ touchedRef.current = false;
397
+ dirtyRef.current = false;
398
+ validatePromiseRef.current = null;
399
+ errorsRef.current = EMPTY_ERRORS;
400
+ warningsRef.current = EMPTY_ERRORS;
401
+ triggerMetaEvent();
402
+ onReset === null || onReset === void 0 || onReset();
403
+ refresh();
404
+ return;
405
+ }
406
+ break;
439
407
 
440
- // Add trigger
441
- control[trigger] = function () {
442
- // Mark as touched
443
- _this.touched = true;
444
- _this.dirty = true;
445
- _this.triggerMetaEvent();
446
- var newValue;
447
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
448
- args[_key] = arguments[_key];
408
+ /**
409
+ * In case field with `preserve = false` nest deps like:
410
+ * - A = 1 => show B
411
+ * - B = 1 => show C
412
+ * - Reset A, need clean B, C
413
+ */
414
+ case 'remove':
415
+ if (shouldUpdate) {
416
+ reRender();
417
+ return;
449
418
  }
450
- if (getValueFromEvent) {
451
- newValue = getValueFromEvent.apply(void 0, args);
452
- } else {
453
- newValue = defaultGetValueFromEvent.apply(void 0, [valuePropName].concat(args));
419
+ break;
420
+ case 'setField':
421
+ {
422
+ if (namePathMatch) {
423
+ var data = info.data;
424
+ if ('touched' in data) {
425
+ touchedRef.current = data.touched;
426
+ }
427
+ if ('validating' in data && !('originRCField' in data)) {
428
+ validatePromiseRef.current = data.validating ? Promise.resolve([]) : null;
429
+ }
430
+ if ('errors' in data) {
431
+ errorsRef.current = data.errors || EMPTY_ERRORS;
432
+ }
433
+ if ('warnings' in data) {
434
+ warningsRef.current = data.warnings || EMPTY_ERRORS;
435
+ }
436
+ dirtyRef.current = true;
437
+ triggerMetaEvent();
438
+ reRender();
439
+ return;
440
+ }
441
+ if (shouldUpdate && !namePath.length && requireUpdate(shouldUpdate, prevStore, store, prevValue, curValue, info)) {
442
+ reRender();
443
+ return;
444
+ }
445
+ break;
454
446
  }
455
- if (normalize) {
456
- newValue = normalize(newValue, value, getFieldsValue(true));
447
+ case 'dependenciesUpdate':
448
+ {
449
+ /**
450
+ * Trigger when marked `dependencies` updated. Related fields will all update
451
+ */
452
+ var dependencyList = dependencies.map(getNameArray);
453
+ // No need for `namePathMath` check and `shouldUpdate` check, since `valueUpdate` will be
454
+ // emitted earlier and they will work there
455
+ // If set it may cause unnecessary twice rerendering
456
+ if (dependencyList.some(function (dependency) {
457
+ return containsNamePath(info.relatedFields, dependency);
458
+ })) {
459
+ reRender();
460
+ return;
461
+ }
462
+ break;
457
463
  }
458
- dispatch({
459
- type: 'updateValue',
460
- namePath: namePath,
461
- value: newValue
462
- });
463
- if (originTriggerFunc) {
464
- originTriggerFunc.apply(void 0, args);
464
+ default:
465
+ // 1. If `namePath` exists in `namePathList`, means it's related value and should update
466
+ // For example <List name="list"><Field name={['list', 0]}/>
467
+ // If `namePathList` is [['list']] (List value update), Field should be updated
468
+ // If `namePathList` is [['list', 0]] (Field value update), List shouldn't be updated
469
+ // 2.
470
+ // 2.1 If `dependencies` is set, `name` is not set and `shouldUpdate` is not set,
471
+ // don't use `shouldUpdate`. `dependencies` is view as a shortcut if `shouldUpdate`
472
+ // is not provided
473
+ // 2.2 If `shouldUpdate` provided, use customize logic to update the field
474
+ // else to check if value changed
475
+ if (namePathMatch || (!dependencies.length || namePath.length || shouldUpdate) && requireUpdate(shouldUpdate, prevStore, store, prevValue, curValue, info)) {
476
+ reRender();
477
+ return;
465
478
  }
479
+ break;
480
+ }
481
+ if (shouldUpdate === true) {
482
+ reRender();
483
+ }
484
+ }, [getNamePath, getValue, dependencies, shouldUpdate, triggerMetaEvent, onReset, refresh, reRender]);
485
+ var getLabelWidth = useCallback(function () {
486
+ var _props$labelPosition;
487
+ var labelWidthContext = fieldContext.labelWidth,
488
+ contextLabelPos = fieldContext.labelPosition;
489
+ var labelPosition = (_props$labelPosition = props.labelPosition) !== null && _props$labelPosition !== void 0 ? _props$labelPosition : contextLabelPos;
490
+ if (labelPosition === 'top') {
491
+ return 0;
492
+ }
493
+ if (isNotEmpty(props.labelWidth)) {
494
+ return addUnit(props.labelWidth);
495
+ }
496
+ if (pure === true) {
497
+ return 0;
498
+ }
499
+ return labelWidthContext;
500
+ }, [fieldContext, props.labelPosition, props.labelWidth, pure]);
501
+ var getValidateLabel = useCallback(function () {
502
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Transition, {
503
+ nodeRef: errorRef,
504
+ name: b('slide-up'),
505
+ visible: errorsRef.current.length > 0,
506
+ transitionAppear: true,
507
+ unmountOnExit: true,
508
+ display: ""
509
+ }, /*#__PURE__*/React.createElement("label", {
510
+ ref: errorRef,
511
+ className: e(_templateObject || (_templateObject = _taggedTemplateLiteral(["error"]))),
512
+ style: errorStyle
513
+ }, head(errorsRef.current))), /*#__PURE__*/React.createElement(Transition, {
514
+ nodeRef: warningRef,
515
+ name: b('slide-up'),
516
+ visible: warningsRef.current.length > 0,
517
+ transitionAppear: true,
518
+ unmountOnExit: true,
519
+ display: ""
520
+ }, /*#__PURE__*/React.createElement("label", {
521
+ ref: warningRef,
522
+ className: e(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["warning"]))),
523
+ style: warningStyle
524
+ }, head(warningsRef.current))));
525
+ }, [b, e, errorStyle, warningStyle]);
526
+ useMount(function () {
527
+ mountedRef.current = true;
528
+ if (fieldContext) {
529
+ var _fieldContext$getInte4 = fieldContext.getInternalHooks(HOOK_MARK),
530
+ initEntityValue = _fieldContext$getInte4.initEntityValue,
531
+ registerField = _fieldContext$getInte4.registerField;
532
+ var fieldEntity = {
533
+ onStoreChange: onStoreChange,
534
+ isFieldTouched: isFieldTouched,
535
+ isFieldDirty: isFieldDirty,
536
+ isFieldValidating: isFieldValidating,
537
+ isListField: function isListField() {
538
+ return props.isListField;
539
+ },
540
+ isList: function isList() {
541
+ return props.isList;
542
+ },
543
+ isPreserve: function isPreserve() {
544
+ return props.preserve;
545
+ },
546
+ validateRules: validateRulesFunc,
547
+ getMeta: getMeta,
548
+ getNamePath: getNamePath,
549
+ getErrors: getErrors,
550
+ getWarnings: getWarnings,
551
+ containerRef: containerRef,
552
+ props: _objectSpread(_objectSpread({
553
+ label: props.label,
554
+ dependencies: props.dependencies,
555
+ initialValue: props.initialValue
556
+ }, props), {}, {
557
+ name: name,
558
+ rules: rules,
559
+ scrollToError: fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.scrollToError
560
+ })
466
561
  };
467
-
468
- // Add validateTrigger
469
- var validateTriggerList = toArray(mergedValidateTrigger || []);
470
- validateTriggerList.forEach(function (triggerName) {
471
- // Wrap additional function of component, so that we can get latest value from store
472
- var originTrigger = control[triggerName];
473
- control[triggerName] = function () {
474
- if (originTrigger) {
475
- originTrigger.apply(void 0, arguments);
476
- }
477
-
478
- // Always use latest rules
479
- var rules = _this.props.rules;
480
- if (rules && rules.length) {
481
- // We dispatch validate to root,
482
- // since it will update related data with other field with same name
483
- dispatch({
484
- type: 'validateField',
485
- namePath: namePath,
486
- triggerName: triggerName
487
- });
488
- }
489
- };
490
- });
491
- return control;
492
- });
493
- _defineProperty(_assertThisInitialized(_this), "onClear", function () {
494
- var _this$props7, _this$props7$onClear;
495
- _this.touched = true;
496
- var getInternalHooks = _this.props.fieldContext.getInternalHooks;
497
- var _getInternalHooks2 = getInternalHooks(HOOK_MARK),
498
- dispatch = _getInternalHooks2.dispatch;
499
- dispatch({
500
- type: 'updateValue',
501
- namePath: _this.getNamePath(),
502
- value: ''
503
- });
504
- // @ts-ignore
505
- (_this$props7 = _this.props) === null || _this$props7 === void 0 || (_this$props7 = _this$props7.children) === null || _this$props7 === void 0 || (_this$props7 = _this$props7.props) === null || _this$props7 === void 0 || (_this$props7$onClear = _this$props7.onClear) === null || _this$props7$onClear === void 0 || _this$props7$onClear.call(_this$props7);
506
- });
507
- _defineProperty(_assertThisInitialized(_this), "getLabelWidth", function () {
508
- var _this$props$labelPosi;
509
- var _this$props8 = _this.props,
510
- pure = _this$props8.pure,
511
- fieldContext = _this$props8.fieldContext,
512
- labelWidth = _this$props8.labelWidth;
513
- var labelWidthContext = fieldContext.labelWidth,
514
- contextLabelPos = fieldContext.labelPosition;
515
- var labelPosition = (_this$props$labelPosi = _this.props.labelPosition) !== null && _this$props$labelPosi !== void 0 ? _this$props$labelPosi : contextLabelPos;
516
- if (labelPosition === 'top') {
517
- return 0;
518
- } else if (isNotEmpty(labelWidth)) {
519
- return addUnit(labelWidth);
520
- } else if (pure === true) {
521
- return 0;
522
- } else {
523
- return labelWidthContext;
562
+ initEntityValue(fieldEntity);
563
+ cancelRegisterFuncRef.current = registerField(fieldEntity);
564
+ if (shouldUpdate === true) {
565
+ reRender();
524
566
  }
567
+ }
568
+ });
569
+ useUnmount(function () {
570
+ cancelRegister();
571
+ triggerMetaEvent(true);
572
+ mountedRef.current = false;
573
+ });
574
+ var sizeContext = fieldContext.size,
575
+ contextLabelPos = fieldContext.labelPosition,
576
+ colonContext = fieldContext.colon,
577
+ hideRequiredAsterisk = fieldContext.hideRequiredAsterisk,
578
+ requireAsteriskPosition = fieldContext.requireAsteriskPosition,
579
+ contextShowMessage = fieldContext.showMessage;
580
+ var labelWidth = getLabelWidth();
581
+ var labelPosition = useMemo(function () {
582
+ var _props$labelPosition2;
583
+ return (_props$labelPosition2 = props.labelPosition) !== null && _props$labelPosition2 !== void 0 ? _props$labelPosition2 : contextLabelPos;
584
+ }, [props.labelPosition, contextLabelPos]);
585
+ var showMessage = useMemo(function () {
586
+ var _props$showMessage;
587
+ return (_props$showMessage = props.showMessage) !== null && _props$showMessage !== void 0 ? _props$showMessage : contextShowMessage;
588
+ }, [props.showMessage, contextShowMessage]);
589
+ var isRequired = useMemo(function () {
590
+ return props.required || getRules().some(function (item) {
591
+ return item.required;
525
592
  });
526
- _defineProperty(_assertThisInitialized(_this), "getValidateLable", function () {
527
- var _this$props9 = _this.props,
528
- errorStyle = _this$props9.errorStyle,
529
- warningStyle = _this$props9.warningStyle;
530
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Transition, {
531
- nodeRef: _this.errorRef,
532
- name: b('slide-up'),
533
- visible: _this.errors.length > 0,
534
- transitionAppear: true,
535
- unmountOnExit: true,
536
- display: ""
537
- }, /*#__PURE__*/React.createElement("label", {
538
- ref: _this.errorRef,
539
- className: e(_templateObject || (_templateObject = _taggedTemplateLiteral(["error"]))),
540
- style: errorStyle
541
- }, head(_this.errors))), /*#__PURE__*/React.createElement(Transition, {
542
- nodeRef: _this.warningRef,
543
- name: b('slide-up'),
544
- visible: _this.warnings.length > 0,
545
- transitionAppear: true,
546
- unmountOnExit: true,
547
- display: ""
548
- }, /*#__PURE__*/React.createElement("label", {
549
- ref: _this.warningRef,
550
- className: e(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["warning"]))),
551
- style: warningStyle
552
- }, head(_this.warnings))));
553
- });
554
- if (props.fieldContext) {
555
- var getInternalHooks = props.fieldContext.getInternalHooks;
556
- var _getInternalHooks3 = getInternalHooks(HOOK_MARK),
557
- initEntityValue = _getInternalHooks3.initEntityValue;
558
- initEntityValue(_assertThisInitialized(_this));
593
+ }, [props.required, getRules]);
594
+ var returnChildNode = useCallback(function () {
595
+ var _getOnlyChild = getOnlyChild(children),
596
+ child = _getOnlyChild.child,
597
+ isFunction = _getOnlyChild.isFunction;
598
+ if (isFunction) {
599
+ return child;
600
+ } else if ( /*#__PURE__*/isValidElement(child)) {
601
+ return /*#__PURE__*/cloneElement(child, getControlled(child.props));
602
+ } else {
603
+ return child;
559
604
  }
560
- _this.warningRef = /*#__PURE__*/createRef();
561
- _this.errorRef = /*#__PURE__*/createRef();
562
- _this.containerRef = /*#__PURE__*/createRef();
563
- return _this;
564
- }
565
- _createClass(Field, [{
566
- key: "componentDidMount",
567
- value: function componentDidMount() {
568
- var _this$props10 = this.props,
569
- shouldUpdate = _this$props10.shouldUpdate,
570
- fieldContext = _this$props10.fieldContext;
571
- this.mounted = true;
572
-
573
- // Register on init
574
- if (fieldContext) {
575
- var getInternalHooks = fieldContext.getInternalHooks;
576
- var _getInternalHooks4 = getInternalHooks(HOOK_MARK),
577
- registerField = _getInternalHooks4.registerField;
578
- this.cancelRegisterFunc = registerField(this);
579
- }
580
-
581
- // One more render for component in case fields not ready
582
- if (shouldUpdate === true) {
583
- this.reRender();
584
- }
605
+ }, [getOnlyChild, children, getControlled]);
606
+ var computedValidateState = useCallback(function () {
607
+ if (validateState) {
608
+ return validateState;
585
609
  }
586
- }, {
587
- key: "componentWillUnmount",
588
- value: function componentWillUnmount() {
589
- this.cancelRegister();
590
- this.triggerMetaEvent(true);
591
- this.mounted = false;
610
+ if (isFieldValidating()) {
611
+ return 'validating';
592
612
  }
593
- }, {
594
- key: "reRender",
595
- value: function reRender() {
596
- if (!this.mounted) {
597
- return;
598
- }
599
- this.forceUpdate();
613
+ if (errorsRef.current.length > 0) {
614
+ return 'error';
600
615
  }
601
- }, {
602
- key: "render",
603
- value: function render() {
604
- var _this$props$labelPosi2, _this$props$showMessa;
605
- var resetCount = this.state.resetCount;
606
- var _this$props11 = this.props,
607
- children = _this$props11.children,
608
- label = _this$props11.label,
609
- center = _this$props11.center,
610
- className = _this$props11.className,
611
- style = _this$props11.style,
612
- noStyle = _this$props11.noStyle,
613
- fieldContext = _this$props11.fieldContext,
614
- _this$props11$labelSt = _this$props11.labelStyle,
615
- labelStyle = _this$props11$labelSt === void 0 ? {} : _this$props11$labelSt,
616
- _this$props11$colon = _this$props11.colon,
617
- colon = _this$props11$colon === void 0 ? false : _this$props11$colon,
618
- size = _this$props11.size,
619
- help = _this$props11.help,
620
- pure = _this$props11.pure;
621
- var sizeContext = fieldContext.size,
622
- contextLabelPos = fieldContext.labelPosition,
623
- colonContext = fieldContext.colon,
624
- hideRequiredAsterisk = fieldContext.hideRequiredAsterisk,
625
- requireAsteriskPosition = fieldContext.requireAsteriskPosition,
626
- contextShowMessage = fieldContext.showMessage;
627
- var labelWidth = this.getLabelWidth();
628
- var labelPosition = (_this$props$labelPosi2 = this.props.labelPosition) !== null && _this$props$labelPosi2 !== void 0 ? _this$props$labelPosi2 : contextLabelPos;
629
- var showMessage = (_this$props$showMessa = this.props.showMessage) !== null && _this$props$showMessa !== void 0 ? _this$props$showMessa : contextShowMessage;
630
- var _this$getOnlyChild = this.getOnlyChild(children),
631
- child = _this$getOnlyChild.child,
632
- isFunction = _this$getOnlyChild.isFunction;
633
-
634
- // 是否必输项
635
- var isRequired = this.props.required || this.getRules().some(function (item) {
636
- return item.required;
637
- });
638
-
639
- // Not need to `cloneElement` since user can handle this in render function self
640
- var returnChildNode;
641
- if (isFunction) {
642
- returnChildNode = child;
643
- } else if ( /*#__PURE__*/isValidElement(child)) {
644
- returnChildNode = /*#__PURE__*/cloneElement(child, this.getControlled(child.props));
645
- } else {
646
- // warning(!child, '当前包裹的组件不是合法的表单组件!');
647
- returnChildNode = child;
648
- }
649
- return noStyle ? /*#__PURE__*/React.createElement(FormItemContext.Provider, {
650
- key: resetCount,
651
- value: {
652
- size: size
653
- }
654
- }, /*#__PURE__*/React.createElement("div", {
655
- ref: this.containerRef,
656
- className: e('nostyle')
657
- }, returnChildNode, showMessage ? this.getValidateLable() : null)) : /*#__PURE__*/React.createElement(FormItemContext.Provider, {
658
- key: resetCount,
659
- value: {
660
- size: size
661
- }
662
- }, /*#__PURE__*/React.createElement("div", {
663
- ref: this.containerRef,
664
- className: classNames(b('form-item'), _defineProperty(_defineProperty({
665
- 'is-required': isRequired && !hideRequiredAsterisk
666
- }, m("label-".concat(labelPosition)), this.props.labelPosition), m(sizeContext !== null && sizeContext !== void 0 ? sizeContext : size), sizeContext !== null && sizeContext !== void 0 ? sizeContext : size), 'asterisk-' + requireAsteriskPosition, className),
667
- style: style
668
- }, label && !pure && /*#__PURE__*/React.createElement("label", {
669
- className: e(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["label"]))),
670
- style: ['left', 'right'].includes(labelPosition) ? _objectSpread({
671
- width: labelWidth
672
- }, labelStyle) : labelStyle
673
- }, typeof label === 'string' || typeof label === 'number' ? "".concat(label).concat((colonContext !== null && colonContext !== void 0 ? colonContext : colon) ? ':' : '') : label, help && /*#__PURE__*/React.createElement(Tooltip, {
674
- className: e(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["label--help"]))),
675
- content: help,
676
- placement: "top",
677
- enterable: true
678
- }, /*#__PURE__*/React.createElement(Icon, {
679
- name: "circle-exclamation",
680
- prefix: "fas"
681
- }))), /*#__PURE__*/React.createElement("div", {
682
- className: classNames(e(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["content"]))), {
683
- 'is-center': center
684
- })
685
- // 没有文本或者表单布局不是top的时候需要添加marginLeft
686
- ,
687
- style: !label ? {
688
- marginLeft: labelWidth
689
- } : {}
690
- }, /*#__PURE__*/React.createElement(React.Fragment, null, Children.map(returnChildNode, function (item) {
691
- return item;
692
- }), showMessage ? this.getValidateLable() : null))));
616
+ if (warningsRef.current.length > 0) {
617
+ return 'error';
618
+ }
619
+ if (!isFieldValidating() && touchedRef.current && errorsRef.current.length === 0 && warningsRef.current.length === 0) {
620
+ return 'success';
693
621
  }
694
- }]);
695
- return Field;
696
- }(React.Component);
697
- _defineProperty(Field, "contextType", FieldContext);
698
- _defineProperty(Field, "defaultProps", {
699
- trigger: 'onChange',
700
- valuePropName: 'value'
701
- });
702
- function InternalFormItem(_ref5) {
703
- var _fieldContext$rules;
704
- var name = _ref5.name,
705
- _ref5$rules = _ref5.rules,
706
- rules = _ref5$rules === void 0 ? [] : _ref5$rules,
707
- restProps = _objectWithoutProperties(_ref5, _excluded);
622
+ return '';
623
+ }, [isFieldValidating, validateState]);
624
+ var contextValue = {
625
+ size: size,
626
+ hasLabel: !!label,
627
+ labelPosition: labelPosition,
628
+ validateState: computedValidateState(),
629
+ computedWidth: computedWidth,
630
+ setComputedWidth: setComputedWidth,
631
+ oldWidthRef: oldWidthRef
632
+ };
633
+ return noStyle ? /*#__PURE__*/React.createElement(FormItemContext.Provider, {
634
+ key: resetCount,
635
+ value: contextValue
636
+ }, /*#__PURE__*/React.createElement("div", {
637
+ ref: containerRef,
638
+ className: classNames(b(), e('nostyle'), is({
639
+ error: errorsRef.current.length > 0,
640
+ warning: warningsRef.current.length > 0,
641
+ validating: !isFieldValidating() && touchedRef.current && errorsRef.current.length === 0 && warningsRef.current.length === 0,
642
+ success: errorsRef.current.length === 0 && warningsRef.current.length === 0
643
+ }), _defineProperty({}, m('feedback'), fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.statusIcon))
644
+ }, /*#__PURE__*/React.createElement("div", {
645
+ className: classNames(e(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["content"]))))
646
+ }, returnChildNode()), showMessage ? getValidateLabel() : null)) : /*#__PURE__*/React.createElement(FormItemContext.Provider, {
647
+ key: resetCount,
648
+ value: contextValue
649
+ }, /*#__PURE__*/React.createElement("div", {
650
+ ref: containerRef,
651
+ className: classNames(b(), is({
652
+ error: errorsRef.current.length > 0,
653
+ warning: warningsRef.current.length > 0,
654
+ validating: !isFieldValidating() && touchedRef.current && errorsRef.current.length === 0 && warningsRef.current.length === 0,
655
+ success: errorsRef.current.length === 0 && warningsRef.current.length === 0,
656
+ required: isRequired,
657
+ 'no-asterisk': hideRequiredAsterisk
658
+ }), _defineProperty(_defineProperty(_defineProperty({}, m('feedback'), fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.statusIcon), m("label-".concat(labelPosition)), labelPosition), m(sizeContext !== null && sizeContext !== void 0 ? sizeContext : size), sizeContext !== null && sizeContext !== void 0 ? sizeContext : size), requireAsteriskPosition === 'right' ? 'asterisk-right' : 'asterisk-left', className),
659
+ style: style
660
+ }, /*#__PURE__*/React.createElement(FormLabelWrap, {
661
+ key: key,
662
+ isAutoWidth: labelWidth === 'auto',
663
+ updateAll: fieldContext.labelWidth === 'auto'
664
+ }, label && !pure && /*#__PURE__*/React.createElement("label", {
665
+ className: e(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["label"]))),
666
+ style: ['left', 'right'].includes(labelPosition) ? _objectSpread({
667
+ width: labelWidth
668
+ }, labelStyle) : labelStyle
669
+ }, typeof label === 'string' || typeof label === 'number' ? "".concat(label).concat((colonContext !== null && colonContext !== void 0 ? colonContext : colon) ? ':' : '') : label, help && /*#__PURE__*/React.createElement(Tooltip, {
670
+ className: e(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["label--help"]))),
671
+ content: help,
672
+ placement: "top",
673
+ enterable: true
674
+ }, /*#__PURE__*/React.createElement(Icon, {
675
+ name: "circle-question",
676
+ prefix: "fas"
677
+ })))), /*#__PURE__*/React.createElement("div", {
678
+ className: classNames(e(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["content"])))),
679
+ style: !label ? {
680
+ marginLeft: labelWidth
681
+ } : {}
682
+ }, /*#__PURE__*/React.createElement(React.Fragment, null, Children.map(returnChildNode(), function (item) {
683
+ return item;
684
+ }), showMessage ? getValidateLabel() : null))));
685
+ }
686
+ function InternalFormItem(_ref4) {
687
+ var _fieldContext$rules2;
688
+ var name = _ref4.name,
689
+ _ref4$rules = _ref4.rules,
690
+ rules = _ref4$rules === void 0 ? [] : _ref4$rules,
691
+ restProps = _objectWithoutProperties(_ref4, _excluded);
692
+ var formContext = useContext(FormContext);
708
693
  var fieldContext = useContext(FieldContext);
709
- var namePath = name !== undefined ? getNamePath(name) : undefined;
694
+ var namePath = name !== undefined ? getNameArray(name) : undefined;
710
695
  var key = 'keep';
711
696
  if (!restProps.isListField) {
712
697
  key = "_".concat((namePath || []).join('_'));
@@ -715,17 +700,15 @@ function InternalFormItem(_ref5) {
715
700
  // Warning if it's a directly list field.
716
701
  // We can still support multiple level field preserve.
717
702
  if (process.env.NODE_ENV !== 'production' && restProps.preserve === false && restProps.isListField && namePath.length <= 1) {
718
- warning(false, '`preserve` should not apply on Form.List fields.');
703
+ warning(false, '`preserve` should not apply on ElFormList fields.');
719
704
  }
720
- var formRules = (namePath === null || namePath === void 0 ? void 0 : namePath.length) > 0 ? get((_fieldContext$rules = fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.rules) !== null && _fieldContext$rules !== void 0 ? _fieldContext$rules : {}, namePath) : undefined;
705
+ var formRules = (namePath === null || namePath === void 0 ? void 0 : namePath.length) > 0 ? get((_fieldContext$rules2 = fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.rules) !== null && _fieldContext$rules2 !== void 0 ? _fieldContext$rules2 : {}, namePath) : undefined;
721
706
  return /*#__PURE__*/React.createElement(Field, _extends({
722
707
  key: key,
723
708
  name: namePath,
724
709
  rules: [].concat(_toConsumableArray(formRules || []), _toConsumableArray(rules))
725
- }, restProps, {
726
- fieldContext: fieldContext
727
- }));
710
+ }, restProps));
728
711
  }
729
- var FormItem = /*#__PURE__*/memo(InternalFormItem);
712
+ var FormItem = /*#__PURE__*/memo(Field);
730
713
  FormItem.displayName = 'ElFormItem';
731
714
  export default FormItem;