@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/store.js CHANGED
@@ -1,311 +1,33 @@
1
- var j = Object.defineProperty;
2
- var k = (F, t, e) => t in F ? j(F, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : F[t] = e;
3
- var i = (F, t, e) => k(F, typeof t != "symbol" ? t + "" : t, e);
4
- import g from "lodash/get";
5
- import R from "lodash/has";
6
- import c from "lodash/isArray";
7
- import v from "lodash/isFunction";
8
- import E from "lodash/isPlainObject";
9
- import _ from "lodash/merge";
10
- import w from "lodash/omit";
11
- import L from "lodash/setWith";
12
- import { isExist as I } from "../components/common/utils/is.js";
13
- import { SubmitStatus as d } from "./interface.js";
14
- import B from "./promisify.js";
15
- import { iterativelyGetKeys as T, cloneDeep as m, set as o } from "./util.js";
16
- class X {
17
- constructor() {
18
- // 表示的 Form 的提交状态而非单个字段的提交状态。
19
- // 只有在触发表单 reset(原生 reset,而非当前的 resetFields) 时,才会回到 init 状态(目前没有支持 form.reset,所以没有这块逻辑)
20
- i(this, "submitStatus", d.init);
21
- i(this, "registerFields", []);
22
- // 所有 form item value 的变动,都会通知这里注册到的 watcher
23
- i(this, "registerWatchers", []);
24
- // 所有 form item 内部 errors, validating, touched 状态的变化,都会通知这里注册到的 watcher
25
- // TODO: 合并 registerWatchers
26
- i(this, "registerStateWatchers", []);
27
- // 所有 form 整体 的变动,都会通知这里注册到的 watcher
28
- i(this, "registerFormWatchers", []);
29
- // 和formControl 的 touched属性不一样。 只要被改过的字段,这里就会存储。并且不会跟随formControl被卸载而清除。
30
- // reset 的时候清除
31
- i(this, "touchedFields", {});
32
- i(this, "store", {});
33
- i(this, "initialValues", {});
34
- i(this, "callbacks", {});
35
- // 告知 form 状态改变,进行状态收集
36
- i(this, "innerCollectFormState", () => {
37
- this.notifyStateWatchers();
38
- });
39
- i(this, "innerSetCallbacks", (t) => {
40
- this.callbacks = t;
41
- });
42
- i(this, "registerFormWatcher", (t) => (this.registerFormWatchers.push(t), () => {
43
- this.registerFormWatchers = this.registerFormWatchers.filter(
44
- (e) => e !== t
45
- );
46
- }));
47
- i(this, "registerStateWatcher", (t) => (this.registerStateWatchers.push(t), () => {
48
- this.registerStateWatchers = this.registerStateWatchers.filter(
49
- (e) => e !== t
50
- );
51
- }));
52
- i(this, "registerWatcher", (t) => (this.registerWatchers.push(t), () => {
53
- this.registerWatchers = this.registerWatchers.filter((e) => e !== t);
54
- }));
55
- // 收集所有control字段,并在组件卸载时移除
56
- i(this, "registerField", (t) => (this.registerFields.push(t), this.notifyWatchers(), () => {
57
- this.registerFields = this.registerFields.filter((e) => e !== t), this.notifyWatchers();
58
- }));
59
- // hasField为true时,只返回传入field属性的control实例
60
- // isFormList 目前只在校验时需要包含
61
- // TODO formlist 实现缺陷,待优化
62
- i(this, "getRegisteredFields", (t, e) => t ? this.registerFields.filter(
63
- (r) => {
64
- var s;
65
- return r.hasFieldProps() && ((e == null ? void 0 : e.containFormList) || !((s = r.props) != null && s.isFormList));
66
- }
67
- ) : this.registerFields);
68
- // 获取props.field === field 的control组件。
69
- i(this, "getRegisteredField", (t) => this.registerFields.filter((e) => e.props.field === t)[0]);
70
- // 通知所有的FormItem进行更新。
71
- // setFieldValue: 外部调用setFieldsValue (setFieldValue等)方法触发更新
72
- // innerSetValue: 控件例如Input,通过onChange事件触发的更新
73
- // reset:重置
74
- i(this, "notify", (t, e) => {
75
- (t === "setFieldValue" || t === "innerSetValue" && !e.ignore) && this._pushTouchField(
76
- e.changeValues ? T(e.changeValues) : this._getIterativelyKeysByField(e.field)
77
- ), this.registerFields.forEach((r) => {
78
- var s;
79
- (s = r == null ? void 0 : r.onStoreChange) == null || s.call(r, t, {
80
- ...e,
81
- current: this.store
82
- });
83
- });
84
- });
85
- i(this, "innerSetInitialValues", (t) => {
86
- t && (this.initialValues = _(this.initialValues, m(t)), Object.keys(t).forEach((e) => {
87
- o(this.store, e, t[e]);
88
- }));
89
- });
90
- i(this, "innerSetInitialValue", (t, e) => {
91
- t && (this.initialValues[t] = e, this._inTouchFields(t) || o(this.store, t, g(this.initialValues, t)));
92
- });
93
- /**
94
- *
95
- * 内部使用,更新value,会同时触发onChange 和 onValuesChange
96
- * @options.isFormList 强制更新field对应的组件包括其子组件,form
97
- */
98
- i(this, "innerSetFieldValue", (t, e, r) => {
99
- if (!t)
100
- return;
101
- const s = this.getFields();
102
- o(this.store, t, e), this.triggerValuesChange({
103
- [t]: e
104
- }), this.triggerTouchChange({ [t]: e }), this.notify("innerSetValue", {
105
- prev: s,
106
- field: t,
107
- ...r,
108
- changeValues: { [t]: e }
109
- });
110
- });
111
- // 内部使用
112
- i(this, "innerGetStore", () => this.store);
113
- // 目前返回提交状态,后续统一维护 errors,warnings 后,这里可进行拓展
114
- i(this, "innerGetStoreStatus", () => ({
115
- submitStatus: this.submitStatus
116
- }));
117
- // 内部使用,返回原始对象,注入到组件的 value 都从这里获取值,cloneDeep 后的值每次引用地址是不同的
118
- i(this, "innerGetFieldValue", (t) => g(this.store, t));
119
- // 获取所有被操作过的字段
120
- i(this, "getTouchedFields", () => this.getRegisteredFields(!0).filter((t) => t.isTouched()).map((t) => t.props.field));
121
- // 外部调用设置表单字段值
122
- i(this, "setFieldValue", (t, e) => {
123
- t && this.setFields({
124
- [t]: { value: e }
125
- });
126
- });
127
- // 外部调用,设置多个表单控件的值
128
- i(this, "setFieldsValue", (t) => {
129
- if (E(t)) {
130
- const e = Object.keys(t), r = {};
131
- e.forEach((s) => {
132
- r[s] = {
133
- value: t[s]
134
- };
135
- }), this.setFields(r);
136
- }
137
- });
138
- // 外部调用,设置多个表单控件的值,以及 error,touch 信息。
139
- i(this, "setFields", (t) => {
140
- const e = Object.keys(t), r = {};
141
- e.forEach((s) => {
142
- const h = t[s], a = this.getFields();
143
- if (h) {
144
- const n = {};
145
- "error" in h && (n.errors = h.error), "warning" in h && (n.warnings = h.warning), "touched" in h && (n.touched = h.touched), "value" in h && (o(this.store, s, h.value), r[s] = h.value), this.notify("setFieldValue", {
146
- data: n,
147
- prev: a,
148
- field: s,
149
- changeValues: { [s]: h.value }
150
- });
151
- }
152
- }), this.triggerValuesChange(r);
153
- });
154
- i(this, "getFieldValue", (t) => m(g(this.store, t)));
155
- // 获取单个字段的错误信息。
156
- i(this, "getFieldError", (t) => {
157
- const e = this.getRegisteredField(t);
158
- return e ? e.getErrors() : null;
159
- });
160
- // 获取传入字段/全部的错误信息
161
- i(this, "getFieldsError", (t) => {
162
- const e = {};
163
- return c(t) ? t.map((r) => {
164
- const s = this.getFieldError(r);
165
- s && (e[r] = s);
166
- }) : this.getRegisteredFields(!0, { containFormList: !0 }).forEach(
167
- (r) => {
168
- r.getErrors() && (e[r.props.field] = r.getErrors());
169
- }
170
- ), e;
171
- });
172
- i(this, "getFields", () => m(this.store));
173
- i(this, "getFieldsValue", (t) => {
174
- const e = {};
175
- return c(t) ? (t.forEach((r) => {
176
- o(e, r, this.getFieldValue(r));
177
- }), e) : (this.getRegisteredFields(!0).forEach(({ props: { field: r } }) => {
178
- const s = g(this.store, r);
179
- o(e, r, s);
180
- }), e);
181
- });
182
- i(this, "getInitialValues", () => this.initialValues);
183
- i(this, "setInitialValues", (t) => {
184
- this.innerSetInitialValues(t), this.setFieldsValue(t);
185
- });
186
- i(this, "setInitialValue", (t, e) => {
187
- this.innerSetInitialValue(t, e), this.setFieldValue(t, e);
188
- });
189
- i(this, "resetFields", (t) => {
190
- const e = this.getFields(), r = I(t) && !c(t) ? [t] : t;
191
- let s = {};
192
- if (r && c(r))
193
- r.forEach((a) => {
194
- o(
195
- this.store,
196
- a,
197
- this.initialValues[a]
198
- ), s[a] = g(this.store, a);
199
- }), this.triggerValuesChange(s), this.notify("reset", { prev: e, field: r }), this._popTouchField(r);
200
- else {
201
- const a = {};
202
- s = this.getFields(), Object.keys(this.initialValues).forEach((n) => {
203
- o(a, n, this.initialValues[n]);
204
- }), this.store = a, this.getRegisteredFields(!0).forEach((n) => {
205
- const p = n.props.field;
206
- o(s, p, g(this.store, p));
207
- }), this.triggerValuesChange(s), this._popTouchField(), this.notify("reset", {
208
- prev: e,
209
- field: Object.keys(s)
210
- });
211
- }
212
- const { onReset: h } = this.callbacks;
213
- h == null || h(s);
214
- });
215
- i(this, "validate", B(
216
- (t, e, r) => {
217
- const s = this.getRegisteredFields(!0, {
218
- containFormList: !0
219
- }), h = c(t) && t.length ? s.filter(
220
- (l) => t.indexOf(l.props.field) > -1
221
- ) : s, a = E(t) ? t : E(e) ? e : {}, n = v(t) ? t : v(e) ? e : r || (() => {
222
- }), p = h.map(
223
- (l) => a != null && a.validateOnly ? l.validateFieldOnly() : l.validateField()
224
- ), S = (l) => {
225
- if (!(a != null && a.validateOnly)) {
226
- const { onValidateFail: u } = this.callbacks;
227
- u == null || u(l);
228
- }
229
- };
230
- return Promise.all(p).then((l) => {
231
- let u = {};
232
- const V = {};
233
- l.map((f) => {
234
- var b;
235
- f.error && (u = { ...u, ...f.error });
236
- const W = this.getRegisteredField(f.field);
237
- (b = W == null ? void 0 : W.props) != null && b.isFormList || o(V, f.field, f.value);
238
- });
239
- let y;
240
- return Object.keys(u).length ? (S == null || S(u), y = n == null ? void 0 : n(u, m(V))) : y = n == null ? void 0 : n(null, m(V)), y;
241
- }).catch((l) => l).finally(() => {
242
- });
243
- }
244
- ));
245
- i(this, "toggleSubmitStatus", (t) => {
246
- this.submitStatus = t, this.innerCollectFormState(), this.notifyFormWatcher();
247
- });
248
- i(this, "submit", () => {
249
- this.toggleSubmitStatus(d.submitting);
250
- const t = (e, r) => {
251
- let s;
252
- const { onSubmit: h, onSubmitFailed: a } = this.callbacks;
253
- return !e && h && (s = h(r)), e && a && (s = a(e)), s && s.then ? s.then((n) => (this.toggleSubmitStatus(d.success), n)).catch((n) => (this.toggleSubmitStatus(d.error), Promise.reject(n))) : this.toggleSubmitStatus(
254
- e ? d.error : d.success
255
- ), s;
256
- };
257
- return this.validate(t);
258
- });
259
- i(this, "getFieldsState", (t) => {
260
- const e = {}, r = (s) => {
261
- if (!s)
262
- return null;
263
- const h = s.getErrors();
264
- return {
265
- errors: h ? [h] : [],
266
- warnings: s.getWarnings(),
267
- validateStatus: s.getValidateStatus(),
268
- isSubmitting: this.submitStatus === d.submitting,
269
- isTouched: s.isTouched(),
270
- value: this.getFieldValue(s.props.field)
271
- };
272
- };
273
- return c(t) ? (t.forEach((s) => {
274
- e[s] = r(this.getRegisteredField(s));
275
- }), e) : (this.getRegisteredFields(!0).forEach((s) => {
276
- e[s.props.field] = r(s);
277
- }), e);
278
- });
279
- i(this, "clearFields", (t) => {
280
- const e = this.getFields(), r = I(t) && !c(t) ? [t] : t;
281
- if (r && c(r)) {
282
- const s = {};
283
- r.forEach((h) => {
284
- o(this.store, h, void 0), s[h] = g(this.store, h);
285
- }), this.triggerValuesChange(s), this.notify("setFieldValue", {
286
- prev: e,
287
- field: r,
288
- data: {
289
- errors: null,
290
- warnings: null
291
- }
292
- });
293
- } else {
294
- const s = {};
295
- this.store = {}, this.getRegisteredFields(!0).forEach((h) => {
296
- const a = h.props.field;
297
- o(s, a, void 0);
298
- }), this.triggerValuesChange(s), this.notify("setFieldValue", {
299
- prev: e,
300
- field: Object.keys(s),
301
- data: {
302
- errors: null,
303
- warnings: null
304
- }
305
- });
306
- }
307
- });
308
- }
1
+ import c from "lodash/get";
2
+ import E from "lodash/has";
3
+ import l from "lodash/isArray";
4
+ import S from "lodash/isFunction";
5
+ import V from "lodash/isPlainObject";
6
+ import v from "lodash/merge";
7
+ import k from "lodash/omit";
8
+ import I from "lodash/setWith";
9
+ import { isExist as y } from "../components/common/utils/is.js";
10
+ import { SubmitStatus as g } from "./interface.js";
11
+ import R from "./promisify.js";
12
+ import { iterativelyGetKeys as b, cloneDeep as F, set as o } from "./util.js";
13
+ class J {
14
+ // 表示的 Form 的提交状态而非单个字段的提交状态。
15
+ // 只有在触发表单 reset(原生 reset,而非当前的 resetFields) 时,才会回到 init 状态(目前没有支持 form.reset,所以没有这块逻辑)
16
+ submitStatus = g.init;
17
+ registerFields = [];
18
+ // 所有 form item value 的变动,都会通知这里注册到的 watcher
19
+ registerWatchers = [];
20
+ // 所有 form item 内部 errors, validating, touched 状态的变化,都会通知这里注册到的 watcher
21
+ // TODO: 合并 registerWatchers
22
+ registerStateWatchers = [];
23
+ // 所有 form 整体 的变动,都会通知这里注册到的 watcher
24
+ registerFormWatchers = [];
25
+ // 和formControl touched属性不一样。 只要被改过的字段,这里就会存储。并且不会跟随formControl被卸载而清除。
26
+ // reset 的时候清除
27
+ touchedFields = {};
28
+ store = {};
29
+ initialValues = {};
30
+ callbacks = {};
309
31
  notifyWatchers() {
310
32
  this.registerWatchers.forEach((t) => {
311
33
  t();
@@ -325,36 +47,302 @@ class X {
325
47
  triggerValuesChange(t) {
326
48
  if (t && Object.keys(t).length) {
327
49
  const { onValuesChange: e } = this.callbacks;
328
- e == null || e(t, this.getFields());
50
+ e?.(t, this.getFields());
329
51
  }
330
52
  this.notifyWatchers();
331
53
  }
332
54
  triggerTouchChange(t) {
333
55
  if (t && Object.keys(t).length) {
334
56
  const { onChange: e } = this.callbacks;
335
- e == null || e(t, this.getFields());
57
+ e?.(t, this.getFields());
336
58
  }
337
59
  }
60
+ // 告知 form 状态改变,进行状态收集
61
+ innerCollectFormState = () => {
62
+ this.notifyStateWatchers();
63
+ };
64
+ innerSetCallbacks = (t) => {
65
+ this.callbacks = t;
66
+ };
67
+ registerFormWatcher = (t) => (this.registerFormWatchers.push(t), () => {
68
+ this.registerFormWatchers = this.registerFormWatchers.filter(
69
+ (e) => e !== t
70
+ );
71
+ });
72
+ registerStateWatcher = (t) => (this.registerStateWatchers.push(t), () => {
73
+ this.registerStateWatchers = this.registerStateWatchers.filter(
74
+ (e) => e !== t
75
+ );
76
+ });
77
+ registerWatcher = (t) => (this.registerWatchers.push(t), () => {
78
+ this.registerWatchers = this.registerWatchers.filter((e) => e !== t);
79
+ });
80
+ // 收集所有control字段,并在组件卸载时移除
81
+ registerField = (t) => (this.registerFields.push(t), this.notifyWatchers(), () => {
82
+ this.registerFields = this.registerFields.filter((e) => e !== t), this.notifyWatchers();
83
+ });
84
+ // hasField为true时,只返回传入field属性的control实例
85
+ // isFormList 目前只在校验时需要包含
86
+ // TODO formlist 实现缺陷,待优化
87
+ getRegisteredFields = (t, e) => t ? this.registerFields.filter(
88
+ (i) => i.hasFieldProps() && (e?.containFormList || !i.props?.isFormList)
89
+ ) : this.registerFields;
90
+ // 获取props.field === field 的control组件。
91
+ getRegisteredField = (t) => this.registerFields.filter((e) => e.props.field === t)[0];
92
+ // 通知所有的FormItem进行更新。
93
+ // setFieldValue: 外部调用setFieldsValue (setFieldValue等)方法触发更新
94
+ // innerSetValue: 控件例如Input,通过onChange事件触发的更新
95
+ // reset:重置
96
+ notify = (t, e) => {
97
+ (t === "setFieldValue" || t === "innerSetValue" && !e.ignore) && this._pushTouchField(
98
+ e.changeValues ? b(e.changeValues) : this._getIterativelyKeysByField(e.field)
99
+ ), this.registerFields.forEach((i) => {
100
+ i?.onStoreChange?.(t, {
101
+ ...e,
102
+ current: this.store
103
+ });
104
+ });
105
+ };
106
+ innerSetInitialValues = (t) => {
107
+ t && (this.initialValues = v(this.initialValues, F(t)), Object.keys(t).forEach((e) => {
108
+ o(this.store, e, t[e]);
109
+ }));
110
+ };
111
+ innerSetInitialValue = (t, e) => {
112
+ t && (this.initialValues[t] = e, this._inTouchFields(t) || o(this.store, t, c(this.initialValues, t)));
113
+ };
338
114
  _getIterativelyKeysByField(t) {
339
115
  if (!t)
340
116
  return [];
341
- const r = [].concat(t).map((s) => T(o({}, s, void 0))).reduce((s, h) => s.concat(h), []);
342
- return [t, ...r];
117
+ const i = [].concat(t).map((s) => b(o({}, s, void 0))).reduce((s, r) => s.concat(r), []);
118
+ return [t, ...i];
343
119
  }
344
120
  _inTouchFields(t) {
345
- return this._getIterativelyKeysByField(t).some((r) => R(this.touchedFields, r));
121
+ return this._getIterativelyKeysByField(t).some((i) => E(this.touchedFields, i));
346
122
  }
347
123
  _popTouchField(t) {
348
124
  t === void 0 && (this.touchedFields = {});
349
125
  const e = this._getIterativelyKeysByField(t);
350
- this.touchedFields = w(this.touchedFields, e);
126
+ this.touchedFields = k(this.touchedFields, e);
351
127
  }
352
128
  _pushTouchField(t) {
353
129
  [].concat(t).forEach((e) => {
354
- L(this.touchedFields, e, void 0, Object);
130
+ I(this.touchedFields, e, void 0, Object);
355
131
  });
356
132
  }
133
+ /**
134
+ *
135
+ * 内部使用,更新value,会同时触发onChange 和 onValuesChange
136
+ * @options.isFormList 强制更新field对应的组件包括其子组件,form
137
+ */
138
+ innerSetFieldValue = (t, e, i) => {
139
+ if (!t)
140
+ return;
141
+ const s = this.getFields();
142
+ o(this.store, t, e), this.triggerValuesChange({
143
+ [t]: e
144
+ }), this.triggerTouchChange({ [t]: e }), this.notify("innerSetValue", {
145
+ prev: s,
146
+ field: t,
147
+ ...i,
148
+ changeValues: { [t]: e }
149
+ });
150
+ };
151
+ // 内部使用
152
+ innerGetStore = () => this.store;
153
+ // 目前返回提交状态,后续统一维护 errors,warnings 后,这里可进行拓展
154
+ innerGetStoreStatus = () => ({
155
+ submitStatus: this.submitStatus
156
+ });
157
+ // 内部使用,返回原始对象,注入到组件的 value 都从这里获取值,cloneDeep 后的值每次引用地址是不同的
158
+ innerGetFieldValue = (t) => c(this.store, t);
159
+ // 获取所有被操作过的字段
160
+ getTouchedFields = () => this.getRegisteredFields(!0).filter((t) => t.isTouched()).map((t) => t.props.field);
161
+ // 外部调用设置表单字段值
162
+ setFieldValue = (t, e) => {
163
+ t && this.setFields({
164
+ [t]: { value: e }
165
+ });
166
+ };
167
+ // 外部调用,设置多个表单控件的值
168
+ setFieldsValue = (t) => {
169
+ if (V(t)) {
170
+ const e = Object.keys(t), i = {};
171
+ e.forEach((s) => {
172
+ i[s] = {
173
+ value: t[s]
174
+ };
175
+ }), this.setFields(i);
176
+ }
177
+ };
178
+ // 外部调用,设置多个表单控件的值,以及 error,touch 信息。
179
+ setFields = (t) => {
180
+ const e = Object.keys(t), i = {};
181
+ e.forEach((s) => {
182
+ const r = t[s], a = this.getFields();
183
+ if (r) {
184
+ const h = {};
185
+ "error" in r && (h.errors = r.error), "warning" in r && (h.warnings = r.warning), "touched" in r && (h.touched = r.touched), "value" in r && (o(this.store, s, r.value), i[s] = r.value), this.notify("setFieldValue", {
186
+ data: h,
187
+ prev: a,
188
+ field: s,
189
+ changeValues: { [s]: r.value }
190
+ });
191
+ }
192
+ }), this.triggerValuesChange(i);
193
+ };
194
+ getFieldValue = (t) => F(c(this.store, t));
195
+ // 获取单个字段的错误信息。
196
+ getFieldError = (t) => {
197
+ const e = this.getRegisteredField(t);
198
+ return e ? e.getErrors() : null;
199
+ };
200
+ // 获取传入字段/全部的错误信息
201
+ getFieldsError = (t) => {
202
+ const e = {};
203
+ return l(t) ? t.map((i) => {
204
+ const s = this.getFieldError(i);
205
+ s && (e[i] = s);
206
+ }) : this.getRegisteredFields(!0, { containFormList: !0 }).forEach(
207
+ (i) => {
208
+ i.getErrors() && (e[i.props.field] = i.getErrors());
209
+ }
210
+ ), e;
211
+ };
212
+ getFields = () => F(this.store);
213
+ getFieldsValue = (t) => {
214
+ const e = {};
215
+ return l(t) ? (t.forEach((i) => {
216
+ o(e, i, this.getFieldValue(i));
217
+ }), e) : (this.getRegisteredFields(!0).forEach(({ props: { field: i } }) => {
218
+ const s = c(this.store, i);
219
+ o(e, i, s);
220
+ }), e);
221
+ };
222
+ getInitialValues = () => this.initialValues;
223
+ setInitialValues = (t) => {
224
+ this.innerSetInitialValues(t), this.setFieldsValue(t);
225
+ };
226
+ setInitialValue = (t, e) => {
227
+ this.innerSetInitialValue(t, e), this.setFieldValue(t, e);
228
+ };
229
+ resetFields = (t) => {
230
+ const e = this.getFields(), i = y(t) && !l(t) ? [t] : t;
231
+ let s = {};
232
+ if (i && l(i))
233
+ i.forEach((a) => {
234
+ o(
235
+ this.store,
236
+ a,
237
+ this.initialValues[a]
238
+ ), s[a] = c(this.store, a);
239
+ }), this.triggerValuesChange(s), this.notify("reset", { prev: e, field: i }), this._popTouchField(i);
240
+ else {
241
+ const a = {};
242
+ s = this.getFields(), Object.keys(this.initialValues).forEach((h) => {
243
+ o(a, h, this.initialValues[h]);
244
+ }), this.store = a, this.getRegisteredFields(!0).forEach((h) => {
245
+ const m = h.props.field;
246
+ o(s, m, c(this.store, m));
247
+ }), this.triggerValuesChange(s), this._popTouchField(), this.notify("reset", {
248
+ prev: e,
249
+ field: Object.keys(s)
250
+ });
251
+ }
252
+ const { onReset: r } = this.callbacks;
253
+ r?.(s);
254
+ };
255
+ validate = R(
256
+ (t, e, i) => {
257
+ const s = this.getRegisteredFields(!0, {
258
+ containFormList: !0
259
+ }), r = l(t) && t.length ? s.filter(
260
+ (n) => t.indexOf(n.props.field) > -1
261
+ ) : s, a = V(t) ? t : V(e) ? e : {}, h = S(t) ? t : S(e) ? e : i || (() => {
262
+ }), m = r.map(
263
+ (n) => a?.validateOnly ? n.validateFieldOnly() : n.validateField()
264
+ ), W = (n) => {
265
+ if (!a?.validateOnly) {
266
+ const { onValidateFail: u } = this.callbacks;
267
+ u?.(n);
268
+ }
269
+ };
270
+ return Promise.all(m).then((n) => {
271
+ let u = {};
272
+ const p = {};
273
+ n.map((d) => {
274
+ d.error && (u = { ...u, ...d.error }), this.getRegisteredField(d.field)?.props?.isFormList || o(p, d.field, d.value);
275
+ });
276
+ let f;
277
+ return Object.keys(u).length ? (W?.(u), f = h?.(u, F(p))) : f = h?.(null, F(p)), f;
278
+ }).catch((n) => n).finally(() => {
279
+ });
280
+ }
281
+ );
282
+ toggleSubmitStatus = (t) => {
283
+ this.submitStatus = t, this.innerCollectFormState(), this.notifyFormWatcher();
284
+ };
285
+ submit = () => {
286
+ this.toggleSubmitStatus(g.submitting);
287
+ const t = (e, i) => {
288
+ let s;
289
+ const { onSubmit: r, onSubmitFailed: a } = this.callbacks;
290
+ return !e && r && (s = r(i)), e && a && (s = a(e)), s && s.then ? s.then((h) => (this.toggleSubmitStatus(g.success), h)).catch((h) => (this.toggleSubmitStatus(g.error), Promise.reject(h))) : this.toggleSubmitStatus(
291
+ e ? g.error : g.success
292
+ ), s;
293
+ };
294
+ return this.validate(t);
295
+ };
296
+ getFieldsState = (t) => {
297
+ const e = {}, i = (s) => {
298
+ if (!s)
299
+ return null;
300
+ const r = s.getErrors();
301
+ return {
302
+ errors: r ? [r] : [],
303
+ warnings: s.getWarnings(),
304
+ validateStatus: s.getValidateStatus(),
305
+ isSubmitting: this.submitStatus === g.submitting,
306
+ isTouched: s.isTouched(),
307
+ value: this.getFieldValue(s.props.field)
308
+ };
309
+ };
310
+ return l(t) ? (t.forEach((s) => {
311
+ e[s] = i(this.getRegisteredField(s));
312
+ }), e) : (this.getRegisteredFields(!0).forEach((s) => {
313
+ e[s.props.field] = i(s);
314
+ }), e);
315
+ };
316
+ clearFields = (t) => {
317
+ const e = this.getFields(), i = y(t) && !l(t) ? [t] : t;
318
+ if (i && l(i)) {
319
+ const s = {};
320
+ i.forEach((r) => {
321
+ o(this.store, r, void 0), s[r] = c(this.store, r);
322
+ }), this.triggerValuesChange(s), this.notify("setFieldValue", {
323
+ prev: e,
324
+ field: i,
325
+ data: {
326
+ errors: null,
327
+ warnings: null
328
+ }
329
+ });
330
+ } else {
331
+ const s = {};
332
+ this.store = {}, this.getRegisteredFields(!0).forEach((r) => {
333
+ const a = r.props.field;
334
+ o(s, a, void 0);
335
+ }), this.triggerValuesChange(s), this.notify("setFieldValue", {
336
+ prev: e,
337
+ field: Object.keys(s),
338
+ data: {
339
+ errors: null,
340
+ warnings: null
341
+ }
342
+ });
343
+ }
344
+ };
357
345
  }
358
346
  export {
359
- X as default
347
+ J as default
360
348
  };