@qsxy/element-plus-react 1.0.0-next.10 → 1.0.0-next.11
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/dist/Avatar/Avatar.js +73 -72
- package/dist/Avatar/index.js +1 -39
- package/dist/Avatar/typings.js +1 -17
- package/dist/Badge/Badge.d.ts +2 -2
- package/dist/Badge/Badge.js +63 -60
- package/dist/Badge/index.js +1 -39
- package/dist/Badge/typings.d.ts +1 -1
- package/dist/Badge/typings.js +1 -17
- package/dist/Breadcrumb/Breadcrumb.js +23 -50
- package/dist/Breadcrumb/BreadcrumbItem.js +45 -51
- package/dist/Breadcrumb/index.js +2 -42
- package/dist/Breadcrumb/typings.js +1 -17
- package/dist/Button/Button.js +132 -105
- package/dist/Button/ButtonGroup.js +29 -48
- package/dist/Button/ButtonGroupContext.js +2 -30
- package/dist/Button/index.js +2 -42
- package/dist/Button/typings.d.ts +4 -2
- package/dist/Button/typings.js +1 -17
- package/dist/Button/useButtonCustomStyle.d.ts +4 -0
- package/dist/Button/useButtonCustomStyle.js +65 -0
- package/dist/Calendar/Calendar.js +310 -237
- package/dist/Calendar/CalendarContext.js +3 -27
- package/dist/Calendar/DatePanel.js +191 -158
- package/dist/Calendar/DateRangePanel.js +140 -125
- package/dist/Calendar/Footer.js +41 -51
- package/dist/Calendar/Header.js +83 -65
- package/dist/Calendar/MonthPanel.js +138 -124
- package/dist/Calendar/MonthRangePanel.js +137 -124
- package/dist/Calendar/ShortCuts.js +21 -40
- package/dist/Calendar/WeekPanel.js +213 -145
- package/dist/Calendar/YearPanel.js +150 -125
- package/dist/Calendar/YearRangePanel.js +138 -128
- package/dist/Calendar/index.js +4 -47
- package/dist/Calendar/typings.js +1 -17
- package/dist/Calendar/util.js +26 -68
- package/dist/Card/Card.js +36 -46
- package/dist/Card/index.js +1 -39
- package/dist/Card/typings.js +1 -17
- package/dist/Carousel/Carousel.js +202 -166
- package/dist/Carousel/CarouselContext.js +14 -42
- package/dist/Carousel/CarouselItem.js +55 -71
- package/dist/Carousel/hooks/useCarousel.js +263 -238
- package/dist/Carousel/hooks/useCarouselItem.js +136 -132
- package/dist/Carousel/index.js +2 -42
- package/dist/Carousel/typings.js +1 -17
- package/dist/Cascader/Cascader.js +693 -569
- package/dist/Cascader/CascaderContext.js +9 -45
- package/dist/Cascader/CascaderDropdown.js +90 -77
- package/dist/Cascader/CascaderMenu.js +101 -114
- package/dist/Cascader/Utils.js +6 -33
- package/dist/Cascader/index.js +1 -39
- package/dist/Cascader/typings.d.ts +1 -1
- package/dist/Cascader/typings.js +1 -17
- package/dist/Cascader/useCascader.js +648 -458
- package/dist/Checkbox/Checkbox.d.ts +3 -3
- package/dist/Checkbox/Checkbox.js +136 -161
- package/dist/Checkbox/CheckboxButton.js +132 -157
- package/dist/Checkbox/index.js +2 -42
- package/dist/Checkbox/typings.d.ts +1 -1
- package/dist/Checkbox/typings.js +1 -17
- package/dist/CheckboxGroup/CheckboxGroup.js +133 -112
- package/dist/CheckboxGroup/CheckboxGroupContext.js +2 -30
- package/dist/CheckboxGroup/index.js +2 -42
- package/dist/Col/Col.js +53 -72
- package/dist/Col/index.js +1 -39
- package/dist/Col/typings.js +1 -17
- package/dist/Collapse/Collapse.js +36 -45
- package/dist/Collapse/CollapseContext.js +3 -31
- package/dist/Collapse/CollapseItem.js +88 -73
- package/dist/Collapse/CollapseTransition.js +29 -67
- package/dist/Collapse/index.js +2 -42
- package/dist/Collapse/typings.js +1 -17
- package/dist/ColorPicker/AlphaSlider.js +117 -99
- package/dist/ColorPicker/ColorPicker.d.ts +1 -1
- package/dist/ColorPicker/ColorPicker.js +233 -189
- package/dist/ColorPicker/HueSlider.js +102 -96
- package/dist/ColorPicker/Predefine.js +65 -66
- package/dist/ColorPicker/SvPanel.js +95 -81
- package/dist/ColorPicker/color.js +301 -213
- package/dist/ColorPicker/draggable.js +30 -48
- package/dist/ColorPicker/index.js +1 -39
- package/dist/ColorPicker/typings.js +1 -17
- package/dist/ColorPicker/util.js +23 -60
- package/dist/ConfigProvider/ConfigProvider.js +4 -28
- package/dist/ConfigProvider/index.js +1 -39
- package/dist/DatePicker/DatePicker.d.ts +3 -3
- package/dist/DatePicker/DatePicker.js +251 -227
- package/dist/DatePicker/DateRangePicker.d.ts +3 -3
- package/dist/DatePicker/DateRangePicker.js +279 -276
- package/dist/DatePicker/index.js +2 -39
- package/dist/DatePicker/main.d.ts +2 -2
- package/dist/DatePicker/main.js +21 -44
- package/dist/DatePicker/typings.d.ts +24 -17
- package/dist/DatePicker/typings.js +1 -17
- package/dist/DateTimePicker/DateTimePicker.d.ts +3 -5
- package/dist/DateTimePicker/DateTimePicker.js +286 -215
- package/dist/DateTimePicker/index.js +1 -39
- package/dist/DateTimePicker/typings.d.ts +10 -13
- package/dist/DateTimePicker/typings.js +1 -17
- package/dist/DateTimePicker/util.js +5 -35
- package/dist/Descriptions/Descriptions.js +83 -63
- package/dist/Descriptions/DescriptionsCell.js +67 -79
- package/dist/Descriptions/DescriptionsContext.js +4 -32
- package/dist/Descriptions/DescriptionsItem.js +4 -27
- package/dist/Descriptions/DescriptionsRow.js +42 -44
- package/dist/Descriptions/index.js +2 -42
- package/dist/Descriptions/typings.js +1 -17
- package/dist/Dialog/Dialog.js +224 -176
- package/dist/Dialog/DialogBody.js +52 -59
- package/dist/Dialog/DialogContext.js +6 -44
- package/dist/Dialog/DialogFooter.js +21 -45
- package/dist/Dialog/DialogHeader.js +44 -50
- package/dist/Dialog/index.js +1 -39
- package/dist/Dialog/typings.d.ts +1 -1
- package/dist/Dialog/typings.js +1 -17
- package/dist/Dialog/useDraggable.js +52 -79
- package/dist/Divider/Divider.d.ts +3 -3
- package/dist/Divider/Divider.js +38 -44
- package/dist/Divider/index.js +1 -39
- package/dist/Drawer/Drawer.js +144 -136
- package/dist/Drawer/DrawerBody.js +35 -57
- package/dist/Drawer/DrawerContext.js +13 -44
- package/dist/Drawer/DrawerFooter.js +22 -43
- package/dist/Drawer/DrawerHeader.js +41 -48
- package/dist/Drawer/index.js +1 -39
- package/dist/Drawer/typings.js +1 -17
- package/dist/Dropdown/Dropdown.js +89 -107
- package/dist/Dropdown/DropdownContext.js +5 -43
- package/dist/Dropdown/DropdownItem.js +40 -60
- package/dist/Dropdown/DropdownMenu.js +28 -56
- package/dist/Dropdown/index.js +3 -45
- package/dist/Dropdown/typings.js +1 -17
- package/dist/Empty/Empty.js +32 -53
- package/dist/Empty/ImgEmpty.js +115 -117
- package/dist/Empty/index.js +1 -39
- package/dist/Form/FieldContext.js +8 -37
- package/dist/Form/Form.js +167 -162
- package/dist/Form/FormContext.js +58 -97
- package/dist/Form/FormItem.js +620 -352
- package/dist/Form/FormItemContext.js +3 -31
- package/dist/Form/List.js +121 -104
- package/dist/Form/ListContext.js +3 -27
- package/dist/Form/index.js +3 -45
- package/dist/Form/typings.d.ts +25 -4
- package/dist/Form/typings.js +1 -17
- package/dist/Form/useForm.js +830 -690
- package/dist/Form/useWatch.js +64 -79
- package/dist/Form/utils/NameMap.js +98 -69
- package/dist/Form/utils/asyncUtil.js +9 -37
- package/dist/Form/utils/classUtil.js +26 -48
- package/dist/Form/utils/cloneDeep.js +8 -29
- package/dist/Form/utils/get.js +6 -30
- package/dist/Form/utils/messages.js +25 -53
- package/dist/Form/utils/set.js +31 -44
- package/dist/Form/utils/typeUtil.js +3 -31
- package/dist/Form/utils/util.js +18 -55
- package/dist/Form/utils/validateUtil.js +284 -159
- package/dist/Form/utils/valueUtil.js +102 -107
- package/dist/Icon/Icon.js +39 -63
- package/dist/Icon/IconList/Check.js +25 -65
- package/dist/Icon/IconList/Close.js +23 -52
- package/dist/Icon/IconList/Delete.js +25 -65
- package/dist/Icon/IconList/Down.js +25 -65
- package/dist/Icon/IconList/Eye.js +25 -65
- package/dist/Icon/IconList/EyeClose.js +25 -65
- package/dist/Icon/IconList/Left.js +25 -65
- package/dist/Icon/IconList/Link.js +19 -55
- package/dist/Icon/IconList/More.js +25 -65
- package/dist/Icon/IconList/Question.js +25 -65
- package/dist/Icon/IconList/Right.js +25 -65
- package/dist/Icon/IconList/Search.js +25 -65
- package/dist/Icon/IconList/Up.js +25 -65
- package/dist/Icon/IconList/Upload.js +25 -65
- package/dist/Icon/IconList/index.js +14 -68
- package/dist/Icon/index.js +2 -42
- package/dist/Icon/typings.js +1 -17
- package/dist/Input/Input.js +334 -358
- package/dist/Input/InputGroup.js +27 -43
- package/dist/Input/InputRange.js +295 -308
- package/dist/Input/TextArea.js +129 -120
- package/dist/Input/index.js +3 -45
- package/dist/Input/typings.js +1 -17
- package/dist/InputNumber/InputNumber.js +219 -203
- package/dist/InputNumber/index.js +1 -39
- package/dist/InputNumber/typings.d.ts +1 -1
- package/dist/InputNumber/typings.js +1 -17
- package/dist/Link/Link.js +43 -60
- package/dist/Link/index.js +1 -39
- package/dist/Link/typings.js +1 -17
- package/dist/Loading/Loading.js +93 -66
- package/dist/Loading/index.js +1 -39
- package/dist/Loading/typings.js +1 -17
- package/dist/Message/Main.js +41 -66
- package/dist/Message/Message.js +167 -130
- package/dist/Message/index.js +68 -88
- package/dist/Message/typings.js +1 -17
- package/dist/MessageBox/Main.js +43 -68
- package/dist/MessageBox/MessageBox.js +253 -202
- package/dist/MessageBox/index.js +74 -79
- package/dist/MessageBox/typings.js +1 -17
- package/dist/Notification/Main.js +41 -66
- package/dist/Notification/Notification.js +148 -131
- package/dist/Notification/index.js +76 -92
- package/dist/Notification/typings.js +1 -17
- package/dist/Pagination/Options.js +104 -99
- package/dist/Pagination/Pager.js +30 -61
- package/dist/Pagination/Pagination.js +462 -380
- package/dist/Pagination/index.js +1 -39
- package/dist/Pagination/typings.js +1 -17
- package/dist/Pagination/util.js +10 -41
- package/dist/Popconfirm/Popconfirm.js +108 -116
- package/dist/Popconfirm/index.js +1 -39
- package/dist/Popconfirm/typings.js +1 -17
- package/dist/Popover/Popover.js +87 -89
- package/dist/Popover/index.js +1 -39
- package/dist/Popover/typings.js +1 -17
- package/dist/Popper/Popper.js +172 -149
- package/dist/Popper/index.js +1 -39
- package/dist/Popper/popperOptions.js +79 -90
- package/dist/Popper/typings.js +1 -17
- package/dist/Progress/Progress.js +186 -155
- package/dist/Progress/index.js +1 -39
- package/dist/Progress/typings.js +1 -17
- package/dist/Radio/Radio.js +158 -117
- package/dist/Radio/RadioButton.js +127 -117
- package/dist/Radio/index.js +1 -39
- package/dist/Radio/typings.js +1 -17
- package/dist/RadioGroup/RadioGroup.js +63 -78
- package/dist/RadioGroup/index.js +1 -39
- package/dist/RadioGroup/typings.js +1 -17
- package/dist/Row/Row.js +41 -62
- package/dist/Row/RowContext.js +3 -31
- package/dist/Row/index.js +2 -42
- package/dist/Row/typings.js +1 -17
- package/dist/Scrollbar/Scrollbar.js +172 -133
- package/dist/Scrollbar/Thumb.js +108 -96
- package/dist/Scrollbar/index.js +1 -39
- package/dist/Scrollbar/typings.d.ts +11 -2
- package/dist/Scrollbar/typings.js +1 -17
- package/dist/Scrollbar/util.js +24 -51
- package/dist/Select/Option.js +50 -75
- package/dist/Select/OptionGroup.js +31 -47
- package/dist/Select/Select.js +25 -48
- package/dist/Select/SelectContext.js +8 -46
- package/dist/Select/SelectCore.js +449 -377
- package/dist/Select/SelectDropdown.js +200 -160
- package/dist/Select/index.js +2 -42
- package/dist/Select/typings.d.ts +1 -1
- package/dist/Select/typings.js +1 -17
- package/dist/Skeleton/PlaceholderGraph.js +39 -45
- package/dist/Skeleton/PlaceholderGrid.js +55 -67
- package/dist/Skeleton/PlaceholderParagraph.js +51 -52
- package/dist/Skeleton/Skeleton.js +8 -42
- package/dist/Skeleton/index.js +1 -39
- package/dist/Switch/Switch.js +177 -154
- package/dist/Switch/index.js +1 -39
- package/dist/Switch/typings.js +1 -17
- package/dist/Table/Colgroup.js +17 -41
- package/dist/Table/Table.js +246 -188
- package/dist/Table/TableBody.js +265 -200
- package/dist/Table/TableCell.js +461 -320
- package/dist/Table/TableColumn.js +9 -43
- package/dist/Table/TableContext.js +44 -63
- package/dist/Table/TableHeader.js +112 -102
- package/dist/Table/TableHeaderCell.js +211 -158
- package/dist/Table/hooks/useResize.js +69 -83
- package/dist/Table/hooks/useScroll.js +88 -114
- package/dist/Table/hooks/useSelection.js +145 -110
- package/dist/Table/hooks/useTable.js +411 -309
- package/dist/Table/index.js +2 -42
- package/dist/Table/treeUtil.js +99 -77
- package/dist/Table/typings.js +1 -17
- package/dist/Table/util.js +168 -109
- package/dist/Tabs/TabPane.js +51 -53
- package/dist/Tabs/Tabs.js +277 -178
- package/dist/Tabs/TabsContext.js +4 -32
- package/dist/Tabs/index.js +2 -42
- package/dist/Tabs/typings.js +1 -17
- package/dist/Tag/Tag.js +75 -74
- package/dist/Tag/index.js +1 -39
- package/dist/Tag/typings.js +1 -17
- package/dist/TimeLine/TimeLine.js +13 -42
- package/dist/TimeLine/TimeLineItem.js +66 -54
- package/dist/TimeLine/index.js +2 -42
- package/dist/TimeLine/typings.js +1 -17
- package/dist/TimePicker/TimePicker.d.ts +1 -4
- package/dist/TimePicker/TimePicker.js +275 -215
- package/dist/TimePicker/TimePickerPanel.js +62 -71
- package/dist/TimePicker/TimePickerRange.d.ts +4 -4
- package/dist/TimePicker/TimePickerRange.js +371 -334
- package/dist/TimePicker/TimeRangePanel.js +182 -165
- package/dist/TimePicker/TimeSpinnerPanel.js +321 -267
- package/dist/TimePicker/index.d.ts +2 -3
- package/dist/TimePicker/index.js +1 -42
- package/dist/TimePicker/main.d.ts +9 -0
- package/dist/TimePicker/main.js +17 -0
- package/dist/TimePicker/typings.d.ts +29 -24
- package/dist/TimePicker/typings.js +1 -17
- package/dist/TimePicker/useTimePicker.js +62 -65
- package/dist/TimePicker/util.js +8 -40
- package/dist/Tooltip/Tooltip.js +172 -180
- package/dist/Tooltip/TooltipContext.js +8 -46
- package/dist/Tooltip/index.js +2 -42
- package/dist/Tooltip/typings.js +1 -17
- package/dist/Transfer/List.js +290 -241
- package/dist/Transfer/ListBody.js +92 -106
- package/dist/Transfer/ListItem.js +38 -51
- package/dist/Transfer/Transfer.js +323 -280
- package/dist/Transfer/index.js +1 -39
- package/dist/Transfer/interface.js +1 -17
- package/dist/Transfer/operation.js +35 -48
- package/dist/Transfer/search.js +30 -62
- package/dist/Transfer/typings/index.js +1 -17
- package/dist/Transfer/typings/list.js +1 -17
- package/dist/Transfer/typings/listBody.js +2 -30
- package/dist/Transition/Transition.js +271 -234
- package/dist/Transition/TransitionGroup.js +136 -88
- package/dist/Transition/TransitionGroupContext.js +2 -26
- package/dist/Transition/childMapping.js +84 -71
- package/dist/Transition/index.js +2 -42
- package/dist/Transition/util.d.ts +0 -1
- package/dist/Transition/util.js +6 -47
- package/dist/Tree/DirectoryTree.js +146 -118
- package/dist/Tree/DropIndicator.js +15 -45
- package/dist/Tree/Indent.js +23 -54
- package/dist/Tree/MotionTreeNode.js +94 -95
- package/dist/Tree/NodeList.js +228 -221
- package/dist/Tree/RCTree.js +969 -702
- package/dist/Tree/Tree.js +64 -79
- package/dist/Tree/TreeNode.js +254 -255
- package/dist/Tree/contextTypes.js +8 -42
- package/dist/Tree/index.js +4 -48
- package/dist/Tree/typings.js +1 -17
- package/dist/Tree/useUnmount.js +21 -41
- package/dist/Tree/util.js +156 -134
- package/dist/Tree/utils/conductUtil.js +113 -104
- package/dist/Tree/utils/dictUtil.js +50 -78
- package/dist/Tree/utils/diffUtil.js +26 -43
- package/dist/Tree/utils/dropIndicator.js +23 -51
- package/dist/Tree/utils/iconUtil.js +44 -51
- package/dist/Tree/utils/keyUtil.js +2 -26
- package/dist/Tree/utils/motion.js +34 -72
- package/dist/Tree/utils/pickAttrs.js +30 -58
- package/dist/Tree/utils/treeUtil.js +263 -203
- package/dist/TreeSelect/TreeSelect.js +521 -459
- package/dist/TreeSelect/Utils.js +15 -36
- package/dist/TreeSelect/index.js +1 -39
- package/dist/TreeSelect/typings.d.ts +1 -1
- package/dist/TreeSelect/typings.js +1 -17
- package/dist/Upload/Upload.js +106 -109
- package/dist/Upload/UploadContent.js +227 -182
- package/dist/Upload/UploadContext.js +5 -33
- package/dist/Upload/UploadDrag.js +77 -97
- package/dist/Upload/UploadList.js +104 -73
- package/dist/Upload/ajax.js +45 -71
- package/dist/Upload/index.js +1 -39
- package/dist/Upload/typings.js +34 -36
- package/dist/Upload/use-handlers.js +182 -126
- package/dist/Util/Math.js +81 -78
- package/dist/Util/PopupManager.js +5 -27
- package/dist/Util/base.js +101 -171
- package/dist/Util/genFileId.js +3 -29
- package/dist/Util/index.js +6 -51
- package/dist/Util/resize-event.js +31 -54
- package/dist/Util/shallowEqual.js +30 -28
- package/dist/Util/treeUtils.js +68 -64
- package/dist/config/Constants.js +17 -47
- package/dist/display.css +1 -0
- package/dist/hooks/animationPropsUtils.js +25 -49
- package/dist/hooks/htmlPropsUtils.js +54 -121
- package/dist/hooks/index.js +14 -73
- package/dist/hooks/popperPropsUtils.js +25 -67
- package/dist/hooks/prefix.js +22 -55
- package/dist/hooks/treePropsUtils.js +24 -103
- package/dist/hooks/useChildrenInstance.js +51 -60
- package/dist/hooks/useClassNames.d.ts +2 -0
- package/dist/hooks/useClassNames.js +279 -197
- package/dist/hooks/useClickOutside.js +37 -62
- package/dist/hooks/useCommonProps.js +17 -53
- package/dist/hooks/useComponentWillMount.js +4 -28
- package/dist/hooks/useControlled.js +31 -37
- package/dist/hooks/useForceUpdate.js +16 -34
- package/dist/hooks/useUpdateEffect.js +6 -29
- package/dist/index.css +1 -57810
- package/dist/index.d.ts +0 -2
- package/dist/index.js +69 -237
- package/dist/theme-chalk/common/index.js +1 -2
- package/dist/theme-chalk/common/index.scss +2 -2
- package/dist/theme-chalk/date-picker/index.scss +1 -1
- package/dist/theme-chalk/display.scss +46 -0
- package/dist/theme-chalk/form/index.scss +21 -2
- package/dist/types/common.js +1 -17
- package/dist/types/type.js +16 -28
- package/package.json +6 -1
- package/theme-chalk/common/index.scss +2 -2
- package/theme-chalk/date-picker/index.scss +1 -1
- package/theme-chalk/display.scss +46 -0
- package/theme-chalk/form/index.scss +21 -2
package/dist/Form/useForm.js
CHANGED
|
@@ -1,751 +1,891 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
isFieldsTouched: this.isFieldsTouched,
|
|
64
|
-
isFieldTouched: this.isFieldTouched,
|
|
65
|
-
isFieldValidating: this.isFieldValidating,
|
|
66
|
-
isFieldsValidating: this.isFieldsValidating,
|
|
67
|
-
resetFields: this.resetFields,
|
|
68
|
-
setFields: this.setFields,
|
|
69
|
-
setFieldValue: this.setFieldValue,
|
|
70
|
-
setFieldsValue: this.setFieldsValue,
|
|
71
|
-
validateFields: this.validateFields,
|
|
72
|
-
submit: this.submit,
|
|
1
|
+
var _excluded = ["name", "errors"];
|
|
2
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
8
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
9
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
10
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
13
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
14
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
18
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
19
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
22
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23
|
+
import { useRef, useState } from 'react';
|
|
24
|
+
import scrollIntoView from 'scroll-into-view-if-needed';
|
|
25
|
+
import { warning } from "../Util";
|
|
26
|
+
import { HOOK_MARK } from "./FieldContext";
|
|
27
|
+
import NameMap from "./utils/NameMap";
|
|
28
|
+
import { allPromiseFinish } from "./utils/asyncUtil";
|
|
29
|
+
import cloneDeep from "./utils/cloneDeep";
|
|
30
|
+
import { defaultValidateMessages } from "./utils/messages";
|
|
31
|
+
import { toArray } from "./utils/typeUtil";
|
|
32
|
+
import { cloneByNamePathList, containsNamePath, getNamePath, getValue, matchNamePath, setValue, setValues } from "./utils/valueUtil";
|
|
33
|
+
export var FormStore = /*#__PURE__*/_createClass(function FormStore(forceRootUpdate) {
|
|
34
|
+
var _this = this;
|
|
35
|
+
_classCallCheck(this, FormStore);
|
|
36
|
+
_defineProperty(this, "formHooked", false);
|
|
37
|
+
_defineProperty(this, "forceRootUpdate", void 0);
|
|
38
|
+
_defineProperty(this, "subscribable", true);
|
|
39
|
+
_defineProperty(this, "store", {});
|
|
40
|
+
_defineProperty(this, "fieldEntities", []);
|
|
41
|
+
_defineProperty(this, "initialValues", {});
|
|
42
|
+
_defineProperty(this, "callbacks", {});
|
|
43
|
+
_defineProperty(this, "validateMessages", null);
|
|
44
|
+
_defineProperty(this, "preserve", null);
|
|
45
|
+
_defineProperty(this, "lastValidatePromise", null);
|
|
46
|
+
_defineProperty(this, "getForm", function () {
|
|
47
|
+
return {
|
|
48
|
+
getFieldValue: _this.getFieldValue,
|
|
49
|
+
getFieldsValue: _this.getFieldsValue,
|
|
50
|
+
getFieldError: _this.getFieldError,
|
|
51
|
+
getFieldWarning: _this.getFieldWarning,
|
|
52
|
+
getFieldsError: _this.getFieldsError,
|
|
53
|
+
isFieldsTouched: _this.isFieldsTouched,
|
|
54
|
+
isFieldTouched: _this.isFieldTouched,
|
|
55
|
+
isFieldValidating: _this.isFieldValidating,
|
|
56
|
+
isFieldsValidating: _this.isFieldsValidating,
|
|
57
|
+
resetFields: _this.resetFields,
|
|
58
|
+
setFields: _this.setFields,
|
|
59
|
+
setFieldValue: _this.setFieldValue,
|
|
60
|
+
setFieldsValue: _this.setFieldsValue,
|
|
61
|
+
validateFields: _this.validateFields,
|
|
62
|
+
submit: _this.submit,
|
|
73
63
|
_init: true,
|
|
74
|
-
scrollToField:
|
|
75
|
-
getInternalHooks:
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
64
|
+
scrollToField: _this.scrollToField,
|
|
65
|
+
getInternalHooks: _this.getInternalHooks
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
_defineProperty(this, "scrollToField", function (name) {
|
|
69
|
+
var _this$getFieldsMap$ge;
|
|
70
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
71
|
+
var namePath = toArray(name);
|
|
72
|
+
var node = (_this$getFieldsMap$ge = _this.getFieldsMap().get(namePath)) === null || _this$getFieldsMap$ge === void 0 ? void 0 : _this$getFieldsMap$ge.containerRef;
|
|
73
|
+
if (node.current) {
|
|
74
|
+
scrollIntoView(node.current, _objectSpread({
|
|
75
|
+
scrollMode: 'if-needed',
|
|
76
|
+
block: 'center'
|
|
77
|
+
}, options));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
// ======================== Internal Hooks ========================
|
|
81
|
+
_defineProperty(this, "getInternalHooks", function (key) {
|
|
82
|
+
if (key === HOOK_MARK) {
|
|
83
|
+
_this.formHooked = true;
|
|
84
|
+
return {
|
|
85
|
+
dispatch: _this.dispatch,
|
|
86
|
+
initEntityValue: _this.initEntityValue,
|
|
87
|
+
registerField: _this.registerField,
|
|
88
|
+
useSubscribe: _this.useSubscribe,
|
|
89
|
+
setInitialValues: _this.setInitialValues,
|
|
90
|
+
destroyForm: _this.destroyForm,
|
|
91
|
+
setCallbacks: _this.setCallbacks,
|
|
92
|
+
setValidateMessages: _this.setValidateMessages,
|
|
93
|
+
getFields: _this.getFields,
|
|
94
|
+
setPreserve: _this.setPreserve,
|
|
95
|
+
getInitialValue: _this.getInitialValue,
|
|
96
|
+
registerWatch: _this.registerWatch
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
warning(false, '`getInternalHooks` is internal usage. Should not call directly.');
|
|
100
|
+
return null;
|
|
101
|
+
});
|
|
102
|
+
_defineProperty(this, "useSubscribe", function (subscribable) {
|
|
103
|
+
_this.subscribable = subscribable;
|
|
104
|
+
});
|
|
105
|
+
/**
|
|
106
|
+
* Record prev Form unmount fieldEntities which config preserve false.
|
|
107
|
+
* This need to be refill with initialValues instead of store value.
|
|
108
|
+
*/
|
|
109
|
+
_defineProperty(this, "prevWithoutPreserves", null);
|
|
110
|
+
/**
|
|
111
|
+
* First time `setInitialValues` should update store with initial value
|
|
112
|
+
*/
|
|
113
|
+
_defineProperty(this, "setInitialValues", function (initialValues, init) {
|
|
114
|
+
_this.initialValues = initialValues || {};
|
|
115
|
+
if (init) {
|
|
116
|
+
var _this$prevWithoutPres;
|
|
117
|
+
var nextStore = setValues({}, initialValues, _this.store);
|
|
118
|
+
|
|
119
|
+
// We will take consider prev form unmount fields.
|
|
120
|
+
// When the field is not `preserve`, we need fill this with initialValues instead of store.
|
|
121
|
+
// eslint-disable-next-line array-callback-return
|
|
122
|
+
(_this$prevWithoutPres = _this.prevWithoutPreserves) === null || _this$prevWithoutPres === void 0 || _this$prevWithoutPres.map(function (_ref) {
|
|
123
|
+
var namePath = _ref.key;
|
|
124
|
+
nextStore = setValue(nextStore, namePath, getValue(initialValues, namePath));
|
|
125
|
+
});
|
|
126
|
+
_this.prevWithoutPreserves = null;
|
|
127
|
+
_this.updateStore(nextStore);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
_defineProperty(this, "destroyForm", function () {
|
|
131
|
+
var prevWithoutPreserves = new NameMap();
|
|
132
|
+
_this.getFieldEntities(true).forEach(function (entity) {
|
|
133
|
+
if (!_this.isMergedPreserve(entity.isPreserve())) {
|
|
134
|
+
prevWithoutPreserves.set(entity.getNamePath(), true);
|
|
132
135
|
}
|
|
136
|
+
});
|
|
137
|
+
_this.prevWithoutPreserves = prevWithoutPreserves;
|
|
138
|
+
});
|
|
139
|
+
_defineProperty(this, "getInitialValue", function (namePath) {
|
|
140
|
+
var initValue = getValue(_this.initialValues, namePath);
|
|
141
|
+
|
|
142
|
+
// Not cloneDeep when without `namePath`
|
|
143
|
+
return namePath.length ? cloneDeep(initValue) : initValue;
|
|
144
|
+
});
|
|
145
|
+
_defineProperty(this, "setCallbacks", function (callbacks) {
|
|
146
|
+
_this.callbacks = callbacks;
|
|
147
|
+
});
|
|
148
|
+
_defineProperty(this, "setValidateMessages", function (validateMessages) {
|
|
149
|
+
_this.validateMessages = validateMessages;
|
|
150
|
+
});
|
|
151
|
+
_defineProperty(this, "setPreserve", function (preserve) {
|
|
152
|
+
_this.preserve = preserve;
|
|
153
|
+
});
|
|
154
|
+
// ============================= Watch ============================
|
|
155
|
+
_defineProperty(this, "watchList", []);
|
|
156
|
+
_defineProperty(this, "registerWatch", function (callback) {
|
|
157
|
+
_this.watchList.push(callback);
|
|
158
|
+
return function () {
|
|
159
|
+
_this.watchList = _this.watchList.filter(function (fn) {
|
|
160
|
+
return fn !== callback;
|
|
161
|
+
});
|
|
133
162
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
163
|
+
});
|
|
164
|
+
_defineProperty(this, "notifyWatch", function () {
|
|
165
|
+
var namePath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
166
|
+
// No need to cost perf when nothing need to watch
|
|
167
|
+
if (_this.watchList.length) {
|
|
168
|
+
var values = _this.getFieldsValue();
|
|
169
|
+
_this.watchList.forEach(function (callback) {
|
|
170
|
+
callback(values, namePath);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
// ========================== Dev Warning =========================
|
|
175
|
+
_defineProperty(this, "timeoutId", null);
|
|
176
|
+
_defineProperty(this, "warningUnhooked", function () {
|
|
177
|
+
if (process.env.NODE_ENV !== 'production' && !_this.timeoutId && typeof window !== 'undefined') {
|
|
178
|
+
_this.timeoutId = setTimeout(function () {
|
|
179
|
+
_this.timeoutId = null;
|
|
180
|
+
if (!_this.formHooked) {
|
|
181
|
+
warning(false, 'Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?');
|
|
139
182
|
}
|
|
140
183
|
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
// ============================ Store =============================
|
|
187
|
+
_defineProperty(this, "updateStore", function (nextStore) {
|
|
188
|
+
_this.store = nextStore;
|
|
189
|
+
});
|
|
190
|
+
// ============================ Fields ============================
|
|
191
|
+
/**
|
|
192
|
+
* Get registered field entities.
|
|
193
|
+
* @param pure Only return field which has a `name`. Default: false
|
|
194
|
+
*/
|
|
195
|
+
_defineProperty(this, "getFieldEntities", function () {
|
|
196
|
+
var pure = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
197
|
+
if (!pure) {
|
|
198
|
+
return _this.fieldEntities;
|
|
199
|
+
}
|
|
200
|
+
return _this.fieldEntities.filter(function (field) {
|
|
201
|
+
return field.getNamePath().length;
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
_defineProperty(this, "getFieldsMap", function () {
|
|
205
|
+
var pure = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
206
|
+
var cache = new NameMap();
|
|
207
|
+
_this.getFieldEntities(pure).forEach(function (field) {
|
|
208
|
+
var namePath = field.getNamePath();
|
|
209
|
+
cache.set(namePath, field);
|
|
210
|
+
});
|
|
211
|
+
return cache;
|
|
212
|
+
});
|
|
213
|
+
_defineProperty(this, "getFieldEntitiesForNamePathList", function (nameList) {
|
|
214
|
+
if (!nameList) {
|
|
215
|
+
return _this.getFieldEntities(true);
|
|
216
|
+
}
|
|
217
|
+
var cache = _this.getFieldsMap(true);
|
|
218
|
+
return nameList.map(function (name) {
|
|
219
|
+
var namePath = getNamePath(name);
|
|
220
|
+
return cache.get(namePath) || {
|
|
221
|
+
INVALIDATE_NAME_PATH: getNamePath(name)
|
|
162
222
|
};
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
_defineProperty(this, "getFieldsValue", function (nameList, filterFunc) {
|
|
226
|
+
_this.warningUnhooked();
|
|
227
|
+
if (nameList === true && !filterFunc) {
|
|
228
|
+
return _this.store;
|
|
229
|
+
}
|
|
230
|
+
var fieldEntities = _this.getFieldEntitiesForNamePathList(Array.isArray(nameList) ? nameList : null);
|
|
231
|
+
var filteredNameList = [];
|
|
232
|
+
fieldEntities.forEach(function (entity) {
|
|
233
|
+
var _isListField, _ref2;
|
|
234
|
+
var namePath = 'INVALIDATE_NAME_PATH' in entity ? entity.INVALIDATE_NAME_PATH : entity.getNamePath();
|
|
235
|
+
|
|
236
|
+
// Ignore when it's a list item and not specific the namePath,
|
|
237
|
+
// since parent field is already take in count
|
|
238
|
+
if (!nameList && (_isListField = (_ref2 = entity).isListField) !== null && _isListField !== void 0 && _isListField.call(_ref2)) {
|
|
239
|
+
return;
|
|
170
240
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (!this.formHooked) {
|
|
179
|
-
(0, import_Util.warning)(false, "Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?");
|
|
180
|
-
}
|
|
181
|
-
});
|
|
241
|
+
if (!filterFunc) {
|
|
242
|
+
filteredNameList.push(namePath);
|
|
243
|
+
} else {
|
|
244
|
+
var _meta = 'getMeta' in entity ? entity.getMeta() : null;
|
|
245
|
+
if (filterFunc(_meta)) {
|
|
246
|
+
filteredNameList.push(namePath);
|
|
247
|
+
}
|
|
182
248
|
}
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
249
|
+
});
|
|
250
|
+
return cloneByNamePathList(_this.store, filteredNameList.map(getNamePath));
|
|
251
|
+
});
|
|
252
|
+
_defineProperty(this, "getFieldValue", function (name) {
|
|
253
|
+
_this.warningUnhooked();
|
|
254
|
+
var namePath = getNamePath(name);
|
|
255
|
+
return getValue(_this.store, namePath);
|
|
256
|
+
});
|
|
257
|
+
_defineProperty(this, "getFieldsError", function (nameList) {
|
|
258
|
+
_this.warningUnhooked();
|
|
259
|
+
var fieldEntities = _this.getFieldEntitiesForNamePathList(nameList);
|
|
260
|
+
return fieldEntities.map(function (entity, index) {
|
|
261
|
+
if (entity && !('INVALIDATE_NAME_PATH' in entity)) {
|
|
262
|
+
return {
|
|
263
|
+
name: entity.getNamePath(),
|
|
264
|
+
errors: entity.getErrors(),
|
|
265
|
+
warnings: entity.getWarnings()
|
|
266
|
+
};
|
|
196
267
|
}
|
|
197
|
-
return
|
|
268
|
+
return {
|
|
269
|
+
name: getNamePath(nameList[index]),
|
|
270
|
+
errors: [],
|
|
271
|
+
warnings: []
|
|
272
|
+
};
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
_defineProperty(this, "getFieldError", function (name) {
|
|
276
|
+
_this.warningUnhooked();
|
|
277
|
+
var namePath = getNamePath(name);
|
|
278
|
+
var fieldError = _this.getFieldsError([namePath])[0];
|
|
279
|
+
return fieldError.errors;
|
|
280
|
+
});
|
|
281
|
+
_defineProperty(this, "getFieldWarning", function (name) {
|
|
282
|
+
_this.warningUnhooked();
|
|
283
|
+
var namePath = getNamePath(name);
|
|
284
|
+
var fieldError = _this.getFieldsError([namePath])[0];
|
|
285
|
+
return fieldError.warnings;
|
|
286
|
+
});
|
|
287
|
+
_defineProperty(this, "isFieldsTouched", function () {
|
|
288
|
+
_this.warningUnhooked();
|
|
289
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
290
|
+
args[_key] = arguments[_key];
|
|
291
|
+
}
|
|
292
|
+
var arg0 = args[0],
|
|
293
|
+
arg1 = args[1];
|
|
294
|
+
var namePathList;
|
|
295
|
+
var isAllFieldsTouched = false;
|
|
296
|
+
if (args.length === 0) {
|
|
297
|
+
namePathList = null;
|
|
298
|
+
} else if (args.length === 1) {
|
|
299
|
+
if (Array.isArray(arg0)) {
|
|
300
|
+
namePathList = arg0.map(getNamePath);
|
|
301
|
+
isAllFieldsTouched = false;
|
|
302
|
+
} else {
|
|
303
|
+
namePathList = null;
|
|
304
|
+
isAllFieldsTouched = arg0;
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
namePathList = arg0.map(getNamePath);
|
|
308
|
+
isAllFieldsTouched = arg1;
|
|
309
|
+
}
|
|
310
|
+
var fieldEntities = _this.getFieldEntities(true);
|
|
311
|
+
var isFieldTouched = function isFieldTouched(field) {
|
|
312
|
+
return field.isFieldTouched();
|
|
198
313
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
314
|
+
|
|
315
|
+
// ===== Will get fully compare when not config namePathList =====
|
|
316
|
+
if (!namePathList) {
|
|
317
|
+
return isAllFieldsTouched ? fieldEntities.every(isFieldTouched) : fieldEntities.some(isFieldTouched);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Generate a nest tree for validate
|
|
321
|
+
var map = new NameMap();
|
|
322
|
+
namePathList.forEach(function (shortNamePath) {
|
|
323
|
+
map.set(shortNamePath, []);
|
|
324
|
+
});
|
|
325
|
+
fieldEntities.forEach(function (field) {
|
|
326
|
+
var fieldNamePath = field.getNamePath();
|
|
327
|
+
|
|
328
|
+
// Find matched entity and put into list
|
|
329
|
+
namePathList.forEach(function (shortNamePath) {
|
|
330
|
+
if (shortNamePath.every(function (nameUnit, i) {
|
|
331
|
+
return fieldNamePath[i] === nameUnit;
|
|
332
|
+
})) {
|
|
333
|
+
map.update(shortNamePath, function (list) {
|
|
334
|
+
return [].concat(_toConsumableArray(list), [field]);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
204
337
|
});
|
|
205
|
-
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
// Check if NameMap value is touched
|
|
341
|
+
var isNamePathListTouched = function isNamePathListTouched(entities) {
|
|
342
|
+
return entities.some(isFieldTouched);
|
|
206
343
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
344
|
+
var namePathListEntities = map.map(function (_ref3) {
|
|
345
|
+
var value = _ref3.value;
|
|
346
|
+
return value;
|
|
347
|
+
});
|
|
348
|
+
return isAllFieldsTouched ? namePathListEntities.every(isNamePathListTouched) : namePathListEntities.some(isNamePathListTouched);
|
|
349
|
+
});
|
|
350
|
+
_defineProperty(this, "isFieldTouched", function (name) {
|
|
351
|
+
_this.warningUnhooked();
|
|
352
|
+
return _this.isFieldsTouched([name]);
|
|
353
|
+
});
|
|
354
|
+
_defineProperty(this, "isFieldsValidating", function (nameList) {
|
|
355
|
+
_this.warningUnhooked();
|
|
356
|
+
var fieldEntities = _this.getFieldEntities();
|
|
357
|
+
if (!nameList) {
|
|
358
|
+
return fieldEntities.some(function (testField) {
|
|
359
|
+
return testField.isFieldValidating();
|
|
215
360
|
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
361
|
+
}
|
|
362
|
+
var namePathList = nameList.map(getNamePath);
|
|
363
|
+
return fieldEntities.some(function (testField) {
|
|
364
|
+
var fieldNamePath = testField.getNamePath();
|
|
365
|
+
return containsNamePath(namePathList, fieldNamePath) && testField.isFieldValidating();
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
_defineProperty(this, "isFieldValidating", function (name) {
|
|
369
|
+
_this.warningUnhooked();
|
|
370
|
+
return _this.isFieldsValidating([name]);
|
|
371
|
+
});
|
|
372
|
+
/**
|
|
373
|
+
* Reset Field with field `initialValue` prop.
|
|
374
|
+
* Can pass `entities` or `namePathList` or just nothing.
|
|
375
|
+
*/
|
|
376
|
+
_defineProperty(this, "resetWithFieldInitialValue", function () {
|
|
377
|
+
var info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
378
|
+
// Create cache
|
|
379
|
+
var cache = new NameMap();
|
|
380
|
+
var fieldEntities = _this.getFieldEntities(true);
|
|
381
|
+
fieldEntities.forEach(function (field) {
|
|
382
|
+
var initialValue = field.props.initialValue;
|
|
383
|
+
var namePath = field.getNamePath();
|
|
384
|
+
|
|
385
|
+
// Record only if has `initialValue`
|
|
386
|
+
if (initialValue !== undefined) {
|
|
387
|
+
var records = cache.get(namePath) || new Set();
|
|
388
|
+
records.add({
|
|
389
|
+
entity: field,
|
|
390
|
+
value: initialValue
|
|
391
|
+
});
|
|
392
|
+
cache.set(namePath, records);
|
|
221
393
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// Reset
|
|
397
|
+
var resetWithFields = function resetWithFields(entities) {
|
|
398
|
+
entities.forEach(function (field) {
|
|
399
|
+
var initialValue = field.props.initialValue;
|
|
400
|
+
if (initialValue !== undefined) {
|
|
401
|
+
var namePath = field.getNamePath();
|
|
402
|
+
var formInitialValue = _this.getInitialValue(namePath);
|
|
403
|
+
if (formInitialValue !== undefined) {
|
|
404
|
+
// Warning if conflict with form initialValues and do not modify value
|
|
405
|
+
warning(false, "Form already set 'initialValues' with path '".concat(namePath.join('.'), "'. Field can not overwrite it."));
|
|
406
|
+
} else {
|
|
407
|
+
var records = cache.get(namePath);
|
|
408
|
+
if (records && records.size > 1) {
|
|
409
|
+
// Warning if multiple field set `initialValue`and do not modify value
|
|
410
|
+
warning(false, "Multiple Field with path '".concat(namePath.join('.'), "' set 'initialValue'. Can not decide which one to pick."));
|
|
411
|
+
} else if (records) {
|
|
412
|
+
var originValue = _this.getFieldValue(namePath);
|
|
413
|
+
// Set `initialValue`
|
|
414
|
+
if (!info.skipExist || originValue === undefined) {
|
|
415
|
+
_this.updateStore(setValue(_this.store, namePath, _toConsumableArray(records)[0].value));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
236
418
|
}
|
|
237
419
|
}
|
|
238
420
|
});
|
|
239
|
-
return (0, import_valueUtil.cloneByNamePathList)(this.store, filteredNameList.map(import_valueUtil.getNamePath));
|
|
240
421
|
};
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
errors: entity.getErrors(),
|
|
254
|
-
warnings: entity.getWarnings()
|
|
255
|
-
};
|
|
422
|
+
var requiredFieldEntities;
|
|
423
|
+
if (info.entities) {
|
|
424
|
+
requiredFieldEntities = info.entities;
|
|
425
|
+
} else if (info.namePathList) {
|
|
426
|
+
requiredFieldEntities = [];
|
|
427
|
+
info.namePathList.forEach(function (namePath) {
|
|
428
|
+
var records = cache.get(namePath);
|
|
429
|
+
if (records) {
|
|
430
|
+
var _requiredFieldEntitie;
|
|
431
|
+
(_requiredFieldEntitie = requiredFieldEntities).push.apply(_requiredFieldEntitie, _toConsumableArray(_toConsumableArray(records).map(function (r) {
|
|
432
|
+
return r.entity;
|
|
433
|
+
})));
|
|
256
434
|
}
|
|
257
|
-
return {
|
|
258
|
-
name: (0, import_valueUtil.getNamePath)(nameList[index]),
|
|
259
|
-
errors: [],
|
|
260
|
-
warnings: []
|
|
261
|
-
};
|
|
262
435
|
});
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
this.isFieldsTouched = (...args) => {
|
|
277
|
-
this.warningUnhooked();
|
|
278
|
-
const [arg0, arg1] = args;
|
|
279
|
-
let namePathList;
|
|
280
|
-
let isAllFieldsTouched = false;
|
|
281
|
-
if (args.length === 0) {
|
|
282
|
-
namePathList = null;
|
|
283
|
-
} else if (args.length === 1) {
|
|
284
|
-
if (Array.isArray(arg0)) {
|
|
285
|
-
namePathList = arg0.map(import_valueUtil.getNamePath);
|
|
286
|
-
isAllFieldsTouched = false;
|
|
287
|
-
} else {
|
|
288
|
-
namePathList = null;
|
|
289
|
-
isAllFieldsTouched = arg0;
|
|
290
|
-
}
|
|
291
|
-
} else {
|
|
292
|
-
namePathList = arg0.map(import_valueUtil.getNamePath);
|
|
293
|
-
isAllFieldsTouched = arg1;
|
|
294
|
-
}
|
|
295
|
-
const fieldEntities = this.getFieldEntities(true);
|
|
296
|
-
const isFieldTouched = (field) => field.isFieldTouched();
|
|
297
|
-
if (!namePathList) {
|
|
298
|
-
return isAllFieldsTouched ? fieldEntities.every(isFieldTouched) : fieldEntities.some(isFieldTouched);
|
|
299
|
-
}
|
|
300
|
-
const map = new import_NameMap.default();
|
|
301
|
-
namePathList.forEach((shortNamePath) => {
|
|
302
|
-
map.set(shortNamePath, []);
|
|
303
|
-
});
|
|
304
|
-
fieldEntities.forEach((field) => {
|
|
305
|
-
const fieldNamePath = field.getNamePath();
|
|
306
|
-
namePathList.forEach((shortNamePath) => {
|
|
307
|
-
if (shortNamePath.every((nameUnit, i) => fieldNamePath[i] === nameUnit)) {
|
|
308
|
-
map.update(shortNamePath, (list) => [...list, field]);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
436
|
+
} else {
|
|
437
|
+
requiredFieldEntities = fieldEntities;
|
|
438
|
+
}
|
|
439
|
+
resetWithFields(requiredFieldEntities);
|
|
440
|
+
});
|
|
441
|
+
_defineProperty(this, "resetFields", function (nameList) {
|
|
442
|
+
_this.warningUnhooked();
|
|
443
|
+
var prevStore = _this.store;
|
|
444
|
+
if (!nameList) {
|
|
445
|
+
_this.updateStore(setValues({}, _this.initialValues));
|
|
446
|
+
_this.resetWithFieldInitialValue();
|
|
447
|
+
_this.notifyObservers(prevStore, null, {
|
|
448
|
+
type: 'reset'
|
|
311
449
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
450
|
+
_this.notifyWatch();
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// Reset by `nameList`
|
|
455
|
+
var namePathList = nameList.map(getNamePath);
|
|
456
|
+
namePathList.forEach(function (namePath) {
|
|
457
|
+
var initialValue = _this.getInitialValue(namePath);
|
|
458
|
+
_this.updateStore(setValue(_this.store, namePath, initialValue));
|
|
459
|
+
});
|
|
460
|
+
_this.resetWithFieldInitialValue({
|
|
461
|
+
namePathList: namePathList
|
|
462
|
+
});
|
|
463
|
+
_this.notifyObservers(prevStore, namePathList, {
|
|
464
|
+
type: 'reset'
|
|
465
|
+
});
|
|
466
|
+
_this.notifyWatch(namePathList);
|
|
467
|
+
});
|
|
468
|
+
_defineProperty(this, "setFields", function (fields) {
|
|
469
|
+
_this.warningUnhooked();
|
|
470
|
+
var prevStore = _this.store;
|
|
471
|
+
var namePathList = [];
|
|
472
|
+
fields.forEach(function (fieldData) {
|
|
473
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
474
|
+
var name = fieldData.name,
|
|
475
|
+
errors = fieldData.errors,
|
|
476
|
+
data = _objectWithoutProperties(fieldData, _excluded);
|
|
477
|
+
var namePath = getNamePath(name);
|
|
478
|
+
namePathList.push(namePath);
|
|
479
|
+
|
|
480
|
+
// Value
|
|
481
|
+
if ('value' in data) {
|
|
482
|
+
_this.updateStore(setValue(_this.store, namePath, data.value));
|
|
325
483
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
return (0, import_valueUtil.containsNamePath)(namePathList, fieldNamePath) && testField.isFieldValidating();
|
|
484
|
+
_this.notifyObservers(prevStore, [namePath], {
|
|
485
|
+
type: 'setField',
|
|
486
|
+
data: fieldData
|
|
330
487
|
});
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const fieldEntities = this.getFieldEntities(true);
|
|
343
|
-
fieldEntities.forEach((field) => {
|
|
344
|
-
const { initialValue } = field.props;
|
|
345
|
-
const namePath = field.getNamePath();
|
|
346
|
-
if (initialValue !== void 0) {
|
|
347
|
-
const records = cache.get(namePath) || /* @__PURE__ */ new Set();
|
|
348
|
-
records.add({ entity: field, value: initialValue });
|
|
349
|
-
cache.set(namePath, records);
|
|
350
|
-
}
|
|
488
|
+
});
|
|
489
|
+
_this.notifyWatch(namePathList);
|
|
490
|
+
});
|
|
491
|
+
_defineProperty(this, "getFields", function () {
|
|
492
|
+
var entities = _this.getFieldEntities(true);
|
|
493
|
+
var fields = entities.map(function (field) {
|
|
494
|
+
var namePath = field.getNamePath();
|
|
495
|
+
var meta = field.getMeta();
|
|
496
|
+
var fieldData = _objectSpread(_objectSpread({}, meta), {}, {
|
|
497
|
+
name: namePath,
|
|
498
|
+
value: _this.getFieldValue(namePath)
|
|
351
499
|
});
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
};
|
|
374
|
-
let requiredFieldEntities;
|
|
375
|
-
if (info.entities) {
|
|
376
|
-
requiredFieldEntities = info.entities;
|
|
377
|
-
} else if (info.namePathList) {
|
|
378
|
-
requiredFieldEntities = [];
|
|
379
|
-
info.namePathList.forEach((namePath) => {
|
|
380
|
-
const records = cache.get(namePath);
|
|
381
|
-
if (records) {
|
|
382
|
-
requiredFieldEntities.push(...[...records].map((r) => r.entity));
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
} else {
|
|
386
|
-
requiredFieldEntities = fieldEntities;
|
|
387
|
-
}
|
|
388
|
-
resetWithFields(requiredFieldEntities);
|
|
389
|
-
};
|
|
390
|
-
this.resetFields = (nameList) => {
|
|
391
|
-
this.warningUnhooked();
|
|
392
|
-
const prevStore = this.store;
|
|
393
|
-
if (!nameList) {
|
|
394
|
-
this.updateStore((0, import_valueUtil.setValues)({}, this.initialValues));
|
|
395
|
-
this.resetWithFieldInitialValue();
|
|
396
|
-
this.notifyObservers(prevStore, null, { type: "reset" });
|
|
397
|
-
this.notifyWatch();
|
|
398
|
-
return;
|
|
500
|
+
Object.defineProperty(fieldData, 'originRCField', {
|
|
501
|
+
value: true
|
|
502
|
+
});
|
|
503
|
+
return fieldData;
|
|
504
|
+
});
|
|
505
|
+
return fields;
|
|
506
|
+
});
|
|
507
|
+
// =========================== Observer ===========================
|
|
508
|
+
/**
|
|
509
|
+
* This only trigger when a field is on constructor to avoid we get initialValue too late
|
|
510
|
+
*/
|
|
511
|
+
_defineProperty(this, "initEntityValue", function (entity) {
|
|
512
|
+
var initialValue = entity.props.initialValue;
|
|
513
|
+
if (initialValue !== undefined) {
|
|
514
|
+
var namePath = entity.getNamePath();
|
|
515
|
+
var prevValue = getValue(_this.store, namePath);
|
|
516
|
+
if (prevValue === undefined) {
|
|
517
|
+
_this.updateStore(setValue(_this.store, namePath, initialValue));
|
|
399
518
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
_defineProperty(this, "isMergedPreserve", function (fieldPreserve) {
|
|
522
|
+
var mergedPreserve = fieldPreserve !== undefined ? fieldPreserve : _this.preserve;
|
|
523
|
+
return mergedPreserve !== null && mergedPreserve !== void 0 ? mergedPreserve : true;
|
|
524
|
+
});
|
|
525
|
+
_defineProperty(this, "registerField", function (entity) {
|
|
526
|
+
_this.fieldEntities.push(entity);
|
|
527
|
+
var namePath = entity.getNamePath();
|
|
528
|
+
_this.notifyWatch([namePath]);
|
|
529
|
+
|
|
530
|
+
// Set initial values
|
|
531
|
+
if (entity.props.initialValue !== undefined) {
|
|
532
|
+
var prevStore = _this.store;
|
|
533
|
+
_this.resetWithFieldInitialValue({
|
|
534
|
+
entities: [entity],
|
|
535
|
+
skipExist: true
|
|
404
536
|
});
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
};
|
|
409
|
-
this.setFields = (fields) => {
|
|
410
|
-
this.warningUnhooked();
|
|
411
|
-
const prevStore = this.store;
|
|
412
|
-
const namePathList = [];
|
|
413
|
-
fields.forEach((fieldData) => {
|
|
414
|
-
const { name, errors, ...data } = fieldData;
|
|
415
|
-
const namePath = (0, import_valueUtil.getNamePath)(name);
|
|
416
|
-
namePathList.push(namePath);
|
|
417
|
-
if ("value" in data) {
|
|
418
|
-
this.updateStore((0, import_valueUtil.setValue)(this.store, namePath, data.value));
|
|
419
|
-
}
|
|
420
|
-
this.notifyObservers(prevStore, [namePath], {
|
|
421
|
-
type: "setField",
|
|
422
|
-
data: fieldData
|
|
423
|
-
});
|
|
537
|
+
_this.notifyObservers(prevStore, [entity.getNamePath()], {
|
|
538
|
+
type: 'valueUpdate',
|
|
539
|
+
source: 'internal'
|
|
424
540
|
});
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
const fieldData = {
|
|
433
|
-
...meta,
|
|
434
|
-
name: namePath,
|
|
435
|
-
value: this.getFieldValue(namePath)
|
|
436
|
-
};
|
|
437
|
-
Object.defineProperty(fieldData, "originRCField", {
|
|
438
|
-
value: true
|
|
439
|
-
});
|
|
440
|
-
return fieldData;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// un-register field callback
|
|
544
|
+
return function (isListField, preserve) {
|
|
545
|
+
var subNamePath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
546
|
+
_this.fieldEntities = _this.fieldEntities.filter(function (item) {
|
|
547
|
+
return item !== entity;
|
|
441
548
|
});
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
549
|
+
|
|
550
|
+
// Clean up store value if not preserve
|
|
551
|
+
if (!_this.isMergedPreserve(preserve) && (!isListField || subNamePath.length > 1)) {
|
|
552
|
+
var defaultValue = isListField ? undefined : _this.getInitialValue(namePath);
|
|
553
|
+
if (namePath.length && _this.getFieldValue(namePath) !== defaultValue && _this.fieldEntities.every(function (field) {
|
|
554
|
+
return (
|
|
555
|
+
// Only reset when no namePath exist
|
|
556
|
+
!matchNamePath(field.getNamePath(), namePath)
|
|
557
|
+
);
|
|
558
|
+
})) {
|
|
559
|
+
var _prevStore = _this.store;
|
|
560
|
+
_this.updateStore(setValue(_prevStore, namePath, defaultValue, true));
|
|
561
|
+
|
|
562
|
+
// Notify that field is unmount
|
|
563
|
+
_this.notifyObservers(_prevStore, [namePath], {
|
|
564
|
+
type: 'remove'
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
// Dependencies update
|
|
568
|
+
_this.triggerDependenciesUpdate(_prevStore, namePath);
|
|
455
569
|
}
|
|
456
570
|
}
|
|
571
|
+
_this.notifyWatch([namePath]);
|
|
457
572
|
};
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
if (entity.props.initialValue !== void 0) {
|
|
467
|
-
const prevStore = this.store;
|
|
468
|
-
this.resetWithFieldInitialValue({ entities: [entity], skipExist: true });
|
|
469
|
-
this.notifyObservers(prevStore, [entity.getNamePath()], {
|
|
470
|
-
type: "valueUpdate",
|
|
471
|
-
source: "internal"
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
return (isListField, preserve, subNamePath = []) => {
|
|
475
|
-
this.fieldEntities = this.fieldEntities.filter((item) => item !== entity);
|
|
476
|
-
if (!this.isMergedPreserve(preserve) && (!isListField || subNamePath.length > 1)) {
|
|
477
|
-
const defaultValue = isListField ? void 0 : this.getInitialValue(namePath);
|
|
478
|
-
if (namePath.length && this.getFieldValue(namePath) !== defaultValue && this.fieldEntities.every(
|
|
479
|
-
(field) => (
|
|
480
|
-
// Only reset when no namePath exist
|
|
481
|
-
!(0, import_valueUtil.matchNamePath)(field.getNamePath(), namePath)
|
|
482
|
-
)
|
|
483
|
-
)) {
|
|
484
|
-
const prevStore = this.store;
|
|
485
|
-
this.updateStore((0, import_valueUtil.setValue)(prevStore, namePath, defaultValue, true));
|
|
486
|
-
this.notifyObservers(prevStore, [namePath], { type: "remove" });
|
|
487
|
-
this.triggerDependenciesUpdate(prevStore, namePath);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
this.notifyWatch([namePath]);
|
|
491
|
-
};
|
|
492
|
-
};
|
|
493
|
-
this.dispatch = (action) => {
|
|
494
|
-
switch (action.type) {
|
|
495
|
-
case "updateValue": {
|
|
496
|
-
const { namePath, value } = action;
|
|
497
|
-
this.updateValue(namePath, value);
|
|
573
|
+
});
|
|
574
|
+
_defineProperty(this, "dispatch", function (action) {
|
|
575
|
+
switch (action.type) {
|
|
576
|
+
case 'updateValue':
|
|
577
|
+
{
|
|
578
|
+
var namePath = action.namePath,
|
|
579
|
+
value = action.value;
|
|
580
|
+
_this.updateValue(namePath, value);
|
|
498
581
|
break;
|
|
499
582
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
583
|
+
case 'validateField':
|
|
584
|
+
{
|
|
585
|
+
var _namePath = action.namePath,
|
|
586
|
+
triggerName = action.triggerName;
|
|
587
|
+
_this.validateFields([_namePath], {
|
|
588
|
+
triggerName: triggerName
|
|
589
|
+
});
|
|
503
590
|
break;
|
|
504
591
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
};
|
|
514
|
-
this.getFieldEntities().forEach(({ onStoreChange }) => {
|
|
515
|
-
onStoreChange(prevStore, namePathList, mergedInfo);
|
|
516
|
-
});
|
|
517
|
-
} else {
|
|
518
|
-
this.forceRootUpdate();
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
/**
|
|
522
|
-
* Notify dependencies children with parent update
|
|
523
|
-
* We need delay to trigger validate in case Field is under render props
|
|
524
|
-
*/
|
|
525
|
-
this.triggerDependenciesUpdate = (prevStore, namePath) => {
|
|
526
|
-
const childrenFields = this.getDependencyChildrenFields(namePath);
|
|
527
|
-
if (childrenFields.length) {
|
|
528
|
-
this.validateFields(childrenFields);
|
|
529
|
-
}
|
|
530
|
-
this.notifyObservers(prevStore, childrenFields, {
|
|
531
|
-
type: "dependenciesUpdate",
|
|
532
|
-
relatedFields: [namePath, ...childrenFields]
|
|
592
|
+
default:
|
|
593
|
+
// Currently we don't have other action. Do nothing.
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
_defineProperty(this, "notifyObservers", function (prevStore, namePathList, info) {
|
|
597
|
+
if (_this.subscribable) {
|
|
598
|
+
var mergedInfo = _objectSpread(_objectSpread({}, info), {}, {
|
|
599
|
+
store: _this.getFieldsValue(true)
|
|
533
600
|
});
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
const namePath = (0, import_valueUtil.getNamePath)(name);
|
|
538
|
-
const prevStore = this.store;
|
|
539
|
-
this.updateStore((0, import_valueUtil.setValue)(this.store, namePath, value));
|
|
540
|
-
this.notifyObservers(prevStore, [namePath], {
|
|
541
|
-
type: "valueUpdate",
|
|
542
|
-
source: "internal"
|
|
601
|
+
_this.getFieldEntities().forEach(function (_ref4) {
|
|
602
|
+
var onStoreChange = _ref4.onStoreChange;
|
|
603
|
+
onStoreChange(prevStore, namePathList, mergedInfo);
|
|
543
604
|
});
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
605
|
+
} else {
|
|
606
|
+
_this.forceRootUpdate();
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
/**
|
|
610
|
+
* Notify dependencies children with parent update
|
|
611
|
+
* We need delay to trigger validate in case Field is under render props
|
|
612
|
+
*/
|
|
613
|
+
_defineProperty(this, "triggerDependenciesUpdate", function (prevStore, namePath) {
|
|
614
|
+
var childrenFields = _this.getDependencyChildrenFields(namePath);
|
|
615
|
+
if (childrenFields.length) {
|
|
616
|
+
_this.validateFields(childrenFields);
|
|
617
|
+
}
|
|
618
|
+
_this.notifyObservers(prevStore, childrenFields, {
|
|
619
|
+
type: 'dependenciesUpdate',
|
|
620
|
+
relatedFields: [namePath].concat(_toConsumableArray(childrenFields))
|
|
621
|
+
});
|
|
622
|
+
return childrenFields;
|
|
623
|
+
});
|
|
624
|
+
_defineProperty(this, "updateValue", function (name, value) {
|
|
625
|
+
var namePath = getNamePath(name);
|
|
626
|
+
var prevStore = _this.store;
|
|
627
|
+
_this.updateStore(setValue(_this.store, namePath, value));
|
|
628
|
+
_this.notifyObservers(prevStore, [namePath], {
|
|
629
|
+
type: 'valueUpdate',
|
|
630
|
+
source: 'internal'
|
|
631
|
+
});
|
|
632
|
+
_this.notifyWatch([namePath]);
|
|
633
|
+
|
|
634
|
+
// Dependencies update
|
|
635
|
+
var childrenFields = _this.triggerDependenciesUpdate(prevStore, namePath);
|
|
636
|
+
|
|
637
|
+
// trigger callback function
|
|
638
|
+
var onValuesChange = _this.callbacks.onValuesChange;
|
|
639
|
+
if (onValuesChange) {
|
|
640
|
+
var changedValues = cloneByNamePathList(_this.store, [namePath]);
|
|
641
|
+
onValuesChange(changedValues, _this.getFieldsValue());
|
|
642
|
+
}
|
|
643
|
+
_this.triggerOnFieldsChange([namePath].concat(_toConsumableArray(childrenFields)));
|
|
644
|
+
});
|
|
645
|
+
// Let all child Field get update.
|
|
646
|
+
_defineProperty(this, "setFieldsValue", function (store) {
|
|
647
|
+
_this.warningUnhooked();
|
|
648
|
+
var prevStore = _this.store;
|
|
649
|
+
if (store) {
|
|
650
|
+
var nextStore = setValues(_this.store, store);
|
|
651
|
+
_this.updateStore(nextStore);
|
|
652
|
+
}
|
|
653
|
+
_this.notifyObservers(prevStore, null, {
|
|
654
|
+
type: 'valueUpdate',
|
|
655
|
+
source: 'external'
|
|
656
|
+
});
|
|
657
|
+
_this.notifyWatch();
|
|
658
|
+
});
|
|
659
|
+
_defineProperty(this, "setFieldValue", function (name, value) {
|
|
660
|
+
_this.setFields([{
|
|
661
|
+
name: name,
|
|
662
|
+
value: value
|
|
663
|
+
}]);
|
|
664
|
+
});
|
|
665
|
+
_defineProperty(this, "getDependencyChildrenFields", function (rootNamePath) {
|
|
666
|
+
var children = new Set();
|
|
667
|
+
var childrenFields = [];
|
|
668
|
+
var dependencies2fields = new NameMap();
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Generate maps
|
|
672
|
+
* Can use cache to save perf if user report performance issue with this
|
|
673
|
+
*/
|
|
674
|
+
_this.getFieldEntities().forEach(function (field) {
|
|
675
|
+
var dependencies = field.props.dependencies;
|
|
676
|
+
(dependencies || []).forEach(function (dependency) {
|
|
677
|
+
var dependencyNamePath = getNamePath(dependency);
|
|
678
|
+
dependencies2fields.update(dependencyNamePath, function () {
|
|
679
|
+
var fields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Set();
|
|
680
|
+
fields.add(field);
|
|
681
|
+
return fields;
|
|
682
|
+
});
|
|
564
683
|
});
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
{
|
|
570
|
-
|
|
571
|
-
|
|
684
|
+
});
|
|
685
|
+
var fillChildren = function fillChildren(namePath) {
|
|
686
|
+
var fields = dependencies2fields.get(namePath) || new Set();
|
|
687
|
+
fields.forEach(function (field) {
|
|
688
|
+
if (!children.has(field)) {
|
|
689
|
+
children.add(field);
|
|
690
|
+
var fieldNamePath = field.getNamePath();
|
|
691
|
+
if (field.isFieldDirty() && fieldNamePath.length) {
|
|
692
|
+
childrenFields.push(fieldNamePath);
|
|
693
|
+
fillChildren(fieldNamePath);
|
|
694
|
+
}
|
|
572
695
|
}
|
|
573
|
-
|
|
696
|
+
});
|
|
574
697
|
};
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
698
|
+
fillChildren(rootNamePath);
|
|
699
|
+
return childrenFields;
|
|
700
|
+
});
|
|
701
|
+
_defineProperty(this, "triggerOnFieldsChange", function (namePathList, filedErrors) {
|
|
702
|
+
var onFieldsChange = _this.callbacks.onFieldsChange;
|
|
703
|
+
if (onFieldsChange) {
|
|
704
|
+
var fields = _this.getFields();
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Fill errors since `fields` may be replaced by controlled fields
|
|
708
|
+
*/
|
|
709
|
+
if (filedErrors) {
|
|
710
|
+
var cache = new NameMap();
|
|
711
|
+
filedErrors.forEach(function (_ref5) {
|
|
712
|
+
var name = _ref5.name,
|
|
713
|
+
errors = _ref5.errors;
|
|
714
|
+
cache.set(name, errors);
|
|
587
715
|
});
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
fields.forEach((field) => {
|
|
592
|
-
if (!children.has(field)) {
|
|
593
|
-
children.add(field);
|
|
594
|
-
const fieldNamePath = field.getNamePath();
|
|
595
|
-
if (field.isFieldDirty() && fieldNamePath.length) {
|
|
596
|
-
childrenFields.push(fieldNamePath);
|
|
597
|
-
fillChildren(fieldNamePath);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
716
|
+
fields.forEach(function (field) {
|
|
717
|
+
// eslint-disable-next-line no-param-reassign
|
|
718
|
+
field.errors = cache.get(field.name) || field.errors;
|
|
600
719
|
});
|
|
601
|
-
};
|
|
602
|
-
fillChildren(rootNamePath);
|
|
603
|
-
return childrenFields;
|
|
604
|
-
};
|
|
605
|
-
this.triggerOnFieldsChange = (namePathList, filedErrors) => {
|
|
606
|
-
const { onFieldsChange } = this.callbacks;
|
|
607
|
-
if (onFieldsChange) {
|
|
608
|
-
const fields = this.getFields();
|
|
609
|
-
if (filedErrors) {
|
|
610
|
-
const cache = new import_NameMap.default();
|
|
611
|
-
filedErrors.forEach(({ name, errors }) => {
|
|
612
|
-
cache.set(name, errors);
|
|
613
|
-
});
|
|
614
|
-
fields.forEach((field) => {
|
|
615
|
-
field.errors = cache.get(field.name) || field.errors;
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
const changedFields = fields.filter(({ name: fieldName }) => (0, import_valueUtil.containsNamePath)(namePathList, fieldName));
|
|
619
|
-
onFieldsChange(changedFields, fields);
|
|
620
720
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
721
|
+
var changedFields = fields.filter(function (_ref6) {
|
|
722
|
+
var fieldName = _ref6.name;
|
|
723
|
+
return containsNamePath(namePathList, fieldName);
|
|
724
|
+
});
|
|
725
|
+
onFieldsChange(changedFields, fields);
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
// =========================== Validate ===========================
|
|
729
|
+
_defineProperty(this, "validateFields", function (nameList, options) {
|
|
730
|
+
_this.warningUnhooked();
|
|
731
|
+
var provideNameList = !!nameList;
|
|
732
|
+
var namePathList = provideNameList ? nameList.map(getNamePath) : [];
|
|
733
|
+
|
|
734
|
+
// Collect result in promise list
|
|
735
|
+
var promiseList = [];
|
|
736
|
+
_this.getFieldEntities(true).forEach(function (field) {
|
|
737
|
+
// Add field if not provide `nameList`
|
|
738
|
+
if (!provideNameList) {
|
|
739
|
+
namePathList.push(field.getNamePath());
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Recursive validate if configured.
|
|
744
|
+
* TODO: perf improvement @zombieJ
|
|
745
|
+
*/
|
|
746
|
+
if (options !== null && options !== void 0 && options.recursive && provideNameList) {
|
|
747
|
+
var namePath = field.getNamePath();
|
|
748
|
+
if (
|
|
749
|
+
// nameList[i] === undefined 说明是以 nameList 开头的
|
|
750
|
+
// ['name'] -> ['name','list']
|
|
751
|
+
namePath.every(function (nameUnit, i) {
|
|
752
|
+
return nameList[i] === nameUnit || nameList[i] === undefined;
|
|
753
|
+
})) {
|
|
754
|
+
namePathList.push(namePath);
|
|
645
755
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// Skip if without rule
|
|
759
|
+
if (!field.props.rules || !field.props.rules.length) {
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
var fieldNamePath = field.getNamePath();
|
|
763
|
+
// Add field validate rule in to promise list
|
|
764
|
+
if (!provideNameList || containsNamePath(namePathList, fieldNamePath)) {
|
|
765
|
+
var _field$props;
|
|
766
|
+
var promise = field.validateRules(_objectSpread({
|
|
767
|
+
validateMessages: _objectSpread(_objectSpread({}, defaultValidateMessages), _this.validateMessages),
|
|
768
|
+
label: typeof (field === null || field === void 0 || (_field$props = field.props) === null || _field$props === void 0 ? void 0 : _field$props.label) === 'string' ? field.props.label : ''
|
|
769
|
+
}, options));
|
|
770
|
+
|
|
771
|
+
// Wrap promise with field
|
|
772
|
+
promiseList.push(promise.then(function () {
|
|
773
|
+
return {
|
|
774
|
+
name: fieldNamePath,
|
|
775
|
+
errors: [],
|
|
776
|
+
warnings: []
|
|
777
|
+
};
|
|
778
|
+
}).catch(function (ruleErrors) {
|
|
779
|
+
var _ruleErrors$forEach;
|
|
780
|
+
var mergedErrors = [];
|
|
781
|
+
var mergedWarnings = [];
|
|
782
|
+
(_ruleErrors$forEach = ruleErrors.forEach) === null || _ruleErrors$forEach === void 0 || _ruleErrors$forEach.call(ruleErrors, function (_ref7) {
|
|
783
|
+
var warningOnly = _ref7.rule.warningOnly,
|
|
784
|
+
errors = _ref7.errors;
|
|
785
|
+
if (warningOnly) {
|
|
786
|
+
mergedWarnings.push.apply(mergedWarnings, _toConsumableArray(errors));
|
|
787
|
+
} else {
|
|
788
|
+
mergedErrors.push.apply(mergedErrors, _toConsumableArray(errors));
|
|
789
|
+
}
|
|
655
790
|
});
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
);
|
|
682
|
-
}
|
|
791
|
+
if (mergedErrors.length) {
|
|
792
|
+
return Promise.reject({
|
|
793
|
+
name: fieldNamePath,
|
|
794
|
+
errors: mergedErrors,
|
|
795
|
+
warnings: mergedWarnings
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
return {
|
|
799
|
+
name: fieldNamePath,
|
|
800
|
+
errors: mergedErrors,
|
|
801
|
+
warnings: mergedWarnings
|
|
802
|
+
};
|
|
803
|
+
}));
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
var summaryPromise = allPromiseFinish(promiseList);
|
|
807
|
+
_this.lastValidatePromise = summaryPromise;
|
|
808
|
+
|
|
809
|
+
// Notify fields with rule that validate has finished and need update
|
|
810
|
+
summaryPromise.catch(function (results) {
|
|
811
|
+
return results;
|
|
812
|
+
}).then(function (results) {
|
|
813
|
+
var resultNamePathList = results.map(function (_ref8) {
|
|
814
|
+
var name = _ref8.name;
|
|
815
|
+
return name;
|
|
683
816
|
});
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
summaryPromise.catch((results) => results).then((results) => {
|
|
687
|
-
const resultNamePathList = results.map(({ name }) => name);
|
|
688
|
-
this.notifyObservers(this.store, resultNamePathList, {
|
|
689
|
-
type: "validateFinish"
|
|
690
|
-
});
|
|
691
|
-
this.triggerOnFieldsChange(resultNamePathList, results);
|
|
817
|
+
_this.notifyObservers(_this.store, resultNamePathList, {
|
|
818
|
+
type: 'validateFinish'
|
|
692
819
|
});
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
return Promise.
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
820
|
+
_this.triggerOnFieldsChange(resultNamePathList, results);
|
|
821
|
+
});
|
|
822
|
+
var returnPromise = summaryPromise.then(function () {
|
|
823
|
+
if (_this.lastValidatePromise === summaryPromise) {
|
|
824
|
+
return Promise.resolve(_this.getFieldsValue(namePathList));
|
|
825
|
+
}
|
|
826
|
+
return Promise.reject([]);
|
|
827
|
+
}).catch(function (results) {
|
|
828
|
+
var _this$getFieldsMap$ge2;
|
|
829
|
+
var fieldContext = (_this$getFieldsMap$ge2 = _this.getFieldsMap().get(results[0].name)) === null || _this$getFieldsMap$ge2 === void 0 || (_this$getFieldsMap$ge2 = _this$getFieldsMap$ge2.props) === null || _this$getFieldsMap$ge2 === void 0 ? void 0 : _this$getFieldsMap$ge2.fieldContext;
|
|
830
|
+
if (fieldContext !== null && fieldContext !== void 0 && fieldContext.scrollToError) {
|
|
831
|
+
_this.scrollToField(results[0].name);
|
|
832
|
+
}
|
|
833
|
+
var errorList = results.filter(function (result) {
|
|
834
|
+
return result && result.errors.length;
|
|
705
835
|
});
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
this.submit = () => {
|
|
711
|
-
this.warningUnhooked();
|
|
712
|
-
this.validateFields().then((values) => {
|
|
713
|
-
const { onFinish } = this.callbacks;
|
|
714
|
-
if (onFinish) {
|
|
715
|
-
try {
|
|
716
|
-
onFinish(values);
|
|
717
|
-
} catch (err) {
|
|
718
|
-
console.error(err);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}).catch((e) => {
|
|
722
|
-
const { onFinishFailed } = this.callbacks;
|
|
723
|
-
if (onFinishFailed) {
|
|
724
|
-
onFinishFailed(e);
|
|
725
|
-
}
|
|
836
|
+
return Promise.reject({
|
|
837
|
+
values: _this.getFieldsValue(namePathList),
|
|
838
|
+
errorFields: errorList,
|
|
839
|
+
outOfDate: _this.lastValidatePromise !== summaryPromise
|
|
726
840
|
});
|
|
727
|
-
};
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
// Do not throw in console
|
|
844
|
+
returnPromise.catch(function (e) {
|
|
845
|
+
return e;
|
|
846
|
+
});
|
|
847
|
+
return returnPromise;
|
|
848
|
+
});
|
|
849
|
+
// ============================ Submit ============================
|
|
850
|
+
_defineProperty(this, "submit", function () {
|
|
851
|
+
_this.warningUnhooked();
|
|
852
|
+
_this.validateFields().then(function (values) {
|
|
853
|
+
var onFinish = _this.callbacks.onFinish;
|
|
854
|
+
if (onFinish) {
|
|
855
|
+
try {
|
|
856
|
+
onFinish(values);
|
|
857
|
+
} catch (err) {
|
|
858
|
+
// Should print error if user `onFinish` callback failed
|
|
859
|
+
// eslint-disable-next-line no-console
|
|
860
|
+
console.error(err);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}).catch(function (e) {
|
|
864
|
+
var onFinishFailed = _this.callbacks.onFinishFailed;
|
|
865
|
+
if (onFinishFailed) {
|
|
866
|
+
onFinishFailed(e);
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
});
|
|
870
|
+
this.forceRootUpdate = forceRootUpdate;
|
|
871
|
+
});
|
|
731
872
|
function useForm(form) {
|
|
732
|
-
|
|
733
|
-
|
|
873
|
+
var formRef = useRef(null);
|
|
874
|
+
var _useState = useState({}),
|
|
875
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
876
|
+
forceUpdate = _useState2[1];
|
|
734
877
|
if (!formRef.current) {
|
|
735
878
|
if (form) {
|
|
736
879
|
formRef.current = form;
|
|
737
880
|
} else {
|
|
738
|
-
|
|
881
|
+
// Create a new FormStore if not provided
|
|
882
|
+
var forceReRender = function forceReRender() {
|
|
739
883
|
forceUpdate({});
|
|
740
884
|
};
|
|
741
|
-
|
|
885
|
+
var formStore = new FormStore(forceReRender);
|
|
742
886
|
formRef.current = formStore.getForm();
|
|
743
887
|
}
|
|
744
888
|
}
|
|
745
889
|
return [formRef.current];
|
|
746
890
|
}
|
|
747
|
-
|
|
748
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
749
|
-
0 && (module.exports = {
|
|
750
|
-
FormStore
|
|
751
|
-
});
|
|
891
|
+
export default useForm;
|