@hi-ui/form 4.0.0-beta.17 → 4.0.0-beta.18
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.
|
@@ -77,18 +77,12 @@ var useFormField = function useFormField(props) {
|
|
|
77
77
|
}, [fieldRules, field]); // 注入当前 field 及其验证规则到 Form
|
|
78
78
|
|
|
79
79
|
React.useEffect(function () {
|
|
80
|
-
if (
|
|
81
|
-
if (typeAssertion.isArray(field) && field.every(function (item) {
|
|
82
|
-
return typeAssertion.isNullish(item) || item === '';
|
|
83
|
-
})) return;
|
|
80
|
+
if (!index.isValidField(field)) return;
|
|
84
81
|
registerField(field, {
|
|
85
82
|
validate: fieldValidate
|
|
86
83
|
});
|
|
87
84
|
return function () {
|
|
88
|
-
if (
|
|
89
|
-
if (typeAssertion.isArray(field) && field.every(function (item) {
|
|
90
|
-
return typeAssertion.isNullish(item) || item === '';
|
|
91
|
-
})) return;
|
|
85
|
+
if (!index.isValidField(field)) return;
|
|
92
86
|
unregisterField(field);
|
|
93
87
|
};
|
|
94
88
|
}, [registerField, unregisterField, field, fieldValidate]);
|
package/lib/cjs/use-form.js
CHANGED
|
@@ -574,7 +574,10 @@ var useForm = function useForm(_a) {
|
|
|
574
574
|
valueConnectTransform = _props.valueConnectTransform,
|
|
575
575
|
_props$validateTrigge = _props.validateTrigger,
|
|
576
576
|
validateTriggerProp = _props$validateTrigge === void 0 ? validateTriggersMemo : _props$validateTrigge,
|
|
577
|
-
children = _props.children;
|
|
577
|
+
children = _props.children; // field 未设置,不进行收集管理
|
|
578
|
+
|
|
579
|
+
if (!index.isValidField(field)) return {}; // 控件的 props
|
|
580
|
+
|
|
578
581
|
var controlProps = children && children.props || {};
|
|
579
582
|
var validateTrigger = typeAssertion.isArray(validateTriggerProp) ? validateTriggerProp : [validateTriggerProp];
|
|
580
583
|
var validateOnCollect = validateTrigger.includes(valueChangeFuncPropName);
|
package/lib/cjs/utils/index.js
CHANGED
|
@@ -13,6 +13,8 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
13
13
|
value: true
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
+
var typeAssertion = require('@hi-ui/type-assertion');
|
|
17
|
+
|
|
16
18
|
var stringify = function stringify(field) {
|
|
17
19
|
return JSON.stringify(field);
|
|
18
20
|
};
|
|
@@ -21,5 +23,14 @@ var parse = function parse(fieldStr) {
|
|
|
21
23
|
return JSON.parse(fieldStr);
|
|
22
24
|
};
|
|
23
25
|
|
|
26
|
+
var isValidField = function isValidField(field) {
|
|
27
|
+
if (typeAssertion.isNullish(field) || field === '') return false;
|
|
28
|
+
if (typeAssertion.isArray(field) && field.every(function (item) {
|
|
29
|
+
return typeAssertion.isNullish(item) || item === '';
|
|
30
|
+
})) return false;
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.isValidField = isValidField;
|
|
24
35
|
exports.parse = parse;
|
|
25
36
|
exports.stringify = stringify;
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { useMemo, useCallback, useEffect } from 'react';
|
|
11
11
|
import { useFormContext } from './context.js';
|
|
12
|
-
import { isArrayNonEmpty
|
|
12
|
+
import { isArrayNonEmpty } from '@hi-ui/type-assertion';
|
|
13
13
|
import Validater from 'async-validator';
|
|
14
14
|
import { normalizeArray } from '@hi-ui/array-utils';
|
|
15
|
-
import { stringify } from './utils/index.js';
|
|
15
|
+
import { stringify, isValidField } from './utils/index.js';
|
|
16
16
|
|
|
17
17
|
var useFormField = function useFormField(props) {
|
|
18
18
|
var field = props.field,
|
|
@@ -56,18 +56,12 @@ var useFormField = function useFormField(props) {
|
|
|
56
56
|
}, [fieldRules, field]); // 注入当前 field 及其验证规则到 Form
|
|
57
57
|
|
|
58
58
|
useEffect(function () {
|
|
59
|
-
if (
|
|
60
|
-
if (isArray(field) && field.every(function (item) {
|
|
61
|
-
return isNullish(item) || item === '';
|
|
62
|
-
})) return;
|
|
59
|
+
if (!isValidField(field)) return;
|
|
63
60
|
registerField(field, {
|
|
64
61
|
validate: fieldValidate
|
|
65
62
|
});
|
|
66
63
|
return function () {
|
|
67
|
-
if (
|
|
68
|
-
if (isArray(field) && field.every(function (item) {
|
|
69
|
-
return isNullish(item) || item === '';
|
|
70
|
-
})) return;
|
|
64
|
+
if (!isValidField(field)) return;
|
|
71
65
|
unregisterField(field);
|
|
72
66
|
};
|
|
73
67
|
}, [registerField, unregisterField, field, fieldValidate]);
|
package/lib/esm/use-form.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
11
11
|
import { __rest, __awaiter } from 'tslib';
|
|
12
|
-
import { stringify, parse } from './utils/index.js';
|
|
12
|
+
import { stringify, parse, isValidField } from './utils/index.js';
|
|
13
13
|
import React, { useMemo, useReducer, useCallback, useRef } from 'react';
|
|
14
14
|
import { useLatestRef, useLatestCallback } from '@hi-ui/use-latest';
|
|
15
15
|
import { isArray, isObjectLike, isFunction } from '@hi-ui/type-assertion';
|
|
@@ -547,7 +547,10 @@ var useForm = function useForm(_a) {
|
|
|
547
547
|
valueConnectTransform = _props.valueConnectTransform,
|
|
548
548
|
_props$validateTrigge = _props.validateTrigger,
|
|
549
549
|
validateTriggerProp = _props$validateTrigge === void 0 ? validateTriggersMemo : _props$validateTrigge,
|
|
550
|
-
children = _props.children;
|
|
550
|
+
children = _props.children; // field 未设置,不进行收集管理
|
|
551
|
+
|
|
552
|
+
if (!isValidField(field)) return {}; // 控件的 props
|
|
553
|
+
|
|
551
554
|
var controlProps = children && children.props || {};
|
|
552
555
|
var validateTrigger = isArray(validateTriggerProp) ? validateTriggerProp : [validateTriggerProp];
|
|
553
556
|
var validateOnCollect = validateTrigger.includes(valueChangeFuncPropName);
|
package/lib/esm/utils/index.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
|
+
import { isNullish, isArray } from '@hi-ui/type-assertion';
|
|
11
|
+
|
|
10
12
|
var stringify = function stringify(field) {
|
|
11
13
|
return JSON.stringify(field);
|
|
12
14
|
};
|
|
@@ -15,4 +17,12 @@ var parse = function parse(fieldStr) {
|
|
|
15
17
|
return JSON.parse(fieldStr);
|
|
16
18
|
};
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
var isValidField = function isValidField(field) {
|
|
21
|
+
if (isNullish(field) || field === '') return false;
|
|
22
|
+
if (isArray(field) && field.every(function (item) {
|
|
23
|
+
return isNullish(item) || item === '';
|
|
24
|
+
})) return false;
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { isValidField, parse, stringify };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FormFieldPath } from './../types';
|
|
2
|
-
export declare const setProp: (o: any, filed: any, value: any) => any;
|
|
3
2
|
export declare const stringify: (field: FormFieldPath) => string;
|
|
4
3
|
export declare const parse: (fieldStr: string) => FormFieldPath;
|
|
4
|
+
export declare const isValidField: (field: FormFieldPath | undefined) => field is FormFieldPath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hi-ui/form",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.18",
|
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "HIUI <mi-hiui@xiaomi.com>",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"react": "^17.0.1",
|
|
66
66
|
"react-dom": "^17.0.1"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "85818619960345c5c33ec381769e7501d189cb41"
|
|
69
69
|
}
|