@hi-ui/form 4.3.1 → 4.3.3
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/CHANGELOG.md +16 -0
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/use-form-field.js +14 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/use-form-field.js +15 -2
- package/lib/types/FormList.d.ts +18 -1
- package/lib/types/index.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @hi-ui/form
|
|
2
2
|
|
|
3
|
+
## 4.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3277](https://github.com/XiaoMi/hiui/pull/3277) [`93df0aaff`](https://github.com/XiaoMi/hiui/commit/93df0aafff09be59faeb4bad0ceea57a00df5ccf) Thanks [@zyprepare](https://github.com/zyprepare)! - fix(form): 处理规则消息为空的情况,将其设置为 undefined (#3276)
|
|
8
|
+
|
|
9
|
+
- [#3275](https://github.com/XiaoMi/hiui/pull/3275) [`b2b66a9e7`](https://github.com/XiaoMi/hiui/commit/b2b66a9e73a1a92d6b0604dc2ad711895154e518) Thanks [@zyprepare](https://github.com/zyprepare)! - fix(form): 优化 valueType 为 number 情况下的校验逻辑 (#3274)
|
|
10
|
+
|
|
11
|
+
## 4.3.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#3160](https://github.com/XiaoMi/hiui/pull/3160) [`3244e5a`](https://github.com/XiaoMi/hiui/commit/3244e5a94d1cfa3d85a65bc8804a21b8b60b80a4) Thanks [@zyprepare](https://github.com/zyprepare)! - <br>
|
|
16
|
+
- feat(form): 入口新增 FormLabel 组件导出
|
|
17
|
+
- feat(form): 更新 FormListProps 中 children 渲染函数中 fields 参数的类型
|
|
18
|
+
|
|
3
19
|
## 4.3.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/lib/cjs/index.js
CHANGED
|
@@ -18,6 +18,7 @@ var FormItem = require('./FormItem.js');
|
|
|
18
18
|
var FormList = require('./FormList.js');
|
|
19
19
|
var FormSubmit = require('./FormSubmit.js');
|
|
20
20
|
var FormReset = require('./FormReset.js');
|
|
21
|
+
var FormLabel = require('./FormLabel.js');
|
|
21
22
|
var Form = Object.assign(Form$1.Form, {
|
|
22
23
|
Item: FormItem.FormItem,
|
|
23
24
|
List: FormList.FormList,
|
|
@@ -30,4 +31,5 @@ exports.FormItem = FormItem.FormItem;
|
|
|
30
31
|
exports.FormList = FormList.FormList;
|
|
31
32
|
exports.FormSubmit = FormSubmit.FormSubmit;
|
|
32
33
|
exports.FormReset = FormReset.FormReset;
|
|
34
|
+
exports.FormLabel = FormLabel.FormLabel;
|
|
33
35
|
exports["default"] = Form;
|
|
@@ -63,6 +63,9 @@ var useFormField = function useFormField(props) {
|
|
|
63
63
|
// TODO: rules 处理成 Async Validate 的指定结构
|
|
64
64
|
var fieldMD5 = index.stringify(field);
|
|
65
65
|
var modifiedFieldRules = fieldRules.map(function (rule) {
|
|
66
|
+
if (rule.message === null || rule.message === '') {
|
|
67
|
+
rule.message = undefined;
|
|
68
|
+
}
|
|
66
69
|
// 重写 rule 的 validator 函数,正则匹配 validatorRule 中的 field 和 fullField,消除 field 和 fullField 中的双引号
|
|
67
70
|
// issue:https://github.com/XiaoMi/hiui/issues/2931
|
|
68
71
|
if (rule.validator) {
|
|
@@ -79,7 +82,17 @@ var useFormField = function useFormField(props) {
|
|
|
79
82
|
} else return Object.assign({}, rule);
|
|
80
83
|
});
|
|
81
84
|
var validater = new Validater__default["default"]((_Validater = {}, _Validater[fieldMD5] = modifiedFieldRules, _Validater));
|
|
82
|
-
|
|
85
|
+
var valueToValidate = value;
|
|
86
|
+
if (valueType === 'number') {
|
|
87
|
+
if (typeAssertion.isNullish(value) || value === '') {
|
|
88
|
+
valueToValidate = value;
|
|
89
|
+
} else if (isNaN(value)) {
|
|
90
|
+
valueToValidate = value;
|
|
91
|
+
} else {
|
|
92
|
+
valueToValidate = Number(value);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return validater.validate((_validater$validate = {}, _validater$validate[fieldMD5] = valueToValidate, _validater$validate), {
|
|
83
96
|
firstFields: true
|
|
84
97
|
});
|
|
85
98
|
}, [fieldRules, field, valueType]);
|
package/lib/esm/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { FormItem } from './FormItem.js';
|
|
|
14
14
|
import { FormList } from './FormList.js';
|
|
15
15
|
import { FormSubmit } from './FormSubmit.js';
|
|
16
16
|
import { FormReset } from './FormReset.js';
|
|
17
|
+
export { FormLabel } from './FormLabel.js';
|
|
17
18
|
var Form = Object.assign(Form$1, {
|
|
18
19
|
Item: FormItem,
|
|
19
20
|
List: FormList,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { useMemo, useCallback, useEffect } from 'react';
|
|
11
11
|
import { useFormContext } from './context.js';
|
|
12
|
-
import { isArrayNonEmpty } from '@hi-ui/type-assertion';
|
|
12
|
+
import { isArrayNonEmpty, isNullish } from '@hi-ui/type-assertion';
|
|
13
13
|
import Validater from 'async-validator';
|
|
14
14
|
import { normalizeArray } from '@hi-ui/array-utils';
|
|
15
15
|
import { stringify, isValidField } from './utils/index.js';
|
|
@@ -51,6 +51,9 @@ var useFormField = function useFormField(props) {
|
|
|
51
51
|
// TODO: rules 处理成 Async Validate 的指定结构
|
|
52
52
|
var fieldMD5 = stringify(field);
|
|
53
53
|
var modifiedFieldRules = fieldRules.map(function (rule) {
|
|
54
|
+
if (rule.message === null || rule.message === '') {
|
|
55
|
+
rule.message = undefined;
|
|
56
|
+
}
|
|
54
57
|
// 重写 rule 的 validator 函数,正则匹配 validatorRule 中的 field 和 fullField,消除 field 和 fullField 中的双引号
|
|
55
58
|
// issue:https://github.com/XiaoMi/hiui/issues/2931
|
|
56
59
|
if (rule.validator) {
|
|
@@ -67,7 +70,17 @@ var useFormField = function useFormField(props) {
|
|
|
67
70
|
} else return Object.assign({}, rule);
|
|
68
71
|
});
|
|
69
72
|
var validater = new Validater((_Validater = {}, _Validater[fieldMD5] = modifiedFieldRules, _Validater));
|
|
70
|
-
|
|
73
|
+
var valueToValidate = value;
|
|
74
|
+
if (valueType === 'number') {
|
|
75
|
+
if (isNullish(value) || value === '') {
|
|
76
|
+
valueToValidate = value;
|
|
77
|
+
} else if (isNaN(value)) {
|
|
78
|
+
valueToValidate = value;
|
|
79
|
+
} else {
|
|
80
|
+
valueToValidate = Number(value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return validater.validate((_validater$validate = {}, _validater$validate[fieldMD5] = valueToValidate, _validater$validate), {
|
|
71
84
|
firstFields: true
|
|
72
85
|
});
|
|
73
86
|
}, [fieldRules, field, valueType]);
|
package/lib/types/FormList.d.ts
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { HiBaseHTMLProps } from '@hi-ui/core';
|
|
3
3
|
import { FormFieldPath, FormListChildrenAction, FormListHelper } from './types';
|
|
4
|
+
declare const fieldListSymbol: unique symbol;
|
|
4
5
|
export declare const FormList: React.ForwardRefExoticComponent<FormListProps & React.RefAttributes<HTMLDivElement | null>>;
|
|
6
|
+
export interface FormListChildField {
|
|
7
|
+
/**
|
|
8
|
+
* 字段名
|
|
9
|
+
* - 实际上是元素在数组中的索引
|
|
10
|
+
*/
|
|
11
|
+
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* 字段符号
|
|
14
|
+
*/
|
|
15
|
+
symbol: typeof fieldListSymbol;
|
|
16
|
+
/**
|
|
17
|
+
* 字段值
|
|
18
|
+
*/
|
|
19
|
+
value: unknown;
|
|
20
|
+
}
|
|
5
21
|
export interface FormListProps extends HiBaseHTMLProps<'div'> {
|
|
6
22
|
/**
|
|
7
23
|
* 表单控件渲染函数
|
|
8
24
|
*/
|
|
9
|
-
children?: (fields:
|
|
25
|
+
children?: (fields: FormListChildField[], action: FormListChildrenAction) => React.ReactElement;
|
|
10
26
|
/**
|
|
11
27
|
* 列表名称
|
|
12
28
|
*/
|
|
@@ -16,3 +32,4 @@ export interface FormListProps extends HiBaseHTMLProps<'div'> {
|
|
|
16
32
|
*/
|
|
17
33
|
innerRef?: React.Ref<FormListHelper>;
|
|
18
34
|
}
|
|
35
|
+
export {};
|
package/lib/types/index.d.ts
CHANGED