@unicom-cloud/ui 0.8.96 → 0.8.98

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 (302) hide show
  1. package/Affix.js +1 -1
  2. package/Carousel.js +1 -1
  3. package/LiquidFill.js +4 -0
  4. package/OverflowEllipsis.js +1 -1
  5. package/PageHeader.js +1 -1
  6. package/QrCode.js +57 -0
  7. package/Tour.js +63 -0
  8. package/Trigger.js +1 -1
  9. package/_virtual/_commonjsHelpers.js +6 -0
  10. package/_virtual/index.js +7 -0
  11. package/_virtual/index2.js +4 -0
  12. package/affix/index.js +70 -72
  13. package/alert/index.js +56 -56
  14. package/anchor/Anchor.js +55 -55
  15. package/anchor/Link.js +34 -34
  16. package/anchor/util.js +5 -5
  17. package/auto-complete/index.js +116 -122
  18. package/avatar/Avatar.js +33 -33
  19. package/avatar/Group.js +26 -26
  20. package/back-top/index.js +58 -61
  21. package/badge/index.js +46 -46
  22. package/breadcrumb/Item.js +42 -43
  23. package/breadcrumb/index.js +47 -47
  24. package/button/Group.js +6 -6
  25. package/button/index.js +91 -91
  26. package/calendar/Month.js +75 -75
  27. package/calendar/Year.js +35 -35
  28. package/calendar/header/index.js +25 -25
  29. package/calendar/index.js +103 -103
  30. package/card/Grid.js +8 -8
  31. package/card/Meta.js +16 -16
  32. package/card/index.js +49 -49
  33. package/carousel/Arrow.js +19 -19
  34. package/carousel/Indicator.js +26 -26
  35. package/carousel/index.js +108 -108
  36. package/cascader/Cascader.js +178 -191
  37. package/cascader/base/node.js +133 -136
  38. package/cascader/base/store.js +82 -85
  39. package/cascader/panel/List.js +125 -129
  40. package/cascader/panel/Search.js +79 -81
  41. package/cascader/util.js +13 -13
  42. package/checkbox/Checkbox.js +94 -96
  43. package/checkbox/Group.js +54 -56
  44. package/checkbox/GroupBlock.js +28 -29
  45. package/collapse/Collapse.js +45 -45
  46. package/collapse/Item.js +53 -55
  47. package/color-picker/ControlBar.js +43 -43
  48. package/color-picker/InputAlpha.js +12 -12
  49. package/color-picker/InputHex.js +30 -31
  50. package/color-picker/InputRgb.js +24 -24
  51. package/color-picker/Palette.js +18 -18
  52. package/color-picker/Panel.js +122 -125
  53. package/color-picker/hooks/useColorPicker.js +85 -88
  54. package/color-picker/hooks/useControlBlock.js +38 -40
  55. package/color-picker/index.js +47 -47
  56. package/comment/index.js +29 -29
  57. package/components/common/higher-order/with-speech-synthesis/index.js +37 -40
  58. package/components/common/hooks/useId.js +8 -8
  59. package/components/common/hooks/useInView.js +16 -16
  60. package/components/common/hooks/useIntersectionObserver.js +1 -1
  61. package/components/common/hooks/useKeyboardEvent.js +9 -10
  62. package/components/common/hooks/useOverflowHidden.js +1 -4
  63. package/components/common/hooks/usePersistCallback.js +7 -7
  64. package/components/common/hooks/useStateCallback.js +9 -10
  65. package/components/common/hooks/useWindowSize.js +8 -8
  66. package/components/common/space/index.js +9 -7
  67. package/components/common/utils/convertToDurationBasedOnTimeUnits.js +6 -0
  68. package/components/common/utils/dom.js +27 -29
  69. package/components/common/utils/findScrollParent.js +17 -0
  70. package/components/common/utils/intersectionObserver.js +21 -0
  71. package/components/common/utils/is.js +99 -109
  72. package/components/common/utils/mutationObserver.js +19 -0
  73. package/components/common/utils/reactDOM.js +34 -34
  74. package/components/common/utils/resizeObserver.js +21 -0
  75. package/copy/index.js +38 -40
  76. package/date-picker/Picker.js +290 -295
  77. package/date-picker/RangePicker.js +367 -372
  78. package/date-picker/index.js +33 -35
  79. package/date-picker/panel/Body.js +46 -47
  80. package/date-picker/panel/Header.js +33 -33
  81. package/date-picker/panel/Shortcut.js +31 -31
  82. package/date-picker/panel/date/index.js +85 -85
  83. package/date-picker/panel/month/index.js +59 -59
  84. package/date-picker/panel/quarter/index.js +67 -70
  85. package/date-picker/panel/range/index.js +101 -101
  86. package/date-picker/panel/year/index.js +39 -39
  87. package/date-picker/util.js +17 -18
  88. package/descriptions/index.js +62 -62
  89. package/details/index.js +53 -55
  90. package/development/index.js +9 -9
  91. package/dist/tinycolor/chunk/BOzCVdr0.js +1 -1
  92. package/dist/validate/src/index.js +5 -5
  93. package/dist/validate/src/util.js +1 -1
  94. package/divider/index.js +21 -21
  95. package/draggable/Item.js +35 -35
  96. package/draggable/index.js +22 -22
  97. package/drawer/Drawer.js +142 -147
  98. package/dropdown/Button.js +48 -48
  99. package/dropdown/index.js +88 -92
  100. package/empty/index.js +16 -16
  101. package/form/Control.js +211 -225
  102. package/form/Form.js +109 -113
  103. package/form/FormItem.js +118 -120
  104. package/form/FormList.js +60 -66
  105. package/form/FormProvider.js +31 -34
  106. package/form/hook/useContext.js +17 -19
  107. package/form/hook/useState.js +22 -23
  108. package/form/hook/useWatch.js +26 -27
  109. package/form/promisify.js +14 -18
  110. package/form/store.js +304 -316
  111. package/form/util.js +14 -15
  112. package/grid/Col.js +64 -64
  113. package/grid/Grid.js +51 -51
  114. package/grid/GridItem.js +48 -48
  115. package/grid/Row.js +39 -39
  116. package/hooks/useVerificationCode.js +41 -43
  117. package/hooks/useWatermark.js +89 -92
  118. package/icon/index.js +23 -24
  119. package/icon-hover/index.js +16 -16
  120. package/icons/file.js +11 -11
  121. package/image/Image.js +140 -141
  122. package/image/ImagePreview.js +252 -255
  123. package/image/ImagePreviewArrow.js +25 -25
  124. package/image/ImagePreviewGroup.js +62 -62
  125. package/image/util/getScale.js +25 -28
  126. package/index.js +684 -675
  127. package/input/Button.js +48 -50
  128. package/input/Group.js +9 -9
  129. package/input/Input.js +145 -154
  130. package/input/InputElement.js +108 -115
  131. package/input/Password.js +38 -38
  132. package/input/Search.js +51 -55
  133. package/input/Textarea.js +80 -81
  134. package/input/useComposition.js +23 -23
  135. package/input-number/decimal.js +59 -62
  136. package/input-number/index.js +139 -141
  137. package/input-tag/InputTag.js +222 -230
  138. package/layout/Content.js +6 -6
  139. package/layout/Footer.js +8 -8
  140. package/layout/Header.js +7 -7
  141. package/layout/Sider.js +88 -90
  142. package/layout/index.js +30 -30
  143. package/link/index.js +45 -46
  144. package/liquid-fill/LiquidFill.js +226 -0
  145. package/liquid-fill/LiquidFill2.js +3 -0
  146. package/liquid-fill/index.js +4 -0
  147. package/list/Item.js +28 -28
  148. package/list/Meta.js +12 -12
  149. package/list/index.js +146 -148
  150. package/mentions/index.js +75 -76
  151. package/menu/Item.js +58 -58
  152. package/menu/Menu.js +125 -127
  153. package/menu/OverflowWrap.js +39 -40
  154. package/menu/sub-menu/Inline.js +45 -45
  155. package/menu/util.js +26 -28
  156. package/message/index.js +96 -99
  157. package/message/useMessage.js +26 -27
  158. package/modal/Confirm.js +47 -49
  159. package/modal/Modal.js +250 -257
  160. package/modal/use-modal/Hook.js +26 -28
  161. package/modal/use-modal/index.js +46 -49
  162. package/notice/index.js +89 -90
  163. package/notification/index.js +60 -65
  164. package/notification/withNotification.js +35 -35
  165. package/overflow-ellipsis/OverflowItem.js +19 -20
  166. package/overflow-ellipsis/index.js +45 -46
  167. package/package.json +1 -1
  168. package/page-header/index.js +45 -45
  169. package/pagination/PageItem.js +87 -91
  170. package/pagination/PageJumper.js +40 -41
  171. package/pagination/PageOption.js +31 -35
  172. package/pagination/Pagination.js +162 -163
  173. package/picker/Input.js +90 -96
  174. package/picker/InputRange.js +115 -122
  175. package/popconfirm/index.js +98 -100
  176. package/popover/index.js +28 -28
  177. package/portal/Portal.js +10 -11
  178. package/progress/index.js +36 -36
  179. package/qr-code/index.js +99 -0
  180. package/qr-code/interface.js +1 -0
  181. package/radio/Group.js +48 -48
  182. package/radio/GroupBlock.js +32 -33
  183. package/radio/Radio.js +62 -64
  184. package/rate/index.js +88 -88
  185. package/resize-box/ResizeTrigger.js +39 -39
  186. package/resize-box/Split.js +92 -96
  187. package/resize-box/SplitGroup.js +116 -122
  188. package/resize-box/index.js +112 -115
  189. package/result/index.js +44 -44
  190. package/select/Option.js +53 -56
  191. package/select/Select.js +365 -381
  192. package/select/util.js +95 -99
  193. package/select-view/Core.js +159 -160
  194. package/skeleton/index.js +23 -23
  195. package/slider/Button.js +84 -92
  196. package/slider/Input.js +47 -49
  197. package/slider/Tick.js +28 -31
  198. package/slider/index.js +107 -107
  199. package/space/index.js +26 -26
  200. package/space-/index.js +51 -51
  201. package/spin/DotLoading.js +8 -8
  202. package/spin/index.js +47 -47
  203. package/statistic/Countdown.js +37 -37
  204. package/statistic/index.js +58 -58
  205. package/steps/Step.js +42 -42
  206. package/steps/index.js +54 -54
  207. package/style.css +1 -1
  208. package/switch/index.js +77 -78
  209. package/table/ColGroup.js +36 -37
  210. package/table/Table.js +447 -450
  211. package/table/hook/useExpand.js +24 -24
  212. package/table/hook/useRowSelection.js +62 -62
  213. package/table/summary/Row.js +16 -17
  214. package/table/tbody/Td.js +119 -118
  215. package/table/tbody/Tr.js +119 -121
  216. package/table/tbody/index.js +62 -63
  217. package/table/th-resizable/index.js +30 -30
  218. package/table/thead/Column.js +148 -148
  219. package/table/thead/index.js +87 -88
  220. package/tabs/Tab.js +55 -55
  221. package/tabs/TabContent.js +8 -8
  222. package/tabs/TabPane.js +15 -15
  223. package/tabs/hook/useHeaderScroll.js +36 -36
  224. package/tabs/tab-header/TabInk.js +31 -33
  225. package/tabs/tab-header/TabNavIcon.js +34 -35
  226. package/tabs/tab-header/index.js +192 -195
  227. package/tag/index.js +94 -97
  228. package/time-picker/Picker.js +167 -172
  229. package/time-picker/RangePicker.js +28 -28
  230. package/time-picker/TimePicker.js +146 -146
  231. package/timeline/Item.js +46 -46
  232. package/timeline/Timeline.js +52 -52
  233. package/tooltip/index.js +89 -95
  234. package/tour/index.js +289 -0
  235. package/transfer/Item.js +54 -54
  236. package/transfer/List.js +134 -136
  237. package/transfer/index.js +91 -91
  238. package/tree/Animation.js +49 -52
  239. package/tree/Node.js +114 -122
  240. package/tree/NodeList.js +51 -51
  241. package/tree/Tree.js +386 -393
  242. package/tree-select/List.js +71 -72
  243. package/tree-select/Select.js +135 -143
  244. package/tree-select/hook/useKeyCache.js +39 -39
  245. package/tree-select/hook/useStateValue.js +12 -12
  246. package/trigger/getPopupStyle.js +60 -61
  247. package/trigger/index.js +337 -346
  248. package/types/common/space/interface.d.ts +1 -1
  249. package/types/common/utils/convertToDurationBasedOnTimeUnits.d.ts +3 -0
  250. package/types/common/utils/findScrollParent.d.ts +2 -0
  251. package/types/common/utils/index.d.ts +5 -0
  252. package/types/common/utils/intersectionObserver.d.ts +2 -0
  253. package/types/common/utils/mutationObserver.d.ts +2 -0
  254. package/types/common/utils/resizeObserver.d.ts +2 -0
  255. package/types/pc/config-provider/interface.d.ts +6 -0
  256. package/types/pc/index.d.ts +3 -0
  257. package/types/pc/liquid-fill/LiquidFill.d.ts +115 -0
  258. package/types/pc/liquid-fill/LiquidFill2.d.ts +1 -0
  259. package/types/pc/liquid-fill/index.d.ts +2 -0
  260. package/types/pc/qr-code/index.d.ts +34 -0
  261. package/types/pc/qr-code/interface.d.ts +39 -0
  262. package/types/pc/table/interface.d.ts +2 -2
  263. package/types/pc/tour/index.d.ts +42 -0
  264. package/types/pc/utils/convertToDurationBasedOnTimeUnits.d.ts +3 -0
  265. package/types/pc/utils/findScrollParent.d.ts +2 -0
  266. package/types/pc/utils/index.d.ts +5 -0
  267. package/types/pc/utils/intersectionObserver.d.ts +2 -0
  268. package/types/pc/utils/mutationObserver.d.ts +2 -0
  269. package/types/pc/utils/names.d.ts +18 -0
  270. package/types/pc/utils/resizeObserver.d.ts +2 -0
  271. package/typography/Base.js +79 -81
  272. package/typography/EditContent.js +30 -33
  273. package/typography/Ellipsis.js +77 -73
  274. package/typography/Operations.js +50 -52
  275. package/typography/Paragraph.js +7 -7
  276. package/typography/Typography.js +7 -7
  277. package/typography/useEllipsis.js +105 -106
  278. package/upload/TriggerNode.js +69 -76
  279. package/upload/Upload.js +84 -87
  280. package/upload/Uploader.js +115 -118
  281. package/upload/list/PictureItem.js +61 -71
  282. package/upload/list/TextItem.js +61 -67
  283. package/upload/list/UploadProgress.js +42 -49
  284. package/upload/list/index.js +48 -49
  285. package/upload/request_.js +37 -38
  286. package/upload/util.js +39 -39
  287. package/utils/convertToDurationBasedOnTimeUnits.js +6 -0
  288. package/utils/findScrollParent.js +4 -0
  289. package/utils/index.js +281 -278
  290. package/utils/intersectionObserver.js +4 -0
  291. package/utils/mutationObserver.js +4 -0
  292. package/utils/names.js +12 -0
  293. package/utils/resizeObserver.js +4 -0
  294. package/verification-code/VerificationCode.js +50 -51
  295. package/version/index.js +1 -1
  296. package/virtual-list/VirtualList.js +243 -244
  297. package/virtual-list/util/item.js +3 -4
  298. package/watermark/Watermark.js +27 -31
  299. package/components/common/utils/resizeObserverEffect.js +0 -23
  300. package/types/common/utils/resizeObserverEffect.d.ts +0 -2
  301. package/types/pc/utils/resizeObserverEffect.d.ts +0 -2
  302. package/utils/resizeObserverEffect.js +0 -4
package/form/Control.js CHANGED
@@ -1,192 +1,42 @@
1
- var M = Object.defineProperty;
2
- var N = (p, g, e) => g in p ? M(p, g, { enumerable: !0, configurable: !0, writable: !0, value: e }) : p[g] = e;
3
- var s = (p, g, e) => N(p, typeof g != "symbol" ? g + "" : g, e);
4
- import { jsx as m, jsxs as E } from "react/jsx-runtime";
5
- import P from "@unicom-cloud/icons/IconUiCheckCircleFill";
6
- import W from "@unicom-cloud/icons/IconUiCloseCircleFill";
7
- import $ from "@unicom-cloud/icons/IconUiExclamationCircleFill";
8
- import L from "@unicom-cloud/icons/IconUiLoading";
9
- import V from "lodash/get";
10
- import b from "lodash/isArray";
11
- import R from "lodash/isBoolean";
12
- import y from "lodash/isEqualWith";
13
- import F from "lodash/isFunction";
14
- import _ from "lodash/isNil";
15
- import j from "lodash/set";
16
- import I, { Component as z, isValidElement as A } from "react";
17
- import G from "@unicom-cloud/utils/class-name";
18
- import { warning as U } from "../components/common/utils/warning.js";
19
- import { FormItemContext as O } from "./context.js";
20
- import { isFieldMatch as C, schemaValidate as k, isSyntheticEvent as q, ID_SUFFIX as B } from "./util.js";
21
- class x extends z {
1
+ import { jsx as u, jsxs as I } from "react/jsx-runtime";
2
+ import T from "@unicom-cloud/icons/IconUiCheckCircleFill";
3
+ import w from "@unicom-cloud/icons/IconUiCloseCircleFill";
4
+ import b from "@unicom-cloud/icons/IconUiExclamationCircleFill";
5
+ import y from "@unicom-cloud/icons/IconUiLoading";
6
+ import f from "lodash/get";
7
+ import S from "lodash/isArray";
8
+ import M from "lodash/isBoolean";
9
+ import V from "lodash/isEqualWith";
10
+ import g from "lodash/isFunction";
11
+ import U from "lodash/isNil";
12
+ import k from "lodash/set";
13
+ import F, { Component as D, isValidElement as N } from "react";
14
+ import P from "@unicom-cloud/utils/class-name";
15
+ import { warning as C } from "../components/common/utils/warning.js";
16
+ import { FormItemContext as W } from "./context.js";
17
+ import { isFieldMatch as v, schemaValidate as x, isSyntheticEvent as $, ID_SUFFIX as L } from "./util.js";
18
+ class re extends D {
19
+ static defaultProps = {
20
+ trigger: "onChange",
21
+ triggerPropName: "value"
22
+ };
23
+ static isFormControl = !0;
24
+ static contextType = W;
25
+ context;
26
+ // 校验信息
27
+ errors = null;
28
+ // 校验 warning 信息
29
+ warnings = null;
30
+ // undefined => validating => success / error => (validating or undefined)
31
+ validateStatus;
32
+ // 是否被用户操作过
33
+ touched;
34
+ isDestroyed = !1;
35
+ // 保存 props.children 或函数类型 props.children() 的返回值
36
+ childrenElement = null;
37
+ removeRegisterField;
22
38
  constructor(e, t) {
23
- var i, o, l;
24
- super(e);
25
- s(this, "context");
26
- // 校验信息
27
- s(this, "errors", null);
28
- // 校验 warning 信息
29
- s(this, "warnings", null);
30
- // undefined => validating => success / error => (validating or undefined)
31
- s(this, "validateStatus");
32
- // 是否被用户操作过
33
- s(this, "touched");
34
- s(this, "isDestroyed", !1);
35
- // 保存 props.children 或函数类型 props.children() 的返回值
36
- s(this, "childrenElement", null);
37
- s(this, "removeRegisterField");
38
- // 触发 store 进行状态收集
39
- // TODO: error, validateStatus ,touched 状态和 UI 组件解耦,统一维护在 store 内部
40
- s(this, "triggerStateCollect", () => {
41
- const { innerCollectFormState: e } = this.context.store.getInnerMethods(!0);
42
- e();
43
- });
44
- // 切换校验状态
45
- s(this, "toggleValidateStatus", (e) => {
46
- this.validateStatus = e, this.triggerStateCollect();
47
- });
48
- // 切换 touch 状态
49
- s(this, "toggleTouched", (e) => {
50
- this.touched = R(e) ? e : !this.touched, this.triggerStateCollect();
51
- });
52
- s(this, "setWarnings", (e) => {
53
- this.warnings = e, this.triggerStateCollect();
54
- });
55
- s(this, "setErrors", (e) => {
56
- this.errors = e, this.triggerStateCollect();
57
- });
58
- s(this, "getErrors", () => this.errors);
59
- s(this, "getWarnings", () => this.warnings || []);
60
- s(this, "isTouched", () => this.touched);
61
- s(this, "getValidateStatus", () => this.props.validateStatus ? this.props.validateStatus : this.validateStatus);
62
- s(this, "hasFieldProps", () => !!this.props.field);
63
- s(this, "clearFormItemError", (e = this.props.field) => {
64
- const { updateFormItem: t } = this.context;
65
- t == null || t(e, { errors: null, warnings: null });
66
- });
67
- s(this, "updateFormItem", () => {
68
- if (this.isDestroyed) return;
69
- this.forceUpdate();
70
- const { updateFormItem: e } = this.context;
71
- e == null || e(this.props.field, {
72
- errors: this.errors,
73
- warnings: this.warnings
74
- });
75
- });
76
- s(this, "getFieldValue", () => {
77
- const e = this.props.field, t = this.context.store;
78
- return e ? t.getInnerMethods(!0).innerGetFieldValue(e) : void 0;
79
- });
80
- s(this, "onStoreChange", (e, t) => {
81
- const i = b(t.field) ? t.field : [t.field], { field: o, shouldUpdate: l, dependencies: r } = this.props, a = (d) => {
82
- if (r && l && U(!0, "`shouldUpdate` of the `Form.Item` will be ignored."), r)
83
- b(r) && r.some((n) => C(n, i)) && this.isTouched() && this.validateField();
84
- else if (l) {
85
- let n = !1;
86
- F(l) ? n = l(t.prev, t.current, {
87
- field: t.field,
88
- ...d
89
- }) : n = !y(t.prev, t.current), n && this.updateFormItem();
90
- }
91
- };
92
- switch (e) {
93
- case "reset":
94
- this.toggleTouched(!1), this.toggleValidateStatus(void 0), this.setErrors(null), this.setWarnings(null), r || l ? a() : this.updateFormItem();
95
- break;
96
- case "innerSetValue":
97
- if (C(o, i)) {
98
- this.toggleTouched(!0), this.updateFormItem();
99
- return;
100
- }
101
- a({
102
- isInner: !0,
103
- isFormList: t.isFormList
104
- });
105
- break;
106
- case "setFieldValue":
107
- if (C(o, i)) {
108
- this.toggleTouched(!0), t.data && "touched" in t.data && this.toggleTouched(t.data.touched), t.data && "warnings" in t.data && this.setWarnings(
109
- _(t.data.warnings) ? [] : [].concat(t.data.warnings)
110
- ), t.data && "errors" in t.data ? this.setErrors(t.data.errors) : y(V(t.prev, o), V(t.current, o)) || this.setErrors(null), this.updateFormItem();
111
- return;
112
- }
113
- a();
114
- break;
115
- }
116
- });
117
- s(this, "innerSetFieldValue", (e, t) => {
118
- var r, a;
119
- if (!e) return;
120
- const { store: i } = this.context;
121
- i.getInnerMethods(!0).innerSetFieldValue(e, t);
122
- const l = {};
123
- j(l, e, t), (a = (r = this.props) == null ? void 0 : r.onValuesChange) == null || a.call(r, l, {
124
- ...i.getFieldsValue()
125
- });
126
- });
127
- // 仅仅校验下值,不做任何状态变更
128
- s(this, "validateFieldOnly", () => {
129
- const { validateMessages: e } = this.context, { field: t, rules: i } = this.props, o = this.getFieldValue();
130
- return k(t, o, i, e).then(
131
- ({ error: l, warning: r }) => Promise.resolve({ error: l, value: o, warning: r, field: t })
132
- );
133
- });
134
- /**
135
- *
136
- * @param triggerType the value of validateTrigger.
137
- * @returns
138
- */
139
- s(this, "validateField", (e) => {
140
- const { validateTrigger: t, validateMessages: i } = this.context, { field: o, rules: l, validateTrigger: r } = this.props, a = this.getFieldValue(), d = () => {
141
- var c;
142
- const h = this.errors || ((c = this.warnings) == null ? void 0 : c.length);
143
- this.toggleValidateStatus("validating"), this.setErrors(null), this.setWarnings(null), h && this.updateFormItem();
144
- }, n = e ? (l || []).filter((h) => [].concat(
145
- h.validateTrigger || r || t
146
- ).indexOf(e) > -1) : l;
147
- return n && n.length && o ? (d(), k(o, a, n, i).then(
148
- ({ error: h, warning: c }) => {
149
- var u;
150
- return this.setErrors(h ? h[o] : null), this.setWarnings(c || null), this.toggleValidateStatus(
151
- this.errors ? "error" : (u = this.warnings) != null && u.length ? "warning" : "success"
152
- ), this.updateFormItem(), Promise.resolve({ error: h, value: a, field: o });
153
- }
154
- )) : Promise.resolve({ error: null, value: a, field: o });
155
- });
156
- // 每次 render 都会作为 onChange 传递给 children,需要保证引用地址不变
157
- // 所以 handleTrigger 需要声明在类上,并且直接作为 children.props.onChange
158
- s(this, "handleTrigger", (e, ...t) => {
159
- const i = this.childrenElement || this.props.children, { store: o } = this.context, { field: l, trigger: r, normalize: a, getValueFromEvent: d } = this.props, n = F(d) ? d(e, ...t) : e;
160
- let h = n;
161
- if (q(n)) {
162
- U(
163
- !0,
164
- "changed value missed, please check whether extra elements is outta input/select controled by Form.Item"
165
- ), n.stopPropagation();
166
- return;
167
- }
168
- typeof a == "function" && (h = a(n, o.getFieldValue(l), {
169
- ...o.getFieldsValue()
170
- })), this.toggleTouched(!0), this.innerSetFieldValue(l, h), this.validateField(r), A(i) && i.props && i.props[r] && (this.props.isFormList || i.props[r](h, ...t));
171
- });
172
- s(this, "getChild", () => {
173
- const { children: e } = this.props, { store: t } = this.context;
174
- let i = e;
175
- return F(e) && (i = e(
176
- t.getFields(),
177
- {
178
- ...t
179
- },
180
- this.props.isFormList && {
181
- value: this.getFieldValue(),
182
- onChange: this.handleTrigger
183
- }
184
- )), this.childrenElement = i, i;
185
- });
186
- if ("initialValue" in e && this.hasFieldProps()) {
187
- const r = (o = (i = t == null ? void 0 : t.store) == null ? void 0 : i.getInnerMethods) == null ? void 0 : o.call(i, !0);
188
- (l = r == null ? void 0 : r.innerSetInitialValue) == null || l.call(r, e.field, e.initialValue);
189
- }
39
+ super(e), "initialValue" in e && this.hasFieldProps() && t?.store?.getInnerMethods?.(!0)?.innerSetInitialValue?.(e.field, e.initialValue);
190
40
  }
191
41
  componentDidMount() {
192
42
  const { store: e } = this.context ?? {};
@@ -201,65 +51,201 @@ class x extends z {
201
51
  this.props.disabled !== e.disabled && this.props.disabled || this.props.rules !== e.rules && !this.props.rules) && (this.updateFormItem(), this.clearFormItemError(e.field));
202
52
  }
203
53
  componentWillUnmount() {
204
- var e;
205
- (e = this.removeRegisterField) == null || e.call(this), this.removeRegisterField = null, this.clearFormItemError(), this.isDestroyed = !0;
54
+ this.removeRegisterField?.(), this.removeRegisterField = null, this.clearFormItemError(), this.isDestroyed = !0;
206
55
  }
56
+ // 触发 store 进行状态收集
57
+ // TODO: error, validateStatus ,touched 状态和 UI 组件解耦,统一维护在 store 内部
58
+ triggerStateCollect = () => {
59
+ const { innerCollectFormState: e } = this.context.store.getInnerMethods(!0);
60
+ e();
61
+ };
62
+ // 切换校验状态
63
+ toggleValidateStatus = (e) => {
64
+ this.validateStatus = e, this.triggerStateCollect();
65
+ };
66
+ // 切换 touch 状态
67
+ toggleTouched = (e) => {
68
+ this.touched = M(e) ? e : !this.touched, this.triggerStateCollect();
69
+ };
70
+ setWarnings = (e) => {
71
+ this.warnings = e, this.triggerStateCollect();
72
+ };
73
+ setErrors = (e) => {
74
+ this.errors = e, this.triggerStateCollect();
75
+ };
76
+ getErrors = () => this.errors;
77
+ getWarnings = () => this.warnings || [];
78
+ isTouched = () => this.touched;
79
+ getValidateStatus = () => this.props.validateStatus ? this.props.validateStatus : this.validateStatus;
80
+ hasFieldProps = () => !!this.props.field;
81
+ clearFormItemError = (e = this.props.field) => {
82
+ const { updateFormItem: t } = this.context;
83
+ t?.(e, { errors: null, warnings: null });
84
+ };
85
+ updateFormItem = () => {
86
+ if (this.isDestroyed) return;
87
+ this.forceUpdate();
88
+ const { updateFormItem: e } = this.context;
89
+ e?.(this.props.field, {
90
+ errors: this.errors,
91
+ warnings: this.warnings
92
+ });
93
+ };
94
+ getFieldValue = () => {
95
+ const e = this.props.field, t = this.context.store;
96
+ return e ? t.getInnerMethods(!0).innerGetFieldValue(e) : void 0;
97
+ };
98
+ onStoreChange = (e, t) => {
99
+ const r = S(t.field) ? t.field : [t.field], { field: s, shouldUpdate: i, dependencies: o } = this.props, n = (a) => {
100
+ if (o && i && C(!0, "`shouldUpdate` of the `Form.Item` will be ignored."), o)
101
+ S(o) && o.some((l) => v(l, r)) && this.isTouched() && this.validateField();
102
+ else if (i) {
103
+ let l = !1;
104
+ g(i) ? l = i(t.prev, t.current, {
105
+ field: t.field,
106
+ ...a
107
+ }) : l = !V(t.prev, t.current), l && this.updateFormItem();
108
+ }
109
+ };
110
+ switch (e) {
111
+ case "reset":
112
+ this.toggleTouched(!1), this.toggleValidateStatus(void 0), this.setErrors(null), this.setWarnings(null), o || i ? n() : this.updateFormItem();
113
+ break;
114
+ case "innerSetValue":
115
+ if (v(s, r)) {
116
+ this.toggleTouched(!0), this.updateFormItem();
117
+ return;
118
+ }
119
+ n({
120
+ isInner: !0,
121
+ isFormList: t.isFormList
122
+ });
123
+ break;
124
+ case "setFieldValue":
125
+ if (v(s, r)) {
126
+ this.toggleTouched(!0), t.data && "touched" in t.data && this.toggleTouched(t.data.touched), t.data && "warnings" in t.data && this.setWarnings(
127
+ U(t.data.warnings) ? [] : [].concat(t.data.warnings)
128
+ ), t.data && "errors" in t.data ? this.setErrors(t.data.errors) : V(f(t.prev, s), f(t.current, s)) || this.setErrors(null), this.updateFormItem();
129
+ return;
130
+ }
131
+ n();
132
+ break;
133
+ }
134
+ };
135
+ innerSetFieldValue = (e, t) => {
136
+ if (!e) return;
137
+ const { store: r } = this.context;
138
+ r.getInnerMethods(!0).innerSetFieldValue(e, t);
139
+ const i = {};
140
+ k(i, e, t), this.props?.onValuesChange?.(i, {
141
+ ...r.getFieldsValue()
142
+ });
143
+ };
144
+ // 仅仅校验下值,不做任何状态变更
145
+ validateFieldOnly = () => {
146
+ const { validateMessages: e } = this.context, { field: t, rules: r } = this.props, s = this.getFieldValue();
147
+ return x(t, s, r, e).then(
148
+ ({ error: i, warning: o }) => Promise.resolve({ error: i, value: s, warning: o, field: t })
149
+ );
150
+ };
151
+ /**
152
+ *
153
+ * @param triggerType the value of validateTrigger.
154
+ * @returns
155
+ */
156
+ validateField = (e) => {
157
+ const { validateTrigger: t, validateMessages: r } = this.context, { field: s, rules: i, validateTrigger: o } = this.props, n = this.getFieldValue(), a = () => {
158
+ const d = this.errors || this.warnings?.length;
159
+ this.toggleValidateStatus("validating"), this.setErrors(null), this.setWarnings(null), d && this.updateFormItem();
160
+ }, l = e ? (i || []).filter((d) => [].concat(
161
+ d.validateTrigger || o || t
162
+ ).indexOf(e) > -1) : i;
163
+ return l && l.length && s ? (a(), x(s, n, l, r).then(
164
+ ({ error: d, warning: h }) => (this.setErrors(d ? d[s] : null), this.setWarnings(h || null), this.toggleValidateStatus(
165
+ this.errors ? "error" : this.warnings?.length ? "warning" : "success"
166
+ ), this.updateFormItem(), Promise.resolve({ error: d, value: n, field: s }))
167
+ )) : Promise.resolve({ error: null, value: n, field: s });
168
+ };
207
169
  /**
208
170
  * 收集rules里的validateTrigger字段
209
171
  */
210
172
  getValidateTrigger() {
211
173
  const e = this.props.validateTrigger || this.context.validateTrigger || "onChange", t = this.props.rules || [];
212
- let i = [];
213
- return t.map((o) => {
214
- i = i.concat(o.validateTrigger || e);
215
- }), Array.from(new Set(i));
174
+ let r = [];
175
+ return t.map((s) => {
176
+ r = r.concat(s.validateTrigger || e);
177
+ }), Array.from(new Set(r));
216
178
  }
179
+ // 每次 render 都会作为 onChange 传递给 children,需要保证引用地址不变
180
+ // 所以 handleTrigger 需要声明在类上,并且直接作为 children.props.onChange
181
+ handleTrigger = (e, ...t) => {
182
+ const r = this.childrenElement || this.props.children, { store: s } = this.context, { field: i, trigger: o, normalize: n, getValueFromEvent: a } = this.props, l = g(a) ? a(e, ...t) : e;
183
+ let d = l;
184
+ if ($(l)) {
185
+ C(
186
+ !0,
187
+ "changed value missed, please check whether extra elements is outta input/select controled by Form.Item"
188
+ ), l.stopPropagation();
189
+ return;
190
+ }
191
+ typeof n == "function" && (d = n(l, s.getFieldValue(i), {
192
+ ...s.getFieldsValue()
193
+ })), this.toggleTouched(!0), this.innerSetFieldValue(i, d), this.validateField(o), N(r) && r.props && r.props[o] && (this.props.isFormList || r.props[o](d, ...t));
194
+ };
217
195
  renderControl(e, t) {
218
- var T;
219
196
  const {
220
- field: i,
221
- trigger: o = "onChange",
222
- triggerPropName: l = "value",
223
- validateStatus: r,
224
- formatter: a
225
- } = this.props, { store: d, disabled: n } = this.context, h = "disabled" in this.props ? this.props.disabled : n, c = I.Children.only(e), u = {
197
+ field: r,
198
+ trigger: s = "onChange",
199
+ triggerPropName: i = "value",
200
+ validateStatus: o,
201
+ formatter: n
202
+ } = this.props, { store: a, disabled: l } = this.context, d = "disabled" in this.props ? this.props.disabled : l, h = F.Children.only(e), c = {
226
203
  // used by label
227
- id: G(((T = c.props) == null ? void 0 : T.id) || { [`${t}${B}`]: t })
204
+ id: P(h.props?.id || { [`${t}${L}`]: t })
228
205
  };
229
- this.getValidateTrigger().forEach((S) => {
230
- u[S] = (D) => {
231
- var f, w;
232
- this.validateField(S), (w = (f = c.props) == null ? void 0 : f[S]) == null || w.call(f, D);
206
+ this.getValidateTrigger().forEach((p) => {
207
+ c[p] = (E) => {
208
+ this.validateField(p), h.props?.[p]?.(E);
233
209
  };
234
- }), u[o] = this.handleTrigger, h !== void 0 && !("disabled" in c.props) && (u.disabled = h);
235
- let v = V(d.getInnerMethods(!0).innerGetStore(), i);
236
- return F(a) && (v = a(v)), u[l] = v, !r && this.errors && (u.error = !0), I.cloneElement(c, u);
210
+ }), c[s] = this.handleTrigger, d !== void 0 && !("disabled" in h.props) && (c.disabled = d);
211
+ let m = f(a.getInnerMethods(!0).innerGetStore(), r);
212
+ return g(n) && (m = n(m)), c[i] = m, !o && this.errors && (c.error = !0), F.cloneElement(h, c);
237
213
  }
214
+ getChild = () => {
215
+ const { children: e } = this.props, { store: t } = this.context;
216
+ let r = e;
217
+ return g(e) && (r = e(
218
+ t.getFields(),
219
+ {
220
+ ...t
221
+ },
222
+ this.props.isFormList && {
223
+ value: this.getFieldValue(),
224
+ onChange: this.handleTrigger
225
+ }
226
+ )), this.childrenElement = r, r;
227
+ };
238
228
  render() {
239
- const { noStyle: e, field: t, isFormList: i, hasFeedback: o } = this.props, l = this.getValidateStatus(), { prefixCls: r, getFormElementId: a } = this.context;
240
- let d = this.getChild();
241
- const n = this.hasFieldProps() ? a == null ? void 0 : a(t) : void 0;
242
- return this.hasFieldProps() && !i && I.Children.count(d) === 1 && (d = this.renderControl(d, n)), e ? d : /* @__PURE__ */ m("div", { className: `${r}-item-control-wrapper`, children: /* @__PURE__ */ m("div", { className: `${r}-item-control`, id: n, children: /* @__PURE__ */ E("div", { className: `${r}-item-control-children`, children: [
243
- d,
244
- l && o && /* @__PURE__ */ E(
229
+ const { noStyle: e, field: t, isFormList: r, hasFeedback: s } = this.props, i = this.getValidateStatus(), { prefixCls: o, getFormElementId: n } = this.context;
230
+ let a = this.getChild();
231
+ const l = this.hasFieldProps() ? n?.(t) : void 0;
232
+ return this.hasFieldProps() && !r && F.Children.count(a) === 1 && (a = this.renderControl(a, l)), e ? a : /* @__PURE__ */ u("div", { className: `${o}-item-control-wrapper`, children: /* @__PURE__ */ u("div", { className: `${o}-item-control`, id: l, children: /* @__PURE__ */ I("div", { className: `${o}-item-control-children`, children: [
233
+ a,
234
+ i && s && /* @__PURE__ */ I(
245
235
  "div",
246
236
  {
247
- className: `${r}-item-feedback ${r}-item-feedback-${l}`,
237
+ className: `${o}-item-feedback ${o}-item-feedback-${i}`,
248
238
  children: [
249
- l === "warning" && /* @__PURE__ */ m($, {}),
250
- l === "success" && /* @__PURE__ */ m(P, {}),
251
- l === "error" && /* @__PURE__ */ m(W, {}),
252
- l === "validating" && /* @__PURE__ */ m(L, {})
239
+ i === "warning" && /* @__PURE__ */ u(b, {}),
240
+ i === "success" && /* @__PURE__ */ u(T, {}),
241
+ i === "error" && /* @__PURE__ */ u(w, {}),
242
+ i === "validating" && /* @__PURE__ */ u(y, {})
253
243
  ]
254
244
  }
255
245
  )
256
246
  ] }) }) });
257
247
  }
258
248
  }
259
- s(x, "defaultProps", {
260
- trigger: "onChange",
261
- triggerPropName: "value"
262
- }), s(x, "isFormControl", !0), s(x, "contextType", O);
263
249
  export {
264
- x as default
250
+ re as default
265
251
  };