@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.
- package/Affix.js +1 -1
- package/Carousel.js +1 -1
- package/LiquidFill.js +4 -0
- package/OverflowEllipsis.js +1 -1
- package/PageHeader.js +1 -1
- package/QrCode.js +57 -0
- package/Tour.js +63 -0
- package/Trigger.js +1 -1
- package/_virtual/_commonjsHelpers.js +6 -0
- package/_virtual/index.js +7 -0
- package/_virtual/index2.js +4 -0
- package/affix/index.js +70 -72
- package/alert/index.js +56 -56
- package/anchor/Anchor.js +55 -55
- package/anchor/Link.js +34 -34
- package/anchor/util.js +5 -5
- package/auto-complete/index.js +116 -122
- package/avatar/Avatar.js +33 -33
- package/avatar/Group.js +26 -26
- package/back-top/index.js +58 -61
- package/badge/index.js +46 -46
- package/breadcrumb/Item.js +42 -43
- package/breadcrumb/index.js +47 -47
- package/button/Group.js +6 -6
- package/button/index.js +91 -91
- package/calendar/Month.js +75 -75
- package/calendar/Year.js +35 -35
- package/calendar/header/index.js +25 -25
- package/calendar/index.js +103 -103
- package/card/Grid.js +8 -8
- package/card/Meta.js +16 -16
- package/card/index.js +49 -49
- package/carousel/Arrow.js +19 -19
- package/carousel/Indicator.js +26 -26
- package/carousel/index.js +108 -108
- package/cascader/Cascader.js +178 -191
- package/cascader/base/node.js +133 -136
- package/cascader/base/store.js +82 -85
- package/cascader/panel/List.js +125 -129
- package/cascader/panel/Search.js +79 -81
- package/cascader/util.js +13 -13
- package/checkbox/Checkbox.js +94 -96
- package/checkbox/Group.js +54 -56
- package/checkbox/GroupBlock.js +28 -29
- package/collapse/Collapse.js +45 -45
- package/collapse/Item.js +53 -55
- package/color-picker/ControlBar.js +43 -43
- package/color-picker/InputAlpha.js +12 -12
- package/color-picker/InputHex.js +30 -31
- package/color-picker/InputRgb.js +24 -24
- package/color-picker/Palette.js +18 -18
- package/color-picker/Panel.js +122 -125
- package/color-picker/hooks/useColorPicker.js +85 -88
- package/color-picker/hooks/useControlBlock.js +38 -40
- package/color-picker/index.js +47 -47
- package/comment/index.js +29 -29
- package/components/common/higher-order/with-speech-synthesis/index.js +37 -40
- package/components/common/hooks/useId.js +8 -8
- package/components/common/hooks/useInView.js +16 -16
- package/components/common/hooks/useIntersectionObserver.js +1 -1
- package/components/common/hooks/useKeyboardEvent.js +9 -10
- package/components/common/hooks/useOverflowHidden.js +1 -4
- package/components/common/hooks/usePersistCallback.js +7 -7
- package/components/common/hooks/useStateCallback.js +9 -10
- package/components/common/hooks/useWindowSize.js +8 -8
- package/components/common/space/index.js +9 -7
- package/components/common/utils/convertToDurationBasedOnTimeUnits.js +6 -0
- package/components/common/utils/dom.js +27 -29
- package/components/common/utils/findScrollParent.js +17 -0
- package/components/common/utils/intersectionObserver.js +21 -0
- package/components/common/utils/is.js +99 -109
- package/components/common/utils/mutationObserver.js +19 -0
- package/components/common/utils/reactDOM.js +34 -34
- package/components/common/utils/resizeObserver.js +21 -0
- package/copy/index.js +38 -40
- package/date-picker/Picker.js +290 -295
- package/date-picker/RangePicker.js +367 -372
- package/date-picker/index.js +33 -35
- package/date-picker/panel/Body.js +46 -47
- package/date-picker/panel/Header.js +33 -33
- package/date-picker/panel/Shortcut.js +31 -31
- package/date-picker/panel/date/index.js +85 -85
- package/date-picker/panel/month/index.js +59 -59
- package/date-picker/panel/quarter/index.js +67 -70
- package/date-picker/panel/range/index.js +101 -101
- package/date-picker/panel/year/index.js +39 -39
- package/date-picker/util.js +17 -18
- package/descriptions/index.js +62 -62
- package/details/index.js +53 -55
- package/development/index.js +9 -9
- package/dist/tinycolor/chunk/BOzCVdr0.js +1 -1
- package/dist/validate/src/index.js +5 -5
- package/dist/validate/src/util.js +1 -1
- package/divider/index.js +21 -21
- package/draggable/Item.js +35 -35
- package/draggable/index.js +22 -22
- package/drawer/Drawer.js +142 -147
- package/dropdown/Button.js +48 -48
- package/dropdown/index.js +88 -92
- package/empty/index.js +16 -16
- package/form/Control.js +211 -225
- package/form/Form.js +109 -113
- package/form/FormItem.js +118 -120
- package/form/FormList.js +60 -66
- package/form/FormProvider.js +31 -34
- package/form/hook/useContext.js +17 -19
- package/form/hook/useState.js +22 -23
- package/form/hook/useWatch.js +26 -27
- package/form/promisify.js +14 -18
- package/form/store.js +304 -316
- package/form/util.js +14 -15
- package/grid/Col.js +64 -64
- package/grid/Grid.js +51 -51
- package/grid/GridItem.js +48 -48
- package/grid/Row.js +39 -39
- package/hooks/useVerificationCode.js +41 -43
- package/hooks/useWatermark.js +89 -92
- package/icon/index.js +23 -24
- package/icon-hover/index.js +16 -16
- package/icons/file.js +11 -11
- package/image/Image.js +140 -141
- package/image/ImagePreview.js +252 -255
- package/image/ImagePreviewArrow.js +25 -25
- package/image/ImagePreviewGroup.js +62 -62
- package/image/util/getScale.js +25 -28
- package/index.js +684 -675
- package/input/Button.js +48 -50
- package/input/Group.js +9 -9
- package/input/Input.js +145 -154
- package/input/InputElement.js +108 -115
- package/input/Password.js +38 -38
- package/input/Search.js +51 -55
- package/input/Textarea.js +80 -81
- package/input/useComposition.js +23 -23
- package/input-number/decimal.js +59 -62
- package/input-number/index.js +139 -141
- package/input-tag/InputTag.js +222 -230
- package/layout/Content.js +6 -6
- package/layout/Footer.js +8 -8
- package/layout/Header.js +7 -7
- package/layout/Sider.js +88 -90
- package/layout/index.js +30 -30
- package/link/index.js +45 -46
- package/liquid-fill/LiquidFill.js +226 -0
- package/liquid-fill/LiquidFill2.js +3 -0
- package/liquid-fill/index.js +4 -0
- package/list/Item.js +28 -28
- package/list/Meta.js +12 -12
- package/list/index.js +146 -148
- package/mentions/index.js +75 -76
- package/menu/Item.js +58 -58
- package/menu/Menu.js +125 -127
- package/menu/OverflowWrap.js +39 -40
- package/menu/sub-menu/Inline.js +45 -45
- package/menu/util.js +26 -28
- package/message/index.js +96 -99
- package/message/useMessage.js +26 -27
- package/modal/Confirm.js +47 -49
- package/modal/Modal.js +250 -257
- package/modal/use-modal/Hook.js +26 -28
- package/modal/use-modal/index.js +46 -49
- package/notice/index.js +89 -90
- package/notification/index.js +60 -65
- package/notification/withNotification.js +35 -35
- package/overflow-ellipsis/OverflowItem.js +19 -20
- package/overflow-ellipsis/index.js +45 -46
- package/package.json +1 -1
- package/page-header/index.js +45 -45
- package/pagination/PageItem.js +87 -91
- package/pagination/PageJumper.js +40 -41
- package/pagination/PageOption.js +31 -35
- package/pagination/Pagination.js +162 -163
- package/picker/Input.js +90 -96
- package/picker/InputRange.js +115 -122
- package/popconfirm/index.js +98 -100
- package/popover/index.js +28 -28
- package/portal/Portal.js +10 -11
- package/progress/index.js +36 -36
- package/qr-code/index.js +99 -0
- package/qr-code/interface.js +1 -0
- package/radio/Group.js +48 -48
- package/radio/GroupBlock.js +32 -33
- package/radio/Radio.js +62 -64
- package/rate/index.js +88 -88
- package/resize-box/ResizeTrigger.js +39 -39
- package/resize-box/Split.js +92 -96
- package/resize-box/SplitGroup.js +116 -122
- package/resize-box/index.js +112 -115
- package/result/index.js +44 -44
- package/select/Option.js +53 -56
- package/select/Select.js +365 -381
- package/select/util.js +95 -99
- package/select-view/Core.js +159 -160
- package/skeleton/index.js +23 -23
- package/slider/Button.js +84 -92
- package/slider/Input.js +47 -49
- package/slider/Tick.js +28 -31
- package/slider/index.js +107 -107
- package/space/index.js +26 -26
- package/space-/index.js +51 -51
- package/spin/DotLoading.js +8 -8
- package/spin/index.js +47 -47
- package/statistic/Countdown.js +37 -37
- package/statistic/index.js +58 -58
- package/steps/Step.js +42 -42
- package/steps/index.js +54 -54
- package/style.css +1 -1
- package/switch/index.js +77 -78
- package/table/ColGroup.js +36 -37
- package/table/Table.js +447 -450
- package/table/hook/useExpand.js +24 -24
- package/table/hook/useRowSelection.js +62 -62
- package/table/summary/Row.js +16 -17
- package/table/tbody/Td.js +119 -118
- package/table/tbody/Tr.js +119 -121
- package/table/tbody/index.js +62 -63
- package/table/th-resizable/index.js +30 -30
- package/table/thead/Column.js +148 -148
- package/table/thead/index.js +87 -88
- package/tabs/Tab.js +55 -55
- package/tabs/TabContent.js +8 -8
- package/tabs/TabPane.js +15 -15
- package/tabs/hook/useHeaderScroll.js +36 -36
- package/tabs/tab-header/TabInk.js +31 -33
- package/tabs/tab-header/TabNavIcon.js +34 -35
- package/tabs/tab-header/index.js +192 -195
- package/tag/index.js +94 -97
- package/time-picker/Picker.js +167 -172
- package/time-picker/RangePicker.js +28 -28
- package/time-picker/TimePicker.js +146 -146
- package/timeline/Item.js +46 -46
- package/timeline/Timeline.js +52 -52
- package/tooltip/index.js +89 -95
- package/tour/index.js +289 -0
- package/transfer/Item.js +54 -54
- package/transfer/List.js +134 -136
- package/transfer/index.js +91 -91
- package/tree/Animation.js +49 -52
- package/tree/Node.js +114 -122
- package/tree/NodeList.js +51 -51
- package/tree/Tree.js +386 -393
- package/tree-select/List.js +71 -72
- package/tree-select/Select.js +135 -143
- package/tree-select/hook/useKeyCache.js +39 -39
- package/tree-select/hook/useStateValue.js +12 -12
- package/trigger/getPopupStyle.js +60 -61
- package/trigger/index.js +337 -346
- package/types/common/space/interface.d.ts +1 -1
- package/types/common/utils/convertToDurationBasedOnTimeUnits.d.ts +3 -0
- package/types/common/utils/findScrollParent.d.ts +2 -0
- package/types/common/utils/index.d.ts +5 -0
- package/types/common/utils/intersectionObserver.d.ts +2 -0
- package/types/common/utils/mutationObserver.d.ts +2 -0
- package/types/common/utils/resizeObserver.d.ts +2 -0
- package/types/pc/config-provider/interface.d.ts +6 -0
- package/types/pc/index.d.ts +3 -0
- package/types/pc/liquid-fill/LiquidFill.d.ts +115 -0
- package/types/pc/liquid-fill/LiquidFill2.d.ts +1 -0
- package/types/pc/liquid-fill/index.d.ts +2 -0
- package/types/pc/qr-code/index.d.ts +34 -0
- package/types/pc/qr-code/interface.d.ts +39 -0
- package/types/pc/table/interface.d.ts +2 -2
- package/types/pc/tour/index.d.ts +42 -0
- package/types/pc/utils/convertToDurationBasedOnTimeUnits.d.ts +3 -0
- package/types/pc/utils/findScrollParent.d.ts +2 -0
- package/types/pc/utils/index.d.ts +5 -0
- package/types/pc/utils/intersectionObserver.d.ts +2 -0
- package/types/pc/utils/mutationObserver.d.ts +2 -0
- package/types/pc/utils/names.d.ts +18 -0
- package/types/pc/utils/resizeObserver.d.ts +2 -0
- package/typography/Base.js +79 -81
- package/typography/EditContent.js +30 -33
- package/typography/Ellipsis.js +77 -73
- package/typography/Operations.js +50 -52
- package/typography/Paragraph.js +7 -7
- package/typography/Typography.js +7 -7
- package/typography/useEllipsis.js +105 -106
- package/upload/TriggerNode.js +69 -76
- package/upload/Upload.js +84 -87
- package/upload/Uploader.js +115 -118
- package/upload/list/PictureItem.js +61 -71
- package/upload/list/TextItem.js +61 -67
- package/upload/list/UploadProgress.js +42 -49
- package/upload/list/index.js +48 -49
- package/upload/request_.js +37 -38
- package/upload/util.js +39 -39
- package/utils/convertToDurationBasedOnTimeUnits.js +6 -0
- package/utils/findScrollParent.js +4 -0
- package/utils/index.js +281 -278
- package/utils/intersectionObserver.js +4 -0
- package/utils/mutationObserver.js +4 -0
- package/utils/names.js +12 -0
- package/utils/resizeObserver.js +4 -0
- package/verification-code/VerificationCode.js +50 -51
- package/version/index.js +1 -1
- package/virtual-list/VirtualList.js +243 -244
- package/virtual-list/util/item.js +3 -4
- package/watermark/Watermark.js +27 -31
- package/components/common/utils/resizeObserverEffect.js +0 -23
- package/types/common/utils/resizeObserverEffect.d.ts +0 -2
- package/types/pc/utils/resizeObserverEffect.d.ts +0 -2
- package/utils/resizeObserverEffect.js +0 -4
package/form/Control.js
CHANGED
|
@@ -1,192 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import V from "lodash/
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import F from "
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
213
|
-
return t.map((
|
|
214
|
-
|
|
215
|
-
}), Array.from(new Set(
|
|
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:
|
|
221
|
-
trigger:
|
|
222
|
-
triggerPropName:
|
|
223
|
-
validateStatus:
|
|
224
|
-
formatter:
|
|
225
|
-
} = this.props, { store:
|
|
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:
|
|
204
|
+
id: P(h.props?.id || { [`${t}${L}`]: t })
|
|
228
205
|
};
|
|
229
|
-
this.getValidateTrigger().forEach((
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
}),
|
|
235
|
-
let
|
|
236
|
-
return
|
|
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:
|
|
240
|
-
let
|
|
241
|
-
const
|
|
242
|
-
return this.hasFieldProps() && !
|
|
243
|
-
|
|
244
|
-
|
|
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: `${
|
|
237
|
+
className: `${o}-item-feedback ${o}-item-feedback-${i}`,
|
|
248
238
|
children: [
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
|
|
250
|
+
re as default
|
|
265
251
|
};
|