@douyinfe/semi-foundation 2.36.0-beta.0 → 2.36.0
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/calendar/foundation.ts +2 -1
- package/lib/cjs/anchor/constants.js +0 -2
- package/lib/cjs/anchor/foundation.js +10 -73
- package/lib/cjs/anchor/linkFoundation.js +4 -16
- package/lib/cjs/autoComplete/constants.js +0 -3
- package/lib/cjs/autoComplete/foundation.d.ts +1 -1
- package/lib/cjs/autoComplete/foundation.js +25 -139
- package/lib/cjs/autoComplete/optionFoundation.js +4 -14
- package/lib/cjs/avatar/constants.js +0 -2
- package/lib/cjs/avatar/foundation.js +0 -17
- package/lib/cjs/backtop/constants.js +0 -2
- package/lib/cjs/backtop/foundation.d.ts +2 -2
- package/lib/cjs/backtop/foundation.js +0 -21
- package/lib/cjs/badge/constants.js +0 -2
- package/lib/cjs/banner/constants.js +0 -2
- package/lib/cjs/banner/foundation.js +0 -7
- package/lib/cjs/base/constants.js +2 -4
- package/lib/cjs/base/foundation.d.ts +1 -1
- package/lib/cjs/base/foundation.js +12 -46
- package/lib/cjs/base/index.js +0 -3
- package/lib/cjs/breadcrumb/constants.js +0 -2
- package/lib/cjs/breadcrumb/foundation.js +1 -12
- package/lib/cjs/breadcrumb/itemFoundation.js +0 -7
- package/lib/cjs/button/constants.js +0 -2
- package/lib/cjs/calendar/constants.js +0 -2
- package/lib/cjs/calendar/eventUtil.d.ts +1 -1
- package/lib/cjs/calendar/eventUtil.js +2 -74
- package/lib/cjs/calendar/foundation.d.ts +2 -2
- package/lib/cjs/calendar/foundation.js +28 -123
- package/lib/cjs/card/constants.js +0 -2
- package/lib/cjs/carousel/constants.js +0 -2
- package/lib/cjs/carousel/foundation.js +2 -52
- package/lib/cjs/cascader/constants.js +0 -3
- package/lib/cjs/cascader/foundation.d.ts +4 -4
- package/lib/cjs/cascader/foundation.js +28 -242
- package/lib/cjs/cascader/util.js +6 -24
- package/lib/cjs/checkbox/checkboxFoundation.js +2 -38
- package/lib/cjs/checkbox/checkboxGroupFoundation.js +2 -23
- package/lib/cjs/checkbox/constants.js +0 -2
- package/lib/cjs/collapse/constants.js +0 -2
- package/lib/cjs/collapse/foundation.d.ts +1 -1
- package/lib/cjs/collapse/foundation.js +2 -13
- package/lib/cjs/collapsible/constants.js +0 -2
- package/lib/cjs/collapsible/foundation.js +0 -9
- package/lib/cjs/datePicker/_utils/formatter.js +4 -10
- package/lib/cjs/datePicker/_utils/getDayOfWeek.d.ts +1 -1
- package/lib/cjs/datePicker/_utils/getDayOfWeek.js +0 -4
- package/lib/cjs/datePicker/_utils/getDefaultFormatToken.js +0 -5
- package/lib/cjs/datePicker/_utils/getDefaultPickerDate.d.ts +1 -1
- package/lib/cjs/datePicker/_utils/getDefaultPickerDate.js +0 -15
- package/lib/cjs/datePicker/_utils/getFullDateOffset.js +0 -7
- package/lib/cjs/datePicker/_utils/getInsetInputFormatToken.js +0 -5
- package/lib/cjs/datePicker/_utils/getInsetInputValueFromInsetInputStr.js +0 -6
- package/lib/cjs/datePicker/_utils/getMonthTable.d.ts +1 -1
- package/lib/cjs/datePicker/_utils/getMonthTable.js +3 -14
- package/lib/cjs/datePicker/_utils/getMonthsInYear.js +0 -2
- package/lib/cjs/datePicker/_utils/getYears.js +0 -4
- package/lib/cjs/datePicker/_utils/index.js +0 -13
- package/lib/cjs/datePicker/_utils/isAfter.js +0 -4
- package/lib/cjs/datePicker/_utils/isBefore.js +0 -4
- package/lib/cjs/datePicker/_utils/isBetween.js +0 -4
- package/lib/cjs/datePicker/_utils/isDate.js +0 -1
- package/lib/cjs/datePicker/_utils/isSameDay.js +0 -4
- package/lib/cjs/datePicker/_utils/isTimestamp.js +0 -4
- package/lib/cjs/datePicker/_utils/isUnixTimestamp.js +0 -4
- package/lib/cjs/datePicker/_utils/isValidDate.js +0 -1
- package/lib/cjs/datePicker/_utils/isValidTimeZone.js +0 -1
- package/lib/cjs/datePicker/_utils/isWithinInterval.js +0 -4
- package/lib/cjs/datePicker/_utils/parser.js +0 -10
- package/lib/cjs/datePicker/constants.js +0 -3
- package/lib/cjs/datePicker/foundation.d.ts +24 -24
- package/lib/cjs/datePicker/foundation.js +22 -333
- package/lib/cjs/datePicker/inputFoundation.d.ts +3 -3
- package/lib/cjs/datePicker/inputFoundation.js +5 -86
- package/lib/cjs/datePicker/monthFoundation.d.ts +1 -1
- package/lib/cjs/datePicker/monthFoundation.js +3 -28
- package/lib/cjs/datePicker/monthsGridFoundation.d.ts +3 -3
- package/lib/cjs/datePicker/monthsGridFoundation.js +43 -238
- package/lib/cjs/datePicker/yearAndMonthFoundation.d.ts +1 -1
- package/lib/cjs/datePicker/yearAndMonthFoundation.js +12 -38
- package/lib/cjs/descriptions/constants.js +0 -2
- package/lib/cjs/divider/constants.js +0 -2
- package/lib/cjs/dropdown/constants.js +0 -3
- package/lib/cjs/dropdown/foundation.js +4 -23
- package/lib/cjs/dropdown/menuFoundation.js +8 -27
- package/lib/cjs/empty/constants.js +0 -2
- package/lib/cjs/form/constants.js +0 -2
- package/lib/cjs/form/foundation.js +75 -206
- package/lib/cjs/form/interface.d.ts +5 -5
- package/lib/cjs/form/utils.js +47 -77
- package/lib/cjs/grid/constants.js +0 -2
- package/lib/cjs/highlight/constants.js +0 -2
- package/lib/cjs/icons/constants.js +0 -2
- package/lib/cjs/image/constants.js +0 -2
- package/lib/cjs/image/imageFoundation.js +4 -18
- package/lib/cjs/image/previewFooterFoundation.js +0 -13
- package/lib/cjs/image/previewFoundation.js +0 -11
- package/lib/cjs/image/previewImageFoundation.js +6 -80
- package/lib/cjs/image/previewInnerFoundation.js +12 -77
- package/lib/cjs/image/utils.js +0 -14
- package/lib/cjs/input/constants.js +0 -2
- package/lib/cjs/input/foundation.js +17 -101
- package/lib/cjs/input/textareaFoundation.js +20 -85
- package/lib/cjs/input/util/calculateNodeHeight.js +6 -18
- package/lib/cjs/input/util/getSizingData.js +7 -11
- package/lib/cjs/inputNumber/constants.js +0 -2
- package/lib/cjs/inputNumber/foundation.js +29 -192
- package/lib/cjs/layout/constants.js +0 -2
- package/lib/cjs/list/constants.js +0 -2
- package/lib/cjs/modal/constants.js +0 -2
- package/lib/cjs/modal/modalContentFoundation.js +0 -20
- package/lib/cjs/modal/modalFoundation.d.ts +2 -2
- package/lib/cjs/modal/modalFoundation.js +2 -22
- package/lib/cjs/navigation/NavItem.js +0 -10
- package/lib/cjs/navigation/constants.js +0 -3
- package/lib/cjs/navigation/foundation.js +3 -67
- package/lib/cjs/navigation/itemFoundation.js +3 -21
- package/lib/cjs/navigation/subNavFoundation.js +4 -40
- package/lib/cjs/notification/constants.js +0 -3
- package/lib/cjs/notification/notificationFoundation.d.ts +3 -3
- package/lib/cjs/notification/notificationFoundation.js +0 -16
- package/lib/cjs/notification/notificationListFoundation.js +7 -17
- package/lib/cjs/overflowList/constants.js +0 -2
- package/lib/cjs/overflowList/foundation.js +11 -41
- package/lib/cjs/pagination/constants.js +0 -2
- package/lib/cjs/pagination/foundation.d.ts +3 -3
- package/lib/cjs/pagination/foundation.js +21 -90
- package/lib/cjs/popconfirm/constants.js +0 -2
- package/lib/cjs/popconfirm/popconfirmFoundation.js +1 -21
- package/lib/cjs/popover/constants.js +0 -3
- package/lib/cjs/progress/constants.js +0 -2
- package/lib/cjs/progress/generates.d.ts +2 -2
- package/lib/cjs/progress/generates.js +19 -60
- package/lib/cjs/radio/constants.js +0 -2
- package/lib/cjs/radio/radioFoundation.js +0 -14
- package/lib/cjs/radio/radioGroupFoundation.js +4 -23
- package/lib/cjs/radio/radioInnerFoundation.js +2 -19
- package/lib/cjs/rating/constants.js +0 -2
- package/lib/cjs/rating/foundation.js +11 -61
- package/lib/cjs/scrollList/constants.js +0 -2
- package/lib/cjs/scrollList/foundation.js +0 -4
- package/lib/cjs/scrollList/itemFoundation.js +8 -61
- package/lib/cjs/scrollList/scrollTo.js +2 -5
- package/lib/cjs/select/constants.js +0 -3
- package/lib/cjs/select/foundation.d.ts +2 -2
- package/lib/cjs/select/foundation.js +122 -425
- package/lib/cjs/select/optionFoundation.js +4 -14
- package/lib/cjs/sideSheet/constants.js +0 -2
- package/lib/cjs/sideSheet/sideSheetFoundation.js +0 -18
- package/lib/cjs/skeleton/constants.js +0 -2
- package/lib/cjs/slider/constants.js +0 -2
- package/lib/cjs/slider/foundation.d.ts +1 -1
- package/lib/cjs/slider/foundation.js +25 -204
- package/lib/cjs/space/constants.js +0 -2
- package/lib/cjs/spin/constants.js +0 -2
- package/lib/cjs/spin/foundation.js +3 -13
- package/lib/cjs/steps/constants.js +0 -2
- package/lib/cjs/switch/constants.js +0 -2
- package/lib/cjs/switch/foundation.js +2 -18
- package/lib/cjs/table/bodyFoundation.js +2 -34
- package/lib/cjs/table/cellFoundation.js +0 -5
- package/lib/cjs/table/constants.js +7 -8
- package/lib/cjs/table/foundation.d.ts +17 -14
- package/lib/cjs/table/foundation.js +71 -302
- package/lib/cjs/table/tableRowFoundation.js +0 -11
- package/lib/cjs/table/tableSelectionCellFoundation.js +0 -6
- package/lib/cjs/table/utils.d.ts +2 -2
- package/lib/cjs/table/utils.js +5 -118
- package/lib/cjs/tabs/constants.js +0 -2
- package/lib/cjs/tabs/foundation.js +2 -40
- package/lib/cjs/tag/constants.js +1 -2
- package/lib/cjs/tagInput/constants.js +0 -2
- package/lib/cjs/tagInput/foundation.d.ts +4 -4
- package/lib/cjs/tagInput/foundation.js +4 -94
- package/lib/cjs/tagInput/utils/getSplitedArray.js +0 -11
- package/lib/cjs/timePicker/ComboxFoundation.js +4 -39
- package/lib/cjs/timePicker/constants.js +0 -3
- package/lib/cjs/timePicker/foundation.d.ts +1 -1
- package/lib/cjs/timePicker/foundation.js +3 -97
- package/lib/cjs/timePicker/inputFoundation.js +6 -25
- package/lib/cjs/timePicker/utils/index.js +6 -45
- package/lib/cjs/timePicker/utils/localeDate.js +0 -10
- package/lib/cjs/timeline/constants.js +0 -2
- package/lib/cjs/toast/constants.js +0 -3
- package/lib/cjs/toast/toastFoundation.d.ts +3 -3
- package/lib/cjs/toast/toastFoundation.js +0 -14
- package/lib/cjs/toast/toastListFoundation.js +4 -22
- package/lib/cjs/tooltip/constants.js +0 -2
- package/lib/cjs/tooltip/foundation.d.ts +1 -1
- package/lib/cjs/tooltip/foundation.js +63 -291
- package/lib/cjs/transfer/constants.js +0 -2
- package/lib/cjs/transfer/foundation.d.ts +1 -1
- package/lib/cjs/transfer/foundation.js +4 -68
- package/lib/cjs/transfer/transferUtils.js +5 -27
- package/lib/cjs/tree/constants.js +0 -2
- package/lib/cjs/tree/foundation.d.ts +3 -3
- package/lib/cjs/tree/foundation.js +34 -150
- package/lib/cjs/tree/treeUtil.js +54 -173
- package/lib/cjs/treeSelect/constants.js +0 -2
- package/lib/cjs/treeSelect/foundation.d.ts +7 -7
- package/lib/cjs/treeSelect/foundation.js +18 -192
- package/lib/cjs/typography/constants.js +0 -2
- package/lib/cjs/typography/formatNumeral.d.ts +3 -3
- package/lib/cjs/typography/formatNumeral.js +16 -32
- package/lib/cjs/upload/constants.js +0 -2
- package/lib/cjs/upload/foundation.d.ts +5 -5
- package/lib/cjs/upload/foundation.js +36 -245
- package/lib/cjs/upload/utils.js +10 -29
- package/lib/cjs/utils/Event.js +2 -21
- package/lib/cjs/utils/FocusHandle.d.ts +1 -1
- package/lib/cjs/utils/FocusHandle.js +6 -35
- package/lib/cjs/utils/Logger.js +0 -21
- package/lib/cjs/utils/Store.js +0 -10
- package/lib/cjs/utils/a11y.js +18 -43
- package/lib/cjs/utils/array.d.ts +1 -1
- package/lib/cjs/utils/array.js +0 -7
- package/lib/cjs/utils/arrayMove.js +0 -1
- package/lib/cjs/utils/classnames.js +0 -12
- package/lib/cjs/utils/date-fns-extra.js +0 -35
- package/lib/cjs/utils/dom.d.ts +1 -1
- package/lib/cjs/utils/dom.js +0 -13
- package/lib/cjs/utils/function.js +0 -1
- package/lib/cjs/utils/getDataAttr.js +0 -2
- package/lib/cjs/utils/getHighlight.js +5 -26
- package/lib/cjs/utils/getMotionObjFromProps.js +0 -12
- package/lib/cjs/utils/index.js +0 -4
- package/lib/cjs/utils/isBothNaN.js +0 -2
- package/lib/cjs/utils/isElement.js +0 -1
- package/lib/cjs/utils/isEnterPress.js +0 -5
- package/lib/cjs/utils/isEscPress.js +0 -5
- package/lib/cjs/utils/isNullOrUndefined.js +0 -1
- package/lib/cjs/utils/isNumber.js +0 -1
- package/lib/cjs/utils/isObject.js +0 -1
- package/lib/cjs/utils/isPromise.js +0 -3
- package/lib/cjs/utils/isString.js +0 -1
- package/lib/cjs/utils/keyCode.js +0 -105
- package/lib/cjs/utils/log.js +0 -5
- package/lib/cjs/utils/number.js +0 -2
- package/lib/cjs/utils/object.d.ts +4 -4
- package/lib/cjs/utils/object.js +12 -34
- package/lib/cjs/utils/set.js +0 -8
- package/lib/cjs/utils/shallowEqualObjects.js +0 -7
- package/lib/cjs/utils/touchPolyfill.js +0 -7
- package/lib/cjs/utils/type.d.ts +3 -3
- package/lib/cjs/utils/uuid.js +2 -9
- package/lib/cjs/utils/warning.js +0 -1
- package/lib/es/anchor/foundation.js +10 -66
- package/lib/es/anchor/linkFoundation.js +4 -12
- package/lib/es/autoComplete/foundation.d.ts +1 -1
- package/lib/es/autoComplete/foundation.js +24 -132
- package/lib/es/autoComplete/optionFoundation.js +4 -10
- package/lib/es/avatar/foundation.js +0 -12
- package/lib/es/backtop/foundation.d.ts +2 -2
- package/lib/es/backtop/foundation.js +0 -16
- package/lib/es/banner/foundation.js +0 -3
- package/lib/es/base/constants.js +2 -2
- package/lib/es/base/foundation.d.ts +1 -1
- package/lib/es/base/foundation.js +11 -44
- package/lib/es/breadcrumb/foundation.js +0 -7
- package/lib/es/breadcrumb/itemFoundation.js +0 -3
- package/lib/es/calendar/eventUtil.d.ts +1 -1
- package/lib/es/calendar/eventUtil.js +2 -36
- package/lib/es/calendar/foundation.d.ts +2 -2
- package/lib/es/calendar/foundation.js +28 -117
- package/lib/es/carousel/foundation.js +2 -47
- package/lib/es/cascader/constants.js +0 -1
- package/lib/es/cascader/foundation.d.ts +4 -4
- package/lib/es/cascader/foundation.js +30 -226
- package/lib/es/cascader/util.js +6 -15
- package/lib/es/checkbox/checkboxFoundation.js +2 -34
- package/lib/es/checkbox/checkboxGroupFoundation.js +2 -20
- package/lib/es/collapse/foundation.d.ts +1 -1
- package/lib/es/collapse/foundation.js +2 -9
- package/lib/es/collapsible/foundation.js +0 -7
- package/lib/es/datePicker/_utils/formatter.js +4 -8
- package/lib/es/datePicker/_utils/getDayOfWeek.d.ts +1 -1
- package/lib/es/datePicker/_utils/getDayOfWeek.js +0 -3
- package/lib/es/datePicker/_utils/getDefaultFormatToken.js +0 -2
- package/lib/es/datePicker/_utils/getDefaultPickerDate.d.ts +1 -1
- package/lib/es/datePicker/_utils/getDefaultPickerDate.js +0 -10
- package/lib/es/datePicker/_utils/getFullDateOffset.js +0 -3
- package/lib/es/datePicker/_utils/getInsetInputFormatToken.js +0 -4
- package/lib/es/datePicker/_utils/getInsetInputValueFromInsetInputStr.js +0 -5
- package/lib/es/datePicker/_utils/getMonthTable.d.ts +1 -1
- package/lib/es/datePicker/_utils/getMonthTable.js +4 -14
- package/lib/es/datePicker/_utils/getMonthsInYear.js +0 -1
- package/lib/es/datePicker/_utils/getYears.js +0 -3
- package/lib/es/datePicker/_utils/isBetween.js +0 -1
- package/lib/es/datePicker/_utils/parser.js +0 -8
- package/lib/es/datePicker/foundation.d.ts +24 -24
- package/lib/es/datePicker/foundation.js +22 -318
- package/lib/es/datePicker/inputFoundation.d.ts +3 -3
- package/lib/es/datePicker/inputFoundation.js +5 -74
- package/lib/es/datePicker/monthFoundation.d.ts +1 -1
- package/lib/es/datePicker/monthFoundation.js +4 -22
- package/lib/es/datePicker/monthsGridFoundation.d.ts +3 -3
- package/lib/es/datePicker/monthsGridFoundation.js +42 -222
- package/lib/es/datePicker/yearAndMonthFoundation.d.ts +1 -1
- package/lib/es/datePicker/yearAndMonthFoundation.js +12 -36
- package/lib/es/dropdown/foundation.js +4 -18
- package/lib/es/dropdown/menuFoundation.js +8 -22
- package/lib/es/form/foundation.js +74 -195
- package/lib/es/form/interface.d.ts +5 -5
- package/lib/es/form/utils.js +47 -70
- package/lib/es/image/imageFoundation.js +4 -13
- package/lib/es/image/previewFooterFoundation.js +0 -9
- package/lib/es/image/previewFoundation.js +0 -7
- package/lib/es/image/previewImageFoundation.js +6 -72
- package/lib/es/image/previewInnerFoundation.js +12 -70
- package/lib/es/image/utils.js +0 -6
- package/lib/es/input/foundation.js +17 -93
- package/lib/es/input/textareaFoundation.js +20 -75
- package/lib/es/input/util/calculateNodeHeight.js +6 -18
- package/lib/es/input/util/getSizingData.js +7 -11
- package/lib/es/inputNumber/foundation.js +28 -183
- package/lib/es/modal/modalContentFoundation.js +0 -15
- package/lib/es/modal/modalFoundation.d.ts +2 -2
- package/lib/es/modal/modalFoundation.js +2 -17
- package/lib/es/navigation/NavItem.js +0 -6
- package/lib/es/navigation/constants.js +1 -1
- package/lib/es/navigation/foundation.js +2 -60
- package/lib/es/navigation/itemFoundation.js +3 -18
- package/lib/es/navigation/subNavFoundation.js +4 -36
- package/lib/es/notification/constants.js +1 -1
- package/lib/es/notification/notificationFoundation.d.ts +3 -3
- package/lib/es/notification/notificationFoundation.js +0 -11
- package/lib/es/notification/notificationListFoundation.js +6 -13
- package/lib/es/overflowList/foundation.js +11 -37
- package/lib/es/pagination/foundation.d.ts +3 -3
- package/lib/es/pagination/foundation.js +20 -87
- package/lib/es/popconfirm/popconfirmFoundation.js +1 -16
- package/lib/es/progress/generates.d.ts +2 -2
- package/lib/es/progress/generates.js +19 -59
- package/lib/es/radio/radioFoundation.js +0 -9
- package/lib/es/radio/radioGroupFoundation.js +4 -19
- package/lib/es/radio/radioInnerFoundation.js +2 -15
- package/lib/es/rating/foundation.js +10 -54
- package/lib/es/scrollList/itemFoundation.js +8 -60
- package/lib/es/scrollList/scrollTo.js +2 -4
- package/lib/es/select/foundation.d.ts +2 -2
- package/lib/es/select/foundation.js +122 -411
- package/lib/es/select/optionFoundation.js +4 -10
- package/lib/es/sideSheet/sideSheetFoundation.js +0 -12
- package/lib/es/slider/foundation.d.ts +1 -1
- package/lib/es/slider/foundation.js +24 -197
- package/lib/es/spin/foundation.js +3 -11
- package/lib/es/switch/foundation.js +2 -13
- package/lib/es/table/bodyFoundation.js +2 -25
- package/lib/es/table/cellFoundation.js +0 -1
- package/lib/es/table/constants.js +6 -6
- package/lib/es/table/foundation.d.ts +17 -14
- package/lib/es/table/foundation.js +71 -309
- package/lib/es/table/tableRowFoundation.js +2 -9
- package/lib/es/table/tableSelectionCellFoundation.js +0 -2
- package/lib/es/table/utils.d.ts +2 -2
- package/lib/es/table/utils.js +5 -81
- package/lib/es/tabs/foundation.js +2 -35
- package/lib/es/tagInput/foundation.d.ts +4 -4
- package/lib/es/tagInput/foundation.js +4 -84
- package/lib/es/tagInput/utils/getSplitedArray.js +0 -7
- package/lib/es/timePicker/ComboxFoundation.js +4 -30
- package/lib/es/timePicker/foundation.d.ts +1 -1
- package/lib/es/timePicker/foundation.js +4 -90
- package/lib/es/timePicker/inputFoundation.js +6 -22
- package/lib/es/timePicker/utils/index.js +6 -25
- package/lib/es/timePicker/utils/localeDate.js +0 -8
- package/lib/es/toast/constants.js +1 -1
- package/lib/es/toast/toastFoundation.d.ts +3 -3
- package/lib/es/toast/toastFoundation.js +0 -9
- package/lib/es/toast/toastListFoundation.js +4 -18
- package/lib/es/tooltip/foundation.d.ts +1 -1
- package/lib/es/tooltip/foundation.js +63 -288
- package/lib/es/transfer/foundation.d.ts +1 -1
- package/lib/es/transfer/foundation.js +6 -62
- package/lib/es/transfer/transferUtils.js +5 -21
- package/lib/es/tree/foundation.d.ts +3 -3
- package/lib/es/tree/foundation.js +34 -143
- package/lib/es/tree/treeUtil.js +54 -139
- package/lib/es/treeSelect/foundation.d.ts +7 -7
- package/lib/es/treeSelect/foundation.js +20 -179
- package/lib/es/typography/formatNumeral.d.ts +3 -3
- package/lib/es/typography/formatNumeral.js +16 -29
- package/lib/es/upload/foundation.d.ts +5 -5
- package/lib/es/upload/foundation.js +36 -238
- package/lib/es/upload/utils.js +10 -24
- package/lib/es/utils/Event.js +2 -17
- package/lib/es/utils/FocusHandle.d.ts +1 -1
- package/lib/es/utils/FocusHandle.js +6 -32
- package/lib/es/utils/Logger.js +0 -20
- package/lib/es/utils/Store.js +0 -9
- package/lib/es/utils/a11y.js +18 -31
- package/lib/es/utils/array.d.ts +1 -1
- package/lib/es/utils/array.js +0 -5
- package/lib/es/utils/classnames.js +0 -10
- package/lib/es/utils/date-fns-extra.js +0 -27
- package/lib/es/utils/dom.d.ts +1 -1
- package/lib/es/utils/dom.js +0 -9
- package/lib/es/utils/getDataAttr.js +0 -1
- package/lib/es/utils/getHighlight.js +5 -26
- package/lib/es/utils/getMotionObjFromProps.js +0 -8
- package/lib/es/utils/isBothNaN.js +0 -1
- package/lib/es/utils/isEnterPress.js +0 -2
- package/lib/es/utils/isEscPress.js +0 -2
- package/lib/es/utils/keyCode.js +0 -104
- package/lib/es/utils/log.js +0 -3
- package/lib/es/utils/object.d.ts +4 -4
- package/lib/es/utils/object.js +12 -28
- package/lib/es/utils/set.js +0 -5
- package/lib/es/utils/shallowEqualObjects.js +0 -6
- package/lib/es/utils/touchPolyfill.js +0 -5
- package/lib/es/utils/type.d.ts +3 -3
- package/lib/es/utils/uuid.js +2 -8
- package/package.json +2 -2
- package/table/foundation.ts +7 -10
- package/upload/foundation.ts +8 -8
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _toPath from "lodash/toPath";
|
|
2
2
|
import _isFunction from "lodash/isFunction";
|
|
3
3
|
import _isUndefined from "lodash/isUndefined";
|
|
4
|
-
|
|
5
4
|
/* eslint-disable prefer-const, max-len */
|
|
6
5
|
import BaseFoundation from '../base/foundation';
|
|
7
6
|
import * as ObjectUtil from '../utils/object';
|
|
@@ -19,26 +18,24 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
19
18
|
这里也需要读一次initValue,因为Form级别可设置初始值,Field级别也可设置初始值.
|
|
20
19
|
Form中设置的字段,不一定会存在Field实体,所以不能完全依赖register时刻来设置初始值
|
|
21
20
|
*/
|
|
22
|
-
|
|
23
21
|
let {
|
|
24
22
|
initValues
|
|
25
23
|
} = this._adapter.getProps();
|
|
26
|
-
|
|
27
24
|
initValues = this._adapter.cloneDeep(initValues);
|
|
28
25
|
this.data = {
|
|
29
26
|
values: initValues ? initValues : {},
|
|
30
27
|
errors: {},
|
|
31
|
-
touched: {}
|
|
28
|
+
touched: {}
|
|
29
|
+
// invalid: false,
|
|
32
30
|
// dirty: false,
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
};
|
|
32
|
+
// Map store all fields
|
|
35
33
|
// key: fieldName
|
|
36
34
|
// value: { field, fieldApi, keepState, initValue}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
this.fields = new Map();
|
|
36
|
+
// Record all registered fields
|
|
37
|
+
this.registered = {};
|
|
38
|
+
// Record all registered ArrayField
|
|
42
39
|
this.registeredArrayField = new Map();
|
|
43
40
|
this.register = this.register.bind(this);
|
|
44
41
|
this.unRegister = this.unRegister.bind(this);
|
|
@@ -61,23 +58,20 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
61
58
|
this.getFieldExist = this.getFieldExist.bind(this);
|
|
62
59
|
this.scrollToField = this.scrollToField.bind(this);
|
|
63
60
|
}
|
|
64
|
-
|
|
65
61
|
init() {
|
|
66
62
|
this._adapter.initFormId();
|
|
67
63
|
}
|
|
68
|
-
|
|
69
64
|
getField(field) {
|
|
70
65
|
const targetField = this.fields.get(field);
|
|
71
66
|
return targetField;
|
|
72
67
|
}
|
|
73
|
-
|
|
74
68
|
register(field, fieldState, fieldStuff) {
|
|
75
69
|
// determine if this field has been register before
|
|
76
70
|
const registered = this.registered[field];
|
|
77
71
|
this.registered[field] = true;
|
|
78
72
|
this.fields.set(field, fieldStuff);
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
if (fieldStuff.keepState) {
|
|
74
|
+
// TODO support keepState
|
|
81
75
|
} else {
|
|
82
76
|
const allowEmpty = fieldStuff.allowEmpty || false;
|
|
83
77
|
const opts = {
|
|
@@ -85,24 +79,22 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
85
79
|
notUpdate: false,
|
|
86
80
|
allowEmpty
|
|
87
81
|
};
|
|
88
|
-
let fieldValue = fieldState.value;
|
|
89
|
-
|
|
82
|
+
let fieldValue = fieldState.value;
|
|
83
|
+
// When allowEmpty is false, 'is equivalent to undefined, and the key of the field does not need to be reflected on values
|
|
90
84
|
if (!allowEmpty && fieldValue === '') {
|
|
91
85
|
fieldValue = undefined;
|
|
92
86
|
}
|
|
93
|
-
|
|
94
87
|
this.updateStateValue(field, fieldValue, opts);
|
|
95
|
-
|
|
96
88
|
if (fieldState.error) {
|
|
97
89
|
this.updateStateError(field, fieldState.error, opts);
|
|
98
90
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
91
|
+
}
|
|
92
|
+
// this.log(this.fields);
|
|
101
93
|
}
|
|
102
94
|
|
|
103
95
|
unRegister(field) {
|
|
104
|
-
const targetField = this.fields.get(field);
|
|
105
|
-
|
|
96
|
+
const targetField = this.fields.get(field);
|
|
97
|
+
// delete data
|
|
106
98
|
try {
|
|
107
99
|
if (!targetField.keepState) {
|
|
108
100
|
ObjectUtil.remove(this.data.values, field);
|
|
@@ -111,50 +103,40 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
111
103
|
}
|
|
112
104
|
} catch (error) {
|
|
113
105
|
console.error(`some thing wrong when unregister field:${field}`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
106
|
+
}
|
|
107
|
+
// delete field
|
|
117
108
|
this.fields.delete(field);
|
|
118
|
-
|
|
119
109
|
this._adapter.notifyChange(this.data);
|
|
120
|
-
|
|
121
110
|
this._adapter.forceUpdate();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
111
|
+
}
|
|
112
|
+
// in order to slove byted-issue-289
|
|
125
113
|
registerArrayField(arrayFieldPath, val) {
|
|
126
114
|
this.updateArrayField(arrayFieldPath, {
|
|
127
115
|
updateKey: new Date().valueOf(),
|
|
128
116
|
initValue: val
|
|
129
117
|
});
|
|
130
118
|
}
|
|
131
|
-
|
|
132
119
|
unRegisterArrayField(arrayField) {
|
|
133
120
|
this.registeredArrayField.delete(arrayField);
|
|
134
121
|
}
|
|
135
|
-
|
|
136
122
|
getArrayField(arrayField) {
|
|
137
123
|
return this.registeredArrayField.get(arrayField);
|
|
138
124
|
}
|
|
139
|
-
|
|
140
125
|
updateArrayField(arrayField, updateValue) {
|
|
141
126
|
const mergeVal = Object.assign(Object.assign({}, this.registeredArrayField.get(arrayField)), updateValue);
|
|
142
127
|
this.registeredArrayField.set(arrayField, mergeVal);
|
|
143
128
|
}
|
|
144
|
-
|
|
145
129
|
validate(fieldPaths) {
|
|
146
130
|
const {
|
|
147
131
|
validateFields
|
|
148
132
|
} = this.getProps();
|
|
149
|
-
|
|
150
133
|
if (validateFields && _isFunction(validateFields)) {
|
|
151
134
|
return this._formValidate();
|
|
152
135
|
} else {
|
|
153
136
|
return this._fieldsValidate(fieldPaths);
|
|
154
137
|
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
138
|
+
}
|
|
139
|
+
// form level validate
|
|
158
140
|
_formValidate() {
|
|
159
141
|
const {
|
|
160
142
|
values
|
|
@@ -164,14 +146,12 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
164
146
|
} = this.getProps();
|
|
165
147
|
return new Promise((resolve, reject) => {
|
|
166
148
|
let maybePromisedErrors;
|
|
167
|
-
|
|
168
149
|
try {
|
|
169
150
|
maybePromisedErrors = validateFields(values);
|
|
170
151
|
} catch (errors) {
|
|
171
152
|
// error throw by sync validate directly
|
|
172
153
|
maybePromisedErrors = errors;
|
|
173
154
|
}
|
|
174
|
-
|
|
175
155
|
if (!maybePromisedErrors) {
|
|
176
156
|
resolve(values);
|
|
177
157
|
this.injectErrorToField({});
|
|
@@ -183,55 +163,42 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
183
163
|
this.injectErrorToField({});
|
|
184
164
|
} else {
|
|
185
165
|
this.data.errors = result;
|
|
186
|
-
|
|
187
166
|
this._adapter.notifyChange(this.data);
|
|
188
|
-
|
|
189
167
|
this.injectErrorToField(result);
|
|
190
|
-
|
|
191
168
|
this._adapter.forceUpdate();
|
|
192
|
-
|
|
193
169
|
this._autoScroll(100);
|
|
194
|
-
|
|
195
170
|
reject(result);
|
|
196
171
|
}
|
|
197
172
|
}, errors => {
|
|
198
173
|
// validate failed
|
|
199
174
|
// this._adapter.notifyChange(this.data);
|
|
200
175
|
this._autoScroll(100);
|
|
201
|
-
|
|
202
176
|
reject(errors);
|
|
203
177
|
});
|
|
204
178
|
} else {
|
|
205
179
|
// TODO: current design, returning an empty object will be considered a checksum failure and will be rejected. Only returning an empty string will be considered a success, consider resetting it in 1.0?
|
|
206
180
|
this.data.errors = maybePromisedErrors;
|
|
207
181
|
this.injectErrorToField(maybePromisedErrors);
|
|
208
|
-
|
|
209
182
|
this._adapter.notifyChange(this.data);
|
|
210
|
-
|
|
211
183
|
this._adapter.forceUpdate();
|
|
212
|
-
|
|
213
184
|
this._autoScroll(100);
|
|
214
|
-
|
|
215
185
|
reject(maybePromisedErrors);
|
|
216
186
|
}
|
|
217
187
|
});
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
188
|
+
}
|
|
189
|
+
// field level validate
|
|
221
190
|
_fieldsValidate(fieldPaths) {
|
|
222
191
|
const {
|
|
223
192
|
values
|
|
224
|
-
} = this.data;
|
|
225
|
-
|
|
193
|
+
} = this.data;
|
|
194
|
+
// When there is no custom validation function at Form level, perform validation of each Field
|
|
226
195
|
return new Promise((resolve, reject) => {
|
|
227
196
|
let promiseSet = [];
|
|
228
|
-
|
|
229
197
|
const targetFields = this._getOperateFieldMap(fieldPaths);
|
|
230
|
-
|
|
231
198
|
targetFields.forEach((field, fieldPath) => {
|
|
232
199
|
// Call each fieldApi for verification
|
|
233
|
-
const fieldValue = this.getValue(fieldPath);
|
|
234
|
-
|
|
200
|
+
const fieldValue = this.getValue(fieldPath);
|
|
201
|
+
// When centralized verification, no need to trigger forceUpdate and notify
|
|
235
202
|
const opts = {
|
|
236
203
|
notNotify: true,
|
|
237
204
|
notUpdate: true
|
|
@@ -243,37 +210,29 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
243
210
|
Promise.all(promiseSet).then(() => {
|
|
244
211
|
// After the centralized verification is completed, trigger notify and forceUpdate once.
|
|
245
212
|
this._adapter.notifyChange(this.data);
|
|
246
|
-
|
|
247
213
|
this._adapter.forceUpdate();
|
|
248
|
-
|
|
249
214
|
const errors = this.getError();
|
|
250
|
-
|
|
251
215
|
if (this._isValid(targetFields)) {
|
|
252
216
|
resolve(values);
|
|
253
217
|
} else {
|
|
254
218
|
this._autoScroll();
|
|
255
|
-
|
|
256
219
|
reject(errors);
|
|
257
220
|
}
|
|
258
221
|
});
|
|
259
222
|
});
|
|
260
223
|
}
|
|
261
|
-
|
|
262
224
|
submit() {
|
|
263
225
|
const {
|
|
264
226
|
values
|
|
265
|
-
} = this.data;
|
|
266
|
-
|
|
227
|
+
} = this.data;
|
|
228
|
+
// validate form
|
|
267
229
|
this.validate().then(resolveValues => {
|
|
268
230
|
// if valid do submit
|
|
269
231
|
const _values = this._adapter.cloneDeep(resolveValues);
|
|
270
|
-
|
|
271
232
|
this._adapter.notifySubmit(_values);
|
|
272
233
|
}).catch(errors => {
|
|
273
234
|
const _errors = this._adapter.cloneDeep(errors);
|
|
274
|
-
|
|
275
235
|
const _values = this._adapter.cloneDeep(values);
|
|
276
|
-
|
|
277
236
|
this._adapter.notifySubmitFail(_errors, _values);
|
|
278
237
|
});
|
|
279
238
|
}
|
|
@@ -290,37 +249,30 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
290
249
|
* activity.a => activity.a[0]、activity.a[1]
|
|
291
250
|
*
|
|
292
251
|
*/
|
|
293
|
-
|
|
294
|
-
|
|
295
252
|
_getNestedField(path) {
|
|
296
253
|
const allRegisterField = this.fields;
|
|
297
254
|
const allFieldPath = [...allRegisterField].map(item => item[0]);
|
|
298
255
|
let nestedFieldPath = new Map();
|
|
299
256
|
allFieldPath.forEach(item => {
|
|
300
257
|
let itemPath = _toPath(item);
|
|
301
|
-
|
|
302
258
|
let targetPath = _toPath(path);
|
|
303
|
-
|
|
304
259
|
if (targetPath.every((path, i) => targetPath[i] === itemPath[i])) {
|
|
305
260
|
const realField = allRegisterField.get(item);
|
|
306
261
|
nestedFieldPath.set(item, realField);
|
|
307
262
|
}
|
|
308
263
|
});
|
|
309
264
|
return nestedFieldPath;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
265
|
+
}
|
|
266
|
+
// get all operate fields, called by validate() / reset()
|
|
313
267
|
_getOperateFieldMap(fieldPaths) {
|
|
314
268
|
let targetFields = new Map();
|
|
315
|
-
|
|
316
269
|
if (!_isUndefined(fieldPaths)) {
|
|
317
270
|
// reset or validate specific fields
|
|
318
271
|
fieldPaths.forEach(path => {
|
|
319
|
-
const field = this.fields.get(path);
|
|
320
|
-
|
|
272
|
+
const field = this.fields.get(path);
|
|
273
|
+
// may be undefined, if exists two fields like 'a[0]'、'a[1]', but user directly call reset(['a']) / validate(['a'])
|
|
321
274
|
if (_isUndefined(field)) {
|
|
322
275
|
const nestedFields = this._getNestedField(path);
|
|
323
|
-
|
|
324
276
|
targetFields = new Map([...targetFields, ...nestedFields]);
|
|
325
277
|
} else {
|
|
326
278
|
targetFields.set(path, field);
|
|
@@ -330,29 +282,21 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
330
282
|
// reset or validate all fields
|
|
331
283
|
targetFields = this.fields;
|
|
332
284
|
}
|
|
333
|
-
|
|
334
285
|
return targetFields;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
286
|
+
}
|
|
287
|
+
// Reset the entire form, reset all fields and remove validation results
|
|
338
288
|
reset(fieldPaths) {
|
|
339
289
|
const targetFields = this._getOperateFieldMap(fieldPaths);
|
|
340
|
-
|
|
341
290
|
targetFields.forEach(field => {
|
|
342
291
|
field.fieldApi.reset();
|
|
343
292
|
});
|
|
344
|
-
|
|
345
293
|
if (this.registeredArrayField.size) {
|
|
346
294
|
this._resetArrayField();
|
|
347
295
|
}
|
|
348
|
-
|
|
349
296
|
this._adapter.notifyChange(this.data);
|
|
350
|
-
|
|
351
297
|
this._adapter.forceUpdate();
|
|
352
|
-
|
|
353
298
|
this._adapter.notifyReset();
|
|
354
299
|
}
|
|
355
|
-
|
|
356
300
|
_resetArrayField() {
|
|
357
301
|
/*
|
|
358
302
|
When Reset, arrayField needs to be processed separately. Restore the key/value of arrayField in formState according to the initial value
|
|
@@ -371,10 +315,9 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
371
315
|
updateKey: new Date().valueOf()
|
|
372
316
|
});
|
|
373
317
|
});
|
|
374
|
-
}
|
|
318
|
+
}
|
|
319
|
+
// After calling the form's custom validateFields function, reject the returned error to the corresponding field
|
|
375
320
|
// 调用了Form的自定义validateFields函数后,将返回的错误展示到对应的field中
|
|
376
|
-
|
|
377
|
-
|
|
378
321
|
injectErrorToField(errors) {
|
|
379
322
|
this.fields.forEach(field => {
|
|
380
323
|
const fieldError = ObjectUtil.get(errors, field.field);
|
|
@@ -385,55 +328,45 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
385
328
|
field.fieldApi.setError(fieldError, opts);
|
|
386
329
|
});
|
|
387
330
|
}
|
|
388
|
-
|
|
389
331
|
getValue(field, opts) {
|
|
390
332
|
const isAllField = typeof field === 'undefined';
|
|
391
333
|
const needClone = opts && opts.needClone;
|
|
392
334
|
let result, fieldValue;
|
|
393
|
-
|
|
394
335
|
switch (true) {
|
|
395
336
|
case !isAllField && !needClone:
|
|
396
337
|
result = ObjectUtil.get(this.data.values, field);
|
|
397
338
|
break;
|
|
398
|
-
|
|
399
339
|
case !isAllField && needClone:
|
|
400
340
|
fieldValue = ObjectUtil.get(this.data.values, field);
|
|
401
341
|
result = this._adapter.cloneDeep(fieldValue);
|
|
402
342
|
break;
|
|
403
|
-
|
|
404
343
|
case isAllField && !needClone:
|
|
405
344
|
result = Object.assign({}, this.data.values);
|
|
406
345
|
break;
|
|
407
|
-
|
|
408
346
|
case isAllField && needClone:
|
|
409
347
|
result = this._adapter.cloneDeep(this.data.values);
|
|
410
348
|
break;
|
|
411
|
-
|
|
412
349
|
default:
|
|
413
350
|
break;
|
|
414
351
|
}
|
|
415
|
-
|
|
416
352
|
return result;
|
|
417
353
|
}
|
|
418
|
-
|
|
419
354
|
setValues(values, _ref) {
|
|
420
355
|
let {
|
|
421
356
|
isOverride = false
|
|
422
357
|
} = _ref;
|
|
423
|
-
|
|
424
358
|
const _values = this._adapter.cloneDeep(values);
|
|
425
|
-
|
|
426
359
|
this.fields.forEach(field => {
|
|
427
|
-
const value = ObjectUtil.get(_values, field.field);
|
|
360
|
+
const value = ObjectUtil.get(_values, field.field);
|
|
361
|
+
// When calling setValues to override the values, only need to trigger onValueChange and onChange once, so setNotNotify of setValue to true
|
|
428
362
|
// 调用setValues进行值的覆盖时,只需要回调一次onValueChange、onChange即可,所以此处将setValue的notNotify置为true
|
|
429
|
-
|
|
430
363
|
const opts = {
|
|
431
364
|
notNotify: true,
|
|
432
365
|
notUpdate: true
|
|
433
366
|
};
|
|
434
367
|
field.fieldApi.setValue(value, opts);
|
|
435
|
-
});
|
|
436
|
-
|
|
368
|
+
});
|
|
369
|
+
// if there exists any arrayField component in this form
|
|
437
370
|
if (this.registeredArrayField.size) {
|
|
438
371
|
const arrayFieldPaths = [...this.registeredArrayField.keys()];
|
|
439
372
|
arrayFieldPaths.forEach(path => {
|
|
@@ -441,24 +374,19 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
441
374
|
updateKey: new Date().valueOf()
|
|
442
375
|
});
|
|
443
376
|
});
|
|
444
|
-
}
|
|
377
|
+
}
|
|
378
|
+
// When isOverride is true, there may be a non-existent field in the values passed in, directly synchronized to formState.values
|
|
445
379
|
// 当isOverride为true,传入的values中可能存在不存在的field时,直接将其同步到formState.values中
|
|
446
|
-
|
|
447
|
-
|
|
448
380
|
if (isOverride) {
|
|
449
381
|
this.data.values = _values;
|
|
450
|
-
}
|
|
382
|
+
}
|
|
383
|
+
// After completing the assignment, the unified callback can be done once.
|
|
451
384
|
// 在完成赋值后,统一回调一次即可
|
|
452
|
-
|
|
453
|
-
|
|
454
385
|
this._adapter.notifyChange(this.data);
|
|
455
|
-
|
|
456
386
|
this._adapter.notifyValueChange(this.data.values, Object.assign({}, values));
|
|
457
|
-
|
|
458
387
|
this._adapter.forceUpdate();
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
|
|
388
|
+
}
|
|
389
|
+
// update formState value
|
|
462
390
|
updateStateValue(field, value, opts, callback) {
|
|
463
391
|
const notNotify = opts && opts.notNotify;
|
|
464
392
|
const notUpdate = opts && opts.notUpdate;
|
|
@@ -469,9 +397,8 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
469
397
|
* When F orm.allow Empty is true, all fields and keys will appear in the formS tate.values. If the value is empty, it is undefined
|
|
470
398
|
* When F orm.allow Empty is false, only fields with values will key appear in the formS tate.values
|
|
471
399
|
*/
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
400
|
+
const formAllowEmpty = this.getProp('allowEmpty');
|
|
401
|
+
// priority at Field level
|
|
475
402
|
const allowEmpty = fieldAllowEmpty ? fieldAllowEmpty : formAllowEmpty;
|
|
476
403
|
ObjectUtil.set(this.data.values, field, value, allowEmpty);
|
|
477
404
|
/**
|
|
@@ -481,76 +408,62 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
481
408
|
* register时,Field中同步initValue到FormState时调用的setValue不应该触发notify
|
|
482
409
|
* 但需要触发forceUpdate,否则useFormState、useFieldState初始渲染会有问题
|
|
483
410
|
*/
|
|
484
|
-
|
|
485
411
|
if (!notNotify) {
|
|
486
412
|
this._adapter.notifyChange(this.data);
|
|
487
|
-
|
|
488
413
|
this._adapter.notifyValueChange(this.data.values, {
|
|
489
414
|
[field]: value
|
|
490
415
|
});
|
|
491
416
|
}
|
|
492
|
-
|
|
493
417
|
if (!notUpdate) {
|
|
494
418
|
this._adapter.forceUpdate(callback);
|
|
495
419
|
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
|
|
420
|
+
}
|
|
421
|
+
// get touched from formState
|
|
499
422
|
getTouched(field) {
|
|
500
423
|
if (typeof field === 'undefined') {
|
|
501
424
|
return this.data.touched;
|
|
502
425
|
}
|
|
503
|
-
|
|
504
426
|
return ObjectUtil.get(this.data.touched, field);
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
|
|
427
|
+
}
|
|
428
|
+
// update formState touched
|
|
508
429
|
updateStateTouched(field, isTouched, opts, callback) {
|
|
509
430
|
const notNotify = opts && opts.notNotify;
|
|
510
431
|
const notUpdate = opts && opts.notUpdate;
|
|
511
432
|
ObjectUtil.set(this.data.touched, field, isTouched);
|
|
512
|
-
|
|
513
433
|
if (!notNotify) {
|
|
514
434
|
this._adapter.notifyChange(this.data);
|
|
515
435
|
}
|
|
516
|
-
|
|
517
436
|
if (!notUpdate) {
|
|
518
437
|
this._adapter.forceUpdate(callback);
|
|
519
438
|
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
|
|
439
|
+
}
|
|
440
|
+
// get error from formState
|
|
523
441
|
getError(field) {
|
|
524
442
|
if (typeof field === 'undefined') {
|
|
525
443
|
return this.data.errors;
|
|
526
444
|
}
|
|
527
|
-
|
|
528
445
|
return ObjectUtil.get(this.data.errors, field);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
|
|
446
|
+
}
|
|
447
|
+
// update formState error
|
|
532
448
|
updateStateError(field, error, opts, callback) {
|
|
533
449
|
const notNotify = opts && opts.notNotify;
|
|
534
450
|
const notUpdate = opts && opts.notUpdate;
|
|
535
|
-
ObjectUtil.set(this.data.errors, field, error);
|
|
451
|
+
ObjectUtil.set(this.data.errors, field, error);
|
|
452
|
+
// The setError caused by centralized validation does not need to trigger notify, otherwise it will be called too frequently, as many times as there are fields
|
|
536
453
|
// 集中validate时,引起的setError不需要触发notify,否则会过于频繁调用,有多少个field就调用了多少次
|
|
537
|
-
|
|
538
454
|
if (!notNotify) {
|
|
539
455
|
this._adapter.notifyChange(this.data);
|
|
540
456
|
}
|
|
541
|
-
|
|
542
457
|
if (!notUpdate) {
|
|
543
458
|
this._adapter.forceUpdate(callback);
|
|
544
459
|
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
460
|
+
}
|
|
461
|
+
// For internal use in the FormApi Operating Field
|
|
548
462
|
getFieldSetterApi() {
|
|
549
463
|
const setValue = (field, value, opts) => {
|
|
550
|
-
const fieldApi = this.fields.get(field) ? this.fields.get(field).fieldApi : undefined;
|
|
551
|
-
|
|
464
|
+
const fieldApi = this.fields.get(field) ? this.fields.get(field).fieldApi : undefined;
|
|
465
|
+
// DeepClone the value entered from the outside to avoid unexpected errors caused by not isolating the scope to the greatest extent. This setValue will be called in eg: ArrayField
|
|
552
466
|
const newValue = this._adapter.cloneDeep(value);
|
|
553
|
-
|
|
554
467
|
if (fieldApi) {
|
|
555
468
|
// If there is a corresponding Field entity, call FieldApi to update the value
|
|
556
469
|
fieldApi.setValue(newValue, opts);
|
|
@@ -561,7 +474,6 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
561
474
|
// When the user directly calls formA pi.set Value ('peoples', [2,3])
|
|
562
475
|
this.updateStateValue(field, newValue, opts, () => {
|
|
563
476
|
let nestedFields = this._getNestedField(field);
|
|
564
|
-
|
|
565
477
|
if (nestedFields.size) {
|
|
566
478
|
nestedFields.forEach(fieldStaff => {
|
|
567
479
|
let fieldPath = fieldStaff.field;
|
|
@@ -573,8 +485,8 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
573
485
|
fieldStaff.fieldApi.setValue(newFieldVal, nestedBatchUpdateOpts);
|
|
574
486
|
});
|
|
575
487
|
}
|
|
576
|
-
});
|
|
577
|
-
|
|
488
|
+
});
|
|
489
|
+
// If the reset happens to be, then update the updateKey corresponding to ArrayField to render it again
|
|
578
490
|
if (this.getArrayField(field)) {
|
|
579
491
|
this.updateArrayField(field, {
|
|
580
492
|
updateKey: new Date().valueOf()
|
|
@@ -582,18 +494,14 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
582
494
|
}
|
|
583
495
|
}
|
|
584
496
|
};
|
|
585
|
-
|
|
586
497
|
const setError = (field, error, opts) => {
|
|
587
498
|
const fieldApi = this.fields.get(field) ? this.fields.get(field).fieldApi : undefined;
|
|
588
|
-
|
|
589
499
|
const newError = this._adapter.cloneDeep(error);
|
|
590
|
-
|
|
591
500
|
if (fieldApi) {
|
|
592
501
|
fieldApi.setError(newError, opts);
|
|
593
502
|
} else {
|
|
594
503
|
this.updateStateError(field, newError, opts, () => {
|
|
595
504
|
let nestedFields = this._getNestedField(field);
|
|
596
|
-
|
|
597
505
|
if (nestedFields.size) {
|
|
598
506
|
nestedFields.forEach(fieldStaff => {
|
|
599
507
|
let fieldPath = fieldStaff.field;
|
|
@@ -606,7 +514,6 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
606
514
|
});
|
|
607
515
|
}
|
|
608
516
|
});
|
|
609
|
-
|
|
610
517
|
if (this.getArrayField(field)) {
|
|
611
518
|
this.updateArrayField(field, {
|
|
612
519
|
updateKey: new Date().valueOf()
|
|
@@ -614,16 +521,14 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
614
521
|
}
|
|
615
522
|
}
|
|
616
523
|
};
|
|
617
|
-
|
|
618
524
|
const setTouched = (field, isTouched, opts) => {
|
|
619
|
-
const fieldApi = this.fields.get(field) ? this.fields.get(field).fieldApi : undefined;
|
|
620
|
-
|
|
525
|
+
const fieldApi = this.fields.get(field) ? this.fields.get(field).fieldApi : undefined;
|
|
526
|
+
// touched is boolean variable, no need to exec deepClone like setValue
|
|
621
527
|
if (fieldApi) {
|
|
622
528
|
fieldApi.setTouched(isTouched, opts);
|
|
623
529
|
} else {
|
|
624
530
|
this.updateStateTouched(field, isTouched, opts, () => {
|
|
625
531
|
let nestedFields = this._getNestedField(field);
|
|
626
|
-
|
|
627
532
|
if (nestedFields.size) {
|
|
628
533
|
nestedFields.forEach(fieldStaff => {
|
|
629
534
|
let fieldPath = fieldStaff.field;
|
|
@@ -636,7 +541,6 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
636
541
|
});
|
|
637
542
|
}
|
|
638
543
|
});
|
|
639
|
-
|
|
640
544
|
if (this.getArrayField(field)) {
|
|
641
545
|
this.updateArrayField(field, {
|
|
642
546
|
updateKey: new Date().valueOf()
|
|
@@ -644,15 +548,13 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
644
548
|
}
|
|
645
549
|
}
|
|
646
550
|
};
|
|
647
|
-
|
|
648
551
|
return {
|
|
649
552
|
setValue,
|
|
650
553
|
setError,
|
|
651
554
|
setTouched
|
|
652
555
|
};
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
|
|
556
|
+
}
|
|
557
|
+
// For Field and ArrayField to read and modify FormState
|
|
656
558
|
getModifyFormStateApi() {
|
|
657
559
|
return {
|
|
658
560
|
register: this.register,
|
|
@@ -672,9 +574,8 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
672
574
|
getArrayField: this.getArrayField,
|
|
673
575
|
updateArrayField: this.updateArrayField
|
|
674
576
|
};
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
|
|
577
|
+
}
|
|
578
|
+
// Form APIs for external use, exposed to the user
|
|
678
579
|
getFormApi() {
|
|
679
580
|
const fieldSetterApi = this.getFieldSetterApi();
|
|
680
581
|
return Object.assign(Object.assign({}, fieldSetterApi), {
|
|
@@ -699,13 +600,10 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
699
600
|
scrollToField: (field, scrollOpts) => this.scrollToField(field, scrollOpts)
|
|
700
601
|
});
|
|
701
602
|
}
|
|
702
|
-
|
|
703
603
|
getFormState() {
|
|
704
604
|
let needClone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
705
|
-
|
|
706
605
|
// NOTES:这里如果直接返回this.data,forceUpdate 触发 Form rerender 时,通过context传下去的formState会被认为是同一个对象【应该是浅对比的原因】
|
|
707
606
|
// 使用了useFormState相关的component都不会触发重新渲染。所以使用...复制一次
|
|
708
|
-
|
|
709
607
|
/*
|
|
710
608
|
The reason for distinguishing deepClone: When semi is calling getFormState for internal consumption,
|
|
711
609
|
the value of formState will not be modified, so deep cloning is not necessary, which can reduce performance loss
|
|
@@ -720,10 +618,8 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
720
618
|
return this._adapter.cloneDeep(this.data);
|
|
721
619
|
}
|
|
722
620
|
}
|
|
723
|
-
|
|
724
621
|
_isValid(targetFields) {
|
|
725
622
|
let valid = true;
|
|
726
|
-
|
|
727
623
|
if (!targetFields) {
|
|
728
624
|
valid = Boolean(ObjectUtil.empty(this.data.errors));
|
|
729
625
|
} else {
|
|
@@ -731,62 +627,49 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
731
627
|
const targetFieldStr = [...targetFields.keys()];
|
|
732
628
|
targetFieldStr.forEach(fieldStr => {
|
|
733
629
|
const fieldError = ObjectUtil.get(this.data.errors, fieldStr);
|
|
734
|
-
|
|
735
630
|
if (!isValid(fieldError)) {
|
|
736
631
|
valid = false;
|
|
737
632
|
}
|
|
738
633
|
});
|
|
739
634
|
}
|
|
740
|
-
|
|
741
635
|
return valid;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
|
|
636
|
+
}
|
|
637
|
+
// get form.props.initValues
|
|
745
638
|
getInitValues() {
|
|
746
639
|
return this._adapter.getInitValues();
|
|
747
640
|
}
|
|
748
|
-
|
|
749
641
|
getInitValue(field) {
|
|
750
642
|
if (typeof field === 'undefined') {
|
|
751
643
|
return this._adapter.getInitValues();
|
|
752
644
|
}
|
|
753
|
-
|
|
754
645
|
return ObjectUtil.get(this._adapter.getInitValues(), field);
|
|
755
646
|
}
|
|
756
|
-
|
|
757
647
|
getFormProps(keys) {
|
|
758
648
|
return this._adapter.getFormProps(keys);
|
|
759
649
|
}
|
|
760
|
-
|
|
761
650
|
getFieldExist(field) {
|
|
762
651
|
return Boolean(this.fields.has(field));
|
|
763
652
|
}
|
|
764
|
-
|
|
765
653
|
_autoScroll(timeout) {
|
|
766
654
|
const {
|
|
767
655
|
autoScrollToError
|
|
768
656
|
} = this.getFormProps();
|
|
769
|
-
|
|
770
657
|
if (!autoScrollToError) {
|
|
771
658
|
return;
|
|
772
659
|
}
|
|
773
|
-
|
|
774
660
|
let scrollOpts = {
|
|
775
661
|
behavior: 'smooth',
|
|
776
662
|
block: 'start'
|
|
777
663
|
};
|
|
778
664
|
typeof autoScrollToError === 'object' ? scrollOpts = autoScrollToError : null;
|
|
779
|
-
|
|
780
665
|
if (timeout) {
|
|
781
666
|
setTimeout(() => this._getErrorFieldAndScroll(scrollOpts), 100);
|
|
782
667
|
} else {
|
|
783
668
|
this._getErrorFieldAndScroll(scrollOpts);
|
|
784
669
|
}
|
|
785
670
|
}
|
|
786
|
-
|
|
787
671
|
_getErrorFieldAndScroll(scrollOpts) {
|
|
788
672
|
const errorDOM = this._adapter.getAllErrorDOM();
|
|
789
|
-
|
|
790
673
|
if (errorDOM && errorDOM.length) {
|
|
791
674
|
try {
|
|
792
675
|
const fieldDom = errorDOM[0].parentNode.parentNode;
|
|
@@ -794,18 +677,14 @@ export default class FormFoundation extends BaseFoundation {
|
|
|
794
677
|
} catch (error) {}
|
|
795
678
|
}
|
|
796
679
|
}
|
|
797
|
-
|
|
798
680
|
scrollToField(field) {
|
|
799
681
|
let scrollOpts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
800
682
|
behavior: 'smooth',
|
|
801
683
|
block: 'start'
|
|
802
684
|
};
|
|
803
|
-
|
|
804
685
|
if (this.getFieldExist(field)) {
|
|
805
686
|
const fieldDOM = this._adapter.getFieldDOM(field);
|
|
806
|
-
|
|
807
687
|
scrollIntoView(fieldDOM, scrollOpts);
|
|
808
688
|
}
|
|
809
689
|
}
|
|
810
|
-
|
|
811
690
|
}
|