@qsxy/element-plus-react 1.0.0-next.10 → 1.0.0-next.12
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.d.ts +2 -2
- package/dist/Avatar/Avatar.js +81 -73
- 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 +75 -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 +138 -161
- package/dist/Checkbox/CheckboxButton.js +133 -157
- package/dist/Checkbox/index.js +2 -42
- package/dist/Checkbox/typings.d.ts +3 -2
- 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.d.ts +3 -3
- package/dist/Dropdown/Dropdown.js +103 -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.d.ts +8 -1
- 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 +335 -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.d.ts +1 -1
- package/dist/Input/typings.js +1 -17
- package/dist/InputNumber/InputNumber.js +224 -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 +162 -117
- package/dist/Radio/RadioButton.d.ts +2 -2
- package/dist/Radio/RadioButton.js +137 -117
- package/dist/Radio/index.js +1 -39
- package/dist/Radio/typings.d.ts +2 -1
- 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 +183 -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 +86 -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
|
@@ -1,143 +1,192 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
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."); }
|
|
4
|
+
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); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
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; }
|
|
8
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
13
|
+
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); }
|
|
14
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
16
|
+
import RawAsyncValidator from 'async-validator';
|
|
17
|
+
import { cloneElement, isValidElement } from 'react';
|
|
18
|
+
import { warning } from "../../Util";
|
|
19
|
+
import { defaultValidateMessages } from "./messages";
|
|
20
|
+
import { setValues } from "./valueUtil";
|
|
21
|
+
|
|
22
|
+
// Remove incorrect original ts define
|
|
23
|
+
var AsyncValidator = RawAsyncValidator;
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(validateUtil_exports);
|
|
35
|
-
var import_async_validator = __toESM(require("async-validator"));
|
|
36
|
-
var import_react = require("react");
|
|
37
|
-
var import_Util = require("../../Util");
|
|
38
|
-
var import_messages = require("./messages");
|
|
39
|
-
var import_valueUtil = require("./valueUtil");
|
|
40
|
-
var AsyncValidator = import_async_validator.default;
|
|
25
|
+
/**
|
|
26
|
+
* Replace with template.
|
|
27
|
+
* `I'm ${name}` + { name: 'bamboo' } = I'm bamboo
|
|
28
|
+
*/
|
|
41
29
|
function replaceMessage(template, kv) {
|
|
42
|
-
return template.replace(/\$\{\w+\}/g, (str)
|
|
43
|
-
|
|
30
|
+
return template.replace(/\$\{\w+\}/g, function (str) {
|
|
31
|
+
var key = str.slice(2, -1);
|
|
44
32
|
return kv[key];
|
|
45
33
|
});
|
|
46
34
|
}
|
|
47
|
-
var CODE_LOGIC_ERROR =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
35
|
+
var CODE_LOGIC_ERROR = 'CODE_LOGIC_ERROR';
|
|
36
|
+
function validateRule(_x, _x2, _x3, _x4, _x5) {
|
|
37
|
+
return _validateRule.apply(this, arguments);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* We use `async-validator` to validate the value.
|
|
41
|
+
* But only check one value in a time to avoid namePath validate issue.
|
|
42
|
+
*/
|
|
43
|
+
function _validateRule() {
|
|
44
|
+
_validateRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(name, value, rule, options, messageVariables) {
|
|
45
|
+
var cloneRule, originValidator, subRuleField, validator, messages, result, subResults, kv, fillVariableResult;
|
|
46
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
47
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
48
|
+
case 0:
|
|
49
|
+
cloneRule = _objectSpread({}, rule); // Bug of `async-validator`
|
|
50
|
+
// https://github.com/react-component/field-form/issues/316
|
|
51
|
+
// https://github.com/react-component/field-form/issues/313
|
|
52
|
+
delete cloneRule.ruleIndex;
|
|
53
|
+
if (cloneRule.validator) {
|
|
54
|
+
originValidator = cloneRule.validator;
|
|
55
|
+
cloneRule.validator = function () {
|
|
56
|
+
try {
|
|
57
|
+
return originValidator.apply(void 0, arguments);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
console.error(error);
|
|
61
|
+
return Promise.reject(CODE_LOGIC_ERROR);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// We should special handle array validate
|
|
67
|
+
subRuleField = null;
|
|
68
|
+
if (cloneRule && cloneRule.type === 'array' && cloneRule.defaultField) {
|
|
69
|
+
subRuleField = cloneRule.defaultField;
|
|
70
|
+
delete cloneRule.defaultField;
|
|
71
|
+
}
|
|
72
|
+
validator = new AsyncValidator(_defineProperty({}, name, [cloneRule]));
|
|
73
|
+
messages = setValues({}, defaultValidateMessages, options.validateMessages);
|
|
74
|
+
validator.messages(messages);
|
|
75
|
+
result = [];
|
|
76
|
+
_context2.prev = 9;
|
|
77
|
+
_context2.next = 12;
|
|
78
|
+
return Promise.resolve(validator.validate(_defineProperty({}, name, value), _objectSpread({}, options)));
|
|
79
|
+
case 12:
|
|
80
|
+
_context2.next = 17;
|
|
81
|
+
break;
|
|
82
|
+
case 14:
|
|
83
|
+
_context2.prev = 14;
|
|
84
|
+
_context2.t0 = _context2["catch"](9);
|
|
85
|
+
if (_context2.t0.errors) {
|
|
86
|
+
result = _context2.t0.errors.map(function (_ref4, index) {
|
|
87
|
+
var message = _ref4.message;
|
|
88
|
+
var mergedMessage = message === CODE_LOGIC_ERROR ? messages.default : message;
|
|
89
|
+
// Wrap ReactNode with `key`
|
|
90
|
+
return /*#__PURE__*/isValidElement(mergedMessage) ? /*#__PURE__*/cloneElement(mergedMessage, {
|
|
91
|
+
key: "error_".concat(index)
|
|
92
|
+
}) : mergedMessage;
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
// eslint-disable-next-line no-console
|
|
96
|
+
console.error(_context2.t0);
|
|
97
|
+
result = [messages.default];
|
|
98
|
+
}
|
|
99
|
+
case 17:
|
|
100
|
+
if (!(!result.length && subRuleField)) {
|
|
101
|
+
_context2.next = 22;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
_context2.next = 20;
|
|
105
|
+
return Promise.all(value.map(function (subValue, i) {
|
|
106
|
+
return validateRule("".concat(name, ".").concat(i), subValue, subRuleField, options, messageVariables);
|
|
107
|
+
}));
|
|
108
|
+
case 20:
|
|
109
|
+
subResults = _context2.sent;
|
|
110
|
+
return _context2.abrupt("return", subResults.reduce(function (prev, errors) {
|
|
111
|
+
return [].concat(_toConsumableArray(prev), _toConsumableArray(errors));
|
|
112
|
+
}, []));
|
|
113
|
+
case 22:
|
|
114
|
+
// Replace message with variables
|
|
115
|
+
kv = _objectSpread(_objectSpread({}, rule), {}, {
|
|
116
|
+
name: name,
|
|
117
|
+
label: typeof (options === null || options === void 0 ? void 0 : options.label) === 'string' ? options.label : '',
|
|
118
|
+
enum: (rule.enum || []).join(', ')
|
|
119
|
+
}, messageVariables);
|
|
120
|
+
fillVariableResult = result.map(function (error) {
|
|
121
|
+
if (typeof error === 'string') {
|
|
122
|
+
return replaceMessage(error, kv);
|
|
123
|
+
}
|
|
124
|
+
return error;
|
|
125
|
+
});
|
|
126
|
+
return _context2.abrupt("return", fillVariableResult);
|
|
127
|
+
case 25:
|
|
128
|
+
case "end":
|
|
129
|
+
return _context2.stop();
|
|
59
130
|
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (cloneRule && cloneRule.type === "array" && cloneRule.defaultField) {
|
|
64
|
-
subRuleField = cloneRule.defaultField;
|
|
65
|
-
delete cloneRule.defaultField;
|
|
66
|
-
}
|
|
67
|
-
const validator = new AsyncValidator({
|
|
68
|
-
[name]: [cloneRule]
|
|
69
|
-
});
|
|
70
|
-
const messages = (0, import_valueUtil.setValues)({}, import_messages.defaultValidateMessages, options.validateMessages);
|
|
71
|
-
validator.messages(messages);
|
|
72
|
-
let result = [];
|
|
73
|
-
try {
|
|
74
|
-
await Promise.resolve(validator.validate({ [name]: value }, { ...options }));
|
|
75
|
-
} catch (errObj) {
|
|
76
|
-
if (errObj.errors) {
|
|
77
|
-
result = errObj.errors.map(({ message }, index) => {
|
|
78
|
-
const mergedMessage = message === CODE_LOGIC_ERROR ? messages.default : message;
|
|
79
|
-
return (0, import_react.isValidElement)(mergedMessage) ? (0, import_react.cloneElement)(mergedMessage, { key: `error_${index}` }) : mergedMessage;
|
|
80
|
-
});
|
|
81
|
-
} else {
|
|
82
|
-
console.error(errObj);
|
|
83
|
-
result = [messages.default];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (!result.length && subRuleField) {
|
|
87
|
-
const subResults = await Promise.all(
|
|
88
|
-
value.map((subValue, i) => validateRule(`${name}.${i}`, subValue, subRuleField, options, messageVariables))
|
|
89
|
-
);
|
|
90
|
-
return subResults.reduce((prev, errors) => [...prev, ...errors], []);
|
|
91
|
-
}
|
|
92
|
-
const kv = {
|
|
93
|
-
...rule,
|
|
94
|
-
name,
|
|
95
|
-
label: typeof (options == null ? void 0 : options.label) === "string" ? options.label : "",
|
|
96
|
-
enum: (rule.enum || []).join(", "),
|
|
97
|
-
...messageVariables
|
|
98
|
-
};
|
|
99
|
-
const fillVariableResult = result.map((error) => {
|
|
100
|
-
if (typeof error === "string") {
|
|
101
|
-
return replaceMessage(error, kv);
|
|
102
|
-
}
|
|
103
|
-
return error;
|
|
104
|
-
});
|
|
105
|
-
return fillVariableResult;
|
|
131
|
+
}, _callee2, null, [[9, 14]]);
|
|
132
|
+
}));
|
|
133
|
+
return _validateRule.apply(this, arguments);
|
|
106
134
|
}
|
|
107
|
-
function validateRules(namePath, value, rules, options, validateFirst, messageVariables) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
135
|
+
export function validateRules(namePath, value, rules, options, validateFirst, messageVariables) {
|
|
136
|
+
var name = namePath.join('.');
|
|
137
|
+
|
|
138
|
+
// Fill rule with context
|
|
139
|
+
var filledRules = rules.map(function (currentRule, ruleIndex) {
|
|
140
|
+
var originValidatorFunc = currentRule.validator;
|
|
141
|
+
var cloneRule = _objectSpread(_objectSpread({}, currentRule), {}, {
|
|
142
|
+
ruleIndex: ruleIndex
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Replace validator if needed
|
|
115
146
|
if (originValidatorFunc) {
|
|
116
|
-
cloneRule.validator = (rule, val, callback)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
147
|
+
cloneRule.validator = function (rule, val, callback) {
|
|
148
|
+
var hasPromise = false;
|
|
149
|
+
|
|
150
|
+
// Wrap callback only accept when promise not provided
|
|
151
|
+
var wrappedCallback = function wrappedCallback() {
|
|
152
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
153
|
+
args[_key] = arguments[_key];
|
|
154
|
+
}
|
|
155
|
+
// Wait a tick to make sure return type is a promise
|
|
156
|
+
Promise.resolve().then(function () {
|
|
157
|
+
warning(!hasPromise, 'Your validator function has already return a promise. `callback` will be ignored.');
|
|
121
158
|
if (!hasPromise) {
|
|
122
|
-
callback(
|
|
159
|
+
callback.apply(void 0, args);
|
|
123
160
|
}
|
|
124
161
|
});
|
|
125
162
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
(
|
|
163
|
+
|
|
164
|
+
// Get promise
|
|
165
|
+
var promise = originValidatorFunc(rule, val, wrappedCallback);
|
|
166
|
+
hasPromise = promise && typeof promise.then === 'function' && typeof promise.catch === 'function';
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 1. Use promise as the first priority.
|
|
170
|
+
* 2. If promise not exist, use callback with warning instead
|
|
171
|
+
*/
|
|
172
|
+
warning(hasPromise, '`callback` is deprecated. Please return a promise instead.');
|
|
129
173
|
if (hasPromise) {
|
|
130
|
-
promise.then(()
|
|
174
|
+
promise.then(function () {
|
|
131
175
|
callback();
|
|
132
|
-
}).catch((err)
|
|
133
|
-
callback(err ||
|
|
176
|
+
}).catch(function (err) {
|
|
177
|
+
callback(err || ' ');
|
|
134
178
|
});
|
|
135
179
|
}
|
|
136
180
|
};
|
|
137
181
|
}
|
|
138
182
|
return cloneRule;
|
|
139
|
-
}).sort((
|
|
183
|
+
}).sort(function (_ref, _ref2) {
|
|
184
|
+
var w1 = _ref.warningOnly,
|
|
185
|
+
i1 = _ref.ruleIndex;
|
|
186
|
+
var w2 = _ref2.warningOnly,
|
|
187
|
+
i2 = _ref2.ruleIndex;
|
|
140
188
|
if (!!w1 === !!w2) {
|
|
189
|
+
// Let keep origin order
|
|
141
190
|
return i1 - i2;
|
|
142
191
|
}
|
|
143
192
|
if (w1) {
|
|
@@ -145,51 +194,127 @@ function validateRules(namePath, value, rules, options, validateFirst, messageVa
|
|
|
145
194
|
}
|
|
146
195
|
return -1;
|
|
147
196
|
});
|
|
148
|
-
|
|
197
|
+
|
|
198
|
+
// Do validate rules
|
|
199
|
+
var summaryPromise;
|
|
149
200
|
if (validateFirst === true) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
201
|
+
// >>>>> Validate by serialization
|
|
202
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
203
|
+
summaryPromise = new Promise( /*#__PURE__*/function () {
|
|
204
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(resolve, reject) {
|
|
205
|
+
var i, rule, errors;
|
|
206
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
207
|
+
while (1) switch (_context.prev = _context.next) {
|
|
208
|
+
case 0:
|
|
209
|
+
i = 0;
|
|
210
|
+
case 1:
|
|
211
|
+
if (!(i < filledRules.length)) {
|
|
212
|
+
_context.next = 12;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
rule = filledRules[i];
|
|
216
|
+
_context.next = 5;
|
|
217
|
+
return validateRule(name, value, rule, options, messageVariables);
|
|
218
|
+
case 5:
|
|
219
|
+
errors = _context.sent;
|
|
220
|
+
if (!errors.length) {
|
|
221
|
+
_context.next = 9;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
reject([{
|
|
225
|
+
errors: errors,
|
|
226
|
+
rule: rule
|
|
227
|
+
}]);
|
|
228
|
+
return _context.abrupt("return");
|
|
229
|
+
case 9:
|
|
230
|
+
i += 1;
|
|
231
|
+
_context.next = 1;
|
|
232
|
+
break;
|
|
233
|
+
case 12:
|
|
234
|
+
/* eslint-enable */
|
|
235
|
+
|
|
236
|
+
resolve([]);
|
|
237
|
+
case 13:
|
|
238
|
+
case "end":
|
|
239
|
+
return _context.stop();
|
|
240
|
+
}
|
|
241
|
+
}, _callee);
|
|
242
|
+
}));
|
|
243
|
+
return function (_x6, _x7) {
|
|
244
|
+
return _ref3.apply(this, arguments);
|
|
245
|
+
};
|
|
246
|
+
}());
|
|
161
247
|
} else {
|
|
162
|
-
|
|
163
|
-
|
|
248
|
+
// >>>>> Validate by parallel
|
|
249
|
+
var rulePromises = filledRules.map(function (rule) {
|
|
250
|
+
return validateRule(name, value, rule, options, messageVariables).then(function (errors) {
|
|
251
|
+
return {
|
|
252
|
+
errors: errors,
|
|
253
|
+
rule: rule
|
|
254
|
+
};
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
summaryPromise = (validateFirst ? finishOnFirstFailed(rulePromises) : finishOnAllFailed(rulePromises)).then(function (errors) {
|
|
258
|
+
// Always change to rejection for Field to catch
|
|
164
259
|
return Promise.reject(errors);
|
|
165
260
|
});
|
|
166
261
|
}
|
|
167
|
-
|
|
262
|
+
|
|
263
|
+
// Internal catch error to avoid console error log.
|
|
264
|
+
summaryPromise.catch(function (e) {
|
|
265
|
+
return e;
|
|
266
|
+
});
|
|
168
267
|
return summaryPromise;
|
|
169
268
|
}
|
|
170
|
-
|
|
171
|
-
return
|
|
172
|
-
const errors = [].concat(...errorsList);
|
|
173
|
-
return errors;
|
|
174
|
-
});
|
|
269
|
+
function finishOnAllFailed(_x8) {
|
|
270
|
+
return _finishOnAllFailed.apply(this, arguments);
|
|
175
271
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
272
|
+
function _finishOnAllFailed() {
|
|
273
|
+
_finishOnAllFailed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(rulePromises) {
|
|
274
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
275
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
276
|
+
case 0:
|
|
277
|
+
return _context3.abrupt("return", Promise.all(rulePromises).then(function (errorsList) {
|
|
278
|
+
var _ref5;
|
|
279
|
+
var errors = (_ref5 = []).concat.apply(_ref5, _toConsumableArray(errorsList));
|
|
280
|
+
return errors;
|
|
281
|
+
}));
|
|
282
|
+
case 1:
|
|
283
|
+
case "end":
|
|
284
|
+
return _context3.stop();
|
|
285
|
+
}
|
|
286
|
+
}, _callee3);
|
|
287
|
+
}));
|
|
288
|
+
return _finishOnAllFailed.apply(this, arguments);
|
|
191
289
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
290
|
+
function finishOnFirstFailed(_x9) {
|
|
291
|
+
return _finishOnFirstFailed.apply(this, arguments);
|
|
292
|
+
}
|
|
293
|
+
function _finishOnFirstFailed() {
|
|
294
|
+
_finishOnFirstFailed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(rulePromises) {
|
|
295
|
+
var count;
|
|
296
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
297
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
298
|
+
case 0:
|
|
299
|
+
count = 0;
|
|
300
|
+
return _context4.abrupt("return", new Promise(function (resolve) {
|
|
301
|
+
rulePromises.forEach(function (promise) {
|
|
302
|
+
promise.then(function (ruleError) {
|
|
303
|
+
if (ruleError.errors.length) {
|
|
304
|
+
resolve([ruleError]);
|
|
305
|
+
}
|
|
306
|
+
count += 1;
|
|
307
|
+
if (count === rulePromises.length) {
|
|
308
|
+
resolve([]);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
}));
|
|
313
|
+
case 2:
|
|
314
|
+
case "end":
|
|
315
|
+
return _context4.stop();
|
|
316
|
+
}
|
|
317
|
+
}, _callee4);
|
|
318
|
+
}));
|
|
319
|
+
return _finishOnFirstFailed.apply(this, arguments);
|
|
320
|
+
}
|